Browse Source

[feat]

1、优化预警统计
杨威 3 months ago
parent
commit
919f31f10c
  1. 5
      dk-api/api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowService.java
  2. 18
      dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertStatisticsController.java
  3. 2
      dk-modules/business/src/main/java/org/dromara/business/domain/BusinessTask.java
  4. 2
      dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java
  5. 4
      dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java
  6. 2
      dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertStatisticsService.java
  7. 66
      dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java
  8. 24
      dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java
  9. 77
      dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml

5
dk-api/api-workflow/src/main/java/org/dromara/workflow/api/RemoteWorkflowService.java

@ -126,6 +126,11 @@ public interface RemoteWorkflowService {
*/
List<RemoteUserVo> currentTaskAllUser(Long taskId);
/**
* 根据岗位code拿到预警流程编码
* @param postCode
* @return
*/
String getFlowCode(String postCode);
}

18
dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertStatisticsController.java

@ -101,7 +101,7 @@ public class BusinessAlertStatisticsController extends BaseController {
* @param businessAlertBo
* @return
*/
@Operation(summary="综治管理-资规/农水/环保(高发分析)/住建(高发分析)", description="综治管理-资规/农水/环保(高发分析)/住建(高发分析)")
@Operation(summary="综治管理-资规/农水/环保(高发分析)/住建(高发分析)(参数:postCode)", description="综治管理-资规/农水/环保(高发分析)/住建(高发分析)")
@GetMapping(value = "/comprehensive/manage")
public R<Map<String,Object>> comprehensiveManage(BusinessAlertBo businessAlertBo) {
return R.ok(statisticsService.comprehensiveManage(businessAlertBo));
@ -114,7 +114,7 @@ public class BusinessAlertStatisticsController extends BaseController {
*/
@Operation(summary="预警信息-资规/农水", description="预警信息-资规/农水")
@GetMapping(value = "/alert/list")
public R<List<Map<String,Object>>> listAlert(BusinessAlertBo businessAlertBo) {
public R<Map<String,Object>> listAlert(BusinessAlertBo businessAlertBo) {
return R.ok(businessAlertService.listAlert(businessAlertBo));
}
@ -124,9 +124,9 @@ public class BusinessAlertStatisticsController extends BaseController {
* @param businessAlertBo
* @return
*/
@Operation(summary="综治管理-城管/环保(事件处理情况)/住建(事件处理情况)", description="综治管理-城管/环保(事件处理情况)/住建(事件处理情况)")
@Operation(summary="综治管理-城管/环保(事件处理情况)/住建(事件处理情况)(参数:postCode、aiName)", description="综治管理-城管/环保(事件处理情况)/住建(事件处理情况)")
@GetMapping(value = "/city/comprehensive/manage")
public R<List<Map<String,Object>>> cityComprehensiveManage(BusinessAlertBo businessAlertBo) {
public R<Map<String,Object>> cityComprehensiveManage(BusinessAlertBo businessAlertBo) {
return R.ok(statisticsService.cityComprehensiveManage(businessAlertBo));
}
@ -138,19 +138,11 @@ public class BusinessAlertStatisticsController extends BaseController {
*/
@Operation(summary="预警信息-城管/环保/住建", description="预警信息-城管/环保/住建")
@GetMapping(value = "/city/alert/list")
public R<List<Map<String,Object>>> cityListAlert(BusinessAlertBo businessAlertBo) {
public R<Map<String, Object>> cityListAlert(BusinessAlertBo businessAlertBo) {
return R.ok(businessAlertService.cityListAlert(businessAlertBo));
}
//饼图显示每个月根据部门
@Operation(summary="根据月份显示预警个数", description="根据月份显示预警个数")
@GetMapping(value = "/month/count")

2
dk-modules/business/src/main/java/org/dromara/business/domain/BusinessTask.java

@ -63,7 +63,7 @@ public class BusinessTask extends BaseEntity {
private String deptName;
private String waylineId;
private String fileName;
private String waylineName;
private String jobName;
private String jobId;

2
dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java

@ -239,4 +239,6 @@ public class BusinessAlertBo {
private String endTime;
private String aiName;
}

4
dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java

@ -70,9 +70,9 @@ public interface IBusinessAlertService {
TableDataInfo<BusinessAlert> getInfo(BusinessAlertBo bo, PageQuery pageQuery, String alertCode);
List<Map<String,Object>> listAlert(BusinessAlertBo businessAlertBo);
Map<String,Object> listAlert(BusinessAlertBo businessAlertBo);
List<Map<String, Object>> cityListAlert(BusinessAlertBo businessAlertBo);
Map<String, Object> cityListAlert(BusinessAlertBo businessAlertBo);
List<BusinessAlertVo> listVerifyAlert(RemoteBusinessAlertBo businessAlertBo);

2
dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertStatisticsService.java

@ -34,5 +34,5 @@ public interface IBusinessAlertStatisticsService {
Map<String, Object> comprehensiveManage(BusinessAlertBo businessAlertBo);
List<Map<String,Object>> cityComprehensiveManage(BusinessAlertBo businessAlertBo);
Map<String,Object> cityComprehensiveManage(BusinessAlertBo businessAlertBo);
}

66
dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java

@ -1,6 +1,7 @@
package org.dromara.business.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -318,36 +319,24 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
@Override
public List<Map<String,Object>> listAlert(BusinessAlertBo businessAlertBo) {
List<Map<String,Object>> resultList = new ArrayList<>();
public Map<String,Object> listAlert(BusinessAlertBo businessAlertBo) {
Map<String,Object> result = new HashMap<>();
//生成近一周开始时间、结束时间
List<String> dayList = getLastSixDays();
String startTime = dayList.get(dayList.size() - 1);
String endTime = dayList.get(0);
//查看的是总览的预警信息
if (ObjectUtil.isEmpty(businessAlertBo.getPostCode())) {
Map<String,Object> result = new HashMap<>();
result.put("date", startTime + "~" + endTime);
//查看的是总览的预警信息
if (ObjectUtil.isEmpty(businessAlertBo.getPostCode())) {
result.put("list",this.baseMapper.listAlert(businessAlertBo,startTime,endTime));
resultList.add(result);
return resultList;
return result;
}
//不是空的话查看是对应各局的
List<RemoteAiLabelPostVo> postVoList = remoteLablePostService.selectLabelByList(businessAlertBo.getPostCode(), LoginHelper.getDeptId());
postVoList.forEach(postVo -> {
Map<String,Object> labelResult = new HashMap<>();
Map<String,Object> result = new HashMap<>();
businessAlertBo.setAiLabelEnList(List.of(postVo.getLabelEn()));
businessAlertBo.setAiLabelEnList(List.of(businessAlertBo.getLabelEn()));
Map<String,Object> handlerMap = new HashMap<>();
@ -362,27 +351,24 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
result.put("list",alertList);
result.put("date", startTime + "~" + endTime);
labelResult.put(postVo.getLabelCn(),result);
resultList.add(labelResult);
});
return resultList;
return result;
}
@Override
public List<Map<String, Object>> cityListAlert(BusinessAlertBo businessAlertBo) {
List<Map<String,Object>> resultList = new ArrayList<>();
public Map<String, Object> cityListAlert(BusinessAlertBo businessAlertBo) {
if (ObjectUtil.hasEmpty(businessAlertBo.getPostCode(),businessAlertBo.getAiName())) {
throw new ServiceException("参数为空!");
}
Map<String,Object> infoMap = new HashMap<>();
//生成近一周开始时间、结束时间
List<String> dayList = getLastSixDays();
String startTime = dayList.get(dayList.size() - 1);
String endTime = dayList.get(0);
infoMap.put("date", startTime + "~" + endTime);
//不是空的话查看是对应各局的
List<RemoteAiLabelPostVo> postVoList = remoteLablePostService.selectLabelByList(businessAlertBo.getPostCode(), LoginHelper.getDeptId());
@ -390,21 +376,21 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
Map<String, List<RemoteAiLabelPostVo>> aiNameMap = postVoList.stream().collect(Collectors.groupingBy(RemoteAiLabelPostVo::getAiName));
if (ObjectUtil.isEmpty(postVoList)){
return resultList;
}
infoMap.put("panel",Map.of());
aiNameMap.keySet().forEach(key -> {
Map<String,Object> result = new HashMap<>();
infoMap.put("list", ListUtil.empty());
return infoMap;
}
Map<String,Object> infoMap = new HashMap<>();
businessAlertBo.setAiLabelEnList(aiNameMap.get(key).stream().map(RemoteAiLabelPostVo::getLabelEn).distinct().toList());
businessAlertBo.setAiLabelEnList(aiNameMap.get(businessAlertBo.getAiName()).stream().map(RemoteAiLabelPostVo::getLabelEn).distinct().toList());
List<BusinessAlert> alertList = this.baseMapper.listAlert(businessAlertBo, startTime, endTime);
Map<String, Integer> labelCnMap = alertList.stream()
.collect(Collectors.groupingBy(
BusinessAlert::getLabelCn,
BusinessAlert::getLabelEn,
Collectors.summingInt(e -> 1)
));
@ -412,14 +398,8 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
infoMap.put("list",alertList);
infoMap.put("date", startTime + "~" + endTime);
result.put(key,infoMap);
resultList.add(result);
});
return resultList;
return infoMap;
}
@Override

24
dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java

@ -29,7 +29,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.dromara.common.core.constant.Constants.FLY_ACC_TIME;
import static org.dromara.common.core.constant.Constants.FLY_COUNT;
@ -579,13 +578,11 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
}
@Override
public List<Map<String,Object>> cityComprehensiveManage(BusinessAlertBo businessAlertBo) {
if (ObjectUtil.isEmpty(businessAlertBo.getPostCode())) {
throw new ServiceException("【postCode】 岗位编码为空!");
public Map<String,Object> cityComprehensiveManage(BusinessAlertBo businessAlertBo) {
if (ObjectUtil.hasEmpty(businessAlertBo.getPostCode(),businessAlertBo.getAiName())) {
throw new ServiceException("【参数为空!】");
}
List<Map<String,Object>> resultList = new ArrayList<>();
//-------------------------------------------------------条件构建--------------------------------------------
List<RemoteAiLabelPostVo> postVoList = remoteLabelPostService.selectLabelByList(businessAlertBo.getPostCode(), LoginHelper.getDeptId());
@ -600,18 +597,15 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
if (ObjectUtil.isEmpty(postVoList)) {
return ListUtil.empty();
return Map.of();
}
aiNameMap.keySet().forEach(key -> {
Map<String,Object> result = new HashMap<>();
Map<String,Object> keyMap = new HashMap<>();
//-------------------------------------------------------事件处理情况--------------------------------------------
List<String> aiLabelList = aiNameMap.get(key).stream().map(RemoteAiLabelPostVo::getLabelEn).distinct().toList();
List<String> aiLabelList = aiNameMap.get(businessAlertBo.getAiName()).stream().map(RemoteAiLabelPostVo::getLabelEn).distinct().toList();
businessAlertBo.setAiLabelEnList(aiLabelList);
@ -655,13 +649,7 @@ public class BusinessAlertStatisticsServiceImpl implements IBusinessAlertStatist
keyMap.put("handlerRateTop1", ObjectUtil.isEmpty(topStreetRate)?null:topStreetRate.get("deptName"));
//-------------------------------------------------------存储结果--------------------------------------------
result.put(key, keyMap);
resultList.add(result);
});
return resultList;
return keyMap;
}
/**

77
dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml

@ -30,7 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
b.business_id businessId,
b.id instanceId
from dk_business.business_alert ba
left join dk_workflow.flow_instance b on ba.id = b.business_id) t
INNER join dk_workflow.flow_instance b on ba.id = b.business_id) t
${ew.getCustomSqlSegment}
</select>
@ -461,16 +461,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="countAiLabel" resultType="java.util.Map">
select
COUNT(DISTINCT ba.id) AS total,
ba.label_cn labelCn,
ba.label_en labelEn
from business_alert ba
where 1=1
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
ws.label_cn AS labelCn,
ws.label_en AS labelEn,
COALESCE(COUNT(DISTINCT ba.id), 0) AS total
FROM
warning_summary ws
LEFT JOIN business_alert ba ON ws.label_en = ba.label_en
WHERE
1=1
and ba.handle_type != 'verify'
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
and ws.label_en in
<foreach collection="param.aiLabelEnList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
GROUP BY
ws.label_cn,
ws.label_en
</select>
<select id="countStreetAlert" resultType="java.util.Map">
@ -687,34 +703,39 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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
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
ws.label_cn AS labelCn,
ws.label_en AS labelEn,
COALESCE(ROUND(
SUM(
TIMESTAMPDIFF(HOUR, ba.create_time, ba.complete_date)
) / COUNT(ba.id)
), 0) AS avgInfo
FROM
warning_summary ws
LEFT JOIN business_alert ba ON ws.label_en = ba.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
GROUP BY
ws.label_en,
ws.label_cn
ORDER BY
avgInfo DESC
</select>

Loading…
Cancel
Save