Browse Source

预警系统首页紧急风险预警和实时风险预警统计接口查询

‘xugp 2 years ago
parent
commit
80d5b08e5c

+ 38 - 3
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/controller/HomeController.java

@@ -1,9 +1,19 @@
 package com.gyee.wisdom.alarm.sharding.controller;
 
+import com.alibaba.fastjson.JSON;
+import com.gyee.wisdom.alarm.sharding.model.AlarmHome;
+import com.gyee.wisdom.alarm.sharding.service.AlarmSnapService;
+import com.gyee.wisdom.alarm.sharding.service.RiskSnapService;
+import com.gyee.wisdom.alarm.sharding.util.ResponseWrapper;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.Map;
+
 
 /**
  * @description:
@@ -16,5 +26,30 @@ import org.springframework.web.bind.annotation.RestController;
 @Tag(name = "首页")
 public class HomeController {
 
+    @Autowired
+    private AlarmSnapService alarmSnapService;
+
+    @Autowired
+    private RiskSnapService riskSnapService;
+
+    @Operation(description = "报警总数查询")
+    @GetMapping("early/latest")
+    public ResponseWrapper selectAlarmCount(
+            @Parameter(name = "stationId", description = "场站id") @RequestParam(value = "stationId") String stationId
+    ){
+
+        ResponseWrapper wrapper = null;
+        try {
+            Map<String,List<AlarmHome>> stringListMap = alarmSnapService.selectAlarmSnapCount(stationId);
+            Map<String, List<AlarmHome>> stringListMap2 = riskSnapService.selectRiskSnapCount(stationId);
+            stringListMap.putAll(stringListMap2);
+            wrapper = ResponseWrapper.success("请求成功", stringListMap);
+        } catch (Exception ex) {
+            wrapper = ResponseWrapper.error("请求失败", JSON.toJSONString(ex.getStackTrace()));
+        }
+        return wrapper;
+
+    }
+
 
 }

+ 25 - 0
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/entity/AlarmPartsCount.java

@@ -0,0 +1,25 @@
+package com.gyee.wisdom.alarm.sharding.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+public class AlarmPartsCount implements Serializable{
+
+    @TableId("ID")
+    private Long id;
+    @TableField("ALARMDATE")
+    private Date alarmDate;
+    @TableField("PARTS")
+    private String parts;
+    @TableField("COUNT")
+    private int count;
+    @TableField("WINDTURBINEID")
+    private String windturbineid;
+
+
+}

+ 4 - 0
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/mapper/AlarmHisotryMapper.java

@@ -54,6 +54,10 @@ public interface AlarmHisotryMapper extends BaseMapper<AlarmHistory> {
                         @Param("starttime") Date startTime,
                         @Param("endtime") Date endTime);
 
+    AlarmHistory selectAlarmHistory(@Param("tbName") String tableName,
+                        @Param("snapid") Long snapid,
+                        @Param("starttime") Date startTime,
+                        @Param("endtime") Date endTime);
 
 
     List<FaultWarning> selectHistoryAlarmSnapAndWarning(

+ 16 - 0
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/mapper/AlarmPartsCountMapper.java

@@ -0,0 +1,16 @@
+package com.gyee.wisdom.alarm.sharding.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.gyee.wisdom.alarm.sharding.entity.*;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+
+@Mapper
+public interface AlarmPartsCountMapper extends BaseMapper<AlarmPartsCount> {
+
+    void batchInsert(  @Param("list") List<AlarmPartsCount> alarmPartsCounts);
+
+}

+ 0 - 1
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/mapper/AlarmSnapMapper.java

@@ -58,6 +58,5 @@ public interface AlarmSnapMapper extends BaseMapper<AlarmSnap> {
 
     List<AlarmSnap>  getRecentAlarm(@Param("category1") String category1,
                                     @Param("lastupdatetime") Date lastUpdateTime);
-
 }
 

+ 35 - 0
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/model/AlarmHome.java

@@ -0,0 +1,35 @@
+package com.gyee.wisdom.alarm.sharding.model;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+
+/**
+ * @author :xugp
+ * @date :Created in 2022/9/6 15:02
+ * @description:首页展示预警信息
+ * @modified By:
+ * @version: $
+ */
+
+@Data
+public class AlarmHome implements Serializable {
+
+    //场站名称
+    private String windpowerstationName;
+    //场站id
+    private String stationid;
+    //风机型号
+    private String modelid;
+    //风机编号
+    private String windturbineid;
+    //描述
+    private String description;
+    //名称
+    private String name;
+    //更新时间
+    private Date lastUpdateTime;
+
+}

+ 4 - 0
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/service/AlarmHistoryService.java

@@ -192,6 +192,10 @@ public class AlarmHistoryService extends ServiceImpl<AlarmHisotryMapper, AlarmHi
         return  alarmHisotryMapper.selectSnapCount(tableName, snapid, startDate, endDate);
     }
 
+    public AlarmHistory selectAlarmHistory(String tbName, Long id, Date dtStart, Date dtEnd) {
+        return alarmHisotryMapper.selectAlarmHistory(tbName,id,dtStart,dtEnd);
+    }
+
     //宁夏定制化功能 暂时干掉
 //    @Scheduled(cron = "0 */2 * * * ?")
 //   public Map<String, String> getTodayCount() throws Exception{

+ 38 - 0
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/service/AlarmSnapService.java

@@ -1,5 +1,6 @@
 package com.gyee.wisdom.alarm.sharding.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -11,6 +12,7 @@ import com.gyee.wisdom.alarm.sharding.mapper.AlarmHisotryMapper;
 import com.gyee.wisdom.alarm.sharding.mapper.AlarmSnapMapper;
 import com.gyee.wisdom.alarm.sharding.mapper.FaultHisotryMapper;
 import com.gyee.wisdom.alarm.sharding.mapper.FaultSnapMapper;
+import com.gyee.wisdom.alarm.sharding.model.AlarmHome;
 import com.gyee.wisdom.alarm.sharding.util.SnowflakeGenerator;
 import com.gyee.wisdom.common.utils.DateUtil;
 import com.gyee.wisdom.common.utils.StringUtil;
@@ -513,4 +515,40 @@ public class AlarmSnapService extends ServiceImpl<AlarmSnapMapper, AlarmSnap> {
         return alarmSnapMapper.getRecentAlarm(category1, lastUpdateTime);
     }
 
+    public Map<String,List<AlarmHome>> selectAlarmSnapCount(String stationId){
+
+        Map<String,List<AlarmHome>> stringListMap = new HashMap<>();
+        QueryWrapper<AlarmSnap> wrapper = new QueryWrapper<>();
+        if (StringUtil.isNotBlank(stationId))
+            wrapper.eq("STATIONID", stationId);
+        wrapper.eq("ISOPENED",1);
+        List<AlarmSnap> alarmSnaps = baseMapper.selectList(wrapper);
+        if (alarmSnaps.size() > 0){
+            Map<String,List<AlarmSnap>> map = alarmSnaps.stream().collect(Collectors.groupingBy(AlarmSnap::getCategory1));
+            for (Map.Entry<String,List<AlarmSnap>> entry : map.entrySet()) {
+                List<AlarmHome> alarmHomes = new ArrayList<>();
+                for (AlarmSnap alarmSnap : entry.getValue()) {
+                    AlarmHome alarmHome = new AlarmHome();
+                    alarmHome.setWindpowerstationName(alarmSnap.getStationName());
+                    alarmHome.setModelid(alarmSnap.getModelId());
+                    alarmHome.setWindturbineid(alarmSnap.getWindturbineId());
+                    alarmHome.setStationid(alarmSnap.getStationId());
+                    alarmHome.setDescription(alarmSnap.getAlertText());
+                    alarmHome.setLastUpdateTime(alarmSnap.getLastUpdateTime());
+                    alarmHome.setName(alarmSnap.getAlertText());
+                    alarmHomes.add(alarmHome);
+                }
+                stringListMap.put(entry.getKey(), alarmHomes);
+            }
+        }
+        return stringListMap;
+    }
+
+    public List<AlarmSnap> getAlarmSnap(String key) {
+        QueryWrapper<AlarmSnap> wrapper = new QueryWrapper<>();
+        if (StringUtil.isNotBlank(key))
+            wrapper.eq("WINDTURBINEID", key);
+        List<AlarmSnap> alarmSnaps = baseMapper.selectList(wrapper);
+        return alarmSnaps;
+    }
 }

+ 38 - 0
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/service/RiskSnapService.java

@@ -1,10 +1,19 @@
 package com.gyee.wisdom.alarm.sharding.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.gyee.wisdom.alarm.sharding.entity.RiskSnap;
 import com.gyee.wisdom.alarm.sharding.mapper.RiskSnapMapper;
+import com.gyee.wisdom.alarm.sharding.model.AlarmHome;
+import com.gyee.wisdom.alarm.sharding.util.StringUtil;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
 /**
  * @description:
  * @auther: Wanghs
@@ -12,4 +21,33 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class RiskSnapService extends ServiceImpl<RiskSnapMapper, RiskSnap> {
+
+    public Map<String, List<AlarmHome>> selectRiskSnapCount(String stationId){
+
+        Map<String,List<AlarmHome>> stringListMap = new HashMap<>();
+
+        QueryWrapper<RiskSnap> wrapper = new QueryWrapper<>();
+        if (StringUtil.isNotBlank(stationId))
+            wrapper.eq("windpowerstationId", stationId);
+        wrapper.eq("OPENED",1);
+        List<RiskSnap> riskSnaps = baseMapper.selectList(wrapper);
+        if(riskSnaps.size() > 0) {
+            Map<Integer, List<RiskSnap>> map = riskSnaps.stream().collect(Collectors.groupingBy(RiskSnap::getRank));
+            for (Map.Entry<Integer, List<RiskSnap>> entry : map.entrySet()) {
+                List<AlarmHome> alarmHomes = new ArrayList<>();
+                for (RiskSnap riskSnap : entry.getValue()) {
+                    AlarmHome alarmHome = new AlarmHome();
+                    alarmHome.setWindpowerstationName(riskSnap.getWindpowerstationName());
+                    alarmHome.setWindturbineid(riskSnap.getWindturbineId());
+                    alarmHome.setStationid(riskSnap.getWindpowerstationId());
+                    alarmHome.setDescription(riskSnap.getDescription());
+                    alarmHome.setName(riskSnap.getName());
+                    alarmHome.setLastUpdateTime(riskSnap.getLastUpdateTime());
+                    alarmHomes.add(alarmHome);
+                }
+                stringListMap.put(entry.getKey().toString(), alarmHomes);
+            }
+        }
+        return stringListMap;
+    }
 }

+ 15 - 0
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/service/Warning2Service.java

@@ -1,8 +1,10 @@
 package com.gyee.wisdom.alarm.sharding.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.wisdom.alarm.sharding.entity.AlarmSnap;
 import com.gyee.wisdom.alarm.sharding.entity.Alertrule2;
 import com.gyee.wisdom.alarm.sharding.entity.Scadafault;
 import com.gyee.wisdom.alarm.sharding.entity.Warning2;
@@ -11,10 +13,13 @@ import com.gyee.wisdom.alarm.sharding.mapper.ScadafaultMapper;
 import com.gyee.wisdom.alarm.sharding.mapper.Warning2Mapper;
 import com.gyee.wisdom.alarm.sharding.util.SnowflakeGenerator;
 import com.gyee.wisdom.alarm.sharding.util.UUIDUtil;
+import com.gyee.wisdom.common.utils.StringUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service
 public class Warning2Service extends ServiceImpl<Warning2Mapper, Warning2> {
     @Autowired
@@ -57,4 +62,14 @@ public class Warning2Service extends ServiceImpl<Warning2Mapper, Warning2> {
     public IPage<Warning2> pageQueryAll(Page page, String modelId, String name, String isLeaf) {
         return warning2Mapper.pageQueryAll(page, modelId, name, isLeaf);
     }
+
+    public Warning2 selectByModelidAndEdnvalue(String modelid,int ednValue) {
+        QueryWrapper<Warning2> wrapper = new QueryWrapper<>();
+        if (StringUtil.isNotBlank(modelid))
+            wrapper.eq("MODELID", modelid);
+        if (StringUtil.isNotBlank(ednValue))
+            wrapper.eq("EDNAVALUE", ednValue);
+        Warning2 warning2 = baseMapper.selectOne(wrapper);
+        return warning2;
+    }
 }

+ 6 - 0
warning-web/src/main/resources/mappers-oracle/AlarmHistoryMapper.xml

@@ -156,6 +156,12 @@
             and alerttime &gt;= #{starttime,jdbcType=DATE} and alerttime &lt; #{endtime,jdbcType=DATE}
     </select>
 
+    <select id="selectAlarmHistory" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.AlarmHistory">
+        select * from ${tbName} where snapid = #{snapid}
+                                  and messagetype = '1'
+                                  and alerttime &gt;= #{starttime,jdbcType=DATE} and alerttime &lt; #{endtime,jdbcType=DATE}
+    </select>
+
 
     <select id="selectHistoryAlarmSnapAndWarning"
             resultType="com.gyee.wisdom.alarm.sharding.entity.FaultWarning">

+ 14 - 0
warning-web/src/main/resources/mappers-oracle/AlarmPartsCountMapper.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.gyee.wisdom.alarm.sharding.mapper.AlarmPartsCountMapper">
+
+    <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false">
+        insert into alarmcount ( ID, alarmdate, count, parts,windturbineid )
+        <foreach collection="list" item="item" index="index" separator="union all" >
+            ( select
+            #{item.id}, #{item.alarmDate},#{item.count},#{item.parts},#{item.windturbineid}
+            from dual )
+        </foreach>
+    </insert>
+
+</mapper>