From f37142db29f7c76ead24b8f646e67fa0ca6921b7 Mon Sep 17 00:00:00 2001 From: wanggeng888 <450292408@qq.com> Date: Wed, 9 Jun 2021 17:49:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=BC=E5=90=88=E7=BB=9F=E8=AE=A1=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=A4=9A=E7=BA=BF=E7=A8=8B=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apis/count/CountController.java | 11 ++-- .../reportform/CheckDetailTable.java | 55 ++++++++++++++++++- .../service/count/impl/CountServiceImpl.java | 2 +- src/main/resources/application-test.yml | 6 +- .../count/list-countcheckdetailtable.html | 2 +- 5 files changed, 65 insertions(+), 11 deletions(-) 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 d1bfa92..225c399 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 @@ -155,7 +155,7 @@ public class CountController extends AbstractController { @RequestParam(name = "areaId", required = false) String areaId, @RequestParam(name = "areaLevel", required = false) Integer areaLevel) { Map result = CheckDetailTable.getInstance().get(year, areaId); - if(result == null) { + if (result == null) { return countService.countCheckDetailTable(areaId, areaLevel, year); } return new SuccessResultData<>(result); @@ -170,9 +170,12 @@ public class CountController extends AbstractController { @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("count-grid-check-detail-table/{year}/{areaId}/{areaLevel}") public SuccessResultData> countGridCheckDetailTable(@PathVariable("year") String year, - @PathVariable("areaId") String areaId, - @PathVariable("areaLevel") Integer areaLevel) { - Map result = countService.countGridCheckDetailTable(areaId, areaLevel, year); + @PathVariable("areaId") String areaId, + @PathVariable("areaLevel") Integer areaLevel) { + Map result = CheckDetailTable.getInstance().getGrid(year, areaId); + if (result == null) { + result = countService.countGridCheckDetailTable(areaId, areaLevel, year); + } return new SuccessResultData<>(result); } diff --git a/src/main/java/com/cm/inspection/reportform/CheckDetailTable.java b/src/main/java/com/cm/inspection/reportform/CheckDetailTable.java index 2840465..d1f8fb0 100644 --- a/src/main/java/com/cm/inspection/reportform/CheckDetailTable.java +++ b/src/main/java/com/cm/inspection/reportform/CheckDetailTable.java @@ -11,6 +11,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; /** * When you feel like quitting. Think about why you started @@ -28,7 +31,12 @@ public class CheckDetailTable { * 保存报表内容,结构为 {year:{areaId:{具体内容}}} */ public Map>> detailTableMap = new ConcurrentHashMap<>(); + /** + * 保存网格员内容,结构为 {year:{areaId:{具体内容}}} + */ + public Map>> gridDetailTableMap = new ConcurrentHashMap<>(); private static CheckDetailTable checkDetailTable = CheckDetailTableBuilder.checkDetailTable; + private ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 10, 6000L, TimeUnit.MINUTES, new LinkedBlockingQueue<>()); private ICountService countService; private CheckDetailTable() { @@ -63,6 +71,26 @@ public class CheckDetailTable { return areaIdMap; } + /** + * 得到网格员内容 + * + * @param year + * @param areaId + * @return + */ + public Map getGrid(String year, String areaId) { + Map> yearMap = gridDetailTableMap.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; + } + /** * 刷新统计内容 */ @@ -85,10 +113,10 @@ public class CheckDetailTable { * @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; } + Map detailMap = getData(areaId, level, year); List> resultMapList = (List>) detailMap.get("resultList"); if (resultMapList.isEmpty()) { return; @@ -101,7 +129,18 @@ public class CheckDetailTable { } yearMap.put(areaId, detailMap); String resultAreaId = (String) resultMap.get("areaId"); - refresh(resultAreaId, level + 1, year); + threadPoolExecutor.execute(() -> { + refresh(resultAreaId, level + 1, year); + }); + threadPoolExecutor.execute(() -> { + Map gridDetailMap = getGridData(resultAreaId, level, year); + Map> yearGridMap = gridDetailTableMap.get(year); + if (yearGridMap == null) { + yearGridMap = new HashMap<>(); + gridDetailTableMap.put(year, yearGridMap); + } + yearGridMap.put(resultAreaId, gridDetailMap); + }); } } @@ -117,6 +156,18 @@ public class CheckDetailTable { return countService.countCheckDetailTable(areaId, level, year).getData(); } + /** + * 统计网格员数据 + * + * @param areaId + * @param level + * @param year + * @return + */ + private Map getGridData(String areaId, Integer level, String year) { + return countService.countGridCheckDetailTable(areaId, level, year); + } + 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 97ef2f1..cd7bc86 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 @@ -272,7 +272,7 @@ public class CountServiceImpl extends BaseService implements ICountService { } else { params.put("area1", areaId); } - params.put("level", areaLevel); + // params.put("level", areaLevel); List> resultList = new ArrayList<>(); List gridPersonnelDTOs = gridPersonnelService.listGridPersonnel(params); for (GridPersonnelDTO gridPersonnelDTO : gridPersonnelDTOs) { diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 8048b06..cc9e14c 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -30,7 +30,7 @@ spring: password: root initial-size: 2 min-idle: 2 - max-active: 5 + max-active: 100 max-wait: 60000 time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 300000 @@ -102,9 +102,9 @@ security: api-path: user-center: ${security.oauth2.oauth-server} notice-url: http://192.168.0.103:7001/usercenter -version: 2 +version: 1 report-form: - check-detail: false + check-detail: true # 访问控制 access-control: diff --git a/src/main/resources/static/route/count/list-countcheckdetailtable.html b/src/main/resources/static/route/count/list-countcheckdetailtable.html index 313756c..4ed2bcb 100644 --- a/src/main/resources/static/route/count/list-countcheckdetailtable.html +++ b/src/main/resources/static/route/count/list-countcheckdetailtable.html @@ -161,7 +161,7 @@ var areaName = this.dataset.areaName; top.dialog.open({ url: top.restAjax.path('route/count/list-countcheckdetailtable-grid.html?areaId={areaId}&areaLevel={areaLevel}', [areaId, parseInt(areaLevel)]), - title: areaName +'本级网格员综合统计', + title: areaName +'网格员综合统计', width: '99%', height: '99%' });