Browse Source

定边报警系统修改

shilin 4 months ago
parent
commit
e401c9e092
25 changed files with 1239 additions and 36 deletions
  1. 2 0
      alarm-custom/src/main/java/com/gyee/alarm/AlarmCustom.java
  2. 2 0
      alarm-custom/src/main/java/com/gyee/alarm/config/ThreadPoolTaskConfig.java
  3. 15 0
      alarm-custom/src/main/java/com/gyee/alarm/init/CacheContext.java
  4. 33 0
      alarm-custom/src/main/java/com/gyee/alarm/model/vo/AlarmVo.java
  5. 360 0
      alarm-custom/src/main/java/com/gyee/alarm/service/AlarmCtService.java
  6. 7 7
      alarm-custom/src/main/java/com/gyee/alarm/service/AlarmCustomService.java
  7. 3 2
      alarm-custom/src/main/java/com/gyee/alarm/service/auto/IProEconAlarmRuleService.java
  8. 64 3
      alarm-custom/src/main/java/com/gyee/alarm/service/auto/impl/ProEconAlarmRuleServiceImpl.java
  9. 63 0
      alarm-custom/src/main/java/com/gyee/alarm/task/thread/ScheduledTasks.java
  10. 3 3
      alarm-service/src/main/java/com/gyee/alarm/AlarmMain.java
  11. 1 1
      alarm-web/src/main/java/com/gyee/alarm/controller/AlarmConfigurationController.java
  12. 7 0
      alarm-web/src/main/java/com/gyee/alarm/init/CacheContext.java
  13. 7 5
      alarm-web/src/main/java/com/gyee/alarm/mapper/auto/AlarmTsMapper.java
  14. 2 0
      alarm-web/src/main/java/com/gyee/alarm/model/vo/AlarmVo.java
  15. 3 0
      alarm-web/src/main/java/com/gyee/alarm/service/AlarmConfigurationService.java
  16. 81 3
      alarm-web/src/main/java/com/gyee/alarm/service/AlarmCtService.java
  17. 1 1
      alarm-web/src/main/java/com/gyee/alarm/service/AlarmHistoryService.java
  18. 11 0
      alarm-web/src/main/java/com/gyee/alarm/service/AlarmRuleService.java
  19. 2 1
      alarm-web/src/main/java/com/gyee/alarm/service/auto/IAlarmTsService.java
  20. 2 0
      alarm-web/src/main/java/com/gyee/alarm/service/auto/IProEconAlarmConfigurationService.java
  21. 1 0
      alarm-web/src/main/java/com/gyee/alarm/service/auto/IProEconAlarmRuleService.java
  22. 4 2
      alarm-web/src/main/java/com/gyee/alarm/service/auto/impl/AlarmTsServiceImpl.java
  23. 128 6
      alarm-web/src/main/java/com/gyee/alarm/service/auto/impl/ProEconAlarmConfigurationServiceImpl.java
  24. 198 0
      alarm-web/src/main/java/com/gyee/alarm/service/auto/impl/ProEconAlarmRuleServiceImpl.java
  25. 239 2
      log/ota.log

+ 2 - 0
alarm-custom/src/main/java/com/gyee/alarm/AlarmCustom.java

@@ -4,9 +4,11 @@ import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 
 @SpringBootApplication
+@EnableScheduling
 @EnableAsync
 @MapperScan("com.gyee.alarm.mapper")
 public class AlarmCustom {

+ 2 - 0
alarm-custom/src/main/java/com/gyee/alarm/config/ThreadPoolTaskConfig.java

@@ -2,6 +2,7 @@ package com.gyee.alarm.config;
 
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 
 import java.util.concurrent.ThreadPoolExecutor;
@@ -51,6 +52,7 @@ public class ThreadPoolTaskConfig {
 
 
     @Bean
+    @Primary
     public ThreadPoolTaskExecutor taskExecutor() {
         ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
         executor.setCorePoolSize(corePoolSize);

+ 15 - 0
alarm-custom/src/main/java/com/gyee/alarm/init/CacheContext.java

@@ -4,6 +4,7 @@ package com.gyee.alarm.init;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
 import com.gyee.alarm.init.redis.RedisService;
+import com.gyee.alarm.model.vo.AlarmCustomTag;
 import com.gyee.alarm.model.vo.AlarmTypeValue;
 import com.gyee.alarm.model.vo.AlarmVo;
 import com.gyee.common.model.PointData;
@@ -21,6 +22,7 @@ import org.springframework.stereotype.Component;
 import javax.annotation.Resource;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.stream.Collectors;
 
 /**
@@ -168,6 +170,19 @@ public class CacheContext implements CommandLineRunner {
 
     public static List<ProBasicPowerstationPoint> wpPointList =new ArrayList<>(); //场站测点集合
     public static List<ProBasicPowerstationPoint> wsPointList =new ArrayList<>(); //升压站测点集合
+
+
+
+    public static Map<String, List<ProEconAlarmRule>> alarmRulesMap = new HashMap<>();
+
+    public static List<AlarmVo> alarmCtList=new ArrayList<>();
+
+    public static Map<String,AlarmVo> alarmCtMap=new HashMap<>();
+
+    public static Map<String, List<AlarmVo>> alarmCtLsMap = new HashMap<>();
+
+
+    public static List<AlarmCustomTag> alarmTags = new CopyOnWriteArrayList<>();
     @Override
     public void run(String... args) throws Exception {
         logger.info("缓存开始------------------------------------------------------------");

+ 33 - 0
alarm-custom/src/main/java/com/gyee/alarm/model/vo/AlarmVo.java

@@ -3,6 +3,8 @@ package com.gyee.alarm.model.vo;
 
 import lombok.Data;
 
+import java.sql.Timestamp;
+
 @Data
 public class AlarmVo {
 
@@ -32,4 +34,35 @@ public class AlarmVo {
     private Integer triggertype;
     private String uniformcode;
     private String superTableName;
+
+    private Timestamp ts;
+    private Integer val;
+    private Integer oval;
+
+    private Timestamp endts;
+
+    private Double timelong;
+
+    /**
+     * 故障名称
+     */
+    private String name;
+
+    /**
+     *故障码
+     */
+    private String nemCode;
+
+    /**
+     * 故障原因
+     */
+    private String faultCause;
+
+    /**
+     * 排查方法
+     */
+    private String resolvent;
+
+    private String faultType;
+    private String aname;
 }

+ 360 - 0
alarm-custom/src/main/java/com/gyee/alarm/service/AlarmCtService.java

@@ -0,0 +1,360 @@
+package com.gyee.alarm.service;
+
+import com.gyee.alarm.init.CacheContext;
+import com.gyee.alarm.model.auto.*;
+import com.gyee.alarm.model.vo.*;
+
+import com.gyee.alarm.util.StringUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.stereotype.Service;
+
+
+import java.util.*;
+
+@Service
+
+public class AlarmCtService {
+
+    private static Logger logger = LoggerFactory.getLogger(AlarmCtService.class);
+
+
+
+    public List<AlarmVo> initalAlarmVo() {
+
+        List<AlarmVo> alarmVoList = new ArrayList<>();
+        Map<String, List<ProEconAlarmRule>> alarmRulesMap = CacheContext.alarmRulesMap;
+
+        //风机自定义报警
+        wtCustomAlarm(alarmVoList, alarmRulesMap);
+        //逆变器自定义报警
+        lnCustomAlarm(alarmVoList, alarmRulesMap);
+//        //场站自定义报警
+//        wpCustomAlarm(alarmVoList, alarmRulesMap);
+        //升压站自定义报警
+        btCustomAlarm(alarmVoList, alarmRulesMap);
+        return alarmVoList;
+    }
+
+    private void wtCustomAlarm(List<AlarmVo> alarmVoList, Map<String, List<ProEconAlarmRule>> alarmRulesMap) {
+
+        Map<String, List<ProEconAlarmRule>> armap = new HashMap<>();
+        //将多有的自定义报警通过场站编号和型号进行分类
+        if (alarmRulesMap.containsKey(DeviceTypeValue.WT.getCode())) {
+            List<ProEconAlarmRule> arls = alarmRulesMap.get(DeviceTypeValue.WT.getCode());
+            if (!arls.isEmpty()) {
+                for (ProEconAlarmRule ar : arls) {
+                    StringBuilder sb = new StringBuilder();
+                    sb.append(ar.getStationId() + ar.getModelId());
+                    if (armap.containsKey(String.valueOf(sb))) {
+                        List<ProEconAlarmRule> ls = armap.get(String.valueOf(sb));
+                        ls.add(ar);
+                    } else {
+                        List<ProEconAlarmRule> ls = new ArrayList<>();
+                        ls.add(ar);
+                        armap.put(String.valueOf(sb), ls);
+                    }
+                }
+            }
+        }
+        //将pg数据库中配置的自定义报警信息转化为报警对象,方便进行自定义报警的判定功能
+        for (ProBasicEquipment wt : CacheContext.wtls) {
+            StringBuilder sb = new StringBuilder();
+            sb.append(wt.getWindpowerstationId() + wt.getModelId());
+
+            if (armap.containsKey(String.valueOf(sb))) {
+                List<ProEconAlarmRule> alarmls = armap.get(String.valueOf(sb));
+
+                if (!alarmls.isEmpty()) {
+                    for (ProEconAlarmRule alarm : alarmls) {
+                        AlarmVo vo = new AlarmVo();
+                        StringBuilder tbName = new StringBuilder();
+                        tbName.append(wt.getId()).append("_").append(alarm.getId());
+                        vo.setTbName(String.valueOf(tbName));
+                        vo.setAlarmid(alarm.getId());
+                        vo.setTagid(alarm.getExpression());
+                        vo.setAlarmtype(AlarmTypeValue.CT.getCode());
+                        vo.setCharacteristic(alarm.getName());
+                        vo.setComponents(alarm.getRelatedParts());
+                        vo.setDescription(alarm.getDescription());
+                        vo.setDeviceid(wt.getId());
+                        vo.setDevicename(wt.getName());
+                        vo.setDevicetype(DeviceTypeValue.WT.getCode());
+                        vo.setEnabled(alarm.getEnable());
+                        vo.setLineid(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());
+                            vo.setProjectname(pj.getName());
+                        }
+                        vo.setRank(alarm.getRank());
+                        vo.setResettable(false);
+                        vo.setStationid(wt.getWindpowerstationId());
+                        if (CacheContext.wpmap.containsKey(wt.getWindpowerstationId())) {
+                            ProBasicPowerstation wp = CacheContext.wpmap.get(wt.getWindpowerstationId());
+                            vo.setStationname(wp.getName());
+                        }
+                        vo.setSubcomponents("");
+                        vo.setSuffix("");
+                        vo.setTriggertype(1);
+                        vo.setUniformcode("");
+                        vo.setSuperTableName(AlarmSuperTalbeType.CT.getCode());
+                        vo.setVal(0);
+
+                        vo.setCharacteristic(alarm.getName());
+                        vo.setFaultCause(alarm.getDescription());
+                        vo.setResolvent(alarm.getExpression());
+                        alarmVoList.add(vo);
+                    }
+                }
+            }
+        }
+    }
+
+    private void lnCustomAlarm(List<AlarmVo> alarmVoList, Map<String, List<ProEconAlarmRule>> alarmRulesMap) {
+
+        Map<String, List<ProEconAlarmRule>> armap = new HashMap<>();
+
+        if (alarmRulesMap.containsKey(DeviceTypeValue.IN.getCode())) {
+            List<ProEconAlarmRule> arls = alarmRulesMap.get(DeviceTypeValue.IN.getCode());
+            if (!arls.isEmpty()) {
+                for (ProEconAlarmRule ar : arls) {
+                    StringBuilder sb = new StringBuilder();
+                    sb.append(ar.getStationId() + ar.getModelId());
+                    if (armap.containsKey(String.valueOf(sb))) {
+                        List<ProEconAlarmRule> ls = armap.get(String.valueOf(sb));
+                        ls.add(ar);
+                    } else {
+                        List<ProEconAlarmRule> ls = new ArrayList<>();
+                        ls.add(ar);
+                        armap.put(String.valueOf(sb), ls);
+                    }
+                }
+            }
+        }
+        for (ProBasicEquipment wt : CacheContext.wtls) {
+            StringBuilder sb = new StringBuilder();
+            sb.append(wt.getWindpowerstationId() + wt.getModelId());
+
+            if (armap.containsKey(String.valueOf(sb))) {
+                List<ProEconAlarmRule> alarmls = armap.get(String.valueOf(sb));
+
+                if (!alarmls.isEmpty()) {
+                    for (ProEconAlarmRule alarm : alarmls) {
+                        AlarmVo vo = new AlarmVo();
+                        StringBuilder tbName = new StringBuilder();
+                        tbName.append(wt.getId()).append("_").append(alarm.getId());
+                        vo.setTbName(String.valueOf(tbName));
+                        vo.setAlarmid(alarm.getId());
+                        vo.setTagid(alarm.getExpression());
+                        vo.setAlarmtype(AlarmTypeValue.CT.getCode());
+                        vo.setCharacteristic(alarm.getName());
+                        vo.setComponents(alarm.getRelatedParts());
+                        vo.setDescription(alarm.getDescription());
+                        vo.setDeviceid(wt.getId());
+                        vo.setDevicename(wt.getName());
+                        vo.setDevicetype(DeviceTypeValue.IN.getCode());
+                        vo.setEnabled(alarm.getEnable());
+                        vo.setLineid(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());
+                            vo.setProjectname(pj.getName());
+                        }
+                        vo.setRank(alarm.getRank());
+                        vo.setResettable(false);
+                        vo.setStationid(wt.getWindpowerstationId());
+                        if (CacheContext.wpmap.containsKey(wt.getWindpowerstationId())) {
+                            ProBasicPowerstation wp = CacheContext.wpmap.get(wt.getWindpowerstationId());
+                            vo.setStationname(wp.getName());
+                        }
+                        vo.setSubcomponents("");
+                        vo.setSuffix("");
+                        vo.setTriggertype(1);
+                        vo.setUniformcode("");
+                        vo.setSuperTableName(AlarmSuperTalbeType.CT.getCode());
+                        vo.setVal(0);
+
+                        vo.setCharacteristic(alarm.getName());
+                        vo.setFaultCause(alarm.getDescription());
+                        vo.setResolvent(alarm.getExpression());
+                        alarmVoList.add(vo);
+                    }
+                }
+            }
+        }
+    }
+
+    private void wpCustomAlarm(List<AlarmVo> alarmVoList, Map<String, List<ProEconAlarmRule>> alarmRulesMap) {
+        List<ProEconAlarmRule> alarmls = new ArrayList<>();
+        if (alarmRulesMap.containsKey(DeviceTypeValue.WP.getCode())) {
+            alarmls = alarmRulesMap.get(DeviceTypeValue.WP.getCode());
+
+        }
+
+        for (ProBasicPowerstation wp : CacheContext.wpls) {
+            if (!alarmls.isEmpty()) {
+                for (ProEconAlarmRule alarm : alarmls) {
+                    AlarmVo vo = new AlarmVo();
+                    StringBuilder tbName = new StringBuilder();
+                    tbName.append(wp.getId()).append("_").append(alarm.getId());
+                    vo.setTbName(String.valueOf(tbName));
+                    vo.setAlarmid(alarm.getId());
+                    vo.setTagid(alarm.getExpression());
+                    vo.setAlarmtype(AlarmTypeValue.CT.getCode());
+                    vo.setCharacteristic(alarm.getName());
+                    vo.setComponents(alarm.getRelatedParts());
+                    vo.setDescription(alarm.getDescription());
+                    vo.setDeviceid("");
+                    vo.setDevicename("");
+                    vo.setDevicetype(DeviceTypeValue.WP.getCode());
+                    vo.setEnabled(alarm.getEnable());
+                    vo.setLineid("");
+                    vo.setLinename("");
+                    vo.setModelId("");
+                    vo.setProjectid("");
+                    vo.setProjectname("");
+                    vo.setRank(alarm.getRank());
+                    vo.setResettable(false);
+                    vo.setStationid(wp.getId());
+                    vo.setStationname(wp.getName());
+                    vo.setSubcomponents("");
+                    vo.setSuffix("");
+                    vo.setTriggertype(1);
+                    vo.setUniformcode("");
+                    vo.setSuperTableName(AlarmSuperTalbeType.CT.getCode());
+                    vo.setVal(0);
+                    alarmVoList.add(vo);
+                }
+            }
+        }
+    }
+
+    private void btCustomAlarm(List<AlarmVo> alarmVoList, Map<String, List<ProEconAlarmRule>> alarmRulesMap) {
+
+
+        Map<String,List<ProEconAlarmRule>> alarmMap=new HashMap<>();
+
+        if (alarmRulesMap.containsKey(DeviceTypeValue.BT.getCode())) {
+
+            List<ProEconAlarmRule>  alarmls = alarmRulesMap.get(DeviceTypeValue.BT.getCode());
+
+            if(!alarmls.isEmpty())
+            {
+                for(ProEconAlarmRule alarm:alarmls)
+                {
+                    if (StringUtils.notEmp(alarm) && StringUtils.notEmp(alarm.getElectricalId()))
+                    {
+                        String [] ids=alarm.getElectricalId().split(",");
+                        if(ids.length>0)
+                        {
+                            for(int i=0;i<ids.length;i++)
+                            {
+                                if(alarmMap.containsKey(ids[i]))
+                                {
+                                    List<ProEconAlarmRule> arls=alarmMap.get(ids[i]);
+                                    arls.add(alarm);
+
+                                }else
+                                {
+                                    List<ProEconAlarmRule> arls=new ArrayList<>();
+                                    arls.add(alarm);
+                                    alarmMap.put(ids[i],arls);
+                                }
+
+                            }
+                        }
+                    }
+
+                }
+            }
+        }
+
+        for (ProBasicSubStation wp : CacheContext.subwpls) {
+
+            if (!alarmMap.isEmpty() && alarmMap.containsKey(wp.getId())) {
+
+                List<ProEconAlarmRule> alarmls = alarmMap.get(wp.getId());
+                for (ProEconAlarmRule alarm : alarmls) {
+                    AlarmVo vo = new AlarmVo();
+                    StringBuilder tbName = new StringBuilder();
+
+                    tbName.append(wp.getId()).append("_").append(alarm.getId());
+                    vo.setTbName(String.valueOf(tbName));
+                    vo.setAlarmid(alarm.getId());
+                    vo.setTagid(alarm.getExpression());
+                    vo.setAlarmtype(AlarmTypeValue.CT.getCode());
+                    vo.setCharacteristic(alarm.getName());
+                    vo.setComponents(alarm.getRelatedParts());
+                    vo.setDescription(alarm.getDescription());
+                    vo.setDeviceid("");
+                    vo.setDevicename("");
+                    vo.setDevicetype(DeviceTypeValue.BT.getCode());
+                    vo.setEnabled(alarm.getEnable());
+                    vo.setLineid("");
+                    vo.setLinename("");
+                    vo.setModelId("");
+                    vo.setProjectid("");
+                    vo.setProjectname("");
+                    vo.setRank(alarm.getRank());
+                    vo.setResettable(false);
+                    vo.setStationid(wp.getId());
+                    vo.setStationname(wp.getName());
+                    vo.setSubcomponents("");
+                    vo.setSuffix("");
+                    vo.setTriggertype(1);
+                    vo.setUniformcode("");
+                    vo.setSuperTableName(AlarmSuperTalbeType.CT.getCode());
+                    vo.setVal(0);
+                    vo.setOval(0);
+
+                    vo.setCharacteristic(alarm.getName());
+                    vo.setFaultCause(alarm.getDescription());
+                    vo.setResolvent(alarm.getExpression());
+                    alarmVoList.add(vo);
+                }
+            }
+        }
+    }
+
+    public List<AlarmCustomTag> findTags(String stbaleName) {
+        List<AlarmCustomTag> ls = new ArrayList<>();
+        if (StringUtils.notEmp(stbaleName)) {
+            // List<AlarmVo> vos= alarmTsService.findTags(stbaleName);
+            List<AlarmVo> vos = CacheContext.alarmCtList;
+            if (!vos.isEmpty()) {
+                for (AlarmVo vo : vos) {
+                    AlarmCustomTag po = new AlarmCustomTag();
+                    po.setId(vo.getTbName());
+                    po.setDescription(vo.getDescription());
+                    po.setTagId(vo.getTagid());
+                    po.setDeviceid(vo.getDeviceid());
+                    po.setDevicetype(vo.getDevicetype());
+                    po.setModelId(vo.getModelId());
+                    po.setAlarmtype(vo.getAlarmtype());
+                    po.setStationid(vo.getStationid());
+
+                    po.setVal(null);
+
+                    ls.add(po);
+                }
+            }
+        }
+        return ls;
+    }
+
+
+
+}

+ 7 - 7
alarm-custom/src/main/java/com/gyee/alarm/service/AlarmCustomService.java

@@ -50,7 +50,7 @@ public class AlarmCustomService {
     @Resource
     private IAlarmService alarmService;
 
-    private List<AlarmCustomTag> alarmTags = new CopyOnWriteArrayList<>();
+
     @Resource
     private Executor executor;
 
@@ -63,7 +63,7 @@ public class AlarmCustomService {
      */
     public void init() {
 
-        alarmTags = alarmService.findTagsByCt();
+        CacheContext.alarmTags = alarmService.findTagsByCt();
     }
 
     public void taskJobs(boolean runStarted) throws InterruptedException {
@@ -233,19 +233,19 @@ public class AlarmCustomService {
 
         List<AlarmCustomTag> alarmls = new ArrayList<>();
 //            int number = 0;
-        int listNumber = alarmTags.size() / taskCount;
+        int listNumber = CacheContext.alarmTags.size() / taskCount;
 
-            if (alarmTags.size() % taskCount == 0) {
+            if (CacheContext.alarmTags.size() % taskCount == 0) {
                 listNumber = listNumber+1;
             }
         StringBuilder str = new StringBuilder();
-        str.append("自定义分析总数:").append(alarmTags.size()).append(",线程数:").append(listNumber).append(",分块大小:").append(taskCount);
+        str.append("自定义分析总数:").append(CacheContext.alarmTags.size()).append(",线程数:").append(listNumber).append(",分块大小:").append(taskCount);
         log.info(String.valueOf(str));
         CountDownLatch countDownLatch = new CountDownLatch(listNumber);
 
         int time = 0;
-        for (int i = 0; i < alarmTags.size(); i++) {
-            alarmls.add(alarmTags.get(i));
+        for (int i = 0; i < CacheContext.alarmTags.size(); i++) {
+            alarmls.add(CacheContext.alarmTags.get(i));
             if (i != 0 && (i) % taskCount == 0) {
 
                 time++;

+ 3 - 2
alarm-custom/src/main/java/com/gyee/alarm/service/auto/IProEconAlarmRuleService.java

@@ -1,7 +1,7 @@
 package com.gyee.alarm.service.auto;
 
-import com.gyee.alarm.model.auto.ProEconAlarmRule;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.gyee.alarm.model.auto.ProEconAlarmRule;
 
 /**
  * <p>
@@ -9,8 +9,9 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * </p>
  *
  * @author shilin
- * @since 2023-06-27
+ * @since 2023-08-09
  */
 public interface IProEconAlarmRuleService extends IService<ProEconAlarmRule> {
 
+    public void inital() throws Exception;
 }

+ 64 - 3
alarm-custom/src/main/java/com/gyee/alarm/service/auto/impl/ProEconAlarmRuleServiceImpl.java

@@ -1,20 +1,81 @@
 package com.gyee.alarm.service.auto.impl;
 
-import com.gyee.alarm.model.auto.ProEconAlarmRule;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.alarm.init.CacheContext;
 import com.gyee.alarm.mapper.auto.ProEconAlarmRuleMapper;
+import com.gyee.alarm.model.auto.ProEconAlarmRule;
+import com.gyee.alarm.model.vo.AlarmCustomType;
+import com.gyee.alarm.model.vo.AlarmVo;
+import com.gyee.alarm.service.AlarmCtService;
 import com.gyee.alarm.service.auto.IProEconAlarmRuleService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * <p>
  * 自定义报警配置 服务实现类
  * </p>
  *
  * @author shilin
- * @since 2023-06-27
+ * @since 2023-08-09
  */
 @Service
 public class ProEconAlarmRuleServiceImpl extends ServiceImpl<ProEconAlarmRuleMapper, ProEconAlarmRule> implements IProEconAlarmRuleService {
 
+
+    @Resource
+    private AlarmCtService alarmCtService;
+    public void inital() throws Exception {
+
+
+        List<ProEconAlarmRule> customls =list().stream().filter(i -> i.getEnable()).collect(Collectors.toList());
+
+        List<ProEconAlarmRule> wtCustomls=new ArrayList<>();
+        List<ProEconAlarmRule> inCustomls=new ArrayList<>();
+
+
+        //对自定义报警进行分类
+        if(!customls.isEmpty())
+        {
+            for(ProEconAlarmRule vo: customls)
+            {
+                if(vo.getCategory().equals(AlarmCustomType.WT.getCode()))
+                {
+                    wtCustomls.add(vo);
+                }else  if(vo.getCategory().equals(AlarmCustomType.IN.getCode()))
+                {
+                    inCustomls.add(vo);
+                }
+
+            }
+        }
+
+
+        CacheContext.alarmRulesMap.put(AlarmCustomType.WT.getCode(),wtCustomls);
+        CacheContext.alarmRulesMap.put(AlarmCustomType.IN.getCode(),inCustomls);
+        //自定义报警初始化标签
+        CacheContext.alarmCtList=alarmCtService.initalAlarmVo();
+        if(!CacheContext.alarmCtList.isEmpty())
+        {
+            for(AlarmVo vo: CacheContext.alarmCtList)
+            {
+                CacheContext.alarmCtMap.put(vo.getTbName().toUpperCase(),vo);
+
+
+                if(CacheContext.alarmCtLsMap.containsKey(vo.getStationid()))
+                {
+                    List<AlarmVo> ls=CacheContext.alarmCtLsMap.get(vo.getStationid());
+                    ls.add(vo);
+                }else {
+                    List<AlarmVo> ls=new ArrayList<>();
+                    ls.add(vo);
+                    CacheContext.alarmCtLsMap.put(vo.getStationid(),ls);
+                }
+            }
+        }
+    }
 }

+ 63 - 0
alarm-custom/src/main/java/com/gyee/alarm/task/thread/ScheduledTasks.java

@@ -0,0 +1,63 @@
+package com.gyee.alarm.task.thread;
+
+import com.gyee.alarm.feigns.IAlarmService;
+import com.gyee.alarm.init.CacheContext;
+import com.gyee.alarm.model.vo.*;
+import com.gyee.alarm.rule.AlarmFunction;
+import com.gyee.alarm.rule.expression.AlarmExpression;
+import com.gyee.alarm.rule.expression.Analyzer;
+import com.gyee.alarm.service.AlarmCtService;
+import com.gyee.alarm.service.auto.IAlarmTsService;
+import com.gyee.alarm.service.auto.IProEconAlarmRuleService;
+import com.gyee.common.model.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executor;
+
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+@Component
+public class ScheduledTasks {
+
+    @Resource
+    private AlarmCtService alarmCtService;
+    @Resource
+    private IProEconAlarmRuleService proEconAlarmRuleService;
+    // 每15分钟执行一次
+    @Scheduled(fixedRate = 1000*60*15)
+    public void reportCurrentTime() throws Exception {
+
+        proEconAlarmRuleService.inital();
+        CacheContext.alarmTags = alarmCtService.findTags(AlarmSuperTalbeType.CT.getCode());
+        System.out.println("当前时间: " + System.currentTimeMillis() / 1000);
+    }
+
+//    // 初始延迟1秒,之后每10秒执行一次
+//    @Scheduled(fixedDelay = 10000, initialDelay = 1000)
+//    public void fixedDelayTask() {
+//        System.out.println("固定延迟任务执行: " + System.currentTimeMillis() / 1000);
+//    }
+//
+//    // 初始延迟1秒,之后在上一次执行结束后再等待10秒执行
+//    @Scheduled(fixedDelayString = "10000", initialDelay = 1000)
+//    public void fixedDelayStringTask() {
+//        System.out.println("固定延迟字符串任务执行: " + System.currentTimeMillis() / 1000);
+//    }
+//
+//    // 初始延迟1秒,之后在上一次执行结束后再等待10秒执行,使用cron表达式
+//    @Scheduled(cron = "*/10 * * * * ?")
+//    public void executeTaskWithCron() {
+//        System.out.println("Cron表达式任务执行: " + System.currentTimeMillis() / 1000);
+//    }
+}

+ 3 - 3
alarm-service/src/main/java/com/gyee/alarm/AlarmMain.java

@@ -20,10 +20,10 @@ public class AlarmMain {
 
 //        AlarmBtService alarmBtService= SpringUtils.getBean("alarmBtService");
 //        AlarmWtService alarmWtService= SpringUtils.getBean("alarmWtService");
-//        AlarmCtService alarmCtService= SpringUtils.getBean("alarmCtService");
+        AlarmCtService alarmCtService= SpringUtils.getBean("alarmCtService");
 //
-//        alarmCtService.createSuperTable();
-//        alarmCtService.initalCtAlarm();
+        alarmCtService.createSuperTable();
+        alarmCtService.initalCtAlarm();
 //
 //
 //

+ 1 - 1
alarm-web/src/main/java/com/gyee/alarm/controller/AlarmConfigurationController.java

@@ -154,7 +154,7 @@ public class AlarmConfigurationController {
 
                     if(CacheContext.wtmap.containsKey(ac.getDeviceId()))
                     {
-                        vo.setDeviceName(CacheContext.wtmap.get(ac.getDeviceId()).getName());
+                        vo.setDeviceName(CacheContext.wtmap.get(ac.getDeviceId()).getNemCode());
                     }
                     vos.add(vo);
                 }

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

@@ -206,6 +206,13 @@ public class CacheContext implements CommandLineRunner {
     public static Map<String, AlarmVo> alarmBtMap = new HashMap<>();
 
     public static List<AlarmVo> alarmCtList = new ArrayList<>();
+
+
+
+    public static Map<String, List<AlarmVo>> alarmBtLsMap = new HashMap<>();
+    public static Map<String, List<AlarmVo>> alarmWtLsMap = new HashMap<>();
+    public static Map<String, List<AlarmVo>> alarmInLsMap = new HashMap<>();
+    public static Map<String, List<AlarmVo>> alarmCtLsMap = new HashMap<>();
     public static Map<String, AlarmVo> alarmCtMap = new HashMap<>();
     public static Map<String, ProEconAlarmType> alarmTypeMap = new HashMap<>();
     public static List<ProEconAlarmType> alarmTypeList = new ArrayList<>();

+ 7 - 5
alarm-web/src/main/java/com/gyee/alarm/mapper/auto/AlarmTsMapper.java

@@ -30,12 +30,13 @@ public interface AlarmTsMapper extends BaseMapper<AlarmTs> {
 
 
 
-    @Update("create table if not exists ${tbName} using ${superTableName} tags( #{alarmid}, #{alarmtype}," +
-            "#{characteristic}, #{components},  #{description}, #{deviceid}, #{devicename}," +
+    @Update("create table if not exists ${tbName} using ${superTableName} TAGS( " +
+            "#{alarmid}, #{alarmtype}," +
+            "#{characteristic}, #{components},#{description}, #{deviceid}, #{devicename}," +
             "#{devicetype}, #{enabled}, #{lineid}, #{linename}, #{modelId}, #{projectid}," +
             "#{projectname}, #{rank}, #{resettable}, #{stationid}, #{stationname}, #{subcomponents}," +
-            "#{suffix},  #{tagid}, #{triggertype}, #{uniformcode}" +
-            ")")
+            "#{suffix},  #{tagid}, #{triggertype}, #{uniformcode},#{name}, #{nemCode}, #{faultCause}, #{resolvent},#{faultType},#{aname} " +
+            " )")
     int createTable(@Param("tbName") String tbName, @Param("alarmid") String alarmid, @Param("alarmtype") String alarmtype,
                     @Param("characteristic") String characteristic, @Param("components") String components,
                     @Param("description") String description,
@@ -47,7 +48,8 @@ public interface AlarmTsMapper extends BaseMapper<AlarmTs> {
                     @Param("resettable") Boolean resettable, @Param("stationid") String stationid,
                     @Param("stationname") String stationname, @Param("subcomponents") String subcomponents,
                     @Param("suffix") String suffix, @Param("tagid") String tagid,
-                    @Param("triggertype") Integer triggertype, @Param("uniformcode") String uniformcode, @Param("superTableName") String superTableName
+                    @Param("triggertype") Integer triggertype, @Param("uniformcode") String uniformcode, @Param("superTableName") String superTableName,
+                    @Param("name") String name, @Param("nemCode") String nemCode, @Param("faultCause") String faultCause, @Param("resolvent") String resolvent, @Param("faultType") String faultType, @Param("aname") String aname
 
     );
 

+ 2 - 0
alarm-web/src/main/java/com/gyee/alarm/model/vo/AlarmVo.java

@@ -67,4 +67,6 @@ public class AlarmVo {
     private String wpId;
     private String faultType;
     private String id;
+
+    private String aname;
 }

+ 3 - 0
alarm-web/src/main/java/com/gyee/alarm/service/AlarmConfigurationService.java

@@ -85,6 +85,9 @@ public class AlarmConfigurationService {
 
         }
 
+
+        proEconAlarmConfigurationService.inital();
+
         return result;
     }
 

+ 81 - 3
alarm-web/src/main/java/com/gyee/alarm/service/AlarmCtService.java

@@ -49,6 +49,84 @@ public class AlarmCtService {
         return alarmVoList;
     }
 
+    public List<AlarmVo> initalAlarmVo(ProEconAlarmRule ar) {
+
+        List<AlarmVo> alarmVoList = new ArrayList<>();
+
+        Map<String, List<ProEconAlarmRule>> armap = new HashMap<>();
+
+            StringBuilder sbs = new StringBuilder();
+            sbs.append(ar.getStationId() + ar.getModelId());
+            if (armap.containsKey(String.valueOf(sbs))){
+                List<ProEconAlarmRule> ls = armap.get(String.valueOf(sbs));
+                ls.add(ar);
+            } else {
+                List<ProEconAlarmRule> ls = new ArrayList<>();
+                ls.add(ar);
+                armap.put(String.valueOf(sbs), ls);
+            }
+
+
+        for (ProBasicEquipment wt : CacheContext.wtls) {
+            StringBuilder sb = new StringBuilder();
+            sb.append(wt.getWindpowerstationId() + wt.getModelId());
+
+            if (armap.containsKey(String.valueOf(sb))) {
+                List<ProEconAlarmRule> alarmls = armap.get(String.valueOf(sb));
+
+                if (!alarmls.isEmpty()) {
+                    for (ProEconAlarmRule alarm : alarmls) {
+                        AlarmVo vo = new AlarmVo();
+                        StringBuilder tbName = new StringBuilder();
+                        tbName.append(wt.getId()).append("_").append(alarm.getId());
+                        vo.setTbName(String.valueOf(tbName));
+                        vo.setAlarmId(alarm.getId());
+                        vo.setTagid(alarm.getExpression());
+                        vo.setAlarmType(AlarmTypeValue.CT.getCode());
+                        vo.setCharacteristic(alarm.getName());
+                        vo.setComponents(alarm.getRelatedParts());
+                        vo.setDescription(alarm.getDescription());
+                        vo.setDeviceId(wt.getId());
+                        vo.setDevicename(wt.getName());
+                        vo.setDeviceType(DeviceTypeValue.WT.getCode());
+                        vo.setEnabled(alarm.getEnable());
+                        vo.setLineid(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());
+                            vo.setProjectname(pj.getName());
+                        }
+                        vo.setRank(alarm.getRank());
+                        vo.setResettable(false);
+                        vo.setStationid(wt.getWindpowerstationId());
+                        if (CacheContext.wpmap.containsKey(wt.getWindpowerstationId())) {
+                            ProBasicPowerstation wp = CacheContext.wpmap.get(wt.getWindpowerstationId());
+                            vo.setStationname(wp.getName());
+                        }
+                        vo.setSubcomponents("");
+                        vo.setSuffix("");
+                        vo.setTriggertype(1);
+                        vo.setUniformcode("");
+                        vo.setSuperTableName(AlarmSuperTalbeType.CT.getCode());
+                        vo.setVal(0);
+
+                        vo.setCharacteristic(alarm.getName());
+                        vo.setFaultCause(alarm.getDescription());
+                        vo.setResolvent(alarm.getExpression());
+                        alarmVoList.add(vo);
+                    }
+                }
+            }
+        }
+
+        return alarmVoList;
+    }
+
     private void wtCustomAlarm(List<AlarmVo> alarmVoList, Map<String, List<ProEconAlarmRule>> alarmRulesMap) {
 
         Map<String, List<ProEconAlarmRule>> armap = new HashMap<>();
@@ -119,7 +197,7 @@ public class AlarmCtService {
                         vo.setSuperTableName(AlarmSuperTalbeType.CT.getCode());
                         vo.setVal(0);
 
-                        vo.setCharacteristic("自定义");
+                        vo.setCharacteristic(alarm.getName());
                         vo.setFaultCause(alarm.getDescription());
                         vo.setResolvent(alarm.getExpression());
                         alarmVoList.add(vo);
@@ -201,7 +279,7 @@ public class AlarmCtService {
                         vo.setSuperTableName(AlarmSuperTalbeType.CT.getCode());
                         vo.setVal(0);
 
-                        vo.setCharacteristic("自定义");
+                        vo.setCharacteristic(alarm.getName());
                         vo.setFaultCause(alarm.getDescription());
                         vo.setResolvent(alarm.getExpression());
                         alarmVoList.add(vo);
@@ -336,7 +414,7 @@ public class AlarmCtService {
                     vo.setVal(0);
                     vo.setOval(0);
 
-                    vo.setCharacteristic("自定义");
+                    vo.setCharacteristic(alarm.getName());
                     vo.setFaultCause(alarm.getDescription());
                     vo.setResolvent(alarm.getExpression());
                     alarmVoList.add(vo);

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

@@ -351,7 +351,7 @@ public class AlarmHistoryService   {
 
             if(com.gyee.alarm.util.StringUtils.notEmp(vo.getDeviceId()) && CacheContext.wtmap.containsKey(vo.getDeviceId()))
             {
-                vo.setCode(CacheContext.wtmap.get(vo.getDeviceId()).getNemCode());
+                vo.setCode(CacheContext.wtmap.get(vo.getDeviceId()).getAname());
             }
 
             if(CacheContext.wpmap.containsKey(vo.getStationid()))

+ 11 - 0
alarm-web/src/main/java/com/gyee/alarm/service/AlarmRuleService.java

@@ -14,6 +14,7 @@ import com.gyee.alarm.model.vo.AlarmConfigurationVo;
 import com.gyee.alarm.model.vo.AlarmRuleVo;
 
 import com.gyee.alarm.service.auto.IProEconAlarmPlanService;
+import com.gyee.alarm.service.auto.IProEconAlarmRuleService;
 import com.gyee.alarm.util.SnowflakeGenerator;
 import com.gyee.alarm.util.StringUtil;
 import com.gyee.alarm.util.StringUtils;
@@ -34,6 +35,9 @@ public class AlarmRuleService {
 
     @Resource
     private IProEconAlarmPlanService proEconAlarmPlanService;
+
+    @Resource
+    private IProEconAlarmRuleService proEconAlarmRuleService;
     /**
      * 查询报警信息接口
      * @param wpId 场站不编号
@@ -145,6 +149,10 @@ public class AlarmRuleService {
         }
 //        if (result > 0) {
 //            int i = eventService.saveEventAlertRule(alarmRule, oldRule2, userData.getUserName());
+
+
+
+
         return result;
     }
 
@@ -176,6 +184,9 @@ public class AlarmRuleService {
                 result = saveAlertrule(alarmRule);
             }
 
+            //同步内存和实时数据库新建测点
+            proEconAlarmRuleService.inital(alarmRule);
+
             proEconAlarmPlanService.updatePlanlistById(alarmRule.getId(), alarmRule.getAlarmPlan());
         }
 

+ 2 - 1
alarm-web/src/main/java/com/gyee/alarm/service/auto/IAlarmTsService.java

@@ -33,7 +33,8 @@ public interface IAlarmTsService extends IService<AlarmTs> {
                            Boolean resettable, String stationid,
                            String stationname, String subcomponents,
                            String suffix, String tagid,
-                           Integer triggertype, String uniformcode,String superTableName
+                           Integer triggertype, String uniformcode,String superTableName,
+                           String name,String nemCode, String faultCause, String resolvent,String faultType,String aname
 
     );
 

+ 2 - 0
alarm-web/src/main/java/com/gyee/alarm/service/auto/IProEconAlarmConfigurationService.java

@@ -22,4 +22,6 @@ public interface IProEconAlarmConfigurationService extends IService<ProEconAlarm
                                          String description,
                                          String wpId,
                                          String modelId,String alarmType);
+
+    public void inital() throws Exception;
 }

+ 1 - 0
alarm-web/src/main/java/com/gyee/alarm/service/auto/IProEconAlarmRuleService.java

@@ -13,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IProEconAlarmRuleService extends IService<ProEconAlarmRule> {
 
+    public void inital(ProEconAlarmRule alarmRule) throws Exception;
 }

+ 4 - 2
alarm-web/src/main/java/com/gyee/alarm/service/auto/impl/AlarmTsServiceImpl.java

@@ -45,7 +45,9 @@ public class AlarmTsServiceImpl extends ServiceImpl<AlarmTsMapper, AlarmTs> impl
                            Boolean resettable, String stationid,
                            String stationname, String subcomponents,
                            String suffix, String tagid,
-                           Integer triggertype, String uniformcode,String superTableName
+                           Integer triggertype, String uniformcode, String superTableName,
+                           String name,String nemCode, String faultCause, String resolvent,String faultType,String aname
+
 
     ) {
         return alarmTsMapper.createTable(tbName, alarmid, alarmtype,
@@ -59,7 +61,7 @@ public class AlarmTsServiceImpl extends ServiceImpl<AlarmTsMapper, AlarmTs> impl
                 resettable, stationid,
                 stationname, subcomponents,
                 suffix, tagid,
-                triggertype, uniformcode,superTableName);
+                triggertype, uniformcode,superTableName,   name, nemCode,  faultCause,  resolvent,faultType,aname);
     }
 
 

+ 128 - 6
alarm-web/src/main/java/com/gyee/alarm/service/auto/impl/ProEconAlarmConfigurationServiceImpl.java

@@ -2,14 +2,23 @@ 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.model.auto.ProEconAlarmConfiguration;
 import com.gyee.alarm.mapper.auto.ProEconAlarmConfigurationMapper;
-import com.gyee.alarm.model.auto.ProEconAlarmRule;
+import com.gyee.alarm.model.vo.AlarmTypeValue;
+import com.gyee.alarm.model.vo.AlarmVo;
+
+import com.gyee.alarm.service.AlarmBtService;
+import com.gyee.alarm.service.AlarmInService;
+import com.gyee.alarm.service.AlarmWtService;
 import com.gyee.alarm.service.auto.IProEconAlarmConfigurationService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -26,17 +35,130 @@ public class ProEconAlarmConfigurationServiceImpl extends ServiceImpl<ProEconAla
     private  ProEconAlarmConfigurationMapper proEconAlarmConfigurationMapper;
 
     public IPage<ProEconAlarmConfiguration> pageQueryAll(Page page,
-                                         String description,
-                                         String wpId,
-                                         String modelId,String alarmType)
+                                                         String description,
+                                                         String wpId,
+                                                         String modelId,String alarmType)
     {
         IPage<ProEconAlarmConfiguration> pages=  proEconAlarmConfigurationMapper.pageQueryAll(page,
                 description,
-                 wpId,
-                 modelId, alarmType);
+                wpId,
+                modelId, alarmType);
 
         return pages;
     }
 
 
+    @Resource
+    private AlarmWtService alarmWtService;
+    @Resource
+    private AlarmInService alarmInService;
+    @Resource
+    private AlarmBtService alarmBtService;
+    public void inital() throws Exception {
+
+
+        List<ProEconAlarmConfiguration> templs =this.list().stream().filter(i -> i.getEnable()).collect(Collectors.toList());
+        if (!templs.isEmpty()) {
+            for (ProEconAlarmConfiguration alarm : templs) {
+                if (alarm.getAlarmType().equals(AlarmTypeValue.WT.getCode())) {
+                    CacheContext.wtalarmls.add(alarm);
+                    StringBuilder sb=new StringBuilder();
+                    sb.append(alarm.getStationId()).append(alarm.getModelId());
+
+                    if(CacheContext.wtAlarmMap.containsKey(String.valueOf(sb)))
+                    {
+                        List<ProEconAlarmConfiguration> ls=CacheContext.wtAlarmMap.get(String.valueOf(sb));
+                        ls.add(alarm);
+                    }else
+                    {
+                        List<ProEconAlarmConfiguration> ls=new ArrayList<>();
+                        ls.add(alarm);
+                        CacheContext.wtAlarmMap.put(String.valueOf(sb),ls);
+                    }
+                } else if (alarm.getAlarmType().equals(AlarmTypeValue.BT.getCode())) {
+                    CacheContext.btalarmls.add(alarm);
+
+                }
+                else if (alarm.getAlarmType().equals(AlarmTypeValue.IN.getCode())) {
+                    CacheContext.inalarmls.add(alarm);
+                    StringBuilder sb=new StringBuilder();
+                    sb.append(alarm.getStationId()).append(alarm.getModelId());
+
+                    if(CacheContext.inAlarmMap.containsKey(String.valueOf(sb)))
+                    {
+                        List<ProEconAlarmConfiguration> ls=CacheContext.inAlarmMap.get(String.valueOf(sb));
+                        ls.add(alarm);
+                    }else
+                    {
+                        List<ProEconAlarmConfiguration> ls=new ArrayList<>();
+                        ls.add(alarm);
+                        CacheContext.inAlarmMap.put(String.valueOf(sb),ls);
+                    }
+                }
+            }
+        }
+
+        //风机报警初始化标签
+        CacheContext.alarmWtList=alarmWtService.initalAlarmVo();
+        if(!CacheContext.alarmWtList.isEmpty())
+        {
+            for(AlarmVo vo: CacheContext.alarmWtList)
+            {
+
+                CacheContext.alarmWtMap.put(vo.getTbName().toUpperCase(),vo);
+
+                if(CacheContext.alarmWtLsMap.containsKey(vo.getStationid()))
+                {
+                    List<AlarmVo> ls=CacheContext.alarmWtLsMap.get(vo.getStationid());
+                    ls.add(vo);
+                }else {
+                    List<AlarmVo> ls=new ArrayList<>();
+                    ls.add(vo);
+                    CacheContext.alarmWtLsMap.put(vo.getStationid(),ls);
+                }
+            }
+        }
+        //逆变器报警初始化标签
+        CacheContext.alarmInList=alarmInService.initalAlarmVo();
+        if(!CacheContext.alarmInList.isEmpty())
+        {
+            for(AlarmVo vo: CacheContext.alarmInList)
+            {
+                CacheContext.alarmInMap.put(vo.getTbName().toUpperCase(),vo);
+
+                if(CacheContext.alarmInLsMap.containsKey(vo.getStationid()))
+                {
+                    List<AlarmVo> ls=CacheContext.alarmInLsMap.get(vo.getStationid());
+                    ls.add(vo);
+                }else {
+                    List<AlarmVo> ls=new ArrayList<>();
+                    ls.add(vo);
+                    CacheContext.alarmInLsMap.put(vo.getStationid(),ls);
+                }
+            }
+        }
+
+
+        //升压站报警初始化标签
+        CacheContext.alarmBtList=alarmBtService.initalAlarmVo();
+        if(!CacheContext.alarmBtList.isEmpty())
+        {
+            for(AlarmVo vo: CacheContext.alarmBtList)
+            {
+                CacheContext.alarmBtMap.put(vo.getTbName().toUpperCase(),vo);
+
+                if(CacheContext.alarmBtLsMap.containsKey(vo.getStationid()))
+                {
+                    List<AlarmVo> ls=CacheContext.alarmBtLsMap.get(vo.getStationid());
+                    ls.add(vo);
+                }else {
+                    List<AlarmVo> ls=new ArrayList<>();
+                    ls.add(vo);
+                    CacheContext.alarmBtLsMap.put(vo.getStationid(),ls);
+                }
+            }
+        }
+    }
+
 }
+

+ 198 - 0
alarm-web/src/main/java/com/gyee/alarm/service/auto/impl/ProEconAlarmRuleServiceImpl.java

@@ -1,11 +1,30 @@
 package com.gyee.alarm.service.auto.impl;
 
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.gyee.alarm.init.CacheContext;
+import com.gyee.alarm.model.auto.ProEconAlarmConfiguration;
 import com.gyee.alarm.model.auto.ProEconAlarmRule;
 import com.gyee.alarm.mapper.auto.ProEconAlarmRuleMapper;
+import com.gyee.alarm.model.vo.AlarmCustomType;
+import com.gyee.alarm.model.vo.AlarmTypeValue;
+import com.gyee.alarm.model.vo.AlarmVo;
+import com.gyee.alarm.service.AlarmBtService;
+import com.gyee.alarm.service.AlarmCtService;
+import com.gyee.alarm.service.auto.IAlarmTsService;
 import com.gyee.alarm.service.auto.IProEconAlarmRuleService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.alarm.util.ChineseDes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * <p>
  * 自定义报警配置 服务实现类
@@ -17,4 +36,183 @@ import org.springframework.stereotype.Service;
 @Service
 public class ProEconAlarmRuleServiceImpl extends ServiceImpl<ProEconAlarmRuleMapper, ProEconAlarmRule> implements IProEconAlarmRuleService {
 
+    private Logger logger = LoggerFactory.getLogger(this.getClass());
+    @Resource
+    private AlarmCtService alarmCtService;
+    @Resource
+    private IAlarmTsService alarmTsService;
+    public void inital(ProEconAlarmRule rule) throws Exception {
+
+
+
+        List<ProEconAlarmRule> wtCustomls= CacheContext.alarmRulesMap.get(AlarmCustomType.WT.getCode());
+        List<ProEconAlarmRule> inCustomls=CacheContext.alarmRulesMap.get(AlarmCustomType.IN.getCode());
+
+
+
+        //对自定义报警进行分类
+        if(rule.getCategory().equals(AlarmCustomType.WT.getCode()))
+        {
+            //筛选是否存在预警配置
+            List<ProEconAlarmRule> filteredList = wtCustomls.stream()
+                    .filter(myObject -> myObject.getId().equals(rule.getId()))
+                    .collect(Collectors.toList());
+            //为空的新建测点
+            if(filteredList.isEmpty())
+            {
+                wtCustomls.add(rule);
+
+                List<AlarmVo> ctls=alarmCtService.initalAlarmVo(rule);
+
+                if (!ctls.isEmpty()) {
+
+                    for (AlarmVo vo : ctls) {
+                        try
+                        {
+                            alarmTsService.createTable(vo.getTbName(), vo.getAlarmId(), vo.getAlarmType(),
+                                    vo.getCharacteristic(), vo.getComponents(),
+                                    vo.getDescription(),
+                                    vo.getDeviceId(), vo.getDevicename(),
+                                    vo.getDeviceType(), vo.getEnabled(),
+                                    vo.getLineid(), vo.getLinename(),
+                                    vo.getModelId(), vo.getProjectid(),
+                                    vo.getProjectname(), vo.getRank(),
+                                    vo.getResettable(), vo.getStationid(),
+                                    vo.getStationname(), vo.getSubcomponents(),
+                                    vo.getSuffix(), vo.getTagid(),
+                                    vo.getTriggertype(), vo.getUniformcode(), vo.getSuperTableName(),
+                                    vo.getName(),
+                                    vo.getNemCode(), vo.getFaultCause(), vo.getResolvent(), vo.getFaultType(), vo.getAname());
+
+                        }catch(Exception e)
+                        {
+                            logger.error("创建实时数据库测点异常"+vo.getTbName());
+                        }
+                    }
+
+                }
+                CacheContext.alarmCtList.addAll(ctls);
+            }else {
+                for(ProEconAlarmRule ct:wtCustomls)
+                {
+                    if(ct.getId().equals(rule.getId())) {
+                        ct.setId(rule.getId());
+                        ct.setName(rule.getName());
+                        ct.setDescription(rule.getDescription());
+                        ct.setExpression(rule.getExpression());
+                        ct.setTag(rule.getTag());
+                        ct.setRank(rule.getRank());
+                        ct.setModelId(rule.getModelId());
+                        ct.setCategory(rule.getCategory());
+                        ct.setRange(rule.getRange());
+                        ct.setStationId(rule.getStationId());
+                        ct.setStationName(rule.getStationName());
+                        ct.setProjectId(rule.getProjectId());
+                        ct.setLineId(rule.getLineId());
+                        ct.setDeviceId(rule.getDeviceId());
+                        ct.setElectricalId(rule.getElectricalId());
+                        ct.setRelatedParts(rule.getRelatedParts());
+                        ct.setCreateTime(rule.getCreateTime());
+                        ct.setEnable(rule.getEnable());
+                        ct.setUniformCode(rule.getUniformCode());
+                        ct.setRelatedPartsName(rule.getRelatedPartsName());
+                        ct.setAlarmPlan(rule.getAlarmPlan());
+                        break;
+                    }
+                }
+            }
+
+        }else  if(rule.getCategory().equals(AlarmCustomType.IN.getCode()))
+        {
+            List<ProEconAlarmRule> filteredList = inCustomls.stream()
+                    .filter(myObject -> myObject.getId().equals(rule.getId()))
+                    .collect(Collectors.toList());
+
+            if(filteredList.isEmpty())
+            {
+                inCustomls.add(rule);
+                List<AlarmVo> ctls=alarmCtService.initalAlarmVo(rule);
+                if (!ctls.isEmpty()) {
+                    for (AlarmVo vo : ctls) {
+                        try
+                        {
+                            alarmTsService.createTable(vo.getTbName(), vo.getAlarmId(), vo.getAlarmType(),
+                                    vo.getCharacteristic(), vo.getComponents(),
+                                    vo.getDescription(),
+                                    vo.getDeviceId(), vo.getDevicename(),
+                                    vo.getDeviceType(), vo.getEnabled(),
+                                    vo.getLineid(), vo.getLinename(),
+                                    vo.getModelId(), vo.getProjectid(),
+                                    vo.getProjectname(), vo.getRank(),
+                                    vo.getResettable(), vo.getStationid(),
+                                    vo.getStationname(), vo.getSubcomponents(),
+                                    vo.getSuffix(), vo.getTagid(),
+                                    vo.getTriggertype(), vo.getUniformcode(), vo.getSuperTableName(),
+                                    vo.getName(),
+                                    vo.getNemCode(), vo.getFaultCause(), vo.getResolvent(), vo.getFaultType(), vo.getAname());
+
+                        }catch(Exception e)
+                        {
+                            logger.error("创建实时数据库测点异常"+vo.getTbName());
+                        }
+                    }
+
+                }
+                CacheContext.alarmCtList.addAll(ctls);
+            }else {
+                for(ProEconAlarmRule ct:inCustomls)
+                {
+
+                    if(ct.getId().equals(rule.getId())) {
+                        ct.setId(rule.getId());
+                        ct.setName(rule.getName());
+                        ct.setDescription(rule.getDescription());
+                        ct.setExpression(rule.getExpression());
+                        ct.setTag(rule.getTag());
+                        ct.setRank(rule.getRank());
+                        ct.setModelId(rule.getModelId());
+                        ct.setCategory(rule.getCategory());
+                        ct.setRange(rule.getRange());
+                        ct.setStationId(rule.getStationId());
+                        ct.setStationName(rule.getStationName());
+                        ct.setProjectId(rule.getProjectId());
+                        ct.setLineId(rule.getLineId());
+                        ct.setDeviceId(rule.getDeviceId());
+                        ct.setElectricalId(rule.getElectricalId());
+                        ct.setRelatedParts(rule.getRelatedParts());
+                        ct.setCreateTime(rule.getCreateTime());
+                        ct.setEnable(rule.getEnable());
+                        ct.setUniformCode(rule.getUniformCode());
+                        ct.setRelatedPartsName(rule.getRelatedPartsName());
+                        ct.setAlarmPlan(rule.getAlarmPlan());
+                        break;
+                    }
+                }
+            }
+
+        }
+
+
+        CacheContext.alarmRulesMap.put(AlarmCustomType.WT.getCode(),wtCustomls);
+        CacheContext.alarmRulesMap.put(AlarmCustomType.IN.getCode(),inCustomls);
+
+        if(!CacheContext.alarmCtList.isEmpty())
+        {
+            for(AlarmVo vo: CacheContext.alarmCtList)
+            {
+                CacheContext.alarmCtMap.put(vo.getTbName().toUpperCase(),vo);
+
+
+                if(CacheContext.alarmCtLsMap.containsKey(vo.getStationid()))
+                {
+                    List<AlarmVo> ls=CacheContext.alarmCtLsMap.get(vo.getStationid());
+                    ls.add(vo);
+                }else {
+                    List<AlarmVo> ls=new ArrayList<>();
+                    ls.add(vo);
+                    CacheContext.alarmCtLsMap.put(vo.getStationid(),ls);
+                }
+            }
+        }
+    }
 }

File diff suppressed because it is too large
+ 239 - 2
log/ota.log