From a9f1c9efe908d5d99bfd2e30bede294c0d110995 Mon Sep 17 00:00:00 2001 From: yangwei <867012372@qq.com> Date: Fri, 28 Mar 2025 11:57:44 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=201=E3=80=81=E5=BC=80=E5=8F=91=E5=86=9C?= =?UTF-8?q?=E6=B0=B4=E9=A6=96=E9=A1=B5=E9=A2=84=E8=AD=A6=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessAlertStatisticsController.java | 23 +- .../business/domain/bo/BusinessAlertBo.java | 2 +- .../business/mapper/BusinessAlertMapper.java | 10 +- .../BusinessAlertStatisticsServiceImpl.java | 274 ++++++++++-------- .../mapper/business/BusinessAlertMapper.xml | 268 ++++++++++++++--- 5 files changed, 397 insertions(+), 180 deletions(-) diff --git a/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertStatisticsController.java b/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertStatisticsController.java index f994eba..7a0d440 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertStatisticsController.java +++ b/dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertStatisticsController.java @@ -97,22 +97,22 @@ public class BusinessAlertStatisticsController extends BaseController { } /** - * 综治管理-资规 + * 综治管理-资规/农水/环保(高发分析) * @param businessAlertBo * @return */ - @Operation(summary="综治管理-资规", description="综治管理-资规") + @Operation(summary="综治管理-资规/农水/环保(高发分析)", description="综治管理-资规/农水/环保(高发分析)") @GetMapping(value = "/comprehensive/manage") public R> comprehensiveManage(BusinessAlertBo businessAlertBo) { return R.ok(statisticsService.comprehensiveManage(businessAlertBo)); } /** - * 预警信息 + * 预警信息-资规/农水 * @param businessAlertBo * @return */ - @Operation(summary="预警信息", description="预警信息") + @Operation(summary="预警信息-资规/农水", description="预警信息-资规/农水") @GetMapping(value = "/alert/list") public R>> listAlert(BusinessAlertBo businessAlertBo) { return R.ok(businessAlertService.listAlert(businessAlertBo)); @@ -120,11 +120,11 @@ public class BusinessAlertStatisticsController extends BaseController { /** - * 综治管理-城管 + * 综治管理-城管/环保(事件处理情况) * @param businessAlertBo * @return */ - @Operation(summary="综治管理-城管", description="综治管理-城管") + @Operation(summary="综治管理-城管/环保(事件处理情况)", description="综治管理-城管/环保(事件处理情况)") @GetMapping(value = "/city/comprehensive/manage") public R>> cityComprehensiveManage(BusinessAlertBo businessAlertBo) { return R.ok(statisticsService.cityComprehensiveManage(businessAlertBo)); @@ -132,11 +132,11 @@ public class BusinessAlertStatisticsController extends BaseController { /** - * 预警信息-城管 + * 预警信息-城管/环保 * @param businessAlertBo * @return */ - @Operation(summary="预警信息-城管", description="预警信息-城管") + @Operation(summary="预警信息-城管/环保", description="预警信息-城管/环保") @GetMapping(value = "/city/alert/list") public R>> cityListAlert(BusinessAlertBo businessAlertBo) { return R.ok(businessAlertService.cityListAlert(businessAlertBo)); @@ -144,6 +144,13 @@ public class BusinessAlertStatisticsController extends BaseController { + + + + + + + //饼图显示每个月根据部门 @Operation(summary="根据月份显示预警个数", description="根据月份显示预警个数") @GetMapping(value = "/month/count") diff --git a/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java b/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java index 143dcba..8db72e8 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java +++ b/dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java @@ -252,6 +252,6 @@ public class BusinessAlertBo { /** * 时间搜索类型 1年,2月,3日 */ - private Integer dateType = 1; + private Integer dateType; } diff --git a/dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java b/dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java index 1b03b01..4f4b7bc 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java +++ b/dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java @@ -83,9 +83,15 @@ public interface BusinessAlertMapper extends BaseMapperPlus> countAiLabel(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime); - Integer countStreetAlert(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime); + List> countStreetAlert(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime,@Param("deptIdList") List deptIdList); List listAlert(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime); - Integer countStreetRateAlert(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime); + List> countStreetRateAlert(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime,@Param("deptIdList") List deptIdList); + + Map streetRateTopAlert(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime,@Param("deptIdList") List deptIdList); + + Map streetTopAlert(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime,@Param("deptIdList") List deptIdList); + + List> countLabelRateAlert(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime); } diff --git a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java index ec762de..cea17e9 100644 --- a/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java +++ b/dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java @@ -22,6 +22,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAdjusters; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -61,7 +62,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist businessAlertBo.setDeptIdList(departIdList); } - businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode())); + businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList())); List> mapList = baseMapper.listMonthAlert(businessAlertBo); return mapList.stream().map(data -> new StatObj(data.get("dateMonth") + "", data.get("total"))).collect(Collectors.toList()); @@ -71,7 +72,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist @Override public ListcountDepartAlert(BusinessAlertBo businessAlertBo) { businessAlertBo.setDeptId(String.valueOf(LoginHelper.getDeptId())); - businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode())); + businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList())); List> mapList = baseMapper.listDepartAlert(businessAlertBo); @@ -80,7 +81,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist @Override public List countMonthAlertStatus(BusinessAlertBo businessAlertBo) { - businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode())); + businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList())); List> mapList = baseMapper.listMonthAlertStatus(businessAlertBo); @@ -100,7 +101,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist @Override public List countDepartAlertStatus(BusinessAlertBo businessAlertBo) { - businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode())); + businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList())); List> mapList = baseMapper.listDepartAlertStatus(businessAlertBo); @@ -125,7 +126,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist */ @Override public List> countAlertStatusCompare(BusinessAlertBo businessAlertBo) { - businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode())); + businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList())); businessAlertBo.setDateList(buildDateList(businessAlertBo)); return baseMapper.countAlertCompare(businessAlertBo); } @@ -146,7 +147,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist businessAlertBo.setCreateTime(today.getYear()+"-"+today.getMonthValue()+"-"+today.getDayOfMonth()); - businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode())); + businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList())); } List> mapList = baseMapper.countPanelAlert(businessAlertBo); @@ -163,7 +164,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist @Override public List> countAlertTypeCompare(BusinessAlertBo businessAlertBo) { - businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode())); + businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList())); businessAlertBo.setDateList(buildDateList(businessAlertBo)); return baseMapper.countAlertTypeCompare(businessAlertBo); } @@ -177,18 +178,18 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist public Map countPanelTotalAlert(BusinessAlertBo businessAlertBo) { Map result = new HashMap<>(); if (ObjectUtil.isNotEmpty(businessAlertBo.getPostCode())){ - List labelList = getAiLabel(businessAlertBo.getPostCode()); + List labelList = getAiLabel(businessAlertBo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList()); if (ObjectUtil.isEmpty(labelList)){ - result.put("totalFinishCount", 0); + result.put("totalFinish", 0); result.put("yearTotal", 0); - result.put("yearFinishCount", 0); + result.put("yearFinish", 0); result.put("yearRate", 0); result.put("monthTotal",0); - result.put("monthFinishCount", 0); + result.put("monthFinish", 0); result.put("monthRate", 0); result.put("dayTotal", 0); - result.put("dayFinishCount", 0); + result.put("dayFinish", 0); result.put("dayTodo", 0); return result; } @@ -198,7 +199,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist // 1、2024一直到当前年份处理预警个数 Integer totalFinishCount = baseMapper.countFromOldToCurrent(businessAlertBo); - result.put("totalFinishCount", totalFinishCount); + result.put("totalFinish", totalFinishCount); //2、今年处理率 今年的预警总数 今年处理个数 Map currentYearMap = baseMapper.countCurrentAlert(businessAlertBo); // 四舍五入保留两位小数 @@ -207,7 +208,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist BigDecimal currentYearAverage = BigDecimal.valueOf((yearTotal == 0) ? 0.0 : yearFinishCount / yearTotal) .setScale(2, RoundingMode.HALF_UP); result.put("yearTotal", currentYearMap.get("total")); - result.put("yearFinishCount", currentYearMap.get("finishCount")); + result.put("yearFinish", currentYearMap.get("finishCount")); result.put("yearRate", currentYearAverage); //3、本月处理率 本月预警总数 本月处理个数 @@ -220,14 +221,14 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist .setScale(2, RoundingMode.HALF_UP); result.put("monthTotal", monthMap.get("total")); - result.put("monthFinishCount", monthMap.get("finishCount")); + result.put("monthFinish", monthMap.get("finishCount")); result.put("monthRate", currentMonthAverage); //4、今日预警总数 今日处理个数 今日未处理个数 Map dayMap = this.baseMapper.countCurrentDayAlert(businessAlertBo); result.put("dayTotal", dayMap.get("total")); - result.put("dayFinishCount", dayMap.get("finishCount")); + result.put("dayFinish", dayMap.get("finishCount")); result.put("dayTodo", dayMap.get("todoCount")); return result; @@ -243,7 +244,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist Map result = new HashMap<>(); if (ObjectUtil.isNotEmpty(businessAlertBo.getPostCode())){ - List labelList = getAiLabel(businessAlertBo.getPostCode()); + List labelList = getAiLabel(businessAlertBo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList()); if (ObjectUtil.isEmpty(labelList)){ result.put("dayTotal", 0); @@ -258,7 +259,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist Map dayMap = this.baseMapper.countCurrentDayAlert(businessAlertBo); result.put("dayTotal", dayMap.get("total")); - result.put("dayFinishCount", dayMap.get("finishCount")); + result.put("dayFinish", dayMap.get("finishCount")); result.put("dayTodo", dayMap.get("todoCount")); return result; } @@ -279,7 +280,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist } postVoList.forEach(postVo -> { - List labelList = getAiLabel(postVo.getPostCode()); + List labelList = getAiLabel(postVo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList()); businessAlertBo.setAiLabelEnList(labelList); Map dayMap = this.baseMapper.countCurrentDayAlert(businessAlertBo); result.put(postVo.getPostName(), dayMap.get("total")); @@ -304,19 +305,28 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist return ListUtil.empty(); } - List monthList = getLastSixMonths(); - String startTime = monthList.get(monthList.size() - 1); - String endTime = monthList.get(0); + String startTime; + String endTime; + + if (ObjectUtil.isEmpty(businessAlertBo.getDateType())){ + Map dateMap = getStartTimeAndEndTime(0); + startTime = dateMap.get("startTime"); + endTime = dateMap.get("endTime"); + }else { + Map dateMap = getStartTimeAndEndTime(businessAlertBo.getDateType()); + startTime = dateMap.get("startTime"); + endTime = dateMap.get("endTime"); + } postVoList.forEach(postVo -> { - List labelList = getAiLabel(postVo.getPostCode()); + List labelList = getAiLabel(postVo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList()); Map dateMap = new HashMap<>(); if (ObjectUtil.isEmpty(labelList)) { dateMap.put("todoCount",0); dateMap.put("finishCount",0); }else { businessAlertBo.setAiLabelEnList(labelList); - dateMap = baseMapper.countPastYearAlert(businessAlertBo,startTime,endTime); + dateMap = baseMapper.countPastYearAlert(businessAlertBo, startTime, endTime); } result.add(new StatObj( @@ -350,7 +360,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist statObj.setStatKey(month); List statObjs = new ArrayList<>(); postVoList.forEach(postVo -> { - List labelList = getAiLabel(postVo.getPostCode()); + List labelList = getAiLabel(postVo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList()); StatObj statObj1 = new StatObj(); statObj1.setStatKey(postVo.getPostName()); if (ObjectUtil.isEmpty(labelList)){ @@ -382,80 +392,109 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist Map result = new HashMap<>(); - List aiLabelList = getAiLabel(businessAlertBo.getPostCode()); + List labelList = getAiLabel(businessAlertBo.getPostCode()); + List aiLabelNameList = labelList.stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList()); - if (ObjectUtil.isEmpty(aiLabelList)) { + + if (ObjectUtil.isEmpty(labelList)) { return Map.of(); } - businessAlertBo.setAiLabelEnList(aiLabelList); + //-------------------------------------------------------条件构建-------------------------------------------- - List monthList = getLastSixMonths(); - String startTime = monthList.get(monthList.size() - 1); - String endTime = monthList.get(0); + businessAlertBo.setAiLabelEnList(aiLabelNameList); + String startTime = null; + String endTime = null; - List> labelMapList = this.baseMapper.countAiLabel(businessAlertBo,startTime,endTime); + if (ObjectUtil.isEmpty(businessAlertBo.getDateType())){ + Map dateMap = getStartTimeAndEndTime(0); + startTime = dateMap.get("startTime"); + endTime = dateMap.get("endTime"); + }else { + Map dateMap = getStartTimeAndEndTime(businessAlertBo.getDateType()); + startTime = dateMap.get("startTime"); + endTime = dateMap.get("endTime"); + } - Map labelMap = new HashMap<>(); - labelMapList.forEach(label -> { - labelMap.put(label.get("labelCn")+ "",label.get("total")); - }); + + //-------------------------------------------------------识别类型事件情况-------------------------------------------- + + List> labelMapList = this.baseMapper.countAiLabel(businessAlertBo,startTime,endTime); //识别类型存储 - result.put("label", labelMap); + result.put("label", labelMapList); + //-------------------------------------------------------街道事件高发区Top5-------------------------------------------- //事件高发区 Long deptId = LoginHelper.getDeptId(); //获取街道信息 List streetList = remoteDeptService.selectListByParentId(String.valueOf(deptId)); + List deptIdList = streetList.stream().map(RemoteDeptVo::getDeptId).filter(id -> !id.equals(deptId)).distinct().toList(); - Map streeMap = new HashMap<>(); - streetList.forEach(street -> { - businessAlertBo.setDeptId(String.valueOf(street.getDeptId())); - Integer alertCount = this.baseMapper.countStreetAlert(businessAlertBo,startTime,endTime); - streeMap.put(street.getDeptName(),alertCount); - }); + List> top5Map = this.baseMapper.countStreetAlert(businessAlertBo,startTime,endTime,deptIdList); - //降序排序,取前五个 - Map top5Map = streeMap.entrySet().stream() - .sorted(Map.Entry.comparingByValue().reversed()) - .limit(5) - .collect(Collectors.toMap( - Map.Entry::getKey, - Map.Entry::getValue, - (e1, e2) -> e1, - LinkedHashMap::new - )); + //街道事件高发区前5个 result.put("streetCount", top5Map); - //处理效率top5 - Map streeRateMap = new HashMap<>(); - streetList.forEach(street -> { - businessAlertBo.setDeptId(String.valueOf(street.getDeptId())); - Integer alertCount = this.baseMapper.countStreetRateAlert(businessAlertBo,startTime,endTime); - if (ObjectUtil.isEmpty(alertCount)) { - streeRateMap.put(street.getDeptName(),0); - }else { - streeRateMap.put(street.getDeptName(),alertCount); - } - }); + //-------------------------------------------------------街道处理效率Top5-------------------------------------------- - Map streeRatetop5Map = streeRateMap.entrySet().stream() - .sorted(Map.Entry.comparingByValue().reversed()) - .limit(5) - .collect(Collectors.toMap( - Map.Entry::getKey, - Map.Entry::getValue, - (e1, e2) -> e1, - LinkedHashMap::new - )); + List> streetRateTop5Map = this.baseMapper.countStreetRateAlert(businessAlertBo,startTime,endTime,deptIdList); + + //街道处理效率top5 + result.put("handlerRate", streetRateTop5Map); + + //-------------------------------------------------------识别类型事件处理情况-------------------------------------------- + //识别类型事件处理情况 + List> labelRateMap = this.baseMapper.countLabelRateAlert(businessAlertBo,startTime,endTime); + result.put("labelRate", labelRateMap); - result.put("handlerRate", streeRatetop5Map); return result; } + private Map getStartTimeAndEndTime(Integer dateType) { + Map result = new HashMap<>(); + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + switch (dateType) { + case 0: + LocalDate today = LocalDate.now(); + LocalDate startDate = today.minusMonths(6) + .with(TemporalAdjusters.firstDayOfMonth()); + + LocalDate endDate = today.with(TemporalAdjusters.lastDayOfMonth()); + + result.put("startTime",startDate.format(formatter)); + result.put("endTime",endDate.format(formatter)); + break; + case 1: // 年 + LocalDate currentDate = LocalDate.now(); + LocalDate yearStartDate = currentDate.with(TemporalAdjusters.firstDayOfYear()); + LocalDate yearEndDate = currentDate.with(TemporalAdjusters.lastDayOfYear()); + + result.put("startTime", yearStartDate.format(formatter)); + result.put("endTime", yearEndDate.format(formatter)); + break; + case 2: // 月 + LocalDate monthStartDate = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()); + LocalDate monthEndDate = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()); + + result.put("startTime", monthStartDate.format(formatter)); + result.put("endTime", monthEndDate.format(formatter)); + break; + case 3: // 日 + LocalDate dayStartDate = LocalDate.now(); + LocalDate dayEndDate = LocalDate.now(); + + result.put("startTime", dayStartDate.format(formatter)); + result.put("endTime", dayEndDate.format(formatter)); + break; + } + return result; + } + @Override public List> cityComprehensiveManage(BusinessAlertBo businessAlertBo) { if (ObjectUtil.isEmpty(businessAlertBo.getPostCode())) { @@ -464,10 +503,19 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist List> resultList = new ArrayList<>(); + //-------------------------------------------------------条件构建-------------------------------------------- + List postVoList = remoteLabelPostService.selectLabelByList(businessAlertBo.getPostCode(), LoginHelper.getDeptId()); Map> aiNameMap = postVoList.stream().collect(Collectors.groupingBy(RemoteAiLabelPostVo::getAiName)); + //事件高发区 + Long deptId = LoginHelper.getDeptId(); + //获取街道信息 + List streetList = remoteDeptService.selectListByParentId(String.valueOf(deptId)); + List deptIdList = streetList.stream().map(RemoteDeptVo::getDeptId).filter(id -> !id.equals(deptId)).distinct().toList(); + + if (ObjectUtil.isEmpty(postVoList)) { return ListUtil.empty(); } @@ -478,76 +526,52 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist Map keyMap = new HashMap<>(); + //-------------------------------------------------------事件处理情况-------------------------------------------- + List aiLabelList = aiNameMap.get(key).stream().map(RemoteAiLabelPostVo::getLabelEn).distinct().toList(); businessAlertBo.setAiLabelEnList(aiLabelList); - List monthList = getLastSixMonths(); - String startTime = monthList.get(monthList.size() - 1); - String endTime = monthList.get(0); + + String startTime = null; + String endTime = null; + + if (ObjectUtil.isEmpty(businessAlertBo.getDateType())){ + Map dateMap = getStartTimeAndEndTime(0); + startTime = dateMap.get("startTime"); + endTime = dateMap.get("endTime"); + }else { + Map dateMap = getStartTimeAndEndTime(businessAlertBo.getDateType()); + startTime = dateMap.get("startTime"); + endTime = dateMap.get("endTime"); + } List> labelMapList = this.baseMapper.countAiLabel(businessAlertBo,startTime,endTime); - Map labelMap = new HashMap<>(); - labelMapList.forEach(label -> { - labelMap.put(label.get("labelCn")+ "",label.get("total")); - }); + keyMap.put("handlerStat", labelMapList); - keyMap.put("handlerStat", labelMap); - //事件高发区 - Long deptId = LoginHelper.getDeptId(); - //获取街道信息 - List streetList = remoteDeptService.selectListByParentId(String.valueOf(deptId)); + //-------------------------------------------------------事件高发区-------------------------------------------- - Map streeMap = new HashMap<>(); - streetList.forEach(street -> { - businessAlertBo.setDeptId(String.valueOf(street.getDeptId())); - Integer alertCount = this.baseMapper.countStreetAlert(businessAlertBo,startTime,endTime); - streeMap.put(street.getDeptName(),alertCount); - }); + //事件高发区top1 + Map topStreet = this.baseMapper.streetTopAlert(businessAlertBo,startTime,endTime,deptIdList); - //降序排序,取前五个 - String topMap = streeMap.entrySet().stream() - .sorted(Map.Entry.comparingByValue().reversed()) - .limit(1) - .map(Map.Entry::getKey) - .findFirst() - .orElse(null); - - keyMap.put("topAlert",topMap); - - //处理效率top5 - Map streeRateMap = new HashMap<>(); - streetList.forEach(street -> { - businessAlertBo.setDeptId(String.valueOf(street.getDeptId())); - Integer alertCount = this.baseMapper.countStreetRateAlert(businessAlertBo,startTime,endTime); - if (ObjectUtil.isEmpty(alertCount)) { - streeRateMap.put(street.getDeptName(),0); - }else { - streeRateMap.put(street.getDeptName(),alertCount); - } - }); + keyMap.put("topAlert",ObjectUtil.isEmpty(topStreet)?null:topStreet.get("deptName")); - String topKey = streeRateMap.entrySet().stream() - .sorted(Map.Entry.comparingByValue().reversed()) - .limit(1) - .map(Map.Entry::getKey) - .findFirst() - .orElse(null); + //-------------------------------------------------------处理效率-------------------------------------------- + //处理效率top1 + Map topStreetRate = this.baseMapper.streetRateTopAlert(businessAlertBo,startTime,endTime,deptIdList); - keyMap.put("handlerRate", topKey); + keyMap.put("handlerRate", ObjectUtil.isEmpty(topStreetRate)?null:topStreetRate.get("deptName")); - //识别类型存储 + //-------------------------------------------------------存储结果-------------------------------------------- result.put(key, keyMap); - resultList.add(result); }); - return resultList; } @@ -591,7 +615,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist return resultList; } - private List getAiLabel(String postCode) { - return remoteLabelPostService.selectLabelByList(postCode,LoginHelper.getDeptId()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList()); + private List getAiLabel(String postCode) { + return remoteLabelPostService.selectLabelByList(postCode,LoginHelper.getDeptId()); } } diff --git a/dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml b/dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml index 46bdaf7..1b6bf60 100644 --- a/dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml +++ b/dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml @@ -443,8 +443,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" IFNULL(SUM( ba.handle_type = 'finish' ),0) AS finishCount from business_alert ba where 1=1 - and = #{startTime} ]]> - and + and = #{startTime} ]]> + and @@ -455,38 +455,62 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ba.label_en labelEn from business_alert ba where 1=1 - and = #{startTime} ]]> - and + and = #{startTime} ]]> + and group by ba.label_cn,ba.label_en - + WITH RECURSIVE warning_summary AS ( + SELECT + dept_id AS root_dept_id, + dept_name AS root_dept_name, + dept_id, + dept_name + FROM dk_cloud.sys_dept + WHERE dept_id IN + + #{deptId} + + UNION ALL + SELECT + dt.root_dept_id, + dt.root_dept_name, + d.dept_id, + d.dept_name + FROM dk_cloud.sys_dept d + JOIN warning_summary dt + ON d.parent_id = dt.dept_id + WHERE d.del_flag = '0' ) - and = #{startTime} ]]> - and + SELECT + root_dept_name deptName, + total + FROM ( + SELECT + dt.root_dept_id, + dt.root_dept_name, + COUNT(ba.id) total + FROM business_alert ba + JOIN warning_summary dt + ON ba.dept_id = dt.dept_id + WHERE + 1=1 + and = #{startTime} ]]> + and + GROUP BY dt.root_dept_id,dt.root_dept_name + ) dept_stats + ORDER BY total DESC + LIMIT 5; - + WITH RECURSIVE warning_summary AS ( + SELECT + dept_id AS root_dept_id, + dept_name AS root_dept_name, + dept_id, + dept_name + FROM dk_cloud.sys_dept + WHERE dept_id IN + + #{deptId} + + UNION ALL + SELECT + dt.root_dept_id, + dt.root_dept_name, + d.dept_id, + d.dept_name + FROM dk_cloud.sys_dept d + JOIN warning_summary dt + ON d.parent_id = dt.dept_id + WHERE d.del_flag = '0' + ) + SELECT + root_dept_name deptName, + avg_duration avgInfo + FROM ( + SELECT + dt.root_dept_id, + dt.root_dept_name, + ROUND( + SUM(TIMESTAMPDIFF(HOUR, ba.create_time, ba.complete_date)) + / COUNT(ba.id) + ) AS avg_duration + FROM business_alert ba + JOIN warning_summary dt + ON ba.dept_id = dt.dept_id + WHERE + 1=1 + and ba.handle_type = 'finish' + and = #{startTime} ]]> + and + + GROUP BY dt.root_dept_id,dt.root_dept_name + ) dept_stats + ORDER BY avgInfo DESC + LIMIT 5 + + + + + + + + + +