Commit 978ebbcb authored by 赵啸非's avatar 赵啸非

重新调整统计线程实现

parent f60af084
package com.mortals.xhx.common.thread;
import cn.hutool.core.date.DateTime;
import cn.hutool.extra.spring.SpringUtil;
import com.mortals.framework.model.Context;
import com.mortals.xhx.common.code.StatTypeEnum;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.module.ph.service.PhQueueStatService;
import com.mortals.xhx.module.pj.service.PjEvaluateStatService;
import com.mortals.xhx.module.stat.service.StatService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch;
import java.util.List;
/**
* 站点统计数据线程
*
* @author: zxfei
* @date: 2024/8/2 14:13
*/
@Slf4j
@AllArgsConstructor
public class StatAllThread implements Runnable {
private DateTime attendStart;
private Long compare;
private SitePdu site;
private Context context;
private List<Integer> typeStatList;
@Override
public void run() {
if (ObjectUtils.isEmpty(site.getId())) return;
StopWatch stopWatch = new StopWatch();
StatService statService = SpringUtil.getBean(StatService.class);
if (typeStatList.contains(StatTypeEnum.STAT_ALL.getValue())) {
statService.updateSiteStatLog(attendStart, compare, stopWatch, site, context);
}
}
}
......@@ -30,7 +30,7 @@ public class StatThread implements Runnable {
private Long compare;
private List<SitePdu> statSiteList;
private SitePdu site;
private Context context;
......@@ -39,8 +39,7 @@ public class StatThread implements Runnable {
@Override
public void run() {
for (SitePdu site : statSiteList) {
if (ObjectUtils.isEmpty(site.getId())) continue;
if (ObjectUtils.isEmpty(site.getId())) return;
StopWatch stopWatch = new StopWatch();
PhQueueStatService phQueueStatService = SpringUtil.getBean(PhQueueStatService.class);
......@@ -58,7 +57,7 @@ public class StatThread implements Runnable {
if (typeStatList.contains(StatTypeEnum.STAT_ALL.getValue())) {
statService.updateSiteStatLog(attendStart, compare, stopWatch, site, context);
}
}
}
......
package com.mortals.xhx.daemon.task;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.framework.util.DataUtil;
import com.mortals.framework.util.ThreadPool;
import com.mortals.xhx.common.code.StatTypeEnum;
import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.thread.StatThread;
import com.mortals.xhx.module.access.model.AccessQuery;
import com.mortals.xhx.module.access.service.AccessService;
import com.mortals.xhx.module.ph.model.PhQueueStatEntity;
import com.mortals.xhx.module.ph.model.PhQueueStatQuery;
import com.mortals.xhx.module.ph.service.PhQueueStatService;
import com.mortals.xhx.module.pj.model.PjEvaluateStatEntity;
import com.mortals.xhx.module.pj.model.PjEvaluateStatQuery;
import com.mortals.xhx.module.pj.service.PjEvaluateStatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* 站点评价统计任务
*
* @author: zxfei
* @date: 2022/3/9 15:19
*/
@Slf4j
@Service("SiteStatAllTask")
public class SiteStatAllTaskImpl implements ITaskExcuteService {
@Autowired
private PjEvaluateStatService pjEvaluateStatService;
@Autowired
private PhQueueStatService phQueueStatService;
@Autowired
private ICacheService cacheService;
@Autowired
private AccessService accessService;
@Override
public void excuteTask(ITask task) throws AppException {
log.info("站点评价统计任务");
//统计最近4天
Long compare = DataUtil.converStr2Long(task.getExcuteParam(), 4L);
statByDate(compare);
}
private void statByDate(Long compare) {
List<SitePdu> sitePduList = accessService.getStatSiteList(new AccessQuery());
DateTime attendStart = DateUtil.offsetDay(new Date(), -compare.intValue());
for (SitePdu site : sitePduList) {
if (ObjectUtils.isEmpty(site.getId())) continue;
StatThread statThread = new StatThread(attendStart, compare, site, null,
Arrays.asList(StatTypeEnum.STAT_ALL.getValue()));
ThreadPool.getInstance().execute(statThread);
}
}
@Override
public void stopTask(ITask task) throws AppException {
}
public static void main(String[] args) {
for (int i = 0; i < 7; i++) {
DateTime beforeDate = DateUtil.offsetDay(new Date(), -i);
int year = beforeDate.year();
int month = beforeDate.month() + 1;
int day = beforeDate.dayOfMonth();
System.out.println(year + "年" + month + "月" + day + "日");
}
/* int year = DateUtil.date().year();
int month = DateUtil.date().month() + 1;
int day = DateUtil.date().dayOfMonth();
// System.out.println(year + "年" + month + "月" + day + "日");
System.out.println(dateTime.toString("yyyy-MM-dd"));*/
}
}
......@@ -79,18 +79,18 @@ public class SiteStatTaskImpl implements ITaskExcuteService {
}
private void statByDate(Long compare) {
List<SitePdu> sitePduList = accessService.getStatSiteList( new AccessQuery());
List<SitePdu> sitePduList = accessService.getStatSiteList(new AccessQuery());
DateTime attendStart = DateUtil.offsetDay(new Date(), -compare.intValue());
// for (SitePdu site : sitePduList) {
// if (ObjectUtils.isEmpty(site.getId())) continue;
StatThread statThread = new StatThread(attendStart, compare, sitePduList, null,
Arrays.asList(StatTypeEnum.STAT_PH.getValue(),StatTypeEnum.STAT_PJ.getValue(),StatTypeEnum.STAT_ALL.getValue()));
for (SitePdu site : sitePduList) {
if (ObjectUtils.isEmpty(site.getId())) continue;
StatThread statThread = new StatThread(attendStart, compare, site, null,
Arrays.asList(StatTypeEnum.STAT_PH.getValue(), StatTypeEnum.STAT_PJ.getValue()));
ThreadPool.getInstance().execute(statThread);
// }
}
}
private void updateSiteCache() {
List<SitePdu> sitePduList = accessService.getStatSiteList( new AccessQuery());
List<SitePdu> sitePduList = accessService.getStatSiteList(new AccessQuery());
for (SitePdu site : sitePduList) {
updatePjSectionCache(site);
......
......@@ -22,6 +22,8 @@ public class AccessVo extends BaseEntityLong {
/** 序号,主键,自增长列表 */
private List <Long> idList;
private List<Integer> typeStatusList;
public static void main(String[] args) {
AccessEntity accessEntity = new AccessEntity();
......
......@@ -19,6 +19,7 @@ import com.mortals.xhx.module.access.model.AccessQuery;
import com.mortals.xhx.module.access.service.AccessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -75,12 +76,16 @@ public class AccessController extends BaseCRUDJsonBodyMappingController<AccessSe
log.info("计算天数区间:{}", compare);
accessQuery.setAccessTimeStart(null);
accessQuery.setAccessTimeEnd(null);
if (ObjectUtils.isEmpty(accessQuery.getTypeStatusList())) {
accessQuery.setTypeStatusList(Arrays.asList(StatTypeEnum.STAT_PH.getValue(), StatTypeEnum.STAT_PJ.getValue()));
}
List<SitePdu> statSiteList = accessService.getStatSiteList(accessQuery);
//for (SitePdu site : statSiteList) {
StatThread statThread = new StatThread(attendStart, compare, statSiteList, context,
Arrays.asList(StatTypeEnum.STAT_PH.getValue(), StatTypeEnum.STAT_PJ.getValue(), StatTypeEnum.STAT_ALL.getValue()));
for (SitePdu site : statSiteList) {
StatThread statThread = new StatThread(attendStart, compare, site, context, accessQuery.getTypeStatusList());
ThreadPool.getInstance().execute(statThread);
// }
}
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) {
......
......@@ -179,10 +179,10 @@ public class PhQueueStatController extends BaseCRUDJsonBodyMappingController<PhQ
Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY);
log.info("计算天数区间:{}", compare);
List<SitePdu> statSiteList = accessService.getStatSiteList(new AccessQuery());
// for (SitePdu site : statSiteList) {
StatThread statThread = new StatThread(attendStart, compare, statSiteList, context, Arrays.asList(StatTypeEnum.STAT_PH.getValue()));
for (SitePdu site : statSiteList) {
StatThread statThread = new StatThread(attendStart, compare, site, context, Arrays.asList(StatTypeEnum.STAT_PH.getValue()));
ThreadPool.getInstance().execute(statThread);
// }
}
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) {
......
......@@ -184,10 +184,10 @@ public class PjEvaluateStatController extends BaseCRUDJsonBodyMappingController<
Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY);
log.info("计算天数区间:{}", compare);
List<SitePdu> statSiteList = accessService.getStatSiteList( new AccessQuery());
// for (SitePdu site : statSiteList) {
StatThread statThread = new StatThread(attendStart, compare, statSiteList, context, Arrays.asList(StatTypeEnum.STAT_PJ.getValue()));
for (SitePdu site : statSiteList) {
StatThread statThread = new StatThread(attendStart, compare, site, context, Arrays.asList(StatTypeEnum.STAT_PJ.getValue()));
ThreadPool.getInstance().execute(statThread);
// }
}
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) {
......
......@@ -100,10 +100,10 @@ public class StatController extends BaseCRUDJsonBodyMappingController<StatServic
Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY);
log.info("计算天数区间:{}", compare);
List<SitePdu> statSiteList = accessService.getStatSiteList(new AccessQuery());
// for (SitePdu site : statSiteList) {
StatThread statThread = new StatThread(attendStart, compare, statSiteList, context, Arrays.asList(StatTypeEnum.STAT_ALL.getValue()));
ThreadPool.getInstance().execute(statThread);
// }
for (SitePdu site : statSiteList) {
StatThread statThread = new StatThread(attendStart, compare, site, context, Arrays.asList(StatTypeEnum.STAT_ALL.getValue()));
ThreadPool.getInstance().execute(statThread);
}
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) {
......
......@@ -76,7 +76,7 @@ Content-Type: application/json
{
"accessTimeStart": "2023-01-01",
"accessTimeEnd": "2024-08-01"
"accessTimeEnd": "2024-08-05"
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment