Browse Source

修正升压站报警异常

shilin 1 year ago
parent
commit
e0bbfe97e6
33 changed files with 3458 additions and 28298 deletions
  1. 37 15
      alarm-scanner/src/main/java/com/gyee/alarm/model/vo/AlarmTag.java
  2. 4 4
      alarm-scanner/src/main/java/com/gyee/alarm/service/AlarmScannerService.java
  3. 6 5
      alarm-scanner/src/main/resources/application-wt.yml
  4. 1 1
      alarm-scanner/src/main/resources/application.yml
  5. 13 2
      alarm-scanner/src/test/java/com/gyee/AppTest.java
  6. 8 8
      alarm-service/src/main/java/com/gyee/alarm/controller/AlarmController.java
  7. 2 2
      alarm-service/src/main/java/com/gyee/alarm/controller/WebSocketController.java
  8. 4 1
      alarm-service/src/main/java/com/gyee/alarm/model/auto/ProEconAlarmInfo.java
  9. 123 13
      alarm-service/src/main/java/com/gyee/alarm/service/AlarmBtService.java
  10. 156 19
      alarm-service/src/main/java/com/gyee/alarm/service/AlarmCtService.java
  11. 121 4
      alarm-service/src/main/java/com/gyee/alarm/service/AlarmInService.java
  12. 179 94
      alarm-service/src/main/java/com/gyee/alarm/service/AlarmWtService.java
  13. 108 118
      alarm-service/src/main/java/com/gyee/alarm/service/PushDataSevice.java
  14. 69 15
      alarm-service/src/main/java/com/gyee/alarm/websocket/WebSocket.java
  15. 191 191
      alarm-service/src/main/java/com/gyee/alarm/websocket/WebSocketBt.java
  16. 5 4
      alarm-service/src/main/resources/application-jn.yml
  17. 38 7
      alarm-service/src/test/java/com/gyee/AppTest.java
  18. 145 0
      alarm-web/src/main/java/com/gyee/alarm/controller/AlarmHistoryController.java
  19. 172 0
      alarm-web/src/main/java/com/gyee/alarm/controller/ProEconAlarmInfoController.java
  20. 17 0
      alarm-web/src/main/java/com/gyee/alarm/init/CacheContext.java
  21. 57 0
      alarm-web/src/main/java/com/gyee/alarm/mapper/auto/AlarmTsMapper.java
  22. 58 0
      alarm-web/src/main/java/com/gyee/alarm/mapper/auto/ProEconAlarmInfoMapper.java
  23. 4 1
      alarm-web/src/main/java/com/gyee/alarm/model/auto/ProEconAlarmInfo.java
  24. 1 1
      alarm-web/src/main/java/com/gyee/alarm/model/vo/AlarmStatVo.java
  25. 182 0
      alarm-web/src/main/java/com/gyee/alarm/model/vo/ProEconAlarmInfoVo.java
  26. 250 6
      alarm-web/src/main/java/com/gyee/alarm/service/AlarmHistoryService.java
  27. 28 28
      alarm-web/src/main/java/com/gyee/alarm/service/TokenService.java
  28. 23 0
      alarm-web/src/main/java/com/gyee/alarm/service/auto/IProEconAlarmInfoService.java
  29. 105 0
      alarm-web/src/main/java/com/gyee/alarm/service/auto/impl/ProEconAlarmInfoServiceImpl.java
  30. 1351 27759
      log/ota.log
  31. BIN
      log/ota.log.2023-10-02.0.gz
  32. BIN
      log/ota.log.2023-10-03.0.gz
  33. BIN
      log/ota.log.2023-10-05.0.gz

+ 37 - 15
alarm-scanner/src/main/java/com/gyee/alarm/model/vo/AlarmTag.java

@@ -121,8 +121,20 @@ public class AlarmTag {
         {
             log.info("tagId_"+tagId+"_wpId_"+wpId+"_ts_"+ts+"_val_"+pointData.getPointValueInDouble());
         }
+        if(StringUtils.notEmp(uniformCode) && uniformCode.startsWith("BI")){
 
-        if(triggerType==-1)
+            int decimal = oval.intValue(); // 十进制报警数
+            String binary = intToBinary32(decimal, 32); // 转换为二进制报警字符串
+
+            String reverse = new StringBuffer(binary).reverse().toString();//翻转字符串,便于报警分析
+            int value = (int) reverse.charAt(triggerType)-48;
+            if (value == 1) {
+                val=1.0;
+            }else {
+                val=0.0;
+            }
+
+        }else  if(triggerType==-1)
         {
             val=1.0;
         }else  if(triggerType==0)
@@ -145,19 +157,6 @@ public class AlarmTag {
                 val=0.0;
 
             }
-        }else if(StringUtils.notEmp(uniformCode) && uniformCode.startsWith("BI")){
-
-            int decimal = oval.intValue(); // 十进制报警数
-            String binary = Integer.toString(decimal, 2); // 转换为二进制报警字符串
-
-            String reverse = new StringBuffer(binary).reverse().toString();//翻转字符串,便于报警分析
-            int value = Integer.valueOf(reverse.charAt(triggerType));
-            if (value == 1) {
-                val=1.0;
-            }else {
-                val=0.0;
-            }
-
         }else {
             if (oval.intValue() == triggerType) {
                 val=1.0;
@@ -183,7 +182,20 @@ public class AlarmTag {
 //        {
 //            log.info("tagId_"+tagId+"_wpId_"+wpId+"_ts_"+ts+"_val_"+pointData.getPointValueInDouble());
 //        }
-        if(triggerType==-1)
+        if(StringUtils.notEmp(uniformCode) && uniformCode.startsWith("BI")){
+
+            int decimal = oval.intValue(); // 十进制报警数
+            String binary = intToBinary32(decimal, 32); // 转换为二进制报警字符串
+
+            String reverse = new StringBuffer(binary).reverse().toString();//翻转字符串,便于报警分析
+            int value = (int) reverse.charAt(triggerType)-48;
+            if (value == 1) {
+                val=1.0;
+            }else {
+                val=0.0;
+            }
+
+        }else if(triggerType==-1)
         {
             val=1.0;
         }else  if(triggerType==0)
@@ -217,4 +229,14 @@ public class AlarmTag {
 
         return true;
     }
+
+
+    // i 是要转换的整数,bitNum 是期望的二进制字符串位数
+    public  String intToBinary32(int i, int bitNum) {
+        String binaryStr = Integer.toBinaryString(i);
+        while (binaryStr.length() < bitNum) {
+            binaryStr = "0" + binaryStr;
+        }
+        return binaryStr;
+    }
 }

+ 4 - 4
alarm-scanner/src/main/java/com/gyee/alarm/service/AlarmScannerService.java

@@ -102,12 +102,12 @@ public class AlarmScannerService {
 
 
         List<AlarmSimpleVo> alarmvols = new CopyOnWriteArrayList<>();
-        AtomicInteger times = new AtomicInteger(0);
+        int times = 0;
         for (AlarmTag alarm : tags) {
 
             sb.append("'").append(alarm.getId().toLowerCase()).append("',");
-            times.getAndAdd(1);
-            if (times.get() == 1000) {
+            times++;
+            if (times  == 1000) {
                 String ids = sb.substring(0, sb.length() - 1);
                 List<AlarmSimpleVo> templs = new CopyOnWriteArrayList<>();
                 if (alarm.getAlarmType().equals(AlarmTypeValue.BT.getCode())) {
@@ -119,7 +119,7 @@ public class AlarmScannerService {
                 }
                 alarmvols.addAll(templs);
                 sb.setLength(0);
-                times.set(0);
+                times=0;
             }
         }
 

+ 6 - 5
alarm-scanner/src/main/resources/application-wt.yml

@@ -134,13 +134,14 @@ logging:
 
 #db url
 db:
-  url1: http://10.81.3.160:8011/ts
-  url2: http://10.81.3.160:8012/ts
-
+  url1: http://10.81.3.154:8011/ts
+  url2: http://10.81.3.154:8012/ts
+#  url1: http://127.0.0.1:8011/ts
+#  url2: http://127.0.0.1:8011/ts
 
 #参与计算的场站
-#runWindpowerstation: SXJ_KGDL_GJY_FDC_STA
-runWindpowerstation: SXJ_KGDL_YLZ_FDC_STA,SXJ_KGDL_YTY_FDC_STA,NMM_KGDL_MLJ_FDC_STA,SXJ_KGDL_PDL_FDC_STA,SXJ_KGDL_XWT_FDC_STA,SXJ_KGDL_GJY_FDC_STA
+runWindpowerstation: SXJ_KGDL_HSM_FDC_STA
+#runWindpowerstation: SXJ_KGDL_YLZ_FDC_STA,SXJ_KGDL_YTY_FDC_STA,NMM_KGDL_MLJ_FDC_STA,SXJ_KGDL_PDL_FDC_STA,SXJ_KGDL_XWT_FDC_STA,SXJ_KGDL_GJY_FDC_STA
 #计算状态用ai或者di
 clauStatus:
   ai: GJY03_GC,YLZ01_GC,PTZ02_GC   #配置期次

+ 1 - 1
alarm-scanner/src/main/resources/application.yml

@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: bt
+    active: wt

File diff suppressed because it is too large
+ 13 - 2
alarm-scanner/src/test/java/com/gyee/AppTest.java


+ 8 - 8
alarm-service/src/main/java/com/gyee/alarm/controller/AlarmController.java

@@ -76,42 +76,42 @@ public class AlarmController {
     }
 
     @PostMapping("/saveWtTags")
-    public void saveWtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException {
+    public void saveWtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException, InterruptedException {
          alarmWtService.saveAlarms(alarms);
     }
 
     @PostMapping("/saveBtTags")
-    public void saveBtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException {
+    public void saveBtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException, InterruptedException {
         alarmBtService.saveAlarms(alarms);
     }
 
     @PostMapping("/saveCtTags")
-    public void saveCtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException {
+    public void saveCtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException, InterruptedException {
         alarmCtService.saveAlarms(alarms);
     }
 
     @PostMapping("/saveInTags")
-    public void saveInTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException {
+    public void saveInTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException, InterruptedException {
         alarmInService.saveAlarms(alarms);
     }
 
     @PostMapping("/updateInTags")
-    public void updateInTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException {
+    public void updateInTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException, InterruptedException {
         alarmInService.updateAlarms(alarms);
     }
 
     @PostMapping("/updateWtTags")
-    public void updateWtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException {
+    public void updateWtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException, InterruptedException {
         alarmWtService.updateAlarms(alarms);
     }
 
     @PostMapping("/updateBtTags")
-    public void updateBtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException {
+    public void updateBtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException, InterruptedException {
         alarmBtService.updateAlarms(alarms);
     }
 
     @PostMapping("/updateCtTags")
-    public void updateCtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException {
+    public void updateCtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException, InterruptedException {
         alarmCtService.updateAlarms(alarms);
     }
 

+ 2 - 2
alarm-service/src/main/java/com/gyee/alarm/controller/WebSocketController.java

@@ -27,7 +27,7 @@ public class WebSocketController {
     public void sentMessage(String userId,String message){
         try {
             webSocket.sendMessageByUserId(userId,message);
-        } catch (IOException e) {
+        } catch (IOException | EncodeException e) {
             e.printStackTrace();
         }
 
@@ -37,7 +37,7 @@ public class WebSocketController {
     public void sentObjectMessage(String userId){
         try {
             webSocket.sendMessageByUserId(userId,"111111");
-        } catch (IOException e) {
+        } catch (IOException | EncodeException e) {
             e.printStackTrace();
         }
 

+ 4 - 1
alarm-service/src/main/java/com/gyee/alarm/model/auto/ProEconAlarmInfo.java

@@ -176,5 +176,8 @@ public class ProEconAlarmInfo extends Model {
      * 关闭时间
      */
     private Date closeTime;
-
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
 }

+ 123 - 13
alarm-service/src/main/java/com/gyee/alarm/service/AlarmBtService.java

@@ -10,7 +10,7 @@ import com.gyee.alarm.util.StringUtils;
 import com.gyee.alarm.util.realtimesource.IEdosUtil;
 import com.gyee.alarm.websocket.PushParams;
 import com.gyee.alarm.websocket.WebSocket;
-import com.gyee.alarm.websocket.WebSocketBt;
+
 import com.gyee.common.model.PointData;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -175,7 +175,7 @@ public class AlarmBtService {
     }
 
 
-    public synchronized void saveAlarms(List<AlarmTag> ls) throws EncodeException, IOException {
+    public synchronized void saveAlarms(List<AlarmTag> ls) throws EncodeException, IOException, InterruptedException {
 
         if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
@@ -190,7 +190,7 @@ public class AlarmBtService {
                         AlarmVo vo = CacheContext.alarmBtMap.get(alarm.getId());
                         ProEconAlarmInfo po = new ProEconAlarmInfo();
                         po.setTbname(vo.getTbName());
-
+                        po.setUpdateTime(new Date(alarm.getTs()));
                         po.setLastUpdateTime(new Date(alarm.getTs()));
                         po.setTagId(alarm.getTagId());
                         po.setTriggerType(alarm.getTriggerType());
@@ -253,7 +253,15 @@ public class AlarmBtService {
                             alarm.setWpName(CacheContext.subwpmap.get(vo.getStationid()).getName());
                         }
                         alarm.setWpId(vo.getStationid());
-                        pushDataSevice.pushBtData(alarm);
+
+//                        try {
+//                            pushDataSevice.pushBtData(alarm);
+//                        }catch (Exception e)
+//                        {
+//                            System.out.println(e.getMessage());
+//                        }
+//
+//
 
                         tempmap.put(po.getTbname(),po);
                     }
@@ -267,14 +275,29 @@ public class AlarmBtService {
                 for (ProEconAlarmInfo vo : valuels) {
                     idls.add(vo.getTbname());
                 }
+//                Map<String,ProEconAlarmInfo> infoMap=new HashMap<>();
                 if (!idls.isEmpty()) {
 
+//                    List<ProEconAlarmInfo> templs= proEconAlarmInfoService.listByIds(idls);
+//                    if(!templs.isEmpty())
+//                    {
+//                        for(ProEconAlarmInfo info:templs)
+//                        {
+//                            infoMap.put(info.getTbname().toLowerCase(),info);
+//                        }
+//                    }
                     proEconAlarmInfoService.removeByIds(idls);
                 }
 
 
                 List<ProEconAlarmInfo> templs = new ArrayList<>();
                 for (ProEconAlarmInfo vo : valuels) {
+
+//                    if(infoMap.containsKey(vo.getTbname().toLowerCase()))
+//                    {
+//                        ProEconAlarmInfo in=infoMap.get(vo.getTbname().toLowerCase());
+//                        vo.setUpdateTime(in.getLastUpdateTime());
+//                    }
                     templs.add(vo);
                     if (templs.size() == 100) {
                         proEconAlarmInfoService.saveBatch(templs);
@@ -288,12 +311,48 @@ public class AlarmBtService {
 
 
             }
+
+            if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+
+                for (AlarmTag alarm : ls) {
+                    if (CacheContext.alarmBtMap.containsKey(alarm.getId())) {
+                        AlarmVo vo = CacheContext.alarmBtMap.get(alarm.getId());
+
+
+                        alarm.setRank(vo.getRank());
+                        alarm.setDescription(vo.getDescription());
+                        alarm.setAlarmType(vo.getAlarmtype());
+                        alarm.setDeviceType(vo.getDevicetype());
+
+                        alarm.setCharacteristic(vo.getCharacteristic());
+                        alarm.setFaultCause(vo.getFaultCause());
+                        alarm.setResolvent(vo.getResolvent());
+                        alarm.setIsClose(false);
+                        alarm.setDeviceId(vo.getDeviceid());
+                        alarm.setAlarmId(vo.getAlarmid());
+
+
+                        if(CacheContext.subwpmap.containsKey(vo.getStationid()))
+                        {
+                            alarm.setWpName(CacheContext.subwpmap.get(vo.getStationid()).getName());
+                        }
+                        alarm.setWpId(vo.getStationid());
+
+                        pushDataSevice.pushBtData(alarm);
+                    }
+                }
+
+                Thread.sleep(300);
+
+
+            }
         }
 
     }
 
 
-    public synchronized void updateAlarms(List<AlarmTag> ls) throws EncodeException, IOException {
+    public synchronized void updateAlarms(List<AlarmTag> ls) throws EncodeException, IOException, InterruptedException {
 
         if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
@@ -359,13 +418,8 @@ public class AlarmBtService {
                         AlarmVo vo = CacheContext.alarmBtMap.get(alarm.getId());
                         ProEconAlarmInfo po = new ProEconAlarmInfo();
                         po.setTbname(vo.getTbName());
-                        if(StringUtils.notEmp(alarm.getEndts()))
-                        {
-                            po.setLastUpdateTime(new Date(alarm.getEndts()));
-                        }else
-                        {
-                            po.setLastUpdateTime(new Date());
-                        }
+                        po.setUpdateTime(new Date(alarm.getTs()));
+                        po.setLastUpdateTime(new Date(alarm.getEndts()));
 
                         po.setTagId(alarm.getTagId());
                         po.setTriggerType(alarm.getTriggerType());
@@ -423,7 +477,12 @@ public class AlarmBtService {
                             alarm.setWpName(CacheContext.subwpmap.get(vo.getStationid()).getName());
                         }
                         alarm.setWpId(vo.getStationid());
-                        pushDataSevice.pushBtData(alarm);
+//                        try {
+//                            pushDataSevice.pushBtData(alarm);
+//                        }catch (Exception e)
+//                        {
+//                            System.out.println(e.getMessage());
+//                        }
 
                         tempmap.put(po.getTbname(),po);
                     }
@@ -437,13 +496,29 @@ public class AlarmBtService {
                 for (ProEconAlarmInfo vo : valuels) {
                     idls.add(vo.getTbname());
                 }
+//                Map<String,ProEconAlarmInfo> infoMap=new HashMap<>();
                 if (!idls.isEmpty()) {
 
+//                    List<ProEconAlarmInfo> templs= proEconAlarmInfoService.listByIds(idls);
+//                    if(!templs.isEmpty())
+//                    {
+//                        for(ProEconAlarmInfo info:templs)
+//                        {
+//                            infoMap.put(info.getTbname().toLowerCase(),info);
+//                        }
+//                    }
                     proEconAlarmInfoService.removeByIds(idls);
                 }
 
+
                 List<ProEconAlarmInfo> templs = new ArrayList<>();
                 for (ProEconAlarmInfo vo : valuels) {
+
+//                    if(infoMap.containsKey(vo.getTbname().toLowerCase()))
+//                    {
+//                        ProEconAlarmInfo in=infoMap.get(vo.getTbname().toLowerCase());
+//                        vo.setUpdateTime(in.getLastUpdateTime());
+//                    }
                     templs.add(vo);
                     if (templs.size() == 100) {
                         proEconAlarmInfoService.saveBatch(templs);
@@ -456,6 +531,41 @@ public class AlarmBtService {
                 }
 
             }
+
+
+            if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+
+                for (AlarmTag alarm : ls) {
+                    if (CacheContext.alarmBtMap.containsKey(alarm.getId())) {
+                        AlarmVo vo = CacheContext.alarmBtMap.get(alarm.getId());
+
+
+                        alarm.setRank(vo.getRank());
+                        alarm.setDescription(vo.getDescription());
+                        alarm.setAlarmType(vo.getAlarmtype());
+                        alarm.setDeviceType(vo.getDevicetype());
+
+                        alarm.setCharacteristic(vo.getCharacteristic());
+                        alarm.setFaultCause(vo.getFaultCause());
+                        alarm.setResolvent(vo.getResolvent());
+                        alarm.setIsClose(false);
+                        alarm.setDeviceId(vo.getDeviceid());
+                        alarm.setAlarmId(vo.getAlarmid());
+
+
+                        if(CacheContext.subwpmap.containsKey(vo.getStationid()))
+                        {
+                            alarm.setWpName(CacheContext.subwpmap.get(vo.getStationid()).getName());
+                        }
+                        alarm.setWpId(vo.getStationid());
+
+                        pushDataSevice.pushBtData(alarm);
+                    }
+                }
+
+                Thread.sleep(300);
+            }
         }
 
     }

+ 156 - 19
alarm-service/src/main/java/com/gyee/alarm/service/AlarmCtService.java

@@ -10,6 +10,9 @@ import com.gyee.alarm.util.DateUtils;
 import com.gyee.alarm.util.StringUtils;
 import com.gyee.alarm.websocket.PushParams;
 import com.gyee.alarm.websocket.WebSocket;
+import org.apache.juli.logging.Log;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
@@ -24,6 +27,8 @@ import java.util.concurrent.ConcurrentHashMap;
 @Service
 
 public class AlarmCtService {
+
+    private static Logger logger = LoggerFactory.getLogger(AlarmCtService.class);
     @Resource
     private IAlarmTsService alarmTsService;
 
@@ -423,7 +428,7 @@ public class AlarmCtService {
     }
 
 
-    public synchronized void saveAlarms(List<AlarmTag> ls) throws EncodeException, IOException {
+    public synchronized void saveAlarms(List<AlarmTag> ls) throws EncodeException, IOException, InterruptedException {
 
         if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
@@ -439,6 +444,7 @@ public class AlarmCtService {
                         ProEconAlarmInfo po = new ProEconAlarmInfo();
                         po.setTbname(vo.getTbName());
                         po.setLastUpdateTime(new Date(alarm.getTs()));
+                        po.setUpdateTime(new Date(alarm.getTs()));
                         po.setTagId(alarm.getTagId());
                         po.setTriggerType(alarm.getTriggerType());
                         po.setAlarmId(vo.getAlarmid());
@@ -488,13 +494,23 @@ public class AlarmCtService {
                             alarm.setWpName(CacheContext.wpmap.get(vo.getStationid()).getName());
                         }
 
-                        if(po.getDeviceType().equals(DeviceTypeValue.IN.getCode()) || po.getDeviceType().equals(DeviceTypeValue.WT.getCode()))
-                        {
-                            pushDataSevice.pushWtData(alarm);
-                        }else  if(po.getDeviceType().equals(DeviceTypeValue.BT.getCode()))
-                        {
-                            pushDataSevice.pushBtData(alarm);
-                        }
+//                        if(po.getDeviceType().equals(DeviceTypeValue.IN.getCode()) || po.getDeviceType().equals(DeviceTypeValue.WT.getCode()))
+//                        {
+//                            try {
+//                                pushDataSevice.pushWtData(alarm);
+//                            }catch (Exception e)
+//                            {
+//                                logger.info(e.getMessage());
+//                            }
+//                        }else  if(po.getDeviceType().equals(DeviceTypeValue.BT.getCode()))
+//                        {
+//                            try {
+//                                pushDataSevice.pushBtData(alarm);
+//                            }catch (Exception e)
+//                            {
+//                                logger.info(e.getMessage());
+//                            }
+//                        }
 
 
                         tempmap.put(po.getTbname(),po);
@@ -508,14 +524,29 @@ public class AlarmCtService {
                 for (ProEconAlarmInfo vo : valuels) {
                     idls.add(vo.getTbname());
                 }
+//                Map<String,ProEconAlarmInfo> infoMap=new HashMap<>();
                 if (!idls.isEmpty()) {
 
+//                    List<ProEconAlarmInfo> templs= proEconAlarmInfoService.listByIds(idls);
+//                    if(!templs.isEmpty())
+//                    {
+//                        for(ProEconAlarmInfo info:templs)
+//                        {
+//                            infoMap.put(info.getTbname().toLowerCase(),info);
+//                        }
+//                    }
                     proEconAlarmInfoService.removeByIds(idls);
                 }
 
 
                 List<ProEconAlarmInfo> templs = new ArrayList<>();
                 for (ProEconAlarmInfo vo : valuels) {
+
+//                    if(infoMap.containsKey(vo.getTbname().toLowerCase()))
+//                    {
+//                        ProEconAlarmInfo in=infoMap.get(vo.getTbname().toLowerCase());
+//                        vo.setUpdateTime(in.getLastUpdateTime());
+//                    }
                     templs.add(vo);
                     if (templs.size() == 100) {
                         proEconAlarmInfoService.saveBatch(templs);
@@ -528,12 +559,55 @@ public class AlarmCtService {
                 }
 
             }
+
+
+            if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+
+                for (AlarmTag alarm : ls) {
+                    if (CacheContext.alarmCtMap.containsKey(alarm.getId())) {
+                        AlarmVo vo = CacheContext.alarmCtMap.get(alarm.getId());
+
+                        alarm.setRank(vo.getRank());
+                        alarm.setDescription(vo.getDescription());
+                        alarm.setAlarmType(vo.getAlarmtype());
+                        alarm.setDeviceType(vo.getDevicetype());
+                        alarm.setCharacteristic(vo.getCharacteristic());
+                        alarm.setFaultCause(vo.getFaultCause());
+                        alarm.setResolvent(vo.getResolvent());
+                        alarm.setIsClose(false);
+                        alarm.setDeviceId(vo.getDeviceid());
+                        alarm.setAlarmId(vo.getAlarmid());
+                        if(StringUtils.notEmp(vo.getDeviceid()) && CacheContext.wtmap.containsKey(vo.getDeviceid()))
+                        {
+                            alarm.setCode(CacheContext.wtmap.get(vo.getDeviceid()).getNemCode());
+                        }
+                        if(CacheContext.wpmap.containsKey(vo.getStationid()))
+                        {
+                            alarm.setWpName(CacheContext.wpmap.get(vo.getStationid()).getName());
+                        }
+
+                        if(vo.getDevicetype().equals(DeviceTypeValue.IN.getCode()) || vo.getDevicetype().equals(DeviceTypeValue.WT.getCode()))
+                        {
+                            pushDataSevice.pushWtData(alarm);
+                        }else  if(vo.getDevicetype().equals(DeviceTypeValue.BT.getCode()))
+                        {
+                            pushDataSevice.pushBtData(alarm);
+                        }
+
+                    }
+                }
+                Thread.sleep(300);
+            }
+
+
+
         }
 
     }
 
 
-    public synchronized void updateAlarms(List<AlarmTag> ls) throws EncodeException, IOException {
+    public synchronized void updateAlarms(List<AlarmTag> ls) throws EncodeException, IOException, InterruptedException {
 
         if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
@@ -604,7 +678,8 @@ public class AlarmCtService {
                             AlarmVo vo = CacheContext.alarmCtMap.get(alarm.getId());
                             ProEconAlarmInfo po = new ProEconAlarmInfo();
                             po.setTbname(vo.getTbName());
-                            po.setLastUpdateTime(new Date(alarm.getTs()));
+                            po.setLastUpdateTime(new Date(alarm.getEndts()));
+                            po.setUpdateTime(new Date(alarm.getTs()));
                             po.setTagId(alarm.getTagId());
                             po.setTriggerType(alarm.getTriggerType());
                             po.setAlarmId(vo.getAlarmid());
@@ -656,15 +731,23 @@ public class AlarmCtService {
                                 alarm.setWpName(CacheContext.wpmap.get(vo.getStationid()).getName());
                             }
 
-                            if(po.getDeviceType().equals(DeviceTypeValue.IN.getCode()) || po.getDeviceType().equals(DeviceTypeValue.WT.getCode()))
-                            {
-                                pushDataSevice.pushWtData(alarm);
-                            }else  if(po.getDeviceType().equals(DeviceTypeValue.BT.getCode()))
-                            {
-                                pushDataSevice.pushBtData(alarm);
-                            }
-
-
+//                            if(po.getDeviceType().equals(DeviceTypeValue.IN.getCode()) || po.getDeviceType().equals(DeviceTypeValue.WT.getCode()))
+//                            {
+//                                try {
+//                                    pushDataSevice.pushWtData(alarm);
+//                                }catch (Exception e)
+//                                {
+//                                    logger.info(e.getMessage());
+//                                }
+//                            }else  if(po.getDeviceType().equals(DeviceTypeValue.BT.getCode()))
+//                            {
+//                                try {
+//                                    pushDataSevice.pushBtData(alarm);
+//                                }catch (Exception e)
+//                                {
+//                                    logger.info(e.getMessage());
+//                                }
+//                            }
                             tempmap.put(po.getTbname(),po);
                         }
                     }
@@ -676,14 +759,29 @@ public class AlarmCtService {
                     for (ProEconAlarmInfo vo : valuels) {
                         idls.add(vo.getTbname());
                     }
+//                    Map<String,ProEconAlarmInfo> infoMap=new HashMap<>();
                     if (!idls.isEmpty()) {
 
+//                        List<ProEconAlarmInfo> templs= proEconAlarmInfoService.listByIds(idls);
+//                        if(!templs.isEmpty())
+//                        {
+//                            for(ProEconAlarmInfo info:templs)
+//                            {
+//                                infoMap.put(info.getTbname().toLowerCase(),info);
+//                            }
+//                        }
                         proEconAlarmInfoService.removeByIds(idls);
                     }
 
 
                     List<ProEconAlarmInfo> templs = new ArrayList<>();
                     for (ProEconAlarmInfo vo : valuels) {
+
+//                        if(infoMap.containsKey(vo.getTbname().toLowerCase()))
+//                        {
+//                            ProEconAlarmInfo in=infoMap.get(vo.getTbname().toLowerCase());
+//                            vo.setUpdateTime(in.getLastUpdateTime());
+//                        }
                         templs.add(vo);
                         if (templs.size() == 100) {
                             proEconAlarmInfoService.saveBatch(templs);
@@ -696,6 +794,45 @@ public class AlarmCtService {
                     }
 
                 }
+
+                if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+
+                    for (AlarmTag alarm : ls) {
+                        if (CacheContext.alarmCtMap.containsKey(alarm.getId())) {
+                            AlarmVo vo = CacheContext.alarmCtMap.get(alarm.getId());
+
+                            alarm.setRank(vo.getRank());
+                            alarm.setDescription(vo.getDescription());
+                            alarm.setAlarmType(vo.getAlarmtype());
+                            alarm.setDeviceType(vo.getDevicetype());
+                            alarm.setCharacteristic(vo.getCharacteristic());
+                            alarm.setFaultCause(vo.getFaultCause());
+                            alarm.setResolvent(vo.getResolvent());
+                            alarm.setIsClose(false);
+                            alarm.setDeviceId(vo.getDeviceid());
+                            alarm.setAlarmId(vo.getAlarmid());
+                            if(StringUtils.notEmp(vo.getDeviceid()) && CacheContext.wtmap.containsKey(vo.getDeviceid()))
+                            {
+                                alarm.setCode(CacheContext.wtmap.get(vo.getDeviceid()).getNemCode());
+                            }
+                            if(CacheContext.wpmap.containsKey(vo.getStationid()))
+                            {
+                                alarm.setWpName(CacheContext.wpmap.get(vo.getStationid()).getName());
+                            }
+
+                            if(vo.getDevicetype().equals(DeviceTypeValue.IN.getCode()) || vo.getDevicetype().equals(DeviceTypeValue.WT.getCode()))
+                            {
+                                pushDataSevice.pushWtData(alarm);
+                            }else  if(vo.getDevicetype().equals(DeviceTypeValue.BT.getCode()))
+                            {
+                                pushDataSevice.pushBtData(alarm);
+                            }
+                        }
+
+                        Thread.sleep(300);
+                    }
+                }
             }
         }
     }

+ 121 - 4
alarm-service/src/main/java/com/gyee/alarm/service/AlarmInService.java

@@ -229,7 +229,7 @@ public class AlarmInService {
     }
 
 
-    public synchronized void saveAlarms(List<AlarmTag> ls) throws EncodeException, IOException {
+    public synchronized void saveAlarms(List<AlarmTag> ls) throws EncodeException, IOException, InterruptedException {
 
         if(StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
@@ -249,6 +249,7 @@ public class AlarmInService {
                         ProEconAlarmInfo po = new ProEconAlarmInfo();
                         po.setTbname(vo.getTbName());
                         po.setLastUpdateTime(new Date(alarm.getTs()));
+                        po.setUpdateTime(new Date(alarm.getTs()));
                         po.setTagId(alarm.getTagId());
                         po.setTriggerType(alarm.getTriggerType());
                         po.setAlarmId(vo.getAlarmid());
@@ -300,7 +301,12 @@ public class AlarmInService {
                         }
 
                         alarm.setWpId(vo.getStationid());
-                        pushDataSevice.pushWtData(alarm);
+                        try {
+                            pushDataSevice.pushBtData(alarm);
+                        }catch (Exception e)
+                        {
+                            System.out.println(e.getMessage());
+                        }
 
 
                         tempmap.put(po.getTbname(),po);
@@ -315,14 +321,29 @@ public class AlarmInService {
                 for (ProEconAlarmInfo vo : valuels) {
                     idls.add(vo.getTbname());
                 }
+//                Map<String,ProEconAlarmInfo> infoMap=new HashMap<>();
                 if (!idls.isEmpty()) {
 
+//                    List<ProEconAlarmInfo> templs= proEconAlarmInfoService.listByIds(idls);
+//                    if(!templs.isEmpty())
+//                    {
+//                        for(ProEconAlarmInfo info:templs)
+//                        {
+//                            infoMap.put(info.getTbname().toLowerCase(),info);
+//                        }
+//                    }
                     proEconAlarmInfoService.removeByIds(idls);
                 }
 
 
                 List<ProEconAlarmInfo> templs = new ArrayList<>();
                 for (ProEconAlarmInfo vo : valuels) {
+
+//                    if(infoMap.containsKey(vo.getTbname().toLowerCase()))
+//                    {
+//                        ProEconAlarmInfo in=infoMap.get(vo.getTbname().toLowerCase());
+//                        vo.setUpdateTime(in.getLastUpdateTime());
+//                    }
                     templs.add(vo);
                     if (templs.size() == 500) {
                         proEconAlarmInfoService.saveBatch(templs);
@@ -334,13 +355,51 @@ public class AlarmInService {
                     proEconAlarmInfoService.saveBatch(templs);
                 }
 
+            }
+            if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+                for (AlarmTag alarm : ls) {
+                    if (CacheContext.alarmInMap.containsKey(alarm.getId())) {
+                        AlarmVo vo = CacheContext.alarmInMap.get(alarm.getId());
+
+
+                        alarm.setRank(vo.getRank());
+                        alarm.setDescription(vo.getDescription());
+                        alarm.setAlarmType(vo.getAlarmtype());
+                        alarm.setDeviceType(vo.getDevicetype());
+
+                        alarm.setCharacteristic(vo.getCharacteristic());
+                        alarm.setFaultCause(vo.getFaultCause());
+                        alarm.setResolvent(vo.getResolvent());
+                        alarm.setIsClose(false);
+                        alarm.setDeviceId(vo.getDeviceid());
+                        alarm.setAlarmId(vo.getAlarmid());
+
+                        if(StringUtils.notEmp(vo.getDeviceid()) && CacheContext.wtmap.containsKey(vo.getDeviceid()))
+                        {
+                            alarm.setCode(CacheContext.wtmap.get(vo.getDeviceid()).getNemCode());
+                        }
+
+                        if(CacheContext.wpmap.containsKey(vo.getStationid()))
+                        {
+                            alarm.setWpName(CacheContext.wpmap.get(vo.getStationid()).getName());
+                        }
+
+                        alarm.setWpId(vo.getStationid());
+                        pushDataSevice.pushWtData(alarm);
+
+                    }
+                }
+
+                Thread.sleep(300);
 
             }
+
         }
     }
 
 
-    public  synchronized void updateAlarms(List<AlarmTag> ls) throws EncodeException, IOException {
+    public  synchronized void updateAlarms(List<AlarmTag> ls) throws EncodeException, IOException, InterruptedException {
 
         if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
@@ -415,6 +474,7 @@ public class AlarmInService {
                         ProEconAlarmInfo po = new ProEconAlarmInfo();
                         po.setTbname(vo.getTbName());
                         po.setLastUpdateTime(new Date(alarm.getEndts()));
+                        po.setUpdateTime(new Date(alarm.getTs()));
                         po.setTagId(alarm.getTagId());
                         po.setTriggerType(alarm.getTriggerType());
                         po.setAlarmId(vo.getAlarmid());
@@ -466,7 +526,7 @@ public class AlarmInService {
                             alarm.setWpName(CacheContext.wpmap.get(vo.getStationid()).getName());
                         }
 
-                        pushDataSevice.pushWtData(alarm);
+                        pushDataSevice.pushBtData(alarm);
 
 
                         tempmap.put(po.getTbname(),po);
@@ -479,13 +539,29 @@ public class AlarmInService {
                 for (ProEconAlarmInfo vo : valuels) {
                     idls.add(vo.getTbname());
                 }
+//                Map<String,ProEconAlarmInfo> infoMap=new HashMap<>();
                 if (!idls.isEmpty()) {
 
+//                    List<ProEconAlarmInfo> templs= proEconAlarmInfoService.listByIds(idls);
+//                    if(!templs.isEmpty())
+//                    {
+//                        for(ProEconAlarmInfo info:templs)
+//                        {
+//                            infoMap.put(info.getTbname().toLowerCase(),info);
+//                        }
+//                    }
                     proEconAlarmInfoService.removeByIds(idls);
                 }
 
+
                 List<ProEconAlarmInfo> templs = new ArrayList<>();
                 for (ProEconAlarmInfo vo : valuels) {
+
+//                    if(infoMap.containsKey(vo.getTbname().toLowerCase()))
+//                    {
+//                        ProEconAlarmInfo in=infoMap.get(vo.getTbname().toLowerCase());
+//                        vo.setUpdateTime(in.getLastUpdateTime());
+//                    }
                     templs.add(vo);
                     if (templs.size() == 500) {
                         proEconAlarmInfoService.saveBatch(templs);
@@ -498,6 +574,47 @@ public class AlarmInService {
                 }
 
             }
+
+
+            if (StringUtils.notEmp(alarmTagls) && !alarmTagls.isEmpty()) {
+
+
+                for (AlarmTag alarm : alarmTagls) {
+                    if (CacheContext.alarmInMap.containsKey(alarm.getId())) {
+                        AlarmVo vo = CacheContext.alarmInMap.get(alarm.getId());
+
+
+                        alarm.setRank(vo.getRank());
+                        alarm.setDescription(vo.getDescription());
+                        alarm.setAlarmType(vo.getAlarmtype());
+                        alarm.setDeviceType(vo.getDevicetype());
+
+                        alarm.setCharacteristic(vo.getCharacteristic());
+                        alarm.setFaultCause(vo.getFaultCause());
+                        alarm.setResolvent(vo.getResolvent());
+
+                        alarm.setDeviceId(vo.getDeviceid());
+                        alarm.setAlarmId(vo.getAlarmid());
+                        alarm.setIsClose(true);
+                        if(CacheContext.wtmap.containsKey(vo.getDeviceid()))
+                        {
+                            alarm.setCode(CacheContext.wtmap.get(vo.getDeviceid()).getNemCode());
+                        }
+
+                        if(CacheContext.wpmap.containsKey(vo.getStationid()))
+                        {
+                            alarm.setWpName(CacheContext.wpmap.get(vo.getStationid()).getName());
+                        }
+
+                        pushDataSevice.pushWtData(alarm);
+
+                    }
+
+                    Thread.sleep(300);
+                }
+
+
+            }
         }
 
     }

+ 179 - 94
alarm-service/src/main/java/com/gyee/alarm/service/AlarmWtService.java

@@ -51,12 +51,12 @@ public class AlarmWtService {
     private IEdosUtil edosUtil;
 
     private static Logger logger = LoggerFactory.getLogger(AlarmWtService.class);
-    public void dropSuperTable()
-    {
+
+    public void dropSuperTable() {
         alarmTsService.dropSuperTable(AlarmSuperTalbeType.WT.getCode());
     }
-    public void createSuperTable()
-    {
+
+    public void createSuperTable() {
 
         alarmTsService.createSuperTable(AlarmSuperTalbeType.WT.getCode());
     }
@@ -64,9 +64,8 @@ public class AlarmWtService {
     public void initalWtAlarm() throws Exception {
 
 
-
-        List<AlarmVo> alarmVoList=CacheContext.alarmWtList;
-        List<AlarmTag>  alarmTags=new ArrayList<>();
+        List<AlarmVo> alarmVoList = CacheContext.alarmWtList;
+        List<AlarmTag> alarmTags = new ArrayList<>();
 
 
 //        List<String>  ls=new ArrayList<>();
@@ -98,10 +97,8 @@ public class AlarmWtService {
 //            valuemap.put(po.getEdnaId(),po);
 //        }
 
-        if(!alarmVoList.isEmpty())
-        {
-            for(AlarmVo vo: alarmVoList)
-            {
+        if (!alarmVoList.isEmpty()) {
+            for (AlarmVo vo : alarmVoList) {
 
 
                 alarmTsService.createTable(vo.getTbName(), vo.getAlarmid(), vo.getAlarmtype(),
@@ -115,9 +112,9 @@ public class AlarmWtService {
                         vo.getResettable(), vo.getStationid(),
                         vo.getStationname(), vo.getSubcomponents(),
                         vo.getSuffix(), vo.getTagid(),
-                        vo.getTriggertype(), vo.getUniformcode(),vo.getSuperTableName(),
+                        vo.getTriggertype(), vo.getUniformcode(), vo.getSuperTableName(),
                         vo.getName(),
-                        vo.getNemCode(),vo.getFaultCause(),vo.getResolvent(),vo.getFaultType(),vo.getAname());
+                        vo.getNemCode(), vo.getFaultCause(), vo.getResolvent(), vo.getFaultType(), vo.getAname());
 
 //                AlarmTag po=new AlarmTag();
 //                po.setId(vo.getTbName());
@@ -147,13 +144,12 @@ public class AlarmWtService {
 
     public List<AlarmVo> initalAlarmVo() throws Exception {
 
-        List<AlarmVo> alarmVoList=new ArrayList<>();
+        List<AlarmVo> alarmVoList = new ArrayList<>();
         Map<String, List<ProEconAlarmConfiguration>> wtAlarmMap = CacheContext.wtAlarmMap;
         Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
         for (ProBasicEquipment wt : CacheContext.wtls) {
 
-            if(wt.getId().contains("_G_"))
-            {
+            if (wt.getId().contains("_G_")) {
                 continue;
             }
 
@@ -170,21 +166,23 @@ public class AlarmWtService {
 
                     if (!alarmls.isEmpty()) {
 //                        System.out.println(wt.getId());
+
+//                        if(wt.getId().equals("SXJ_KGDL_PTZ_F_WT_0001_EQ"))
+//                        {
+//                            System.out.println("");
+//                        }
                         for (ProEconAlarmConfiguration alarm : alarmls) {
                             if (pointMap.containsKey(alarm.getUniformCode())) {
                                 ProBasicEquipmentPoint equipmentPoint = pointMap.get(alarm.getUniformCode());
 
-                                if(StringUtils.notEmp(initialcode) &&
+                                if (StringUtils.notEmp(initialcode) &&
                                         StringUtils.notEmp(equipmentPoint.getNemCode()) &&
                                         !equipmentPoint.getNemCode().equals(initialcode) &&
                                         alarm.getAlarmType().equals(AlarmTypeValue.WT.getCode())
-                                )
-
-
-                                {
+                                ) {
 
 //                                    System.out.println("ok");
-                                    AlarmVo vo=new AlarmVo();
+                                    AlarmVo vo = new AlarmVo();
                                     StringBuilder tbName = new StringBuilder();
                                     tbName.append(wt.getId()).append("_").append(alarm.getId());
                                     vo.setTbName(String.valueOf(tbName));
@@ -199,24 +197,21 @@ public class AlarmWtService {
                                     vo.setDevicetype(alarm.getDeviceType());
                                     vo.setEnabled(alarm.getEnable());
                                     vo.setLineid(wt.getLineId());
-                                    if(CacheContext.lnmap.containsKey(wt.getLineId()))
-                                    {
-                                        ProBasicLine ln=CacheContext.lnmap.get(wt.getLineId());
+                                    if (CacheContext.lnmap.containsKey(wt.getLineId())) {
+                                        ProBasicLine ln = CacheContext.lnmap.get(wt.getLineId());
                                         vo.setLinename(ln.getName());
                                     }
                                     vo.setModelId(wt.getModelId());
                                     vo.setProjectid(wt.getProjectId());
-                                    if(CacheContext.pjmap.containsKey(wt.getProjectId()))
-                                    {
-                                        ProBasicProject pj=CacheContext.pjmap.get(wt.getProjectId());
+                                    if (CacheContext.pjmap.containsKey(wt.getProjectId())) {
+                                        ProBasicProject pj = CacheContext.pjmap.get(wt.getProjectId());
                                         vo.setProjectname(pj.getName());
                                     }
                                     vo.setRank(alarm.getRank());
                                     vo.setResettable(alarm.getResetTable());
                                     vo.setStationid(wt.getWindpowerstationId());
-                                    if(CacheContext.wpmap.containsKey(wt.getWindpowerstationId()))
-                                    {
-                                        ProBasicPowerstation wp=CacheContext.wpmap.get(wt.getWindpowerstationId());
+                                    if (CacheContext.wpmap.containsKey(wt.getWindpowerstationId())) {
+                                        ProBasicPowerstation wp = CacheContext.wpmap.get(wt.getWindpowerstationId());
                                         vo.setStationname(wp.getName());
                                     }
                                     vo.setSubcomponents(alarm.getSubcomponents());
@@ -247,35 +242,27 @@ public class AlarmWtService {
             }
 
         }
-        return  alarmVoList;
+        return alarmVoList;
     }
 
 
+    public List<AlarmTag> findTags(String stbaleName, String wpIds) {
+        List<AlarmVo> vos = new ArrayList<>();
+        List<AlarmTag> ls = new ArrayList<>();
+        if (StringUtils.notEmp(stbaleName) && StringUtils.notEmp(wpIds)) {
 
-
-    public List<AlarmTag> findTags(String stbaleName,String wpIds)
-    {
-        List<AlarmVo> vos= new ArrayList<>();
-        List<AlarmTag> ls=new ArrayList<>();
-        if(StringUtils.notEmp(stbaleName) && StringUtils.notEmp(wpIds))
-        {
-
-            String[] ids= wpIds.split(",");
-            for(int i=0;i<ids.length;i++)
-            {
-                if(CacheContext.alarmWpMap.containsKey(ids[i]))
-                {
+            String[] ids = wpIds.split(",");
+            for (int i = 0; i < ids.length; i++) {
+                if (CacheContext.alarmWpMap.containsKey(ids[i])) {
                     vos.addAll(CacheContext.alarmWpMap.get(ids[i]));
                 }
 
             }
 
 
-            if(!vos.isEmpty())
-            {
-                for(AlarmVo vo:vos)
-                {
-                    AlarmTag po=new AlarmTag();
+            if (!vos.isEmpty()) {
+                for (AlarmVo vo : vos) {
+                    AlarmTag po = new AlarmTag();
                     po.setId(vo.getTbName());
                     po.setOval(null);
                     po.setTriggerType(vo.getTriggertype());
@@ -293,16 +280,16 @@ public class AlarmWtService {
     }
 
 
-    public synchronized void saveAlarms(List<AlarmTag> ls) throws EncodeException, IOException {
+    public synchronized void saveAlarms(List<AlarmTag> ls) throws EncodeException, IOException, InterruptedException {
 
-        if(StringUtils.notEmp(ls) && !ls.isEmpty()) {
+        if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
             for (AlarmTag alarm : ls) {
-               alarm.setConfirmed(false);
+                alarm.setConfirmed(false);
 
             }
             alarmTsService.insertList(ls);
-            Map<String,ProEconAlarmInfo> tempmap=new HashMap<>();
+            Map<String, ProEconAlarmInfo> tempmap = new HashMap<>();
 
             if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
@@ -313,6 +300,7 @@ public class AlarmWtService {
                         ProEconAlarmInfo po = new ProEconAlarmInfo();
                         po.setTbname(vo.getTbName());
                         po.setLastUpdateTime(new Date(alarm.getTs()));
+                        po.setUpdateTime(new Date(alarm.getTs()));
                         po.setTagId(alarm.getTagId());
                         po.setTriggerType(alarm.getTriggerType());
                         po.setAlarmId(vo.getAlarmid());
@@ -353,21 +341,18 @@ public class AlarmWtService {
                         alarm.setDeviceId(vo.getDeviceid());
                         alarm.setAlarmId(vo.getAlarmid());
 
-                        if(StringUtils.notEmp(vo.getDeviceid()) && CacheContext.wtmap.containsKey(vo.getDeviceid()))
-                        {
+                        if (StringUtils.notEmp(vo.getDeviceid()) && CacheContext.wtmap.containsKey(vo.getDeviceid())) {
                             alarm.setCode(CacheContext.wtmap.get(vo.getDeviceid()).getNemCode());
                         }
 
-                        if(CacheContext.wpmap.containsKey(vo.getStationid()))
-                        {
+                        if (CacheContext.wpmap.containsKey(vo.getStationid())) {
                             alarm.setWpName(CacheContext.wpmap.get(vo.getStationid()).getName());
                         }
 
                         alarm.setWpId(vo.getStationid());
-                        pushDataSevice.pushWtData(alarm);
 
 
-                        tempmap.put(po.getTbname(),po);
+                        tempmap.put(po.getTbname(), po);
                     }
                 }
 
@@ -379,14 +364,30 @@ public class AlarmWtService {
                 for (ProEconAlarmInfo vo : valuels) {
                     idls.add(vo.getTbname());
                 }
+//
+//                Map<String,ProEconAlarmInfo> infoMap=new HashMap<>();
                 if (!idls.isEmpty()) {
 
+//                    List<ProEconAlarmInfo> templs= proEconAlarmInfoService.listByIds(idls);
+//                    if(!templs.isEmpty())
+//                    {
+//                        for(ProEconAlarmInfo info:templs)
+//                        {
+//                            infoMap.put(info.getTbname().toLowerCase(),info);
+//                        }
+//                    }
                     proEconAlarmInfoService.removeByIds(idls);
                 }
 
 
                 List<ProEconAlarmInfo> templs = new ArrayList<>();
                 for (ProEconAlarmInfo vo : valuels) {
+
+//                    if(infoMap.containsKey(vo.getTbname().toLowerCase()))
+//                    {
+//                        ProEconAlarmInfo in=infoMap.get(vo.getTbname().toLowerCase());
+//                        vo.setUpdateTime(in.getLastUpdateTime());
+//                    }
                     templs.add(vo);
                     if (templs.size() == 500) {
                         proEconAlarmInfoService.saveBatch(templs);
@@ -398,61 +399,89 @@ public class AlarmWtService {
                     proEconAlarmInfoService.saveBatch(templs);
                 }
 
+            }
+
+            if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+
+                for (AlarmTag alarm : ls) {
+                    if (CacheContext.alarmWtMap.containsKey(alarm.getId())) {
+                        AlarmVo vo = CacheContext.alarmWtMap.get(alarm.getId());
 
+                        alarm.setRank(vo.getRank());
+                        alarm.setDescription(vo.getDescription());
+                        alarm.setAlarmType(vo.getAlarmtype());
+                        alarm.setDeviceType(vo.getDevicetype());
+
+                        alarm.setCharacteristic(vo.getCharacteristic());
+                        alarm.setFaultCause(vo.getFaultCause());
+                        alarm.setResolvent(vo.getResolvent());
+                        alarm.setIsClose(false);
+                        alarm.setDeviceId(vo.getDeviceid());
+                        alarm.setAlarmId(vo.getAlarmid());
+
+                        if (StringUtils.notEmp(vo.getDeviceid()) && CacheContext.wtmap.containsKey(vo.getDeviceid())) {
+                            alarm.setCode(CacheContext.wtmap.get(vo.getDeviceid()).getNemCode());
+                        }
+
+                        if (CacheContext.wpmap.containsKey(vo.getStationid())) {
+                            alarm.setWpName(CacheContext.wpmap.get(vo.getStationid()).getName());
+                        }
+
+                        alarm.setWpId(vo.getStationid());
+
+
+                        pushDataSevice.pushWtData(alarm);
+                    }
+                }
+                Thread.sleep(300);
             }
         }
     }
 
 
-    public  synchronized void updateAlarms(List<AlarmTag> ls) throws EncodeException, IOException {
+    public synchronized void updateAlarms(List<AlarmTag> ls) throws EncodeException, IOException, InterruptedException {
 
         if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
-            StringBuilder sb=new StringBuilder();
-            Map<String, AlarmSimpleVo> map=new HashMap<>();
+            StringBuilder sb = new StringBuilder();
+            Map<String, AlarmSimpleVo> map = new HashMap<>();
             for (AlarmTag alarm : ls) {
                 if (CacheContext.alarmWtMap.containsKey(alarm.getId())) {
                     AlarmVo vo = CacheContext.alarmWtMap.get(alarm.getId());
-                    if(vo.getAlarmtype().equals(AlarmTypeValue.WT.getCode())  )
-                    {
+                    if (vo.getAlarmtype().equals(AlarmTypeValue.WT.getCode())) {
                         sb.append("'").append(alarm.getId().toLowerCase()).append("',");
                     }
                 }
 
             }
-            String ids=null;
-            if(sb.length()>0)
-            {
-                ids=sb.substring(0,sb.length()-1);
+            String ids = null;
+            if (sb.length() > 0) {
+                ids = sb.substring(0, sb.length() - 1);
             }
-            List<AlarmSimpleVo> alarmls=new ArrayList<>();
-            if( null !=ids)
-            {
-                alarmls=alarmTsService.selectLastRowByTbname(AlarmSuperTalbeType.WT.getCode(),ids);
+            List<AlarmSimpleVo> alarmls = new ArrayList<>();
+            if (null != ids) {
+                alarmls = alarmTsService.selectLastRowByTbname(AlarmSuperTalbeType.WT.getCode(), ids);
             }
 
-            if(!alarmls.isEmpty())
-            {
-                for(AlarmSimpleVo vo:alarmls)
-                {
-                    map.put(vo.getTbName().toLowerCase(),vo);
+            if (!alarmls.isEmpty()) {
+                for (AlarmSimpleVo vo : alarmls) {
+                    map.put(vo.getTbName().toLowerCase(), vo);
                 }
             }
-            List<AlarmTag> alarmTagls=new ArrayList<>();
+            List<AlarmTag> alarmTagls = new ArrayList<>();
             for (AlarmTag alarm : ls) {
 
 
-                if(map.containsKey(alarm.getId().toLowerCase()))
-                {
-                    AlarmSimpleVo tag=map.get(alarm.getId().toLowerCase());
+                if (map.containsKey(alarm.getId().toLowerCase())) {
+                    AlarmSimpleVo tag = map.get(alarm.getId().toLowerCase());
 
-                    if(null !=tag.getTs())
-                    {
+                    if (null != tag.getTs()) {
                         alarm.setTs(tag.getTs());
                         Date begin = new Date(alarm.getEndts());
                         Date end = new Date(alarm.getTs());
 
-                        double value= DateUtils.secondsDiff(begin,end);
+                        double value = DateUtils.secondsDiff(begin, end);
                         alarm.setTimeLong(value);
                         alarm.setConfirmed(tag.getConfirmed());
                         alarm.setSuperTalbe(AlarmSuperTalbeType.WT.getCode());
@@ -468,16 +497,17 @@ public class AlarmWtService {
                 alarmTsService.insertList(alarmTagls);
             }
 
-            Map<String,ProEconAlarmInfo> tempmap=new HashMap<>();
+            Map<String, ProEconAlarmInfo> tempmap = new HashMap<>();
             if (StringUtils.notEmp(alarmTagls) && !alarmTagls.isEmpty()) {
 
                 List<ProEconAlarmInfo> valuels = new ArrayList<>();
                 for (AlarmTag alarm : alarmTagls) {
                     if (CacheContext.alarmWtMap.containsKey(alarm.getId())) {
                         AlarmVo vo = CacheContext.alarmWtMap.get(alarm.getId());
-         ;
+
                         ProEconAlarmInfo po = new ProEconAlarmInfo();
                         po.setTbname(vo.getTbName());
+                        po.setUpdateTime(new Date(alarm.getTs()));
                         po.setLastUpdateTime(new Date(alarm.getEndts()));
                         po.setTagId(alarm.getTagId());
                         po.setTriggerType(alarm.getTriggerType());
@@ -520,20 +550,23 @@ public class AlarmWtService {
                         alarm.setDeviceId(vo.getDeviceid());
                         alarm.setAlarmId(vo.getAlarmid());
                         alarm.setIsClose(true);
-                        if(CacheContext.wtmap.containsKey(vo.getDeviceid()))
-                        {
+                        if (CacheContext.wtmap.containsKey(vo.getDeviceid())) {
                             alarm.setCode(CacheContext.wtmap.get(vo.getDeviceid()).getNemCode());
                         }
 
-                        if(CacheContext.wpmap.containsKey(vo.getStationid()))
-                        {
+                        if (CacheContext.wpmap.containsKey(vo.getStationid())) {
                             alarm.setWpName(CacheContext.wpmap.get(vo.getStationid()).getName());
                         }
 
-                        pushDataSevice.pushWtData(alarm);
+//                        try {
+//                            pushDataSevice.pushWtData(alarm);
+//                        }catch (Exception e)
+//                        {
+//                            logger.info(e.getMessage());
+//                        }
 
 
-                        tempmap.put(po.getTbname(),po);
+                        tempmap.put(po.getTbname(), po);
                     }
                 }
                 for (Map.Entry<String, ProEconAlarmInfo> entry : tempmap.entrySet()) {
@@ -543,13 +576,29 @@ public class AlarmWtService {
                 for (ProEconAlarmInfo vo : valuels) {
                     idls.add(vo.getTbname());
                 }
+//                Map<String,ProEconAlarmInfo> infoMap=new HashMap<>();
                 if (!idls.isEmpty()) {
 
+//                    List<ProEconAlarmInfo> templs= proEconAlarmInfoService.listByIds(idls);
+//                    if(!templs.isEmpty())
+//                    {
+//                        for(ProEconAlarmInfo info:templs)
+//                        {
+//                            infoMap.put(info.getTbname().toLowerCase(),info);
+//                        }
+//                    }
                     proEconAlarmInfoService.removeByIds(idls);
                 }
 
+
                 List<ProEconAlarmInfo> templs = new ArrayList<>();
                 for (ProEconAlarmInfo vo : valuels) {
+
+//                    if(infoMap.containsKey(vo.getTbname().toLowerCase()))
+//                    {
+//                        ProEconAlarmInfo in=infoMap.get(vo.getTbname().toLowerCase());
+//                        vo.setUpdateTime(in.getLastUpdateTime());
+//                    }
                     templs.add(vo);
                     if (templs.size() == 500) {
                         proEconAlarmInfoService.saveBatch(templs);
@@ -562,8 +611,44 @@ public class AlarmWtService {
                 }
 
             }
-        }
 
+            if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+
+                for (AlarmTag alarm : ls) {
+                    if (CacheContext.alarmWtMap.containsKey(alarm.getId())) {
+                        AlarmVo vo = CacheContext.alarmWtMap.get(alarm.getId());
+
+                        alarm.setRank(vo.getRank());
+                        alarm.setDescription(vo.getDescription());
+                        alarm.setAlarmType(vo.getAlarmtype());
+                        alarm.setDeviceType(vo.getDevicetype());
+
+                        alarm.setCharacteristic(vo.getCharacteristic());
+                        alarm.setFaultCause(vo.getFaultCause());
+                        alarm.setResolvent(vo.getResolvent());
+                        alarm.setIsClose(false);
+                        alarm.setDeviceId(vo.getDeviceid());
+                        alarm.setAlarmId(vo.getAlarmid());
+
+                        if (StringUtils.notEmp(vo.getDeviceid()) && CacheContext.wtmap.containsKey(vo.getDeviceid())) {
+                            alarm.setCode(CacheContext.wtmap.get(vo.getDeviceid()).getNemCode());
+                        }
+
+                        if (CacheContext.wpmap.containsKey(vo.getStationid())) {
+                            alarm.setWpName(CacheContext.wpmap.get(vo.getStationid()).getName());
+                        }
+
+                        alarm.setWpId(vo.getStationid());
+
+
+                        pushDataSevice.pushWtData(alarm);
+                    }
+
+                    Thread.sleep(300);
+                }
+            }
+        }
     }
 
 

+ 108 - 118
alarm-service/src/main/java/com/gyee/alarm/service/PushDataSevice.java

@@ -9,7 +9,7 @@ import com.gyee.alarm.service.auto.ISysUserService;
 import com.gyee.alarm.util.DateUtils;
 import com.gyee.alarm.websocket.PushParams;
 import com.gyee.alarm.websocket.WebSocket;
-import com.gyee.alarm.websocket.WebSocketBt;
+
 import com.gyee.common.model.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -31,10 +31,8 @@ public class PushDataSevice {
     @Resource
     private WebSocket webSocket;
 
-    @Resource
-    private WebSocketBt webSocketBt;
 
-    public void pushWtData(AlarmTag po) throws EncodeException, IOException {
+    public synchronized void pushWtData(AlarmTag po) throws EncodeException, IOException, InterruptedException {
         ConcurrentHashMap<String, WebSocket> webSocketPushMap = WebSocket.webSocketMap;
         ConcurrentHashMap<String, PushParams> webSocketPushParamsMap = WebSocket.webSocketParamsMap;
 
@@ -43,40 +41,13 @@ public class PushDataSevice {
                 // 根据ws连接用户ID获取推送参数
 
 
-                synchronized (po.getId()) {
-//                    if(webSocketPushParamsMap.contains(po.getId()))
-//                    {
-//                        PushParams pp=webSocketPushParamsMap.get(po.getId());
-//
-//                        double hours= DateUtils.hoursDiff(pp.getStartTime(),new Date());
-//                        if(hours>pushinterval)
-//                        {
-//                            if(checkWtId(key,po.getDeviceId()))
-//                            {
-//                                webSocket.sendMessageByUserId(key,po);
-//                                pp.setStartTime(new Date(po.getTs()));
-//                            }
-//                        }
-//                    }else
-//                    {
-//                        if(checkWtId(key,po.getDeviceId()))
-//                        {
-//                            webSocket.sendMessageByUserId(key,po);
-//                            PushParams pp=new PushParams();
-//                            pp.setStartTime(new Date());
-//                            webSocketPushParamsMap.put(po.getId(),pp);
-//
-//
-//                        }
-//
-//                    }
+                if (checkWtId(key, po.getDeviceId())) {
 
-                    if (checkWtId(key, po.getDeviceId())) {
+                    if(webSocketPushMap.containsKey(key))
+                    {
+                        webSocket.sendMessageByUserId(key, po);
 
-                        if(webSocketPushMap.containsKey(key))
-                        {
-                            webSocket.sendMessageByUserId(key, po);
-                        }
+//                        Thread.sleep(300);
                     }
                 }
 
@@ -85,100 +56,119 @@ public class PushDataSevice {
 
     }
 
-    public void pushBtData(AlarmTag po) throws EncodeException, IOException {
+//    public synchronized void pushBtData(AlarmTag po) throws EncodeException, IOException {
+//        ConcurrentHashMap<String, WebSocket> webSocketPushMap = WebSocket.webSocketMap;
+//        ConcurrentHashMap<String, WebSocketBt> webSocketPushBtMap = WebSocketBt.webSocketBtMap;
+//        ConcurrentHashMap<String, PushParams> webSocketPushParamsMap = WebSocket.webSocketParamsMap;
+//
+//        ConcurrentHashMap<String, List<String>> btParamsMap = WebSocketBt.btParamsMap;
+//
+//        if (!webSocketPushMap.isEmpty()) {
+//            for (String key : webSocketPushMap.keySet()) {
+//                // 根据ws连接用户ID获取推送参数
+////                PushParams pushParams = webSocketPushParamsMap.get(key);
+//                synchronized (po.getId()) {
+//                    if (checkBtId(key, po.getWpId())) {
+//                        webSocket.sendMessageByUserId(key, po);
+//
+//                    }
+//                }
+//            }
+//        }
+//
+//        if (!webSocketPushBtMap.isEmpty()) {
+//
+//
+//
+//
+//                if (po.getRank() > 3) {
+//
+//                    if (btParamsMap.containsKey(po.getWpId())) {
+//
+//                        List<String> btls = btParamsMap.get(po.getWpId());
+//
+//                        if (btls.contains(po.getAlarmId())) {
+//                            btls.remove(po.getAlarmId());
+//                        } else {
+//                            btls.add(po.getAlarmId());
+//                        }
+//                        if (btls.isEmpty()) {
+//                            for (String key : webSocketPushBtMap.keySet()) {
+//
+//                                if (checkBtId(key, po.getWpId())) {
+//                                    Map<String, Boolean> map = new HashMap<>();
+//                                    map.put(po.getWpId(), false);
+//                                    webSocketBt.sendMessageByUserId(key, map);
+//                                }
+//                            }
+//
+//                        } else {
+//
+//                            for (String key : webSocketPushBtMap.keySet()) {
+//
+//                                if (checkBtId(key, po.getWpId())) {
+//                                    Map<String, Boolean> map = new HashMap<>();
+//                                    map.put(po.getWpId(), true);
+//                                    webSocketBt.sendMessageByUserId(key, map);
+//                                }
+//                            }
+//                        }
+//                    } else {
+//                        List<String> btls = new ArrayList<>();
+//
+//                        btls.add(po.getAlarmId());
+//
+//                        btParamsMap.put(po.getWpId(), btls);
+//
+//                        if (StringUtils.empty(po.getIsClose())) {
+//                            for (String key : webSocketPushBtMap.keySet()) {
+//
+//
+//                                if (checkBtId(key, po.getWpId())) {
+//                                    Map<String, Boolean> map = new HashMap<>();
+//                                    map.put(po.getWpId(), false);
+//                                    webSocketBt.sendMessageByUserId(key, map);
+//                                }
+//                            }
+//
+//                        } else {
+//                            for (String key : webSocketPushBtMap.keySet()) {
+//
+//
+//                                if (checkBtId(key, po.getWpId())) {
+//                                    Map<String, Boolean> map = new HashMap<>();
+//                                    map.put(po.getWpId(), true);
+//                                    webSocketBt.sendMessageByUserId(key, map);
+//                                }
+//                            }
+//
+//                        }
+//
+//                    }
+//                }
+//
+//            }
+//
+//
+//    }
+
+    public synchronized void pushBtData(AlarmTag po) throws EncodeException, IOException, InterruptedException {
         ConcurrentHashMap<String, WebSocket> webSocketPushMap = WebSocket.webSocketMap;
-        ConcurrentHashMap<String, WebSocketBt> webSocketPushBtMap = WebSocketBt.webSocketBtMap;
         ConcurrentHashMap<String, PushParams> webSocketPushParamsMap = WebSocket.webSocketParamsMap;
 
-        ConcurrentHashMap<String, List<String>> btParamsMap = WebSocketBt.btParamsMap;
+
 
         if (!webSocketPushMap.isEmpty()) {
             for (String key : webSocketPushMap.keySet()) {
                 // 根据ws连接用户ID获取推送参数
 //                PushParams pushParams = webSocketPushParamsMap.get(key);
-                synchronized (po.getId()) {
-                    if (checkBtId(key, po.getWpId())) {
-                        webSocket.sendMessageByUserId(key, po);
-
-                    }
+                if (checkBtId(key, po.getWpId())) {
+                    webSocket.sendMessageByUserId(key, po);
+//                        Thread.sleep(300);
                 }
             }
         }
 
-        if (!webSocketPushBtMap.isEmpty()) {
-
-            synchronized (po.getId()) {
-
-
-                if (po.getRank() > 3) {
-
-                    if (btParamsMap.containsKey(po.getWpId())) {
-
-                        List<String> btls = btParamsMap.get(po.getWpId());
-
-                        if (btls.contains(po.getAlarmId())) {
-                            btls.remove(po.getAlarmId());
-                        } else {
-                            btls.add(po.getAlarmId());
-                        }
-                        if (btls.isEmpty()) {
-                            for (String key : webSocketPushBtMap.keySet()) {
-
-                                if (checkBtId(key, po.getWpId())) {
-                                    Map<String, Boolean> map = new HashMap<>();
-                                    map.put(po.getWpId(), false);
-                                    webSocketBt.sendMessageByUserId(key, map);
-                                }
-                            }
-
-                        } else {
-
-                            for (String key : webSocketPushBtMap.keySet()) {
-
-                                if (checkBtId(key, po.getWpId())) {
-                                    Map<String, Boolean> map = new HashMap<>();
-                                    map.put(po.getWpId(), true);
-                                    webSocketBt.sendMessageByUserId(key, map);
-                                }
-                            }
-                        }
-                    } else {
-                        List<String> btls = new ArrayList<>();
-
-                        btls.add(po.getAlarmId());
-
-                        btParamsMap.put(po.getWpId(), btls);
-
-                        if (StringUtils.empty(po.getIsClose())) {
-                            for (String key : webSocketPushBtMap.keySet()) {
-
-
-                                if (checkBtId(key, po.getWpId())) {
-                                    Map<String, Boolean> map = new HashMap<>();
-                                    map.put(po.getWpId(), false);
-                                    webSocketBt.sendMessageByUserId(key, map);
-                                }
-                            }
-
-                        } else {
-                            for (String key : webSocketPushBtMap.keySet()) {
-
-
-                                if (checkBtId(key, po.getWpId())) {
-                                    Map<String, Boolean> map = new HashMap<>();
-                                    map.put(po.getWpId(), true);
-                                    webSocketBt.sendMessageByUserId(key, map);
-                                }
-                            }
-
-                        }
-
-                    }
-                }
-
-            }
-        }
-
     }
 
     private boolean checkWtId(String userId, String wtId) {

+ 69 - 15
alarm-service/src/main/java/com/gyee/alarm/websocket/WebSocket.java

@@ -62,7 +62,7 @@ public class WebSocket {
         logger.info("用户{}连接成功,当前在线人数为{}", userId, getOnlineCount());
         try {
             sendMessage(String.valueOf(this.session.getQueryString()));
-        } catch (IOException e) {
+        } catch (IOException | EncodeException e) {
             logger.error("IO异常");
         }
     }
@@ -85,9 +85,21 @@ public class WebSocket {
      * @param message 客户端发送过来的消息
      */
     @OnMessage
-    public void onMessage(String message, Session session) throws IOException {
+    public synchronized  void onMessage(String message, Session session) throws IOException, EncodeException {
         logger.info("来自客户端用户:{} 消息:{}",userId, message);
-        sendMessageByUserId(userId,"ok");
+
+
+        if(StringUtils.notEmp(session))
+        {
+
+            synchronized (session){
+                if(session.isOpen() && message.equals("HeartBeat"))
+                {
+                    session.getBasicRemote().sendText("ok");
+                }
+            }
+
+        }
         //群发消息
         /*for (String item : webSocketMap.keySet()) {
             try {
@@ -104,43 +116,84 @@ public class WebSocket {
      * @OnError
      */
     @OnError
-    public void onError(Session session, Throwable error) {
+    public void onError(Session session, Throwable error)   {
         logger.error("用户错误:" + this.userId + ",原因:" + error.getMessage());
         error.printStackTrace();
+
+
+
     }
 
     /**
      * 向客户端发送消息
      */
-    public void sendMessage(String message) throws IOException {
-        this.session.getBasicRemote().sendText(message);
+    public void sendMessage(String message) throws IOException, EncodeException {
+//        this.session.getBasicRemote().sendText(message);
+
+        if(StringUtils.notEmp(session))
+        {
+
+            synchronized (session){
+                if(session.isOpen())
+                {
+                    session.getBasicRemote().sendObject(message);
+                }
+            }
+
+        }
         //this.session.getAsyncRemote().sendText(message);
     }
 
     /**
      * 向客户端发送消息
      */
-    public   void sendMessage(Object message) throws IOException, EncodeException {
+    public synchronized void sendMessage(Object message) throws IOException, EncodeException {
+
+        try {
+            if(StringUtils.notEmp(session))
+            {
 
-        if(StringUtils.notEmp(this.session))
+                synchronized (session){
+
+                    if( session.isOpen())
+                    {
+                        session.getBasicRemote().sendObject(message);
+                    }
+                }
+
+            }
+        }catch (Exception e)
         {
+            if(StringUtils.notEmp(userId) && webSocketMap.containsKey(userId))
+            {
+                webSocketMap.remove(userId);
+                subOnlineCount();           //在线数减1
+                logger.info("用户{}关闭连接!当前在线人数为{}", userId, getOnlineCount());
+            }
 
-            synchronized (this.session){
-                if(this.session.isOpen())
+            try {
+                if(StringUtils.notEmp(session))
                 {
-                    this.session.getBasicRemote().sendObject(message);
+                    session.close();
+                    logger.info("用户错误:" + this.userId + ",关闭session:" );
+                }else
+                {
+                    logger.info( ",session:null" );
                 }
-            }
+            }catch (IOException io)
+            {
 
+            }
         }
 
+
         //this.session.getAsyncRemote().sendText(message);
     }
 
     /**
      * 通过userId向客户端发送消息
      */
-    public void sendMessageByUserId(String userId, String message) throws IOException {
+    public void sendMessageByUserId(String userId, String message) throws IOException, EncodeException {
         logger.info("服务端发送消息到{},消息:{}",userId,message);
 
         if(StringUtils.isNotBlank(userId)&&webSocketMap.containsKey(userId)){
@@ -159,7 +212,7 @@ public class WebSocket {
     /**
      * 通过userId向客户端发送消息
      */
-    public void sendMessageByUserId(String userId, Object message) throws IOException, EncodeException {
+    public synchronized  void sendMessageByUserId(String userId, Object message) throws IOException, EncodeException {
         logger.info("服务端发送消息到{},消息:{}",userId,message);
         if(StringUtils.isNotBlank(userId)&&webSocketMap.containsKey(userId)){
             webSocketMap.get(userId).sendMessage(message);
@@ -183,7 +236,7 @@ public class WebSocket {
         for (String item : webSocketMap.keySet()) {
             try {
                 webSocketMap.get(item).sendMessage(message);
-            } catch (IOException e) {
+            } catch (IOException | EncodeException e) {
                 continue;
             }
         }
@@ -201,4 +254,5 @@ public class WebSocket {
         WebSocket.onlineCount--;
     }
 
+
 }

+ 191 - 191
alarm-service/src/main/java/com/gyee/alarm/websocket/WebSocketBt.java

@@ -1,191 +1,191 @@
-package com.gyee.alarm.websocket;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import javax.websocket.*;
-import javax.websocket.server.PathParam;
-import javax.websocket.server.ServerEndpoint;
-import java.io.IOException;
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * 功能描述:
- * WebSocketServer服务端
- * @Date: 2022-12-01 09:41:32
- * @since: 1.0.0
- */
-// @ServerEndpoint 注解是一个类层次的注解,它的功能主要是将目前的类定义成一个websocket服务器端。注解的值将被用于监听用户连接的终端访问URL地址
-// encoders = WebSocketCustomEncoding.class 是为了使用ws自己的推送Object消息对象(sendObject())时进行解码,通过Encoder 自定义规则(转换为JSON字符串)
-@ServerEndpoint(value = "/websocketBt/{userId}",encoders = WebSocketCustomEncoding.class)
-@Component
-public class WebSocketBt {
-    private final static Logger logger = LogManager.getLogger(WebSocketBt.class);
-
-    /**
-     * 静态变量,用来记录当前在线连接数。应该把它设计成线程安全的
-     */
-
-    private static int onlineCount = 0;
-
-    /**
-     * concurrent包的线程安全Map,用来存放每个客户端对应的MyWebSocket对象
-     */
-    public static ConcurrentHashMap<String, WebSocketBt> webSocketBtMap = new ConcurrentHashMap<>();
-
-    /***
-     * 功能描述:
-     * concurrent包的线程安全Map,用来存放每个客户端对应的MyWebSocket对象的参数体
-     */
-    public static ConcurrentHashMap<String, PushParams> webSocketParamsBtMap = new ConcurrentHashMap<>();
-
-    public static ConcurrentHashMap<String, List<String>> btParamsMap = new ConcurrentHashMap<>();
-    /**
-     * 与某个客户端的连接会话,需要通过它来给客户端发送数据
-     */
-
-    private Session session;
-    private String userId;
-
-
-    /**
-     * 连接建立成功调用的方法
-     * onOpen 和 onClose 方法分别被@OnOpen和@OnClose 所注解。他们定义了当一个新用户连接和断开的时候所调用的方法。
-     */
-    @OnOpen
-    public void onOpen(Session session, @PathParam("userId") String userId) {
-        this.session = session;
-        this.userId = userId;
-        //加入map
-        webSocketBtMap.put(userId, this);
-        addOnlineCount();           //在线数加1
-        logger.info("Bt用户{}连接成功,当前在线人数为{}", userId, getOnlineCount());
-        try {
-            sendMessage(String.valueOf(this.session.getQueryString()));
-        } catch (IOException e) {
-            logger.error("BtIO异常");
-        }
-    }
-
-
-    /**
-     * 连接关闭调用的方法
-     */
-    @OnClose
-    public void onClose() {
-        //从map中删除
-        webSocketBtMap.remove(userId);
-        subOnlineCount();           //在线数减1
-        logger.info("Bt用户{}关闭连接!当前在线人数为{}", userId, getOnlineCount());
-    }
-
-    /**
-     * 收到客户端消息后调用的方法
-     * onMessage 方法被@OnMessage所注解。这个注解定义了当服务器接收到客户端发送的消息时所调用的方法。
-     * @param message 客户端发送过来的消息
-     */
-    @OnMessage
-    public void onMessage(String message, Session session) throws IOException {
-        logger.info("Bt来自客户端用户:{} 消息:{}",userId, message);
-
-        sendMessageByUserId(userId,"ok");
-        //群发消息
-        /*for (String item : webSocketBtMap.keySet()) {
-            try {
-                webSocketBtMap.get(item).sendMessage(message);
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }*/
-    }
-
-    /**
-     * 发生错误时调用
-     *
-     * @OnError
-     */
-    @OnError
-    public void onError(Session session, Throwable error) {
-        logger.error("Bt用户错误:" + this.userId + ",原因:" + error.getMessage());
-        error.printStackTrace();
-    }
-
-    /**
-     * 向客户端发送消息
-     */
-    public void sendMessage(String message) throws IOException {
-        this.session.getBasicRemote().sendText(message);
-        //this.session.getAsyncRemote().sendText(message);
-    }
-
-    /**
-     * 向客户端发送消息
-     */
-    public void sendMessage(Object message) throws IOException, EncodeException {
-        this.session.getBasicRemote().sendObject(message);
-        //this.session.getAsyncRemote().sendText(message);
-    }
-
-    /**
-     * 通过userId向客户端发送消息
-     */
-    public void sendMessageByUserId(String userId, String message) throws IOException {
-        logger.info("Bt服务端发送消息到{},消息:{}",userId,message);
-
-        if(StringUtils.isNotBlank(userId)&&webSocketBtMap.containsKey(userId)){
-            webSocketBtMap.get(userId).sendMessage(message);
-        }else{
-            logger.error("Bt用户{}不在线",userId);
-        }
-
-    }
-
-    /**
-     * 通过userId向客户端发送消息
-     */
-    public void sendMessageByUserId(String userId, Object message) throws IOException, EncodeException {
-        logger.info("Bt服务端发送消息到{},消息:{}",userId,message);
-        if(StringUtils.isNotBlank(userId)&&webSocketBtMap.containsKey(userId)){
-            webSocketBtMap.get(userId).sendMessage(message);
-        }else{
-            logger.error("Bt用户{}不在线",userId);
-        }
-    }
-
-    /**
-     * 通过userId更新缓存的参数
-     */
-    public void changeParamsByUserId(String userId, PushParams pushParams) throws IOException, EncodeException {
-        logger.info("wsBt用户{}请求参数更新,参数:{}",userId,pushParams.toString());
-        webSocketParamsBtMap.put(userId,pushParams);
-    }
-
-    /**
-     * 群发自定义消息
-     */
-    public static void sendInfo(String message) throws IOException {
-        for (String item : webSocketBtMap.keySet()) {
-            try {
-                webSocketBtMap.get(item).sendMessage(message);
-            } catch (IOException e) {
-                continue;
-            }
-        }
-    }
-
-    public static synchronized int getOnlineCount() {
-        return onlineCount;
-    }
-
-    public static synchronized void addOnlineCount() {
-        WebSocketBt.onlineCount++;
-    }
-
-    public static synchronized void subOnlineCount() {
-        WebSocketBt.onlineCount--;
-    }
-
-}
+//package com.gyee.alarm.websocket;
+//
+//import org.apache.commons.lang.StringUtils;
+//import org.apache.logging.log4j.LogManager;
+//import org.apache.logging.log4j.Logger;
+//import org.springframework.stereotype.Component;
+//
+//import javax.websocket.*;
+//import javax.websocket.server.PathParam;
+//import javax.websocket.server.ServerEndpoint;
+//import java.io.IOException;
+//import java.util.List;
+//import java.util.concurrent.ConcurrentHashMap;
+//
+///**
+// * 功能描述:
+// * WebSocketServer服务端
+// * @Date: 2022-12-01 09:41:32
+// * @since: 1.0.0
+// */
+//// @ServerEndpoint 注解是一个类层次的注解,它的功能主要是将目前的类定义成一个websocket服务器端。注解的值将被用于监听用户连接的终端访问URL地址
+//// encoders = WebSocketCustomEncoding.class 是为了使用ws自己的推送Object消息对象(sendObject())时进行解码,通过Encoder 自定义规则(转换为JSON字符串)
+//@ServerEndpoint(value = "/websocketBt/{userId}",encoders = WebSocketCustomEncoding.class)
+//@Component
+//public class WebSocketBt {
+//    private final static Logger logger = LogManager.getLogger(WebSocketBt.class);
+//
+//    /**
+//     * 静态变量,用来记录当前在线连接数。应该把它设计成线程安全的
+//     */
+//
+//    private static int onlineCount = 0;
+//
+//    /**
+//     * concurrent包的线程安全Map,用来存放每个客户端对应的MyWebSocket对象
+//     */
+//    public static ConcurrentHashMap<String, WebSocketBt> webSocketBtMap = new ConcurrentHashMap<>();
+//
+//    /***
+//     * 功能描述:
+//     * concurrent包的线程安全Map,用来存放每个客户端对应的MyWebSocket对象的参数体
+//     */
+//    public static ConcurrentHashMap<String, PushParams> webSocketParamsBtMap = new ConcurrentHashMap<>();
+//
+//    public static ConcurrentHashMap<String, List<String>> btParamsMap = new ConcurrentHashMap<>();
+//    /**
+//     * 与某个客户端的连接会话,需要通过它来给客户端发送数据
+//     */
+//
+//    private Session session;
+//    private String userId;
+//
+//
+//    /**
+//     * 连接建立成功调用的方法
+//     * onOpen 和 onClose 方法分别被@OnOpen和@OnClose 所注解。他们定义了当一个新用户连接和断开的时候所调用的方法。
+//     */
+//    @OnOpen
+//    public void onOpen(Session session, @PathParam("userId") String userId) {
+//        this.session = session;
+//        this.userId = userId;
+//        //加入map
+//        webSocketBtMap.put(userId, this);
+//        addOnlineCount();           //在线数加1
+//        logger.info("Bt用户{}连接成功,当前在线人数为{}", userId, getOnlineCount());
+//        try {
+//            sendMessage(String.valueOf(this.session.getQueryString()));
+//        } catch (IOException e) {
+//            logger.error("BtIO异常");
+//        }
+//    }
+//
+//
+//    /**
+//     * 连接关闭调用的方法
+//     */
+//    @OnClose
+//    public void onClose() {
+//        //从map中删除
+//        webSocketBtMap.remove(userId);
+//        subOnlineCount();           //在线数减1
+//        logger.info("Bt用户{}关闭连接!当前在线人数为{}", userId, getOnlineCount());
+//    }
+//
+//    /**
+//     * 收到客户端消息后调用的方法
+//     * onMessage 方法被@OnMessage所注解。这个注解定义了当服务器接收到客户端发送的消息时所调用的方法。
+//     * @param message 客户端发送过来的消息
+//     */
+//    @OnMessage
+//    public void onMessage(String message, Session session) throws IOException {
+//        logger.info("Bt来自客户端用户:{} 消息:{}",userId, message);
+//
+//        sendMessageByUserId(userId,"ok");
+//        //群发消息
+//        /*for (String item : webSocketBtMap.keySet()) {
+//            try {
+//                webSocketBtMap.get(item).sendMessage(message);
+//            } catch (IOException e) {
+//                e.printStackTrace();
+//            }
+//        }*/
+//    }
+//
+//    /**
+//     * 发生错误时调用
+//     *
+//     * @OnError
+//     */
+//    @OnError
+//    public void onError(Session session, Throwable error) {
+//        logger.error("Bt用户错误:" + this.userId + ",原因:" + error.getMessage());
+//        error.printStackTrace();
+//    }
+//
+//    /**
+//     * 向客户端发送消息
+//     */
+//    public void sendMessage(String message) throws IOException {
+//        this.session.getBasicRemote().sendText(message);
+//        //this.session.getAsyncRemote().sendText(message);
+//    }
+//
+//    /**
+//     * 向客户端发送消息
+//     */
+//    public void sendMessage(Object message) throws IOException, EncodeException {
+//        this.session.getBasicRemote().sendObject(message);
+//        //this.session.getAsyncRemote().sendText(message);
+//    }
+//
+//    /**
+//     * 通过userId向客户端发送消息
+//     */
+//    public void sendMessageByUserId(String userId, String message) throws IOException {
+//        logger.info("Bt服务端发送消息到{},消息:{}",userId,message);
+//
+//        if(StringUtils.isNotBlank(userId)&&webSocketBtMap.containsKey(userId)){
+//            webSocketBtMap.get(userId).sendMessage(message);
+//        }else{
+//            logger.error("Bt用户{}不在线",userId);
+//        }
+//
+//    }
+//
+//    /**
+//     * 通过userId向客户端发送消息
+//     */
+//    public synchronized void sendMessageByUserId(String userId, Object message) throws IOException, EncodeException {
+//        logger.info("Bt服务端发送消息到{},消息:{}",userId,message);
+//        if(StringUtils.isNotBlank(userId)&&webSocketBtMap.containsKey(userId)){
+//            webSocketBtMap.get(userId).sendMessage(message);
+//        }else{
+//            logger.error("Bt用户{}不在线",userId);
+//        }
+//    }
+//
+//    /**
+//     * 通过userId更新缓存的参数
+//     */
+//    public void changeParamsByUserId(String userId, PushParams pushParams) throws IOException, EncodeException {
+//        logger.info("wsBt用户{}请求参数更新,参数:{}",userId,pushParams.toString());
+//        webSocketParamsBtMap.put(userId,pushParams);
+//    }
+//
+//    /**
+//     * 群发自定义消息
+//     */
+//    public static void sendInfo(String message) throws IOException {
+//        for (String item : webSocketBtMap.keySet()) {
+//            try {
+//                webSocketBtMap.get(item).sendMessage(message);
+//            } catch (IOException e) {
+//                continue;
+//            }
+//        }
+//    }
+//
+//    public static synchronized int getOnlineCount() {
+//        return onlineCount;
+//    }
+//
+//    public static synchronized void addOnlineCount() {
+//        WebSocketBt.onlineCount++;
+//    }
+//
+//    public static synchronized void subOnlineCount() {
+//        WebSocketBt.onlineCount--;
+//    }
+//
+//}

+ 5 - 4
alarm-service/src/main/resources/application-jn.yml

@@ -134,12 +134,13 @@ logging:
 
 #db url
 db:
-  url1: http://10.81.3.154:8011/ts
-  url2: http://10.81.3.154:8012/ts
-
+#  url1: http://10.81.3.154:8011/ts
+#  url2: http://10.81.3.154:8012/ts
+  url1: http://127.0.0.1:8011/ts
+  url2: http://127.0.0.1:8012/ts
 
 #参与计算的场站
-#runWindpowerstation: SXJ_KGDL_GJY_FDC_STA
+#runWindpowerstation: SXJ_KGDL_PTZ_FDC_STA
 runWindpowerstation: SXJ_KGDL_DJY_FDC_STA,SXJ_KGDL_NJL_FDC_STA,SXJ_KGDL_YF_FDC_STA,SXJ_KGDL_YLZ_FDC_STA,SXJ_KGDL_XWT_FDC_STA,SXJ_KGDL_PTZ_FDC_STA,SXJ_KGDL_GJY_FDC_STA,SXJ_KGDL_BHB_FDC_STA,SXJ_KGDL_HSM_FDC_STA,SXJ_KGDL_YTY_FDC_STA,SXJ_KGDL_BHB3_FDC_STA,SXJ_KGDL_SY_GDC_STA,SXJ_KGDL_PDL_FDC_STA,SXJ_KGDL_ZK_FDC_STA,SXJ_KGDL_JR_GDC_STA,SXJ_KGDL_FS_GDC_STA,SXJ_KGDL_HR_GDC_STA,SXJ_KGDL_YY_GDC_STA,SXJ_KGDL_PL_GDC_STA,SXJ_KGDL_YG_GDC_STA,SXJ_KGDL_YX_GDC_STA,SXJ_KGDL_TZ_GDC_STA,SXJ_KGDL_TL_GDC_STA
 #计算状态用ai或者di
 clauStatus:

File diff suppressed because it is too large
+ 38 - 7
alarm-service/src/test/java/com/gyee/AppTest.java


+ 145 - 0
alarm-web/src/main/java/com/gyee/alarm/controller/AlarmHistoryController.java

@@ -253,6 +253,151 @@ public class AlarmHistoryController {
 
     }
 
+
+
+    @GetMapping(value = "/history/findCtFeatureStatByWpId")
+    @ApiOperation(value = "查询自定义报警类型、报警时长、报警次数", notes = "查询报警类型、报警时长、报警次数")
+    @ApiImplicitParams({
+
+            @ApiImplicitParam(name = "begin", value = "开始时间", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "end", value = "结束时间", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "stationid", value = "场站编号", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "modelId", value = "型号编号", required = false, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "components", value = "部件集合", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "deviceType", value = "报警类型 booststation:升压站报警,windturbine:设备报警,inverter:光伏", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "alarmIds", value = "报警编号集合", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "timeType", value = "秒、分、时(s,m,h)", required = false, dataType = "string", paramType = "query")
+    })
+    public List<Map.Entry<String, List<AlarmStatVo>>> findCtFeatureStatByWpId(
+
+            @RequestParam(value = "begin", required = true) String begin,
+            @RequestParam(value = "end", required = true) String end,
+            @RequestParam(value = "stationid", required = true) String stId,
+            @RequestParam(value = "modelId", required = false) String modelId,
+            @RequestParam(value = "components", required = true) String components,
+            @RequestParam(value = "deviceType", required = true) String deviceType,
+            @RequestParam(value = "alarmIds", required = true) String alarmIds,
+            @RequestParam(value = "timeType", required = false) String timeType
+    ) throws ParseException {
+
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date dtStart = sdf.parse(begin);
+        Date dtEnd = sdf.parse(end);
+
+        if(StringUtils.empty(modelId))
+        {
+            modelId=null;
+        }
+        List<AlarmStatVo> pressureList = alarmHistoryService.findCtFeatureStatByWpId(modelId, dtStart, dtEnd,components,deviceType,alarmIds,timeType);
+
+//
+//        Map<String, List<AlarmStatVo>> map=new TreeMap<>();
+//
+//        for(AlarmStatVo vo:pressureList)
+//        {
+//            if(map.containsKey(vo.getRelateParts()))
+//            {
+//                List<AlarmStatVo>
+//            }
+//        }
+        //根据风机编号分组
+        Map<String, List<AlarmStatVo>> alarmStatMapGroupbyWindturbineId = pressureList.stream().collect(Collectors.groupingBy(AlarmStatVo::getStationId));
+
+        Map<String, List<AlarmStatVo>> resultMap = new TreeMap<>();
+
+        for (Map.Entry<String, List<AlarmStatVo>> entry : alarmStatMapGroupbyWindturbineId.entrySet()) {
+            String wpId = entry.getKey();
+            resultMap.put(wpId, entry.getValue());
+        }
+
+        //根据风机编号进行排序
+        List<Map.Entry<String, List<AlarmStatVo>>> list = new ArrayList<>(resultMap.entrySet());
+        Collections.sort(list, new Comparator<Map.Entry<String, List<AlarmStatVo>>>() {
+            @Override
+            public int compare(Map.Entry<String, List<AlarmStatVo>> o1, Map.Entry<String, List<AlarmStatVo>> o2) {
+                String key1=o1.getKey();
+                String key2=o1.getKey();
+                return key1.compareTo(key2);
+            }
+        });
+
+        return list;
+
+    }
+
+
+    @GetMapping(value = "/history/findCtFeatureStatByLnId")
+    @ApiOperation(value = "查询自定义报警类型、报警时长、报警次数", notes = "查询报警类型、报警时长、报警次数")
+    @ApiImplicitParams({
+
+            @ApiImplicitParam(name = "begin", value = "开始时间", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "end", value = "结束时间", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "stationid", value = "场站编号", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "modelId", value = "型号编号", required = false, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "components", value = "部件集合", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "deviceType", value = "报警类型 booststation:升压站报警,windturbine:设备报警,inverter:光伏", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "alarmIds", value = "报警编号集合", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "timeType", value = "秒、分、时(s,m,h)", required = false, dataType = "string", paramType = "query")
+    })
+    public List<Map.Entry<String, List<AlarmStatVo>>> findCtFeatureStatByLnId(
+
+            @RequestParam(value = "begin", required = true) String begin,
+            @RequestParam(value = "end", required = true) String end,
+            @RequestParam(value = "stationid", required = true) String stId,
+            @RequestParam(value = "modelId", required = false) String modelId,
+            @RequestParam(value = "components", required = true) String components,
+            @RequestParam(value = "deviceType", required = true) String deviceType,
+            @RequestParam(value = "alarmIds", required = true) String alarmIds,
+            @RequestParam(value = "timeType", required = false) String timeType
+    ) throws ParseException {
+
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date dtStart = sdf.parse(begin);
+        Date dtEnd = sdf.parse(end);
+
+        if(StringUtils.empty(modelId))
+        {
+            modelId=null;
+        }
+        List<AlarmStatVo> pressureList = alarmHistoryService.findCtFeatureStatByLnId(stId,modelId, dtStart, dtEnd,components,deviceType,alarmIds,timeType);
+
+//
+//        Map<String, List<AlarmStatVo>> map=new TreeMap<>();
+//
+//        for(AlarmStatVo vo:pressureList)
+//        {
+//            if(map.containsKey(vo.getRelateParts()))
+//            {
+//                List<AlarmStatVo>
+//            }
+//        }
+        //根据风机编号分组
+        Map<String, List<AlarmStatVo>> alarmStatMapGroupbyWindturbineId = pressureList.stream().collect(Collectors.groupingBy(AlarmStatVo::getStationId));
+
+        Map<String, List<AlarmStatVo>> resultMap = new TreeMap<>();
+
+        for (Map.Entry<String, List<AlarmStatVo>> entry : alarmStatMapGroupbyWindturbineId.entrySet()) {
+            String wpId = entry.getKey();
+            resultMap.put(wpId, entry.getValue());
+        }
+
+        //根据风机编号进行排序
+        List<Map.Entry<String, List<AlarmStatVo>>> list = new ArrayList<>(resultMap.entrySet());
+        Collections.sort(list, new Comparator<Map.Entry<String, List<AlarmStatVo>>>() {
+            @Override
+            public int compare(Map.Entry<String, List<AlarmStatVo>> o1, Map.Entry<String, List<AlarmStatVo>> o2) {
+                String key1=o1.getKey();
+                String key2=o1.getKey();
+                return key1.compareTo(key2);
+            }
+        });
+
+        return list;
+
+    }
+
 }
 
 

+ 172 - 0
alarm-web/src/main/java/com/gyee/alarm/controller/ProEconAlarmInfoController.java

@@ -0,0 +1,172 @@
+package com.gyee.alarm.controller;
+
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gyee.alarm.model.auto.ProEconAlarmConfiguration;
+import com.gyee.alarm.model.auto.ProEconAlarmInfo;
+import com.gyee.alarm.model.vo.AjaxResult;
+import com.gyee.alarm.model.vo.AjaxStatus;
+import com.gyee.alarm.model.vo.AlarmConfigurationVo;
+import com.gyee.alarm.model.vo.ProEconAlarmInfoVo;
+import com.gyee.alarm.service.AlarmConfigurationService;
+import com.gyee.alarm.service.auto.IProEconAlarmInfoService;
+import com.gyee.alarm.util.StringUtils;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>
+ * 报警缓存表 前端控制器
+ * </p>
+ *
+ * @author shilin
+ * @since 2023-10-12
+ */
+@RestController
+@RequestMapping("//alarminfo")
+public class ProEconAlarmInfoController {
+    @Resource
+    private IProEconAlarmInfoService proEconAlarmInfoService;
+
+    @GetMapping(value = "/findAlarmlist")
+    @ApiOperation(value = "报警信息查询", notes = "报警信息查询")
+    @ApiImplicitParams({
+
+            @ApiImplicitParam(name = "begin", value = "开始时间", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "end", value = "结束时间", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "alarmType", value = "报警类型 booststation:升压站报警,windturbine:设备报警,custom:自定义报警", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "stationid", value = "场站编号", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "deviceid", value = "设备编号", required = false, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "description", value = "描述", required = false, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "modelId", value = "型号", required = false, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "deviceType", value = "报警类型 booststation:升压站报警,windturbine:设备报警", required = false, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "components", value = "部件编号", required = false, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "alarmId", value = "报警编号", required = false, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "isclose", value = "是否完成 不传全查,true 完成的,false 没完成的", required = false, dataType = "Boolean", paramType = "query"),
+            @ApiImplicitParam(name = "pageNum", value = "页号", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "pageSize", value = "每页显示行数", required = true, dataType = "string", paramType = "query")})
+    public AjaxResult findAlarmlist(
+            @RequestParam(value = "begin", required = false) String begin,
+            @RequestParam(value = "end", required = false) String end,
+            @RequestParam(value = "alarmType", required = false) String alarmType,
+            @RequestParam(value = "stationid", required = false) String stationid,
+            @RequestParam(value = "deviceid", required = false) String deviceid,
+            @RequestParam(value = "description", required = false) String description,
+            @RequestParam(value = "modelId", required = false) String modelId,
+            @RequestParam(value = "deviceType", required = false) String deviceType,
+            @RequestParam(value = "components", required = false) String components,
+            @RequestParam(value = "alarmId", required = false) String alarmId,
+            @RequestParam(value = "isclose", required = false) Boolean isclose,
+            @RequestParam(value = "pageNum", required = true) Integer pageNum,
+            @RequestParam(value = "pageSize", required = true) Integer pageSize
+
+    ) throws Exception {
+
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+        Date beginDate = null;
+        Date endDate = null;
+        if(StringUtils.notEmp(begin) && StringUtils.notEmp(end))
+        {         beginDate = df.parse(begin);
+             endDate = df.parse(end);
+        }
+
+        Page<ProEconAlarmConfiguration> page = new Page(pageNum, pageSize);
+        IPage<ProEconAlarmInfo> map = proEconAlarmInfoService.findAlarmlist(page,modelId,beginDate, endDate, alarmType, stationid,deviceid, description,deviceType,components,alarmId,isclose, pageNum, pageSize);
+
+        IPage<ProEconAlarmInfoVo> vomap=new Page<>();
+        if(StringUtils.notEmp(map) && StringUtils.notEmp(map.getRecords()))
+        {
+            vomap.setTotal(map.getTotal());
+            List<ProEconAlarmInfoVo> vos=new ArrayList<>();
+            for(ProEconAlarmInfo info:map.getRecords())
+            {
+                ProEconAlarmInfoVo vo=new ProEconAlarmInfoVo();
+                vo.setCharacteristic(info.getCharacteristic());
+                vo.setTbname(info.getTbname());
+
+                if(StringUtils.notEmp(info.getLastUpdateTime()))
+                {
+                    vo.setLastUpdateTime(info.getLastUpdateTime().getTime());
+                }else
+                {
+                    vo.setLastUpdateTime(0l);
+                }
+                vo.setVal(info.getVal());
+                vo.setTagId(info.getTagId());
+                vo.setTriggerType(info.getTriggerType());
+                vo.setAlarmId(info.getAlarmId());
+                vo.setDeviceId(info.getDeviceId());
+                vo.setSuffix(info.getSuffix());
+                vo.setRank(info.getRank());
+                vo.setConfirmed(info.getConfirmed());
+                vo.setUniformCode(info.getUniformCode());
+                vo.setAlarmType(info.getAlarmType());
+                vo.setDeviceType(info.getDeviceType());
+                vo.setComponents(info.getComponents());
+                vo.setSubcomponents(info.getSubcomponents());
+                vo.setDescription(info.getDescription());
+                vo.setModelId(info.getModelId());
+                vo.setResetTable(info.getResetTable());
+                vo.setEnable(info.getEnable());
+                vo.setCharacteristic(info.getCharacteristic());
+                vo.setStationId(info.getStationId());
+                vo.setProjectId(info.getProjectId());
+                vo.setLineId(info.getLineId());
+                vo.setStationName(info.getStationName());
+                vo.setProjectiName(info.getProjectiName());
+                vo.setLineidName(info.getLineidName());
+                vo.setDeviceName(info.getDeviceName());
+                vo.setOval(info.getOval());
+                vo.setIsOpen(info.getIsOpen());
+
+                if(StringUtils.notEmp(info.getConfirmedTime()))
+                {
+                    vo.setConfirmedTime(info.getConfirmedTime().getTime());
+                }else
+                {
+                    vo.setConfirmedTime(0l);
+                }
+
+                if(StringUtils.notEmp(info.getCloseTime()))
+                {
+                    vo.setCloseTime(info.getCloseTime().getTime());
+                }else
+                {
+                    vo.setCloseTime(0l);
+                }
+
+                if(StringUtils.notEmp(info.getUpdateTime()))
+                {
+                    vo.setUpdateTime(info.getUpdateTime().getTime());
+                }else
+                {
+                    vo.setUpdateTime(0l);
+                }
+
+                vos.add(vo);
+            }
+            vomap.setRecords(vos);
+
+        }
+        return AjaxResult.successData(AjaxStatus.success.code, vomap);
+
+    }
+}

+ 17 - 0
alarm-web/src/main/java/com/gyee/alarm/init/CacheContext.java

@@ -141,6 +141,7 @@ public class CacheContext implements CommandLineRunner {
     public static Map<String, ProBasicMeterPoint> meterpointMap = new HashMap<>();
     public static Map<String, List<ProBasicProject>> wppromap = new HashMap<>();
     public static Map<String, List<ProBasicLine>> prolinemap = new HashMap<>();
+    public static Map<String, List<ProBasicLine>> wplinemap = new HashMap<>();
     public static Map<String, List<ProBasicEquipment>> wpwtmap = new HashMap<>();
     public static Map<String, List<ProBasicEquipment>> pjwtmap = new HashMap<>();
     public static Map<String, List<ProBasicEquipment>> lnwtmap = new HashMap<>();
@@ -550,6 +551,22 @@ public class CacheContext implements CommandLineRunner {
                 lineList.add(l);
                 prolinemap.put(l.getProjectId(), lineList);
             }
+
+            if(pjmap.containsKey(l.getProjectId()))
+            {
+                ProBasicProject pj= pjmap.get(l.getProjectId());
+                if (wplinemap.containsKey(pj.getWindpowerstationId())) {
+                    wplinemap.get(pj.getWindpowerstationId()).add(l);
+                } else {
+                    List<ProBasicLine> lineList = new ArrayList<>();
+
+                    lineList.add(l);
+                    wplinemap.put(pj.getWindpowerstationId(), lineList);
+                }
+            }
+
+
+
             String lnString = redisService.get(l.getId());
             Map<String, ProBasicPowerstationPoint> stringWindpowerstationpointnewMap = JSONObject.parseObject(lnString, new TypeReference<Map<String, ProBasicPowerstationPoint>>() {
             });

+ 57 - 0
alarm-web/src/main/java/com/gyee/alarm/mapper/auto/AlarmTsMapper.java

@@ -250,7 +250,9 @@ public interface AlarmTsMapper extends BaseMapper<AlarmTs> {
             " ts &gt;= #{begin}",
             "and ts &lt;= #{end}",
             "and stationid = #{stationid}",
+            "<if test='modelId != null'>",
             "and modelId = #{modelId}",
+            "</if>",
             "<if test='alarmid != null'>",
             "and alarmid in(${alarmid}) ",
             "</if>",
@@ -267,6 +269,61 @@ public interface AlarmTsMapper extends BaseMapper<AlarmTs> {
             "</script>"})
     List<ProBasicFeatureStat> findCtFeatureStat( @Param("begin")long begin, @Param("end") long end, @Param("stationid") String stationid, @Param("modelId")String modelId, @Param("components") String components, @Param("alarmid") String alarmid, @Param("deviceType")String deviceType);
 
+    @Select({"<script>",
+            "select  stationid as stationId,alarmid,description,components as typeCode,max(timeLong) as maxSeconds,min(timeLong) as minSeconds,avg(timeLong) as avgSeconds,sum(timeLong) as totalSeconds,count(*) as total from alarmCt " ,
+            "<where>" ,
+
+            " ts &gt;= #{begin}",
+            "and ts &lt;= #{end}",
+
+            "<if test='modelId != null'>",
+            "and modelId = #{modelId}",
+            "</if>",
+
+            "<if test='alarmid != null'>",
+            "and alarmid in(${alarmid}) ",
+            "</if>",
+            "<if test='components != null'>",
+            "and components in(${components}) ",
+            "</if>",
+            "<if test='deviceType != null'>",
+            "and deviceType = #{deviceType}",
+            "</if>",
+            "</where>",
+
+            " group by  components,stationid,alarmid,description ",
+            " order by stationid  ",
+            "</script>"})
+    List<ProBasicFeatureStat> findCtFeatureStatByWpId( @Param("begin")long begin, @Param("end") long end, @Param("stationid") String stationid, @Param("modelId")String modelId, @Param("components") String components, @Param("alarmid") String alarmid, @Param("deviceType")String deviceType);
+
+
+    @Select({"<script>",
+            "select  lineid as stationId,alarmid,description,components as typeCode,max(timeLong) as maxSeconds,min(timeLong) as minSeconds,avg(timeLong) as avgSeconds,sum(timeLong) as totalSeconds,count(*) as total from alarmCt " ,
+            "<where>" ,
+
+            " ts &gt;= #{begin}",
+            "and ts &lt;= #{end}",
+            "and stationid = #{stationid}",
+            "<if test='modelId != null'>",
+            "and modelId = #{modelId}",
+            "</if>",
+
+            "<if test='alarmid != null'>",
+            "and alarmid in(${alarmid}) ",
+            "</if>",
+            "<if test='components != null'>",
+            "and components in(${components}) ",
+            "</if>",
+            "<if test='deviceType != null'>",
+            "and deviceType = #{deviceType}",
+            "</if>",
+            "</where>",
+
+            " group by  components,lineid,alarmid,description ",
+            " order by lineid  ",
+            "</script>"})
+    List<ProBasicFeatureStat> findCtFeatureStatByLnId( @Param("begin")long begin, @Param("end") long end, @Param("stationid") String stationid, @Param("modelId")String modelId, @Param("components") String components, @Param("alarmid") String alarmid, @Param("deviceType")String deviceType);
+
     @Select("${sql}")
     List<AlarmSimpleVo> selectLastRowByTbname( @Param("sql") String sql);
 }

+ 58 - 0
alarm-web/src/main/java/com/gyee/alarm/mapper/auto/ProEconAlarmInfoMapper.java

@@ -1,7 +1,16 @@
 package com.gyee.alarm.mapper.auto;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gyee.alarm.model.auto.ProEconAlarmConfiguration;
 import com.gyee.alarm.model.auto.ProEconAlarmInfo;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.gyee.alarm.model.vo.AlarmVo;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.Date;
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +22,53 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface ProEconAlarmInfoMapper extends BaseMapper<ProEconAlarmInfo> {
 
+
+
+    @Select({"<script>",
+            "select * from pro_econ_alarm_info " ,
+            "<where>" ,
+
+
+            "<if test='begin != null'>",
+            " last_update_time &gt;= #{begin}",
+            "</if>",
+            "<if test='end != null'>",
+            "and last_update_time &lt;= #{end}",
+            "</if>",
+            "<if test='modelId != null'>",
+            "and model_id= #{modelId}",
+            "</if>",
+            "<if test='description != null'>",
+            "and description like #{description}",
+            "</if>",
+            "<if test='deviceid != null'>",
+            "and device_id = #{deviceid}",
+            "</if>",
+            "<if test='deviceType != null'>",
+            "and device_Type = #{deviceType}",
+            "</if>",
+            "<if test='alarmType != null'>",
+            "and alarm_type = #{alarmType}",
+            "</if>",
+            "<if test='components != null'>",
+            "and components = #{components}",
+            "</if>",
+            "<if test='stationid != null'>",
+            "and station_id = #{stationid}",
+            "</if>",
+            "<if test='alarmid != null'>",
+            "and alarm_id = #{alarmid}",
+            "</if>",
+            "<if test='isclose== true'>",
+            "and close_time is not null ",
+            "</if>",
+            "<if test='isclose== false'>",
+            "and close_time is null ",
+            "</if>",
+
+            "</where>",
+            " order by last_update_time desc,rank desc  ",
+            "</script>"})
+    IPage<ProEconAlarmInfo> selectByWtLimit(Page page, @Param("begin") Date begin, @Param("end")Date end, @Param("modelId")String modelId, @Param("superTableName") String superTableName, @Param("alarmType")String alarmType, @Param("stationid")String stationid, @Param("deviceid")String deviceid, @Param("description")String description, @Param("deviceType")String deviceType, @Param("components")String components, @Param("alarmid")String alarmid, @Param("isclose")Boolean isclose);
+
 }

+ 4 - 1
alarm-web/src/main/java/com/gyee/alarm/model/auto/ProEconAlarmInfo.java

@@ -176,5 +176,8 @@ public class ProEconAlarmInfo extends Model {
      * 关闭时间
      */
     private Date closeTime;
-
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
 }

+ 1 - 1
alarm-web/src/main/java/com/gyee/alarm/model/vo/AlarmStatVo.java

@@ -27,5 +27,5 @@ public class AlarmStatVo implements Serializable{
 
     private String windturbineCode;
 
-
+    private String lineId;
 }

+ 182 - 0
alarm-web/src/main/java/com/gyee/alarm/model/vo/ProEconAlarmInfoVo.java

@@ -0,0 +1,182 @@
+package com.gyee.alarm.model.vo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+
+/**
+ * <p>
+ * 报警缓存表
+ * </p>
+ *
+ * @author shilin
+ * @since 2023-06-19
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ProEconAlarmInfoVo extends Model {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 表名
+     */
+    @TableId(type = IdType.INPUT)
+    private String tbname;
+
+    /**
+     * 最近更新时间戳
+     */
+    private Long lastUpdateTime;
+
+    /**
+     * 值
+     */
+    private Integer val;
+
+    /**
+     * 测点
+     */
+    private String tagId;
+
+    /**
+     * 报警类别
+     */
+    private Integer triggerType;
+
+    /**
+     * 报警唯一id
+     */
+    private String alarmId;
+
+    /**
+     * 设备ID
+     */
+    private String deviceId;
+
+    /**
+     * 后缀
+     */
+    private String suffix;
+
+    /**
+     * 报警级别
+     */
+    private Integer rank;
+
+    /**
+     * 是否确认
+     */
+    private Boolean confirmed;
+
+    /**
+     * 统一识别码(如果通过uniformCode配置,则设备类型,场站,机型不能为空)
+     */
+    private String uniformCode;
+
+    /**
+     * 报警类型 /自定义报警 custom,风机 windturbine,场站 station,升压站 booststation
+     */
+    private String alarmType;
+
+    /**
+     * 设备类型,场站 station,风机 windturbine,升压站 booststation
+     */
+    private String deviceType;
+
+    /**
+     * 设备部件
+     */
+    private String components;
+
+    /**
+     * 设备子部件
+     */
+    private String subcomponents;
+
+    /**
+     * 报警描述
+     */
+    private String description;
+
+    /**
+     * 机型
+     */
+    private String modelId;
+
+    /**
+     * 是否可复位
+     */
+    private Boolean resetTable;
+
+    /**
+     * 是否启用
+     */
+    private Boolean enable;
+
+    /**
+     * 特性
+     */
+    private String characteristic;
+
+    /**
+     * 场站ID
+     */
+    private String stationId;
+
+    /**
+     * 项目ID
+     */
+    private String projectId;
+
+    /**
+     * 线路ID
+     */
+    private String lineId;
+
+    /**
+     * 场站名称
+     */
+    private String stationName;
+
+    /**
+     * 项目名称
+     */
+    private String projectiName;
+
+    /**
+     * 线路名称
+     */
+    private String lineidName;
+
+    /**
+     * 设备名称
+     */
+    private String deviceName;
+
+    /**
+     * 当前原始值
+     */
+    private Integer oval;
+    /**
+     * 报警是否结束
+     */
+    private Integer isOpen;
+
+    /**
+     * 确认时间
+     */
+    private Long confirmedTime;
+
+    /**
+     * 关闭时间
+     */
+    private Long closeTime;
+    /**
+     * 更新时间
+     */
+    private Long updateTime;
+}

+ 250 - 6
alarm-web/src/main/java/com/gyee/alarm/service/AlarmHistoryService.java

@@ -167,8 +167,8 @@ public class AlarmHistoryService   {
                     ProEconAlarmInfo po = new ProEconAlarmInfo();
                     po.setTbname(vo.getTbName());
                     po.setLastUpdateTime(new Date());
-                    po.setTagId(alarm.getTagId());
-                    po.setTriggerType(alarm.getTriggerType());
+                    po.setTagId(vo.getTagid());
+                    po.setTriggerType(vo.getTriggertype());
                     po.setAlarmId(vo.getAlarmId());
                     po.setDeviceId(vo.getDeviceId());
                     po.setSubcomponents(vo.getSuffix());
@@ -698,6 +698,7 @@ public class AlarmHistoryService   {
             d.setRelatePartsText(fs.getTypeName());
             d.setAlertText(fs.getDescription());
             d.setCount(fs.getTotal());
+            d.setAlarmid(fs.getAlarmid());
             if(StringUtils.notEmp(timeType))
             {
                 if(AlarmTime.H.getCode().equals(timeType))
@@ -745,24 +746,265 @@ public class AlarmHistoryService   {
 
         return resultList;
     }
+
+
+    public List<AlarmStatVo> findCtFeatureStatByWpId(String modelId, Date startTime, Date endTime,String components,String deviceType,String alarmIds,String timeType) {
+        List<AlarmStatVo> resultList = new ArrayList<>();
+
+
+        StringBuilder alarmIdList=new StringBuilder();
+        StringBuilder componentsList=new StringBuilder();
+
+        Map<String,String> alarmIdMap=new HashMap<>();
+        Map<String,String> componentsMap=new HashMap();
+
+        if(StringUtils.notEmp(components))
+        {
+            String [] componentsStr=components.split(",");
+            for(String c:componentsStr)
+            {
+                componentsList.append("'").append(c).append("',");
+                componentsMap.put(c,c);
+            }
+
+        }
+        if(StringUtils.notEmp(alarmIds))
+        {
+            String [] alarmIdStr=alarmIds.split(",");
+            for(String c:alarmIdStr)
+            {
+                alarmIdList.append("'").append(c).append("',");
+                alarmIdMap.put(c,c);
+            }
+
+        }
+        String alarmId=null;
+        String component=null;
+        if(alarmIdList.length()>0)
+        {
+            alarmId=String.valueOf(alarmIdList.substring(0,alarmIdList.length()-1));
+        }
+        if(componentsList.length()>0)
+        {
+            component=String.valueOf(componentsList.substring(0,componentsList.length()-1));
+        }
+        List<ProBasicFeatureStat> fsls = alarmTsMapper.findCtFeatureStatByWpId(startTime.getTime(), endTime.getTime(),null,modelId,component,alarmId,deviceType);
+
+
+        Map<String, ProBasicFeatureStat> map = new HashMap<>();
+        Date statDate=DateUtils.truncate(new Date());
+
+        if (!fsls.isEmpty()) {
+            for (ProBasicFeatureStat fs : fsls) {
+                if (StringUtils.notEmp(fs.getTypeCode()) && CacheContext.alarmTypeMap.containsKey(fs.getTypeCode())) {
+                    ProEconAlarmType at = CacheContext.alarmTypeMap.get(fs.getTypeCode());
+                    fs.setTypeName(at.getName());
+                }
+                fs.setStatDate(new Timestamp(statDate.getTime()));
+                fs.setId(String.valueOf(SnowflakeGenerator.generateId()));
+                StringBuilder sb = new StringBuilder();
+                sb.append(fs.getStationId()).append("_").append(fs.getAlarmid());
+                map.put(String.valueOf(sb), fs);
+            }
+        }
+
+
+
+        Map<String,List<AlarmStatVo>> vomap=new HashMap<>();
+        for(ProBasicFeatureStat fs:fsls)
+        {
+            AlarmStatVo d = new AlarmStatVo();
+            d.setRelateParts(fs.getTypeCode());
+            d.setRelatePartsText(fs.getTypeName());
+            d.setAlertText(fs.getDescription());
+            d.setCount(fs.getTotal());
+            d.setAlarmid(fs.getAlarmid());
+            if(StringUtils.notEmp(timeType))
+            {
+                if(AlarmTime.H.getCode().equals(timeType))
+                {
+                    double times= new BigDecimal(fs.getAvgSeconds()).divide(new BigDecimal(360), 2, RoundingMode.HALF_EVEN).doubleValue();
+                    d.setTime(times);
+                }else if(AlarmTime.M.getCode().equals(timeType))
+                {
+                    double times= new BigDecimal(fs.getAvgSeconds()).divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN).doubleValue();
+                    d.setTime(times);
+                }else
+                {
+                    d.setTime(fs.getAvgSeconds());
+                }
+            }else
+            {
+                double times= new BigDecimal(fs.getAvgSeconds()).divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN).doubleValue();
+                d.setTime(times);
+            }
+            d.setStationId(fs.getStationId());
+            d.setSnapId(SnowflakeGenerator.generateId());
+            d.setWindturbineId(fs.getWtId());
+            if(CacheContext.wpmap.containsKey(fs.getStationId()))
+            {
+                ProBasicPowerstation wt= CacheContext.wpmap.get(fs.getStationId());
+                d.setWindturbineCode(wt.getAname());
+            }
+
+            StringBuilder sb=new StringBuilder();
+            sb.append(fs.getStationId()).append("_").append(fs.getAlarmid());
+
+            if(vomap.containsKey(String.valueOf(sb)))
+            {
+                List<AlarmStatVo> ls=vomap.get(String.valueOf(sb));
+                ls.add(d);
+            }else
+            {
+                List<AlarmStatVo> ls=new ArrayList<>();
+                ls.add(d);
+                vomap.put(String.valueOf(sb),ls);
+            }
+            resultList.add(d);
+        }
+
+
+        return resultList;
+    }
+
+
+    public List<AlarmStatVo> findCtFeatureStatByLnId(String wpId,String modelId, Date startTime, Date endTime,String components,String deviceType,String alarmIds,String timeType) {
+        List<AlarmStatVo> resultList = new ArrayList<>();
+
+
+        StringBuilder alarmIdList=new StringBuilder();
+        StringBuilder componentsList=new StringBuilder();
+
+        Map<String,String> alarmIdMap=new HashMap<>();
+        Map<String,String> componentsMap=new HashMap();
+
+        if(StringUtils.notEmp(components))
+        {
+            String [] componentsStr=components.split(",");
+            for(String c:componentsStr)
+            {
+                componentsList.append("'").append(c).append("',");
+                componentsMap.put(c,c);
+            }
+
+        }
+        if(StringUtils.notEmp(alarmIds))
+        {
+            String [] alarmIdStr=alarmIds.split(",");
+            for(String c:alarmIdStr)
+            {
+                alarmIdList.append("'").append(c).append("',");
+                alarmIdMap.put(c,c);
+            }
+
+        }
+        String alarmId=null;
+        String component=null;
+        if(alarmIdList.length()>0)
+        {
+            alarmId=String.valueOf(alarmIdList.substring(0,alarmIdList.length()-1));
+        }
+        if(componentsList.length()>0)
+        {
+            component=String.valueOf(componentsList.substring(0,componentsList.length()-1));
+        }
+        List<ProBasicFeatureStat> fsls = alarmTsMapper.findCtFeatureStatByLnId(startTime.getTime(), endTime.getTime(),wpId,modelId,component,alarmId,deviceType);
+
+
+        Map<String, ProBasicFeatureStat> map = new HashMap<>();
+        Date statDate=DateUtils.truncate(new Date());
+
+        if (!fsls.isEmpty()) {
+            for (ProBasicFeatureStat fs : fsls) {
+                if (StringUtils.notEmp(fs.getTypeCode()) && CacheContext.alarmTypeMap.containsKey(fs.getTypeCode())) {
+                    ProEconAlarmType at = CacheContext.alarmTypeMap.get(fs.getTypeCode());
+                    fs.setTypeName(at.getName());
+                }
+                fs.setStatDate(new Timestamp(statDate.getTime()));
+                fs.setId(String.valueOf(SnowflakeGenerator.generateId()));
+                StringBuilder sb = new StringBuilder();
+                sb.append(fs.getStationId()).append("_").append(fs.getAlarmid());
+                map.put(String.valueOf(sb), fs);
+            }
+        }
+
+
+
+        Map<String,List<AlarmStatVo>> vomap=new HashMap<>();
+        for(ProBasicFeatureStat fs:fsls)
+        {
+            AlarmStatVo d = new AlarmStatVo();
+            d.setRelateParts(fs.getTypeCode());
+            d.setRelatePartsText(fs.getTypeName());
+            d.setAlertText(fs.getDescription());
+            d.setCount(fs.getTotal());
+            d.setAlarmid(fs.getAlarmid());
+            if(StringUtils.notEmp(timeType))
+            {
+                if(AlarmTime.H.getCode().equals(timeType))
+                {
+                    double times= new BigDecimal(fs.getAvgSeconds()).divide(new BigDecimal(360), 2, RoundingMode.HALF_EVEN).doubleValue();
+                    d.setTime(times);
+                }else if(AlarmTime.M.getCode().equals(timeType))
+                {
+                    double times= new BigDecimal(fs.getAvgSeconds()).divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN).doubleValue();
+                    d.setTime(times);
+                }else
+                {
+                    d.setTime(fs.getAvgSeconds());
+                }
+            }else
+            {
+                double times= new BigDecimal(fs.getAvgSeconds()).divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN).doubleValue();
+                d.setTime(times);
+            }
+            d.setStationId(fs.getStationId());
+            d.setSnapId(SnowflakeGenerator.generateId());
+            d.setWindturbineId(fs.getWtId());
+            if(CacheContext.lnmap.containsKey(fs.getStationId()))
+            {
+                ProBasicLine ln= CacheContext.lnmap.get(fs.getStationId());
+                d.setWindturbineCode(ln.getNemCode());
+            }
+
+            StringBuilder sb=new StringBuilder();
+            sb.append(fs.getStationId()).append("_").append(fs.getAlarmid());
+
+            if(map.containsKey(String.valueOf(sb)))
+            {
+                List<AlarmStatVo> ls=vomap.get(String.valueOf(sb));
+                ls.add(d);
+            }else
+            {
+                List<AlarmStatVo> ls=new ArrayList<>();
+                ls.add(d);
+                vomap.put(String.valueOf(sb),ls);
+            }
+            resultList.add(d);
+        }
+
+
+        return resultList;
+    }
     private  static void setCtValues(Date statDate,Map<String, ProBasicFeatureStat> map, List<ProBasicFeatureStat> vos, ProBasicEquipment wt, ProEconAlarmRule at) {
 
         ProBasicFeatureStat fs = new ProBasicFeatureStat();
 
         StringBuilder sb = new StringBuilder();
-        sb.append(fs.getWtId()).append("_").append(at.getId());
+        sb.append(wt.getId()).append("_").append(at.getId());
         if (map.containsKey(String.valueOf(sb))) {
             ProBasicFeatureStat old = map.get(String.valueOf(sb));
             BeanUtil.copyProperties(old, fs);
+            fs.setAlarmid(old.getAlarmid());
         } else {
             fs.setStatDate(new Timestamp(statDate.getTime()));
             fs.setId(String.valueOf(SnowflakeGenerator.generateId()));
             fs.setWtId(wt.getId());
             fs.setStationId(wt.getWindpowerstationId());
-            fs.setTypeCode(at.getCategory());
-            if(CacheContext.alarmTypeMap.containsKey(at.getCategory()))
+            fs.setTypeCode(at.getRelatedParts());
+            if(CacheContext.alarmTypeMap.containsKey(at.getRelatedParts()))
             {
-                fs.setTypeName(CacheContext.alarmTypeMap.get(at.getCategory()).getName());
+                fs.setTypeName(CacheContext.alarmTypeMap.get(at.getRelatedParts()).getName());
             }
             fs.setAlarmid(at.getId());
             fs.setDescription(at.getDescription());
@@ -775,4 +1017,6 @@ public class AlarmHistoryService   {
         }
         vos.add(fs);
     }
+
+
 }

+ 28 - 28
alarm-web/src/main/java/com/gyee/alarm/service/TokenService.java

@@ -40,7 +40,7 @@ public class TokenService {
         List<ProBasicEquipment> wtlist = new ArrayList<>();
         if (StringUtils.notEmp(token) && StringUtils.notEmp(userId))
         {
-            if (sessionMap.containsKey(token) && !sessionWtMap.containsKey(token)) {
+//            if (sessionMap.containsKey(token) && !sessionWtMap.containsKey(token)) {
 
                 List<String> depls = sysUserService.getUserByuserId(Long.valueOf(userId));
                 if (!depls.isEmpty()) {
@@ -87,11 +87,11 @@ public class TokenService {
 
                     }
                 }
-                sessionWtMap.put(token,wtlist);
-            } else if (sessionMap.containsKey(token) && sessionWtMap.containsKey(token))
-            {
-                wtlist =sessionWtMap.get(token);
-            }
+//                sessionWtMap.put(token,wtlist);
+//            } else if (sessionMap.containsKey(token) && sessionWtMap.containsKey(token))
+//            {
+//                wtlist =sessionWtMap.get(token);
+//            }
         }else
         {
             for(ProBasicEquipment wt:CacheContext.wtls)
@@ -113,8 +113,8 @@ public class TokenService {
         List<ProBasicPowerstation> wplist=new ArrayList<>();
         if(StringUtils.notEmp(token)  && StringUtils.notEmp(token))
         {
-            if(sessionMap.containsKey(token) && !sessionWpMap.containsKey(token))
-            {
+//            if(sessionMap.containsKey(token) && !sessionWpMap.containsKey(token))
+//            {
 
                 List<String> depls= sysUserService.getUserByuserId(Long.valueOf(userId));
                 if(!depls.isEmpty())
@@ -167,11 +167,11 @@ public class TokenService {
 
                     }
                 }
-                sessionWpMap.put(token,wplist);
-            }else if (sessionMap.containsKey(token) && sessionWpMap.containsKey(token))
-            {
-                wplist=sessionWpMap.get(token);
-            }
+//                sessionWpMap.put(token,wplist);
+//            }else if (sessionMap.containsKey(token) && sessionWpMap.containsKey(token))
+//            {
+//                wplist=sessionWpMap.get(token);
+//            }
 
         }else
         {
@@ -193,8 +193,8 @@ public class TokenService {
         List<ProBasicSubStation> wplist=new ArrayList<>();
         if(StringUtils.notEmp(token) && StringUtils.notEmp(userId))
         {
-            if(!sessionSubMap.containsKey(token))
-            {
+//            if(!sessionSubMap.containsKey(token))
+//            {
 
                 List<String> depls= sysUserService.getUserByuserId(Long.valueOf(userId));
                 if(!depls.isEmpty())
@@ -262,12 +262,12 @@ public class TokenService {
 
                     }
                 }
-                sessionSubMap.put(token,wplist);
-            }else  if (sessionMap.containsKey(token) && sessionSubMap.containsKey(token))
-            {
-                wplist=sessionSubMap.get(token);
-
-            }
+//                sessionSubMap.put(token,wplist);
+//            }else  if (sessionMap.containsKey(token) && sessionSubMap.containsKey(token))
+//            {
+//                wplist=sessionSubMap.get(token);
+//
+//            }
         }else
         {
             for(ProBasicSubStation subStation:CacheContext.subwpls)
@@ -289,8 +289,8 @@ public class TokenService {
         List<ProBasicWeatherStation> wplist=new ArrayList<>();
         if(StringUtils.notEmp(token) && StringUtils.notEmp(userId))
         {
-            if(!sessionWeMap.containsKey(token))
-            {
+//            if(!sessionWeMap.containsKey(token))
+//            {
 
                 List<String> depls= sysUserService.getUserByuserId(Long.valueOf(userId));
                 if(!depls.isEmpty())
@@ -361,11 +361,11 @@ public class TokenService {
                         }
                     }
                 }
-                sessionWeMap.put(token,wplist);
-            }else  if (sessionMap.containsKey(token) && sessionWeMap.containsKey(token))
-            {
-                wplist=sessionWeMap.get(token);
-            }
+//                sessionWeMap.put(token,wplist);
+//            }else  if (sessionMap.containsKey(token) && sessionWeMap.containsKey(token))
+//            {
+//                wplist=sessionWeMap.get(token);
+//            }
 
         }else
         {

+ 23 - 0
alarm-web/src/main/java/com/gyee/alarm/service/auto/IProEconAlarmInfoService.java

@@ -1,7 +1,18 @@
 package com.gyee.alarm.service.auto;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gyee.alarm.init.CacheContext;
+import com.gyee.alarm.model.auto.ProEconAlarmConfiguration;
 import com.gyee.alarm.model.auto.ProEconAlarmInfo;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.gyee.alarm.model.vo.AlarmSuperTalbeType;
+import com.gyee.alarm.model.vo.AlarmTypeValue;
+import com.gyee.alarm.model.vo.AlarmVo;
+import com.gyee.common.model.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
+
+import java.util.*;
 
 /**
  * <p>
@@ -13,4 +24,16 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IProEconAlarmInfoService extends IService<ProEconAlarmInfo> {
 
+    /**
+     * 查询报警信息接口
+     * @param begin 开始时间
+     * @param end 结束时间
+     * @param alarmType 报警类型
+     * @param stationid 场站
+     * @param description 描述
+     * @param pageNum 页数
+     * @param pageSize 每页多少条
+     * @return
+     */
+    public IPage<ProEconAlarmInfo> findAlarmlist(Page page, String modelId, Date begin, Date end , String alarmType, String stationid, String deviceid, String description, String deviceType, String components, String alarmId, Boolean isclose, int pageNum, int pageSize);
 }

+ 105 - 0
alarm-web/src/main/java/com/gyee/alarm/service/auto/impl/ProEconAlarmInfoServiceImpl.java

@@ -1,11 +1,24 @@
 package com.gyee.alarm.service.auto.impl;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gyee.alarm.init.CacheContext;
+import com.gyee.alarm.mapper.auto.ProEconAlarmConfigurationMapper;
+import com.gyee.alarm.model.auto.ProEconAlarmConfiguration;
 import com.gyee.alarm.model.auto.ProEconAlarmInfo;
 import com.gyee.alarm.mapper.auto.ProEconAlarmInfoMapper;
+import com.gyee.alarm.model.vo.AlarmSuperTalbeType;
+import com.gyee.alarm.model.vo.AlarmTypeValue;
+import com.gyee.alarm.model.vo.AlarmVo;
 import com.gyee.alarm.service.auto.IProEconAlarmInfoService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.common.model.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.util.*;
+
 /**
  * <p>
  * 报警缓存表 服务实现类
@@ -17,4 +30,96 @@ import org.springframework.stereotype.Service;
 @Service
 public class ProEconAlarmInfoServiceImpl extends ServiceImpl<ProEconAlarmInfoMapper, ProEconAlarmInfo> implements IProEconAlarmInfoService {
 
+
+    @Resource
+    private ProEconAlarmInfoMapper proEconAlarmInfoMapper;
+
+
+    /**
+     * 查询报警信息接口
+     * @param begin 开始时间
+     * @param end 结束时间
+     * @param alarmType 报警类型
+     * @param stationid 场站
+     * @param description 描述
+     * @param pageNum 页数
+     * @param pageSize 每页多少条
+     * @return
+     */
+    public IPage<ProEconAlarmInfo> findAlarmlist(Page page, String modelId, Date begin, Date end , String alarmType, String stationid, String deviceid, String description, String deviceType, String components, String alarmId, Boolean isclose, int pageNum, int pageSize) {
+
+        Map<String,Object> map=new HashMap<>();
+
+
+        String superTableName= null;
+        StringBuilder descriptionSql=new StringBuilder();
+
+
+//
+        if(StringUtils.notEmp(description)  )
+        {
+            descriptionSql.append("%").append(description).append("%");
+            description=String.valueOf(descriptionSql);
+        }
+        if(StringUtils.empty(deviceid)  )
+        {
+            deviceid=null;
+        }
+
+        if(StringUtils.empty(stationid)  )
+        {
+            stationid=null;
+        }
+        if(StringUtils.empty(modelId)  )
+        {
+            modelId=null;
+        }
+        if(StringUtils.empty(description)  )
+        {
+            description=null;
+        }
+        if(StringUtils.empty(deviceType)  )
+        {
+            deviceType=null;
+        }
+
+        if(StringUtils.empty(components)  )
+        {
+            components=null;
+        }
+        if(StringUtils.empty(alarmId)  )
+        {
+            alarmId=null;
+        }
+
+        if(StringUtils.empty(isclose)  )
+        {
+            isclose=null;
+        }
+       IPage<ProEconAlarmInfo> vos =proEconAlarmInfoMapper.selectByWtLimit(page,begin,end,modelId,superTableName, alarmType, stationid, deviceid, description,deviceType,components, alarmId,isclose);
+
+        for(ProEconAlarmInfo vo:vos.getRecords())
+        {
+
+            if(com.gyee.alarm.util.StringUtils.notEmp(vo.getDeviceId()) && CacheContext.wtmap.containsKey(vo.getDeviceId()))
+            {
+                vo.setDeviceName(CacheContext.wtmap.get(vo.getDeviceId()).getNemCode());
+            }
+
+            if(CacheContext.wpmap.containsKey(vo.getStationId()))
+            {
+                vo.setStationName(CacheContext.wpmap.get(vo.getStationId()).getName());
+            }
+
+            if(CacheContext.subwpmap.containsKey(vo.getStationId()))
+            {
+                vo.setStationName(CacheContext.subwpmap.get(vo.getStationId()).getName());
+            }
+        }
+
+
+
+
+        return vos;
+    }
 }

File diff suppressed because it is too large
+ 1351 - 27759
log/ota.log


BIN
log/ota.log.2023-10-02.0.gz


BIN
log/ota.log.2023-10-03.0.gz


BIN
log/ota.log.2023-10-05.0.gz