From 2346b115a69005e278ddae52505af61ed3407a21 Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Sat, 18 Jul 2020 19:15:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apis/count/CountController.java | 2 +- .../service/count/ICountService.java | 2 +- .../service/count/impl/CountServiceImpl.java | 165 ++++++++++++++---- 3 files changed, 135 insertions(+), 34 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 92dd2db..5b70990 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 { }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("counthiddendangerreportdetail/{year}") - public SuccessResultData> countHiddenDangerReportDetail(@PathVariable("year") String year) { + public SuccessResultData> countHiddenDangerReportDetail(@PathVariable("year") String year) throws Exception { return countService.countHiddenDangerReportDetail(year); } diff --git a/src/main/java/com/cm/inspection/service/count/ICountService.java b/src/main/java/com/cm/inspection/service/count/ICountService.java index f37c2b6..b4e6f8f 100644 --- a/src/main/java/com/cm/inspection/service/count/ICountService.java +++ b/src/main/java/com/cm/inspection/service/count/ICountService.java @@ -71,5 +71,5 @@ public interface ICountService { * @return * @throws SearchException */ - SuccessResultData> countHiddenDangerReportDetail(String year) throws SearchException; + SuccessResultData> countHiddenDangerReportDetail(String year) throws Exception; } 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 a37931c..c0bc54e 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 @@ -26,6 +26,7 @@ import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; import org.springframework.stereotype.Service; import java.math.BigDecimal; @@ -228,23 +229,26 @@ public class CountServiceImpl extends BaseService implements ICountService { } @Override - public SuccessResultData> countHiddenDangerReportDetail(String year) throws SearchException { + public SuccessResultData> countHiddenDangerReportDetail(String year) throws Exception { LOG.debug("获取三级区域"); List areaDTOs = dataDictionaryService.listDictionaryByParentId("3f62e230-47a5-4ad9-ab01-08fd2c5218d8"); // 获取检查项列表 List checkItemDTOs = listCheckItemDTO(); // 检查项详细列表 List checkItemOptionDTOs = listCheckItemOptionDTO(); - // 组合检查项 - - List> resultList = new ArrayList<>(); + // 检查结果 + List> listCheckItemOptionArea = new ArrayList<>(); for (DataDictionaryDTO areaDTO : areaDTOs) { - Map resultListMap = getHashMap(3); - resultListMap.put("areaName", areaDTO.getDictionaryName()); + Map areaMap = getHashMap(4); + areaMap.put("areaName", areaDTO.getDictionaryName()); // 网格员的Id列表 List userIdList = listGridPersonnelUserId(areaDTO.getDictionaryId()); + // 网格员的所有上报项 List listHiddenDangerReport = hiddenDangerReportService.listHiddenDangerReportSimpleByUserIdsYear(userIdList, year); + // 遍历所有的检查项 + List> listCheckItemOption = new ArrayList<>(); for (CheckItemOptionDTO checkItemOptionDTO : checkItemOptionDTOs) { + Map checkItemOptionMap = HashMapUtil.beanToMap(checkItemOptionDTO); int checkCount = 0; for (HiddenDangerReportDTO hiddenDangerReportDTO : listHiddenDangerReport) { // 检查项相同 @@ -253,43 +257,138 @@ public class CountServiceImpl extends BaseService implements ICountService { checkCount++; } } - Map checkItemOptionMap = HashMapUtil.beanToMap(checkItemOptionDTO); checkItemOptionMap.put("checkCount", checkCount); + listCheckItemOption.add(checkItemOptionMap); } + areaMap.put("listCheckItemOption", listCheckItemOption); + listCheckItemOptionArea.add(areaMap); } - return null; + // 封装结果 + // 构建检查项列表 + List> checkItemList = buildCheckItem(checkItemDTOs); + // 检查详细结果加入地区的结果列表 + List> checkItemOptionList = buildCheckItemOptionArea(checkItemOptionDTOs, listCheckItemOptionArea); + // 构建检查项详细列表,检查项、检查详细项合并 + buildCheckItemAndCheckItemOption(checkItemList, checkItemOptionList); + + // 返回结果 + Map result = getHashMap(4); + result.put("year", year); + result.put("checkItemList", checkItemList); + return new SuccessResultData<>(result); } - private List> listCheckItem(List checkItemDTOs) throws Exception { - List> checkItemMapList = new ArrayList<>(); - if (checkItemDTOs) { - return checkItemMapList; - } - // 处理一级选项 - for (CheckItemDTO checkItemDTO : checkItemDTOs) { - if (checkItemDTO.getCheckItemParentId() == null || checkItemDTO.getCheckItemParentId() == 0) { - checkItemMapList.add(HashMapUtil.beanToMap(checkItemDTO)); - } - } - // 处理二级选项 - for (Map checkItemMap : checkItemMapList) { - List> subCheckItemList = new ArrayList<>(); - for (CheckItemDTO checkItemDTO : checkItemDTOs) { - if (StringUtils.equals(checkItemMap.get("checkItemId").toString(), checkItemDTO.getCheckItemParentId())) { - subCheckItemList.add(HashMapUtil.beanToMap(checkItemDTO)); + /** + * 构建检查结果到检查项中 + * + * @param checkItemList + * @param checkItemOptionList + */ + private void buildCheckItemAndCheckItemOption(List> checkItemList, List> checkItemOptionList) { + for (Map checkItem : checkItemList) { + List> checkItemOptions = new ArrayList<>(); + for (int i = 0; i < checkItemOptionList.size(); i++) { + Map checkItemOption = checkItemOptionList.get(i); + if (StringUtils.equals(checkItem.get("checkItemId").toString(), checkItemOption.get("checkItemId").toString())) { + checkItemOptions.add(checkItemOption); + checkItemOptionList.remove(i); + i--; } } - // 处理选项 + List> subCheckItem = (List>) checkItem.get("subCheckItem"); + if (subCheckItem != null && !subCheckItem.isEmpty()) { + buildCheckItemAndCheckItemOption(subCheckItem, checkItemOptionList); + } + checkItem.put("checkItemOptions", checkItemOptions); } } - private void buildCheckItem(List checkItemDTOs) { - List> checkItemMapList = new ArrayList<>(); - for (CheckItemDTO checkItemDTO : checkItemDTOs) { - if (checkItemDTO.getCheckItemParentId() == null || StringUtils.equals(checkItemDTO.getCheckItemParentId(), "0")) { + /** + * 构建具体的检查项结果,将地区的检查结果根据检查项的不同重新构建; + * 比如说,原来的结果是地区1下面的各个检查总数的统计, + * 现在将其转换为每一个检查结果下,地区的总数统计。 + *

+ * 格式如下所示:option1中包含了[{area1: 0}, {area2: 0}]数组 + *

+ * | | area1 | area2 | area3 | area4 | area5 | + * | option1 | 0 | 0 | 0 | 0 | 0 | + * | option2 | 0 | 0 | 0 | 0 | 0 | + * | option3 | 0 | 0 | 0 | 0 | 0 | + * | option4 | 0 | 0 | 0 | 0 | 0 | + * + * @param checkItemOptionDTOs + * @param listCheckItemOptionArea + * @return + * @throws Exception + */ + private List> buildCheckItemOptionArea(List checkItemOptionDTOs, List> listCheckItemOptionArea) throws Exception { + List> checkItemOptionList = new ArrayList<>(); + for (CheckItemOptionDTO checkItemOptionDTO : checkItemOptionDTOs) { + Map checkItemOptionMap = HashMapUtil.beanToMap(checkItemOptionDTO); + List> areaList = new ArrayList<>(); + for (Map checkItemOptionArea : listCheckItemOptionArea) { + Map areaMap = getHashMap(3); + areaMap.put("areaName", checkItemOptionArea.get("areaName")); + List> checkItemOptions = (List>) checkItemOptionArea.get("listCheckItemOption"); + for (Map checkItemOption : checkItemOptions) { + if (StringUtils.equals(checkItemOptionDTO.getCheckItemOptionId(), checkItemOption.get("checkItemOptionId").toString())) { + areaMap.put("checkCount", checkItemOption.get("checkCount")); + areaList.add(areaMap); + break; + } + } + } + checkItemOptionMap.put("areaList", areaList); + checkItemOptionList.add(checkItemOptionMap); + } + return checkItemOptionList; + } + /** + * 构建检查项列表。由于检查项是动态的,不确定层级,要动态构建列表 + * + * @param checkItemDTOs + * @return + * @throws Exception + */ + private List> buildCheckItem(List checkItemDTOs) throws Exception { + // 中间变量 + Map>> tempMap = new HashMap<>(20); + for (CheckItemDTO checkItemDTO : checkItemDTOs) { + String parentId = checkItemDTO.getCheckItemParentId(); + if (StringUtils.isBlank(parentId)) { + continue; + } + List> tempList = tempMap.get(parentId); + if (tempList == null) { + tempList = new ArrayList<>(); + tempMap.put(parentId, tempList); + } + tempList.add(HashMapUtil.beanToMap(checkItemDTO)); + } + // 组合列表 + for (Map.Entry>> kv : tempMap.entrySet()) { + // 取出当前的键值 + String key = kv.getKey(); + List> value = kv.getValue(); + // 从temp找到对应的父级 + for (Map.Entry>> kv2 : tempMap.entrySet()) { + List> value2 = kv2.getValue(); + boolean find = false; + for (Map map : value2) { + // 加入父级 + if (StringUtils.equals(map.get("checkItemId").toString(), key)) { + map.put("subCheckItem", value); + find = true; + break; + } + } + if (find) { + break; + } } } + return tempMap.get("0"); } /** @@ -354,7 +453,9 @@ public class CountServiceImpl extends BaseService implements ICountService { /** * 统计隐患问题 * - * @param checkIds + * @param checkItemOptionDTOs + * @param userIdList + * @param year * @return */ private Integer countCheckHiddenDanger(List checkItemOptionDTOs, List userIdList, String year) { @@ -481,7 +582,7 @@ public class CountServiceImpl extends BaseService implements ICountService { /** * 获取检查ID列表 * - * @param userIds + * @param userIdList * @return */ private List listNeedReCheckIds(List userIdList) {