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; ...@@ -11,6 +11,7 @@ import com.mortals.xhx.module.pj.service.PjEvaluateStatService;
import com.mortals.xhx.module.stat.service.StatService; import com.mortals.xhx.module.stat.service.StatService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
import java.util.List; import java.util.List;
...@@ -29,14 +30,18 @@ public class StatThread implements Runnable { ...@@ -29,14 +30,18 @@ public class StatThread implements Runnable {
private Long compare; private Long compare;
private SitePdu site; private List<SitePdu> statSiteList;
private Context context; private Context context;
private List<Integer> typeStatList; private List<Integer> typeStatList;
@Override @Override
public void run() { public void run() {
for (SitePdu site : statSiteList) {
if (ObjectUtils.isEmpty(site.getId())) continue;
StopWatch stopWatch = new StopWatch(); StopWatch stopWatch = new StopWatch();
PhQueueStatService phQueueStatService = SpringUtil.getBean(PhQueueStatService.class); PhQueueStatService phQueueStatService = SpringUtil.getBean(PhQueueStatService.class);
PjEvaluateStatService pjEvaluateStatService = SpringUtil.getBean(PjEvaluateStatService.class); PjEvaluateStatService pjEvaluateStatService = SpringUtil.getBean(PjEvaluateStatService.class);
...@@ -53,6 +58,7 @@ public class StatThread implements Runnable { ...@@ -53,6 +58,7 @@ public class StatThread implements Runnable {
if (typeStatList.contains(StatTypeEnum.STAT_ALL.getValue())) { if (typeStatList.contains(StatTypeEnum.STAT_ALL.getValue())) {
statService.updateSiteStatLog(attendStart, compare, stopWatch, site, context); statService.updateSiteStatLog(attendStart, compare, stopWatch, site, context);
} }
}
} }
......
...@@ -81,12 +81,12 @@ public class SiteStatTaskImpl implements ITaskExcuteService { ...@@ -81,12 +81,12 @@ public class SiteStatTaskImpl implements ITaskExcuteService {
private void statByDate(Long compare) { 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()); DateTime attendStart = DateUtil.offsetDay(new Date(), -compare.intValue());
for (SitePdu site : sitePduList) { // for (SitePdu site : sitePduList) {
if (ObjectUtils.isEmpty(site.getId())) continue; // if (ObjectUtils.isEmpty(site.getId())) continue;
StatThread statThread = new StatThread(attendStart, compare, site, null, StatThread statThread = new StatThread(attendStart, compare, sitePduList, null,
Arrays.asList(StatTypeEnum.STAT_PH.getValue(),StatTypeEnum.STAT_PJ.getValue(),StatTypeEnum.STAT_ALL.getValue())); Arrays.asList(StatTypeEnum.STAT_PH.getValue(),StatTypeEnum.STAT_PJ.getValue(),StatTypeEnum.STAT_ALL.getValue()));
ThreadPool.getInstance().execute(statThread); ThreadPool.getInstance().execute(statThread);
} // }
} }
private void updateSiteCache() { private void updateSiteCache() {
......
...@@ -185,11 +185,11 @@ public class PhQueueStatController extends BaseCRUDJsonBodyMappingController<PhQ ...@@ -185,11 +185,11 @@ public class PhQueueStatController extends BaseCRUDJsonBodyMappingController<PhQ
DateTime attendEnd = DateUtil.parseDate(phQueueQuery.getTaketimeEnd()); DateTime attendEnd = DateUtil.parseDate(phQueueQuery.getTaketimeEnd());
Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY); Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY);
log.info("计算天数区间:{}", compare); log.info("计算天数区间:{}", compare);
List<SitePdu> statSiteList = accessService.getStatSiteList( new AccessQuery()); List<SitePdu> statSiteList = accessService.getStatSiteList(new AccessQuery());
for (SitePdu site : statSiteList) { // for (SitePdu site : statSiteList) {
StatThread statThread = new StatThread(attendStart, compare, site, context, Arrays.asList(StatTypeEnum.STAT_PH.getValue())); StatThread statThread = new StatThread(attendStart, compare, statSiteList, context, Arrays.asList(StatTypeEnum.STAT_PH.getValue()));
ThreadPool.getInstance().execute(statThread); ThreadPool.getInstance().execute(statThread);
} // }
model.put("message_info", busiDesc + "成功"); model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】"); this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) { } catch (Exception e) {
......
...@@ -108,15 +108,7 @@ public class PjEvaluateController extends BaseCRUDJsonBodyMappingController<PjEv ...@@ -108,15 +108,7 @@ public class PjEvaluateController extends BaseCRUDJsonBodyMappingController<PjEv
@Override @Override
@UnAuth @UnAuth
public String batchSave(@RequestBody List<PjEvaluateEntity> list) { public String batchSave(@RequestBody List<PjEvaluateEntity> list) {
/* BatchSavePjTask batchSavePjTask = new BatchSavePjTask(list);
ThreadPool.getInstance().execute(batchSavePjTask);*/
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
@Override @Override
public void run() { public void run() {
for (PjEvaluateEntity entity : list) { for (PjEvaluateEntity entity : list) {
......
...@@ -184,10 +184,10 @@ public class PjEvaluateStatController extends BaseCRUDJsonBodyMappingController< ...@@ -184,10 +184,10 @@ public class PjEvaluateStatController extends BaseCRUDJsonBodyMappingController<
Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY); Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY);
log.info("计算天数区间:{}", compare); log.info("计算天数区间:{}", compare);
List<SitePdu> statSiteList = accessService.getStatSiteList( new AccessQuery()); List<SitePdu> statSiteList = accessService.getStatSiteList( new AccessQuery());
for (SitePdu site : statSiteList) { // for (SitePdu site : statSiteList) {
StatThread statThread = new StatThread(attendStart, compare, site, context, Arrays.asList(StatTypeEnum.STAT_PJ.getValue())); StatThread statThread = new StatThread(attendStart, compare, statSiteList, context, Arrays.asList(StatTypeEnum.STAT_PJ.getValue()));
ThreadPool.getInstance().execute(statThread); ThreadPool.getInstance().execute(statThread);
} // }
model.put("message_info", busiDesc + "成功"); model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】"); this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) { } catch (Exception e) {
......
...@@ -99,11 +99,11 @@ public class StatController extends BaseCRUDJsonBodyMappingController<StatServic ...@@ -99,11 +99,11 @@ public class StatController extends BaseCRUDJsonBodyMappingController<StatServic
DateTime attendEnd = DateUtil.parseDate(query.getCreateTimeEnd()); DateTime attendEnd = DateUtil.parseDate(query.getCreateTimeEnd());
Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY); Long compare = DateUtil.between(attendEnd, attendStart, DateUnit.DAY);
log.info("计算天数区间:{}", compare); log.info("计算天数区间:{}", compare);
List<SitePdu> statSiteList = accessService.getStatSiteList( new AccessQuery()); List<SitePdu> statSiteList = accessService.getStatSiteList(new AccessQuery());
for (SitePdu site : statSiteList) { // for (SitePdu site : statSiteList) {
StatThread statThread = new StatThread(attendStart, compare, site, context, Arrays.asList(StatTypeEnum.STAT_ALL.getValue())); StatThread statThread = new StatThread(attendStart, compare, statSiteList, context, Arrays.asList(StatTypeEnum.STAT_ALL.getValue()));
ThreadPool.getInstance().execute(statThread); ThreadPool.getInstance().execute(statThread);
} // }
model.put("message_info", busiDesc + "成功"); model.put("message_info", busiDesc + "成功");
this.recordSysLog(this.request, busiDesc + " 【成功】"); this.recordSysLog(this.request, busiDesc + " 【成功】");
} catch (Exception e) { } catch (Exception e) {
......
...@@ -75,8 +75,8 @@ POST {{baseUrl}}/access/stat ...@@ -75,8 +75,8 @@ POST {{baseUrl}}/access/stat
Content-Type: application/json Content-Type: application/json
{ {
"accessTimeStart": "2024-07-01", "accessTimeStart": "2023-01-01",
"accessTimeEnd": "2024-07-29" "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