diff --git a/src/main/java/com/cm/inspection/controller/apis/count/CountController.java b/src/main/java/com/cm/inspection/controller/apis/count/CountController.java index 957408d..d08d7f9 100644 --- a/src/main/java/com/cm/inspection/controller/apis/count/CountController.java +++ b/src/main/java/com/cm/inspection/controller/apis/count/CountController.java @@ -4,9 +4,9 @@ import com.cm.common.base.AbstractController; import com.cm.common.constants.ISystemConstant; import com.cm.common.exception.ParamsException; import com.cm.common.result.ErrorResult; -import com.cm.common.result.SuccessResult; import com.cm.common.result.SuccessResultData; import com.cm.common.utils.RegexUtil; +import com.cm.inspection.reportform.CheckDetailTable; import com.cm.inspection.service.check.ICheckService; import com.cm.inspection.service.count.ICountService; import com.cm.inspection.service.enterprise.IEnterpriseService; @@ -154,7 +154,11 @@ public class CountController extends AbstractController { public SuccessResultData> countCheckDetailTable(@PathVariable("year") String year, @RequestParam(name = "areaId", required = false) String areaId, @RequestParam(name = "areaLevel", required = false) Integer areaLevel) { - return countService.countCheckDetailTable(areaId, areaLevel, year); + Map result = CheckDetailTable.getInstance().get(year, areaId); + if(result == null) { + return countService.countCheckDetailTable(areaId, areaLevel, year); + } + return new SuccessResultData<>(result); } @ApiOperation(value = "隐患上报详情表", notes = "隐患上报详情表接口") diff --git a/src/main/java/com/cm/inspection/reportform/CheckDetailTable.java b/src/main/java/com/cm/inspection/reportform/CheckDetailTable.java new file mode 100644 index 0000000..2840465 --- /dev/null +++ b/src/main/java/com/cm/inspection/reportform/CheckDetailTable.java @@ -0,0 +1,123 @@ +package com.cm.inspection.reportform; + +import com.cm.common.utils.DateUtil; +import com.cm.inspection.service.count.ICountService; +import com.cm.inspection.service.count.impl.CountServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.thymeleaf.util.StringUtils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: WorkTable + * @Description: 综合统计 + * @Author: wanggeng + * @Date: 2021/4/20 4:47 下午 + * @Version: 1.0 + */ +public class CheckDetailTable { + private static final Logger LOG = LoggerFactory.getLogger(CheckDetailTable.class); + /** + * 保存报表内容,结构为 {year:{areaId:{具体内容}}} + */ + public Map>> detailTableMap = new ConcurrentHashMap<>(); + private static CheckDetailTable checkDetailTable = CheckDetailTableBuilder.checkDetailTable; + private ICountService countService; + + private CheckDetailTable() { + } + + public static CheckDetailTable getInstance() { + return checkDetailTable; + } + + public CheckDetailTable setCountService(ICountService countService) { + this.countService = countService; + return this; + } + + /** + * 得到内容 + * + * @param year + * @param areaId + * @return + */ + public Map get(String year, String areaId) { + Map> yearMap = detailTableMap.get(year); + if (yearMap == null) { + return null; + } + areaId = StringUtils.isEmpty(areaId) ? CountServiceImpl.DEFAULT_AREA_ID : areaId; + Map areaIdMap = yearMap.get(areaId); + if (areaIdMap == null) { + return null; + } + return areaIdMap; + } + + /** + * 刷新统计内容 + */ + public void refresh() { + LOG.info("刷新综合统计,开始...."); + long startTime = System.currentTimeMillis(); + int currentYear = Integer.parseInt(DateUtil.getYear()); + for (int year = currentYear; year >= 2020; year--) { + refresh("", 3, String.valueOf(year)); + } + long endTime = System.currentTimeMillis(); + LOG.info("刷新综合统计,结束,总耗时:{}", (endTime - startTime) / 1000 + "秒"); + } + + /** + * 递归加载统计内容 + * + * @param areaId + * @param level + * @param year + */ + private void refresh(String areaId, Integer level, String year) { + Map detailMap = getData(areaId, level, year); + if (StringUtils.isEmpty(areaId)) { + areaId = CountServiceImpl.DEFAULT_AREA_ID; + } + List> resultMapList = (List>) detailMap.get("resultList"); + if (resultMapList.isEmpty()) { + return; + } + for (Map resultMap : resultMapList) { + Map> yearMap = detailTableMap.get(year); + if (yearMap == null) { + yearMap = new HashMap<>(); + detailTableMap.put(year, yearMap); + } + yearMap.put(areaId, detailMap); + String resultAreaId = (String) resultMap.get("areaId"); + refresh(resultAreaId, level + 1, year); + } + } + + /** + * 统计数据 + * + * @param areaId + * @param level + * @param year + * @return + */ + private Map getData(String areaId, Integer level, String year) { + return countService.countCheckDetailTable(areaId, level, year).getData(); + } + + private static class CheckDetailTableBuilder { + public final static CheckDetailTable checkDetailTable = new CheckDetailTable(); + } +} diff --git a/src/main/java/com/cm/inspection/service/count/impl/CountServiceImpl.java b/src/main/java/com/cm/inspection/service/count/impl/CountServiceImpl.java index 14621d8..48acb33 100644 --- a/src/main/java/com/cm/inspection/service/count/impl/CountServiceImpl.java +++ b/src/main/java/com/cm/inspection/service/count/impl/CountServiceImpl.java @@ -1,12 +1,10 @@ package com.cm.inspection.service.count.impl; -import com.cm.common.constants.ISystemConstant; import com.cm.common.exception.SearchException; import com.cm.common.plugin.pojo.dtos.datadictionary.DataDictionaryDTO; import com.cm.common.plugin.service.datadictionary.IDataDictionaryService; import com.cm.common.result.SuccessResultData; import com.cm.common.token.app.AppTokenManager; -import com.cm.common.token.app.entity.AppToken; import com.cm.common.utils.HashMapUtil; import com.cm.inspection.pojo.dtos.check.CheckDTO; import com.cm.inspection.pojo.dtos.checkitem.CheckItemDTO; @@ -28,7 +26,6 @@ import org.activiti.engine.task.Task; import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; -import org.omg.PortableInterceptor.USER_EXCEPTION; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -67,7 +64,7 @@ public class CountServiceImpl extends BaseService implements ICountService { private ICheckItemOptionService checkItemOptionService; @Autowired private ICheckItemService checkItemService; - private static final String DEFAULT_AREA_ID = "3f62e230-47a5-4ad9-ab01-08fd2c5218d8"; + public static final String DEFAULT_AREA_ID = "3f62e230-47a5-4ad9-ab01-08fd2c5218d8"; @Override public SuccessResultData> countWorkTable(String areaId, Integer areaLevel, String startDate, String endDate) throws SearchException { diff --git a/src/main/java/com/cm/inspection/startup/StartUp.java b/src/main/java/com/cm/inspection/startup/StartUp.java index 447446f..0ed9631 100644 --- a/src/main/java/com/cm/inspection/startup/StartUp.java +++ b/src/main/java/com/cm/inspection/startup/StartUp.java @@ -1,6 +1,7 @@ package com.cm.inspection.startup; import com.cm.common.utils.DateUtil; +import com.cm.inspection.reportform.CheckDetailTable; import com.cm.inspection.service.count.ICountService; import com.cm.inspection.service.dingding.IDingDingMsgService; import com.cm.inspection.service.dischargepermit.IDischargePermitService; @@ -14,9 +15,6 @@ import org.springframework.boot.ApplicationRunner; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import java.util.HashMap; -import java.util.Map; - /** * When you feel like quitting. Think about why you started * 当你想要放弃的时候,想想当初你为何开始 @@ -54,20 +52,17 @@ public class StartUp implements ApplicationRunner { processService.deployProcess("check-self", "网格员检查上报流程"); // 初始化统计,防止第一次打开慢 - Map params = new HashMap<>(); - enterpriseService.countEnterpriseByNature(params); - for (int year = currentYear; year >= startYear; year--) { - final String yearStr = String.valueOf(year); - new Thread(() -> { - try { - countService.countCheckDetailTable("", 3, yearStr); - countService.countHiddenDangerReportDetail("", 3, yearStr); - } catch (Exception e) { - e.printStackTrace(); - } - }).start(); + new Thread(() -> { + CheckDetailTable.getInstance().setCountService(countService).refresh(); + }).start(); + } - } + /** + * 每天0点和1点跑一次 + */ + @Scheduled(cron = "0 0 23 * * ?") + public void checkDetailTable() { + CheckDetailTable.getInstance().setCountService(countService).refresh(); } /** diff --git a/src/main/resources/static/route/count/list-countcheckdetailtable.html b/src/main/resources/static/route/count/list-countcheckdetailtable.html index d32da62..d01c5dd 100644 --- a/src/main/resources/static/route/count/list-countcheckdetailtable.html +++ b/src/main/resources/static/route/count/list-countcheckdetailtable.html @@ -64,18 +64,18 @@ {{item.areaName}} - {{item.enterpriseReceiveCount}} - {{item.checkPlanCount}} - {{item.checkCount}} - {{item.completeRatio}}% - {{item.needReCheck}} - {{item.countTimeoutCheck}} - {{item.countCheckHiddenDanger}} - {{item.countReCheckHiddenDanger}} - {{item.countRectification}} - {{item.countImmediatelyRectification}} - {{item.rectificationRate}}% - {{item.countUnCoordination}} + {{item.enterpriseReceiveCount ? item.enterpriseReceiveCount : 0}} + {{item.checkPlanCount ? item.checkPlanCount : 0}} + {{item.checkCount ? item.checkCount : 0}} + {{item.completeRatio ? item.completeRatio : 0}}% + {{item.needReCheck ? item.needReCheck : 0}} + {{item.countTimeoutCheck ? item.countTimeoutCheck : 0}} + {{item.countCheckHiddenDanger ? item.countCheckHiddenDanger : 0}} + {{item.countReCheckHiddenDanger ? item.countReCheckHiddenDanger : 0}} + {{item.countRectification ? item.countRectification : 0}} + {{item.countImmediatelyRectification ? item.countImmediatelyRectification : 0}} + {{item.rectificationRate ? item.rectificationRate : 0}}% + {{item.countUnCoordination ? item.countUnCoordination : 0}} {{# } }}