Quellcode durchsuchen

- 添加 预警信息-今日预警统计 接口

Kazerin vor 1 Monat
Ursprung
Commit
a792c2e26e

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

@@ -0,0 +1,68 @@
+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.domain.EarlyWarning;
+import com.zksy.base.warning.service.IEarlyWarningTodayService;
+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.web.bind.annotation.*;
+
+import java.util.Map;
+
+/**
+ * 今日预警统计接口
+ */
+@RestController
+@RequestMapping("/api/warning/today")
+@Api(tags = "预警信息-今日预警统计接口")
+public class EarlyWarningTodayController {
+
+    private static final Logger log = LoggerFactory.getLogger(EarlyWarningTodayController.class);
+
+    @Autowired
+    private IEarlyWarningTodayService earlyWarningTodayService;
+
+    @GetMapping("/stats")
+    @ApiOperation(value = "获取今日预警统计指标", notes = "返回今日预警总数、已处置数、已解除数三个核心指标")
+    @ApiResponses({
+            @ApiResponse(code = 200, message = "查询成功", response = AjaxResult.class),
+            @ApiResponse(code = 500, message = "服务器内部错误,查询失败", response = AjaxResult.class)
+    })
+    public AjaxResult getTodayStats() {
+        try {
+            Map<String, Object> stats = earlyWarningTodayService.getTodayWarningStats();
+            return AjaxResult.success("查询成功", stats);
+        } 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 queryTodayPage(
+            @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer pageNum,
+            @ApiParam(value = "每页大小", defaultValue = "10") @RequestParam(defaultValue = "10") Integer pageSize,
+            @ApiParam(value = "预警状态", allowableValues = "PENDING,PROCESSING,RELEASED,HANDLED,CLOSED") @RequestParam(required = false) String status) {
+        try {
+            Page<EarlyWarning> page = new Page<>(pageNum, pageSize);
+            IPage<EarlyWarning> resultPage = earlyWarningTodayService.queryTodayWarningPage(page, status);
+            return AjaxResult.success("查询成功", resultPage);
+        } catch (Exception e) {
+            log.error("分页查询今日预警列表异常", e);
+            return AjaxResult.error("查询失败:" + e.getMessage());
+        }
+    }
+}

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

@@ -27,4 +27,16 @@ public interface EarlyWarningMapper extends BaseMapper<EarlyWarning> {
     Map<String, Object> selectWarningDetail(@Param("warningId") String warningId);
 
     List<Map<String, Object>> selectStatistics();
+
+    /**
+     * 统计今日预警核心指标
+     * @return 包含今日预警总数、已处置数、已解除数的Map
+     */
+    Map<String, Object> selectTodayWarningStats();
+
+    /**
+     * 查询今日预警列表(支持按状态筛选)
+     * @param status 预警状态,为空则查询所有非草稿状态
+     */
+    List<EarlyWarning> selectTodayWarningList(@Param("status") String status);
 }

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

@@ -0,0 +1,22 @@
+package com.zksy.base.warning.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.zksy.base.warning.domain.EarlyWarning;
+
+import java.util.Map;
+
+public interface IEarlyWarningTodayService {
+
+    /**
+     * 获取今日预警统计指标
+     */
+    Map<String, Object> getTodayWarningStats();
+
+    /**
+     * 分页查询今日预警列表
+     * @param page 分页参数
+     * @param status 预警状态,为空查所有非草稿
+     */
+    IPage<EarlyWarning> queryTodayWarningPage(Page<EarlyWarning> page, String status);
+}

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

@@ -0,0 +1,32 @@
+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.domain.EarlyWarning;
+import com.zksy.base.warning.mapper.EarlyWarningMapper;
+import com.zksy.base.warning.service.IEarlyWarningTodayService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class EarlyWarningTodayServiceImpl implements IEarlyWarningTodayService {
+
+    @Autowired
+    private EarlyWarningMapper earlyWarningMapper;
+
+    @Override
+    public Map<String, Object> getTodayWarningStats() {
+        return earlyWarningMapper.selectTodayWarningStats();
+    }
+
+    @Override
+    public IPage<EarlyWarning> queryTodayWarningPage(Page<EarlyWarning> page, String status) {
+        List<EarlyWarning> list = earlyWarningMapper.selectTodayWarningList(status);
+        page.setRecords(list);
+        page.setTotal(list.size());
+        return page;
+    }
+}

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

@@ -2,6 +2,65 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.zksy.base.warning.mapper.EarlyWarningMapper">
 
+    <resultMap id="BaseResultMap" type="com.zksy.base.warning.domain.EarlyWarning">
+        <id column="warning_id" property="warningId"/>
+        <result column="warning_no" property="warningNo"/>
+        <result column="warning_name" property="warningName"/>
+        <result column="warning_type" property="warningType"/>
+        <result column="warning_level" property="warningLevel"/>
+        <result column="warning_special" property="warningSpecial"/>
+        <result column="location" property="location"/>
+        <result column="longitude" property="longitude"/>
+        <result column="latitude" property="latitude"/>
+        <result column="ownership_unit" property="ownershipUnit"/>
+        <result column="publisher" property="publisher"/>
+        <result column="publish_time" property="publishTime"/>
+        <result column="handler" property="handler"/>
+        <result column="status" property="status"/>
+        <result column="warning_content" property="warningContent"/>
+        <result column="process_instance_id" property="processInstanceId"/>
+        <result column="create_by" property="createBy"/>
+        <result column="create_time" property="createTime"/>
+        <result column="update_by" property="updateBy"/>
+        <result column="update_time" property="updateTime"/>
+        <result column="remark" property="remark"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        warning_id, warning_no, warning_name, warning_type, warning_level, warning_special,
+        location, longitude, latitude, ownership_unit, publisher, publish_time, handler,
+        status, warning_content, process_instance_id, create_by, create_time, update_by,
+        update_time, remark
+    </sql>
+
+    <!-- 统计今日预警核心指标 -->
+    <select id="selectTodayWarningStats" resultType="java.util.Map">
+        SELECT
+        COUNT(CASE WHEN status != 'DRAFT' THEN 1 END) AS today_total,
+        COUNT(CASE WHEN status = 'HANDLED' THEN 1 END) AS handled_today,
+        COUNT(CASE WHEN status = 'CLOSED' THEN 1 END) AS closed_today
+        FROM early_warning
+        WHERE publish_time &gt;= DATE_FORMAT(NOW(), '%Y-%m-%d 00:00:00')
+        AND publish_time &lt; DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-%d'), INTERVAL 1 DAY)
+    </select>
+
+    <!-- 查询今日预警列表 -->
+    <select id="selectTodayWarningList" resultMap="BaseResultMap">
+        SELECT <include refid="Base_Column_List"/>
+        FROM early_warning
+        WHERE publish_time &gt;= DATE_FORMAT(NOW(), '%Y-%m-%d 00:00:00')
+        AND publish_time &lt; DATE_ADD(DATE_FORMAT(NOW(), '%Y-%m-%d'), INTERVAL 1 DAY)
+        <choose>
+            <when test="status != null and status != ''">
+                AND status = #{status}
+            </when>
+            <otherwise>
+                AND status != 'DRAFT'
+            </otherwise>
+        </choose>
+        ORDER BY publish_time DESC
+    </select>
+
     <select id="selectWarningList" resultType="java.util.Map">
         SELECT w.*
         FROM early_warning w