Просмотр исходного кода

- 添加 预警信息-接警效率 接口

Kazerin 1 месяц назад
Родитель
Сommit
b23db57124

+ 163 - 0
pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/warning/EarlyWarningReceiveEfficiencyController.java

@@ -0,0 +1,163 @@
+package com.zksy.web.controller.warning;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.zksy.base.warning.service.IEarlyWarningReceiveEfficiencyService;
+import com.zksy.common.core.domain.AjaxResult;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.web.bind.annotation.*;
+
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 预警统计-接警效率分析接口
+ */
+@RestController
+@RequestMapping("/warning/receiveEfficiency")
+@Api(tags = "预警信息-接警效率统计模块")
+public class EarlyWarningReceiveEfficiencyController {
+
+    private static final Logger log = LoggerFactory.getLogger(EarlyWarningReceiveEfficiencyController.class);
+
+    @Autowired
+    private IEarlyWarningReceiveEfficiencyService receiveEfficiencyService;
+
+    @GetMapping("/overview")
+    @ApiOperation(value = "接警效率概览统计", notes = "返回平均、最长、最短接警时长及接警总数核心指标")
+    @ApiResponses({
+            @ApiResponse(code = 200, message = "统计成功", response = AjaxResult.class),
+            @ApiResponse(code = 500, message = "统计异常", response = AjaxResult.class)
+    })
+    public AjaxResult getOverview(
+            @ApiParam(value = "发布开始时间 yyyy-MM-dd HH:mm:ss", example = "2026-01-01 00:00:00")
+            @RequestParam(required = false)
+            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
+
+            @ApiParam(value = "发布结束时间 yyyy-MM-dd HH:mm:ss", example = "2026-06-01 23:59:59")
+            @RequestParam(required = false)
+            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime,
+
+            @ApiParam(value = "预警类型", example = "压力预警")
+            @RequestParam(required = false) String warningType,
+
+            @ApiParam(value = "预警专项", example = "供水管网专项")
+            @RequestParam(required = false) String warningSpecial,
+
+            @ApiParam(value = "处置状态", example = "HANDLED")
+            @RequestParam(required = false) String status) {
+        try {
+            Map<String, Object> result = receiveEfficiencyService.getEfficiencyOverview(
+                    startTime, endTime, warningType, warningSpecial, status);
+            return AjaxResult.success("概览统计查询成功", result);
+        } catch (Exception e) {
+            log.error("接警效率概览统计异常", e);
+            return AjaxResult.error("统计失败:" + e.getMessage());
+        }
+    }
+
+    @GetMapping("/range")
+    @ApiOperation(value = "接警时效区间分布", notes = "按响应时长区间统计预警数量,适配柱状图展示")
+    @ApiResponses({
+            @ApiResponse(code = 200, message = "统计成功", response = AjaxResult.class),
+            @ApiResponse(code = 500, message = "统计异常", response = AjaxResult.class)
+    })
+    public AjaxResult getRange(
+            @ApiParam(value = "发布开始时间 yyyy-MM-dd HH:mm:ss", example = "2026-01-01 00:00:00")
+            @RequestParam(required = false)
+            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
+
+            @ApiParam(value = "发布结束时间 yyyy-MM-dd HH:mm:ss", example = "2026-06-01 23:59:59")
+            @RequestParam(required = false)
+            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime,
+
+            @ApiParam(value = "预警类型", example = "压力预警")
+            @RequestParam(required = false) String warningType,
+
+            @ApiParam(value = "预警专项", example = "供水管网专项")
+            @RequestParam(required = false) String warningSpecial,
+
+            @ApiParam(value = "处置状态", example = "HANDLED")
+            @RequestParam(required = false) String status) {
+        try {
+            List<Map<String, Object>> result = receiveEfficiencyService.getEfficiencyRange(
+                    startTime, endTime, warningType, warningSpecial, status);
+            return AjaxResult.success("区间分布统计查询成功", result);
+        } catch (Exception e) {
+            log.error("接警时效区间统计异常", e);
+            return AjaxResult.error("统计失败:" + e.getMessage());
+        }
+    }
+
+    @GetMapping("/type")
+    @ApiOperation(value = "按类型接警统计接警效率", notes = "按预警类型维度统计平均接警时长,从高到低排序")
+    @ApiResponses({
+            @ApiResponse(code = 200, message = "统计成功", response = AjaxResult.class),
+            @ApiResponse(code = 500, message = "统计异常", response = AjaxResult.class)
+    })
+    public AjaxResult getByType(
+            @ApiParam(value = "发布开始时间 yyyy-MM-dd HH:mm:ss", example = "2026-01-01 00:00:00")
+            @RequestParam(required = false)
+            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
+
+            @ApiParam(value = "发布结束时间 yyyy-MM-dd HH:mm:ss", example = "2026-06-01 23:59:59")
+            @RequestParam(required = false)
+            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime) {
+        try {
+            List<Map<String, Object>> result = receiveEfficiencyService.getEfficiencyByType(startTime, endTime);
+            return AjaxResult.success("类型维度统计查询成功", result);
+        } catch (Exception e) {
+            log.error("按类型统计接警效率异常", e);
+            return AjaxResult.error("统计失败:" + e.getMessage());
+        }
+    }
+
+    @GetMapping("/page")
+    @ApiOperation(value = "接警时效明细列表", notes = "分页查询预警接警时效明细,支持按时长排序,定位低效响应案例")
+    @ApiResponses({
+            @ApiResponse(code = 200, message = "查询成功", response = AjaxResult.class),
+            @ApiResponse(code = 500, message = "查询异常", response = AjaxResult.class)
+    })
+    public AjaxResult queryPage(
+            @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer pageNum,
+            @ApiParam(value = "每页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer pageSize,
+
+            @ApiParam(value = "发布开始时间 yyyy-MM-dd HH:mm:ss", example = "2026-01-01 00:00:00")
+            @RequestParam(required = false)
+            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
+
+            @ApiParam(value = "发布结束时间 yyyy-MM-dd HH:mm:ss", example = "2026-06-01 23:59:59")
+            @RequestParam(required = false)
+            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime,
+
+            @ApiParam(value = "预警类型", example = "压力预警")
+            @RequestParam(required = false) String warningType,
+
+            @ApiParam(value = "预警专项", example = "供水管网专项")
+            @RequestParam(required = false) String warningSpecial,
+
+            @ApiParam(value = "处置状态", example = "HANDLED")
+            @RequestParam(required = false) String status,
+
+            @ApiParam(value = "排序方式", allowableValues = "asc,desc", example = "desc")
+            @RequestParam(defaultValue = "desc") String sortType) {
+        try {
+            Page<Map<String, Object>> page = new Page<>(pageNum, pageSize);
+            IPage<Map<String, Object>> resultPage = receiveEfficiencyService.queryEfficiencyPage(
+                    page, startTime, endTime, warningType, warningSpecial, status, sortType);
+            return AjaxResult.success("明细查询成功", resultPage);
+        } catch (Exception e) {
+            log.error("接警时效明细查询异常", e);
+            return AjaxResult.error("查询失败:" + e.getMessage());
+        }
+    }
+}

+ 60 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/warning/mapper/EarlyWarningMapper.java

@@ -121,4 +121,64 @@ public interface EarlyWarningMapper extends BaseMapper<EarlyWarning> {
             @Param("endTime") LocalDateTime endTime,
             @Param("warningSpecial") String warningSpecial,
             @Param("sortType") String sortType);
+
+    /**
+     * 接警效率分析-概览指标统计
+     * @param startTime 发布开始时间
+     * @param endTime 发布结束时间
+     * @param warningType 预警类型(可选)
+     * @param warningSpecial 预警专项(可选)
+     * @param status 处置状态(可选)
+     * @return 平均/最长/最短接警时长 + 接警总数
+     */
+    Map<String, Object> selectReceiveEfficiencyOverview(
+            @Param("startTime") LocalDateTime startTime,
+            @Param("endTime") LocalDateTime endTime,
+            @Param("warningType") String warningType,
+            @Param("warningSpecial") String warningSpecial,
+            @Param("status") String status);
+
+    /**
+     * 接警效率分析-时效区间分布统计
+     * @param startTime 发布开始时间
+     * @param endTime 发布结束时间
+     * @param warningType 预警类型(可选)
+     * @param warningSpecial 预警专项(可选)
+     * @param status 处置状态(可选)
+     * @return 各时长区间预警数量
+     */
+    List<Map<String, Object>> selectReceiveEfficiencyRange(
+            @Param("startTime") LocalDateTime startTime,
+            @Param("endTime") LocalDateTime endTime,
+            @Param("warningType") String warningType,
+            @Param("warningSpecial") String warningSpecial,
+            @Param("status") String status);
+
+    /**
+     * 接警效率分析-按预警类型统计平均时效
+     * @param startTime 发布开始时间
+     * @param endTime 发布结束时间
+     * @return 各类型平均接警时长、数量
+     */
+    List<Map<String, Object>> selectReceiveEfficiencyByType(
+            @Param("startTime") LocalDateTime startTime,
+            @Param("endTime") LocalDateTime endTime);
+
+    /**
+     * 接警效率分析-明细列表
+     * @param startTime 发布开始时间
+     * @param endTime 发布结束时间
+     * @param warningType 预警类型(可选)
+     * @param warningSpecial 预警专项(可选)
+     * @param status 处置状态(可选)
+     * @param sortType 排序方式 asc-时效从短到长 desc-时效从长到短
+     * @return 预警接警时效明细
+     */
+    List<Map<String, Object>> selectReceiveEfficiencyList(
+            @Param("startTime") LocalDateTime startTime,
+            @Param("endTime") LocalDateTime endTime,
+            @Param("warningType") String warningType,
+            @Param("warningSpecial") String warningSpecial,
+            @Param("status") String status,
+            @Param("sortType") String sortType);
 }

+ 45 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/warning/service/IEarlyWarningReceiveEfficiencyService.java

@@ -0,0 +1,45 @@
+package com.zksy.base.warning.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Map;
+
+public interface IEarlyWarningReceiveEfficiencyService {
+
+    /**
+     * 获取接警效率概览指标
+     */
+    Map<String, Object> getEfficiencyOverview(LocalDateTime startTime,
+                                              LocalDateTime endTime,
+                                              String warningType,
+                                              String warningSpecial,
+                                              String status);
+
+    /**
+     * 获取接警时效区间分布
+     */
+    List<Map<String, Object>> getEfficiencyRange(LocalDateTime startTime,
+                                                 LocalDateTime endTime,
+                                                 String warningType,
+                                                 String warningSpecial,
+                                                 String status);
+
+    /**
+     * 按预警类型统计平均接警时效
+     */
+    List<Map<String, Object>> getEfficiencyByType(LocalDateTime startTime, LocalDateTime endTime);
+
+    /**
+     * 分页查询接警时效明细列表
+     */
+    IPage<Map<String, Object>> queryEfficiencyPage(Page<Map<String, Object>> page,
+                                                   LocalDateTime startTime,
+                                                   LocalDateTime endTime,
+                                                   String warningType,
+                                                   String warningSpecial,
+                                                   String status,
+                                                   String sortType);
+}

+ 57 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/warning/service/impl/EarlyWarningReceiveEfficiencyServiceImpl.java

@@ -0,0 +1,57 @@
+package com.zksy.base.warning.service.impl;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.zksy.base.warning.mapper.EarlyWarningMapper;
+import com.zksy.base.warning.service.IEarlyWarningReceiveEfficiencyService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class EarlyWarningReceiveEfficiencyServiceImpl implements IEarlyWarningReceiveEfficiencyService {
+
+    @Autowired
+    private EarlyWarningMapper earlyWarningMapper;
+
+    @Override
+    public Map<String, Object> getEfficiencyOverview(LocalDateTime startTime,
+                                                     LocalDateTime endTime,
+                                                     String warningType,
+                                                     String warningSpecial,
+                                                     String status) {
+        return earlyWarningMapper.selectReceiveEfficiencyOverview(startTime, endTime, warningType, warningSpecial, status);
+    }
+
+    @Override
+    public List<Map<String, Object>> getEfficiencyRange(LocalDateTime startTime,
+                                                        LocalDateTime endTime,
+                                                        String warningType,
+                                                        String warningSpecial,
+                                                        String status) {
+        return earlyWarningMapper.selectReceiveEfficiencyRange(startTime, endTime, warningType, warningSpecial, status);
+    }
+
+    @Override
+    public List<Map<String, Object>> getEfficiencyByType(LocalDateTime startTime, LocalDateTime endTime) {
+        return earlyWarningMapper.selectReceiveEfficiencyByType(startTime, endTime);
+    }
+
+    @Override
+    public IPage<Map<String, Object>> queryEfficiencyPage(Page<Map<String, Object>> page,
+                                                          LocalDateTime startTime,
+                                                          LocalDateTime endTime,
+                                                          String warningType,
+                                                          String warningSpecial,
+                                                          String status,
+                                                          String sortType) {
+        List<Map<String, Object>> list = earlyWarningMapper.selectReceiveEfficiencyList(
+                startTime, endTime, warningType, warningSpecial, status, sortType);
+        page.setRecords(list);
+        page.setTotal(list.size());
+        return page;
+    }
+}

+ 145 - 1
pipe-network-service/zksy-system/src/main/resources/mapper/warning/EarlyWarningMapper.xml

@@ -248,7 +248,151 @@
         </if>
     </select>
 
-    <!--  -->
+    <!-- 接警效率分析-概览指标统计 -->
+    <select id="selectReceiveEfficiencyOverview" resultType="java.util.Map">
+        SELECT
+        ROUND(AVG(receive_hours), 2) AS avg_hours,
+        ROUND(MAX(receive_hours), 2) AS max_hours,
+        ROUND(MIN(receive_hours), 2) AS min_hours,
+        COUNT(*) AS total_count
+        FROM (
+        SELECT
+        TIMESTAMPDIFF(SECOND, w.publish_time, MIN(d.create_time)) / 3600 AS receive_hours
+        FROM early_warning w
+        INNER JOIN warning_disposal d ON w.warning_id = d.warning_id
+        WHERE w.status != 'DRAFT'
+        <if test="startTime != null">
+            AND w.publish_time &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND w.publish_time &lt; #{endTime}
+        </if>
+        <if test="warningType != null and warningType != ''">
+            AND w.warning_type = #{warningType}
+        </if>
+        <if test="warningSpecial != null and warningSpecial != ''">
+            AND w.warning_special = #{warningSpecial}
+        </if>
+        <if test="status != null and status != ''">
+            AND w.status = #{status}
+        </if>
+        GROUP BY w.warning_id
+        HAVING receive_hours IS NOT NULL
+        ) AS temp
+    </select>
+
+    <!-- 接警效率分析-时效区间分布统计 -->
+    <select id="selectReceiveEfficiencyRange" resultType="java.util.Map">
+        SELECT
+        CASE
+        WHEN receive_hours &lt;= 0.5 THEN '0-30分钟'
+        WHEN receive_hours &lt;= 2 THEN '30分钟-2小时'
+        WHEN receive_hours &lt;= 6 THEN '2-6小时'
+        ELSE '6小时以上'
+        END AS time_range,
+        COUNT(*) AS warning_count
+        FROM (
+        SELECT
+        TIMESTAMPDIFF(SECOND, w.publish_time, MIN(d.create_time)) / 3600 AS receive_hours
+        FROM early_warning w
+        INNER JOIN warning_disposal d ON w.warning_id = d.warning_id
+        WHERE w.status != 'DRAFT'
+        <if test="startTime != null">
+            AND w.publish_time &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND w.publish_time &lt; #{endTime}
+        </if>
+        <if test="warningType != null and warningType != ''">
+            AND w.warning_type = #{warningType}
+        </if>
+        <if test="warningSpecial != null and warningSpecial != ''">
+            AND w.warning_special = #{warningSpecial}
+        </if>
+        <if test="status != null and status != ''">
+            AND w.status = #{status}
+        </if>
+        GROUP BY w.warning_id
+        HAVING receive_hours IS NOT NULL
+        ) AS temp
+        GROUP BY time_range
+        ORDER BY
+        CASE time_range
+        WHEN '0-30分钟' THEN 1
+        WHEN '30分钟-2小时' THEN 2
+        WHEN '2-6小时' THEN 3
+        ELSE 4
+        END ASC
+    </select>
+
+    <!-- 接警效率分析-按预警类型统计平均时效 -->
+    <select id="selectReceiveEfficiencyByType" resultType="java.util.Map">
+        SELECT
+        IFNULL(warning_type, '其他') AS warning_type,
+        COUNT(*) AS warning_count,
+        ROUND(AVG(receive_hours), 2) AS avg_receive_hours
+        FROM (
+        SELECT
+        w.warning_type,
+        TIMESTAMPDIFF(SECOND, w.publish_time, MIN(d.create_time)) / 3600 AS receive_hours
+        FROM early_warning w
+        INNER JOIN warning_disposal d ON w.warning_id = d.warning_id
+        WHERE w.status != 'DRAFT'
+        <if test="startTime != null">
+            AND w.publish_time &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND w.publish_time &lt; #{endTime}
+        </if>
+        GROUP BY w.warning_id
+        HAVING receive_hours IS NOT NULL
+        ) AS temp
+        GROUP BY warning_type
+        ORDER BY avg_receive_hours DESC
+    </select>
+
+    <!-- 接警效率分析-明细列表 -->
+    <select id="selectReceiveEfficiencyList" resultType="java.util.Map">
+        SELECT
+        w.warning_id,
+        w.warning_no,
+        w.warning_name,
+        IFNULL(w.warning_type, '其他') AS warning_type,
+        IFNULL(w.warning_special, '其他') AS warning_special,
+        w.publish_time,
+        MIN(d.create_time) AS receive_time,
+        ROUND(TIMESTAMPDIFF(SECOND, w.publish_time, MIN(d.create_time)) / 3600, 2) AS receive_hours,
+        w.status
+        FROM early_warning w
+        INNER JOIN warning_disposal d ON w.warning_id = d.warning_id
+        WHERE w.status != 'DRAFT'
+        <if test="startTime != null">
+            AND w.publish_time &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND w.publish_time &lt; #{endTime}
+        </if>
+        <if test="warningType != null and warningType != ''">
+            AND w.warning_type = #{warningType}
+        </if>
+        <if test="warningSpecial != null and warningSpecial != ''">
+            AND w.warning_special = #{warningSpecial}
+        </if>
+        <if test="status != null and status != ''">
+            AND w.status = #{status}
+        </if>
+        GROUP BY w.warning_id
+        HAVING receive_hours IS NOT NULL
+        ORDER BY receive_hours
+        <if test="sortType != null and sortType == 'desc'">
+            DESC
+        </if>
+        <if test="sortType == null or sortType == 'asc'">
+            ASC
+        </if>
+    </select>
+
+    <!-- ————————————————————————————————————————————————————————————— -->
 
     <select id="selectWarningList" resultType="java.util.Map">
         SELECT w.*