Browse Source

[feat]

1、开发农水首页预警统计
pull/1/head
杨威 3 months ago
parent
commit
a9f1c9efe9
  1. 23
      dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertStatisticsController.java
  2. 2
      dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java
  3. 10
      dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java
  4. 272
      dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java
  5. 246
      dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml

23
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<Map<String,Object>> comprehensiveManage(BusinessAlertBo businessAlertBo) {
return R.ok(statisticsService.comprehensiveManage(businessAlertBo));
}
/**
* 预警信息
* 预警信息-资规/农水
* @param businessAlertBo
* @return
*/
@Operation(summary="预警信息", description="预警信息")
@Operation(summary="预警信息-资规/农水", description="预警信息-资规/农水")
@GetMapping(value = "/alert/list")
public R<List<Map<String,Object>>> 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<List<Map<String,Object>>> 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<List<Map<String,Object>>> 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")

2
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;
}

10
dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java

@ -83,9 +83,15 @@ public interface BusinessAlertMapper extends BaseMapperPlus<BusinessAlert, Busin
List<Map<String, Object>> 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<Map<String,Object>> countStreetAlert(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime,@Param("deptIdList") List<Long> deptIdList);
List<BusinessAlert> 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<Map<String,Object>> countStreetRateAlert(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime,@Param("deptIdList") List<Long> deptIdList);
Map<String, Object> streetRateTopAlert(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime,@Param("deptIdList") List<Long> deptIdList);
Map<String, Object> streetTopAlert(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime,@Param("deptIdList") List<Long> deptIdList);
List<Map<String, Object>> countLabelRateAlert(@Param("param") BusinessAlertBo businessAlertBo,@Param("startTime") String startTime,@Param("endTime") String endTime);
}

272
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<Map<String, Object>> 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 List<StatObj>countDepartAlert(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<Map<String, Object>> mapList = baseMapper.listDepartAlert(businessAlertBo);
@ -80,7 +81,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
@Override
public List<StatObj> countMonthAlertStatus(BusinessAlertBo businessAlertBo) {
businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode()));
businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList()));
List<Map<String, Object>> mapList = baseMapper.listMonthAlertStatus(businessAlertBo);
@ -100,7 +101,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
@Override
public List<StatObj> countDepartAlertStatus(BusinessAlertBo businessAlertBo) {
businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode()));
businessAlertBo.setAiLabelEnList(getAiLabel(businessAlertBo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList()));
List<Map<String, Object>> mapList = baseMapper.listDepartAlertStatus(businessAlertBo);
@ -125,7 +126,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
*/
@Override
public List<Map<String, Object>> 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<Map<String, Object>> mapList = baseMapper.countPanelAlert(businessAlertBo);
@ -163,7 +164,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
@Override
public List<Map<String, Object>> 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<String,Object> countPanelTotalAlert(BusinessAlertBo businessAlertBo) {
Map<String,Object> result = new HashMap<>();
if (ObjectUtil.isNotEmpty(businessAlertBo.getPostCode())){
List<String> labelList = getAiLabel(businessAlertBo.getPostCode());
List<String> 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<String, Object> 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<String, Object> 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<String,Object> result = new HashMap<>();
if (ObjectUtil.isNotEmpty(businessAlertBo.getPostCode())){
List<String> labelList = getAiLabel(businessAlertBo.getPostCode());
List<String> 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<String, Object> 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<String> labelList = getAiLabel(postVo.getPostCode());
List<String> labelList = getAiLabel(postVo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList());
businessAlertBo.setAiLabelEnList(labelList);
Map<String, Object> 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<String> monthList = getLastSixMonths();
String startTime = monthList.get(monthList.size() - 1);
String endTime = monthList.get(0);
String startTime;
String endTime;
if (ObjectUtil.isEmpty(businessAlertBo.getDateType())){
Map<String,String> dateMap = getStartTimeAndEndTime(0);
startTime = dateMap.get("startTime");
endTime = dateMap.get("endTime");
}else {
Map<String,String> dateMap = getStartTimeAndEndTime(businessAlertBo.getDateType());
startTime = dateMap.get("startTime");
endTime = dateMap.get("endTime");
}
postVoList.forEach(postVo -> {
List<String> labelList = getAiLabel(postVo.getPostCode());
List<String> labelList = getAiLabel(postVo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList());
Map<String, Object> 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<StatObj> statObjs = new ArrayList<>();
postVoList.forEach(postVo -> {
List<String> labelList = getAiLabel(postVo.getPostCode());
List<String> labelList = getAiLabel(postVo.getPostCode()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList());
StatObj statObj1 = new StatObj();
statObj1.setStatKey(postVo.getPostName());
if (ObjectUtil.isEmpty(labelList)){
@ -382,77 +392,106 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
Map<String,Object> result = new HashMap<>();
List<String> aiLabelList = getAiLabel(businessAlertBo.getPostCode());
List<RemoteAiLabelPostVo> labelList = getAiLabel(businessAlertBo.getPostCode());
List<String> aiLabelNameList = labelList.stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList());
if (ObjectUtil.isEmpty(aiLabelList)) {
if (ObjectUtil.isEmpty(labelList)) {
return Map.of();
}
businessAlertBo.setAiLabelEnList(aiLabelList);
//-------------------------------------------------------条件构建--------------------------------------------
List<String> monthList = getLastSixMonths();
String startTime = monthList.get(monthList.size() - 1);
String endTime = monthList.get(0);
businessAlertBo.setAiLabelEnList(aiLabelNameList);
String startTime = null;
String endTime = null;
List<Map<String,Object>> labelMapList = this.baseMapper.countAiLabel(businessAlertBo,startTime,endTime);
if (ObjectUtil.isEmpty(businessAlertBo.getDateType())){
Map<String,String> dateMap = getStartTimeAndEndTime(0);
startTime = dateMap.get("startTime");
endTime = dateMap.get("endTime");
}else {
Map<String,String> dateMap = getStartTimeAndEndTime(businessAlertBo.getDateType());
startTime = dateMap.get("startTime");
endTime = dateMap.get("endTime");
}
Map<String,Object> labelMap = new HashMap<>();
labelMapList.forEach(label -> {
labelMap.put(label.get("labelCn")+ "",label.get("total"));
});
//-------------------------------------------------------识别类型事件情况--------------------------------------------
List<Map<String,Object>> labelMapList = this.baseMapper.countAiLabel(businessAlertBo,startTime,endTime);
//识别类型存储
result.put("label", labelMap);
result.put("label", labelMapList);
//-------------------------------------------------------街道事件高发区Top5--------------------------------------------
//事件高发区
Long deptId = LoginHelper.getDeptId();
//获取街道信息
List<RemoteDeptVo> streetList = remoteDeptService.selectListByParentId(String.valueOf(deptId));
List<Long> deptIdList = streetList.stream().map(RemoteDeptVo::getDeptId).filter(id -> !id.equals(deptId)).distinct().toList();
Map<String,Integer> 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<Map<String,Object>> top5Map = this.baseMapper.countStreetAlert(businessAlertBo,startTime,endTime,deptIdList);
//降序排序,取前五个
Map<String, Integer> top5Map = streeMap.entrySet().stream()
.sorted(Map.Entry.<String, Integer>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<String,Integer> 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--------------------------------------------
List<Map<String,Object>> streetRateTop5Map = this.baseMapper.countStreetRateAlert(businessAlertBo,startTime,endTime,deptIdList);
//街道处理效率top5
result.put("handlerRate", streetRateTop5Map);
//-------------------------------------------------------识别类型事件处理情况--------------------------------------------
//识别类型事件处理情况
List<Map<String,Object>> labelRateMap = this.baseMapper.countLabelRateAlert(businessAlertBo,startTime,endTime);
result.put("labelRate", labelRateMap);
return result;
}
});
Map<String, Integer> streeRatetop5Map = streeRateMap.entrySet().stream()
.sorted(Map.Entry.<String, Integer>comparingByValue().reversed())
.limit(5)
.collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(e1, e2) -> e1,
LinkedHashMap::new
));
private Map<String, String> getStartTimeAndEndTime(Integer dateType) {
Map<String, String> result = new HashMap<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
result.put("handlerRate", streeRatetop5Map);
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;
}
@ -464,10 +503,19 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
List<Map<String,Object>> resultList = new ArrayList<>();
//-------------------------------------------------------条件构建--------------------------------------------
List<RemoteAiLabelPostVo> postVoList = remoteLabelPostService.selectLabelByList(businessAlertBo.getPostCode(), LoginHelper.getDeptId());
Map<String, List<RemoteAiLabelPostVo>> aiNameMap = postVoList.stream().collect(Collectors.groupingBy(RemoteAiLabelPostVo::getAiName));
//事件高发区
Long deptId = LoginHelper.getDeptId();
//获取街道信息
List<RemoteDeptVo> streetList = remoteDeptService.selectListByParentId(String.valueOf(deptId));
List<Long> 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<String,Object> keyMap = new HashMap<>();
//-------------------------------------------------------事件处理情况--------------------------------------------
List<String> aiLabelList = aiNameMap.get(key).stream().map(RemoteAiLabelPostVo::getLabelEn).distinct().toList();
businessAlertBo.setAiLabelEnList(aiLabelList);
List<String> 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<String,String> dateMap = getStartTimeAndEndTime(0);
startTime = dateMap.get("startTime");
endTime = dateMap.get("endTime");
}else {
Map<String,String> dateMap = getStartTimeAndEndTime(businessAlertBo.getDateType());
startTime = dateMap.get("startTime");
endTime = dateMap.get("endTime");
}
List<Map<String,Object>> labelMapList = this.baseMapper.countAiLabel(businessAlertBo,startTime,endTime);
Map<String,Object> 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<RemoteDeptVo> streetList = remoteDeptService.selectListByParentId(String.valueOf(deptId));
//-------------------------------------------------------事件高发区--------------------------------------------
Map<String,Integer> 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<String,Object> topStreet = this.baseMapper.streetTopAlert(businessAlertBo,startTime,endTime,deptIdList);
//降序排序,取前五个
String topMap = streeMap.entrySet().stream()
.sorted(Map.Entry.<String, Integer>comparingByValue().reversed())
.limit(1)
.map(Map.Entry::getKey)
.findFirst()
.orElse(null);
keyMap.put("topAlert",topMap);
//处理效率top5
Map<String,Integer> 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.<String, Integer>comparingByValue().reversed())
.limit(1)
.map(Map.Entry::getKey)
.findFirst()
.orElse(null);
//-------------------------------------------------------处理效率--------------------------------------------
//处理效率top1
Map<String,Object> 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<String> getAiLabel(String postCode) {
return remoteLabelPostService.selectLabelByList(postCode,LoginHelper.getDeptId()).stream().map(RemoteAiLabelPostVo::getLabelEn).collect(Collectors.toList());
private List<RemoteAiLabelPostVo> getAiLabel(String postCode) {
return remoteLabelPostService.selectLabelByList(postCode,LoginHelper.getDeptId());
}
}

246
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 <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m') >= #{startTime} ]]>
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m') <= #{endTime} ]]>
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') >= #{startTime} ]]>
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') <= #{endTime} ]]>
<include refid="searchSql"></include>
</select>
@ -455,38 +455,62 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ba.label_en labelEn
from business_alert ba
where 1=1
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m') >= #{startTime} ]]>
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m') <= #{endTime} ]]>
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') >= #{startTime} ]]>
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') <= #{endTime} ]]>
<include refid="searchSql"></include>
group by ba.label_cn,ba.label_en
</select>
<select id="countStreetAlert" resultType="java.lang.Integer">
SELECT COUNT(DISTINCT ba.id) AS total
FROM business_alert ba
WHERE 1=1
and ba.dept_id IN (
<select id="countStreetAlert" resultType="java.util.Map">
WITH RECURSIVE warning_summary AS (
SELECT dept_id
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 = #{param.deptId}
WHERE dept_id IN
<foreach collection="deptIdList" item="deptId" open="(" separator="," close=")">
#{deptId}
</foreach>
UNION ALL
SELECT d.dept_id
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
JOIN warning_summary dt
ON d.parent_id = dt.dept_id
WHERE d.del_flag = '0'
)
SELECT dept_id
FROM warning_summary
)
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m') >= #{startTime} ]]>
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m') <= #{endTime} ]]>
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 <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') >= #{startTime} ]]>
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') <= #{endTime} ]]>
<include refid="searchSql"></include>
GROUP BY dt.root_dept_id,dt.root_dept_name
) dept_stats
ORDER BY total DESC
LIMIT 5;
</select>
<select id="listAlert" resultType="org.dromara.business.domain.BusinessAlert">
select
ba.*,
ba.label_en labelEn,
ba.label_cn labelCn,
ba.create_time createTime
b.flow_status flowStatus,
b.business_id businessId,
b.id instanceId
@ -499,28 +523,184 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by ba.create_time desc
</select>
<select id="countStreetRateAlert" resultType="java.lang.Integer">
select
ROUND(SUM(TIMESTAMPDIFF(HOUR, ba.create_time, ba.complete_date)) / COUNT(*)) AS avgInfo
from business_alert ba
WHERE 1=1
and ba.dept_id IN (
<select id="countStreetRateAlert" resultType="java.util.Map">
WITH RECURSIVE warning_summary AS (
SELECT dept_id
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 = #{param.deptId}
WHERE dept_id IN
<foreach collection="deptIdList" item="deptId" open="(" separator="," close=")">
#{deptId}
</foreach>
UNION ALL
SELECT d.dept_id
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
JOIN warning_summary dt
ON d.parent_id = dt.dept_id
WHERE d.del_flag = '0'
)
SELECT dept_id
FROM warning_summary
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 <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') >= #{startTime} ]]>
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') <= #{endTime} ]]>
<include refid="searchSql"></include>
GROUP BY dt.root_dept_id,dt.root_dept_name
) dept_stats
ORDER BY avgInfo DESC
LIMIT 5
</select>
<select id="streetRateTopAlert" resultType="java.util.Map">
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
<foreach collection="deptIdList" item="deptId" open="(" separator="," close=")">
#{deptId}
</foreach>
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_id deptId,
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 <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') >= #{startTime} ]]>
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') <= #{endTime} ]]>
<include refid="searchSql"></include>
GROUP BY dt.root_dept_id,dt.root_dept_name
) dept_stats
ORDER BY avgInfo DESC
LIMIT 1
</select>
<select id="streetTopAlert" resultType="java.util.Map">
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
<foreach collection="deptIdList" item="deptId" open="(" separator="," close=")">
#{deptId}
</foreach>
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 <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m') >= #{startTime} ]]>
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m') <= #{endTime} ]]>
SELECT
root_dept_id deptId,
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 <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') >= #{startTime} ]]>
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') <= #{endTime} ]]>
<include refid="searchSql"></include>
GROUP BY dt.root_dept_id,dt.root_dept_name
) dept_stats
ORDER BY total DESC
LIMIT 1;
</select>
<select id="countLabelRateAlert" resultType="java.util.Map">
WITH warning_summary AS (
SELECT al.label_cn, al.label_en FROM dk_cloud.ai_label al WHERE al.label_en IN
<foreach collection="param.aiLabelEnList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
)
SELECT
label_cn AS labelCn,
label_en AS labelEn,
avg_duration AS avgInfo
FROM (
SELECT
dt.label_cn,
dt.label_en,
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.label_en = dt.label_en
WHERE 1=1
and ba.handle_type = 'finish'
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') >= #{startTime} ]]>
and <![CDATA[ DATE_FORMAT(ba.create_time, '%Y-%m-%d') <= #{endTime} ]]>
<include refid="searchSql"></include>
GROUP BY dt.label_en, dt.label_cn
) label_stats
ORDER BY avgInfo DESC
</select>
</mapper>

Loading…
Cancel
Save