Quellcode durchsuchen

- 添加 预警信息-预警发展趋势 接口

Kazerin vor 1 Monat
Ursprung
Commit
db63dead82

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

@@ -0,0 +1,80 @@
+package com.zksy.web.controller.warning;
+
+import com.zksy.base.warning.service.IEarlyWarningTrendService;
+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("/api/warning/trend")
+@Api(tags = "预警信息-预警发展趋势接口")
+public class EarlyWarningTrendController {
+
+    private static final Logger log = LoggerFactory.getLogger(EarlyWarningTrendController.class);
+
+    @Autowired
+    private IEarlyWarningTrendService earlyWarningTrendService;
+
+    @GetMapping("/day")
+    @ApiOperation(value = "按日统计预警发展趋势", notes = "按日期维度统计各专项预警数量趋势,支持时间范围、预警专项筛选")
+    @ApiResponses({
+            @ApiResponse(code = 200, message = "统计成功", response = AjaxResult.class),
+            @ApiResponse(code = 500, message = "服务器内部错误,统计失败", response = AjaxResult.class)
+    })
+    public AjaxResult getTrendByDay(
+            @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-12-31 23:59:59")
+            @RequestParam(required = false)
+            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime,
+            @ApiParam(value = "预警专项")
+            @RequestParam(required = false) String warningSpecial) {
+        try {
+            List<Map<String, Object>> list = earlyWarningTrendService.getTrendByDay(startTime, endTime, warningSpecial);
+            return AjaxResult.success("统计成功", list);
+        } catch (Exception e) {
+            log.error("按日统计预警发展趋势异常", e);
+            return AjaxResult.error("统计失败:" + e.getMessage());
+        }
+    }
+
+    @GetMapping("/month")
+    @ApiOperation(value = "按月统计预警发展趋势", notes = "按月份维度统计各专项预警数量趋势,支持时间范围、预警专项筛选")
+    @ApiResponses({
+            @ApiResponse(code = 200, message = "统计成功", response = AjaxResult.class),
+            @ApiResponse(code = 500, message = "服务器内部错误,统计失败", response = AjaxResult.class)
+    })
+    public AjaxResult getTrendByMonth(
+            @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-12-31 23:59:59")
+            @RequestParam(required = false)
+            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime,
+            @ApiParam(value = "预警专项")
+            @RequestParam(required = false) String warningSpecial) {
+        try {
+            List<Map<String, Object>> list = earlyWarningTrendService.getTrendByMonth(startTime, endTime, warningSpecial);
+            return AjaxResult.success("统计成功", list);
+        } catch (Exception e) {
+            log.error("按月统计预警发展趋势异常", e);
+            return AjaxResult.error("统计失败:" + e.getMessage());
+        }
+    }
+}

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

@@ -39,4 +39,26 @@ public interface EarlyWarningMapper extends BaseMapper<EarlyWarning> {
      * @param status 预警状态,为空则查询所有非草稿状态
      */
     List<EarlyWarning> selectTodayWarningList(@Param("status") String status);
+
+    /**
+     * 按日统计预警发展趋势(按专项分组)
+     * @param startTime 开始时间
+     * @param endTime 结束时间
+     * @param warningSpecial 预警专项(可选)
+     */
+    List<Map<String, Object>> selectWarningTrendByDay(
+            @Param("startTime") LocalDateTime startTime,
+            @Param("endTime") LocalDateTime endTime,
+            @Param("warningSpecial") String warningSpecial);
+
+    /**
+     * 按月统计预警发展趋势(按专项分组)
+     * @param startTime 开始时间
+     * @param endTime 结束时间
+     * @param warningSpecial 预警专项(可选)
+     */
+    List<Map<String, Object>> selectWarningTrendByMonth(
+            @Param("startTime") LocalDateTime startTime,
+            @Param("endTime") LocalDateTime endTime,
+            @Param("warningSpecial") String warningSpecial);
 }

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

@@ -0,0 +1,24 @@
+package com.zksy.base.warning.service;
+
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Map;
+
+public interface IEarlyWarningTrendService {
+
+    /**
+     * 按日统计预警发展趋势
+     * @param startTime 开始时间
+     * @param endTime 结束时间
+     * @param warningSpecial 预警专项(可选)
+     */
+    List<Map<String, Object>> getTrendByDay(LocalDateTime startTime, LocalDateTime endTime, String warningSpecial);
+
+    /**
+     * 按月统计预警发展趋势
+     * @param startTime 开始时间
+     * @param endTime 结束时间
+     * @param warningSpecial 预警专项(可选)
+     */
+    List<Map<String, Object>> getTrendByMonth(LocalDateTime startTime, LocalDateTime endTime, String warningSpecial);
+}

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

@@ -0,0 +1,27 @@
+package com.zksy.base.warning.service.impl;
+
+import com.zksy.base.warning.mapper.EarlyWarningMapper;
+import com.zksy.base.warning.service.IEarlyWarningTrendService;
+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 EarlyWarningTrendServiceImpl implements IEarlyWarningTrendService {
+
+    @Autowired
+    private EarlyWarningMapper earlyWarningMapper;
+
+    @Override
+    public List<Map<String, Object>> getTrendByDay(LocalDateTime startTime, LocalDateTime endTime, String warningSpecial) {
+        return earlyWarningMapper.selectWarningTrendByDay(startTime, endTime, warningSpecial);
+    }
+
+    @Override
+    public List<Map<String, Object>> getTrendByMonth(LocalDateTime startTime, LocalDateTime endTime, String warningSpecial) {
+        return earlyWarningMapper.selectWarningTrendByMonth(startTime, endTime, warningSpecial);
+    }
+}

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

@@ -61,6 +61,50 @@
         ORDER BY publish_time DESC
     </select>
 
+    <!-- 按日统计预警发展趋势 -->
+    <select id="selectWarningTrendByDay" resultType="java.util.Map">
+        SELECT
+        DATE_FORMAT(publish_time, '%Y-%m-%d') AS stat_date,
+        IFNULL(warning_special, '其他') AS warning_special,
+        COUNT(*) AS warning_count
+        FROM early_warning
+        WHERE status != 'DRAFT'
+        <if test="startTime != null">
+            AND publish_time &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND publish_time &lt; #{endTime}
+        </if>
+        <if test="warningSpecial != null and warningSpecial != ''">
+            AND warning_special = #{warningSpecial}
+        </if>
+        GROUP BY stat_date, warning_special
+        ORDER BY stat_date ASC, warning_special ASC
+    </select>
+
+    <!-- 按月统计预警发展趋势 -->
+    <select id="selectWarningTrendByMonth" resultType="java.util.Map">
+        SELECT
+        DATE_FORMAT(publish_time, '%Y-%m') AS stat_month,
+        IFNULL(warning_special, '其他') AS warning_special,
+        COUNT(*) AS warning_count
+        FROM early_warning
+        WHERE status != 'DRAFT'
+        <if test="startTime != null">
+            AND publish_time &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND publish_time &lt; #{endTime}
+        </if>
+        <if test="warningSpecial != null and warningSpecial != ''">
+            AND warning_special = #{warningSpecial}
+        </if>
+        GROUP BY stat_month, warning_special
+        ORDER BY stat_month ASC, warning_special ASC
+    </select>
+
+    <!--  -->
+
     <select id="selectWarningList" resultType="java.util.Map">
         SELECT w.*
         FROM early_warning w