소스 검색

修改数据统计

wyyay 2 년 전
부모
커밋
573b5a3087

+ 5 - 0
business-service/src/main/java/com/ozs/entity/vo/AlarmStatisticMonthDto.java

@@ -45,6 +45,11 @@ public class AlarmStatisticMonthDto {
     @Excel(name = "报警日期")
     private String monthstaString;
 
+    /**
+     * 百分比
+     */
+    private String percent;
+
     /**
      * 报警次数
      */

+ 0 - 120
business-service/src/main/java/com/ozs/entity/vo/AlarmStatisticVo.java

@@ -1,120 +0,0 @@
-package com.ozs.entity.vo;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.ozs.common.annotation.Excel;
-import lombok.Data;
-
-import java.util.Date;
-
-/**
- * 统计管理页面实体类
- *
- * @author wyy
- * @subject
- * @creat 2023/3/6
- */
-@Data
-public class AlarmStatisticVo {
-
-    /**
-     * 报警唯一标识
-     */
-    private String alarmId;
-
-    /**
-     * 报警时间
-     */
-    @JsonFormat(
-            pattern = "yyyy-MM-dd HH:mm:ss"
-    )
-    private Date alarmTime;
-
-    /**
-     * 线路名称
-     */
-    private String railwayName;
-
-    /**
-     * 报警行别(1上行2下行)
-     */
-    private Integer lineDir;
-
-    /**
-     * 报警里程位置
-     */
-    private String alarmMile;
-
-    /**
-     * 报警内容
-     */
-    private String content;
-
-    /**
-     * 报警级别
-     */
-    private String alarmLevel;
-
-    /**
-     * 报警置信度(百分比)
-     */
-    private Integer alarmConfidence;
-
-    /**
-     * 报警病害类型(目前只有1泥石流,后续可扩展使用)
-     */
-    private Integer alarmType;
-
-    /**
-     * 框定范围
-     */
-    private Integer alarmAttr;
-
-    /**
-     * 报警是否解除 1已解除2未解除
-     */
-    private Integer isRelease;
-
-    /**
-     * 解除人
-     */
-    private String releasedBy;
-
-    /**
-     * 解除时间
-     */
-    @JsonFormat(
-            pattern = "yyyy-MM-dd HH:mm:ss"
-    )
-    private Date releasedTime;
-
-    /**
-     * 解除内容
-     */
-    private String releaseContent;
-
-    /**
-     * 备注
-     */
-    private String remark;
-
-    /**
-     * 报警行别字符串(1上行2下行)
-     */
-    private String lineDirName;
-
-
-    /**
-     * 报警病害类型(目前只有1泥石流,后续可扩展使用)
-     */
-    private String alarmTypeName;
-
-    /**
-     * 解除人
-     */
-    private String releasedByName;
-
-    /**
-     * 报警是否解除 1已解除2未解除
-     */
-    private String isReleaseName;
-}

+ 7 - 0
business-service/src/main/java/com/ozs/mapper/MsgAlarmMapper.java

@@ -2,6 +2,7 @@ package com.ozs.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ozs.entity.MsgAlarm;
+import com.ozs.entity.vo.AlarmFreqArea;
 import com.ozs.entity.vo.AlarmStatisticDto;
 import com.ozs.entity.vo.AlarmStatisticMonthDto;
 import com.ozs.entity.vo.MsgAlarmVo;
@@ -29,6 +30,12 @@ public interface MsgAlarmMapper extends BaseMapper<MsgAlarm> {
     //报警月统计数据导出数据集合(天)
     List<AlarmStatisticMonthDto> listDtoDay(@Param("railwayCode") String railwayCode, @Param("currentYear") Integer currentYear, @Param("currentMonth") Integer currentMonth);
 
+    //数据统计-灾害占比
+    List<AlarmStatisticMonthDto> alarmTypeCount(@Param("railwayCode") String railwayCode, @Param("currentYear") Integer currentYear, @Param("currentMonth") Integer currentMonth);
+
+    //数据统计-频繁出现灾害地点排名
+    List<AlarmFreqArea> alarmTypeAreaCount(@Param("railwayCode") String railwayCode, @Param("currentYear") Integer currentYear, @Param("currentMonth") Integer currentMonth);
+
     Integer selectCameraCode(@Param("cameraCode") String cameraCode);
 
     MsgAlarm selectByCameraCode(@Param("cameraCode") String cameraCode);

+ 6 - 0
business-service/src/main/java/com/ozs/service/MsgAlarmService.java

@@ -28,6 +28,12 @@ public interface MsgAlarmService extends IService<MsgAlarm> {
     //web数据统计 报警月统计数据(天)
     List<AlarmStatisticMonthDto> getDayCount(String railwayCode, Integer currentYear, Integer currentMonth);
 
+    //数据统计-灾害占比
+    List<AlarmStatisticMonthDto> getAlarmTypeCount(String railwayCode, Integer currentYear, Integer currentMonth);
+
+    //数据统计-频繁出现灾害地点排名
+    List<AlarmFreqArea> alarmTypeAreaCount(String railwayCode, Integer currentYear, Integer currentMonth);
+
     //报警数据详情导出数据集合
     List<AlarmStatisticDto> exportExcel(AlarmStatisticResVo alarmStatisticResVo);
 

+ 12 - 0
business-service/src/main/java/com/ozs/service/impl/MsgAlarmServiceImpl.java

@@ -63,6 +63,18 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
         return list;
     }
 
+    @Override
+    public List<AlarmStatisticMonthDto> getAlarmTypeCount(String railwayCode, Integer currentYear, Integer currentMonth) {
+        List<AlarmStatisticMonthDto> list = msgAlarmMapper.alarmTypeCount(railwayCode, currentYear, currentMonth);
+        return list;
+    }
+
+    @Override
+    public List<AlarmFreqArea> alarmTypeAreaCount(String railwayCode, Integer currentYear, Integer currentMonth) {
+        List<AlarmFreqArea> list = msgAlarmMapper.alarmTypeAreaCount(railwayCode, currentYear, currentMonth);
+        return list;
+    }
+
     @Override
     public List<AlarmStatisticDto> exportExcel(AlarmStatisticResVo alarmStatisticResVo) {
         List<AlarmStatisticDto> listDto = msgAlarmMapper.list(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getCurrentYear(),

+ 68 - 8
business-service/src/main/resources/mapper/MsgAlarmMapper.xml

@@ -43,7 +43,7 @@
 
         <where>
             <if test="railwayCode != null and railwayCode != ''">
-                and UPPER(b.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
+                and UPPER(a.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
             </if>
             <if test="currentYear != null and currentYear != 0">
                 and YEAR(a.alarm_time) like UPPER(CONCAT('%',#{currentYear},'%'))
@@ -61,10 +61,35 @@
     <resultMap id="AlarmStatisticMonthDtoResult" type="com.ozs.entity.vo.AlarmStatisticMonthDto">
         <id column="id" property="id"/>
         <result column="monthsta" property="monthsta"/>
+        <result column="alarmType" property="alarmType"/>
         <result column="monthstaString" property="monthstaString"/>
         <result column="frequency" property="frequency"/>
-        <result column="alarm_type" property="alarmType"/>
     </resultMap>
+    <select id="alarmTypeCount" resultMap="AlarmStatisticMonthDtoResult">
+        SELECT sum(p.fre) as frequency,p.alarmType as alarmType
+        from
+        (SELECT
+        a.alarm_type as alarmType,
+        count(DISTINCT a.alarm_id) as fre
+        FROM
+        msg_alarm AS a
+
+        <where>
+            <if test="railwayCode != null and railwayCode != ''">
+                and UPPER(a.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
+            </if>
+            <if test="currentYear != null and currentYear != 0">
+                and YEAR(a.alarm_time) like UPPER(CONCAT('%',#{currentYear},'%'))
+            </if>
+            <if test="currentYear == null or currentYear == ''">
+                and YEAR(a.alarm_time) = YEAR(SYSDATE())
+            </if>
+            <if test="currentMonth != null and currentMonth != 0">
+                and MONTH(a.alarm_time) =#{currentMonth}
+            </if>
+        </where>
+        group by a.alarm_id) AS p group by p.alarmType
+    </select>
     <select id="listDtoMonth" resultMap="AlarmStatisticMonthDtoResult">
         SELECT p.monthsta as monthsta,sum(p.fre) as frequency,p.monthstaString as monthstaString
         from
@@ -73,12 +98,11 @@
         MONTH(a.alarm_time) as monthsta,
         count(DISTINCT a.alarm_id) as fre
         FROM
-        msg_alarm AS a inner join
-        base_railway_management AS b on a.railway_code=b.railway_code
+        msg_alarm AS a
 
         <where>
             <if test="railwayCode != null and railwayCode != ''">
-                and UPPER(b.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
+                and UPPER(a.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
             </if>
             <if test="currentYear != null and currentYear != 0">
                 and YEAR(a.alarm_time) like UPPER(CONCAT('%',#{currentYear},'%'))
@@ -101,12 +125,11 @@
         DAY(a.alarm_time) as daysta,
         count(DISTINCT a.alarm_id) as fre
         FROM
-        msg_alarm AS a inner join
-        base_railway_management AS b on a.railway_code=b.railway_code
+        msg_alarm AS a
 
         <where>
             <if test="railwayCode != null and railwayCode != ''">
-                and UPPER(b.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
+                and UPPER(a.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
             </if>
             <if test="currentYear != null and currentYear != 0">
                 and YEAR(a.alarm_time) like UPPER(CONCAT('%',#{currentYear},'%'))
@@ -120,6 +143,43 @@
         </where>
         group by a.alarm_id) AS p group by p.daysta order by p.daysta
     </select>
+
+    <resultMap id="AlarmTypeStatisticResult" type="com.ozs.entity.vo.AlarmFreqArea">
+        <id column="id" property="id"/>
+        <result column="railwayName" property="railwayName"/>
+        <result column="railwayCode" property="railwayCode"/>
+        <result column="alarmMile" property="alarmMile"/>
+        <result column="frequency" property="frequency"/>
+    </resultMap>
+    <select id="alarmTypeAreaCount" resultMap="AlarmTypeStatisticResult">
+        SELECT railwayCode,railwayName,alarmMile,SUM(p.pre) as frequency
+        from
+        (SELECT
+        a.railway_code as railwayCode,
+        b.railway_name as railwayName,
+        a.alarm_mile as alarmMile,
+        count(a.railway_code) as pre
+        FROM
+        msg_alarm AS a inner join
+        base_railway_management b on a.railway_code=b.railway_code
+
+        <where>
+            <if test="railwayCode != null and railwayCode != ''">
+                and UPPER(a.railway_code) like UPPER(CONCAT('%',#{railwayCode},'%'))
+            </if>
+            <if test="currentYear != null and currentYear != 0">
+                and YEAR(a.alarm_time) like UPPER(CONCAT('%',#{currentYear},'%'))
+            </if>
+            <if test="currentYear == null or currentYear == ''">
+                and YEAR(a.alarm_time) = YEAR(SYSDATE())
+            </if>
+            <if test="currentMonth != null and currentMonth != 0">
+                and MONTH(a.alarm_time) =#{currentMonth}
+            </if>
+        </where>
+        group by a.alarm_id) AS p group by p.railwayCode order by frequency desc
+    </select>
+
     <select id="selectCameraCode" parameterType="java.lang.String" resultType="java.lang.Integer">
         select is_lock from msg_alarm where camera_code = #{cameraCode} ORDER BY alarm_time DESC LIMIT 1
     </select>

+ 73 - 14
vehicle-admin/src/main/java/com/ozs/web/controller/accountmanagment/DataStatisticController.java

@@ -10,10 +10,10 @@ import com.ozs.common.utils.AppendUtils;
 import com.ozs.common.utils.StringUtils;
 import com.ozs.common.utils.poi.ExcelUtil;
 import com.ozs.entity.BaseUser;
+import com.ozs.entity.vo.AlarmFreqArea;
 import com.ozs.entity.vo.AlarmStatisticDto;
 import com.ozs.entity.vo.AlarmStatisticMonthDto;
 import com.ozs.entity.vo.AlarmStatisticResVo;
-import com.ozs.entity.vo.AlarmStatisticVo;
 import com.ozs.service.BaseUserService;
 import com.ozs.service.MsgAlarmService;
 import com.ozs.system.service.ISysDictDataService;
@@ -32,6 +32,8 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
 import java.util.*;
 
 /**
@@ -55,14 +57,13 @@ public class DataStatisticController extends BaseController {
      * @param alarmStatisticResVo
      * @return
      */
-    @Log(title = "报警信息管理", businessType = BusinessType.OTHER)
+    @Log(title = "报警数据详情", businessType = BusinessType.SELECT)
     @PostMapping("/dataStatistic")
     @ApiOperation(value = "web数据统计 报警数据详情")
     @ApiImplicitParams(value = {
             @ApiImplicitParam(paramType = "query", name = "railwayCode", value = "线路编码"),
             @ApiImplicitParam(paramType = "query", name = "currentYear", value = "当前年份"),
-            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份"),
-            @ApiImplicitParam(paramType = "query", name = "alarmType", value = "灾害类型"),
+            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份")
     })
     public AjaxResult dataStatistic(@RequestBody AlarmStatisticResVo alarmStatisticResVo) {
         Integer pageNum = alarmStatisticResVo.getPageNum().intValue();
@@ -100,14 +101,13 @@ public class DataStatisticController extends BaseController {
      * @param
      * @return
      */
-    @Log(title = "报警信息管理", businessType = BusinessType.OTHER)
+    @Log(title = "报警月统计", businessType = BusinessType.SELECT)
     @PostMapping("/alarmMonthStatistic")
     @ApiOperation(value = "web数据统计 报警月统计数据")
     @ApiImplicitParams(value = {
             @ApiImplicitParam(paramType = "query", name = "railwayCode", value = "线路编码"),
             @ApiImplicitParam(paramType = "query", name = "currentYear", value = "当前年份"),
-            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份"),
-            @ApiImplicitParam(paramType = "query", name = "alarmType", value = "灾害类型"),
+            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份")
     })
     public AjaxResult alarmMonthStatistic(@RequestBody AlarmStatisticResVo alarmStatisticResVo) {
         List<Integer> numbs = new ArrayList<>();
@@ -160,6 +160,67 @@ public class DataStatisticController extends BaseController {
         return AjaxResult.success(list);
     }
 
+    /**
+     * web数据统计
+     *
+     * @param
+     * @return
+     */
+    @Log(title = "灾害类型统计", businessType = BusinessType.SELECT)
+    @PostMapping("/alarmTypeStatistic")
+    @ApiOperation(value = "web数据统计 灾害类型统计数据")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(paramType = "query", name = "railwayCode", value = "线路编码"),
+            @ApiImplicitParam(paramType = "query", name = "currentYear", value = "当前年份"),
+            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份")
+    })
+    public AjaxResult alarmTypeStatistic(@RequestBody AlarmStatisticResVo alarmStatisticResVo) {
+        List<AlarmStatisticMonthDto> list = msgAlarmService.getAlarmTypeCount(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getCurrentYear(),
+                alarmStatisticResVo.getCurrentMonth());
+        Integer sum = list.stream().mapToInt((x) -> Integer.parseInt(String.valueOf(x.getFrequency()))).sum();
+        NumberFormat numberFormat = NumberFormat.getPercentInstance();
+        numberFormat.setMinimumFractionDigits(2);
+        if (!CollectionUtils.isEmpty(list) && list.size()!= 0){
+            list.forEach(l -> {
+                if (!ObjectUtils.isEmpty(l.getAlarmType())) {
+                    l.setAlarmTypeValue(dictDataService.selectDictLabel("sys_alarm_type", String.valueOf(l.getAlarmType())));
+                }
+                    l.setPercent(numberFormat.format(l.getFrequency()*1.0 / sum));
+            });
+        }
+        return AjaxResult.success(list);
+    }
+
+    /**
+     * web数据统计
+     *
+     * @param
+     * @return
+     */
+    @Log(title = "频繁出现灾害地点排名", businessType = BusinessType.SELECT)
+    @PostMapping("/alarmTypeAreaCount")
+    @ApiOperation(value = "web数据统计 频繁出现灾害地点排名")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(paramType = "query", name = "railwayCode", value = "线路编码"),
+            @ApiImplicitParam(paramType = "query", name = "currentYear", value = "当前年份"),
+            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份")
+    })
+    public AjaxResult alarmTypeAreaCount(@RequestBody AlarmStatisticResVo alarmStatisticResVo) {
+        Integer pageNum = alarmStatisticResVo.getPageNum().intValue();
+        Integer pageSize = alarmStatisticResVo.getPageSize().intValue();
+        List<AlarmFreqArea> list = msgAlarmService.alarmTypeAreaCount(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getCurrentYear(),
+                alarmStatisticResVo.getCurrentMonth());
+        list.forEach(l -> {
+                    if (!ObjectUtils.isEmpty(l.getAlarmMile())) {
+                        l.setAlarmMiles(AppendUtils.stringAppend(Integer.valueOf(l.getAlarmMile())));
+                    }
+        });
+        IPage page = msgAlarmService.listToPage(list, pageNum, pageSize);
+        if (!ObjectUtils.isEmpty(page) && !ObjectUtils.isEmpty(page.getRecords())) {
+            return AjaxResult.success(page);
+        }
+        return AjaxResult.success(null);
+    }
 
     /**
      * web数据统计 数据导出
@@ -167,14 +228,13 @@ public class DataStatisticController extends BaseController {
      * @param
      * @return
      */
-    @Log(title = "报警信息管理", businessType = BusinessType.EXPORT)
+    @Log(title = "报警详情导出管理", businessType = BusinessType.EXPORT)
     @PostMapping("/exportDataStatistic")
-    @ApiOperation(value = "web数据统计-数据导出")
+    @ApiOperation(value = "报警详情导出管理")
     @ApiImplicitParams(value = {
             @ApiImplicitParam(paramType = "query", name = "railwayCode", value = "线路编码"),
             @ApiImplicitParam(paramType = "query", name = "currentYear", value = "当前年份"),
-            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份"),
-            @ApiImplicitParam(paramType = "query", name = "alarmType", value = "灾害类型"),
+            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份")
     })
     public void exportDataStatistic(HttpServletResponse response, @RequestBody AlarmStatisticResVo alarmStatisticResVo) {
         try {
@@ -216,14 +276,13 @@ public class DataStatisticController extends BaseController {
      * @param
      * @return
      */
-    @Log(title = "报警信息管理", businessType = BusinessType.EXPORT)
+    @Log(title = "报警月统计数据导出", businessType = BusinessType.EXPORT)
     @PostMapping("/exportDataStatisticMonth")
     @ApiOperation(value = "报警月统计数据导出")
     @ApiImplicitParams(value = {
             @ApiImplicitParam(paramType = "query", name = "railwayCode", value = "线路编码"),
             @ApiImplicitParam(paramType = "query", name = "currentYear", value = "当前年份"),
-            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份"),
-            @ApiImplicitParam(paramType = "query", name = "alarmType", value = "灾害类型"),
+            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份")
     })
     public void exportDataStatisticMonth(HttpServletResponse response, @RequestBody AlarmStatisticResVo alarmStatisticResVo) {
         List<AlarmStatisticMonthDto> list = null;