Commit 964e25d6 authored by 赵啸非's avatar 赵啸非

重新调整统计线程实现

parent 6cfbf0b9
package com.mortals.xhx.common.thread;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.access.model.AccessEntity;
import com.mortals.xhx.module.access.model.AccessQuery;
import com.mortals.xhx.module.access.model.AccessSystemEntity;
import com.mortals.xhx.module.access.service.AccessService;
import com.mortals.xhx.module.ph.model.PhQueueQuery;
import com.mortals.xhx.module.ph.service.PhQueueStatService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;
/**
* 排号统计数据
* @author: zxfei
* @date: 2024/8/2 14:13
*/
@Slf4j
@AllArgsConstructor
public class PhStatThread implements Runnable {
private DateTime attendStart;
private Long compare;
private SitePdu site;
private Context context;
@Override
public void run() {
StopWatch stopWatch = new StopWatch();
PhQueueStatService phQueueStatService= SpringUtil.getBean(PhQueueStatService.class);
phQueueStatService.updateSitePhStatLog(attendStart, compare, stopWatch, site, context);
}
}
......@@ -11,6 +11,7 @@ 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;
......@@ -29,29 +30,34 @@ public class StatThread implements Runnable {
private Long compare;
private SitePdu site;
private List<SitePdu> statSiteList;
private Context context;
private List<Integer> typeStatList;
@Override
public void run() {
StopWatch stopWatch = new StopWatch();
PhQueueStatService phQueueStatService = SpringUtil.getBean(PhQueueStatService.class);
PjEvaluateStatService pjEvaluateStatService = SpringUtil.getBean(PjEvaluateStatService.class);
StatService statService = SpringUtil.getBean(StatService.class);
for (SitePdu site : statSiteList) {
if (ObjectUtils.isEmpty(site.getId())) continue;
if (typeStatList.contains(StatTypeEnum.STAT_PH.getValue())) {
phQueueStatService.updateSitePhStatLog(attendStart, compare, stopWatch, site, context);
}
StopWatch stopWatch = new StopWatch();
PhQueueStatService phQueueStatService = SpringUtil.getBean(PhQueueStatService.class);
PjEvaluateStatService pjEvaluateStatService = SpringUtil.getBean(PjEvaluateStatService.class);
StatService statService = SpringUtil.getBean(StatService.class);
if (typeStatList.contains(StatTypeEnum.STAT_PJ.getValue())) {
pjEvaluateStatService.updateSitePjStatLog(attendStart, compare, stopWatch, site, context);
}
if (typeStatList.contains(StatTypeEnum.STAT_PH.getValue())) {
phQueueStatService.updateSitePhStatLog(attendStart, compare, stopWatch, site, context);
}
if (typeStatList.contains(StatTypeEnum.STAT_PJ.getValue())) {
pjEvaluateStatService.updateSitePjStatLog(attendStart, compare, stopWatch, site, context);
}
if (typeStatList.contains(StatTypeEnum.STAT_ALL.getValue())) {
statService.updateSiteStatLog(attendStart, compare, stopWatch, site, context);
if (typeStatList.contains(StatTypeEnum.STAT_ALL.getValue())) {
statService.updateSiteStatLog(attendStart, compare, stopWatch, site, context);
}
}
}
......
......@@ -81,12 +81,12 @@ public class SiteStatTaskImpl implements ITaskExcuteService {
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,
// 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()));
ThreadPool.getInstance().execute(statThread);
}
// }
}
private void updateSiteCache() {
......
......@@ -185,11 +185,11 @@ public class PhQueueStatController extends BaseCRUDJsonBodyMappingController<PhQ
DateTime attendEnd = DateUtil.parseDate(phQueueQuery.getTaketimeEnd());
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, site, context, Arrays.asList(StatTypeEnum.STAT_PH.getValue()));
ThreadPool.getInstance().execute(statThread);
}
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()));
ThreadPool.getInstance().execute(statThread);
// }
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) {
......
......@@ -108,15 +108,7 @@ public class PjEvaluateController extends BaseCRUDJsonBodyMappingController<PjEv
@Override
@UnAuth
public String batchSave(@RequestBody List<PjEvaluateEntity> list) {
/* BatchSavePjTask batchSavePjTask = new BatchSavePjTask(list);
ThreadPool.getInstance().execute(batchSavePjTask);*/
Runnable runnable = new Runnable() {
@Override
public void run() {
for (PjEvaluateEntity entity : list) {
......
......@@ -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, site, context, Arrays.asList(StatTypeEnum.STAT_PJ.getValue()));
// for (SitePdu site : statSiteList) {
StatThread statThread = new StatThread(attendStart, compare, statSiteList, context, Arrays.asList(StatTypeEnum.STAT_PJ.getValue()));
ThreadPool.getInstance().execute(statThread);
}
// }
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) {
......
......@@ -99,11 +99,11 @@ public class StatController extends BaseCRUDJsonBodyMappingController<StatServic
DateTime attendEnd = DateUtil.parseDate(query.getCreateTimeEnd());
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, site, context, Arrays.asList(StatTypeEnum.STAT_ALL.getValue()));
ThreadPool.getInstance().execute(statThread);
}
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);
// }
model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) {
......
......@@ -75,8 +75,8 @@ POST {{baseUrl}}/access/stat
Content-Type: application/json
{
"accessTimeStart": "2024-07-01",
"accessTimeEnd": "2024-07-29"
"accessTimeStart": "2023-01-01",
"accessTimeEnd": "2024-08-01"
}
......
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