综合统计加载慢问题
This commit is contained in:
parent
1ce135f78e
commit
d995a2c91a
@ -4,9 +4,9 @@ import com.cm.common.base.AbstractController;
|
|||||||
import com.cm.common.constants.ISystemConstant;
|
import com.cm.common.constants.ISystemConstant;
|
||||||
import com.cm.common.exception.ParamsException;
|
import com.cm.common.exception.ParamsException;
|
||||||
import com.cm.common.result.ErrorResult;
|
import com.cm.common.result.ErrorResult;
|
||||||
import com.cm.common.result.SuccessResult;
|
|
||||||
import com.cm.common.result.SuccessResultData;
|
import com.cm.common.result.SuccessResultData;
|
||||||
import com.cm.common.utils.RegexUtil;
|
import com.cm.common.utils.RegexUtil;
|
||||||
|
import com.cm.inspection.reportform.CheckDetailTable;
|
||||||
import com.cm.inspection.service.check.ICheckService;
|
import com.cm.inspection.service.check.ICheckService;
|
||||||
import com.cm.inspection.service.count.ICountService;
|
import com.cm.inspection.service.count.ICountService;
|
||||||
import com.cm.inspection.service.enterprise.IEnterpriseService;
|
import com.cm.inspection.service.enterprise.IEnterpriseService;
|
||||||
@ -154,7 +154,11 @@ public class CountController extends AbstractController {
|
|||||||
public SuccessResultData<Map<String, Object>> countCheckDetailTable(@PathVariable("year") String year,
|
public SuccessResultData<Map<String, Object>> countCheckDetailTable(@PathVariable("year") String year,
|
||||||
@RequestParam(name = "areaId", required = false) String areaId,
|
@RequestParam(name = "areaId", required = false) String areaId,
|
||||||
@RequestParam(name = "areaLevel", required = false) Integer areaLevel) {
|
@RequestParam(name = "areaLevel", required = false) Integer areaLevel) {
|
||||||
return countService.countCheckDetailTable(areaId, areaLevel, year);
|
Map<String, Object> result = CheckDetailTable.getInstance().get(year, areaId);
|
||||||
|
if(result == null) {
|
||||||
|
return countService.countCheckDetailTable(areaId, areaLevel, year);
|
||||||
|
}
|
||||||
|
return new SuccessResultData<>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "隐患上报详情表", notes = "隐患上报详情表接口")
|
@ApiOperation(value = "隐患上报详情表", notes = "隐患上报详情表接口")
|
||||||
|
123
src/main/java/com/cm/inspection/reportform/CheckDetailTable.java
Normal file
123
src/main/java/com/cm/inspection/reportform/CheckDetailTable.java
Normal file
@ -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<String, Map<String, Map<String, Object>>> 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<String, Object> get(String year, String areaId) {
|
||||||
|
Map<String, Map<String, Object>> yearMap = detailTableMap.get(year);
|
||||||
|
if (yearMap == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
areaId = StringUtils.isEmpty(areaId) ? CountServiceImpl.DEFAULT_AREA_ID : areaId;
|
||||||
|
Map<String, Object> 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<String, Object> detailMap = getData(areaId, level, year);
|
||||||
|
if (StringUtils.isEmpty(areaId)) {
|
||||||
|
areaId = CountServiceImpl.DEFAULT_AREA_ID;
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> resultMapList = (List<Map<String, Object>>) detailMap.get("resultList");
|
||||||
|
if (resultMapList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Map<String, Object> resultMap : resultMapList) {
|
||||||
|
Map<String, Map<String, Object>> 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<String, Object> 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();
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,10 @@
|
|||||||
package com.cm.inspection.service.count.impl;
|
package com.cm.inspection.service.count.impl;
|
||||||
|
|
||||||
import com.cm.common.constants.ISystemConstant;
|
|
||||||
import com.cm.common.exception.SearchException;
|
import com.cm.common.exception.SearchException;
|
||||||
import com.cm.common.plugin.pojo.dtos.datadictionary.DataDictionaryDTO;
|
import com.cm.common.plugin.pojo.dtos.datadictionary.DataDictionaryDTO;
|
||||||
import com.cm.common.plugin.service.datadictionary.IDataDictionaryService;
|
import com.cm.common.plugin.service.datadictionary.IDataDictionaryService;
|
||||||
import com.cm.common.result.SuccessResultData;
|
import com.cm.common.result.SuccessResultData;
|
||||||
import com.cm.common.token.app.AppTokenManager;
|
import com.cm.common.token.app.AppTokenManager;
|
||||||
import com.cm.common.token.app.entity.AppToken;
|
|
||||||
import com.cm.common.utils.HashMapUtil;
|
import com.cm.common.utils.HashMapUtil;
|
||||||
import com.cm.inspection.pojo.dtos.check.CheckDTO;
|
import com.cm.inspection.pojo.dtos.check.CheckDTO;
|
||||||
import com.cm.inspection.pojo.dtos.checkitem.CheckItemDTO;
|
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.apache.commons.lang3.StringUtils;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.format.DateTimeFormat;
|
import org.joda.time.format.DateTimeFormat;
|
||||||
import org.omg.PortableInterceptor.USER_EXCEPTION;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -67,7 +64,7 @@ public class CountServiceImpl extends BaseService implements ICountService {
|
|||||||
private ICheckItemOptionService checkItemOptionService;
|
private ICheckItemOptionService checkItemOptionService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ICheckItemService checkItemService;
|
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
|
@Override
|
||||||
public SuccessResultData<Map<String, Object>> countWorkTable(String areaId, Integer areaLevel, String startDate, String endDate) throws SearchException {
|
public SuccessResultData<Map<String, Object>> countWorkTable(String areaId, Integer areaLevel, String startDate, String endDate) throws SearchException {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.cm.inspection.startup;
|
package com.cm.inspection.startup;
|
||||||
|
|
||||||
import com.cm.common.utils.DateUtil;
|
import com.cm.common.utils.DateUtil;
|
||||||
|
import com.cm.inspection.reportform.CheckDetailTable;
|
||||||
import com.cm.inspection.service.count.ICountService;
|
import com.cm.inspection.service.count.ICountService;
|
||||||
import com.cm.inspection.service.dingding.IDingDingMsgService;
|
import com.cm.inspection.service.dingding.IDingDingMsgService;
|
||||||
import com.cm.inspection.service.dischargepermit.IDischargePermitService;
|
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.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When you feel like quitting. Think about why you started
|
* When you feel like quitting. Think about why you started
|
||||||
* 当你想要放弃的时候,想想当初你为何开始
|
* 当你想要放弃的时候,想想当初你为何开始
|
||||||
@ -54,20 +52,17 @@ public class StartUp implements ApplicationRunner {
|
|||||||
processService.deployProcess("check-self", "网格员检查上报流程");
|
processService.deployProcess("check-self", "网格员检查上报流程");
|
||||||
|
|
||||||
// 初始化统计,防止第一次打开慢
|
// 初始化统计,防止第一次打开慢
|
||||||
Map<String, Object> params = new HashMap<>();
|
new Thread(() -> {
|
||||||
enterpriseService.countEnterpriseByNature(params);
|
CheckDetailTable.getInstance().setCountService(countService).refresh();
|
||||||
for (int year = currentYear; year >= startYear; year--) {
|
}).start();
|
||||||
final String yearStr = String.valueOf(year);
|
}
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
|
||||||
countService.countCheckDetailTable("", 3, yearStr);
|
|
||||||
countService.countHiddenDangerReportDetail("", 3, yearStr);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* 每天0点和1点跑一次
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 23 * * ?")
|
||||||
|
public void checkDetailTable() {
|
||||||
|
CheckDetailTable.getInstance().setCountService(countService).refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,18 +64,18 @@
|
|||||||
<td>
|
<td>
|
||||||
<a href="javascript:void(0);" class="area-name" data-area-id="{{item.areaId}}" data-area-name="{{item.areaName}}">{{item.areaName}} <i class="fa fa-mail-forward"></i></a>
|
<a href="javascript:void(0);" class="area-name" data-area-id="{{item.areaId}}" data-area-name="{{item.areaName}}">{{item.areaName}} <i class="fa fa-mail-forward"></i></a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{item.enterpriseReceiveCount}}</td>
|
<td>{{item.enterpriseReceiveCount ? item.enterpriseReceiveCount : 0}}</td>
|
||||||
<td>{{item.checkPlanCount}}</td>
|
<td>{{item.checkPlanCount ? item.checkPlanCount : 0}}</td>
|
||||||
<td>{{item.checkCount}}</td>
|
<td>{{item.checkCount ? item.checkCount : 0}}</td>
|
||||||
<td>{{item.completeRatio}}%</td>
|
<td>{{item.completeRatio ? item.completeRatio : 0}}%</td>
|
||||||
<td>{{item.needReCheck}}</td>
|
<td>{{item.needReCheck ? item.needReCheck : 0}}</td>
|
||||||
<td>{{item.countTimeoutCheck}}</td>
|
<td>{{item.countTimeoutCheck ? item.countTimeoutCheck : 0}}</td>
|
||||||
<td>{{item.countCheckHiddenDanger}}</td>
|
<td>{{item.countCheckHiddenDanger ? item.countCheckHiddenDanger : 0}}</td>
|
||||||
<td>{{item.countReCheckHiddenDanger}}</td>
|
<td>{{item.countReCheckHiddenDanger ? item.countReCheckHiddenDanger : 0}}</td>
|
||||||
<td>{{item.countRectification}}</td>
|
<td>{{item.countRectification ? item.countRectification : 0}}</td>
|
||||||
<td>{{item.countImmediatelyRectification}}</td>
|
<td>{{item.countImmediatelyRectification ? item.countImmediatelyRectification : 0}}</td>
|
||||||
<td>{{item.rectificationRate}}%</td>
|
<td>{{item.rectificationRate ? item.rectificationRate : 0}}%</td>
|
||||||
<td>{{item.countUnCoordination}}</td>
|
<td>{{item.countUnCoordination ? item.countUnCoordination : 0}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{# } }}
|
{{# } }}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Loading…
Reference in New Issue
Block a user