Browse Source

隐患分布和预警明细统计接口查询

‘xugp 2 years ago
parent
commit
dddd6cec7f
26 changed files with 533 additions and 24 deletions
  1. 1 0
      alarm/scadasnew/build.gradle
  2. 28 18
      warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/controller/HomeController.java
  3. 1 1
      warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/entity/AlarmPartsCount.java
  4. 27 0
      warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/entity/AlarmRuleCount.java
  5. 4 0
      warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/mapper/AlarmCountMapper.java
  6. 5 1
      warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/mapper/AlarmHisotryMapper.java
  7. 17 0
      warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/mapper/AlarmRuleCountMapper.java
  8. 20 0
      warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/model/AlarmCountStat.java
  9. 144 0
      warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/schedule/AlarmCountPartsScheduled.java
  10. 1 1
      warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/schedule/CreateTablesScheduled.java
  11. 118 0
      warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/service/AlarmCountService.java
  12. 5 1
      warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/service/AlarmHistoryService.java
  13. 12 0
      warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/service/AlarmSnapService.java
  14. 4 0
      warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/service/Alertrule2Service.java
  15. 12 0
      warning-web/src/main/resources/mappers-oracle/AlarmCountMapper.xml
  16. 18 0
      warning-web/src/main/resources/mappers-oracle/AlarmHistoryMapper.xml
  17. 2 2
      warning-web/src/main/resources/mappers-oracle/AlarmPartsCountMapper.xml
  18. 14 0
      warning-web/src/main/resources/mappers-oracle/AlarmRuleCountMapper.xml
  19. 13 0
      warning-web/src/main/resources/mappers-postgresql/AlarmCountMapper.xml
  20. 9 0
      warning-web/src/main/resources/mappers-postgresql/AlarmHistoryMapper.xml
  21. 14 0
      warning-web/src/main/resources/mappers-postgresql/AlarmPartsCountMapper.xml
  22. 14 0
      warning-web/src/main/resources/mappers-postgresql/AlarmRuleCountMapper.xml
  23. 13 0
      warning-web/src/main/resources/mappers/AlarmCountMapper.xml
  24. 9 0
      warning-web/src/main/resources/mappers/AlarmHistoryMapper.xml
  25. 14 0
      warning-web/src/main/resources/mappers/AlarmPartsCountMapper.xml
  26. 14 0
      warning-web/src/main/resources/mappers/AlarmRuleCountMapper.xml

+ 1 - 0
alarm/scadasnew/build.gradle

@@ -38,5 +38,6 @@ dependencies {
     testImplementation("$bootGroup:spring-boot-starter-test")
     implementation("io.github.openfeign:feign-core:$openFeignVersion")
     implementation("io.github.openfeign:feign-jackson:$openFeignVersion")
+    implementation 'org.postgresql:postgresql:42.4.0'
 }
 

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

@@ -1,18 +1,17 @@
 package com.gyee.wisdom.alarm.sharding.controller;
 
 import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.gyee.wisdom.alarm.sharding.entity.Alertrule2;
+import com.gyee.wisdom.alarm.sharding.model.AlarmCountStat;
 import com.gyee.wisdom.alarm.sharding.model.AlarmHome;
+import com.gyee.wisdom.alarm.sharding.service.AlarmCountService;
 import com.gyee.wisdom.alarm.sharding.service.AlarmSnapService;
-import com.gyee.wisdom.alarm.sharding.service.Alertrule2Service;
 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.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
@@ -37,19 +36,18 @@ public class HomeController {
     private RiskSnapService riskSnapService;
 
     @Autowired
-    private Alertrule2Service alertrule2Service;
+    private AlarmCountService alarmCountService;
 
 
     @Operation(description = "报警总数查询")
     @GetMapping("early/latest")
     public ResponseWrapper selectAlarmCount(
-            @Parameter(name = "stationId", description = "场站id")
-            @RequestParam(value = "stationId") String stationId
-    ) {
+            @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>> stringListMap = alarmSnapService.selectAlarmSnapCount(stationId);
             Map<String, List<AlarmHome>> stringListMap2 = riskSnapService.selectRiskSnapCount(stationId);
             stringListMap.putAll(stringListMap2);
             wrapper = ResponseWrapper.success("请求成功", stringListMap);
@@ -60,17 +58,29 @@ public class HomeController {
 
     }
 
-    @Operation(description = "风机部件查询接口")
-    @GetMapping("alertrule")
-    public ResponseWrapper selectAlertrule2(
-            @RequestParam(value = "station",required = false) String station,
-            @RequestParam(value = "modelid",required = false) String modelid
-    ) {
+    @Operation(description = "首页明细分析")
+    @GetMapping("/total/duration")
+    public ResponseWrapper selectTotalDuration(){
 
         ResponseWrapper wrapper = null;
         try {
-            Map<String,Integer> alertrule2s = alertrule2Service.queryList(station,modelid);
-            wrapper = ResponseWrapper.success("请求成功", alertrule2s);
+            List<AlarmCountStat> alarmCountStatList = alarmCountService.selectTotalDuration();
+            wrapper = ResponseWrapper.success("请求成功", alarmCountStatList);
+        } catch (Exception ex) {
+            wrapper = ResponseWrapper.error("请求失败", JSON.toJSONString(ex.getStackTrace()));
+        }
+        return wrapper;
+
+    }
+
+    @Operation(description = "首页隐患分布")
+    @GetMapping("/hidden/danger")
+    public ResponseWrapper hiddeDanger(){
+
+        ResponseWrapper wrapper = null;
+        try {
+            Map<String, Double> map = alarmCountService.hiddeDanger();
+            wrapper = ResponseWrapper.success("请求成功", map);
         } catch (Exception ex) {
             wrapper = ResponseWrapper.error("请求失败", JSON.toJSONString(ex.getStackTrace()));
         }
@@ -78,5 +88,5 @@ public class HomeController {
 
     }
 
-}
 
+}

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

@@ -19,7 +19,7 @@ public class AlarmPartsCount implements Serializable{
     @TableField("COUNT")
     private int count;
     @TableField("WINDTURBINEID")
-    private String windturbineid;
+    private String windturbineId;
 
 
 }

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

@@ -0,0 +1,27 @@
+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 AlarmRuleCount implements Serializable{
+
+    @TableId("ID")
+    private Long id;
+    @TableField("ALARMDATE")
+    private Date alarmDate;
+    @TableField("PARTS")
+    private String parts;
+    @TableField("RULESID")
+    private String rulesId;
+    @TableField("COUNT")
+    private int count;
+    @TableField("WINDTURBINEID")
+    private String windturbineId;
+
+
+}

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

@@ -57,4 +57,8 @@ public interface AlarmCountMapper extends BaseMapper<AlarmCount> {
 
     List<AlarmCountInfo> getAlarmCountInfo(@Param("windturbineid")String wtId,
                                          @Param("currentDate") Date currentDate);
+
+    AlarmCount selectBySnapId(@Param("id") long id,
+                                     @Param("dtStart") Date dtStart,
+                                     @Param("dtEnd") Date dtEnd);
 }

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

@@ -54,7 +54,10 @@ public interface AlarmHisotryMapper extends BaseMapper<AlarmHistory> {
                         @Param("starttime") Date startTime,
                         @Param("endtime") Date endTime);
 
-    AlarmHistory selectAlarmHistory(@Param("tbName") String tableName,
+    int selectAlarmSnapCount(@Param("tbName") String tableName,
+                        @Param("id") Long id);
+
+    List<AlarmHistory> selectAlarmHistory(@Param("tbName") String tableName,
                         @Param("snapid") Long snapid,
                         @Param("starttime") Date startTime,
                         @Param("endtime") Date endTime);
@@ -89,4 +92,5 @@ public interface AlarmHisotryMapper extends BaseMapper<AlarmHistory> {
 
     List<AlarmHistory> getAlarmHistoryList(@Param("tbName") String  tbName,@Param("snapIdList") List<Long> snapIdList,@Param("messageType")String messageType,@Param("startTime")Date startTime,@Param("endTime")Date endTime);
 
+    AlarmHistory queryByIdAndTname(@Param("tbName") String tbName, @Param("snapId") Long snapId);
 }

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

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

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

@@ -0,0 +1,20 @@
+package com.gyee.wisdom.alarm.sharding.model;
+
+import lombok.Data;
+
+/**
+ * @author :xugp
+ * @date :Created in 2022/9/12 11:08
+ * @description:
+ * @modified By:
+ * @version: $
+ */
+@Data
+public class AlarmCountStat {
+
+    private String windturbineId;
+    private String windturbineName;
+    private double time;
+    private int count;
+
+}

+ 144 - 0
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/schedule/AlarmCountPartsScheduled.java

@@ -0,0 +1,144 @@
+package com.gyee.wisdom.alarm.sharding.schedule;
+
+import com.gyee.wisdom.alarm.sharding.entity.*;
+import com.gyee.wisdom.alarm.sharding.mapper.AlarmPartsCountMapper;
+import com.gyee.wisdom.alarm.sharding.mapper.AlarmRuleCountMapper;
+import com.gyee.wisdom.alarm.sharding.service.AlarmHistoryService;
+import com.gyee.wisdom.alarm.sharding.service.AlarmSnapService;
+import com.gyee.wisdom.alarm.sharding.service.TableNameService;
+import com.gyee.wisdom.alarm.sharding.service.Warning2Service;
+import com.gyee.wisdom.alarm.sharding.util.SnowflakeGenerator;
+import com.gyee.wisdom.common.utils.DateUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+import org.w3c.dom.ls.LSInput;
+
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author :xugp
+ * @date :Created in 2022/9/8 10:15
+ * @description:报警信息统计,根据部件、规则统计发生报警次数
+ * @modified By:
+ * @version: $
+ */
+@Component
+@Slf4j
+@EnableScheduling
+public class AlarmCountPartsScheduled {
+
+    @Autowired
+    private AlarmSnapService alarmSnapService;
+
+    @Autowired
+    private TableNameService tableNameService;
+
+    @Autowired
+    private AlarmPartsCountMapper alarmPartsCountMapper;
+
+    @Autowired
+    private AlarmRuleCountMapper alarmRuleCountMapper;
+
+    @Autowired
+    private Warning2Service warning2Service;
+
+
+    @Autowired
+    private AlarmHistoryService alarmHistoryService;
+    @Scheduled(cron = "* 46 17 ? * 5")
+    public boolean doTask() {
+
+        try {
+            List<AlarmSnap> snapList = alarmSnapService.queryAll(null, null, "windturbine", null, null, null, null, null, null, null);
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            String strDate = sdf.format(DateUtil.addDays(new Date(),-1));
+            Date dtStart = sdf.parse(strDate);
+            Date dtEnd = DateUtil.addDays(dtStart, 1);
+            Date dtNow = new Date();
+            while (dtEnd.getTime() < dtNow.getTime()) {
+                List<AlarmPartsCount> acList = new ArrayList<>();
+                List<AlarmRuleCount> alarmRuleCounts = new ArrayList<>();
+                Map<String,List<AlarmHistory>> map = new HashMap<>();
+                //根据windturbineid分组
+                Map<String,List<AlarmSnap>> maps = snapList.stream().collect(Collectors.groupingBy(AlarmSnap::getWindturbineId));
+                for (Map.Entry<String,List<AlarmSnap>> listEntry : maps.entrySet()) {
+                    List<AlarmSnap> alarmSnap = alarmSnapService.getAlarmSnap(listEntry.getKey());
+                    List<AlarmHistory> alarmHistories = new ArrayList<>();
+                    for(AlarmSnap snap : alarmSnap){
+                        String tbName = tableNameService.getAlarmHistoryTableName(snap.getStationId(), dtStart);
+                        List<AlarmHistory> alarmHistories1 = alarmHistoryService.selectAlarmHistory(tbName, snap.getId(), dtStart, dtEnd);
+                        alarmHistories.addAll(alarmHistories1);
+                    }
+                    map.put(listEntry.getKey(),alarmHistories);
+                }
+                //遍历map(key:windturbined,value:history)
+                for (Map.Entry<String,List<AlarmHistory>> entry : map.entrySet()){
+                    Map<String,String> map1 = new HashMap<>();
+                    List<AlarmHistory> value = entry.getValue();
+                    for (AlarmHistory alarmHistory : value){
+                        AlarmSnap alarmSnap = alarmSnapService.queryById(alarmHistory.getSnapId());
+                        Warning2 warning2 = warning2Service.selectByModelidAndEdnvalue(alarmSnap.getModelId(),alarmSnap.getAlertValue());
+                        String id = alarmHistory.getId() + "_" + alarmHistory.getSnapId();
+                        map1.put(id, warning2.getRelatedParts());
+                    }
+                    //分组转化为key:parts,value:snapId
+                    Map<String, List<Map.Entry<String,String>>> result = map1.entrySet().stream().collect(Collectors.groupingBy(c -> c.getValue()));
+                    for (Map.Entry<String, List<Map.Entry<String,String>>> entry1 : result.entrySet()) {
+                        List<Map.Entry<String, String>> listValue = entry1.getValue();
+                        int count = 0;
+                        List<String> list = new ArrayList<>();
+                        for (Map.Entry<String, String> map2 : listValue) {
+                            String[] split = map2.getKey().split("_");
+                            long l = Long.parseLong(split[1]);
+                            AlarmSnap alarmSnap = alarmSnapService.queryById(l);
+                            Warning2 warning2 = warning2Service.selectByModelidAndEdnvalue(alarmSnap.getModelId(), alarmSnap.getAlertValue());
+                            String tbName = tableNameService.getAlarmHistoryTableName(alarmSnap.getStationId(), dtStart);
+                            count = count + alarmHistoryService.selectAlarmSnapCount(tbName,Long.parseLong(split[0]));
+                            list.add(warning2.getId());
+                        }
+                        Map<String, Integer> mapCount = list.stream().collect(Collectors.toMap(key -> key, values -> 1, (value1,value2) ->value1 + value2));
+                        for(Map.Entry<String,Integer> entryString : mapCount.entrySet()){
+                            //统计某一种规则的报警次数
+                            AlarmRuleCount alarmRuleCount = new AlarmRuleCount();
+                            alarmRuleCount.setId(SnowflakeGenerator.generateId());
+                            alarmRuleCount.setAlarmDate(dtStart);
+                            alarmRuleCount.setParts(entry1.getKey());
+                            alarmRuleCount.setRulesId(entryString.getKey());
+                            alarmRuleCount.setCount(entryString.getValue());
+                            alarmRuleCount.setWindturbineId(entry.getKey());
+                            alarmRuleCounts.add(alarmRuleCount);
+                        }
+                        if (count > 0) {
+                            //统计部件分类的部件次数
+                            AlarmPartsCount alarmPartsCount = new AlarmPartsCount();
+                            alarmPartsCount.setId(SnowflakeGenerator.generateId());
+                            alarmPartsCount.setAlarmDate(dtStart);
+                            alarmPartsCount.setParts(entry1.getKey());
+                            alarmPartsCount.setCount(count);
+                            alarmPartsCount.setWindturbineId(entry.getKey());
+                            acList.add(alarmPartsCount);
+                        }
+                    }
+                }
+                if (alarmRuleCounts.size() > 0)
+                    alarmRuleCountMapper.batchInsert(alarmRuleCounts);
+                if (acList.size() > 0)
+                    alarmPartsCountMapper.batchInsert(acList);
+                dtStart = dtEnd;
+                dtEnd = DateUtil.addDays(dtStart, 1);
+            }
+
+        } catch(Exception ex){
+            log.error(ex.getMessage());
+            log.error(ex.getStackTrace().toString());
+            return false;
+        }
+
+        return true;
+    }
+}

+ 1 - 1
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/schedule/CreateTablesScheduled.java

@@ -17,7 +17,7 @@ public class CreateTablesScheduled {
     @Value("${tablespace}")
     String tablespace;
     //秒 分 时 日 月 周
-    @Scheduled(cron="0 45 11 * * 1")
+    @Scheduled(cron="0 34 11 * * 5")
     public void doTask(){
         Calendar instance = Calendar.getInstance();
         //查看当前时间的下月是否有表,没有就创建

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

@@ -7,11 +7,14 @@ import com.gyee.wisdom.alarm.sharding.cache.WindturbineCache;
 import com.gyee.wisdom.alarm.sharding.entity.*;
 import com.gyee.wisdom.alarm.sharding.mapper.AlarmCountMapper;
 import com.gyee.wisdom.alarm.sharding.mapper.AlarmHisotryMapper;
+import com.gyee.wisdom.alarm.sharding.model.AlarmCountStat;
 import com.gyee.wisdom.alarm.sharding.model.AlarmHistoryInfo;
 import com.gyee.wisdom.alarm.sharding.model.CodeValue;
+import com.gyee.wisdom.alarm.sharding.util.ResponseWrapper;
 import com.gyee.wisdom.alarm.sharding.util.SnowflakeGenerator;
 import com.gyee.wisdom.common.utils.DateUtil;
 import com.gyee.wisdom.common.utils.StringUtil;
+import io.swagger.v3.oas.annotations.Parameter;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -49,10 +52,125 @@ public class AlarmCountService extends ServiceImpl<AlarmCountMapper, AlarmCount>
     @Autowired
     private WindturbineService windturbineService;
 
+    @Autowired
+    private Alertrule2Service alertrule2Service;
+
 
     @Value("${count.custom}")
     public boolean custom;
 
+    @Value("${homestat.alertIds}")
+    private String alertIds;
+
+    public List<AlarmSnap> getAllSnap(){
+        //分解规则id
+        String[] split = alertIds.split(",");
+        List<Alertrule2> alertrule2s = new ArrayList<>();
+        for (String id : split){
+            Alertrule2 alertrule2 = alertrule2Service.selectByAlertrule2Id(id);
+            if (alertrule2 != null){
+                alertrule2s.add(alertrule2);
+            }
+        }
+        //根据alertrule2的alertvalue得到alarmsnap
+        List<AlarmSnap> alarmSnaps = new ArrayList<>();
+        for (Alertrule2 alertrule2 :alertrule2s){
+            alarmSnaps.addAll(alarmSnapService.selectByAlertValue(alertrule2.getEdnaValue()));
+        }
+        return alarmSnaps;
+    }
+
+    public Map<String,Double> hiddeDanger(){
+        try {
+            Map<String,Double> doubleMap =new HashMap<>();
+            List<AlarmSnap> alarmSnaps = getAllSnap();
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            String strDate = sdf.format(DateUtil.addDays(new Date(),-1));
+            Date dtStart = sdf.parse(strDate);
+            Date dtEnd = DateUtil.addDays(dtStart, 1);
+            Map<String,List<AlarmSnap>> map = alarmSnaps.stream().collect(Collectors.groupingBy(AlarmSnap::getCategory3));
+            for (Map.Entry<String,List<AlarmSnap>> stringListMap : map.entrySet()){
+                double time = 0;
+                for (AlarmSnap alarmSnap : stringListMap.getValue()){
+                    AlarmCount alarmCount = alarmCountMapper.selectBySnapId(alarmSnap.getId(), dtStart, dtEnd);
+                    if (alarmCount != null){
+                        time = time + alarmCount.getTime();
+                    }
+                }
+                doubleMap.put(stringListMap.getKey(),time);
+            }
+            return doubleMap;
+        }catch (Exception ex) {
+            log.error(ex.getMessage());
+            log.error(ex.getStackTrace().toString());
+            return null;
+        }
+    }
+
+    public List<AlarmCountStat> selectTotalDuration() {
+        try {
+            List<AlarmSnap> alarmSnaps = getAllSnap();
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            String strDate = sdf.format(DateUtil.addDays(new Date(),-1));
+            Date dtStart = sdf.parse(strDate);
+            Date dtEnd = DateUtil.addDays(dtStart, 1);
+            List<AlarmCountStat> oldList = new ArrayList<>();
+            for (AlarmSnap alarmSnap : alarmSnaps){
+                AlarmCount alarmCount = selectBySnapId(alarmSnap.getId(), dtStart, dtEnd);
+                if (alarmCount != null){
+                    AlarmCountStat alarmCountStat = new AlarmCountStat();
+                    alarmCountStat.setWindturbineId(alarmSnap.getWindturbineId());
+                    alarmCountStat.setWindturbineName(alarmSnap.getWindturbineName());
+                    alarmCountStat.setCount(alarmCount.getCount());
+                    alarmCountStat.setTime(alarmCount.getTime());
+                    oldList.add(alarmCountStat);
+                }
+
+            }
+            //对重复的风机号进行合并
+            List<AlarmCountStat> newList = new ArrayList<>();
+            for (AlarmCountStat oldAlarmCountStat : oldList) {
+                // 遍历新的List,看是否存在,存在则相加,不存在则放入新的List
+                boolean flag = false;
+                if (newList.size() > 0){
+                    for (AlarmCountStat newAlarmCountStat : newList) {
+                        if (newAlarmCountStat.getWindturbineId().equals(oldAlarmCountStat.getWindturbineId())) {
+                            newAlarmCountStat.setCount(newAlarmCountStat.getCount()+oldAlarmCountStat.getCount());
+                            newAlarmCountStat.setTime(newAlarmCountStat.getTime()+oldAlarmCountStat.getTime());
+                            flag = true;
+                        }
+                    }
+                }
+                if (!flag){
+                    AlarmCountStat alarmCountStat = new AlarmCountStat();
+                    alarmCountStat.setWindturbineId(oldAlarmCountStat.getWindturbineId());
+                    alarmCountStat.setWindturbineName(oldAlarmCountStat.getWindturbineName());
+                    alarmCountStat.setCount(oldAlarmCountStat.getCount());
+                    alarmCountStat.setTime(oldAlarmCountStat.getTime());
+                    newList.add(alarmCountStat);
+                }
+            }
+            //对集合进行降序排序,取前十个
+            Collections.sort(newList,new Comparator<AlarmCountStat>(){
+                @Override
+                public int compare(AlarmCountStat o1, AlarmCountStat o2) {
+                //会把集合里面的对象两两传进方法里面比较,这里比较age,降序就O2-O1,升序就O1-O2
+                    return (int) (o2.getTime()-o1.getTime());
+                }
+            });
+            List<AlarmCountStat> limitlist = newList.stream().limit(10).collect(Collectors.toList());
+        return limitlist;
+    }catch (Exception ex) {
+            log.error(ex.getMessage());
+            log.error(ex.getStackTrace().toString());
+            return null;
+        }
+    }
+
+    public AlarmCount selectBySnapId(long id,Date dtStart,Date dtEnd){
+        return alarmCountMapper.selectBySnapId(id,dtStart,dtEnd);
+    }
+
     public boolean startCount(String strDate) {
         try {
             List<AlarmSnap> snapList = alarmSnapService.queryAll(null, null, "custom", null, null, null, null, null, null, null);

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

@@ -192,10 +192,14 @@ 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) {
+    public List<AlarmHistory> selectAlarmHistory(String tbName, Long id, Date dtStart, Date dtEnd) {
         return alarmHisotryMapper.selectAlarmHistory(tbName,id,dtStart,dtEnd);
     }
 
+    public int selectAlarmSnapCount(String tableName, long id) {
+        return  alarmHisotryMapper.selectAlarmSnapCount(tableName, id);
+    }
+
     //宁夏定制化功能 暂时干掉
 //    @Scheduled(cron = "0 */2 * * * ?")
 //   public Map<String, String> getTodayCount() throws Exception{

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

@@ -519,9 +519,13 @@ public class AlarmSnapService extends ServiceImpl<AlarmSnapMapper, AlarmSnap> {
 
         Map<String,List<AlarmHome>> stringListMap = new HashMap<>();
         QueryWrapper<AlarmSnap> wrapper = new QueryWrapper<>();
+        List<String> strings = new ArrayList<>();
+        strings.add("windturbine");
+        strings.add("SYZ");
         if (StringUtil.isNotBlank(stationId))
             wrapper.eq("STATIONID", stationId);
         wrapper.eq("ISOPENED",1);
+        wrapper.in("CATEGORY1",strings);
         List<AlarmSnap> alarmSnaps = baseMapper.selectList(wrapper);
         if (alarmSnaps.size() > 0){
             Map<String,List<AlarmSnap>> map = alarmSnaps.stream().collect(Collectors.groupingBy(AlarmSnap::getCategory1));
@@ -551,4 +555,12 @@ public class AlarmSnapService extends ServiceImpl<AlarmSnapMapper, AlarmSnap> {
         List<AlarmSnap> alarmSnaps = baseMapper.selectList(wrapper);
         return alarmSnaps;
     }
+
+    public List<AlarmSnap> selectByAlertValue(int alertValue) {
+        QueryWrapper<AlarmSnap> wrapper = new QueryWrapper<>();
+        if (StringUtil.isNotBlank(alertValue+""))
+            wrapper.eq("ALERTVALUE", alertValue);
+        List<AlarmSnap> alarmSnaps = baseMapper.selectList(wrapper);
+        return alarmSnaps;
+    }
 }

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

@@ -236,4 +236,8 @@ public class Alertrule2Service extends ServiceImpl<Alertrule2Mapper, Alertrule2>
 
         return list;
     }
+
+    public Alertrule2 selectByAlertrule2Id(String id) {
+        return alertrule2Mapper.selectByAlertrule2Id(id);
+    }
 }

+ 12 - 0
warning-web/src/main/resources/mappers-oracle/AlarmCountMapper.xml

@@ -132,4 +132,16 @@
         AND s.windturbineid = #{windturbineid}
     </select>
 
+    <select id="selectBySnapId" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.AlarmCount">
+        select * from alarmcount a
+        <where>
+            1=1
+            <if test="dtStart !=null and dtEnd !=null">
+                and a.alarmdate &gt;= #{dtStart,jdbcType=DATE} and a.alarmdate &lt;= #{dtEnd,jdbcType=DATE}
+            </if>
+            <if test="id !=null and id !=''">
+                and a.snapid=#{id}
+            </if>
+        </where>
+    </select>
 </mapper>

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

@@ -156,6 +156,10 @@
             and alerttime &gt;= #{starttime,jdbcType=DATE} and alerttime &lt; #{endtime,jdbcType=DATE}
     </select>
 
+    <select id="selectAlarmSnapCount" parameterType="java.util.Map" resultType="java.lang.Integer">
+        select count(*) from ${tbName} where id = #{id}
+    </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'
@@ -277,6 +281,20 @@
 
     </select>
 
+    <select id="queryByIdAndTname" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.model.AlarmHistoryInfo">
+
+        select * from (
+        SELECT * FROM  ${tbName} a
+        <where>
+            <if test="snapId !=null and snapId !=''">
+                and a.SNAPID=#{snapId}
+            </if>
+        </where>
+        order by a.ALERTTIME DESC)
+        where ROWNUM=1
+
+    </select>
+
     <select id="getAlarmHistoryList" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.model.AlarmHistoryInfo">
         SELECT * FROM  ${tbName} a
         <where>

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

@@ -3,10 +3,10 @@
 <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 )
+        insert into alarmpartscount ( ID, alarmdate, parts,count,windturbineid )
         <foreach collection="list" item="item" index="index" separator="union all" >
             ( select
-            #{item.id}, #{item.alarmDate},#{item.count},#{item.parts},#{item.windturbineid}
+            #{item.id}, #{item.alarmDate},#{item.parts},#{item.count},#{item.windturbineId}
             from dual )
         </foreach>
     </insert>

+ 14 - 0
warning-web/src/main/resources/mappers-oracle/AlarmRuleCountMapper.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.AlarmRuleCountMapper">
+
+    <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false">
+        insert into alarmrulecount ( ID, alarmdate, parts,rulesid,count,windturbineid)
+        <foreach collection="list" item="item" index="index" separator="union all" >
+            ( select
+            #{item.id}, #{item.alarmDate},#{item.parts},#{item.rulesId},#{item.count},#{item.windturbineId}
+            from dual )
+        </foreach>
+    </insert>
+
+</mapper>

+ 13 - 0
warning-web/src/main/resources/mappers-postgresql/AlarmCountMapper.xml

@@ -132,4 +132,17 @@
         AND s.windturbineid = #{windturbineid}
     </select>
 
+    <select id="selectBySnapId" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.AlarmCount">
+        select * from alarmcount a
+        <where>
+            1=1
+            <if test="dtStart !=null and dtEnd !=null">
+                and a.alarmdate &gt;= #{dtStart,jdbcType=DATE} and a.alarmdate &lt;= #{dtEnd,jdbcType=DATE}
+            </if>
+            <if test="id !=null and id !=''">
+                and a.snapid=#{id}
+            </if>
+        </where>
+    </select>
+
 </mapper>

+ 9 - 0
warning-web/src/main/resources/mappers-postgresql/AlarmHistoryMapper.xml

@@ -150,6 +150,15 @@
             and alerttime &gt;= #{starttime,jdbcType=DATE} and alerttime &lt; #{endtime,jdbcType=DATE}
     </select>
 
+    <select id="selectAlarmSnapCount" parameterType="java.util.Map" resultType="java.lang.Integer">
+        select count(*) from ${tbName} where id = #{id}
+    </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-postgresql/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 alarmpartscount ( ID, alarmdate, parts,count,windturbineid )
+        <foreach collection="list" item="item" index="index" separator="union all" >
+            ( select
+            #{item.id}, #{item.alarmDate},#{item.parts},#{item.count},#{item.windturbineId}
+            from dual )
+        </foreach>
+    </insert>
+
+</mapper>

+ 14 - 0
warning-web/src/main/resources/mappers-postgresql/AlarmRuleCountMapper.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.AlarmRuleCountMapper">
+
+    <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false">
+        insert into alarmrulecount ( ID, alarmdate, parts,rulesid,count,windturbineid)
+        <foreach collection="list" item="item" index="index" separator="union all" >
+            ( select
+            #{item.id}, #{item.alarmDate},#{item.parts},#{item.rulesId},#{item.count},#{item.windturbineId}
+            from dual )
+        </foreach>
+    </insert>
+
+</mapper>

+ 13 - 0
warning-web/src/main/resources/mappers/AlarmCountMapper.xml

@@ -132,4 +132,17 @@
         AND s.windturbineid = #{windturbineid}
     </select>
 
+    <select id="selectBySnapId" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.AlarmCount">
+        select * from alarmcount a
+        <where>
+            1=1
+            <if test="dtStart !=null and dtEnd !=null">
+                and a.alarmdate &gt;= #{dtStart,jdbcType=DATE} and a.alarmdate &lt;= #{dtEnd,jdbcType=DATE}
+            </if>
+            <if test="id !=null and id !=''">
+                and a.snapid=#{id}
+            </if>
+        </where>
+    </select>
+
 </mapper>

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

@@ -150,6 +150,15 @@
             and alerttime &gt;= #{starttime,jdbcType=DATE} and alerttime &lt; #{endtime,jdbcType=DATE}
     </select>
 
+    <select id="selectAlarmSnapCount" parameterType="java.util.Map" resultType="java.lang.Integer">
+        select count(*) from ${tbName} where id = #{id}
+    </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/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 alarmpartscount ( ID, alarmdate, parts,count,windturbineid )
+        <foreach collection="list" item="item" index="index" separator="union all" >
+            ( select
+            #{item.id}, #{item.alarmDate},#{item.parts},#{item.count},#{item.windturbineId}
+            from dual )
+        </foreach>
+    </insert>
+
+</mapper>

+ 14 - 0
warning-web/src/main/resources/mappers/AlarmRuleCountMapper.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.AlarmRuleCountMapper">
+
+    <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false">
+        insert into alarmrulecount ( ID, alarmdate, parts,rulesid,count,windturbineid)
+        <foreach collection="list" item="item" index="index" separator="union all" >
+            ( select
+            #{item.id}, #{item.alarmDate},#{item.parts},#{item.rulesId},#{item.count},#{item.windturbineId}
+            from dual )
+        </foreach>
+    </insert>
+
+</mapper>