Browse Source

报警统计功能

shilin 1 year ago
parent
commit
312eccafd2

+ 10 - 1
alarm-web/pom.xml

@@ -204,7 +204,16 @@
             <version>1.5.21</version>
         </dependency>
 
-
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>4.1.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>4.1.2</version>
+        </dependency>
 
     </dependencies>
     <build>

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

@@ -210,7 +210,6 @@ public class AlarmConfigurationController {
                 }
 
                 if (allCheck) {
-                    alertrule.setId(String.valueOf(SnowflakeGenerator.generateId()));
 
                     alarmConfigurationService.saveAndUpdateAlertrule(alertrule);
                 }

+ 7 - 8
alarm-web/src/main/java/com/gyee/alarm/controller/AlertRuleController.java

@@ -308,9 +308,9 @@ public class AlertRuleController {
                                   @RequestParam(value = "name", required = false) String name,
                                   @RequestParam(value = "wpId", required = false) String wpId,
                                   @RequestParam(value = "modelId", required = false) String modelId,
-                                  @RequestParam(value = "rank", required = false) String rank,
+                                  @RequestParam(value = "rank", required = false) Integer rank,
                                   @RequestParam(value = "category", required = false) String category,
-                                  @RequestParam(value = "enabled", required = false) String enabled,
+                                  @RequestParam(value = "enabled", required = false) Boolean enabled,
                                   @RequestParam(value = "relatedparts", required = false) String relatedparts
     ) {
         Page<ProEconAlarmRule> page = new Page(pageNum, pageSize);
@@ -404,17 +404,17 @@ public class AlertRuleController {
         List<ProEconAlarmRule> list = Arrays.asList(
                 ProEconAlarmRule.builder().id("").name("单机变桨电池柜温度1温度传感器异常值").description("温度等于850度或者温度小于零下40度")
                         .expression("AI242 == 850 || AI242 <-40").tag("").rank(4).modelId("TZ-2000")
-                        .category("1").range("0")
+                        .category("windturbine").range("parts")
                         .stationId("SXJ_KGDL_HSM_FDC_STA").projectId("SXJ_KGDL_HSMF01_EG").lineId("SXJ_KGDL_HSMF01_LN").deviceId("SXJ_KGDL_HSM_F_WT_0001_EQ")
-                        .electricalId("").relatedParts("BJ").createTime(DateUtils.truncate(previousDay))
+                        .electricalId("").relatedParts("BJXT").createTime(DateUtils.truncate(previousDay))
                         .enable(true).uniformCode("AI091")
                         .build(),
 
                 ProEconAlarmRule.builder().id("").name("单机变桨电池柜温度2超限报警").description("温度等于850度或者温度小于零下40度")
                         .expression("(AI243>=65 || AI243<-10)").tag("").rank(4).modelId("TZ-2000")
-                        .category("1").range("0")
+                        .category("windturbine").range("parts")
                         .stationId("SXJ_KGDL_HSM_FDC_STA").projectId("SXJ_KGDL_HSMF01_EG").lineId("SXJ_KGDL_HSMF01_LN").deviceId("SXJ_KGDL_HSM_F_WT_0002_EQ")
-                        .electricalId("").relatedParts("BJ").createTime(DateUtils.truncate(previousDay))
+                        .electricalId("").relatedParts("BJXT").createTime(DateUtils.truncate(previousDay))
                         .enable(true).uniformCode("AI091")
                         .build()
 
@@ -470,8 +470,7 @@ public class AlertRuleController {
                 }
 
                 if (allCheck) {
-                    alertrule.setId(String.valueOf(SnowflakeGenerator.generateId()));
-                    alertrule.setCreateTime(new Date());
+
 
                     alarmRuleService.saveAndUpdateAlertrule(alertrule);
                 }

+ 24 - 0
alarm-web/src/main/java/com/gyee/alarm/mapper/auto/ProEconAlarmConfigurationMapper.java

@@ -8,6 +8,8 @@ import com.gyee.alarm.model.auto.ProEconAlarmRule;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
+import java.util.List;
+
 /**
  * <p>
  * 报警配置表 Mapper 接口
@@ -40,4 +42,26 @@ public interface ProEconAlarmConfigurationMapper extends BaseMapper<ProEconAlarm
                                          @Param("description") String description,
                                          @Param("wpId") String wpId,
                                          @Param("modelId") String modelId);
+
+
+    @Select({"<script>",
+            "select * from pro_econ_alarm_configuration ",
+            "<where>",
+            " 1=1 ",
+
+            "<if test='wpId !=null  '>",
+            "and station_id  = #{wpId} ",
+            "</if>",
+            "<if test='description !=null  '>",
+            "and description = #{description} ",
+            "</if>",
+            "<if test='modelId !=null  '>",
+            "and model_id = #{modelId} ",
+            "</if>",
+            "</where>",
+
+            "</script>"})
+    List<ProEconAlarmConfiguration> queryObject(@Param("description") String description,
+                                       @Param("wpId") String wpId,
+                                       @Param("modelId") String modelId);
 }

+ 24 - 3
alarm-web/src/main/java/com/gyee/alarm/mapper/auto/ProEconAlarmRuleMapper.java

@@ -55,7 +55,7 @@ public interface ProEconAlarmRuleMapper extends BaseMapper<ProEconAlarmRule> {
             " 1=1 ",
 
             "<if test='wpId !=null  '>",
-            "a.station_id  = #{wpId} ",
+            "and a.station_id  = #{wpId} ",
             "</if>",
             "<if test='name !=null  '>",
             "and a.name like #{name} ",
@@ -82,9 +82,9 @@ public interface ProEconAlarmRuleMapper extends BaseMapper<ProEconAlarmRule> {
                                          @Param("name") String name,
                                          @Param("wpId") String wpId,
                                          @Param("modelId") String modelId,
-                                         @Param("rank") String rank,
+                                         @Param("rank") Integer rank,
                                          @Param("category") String category,
-                                         @Param("enable") String enable,
+                                         @Param("enable") Boolean enable,
                                          @Param("relatedparts") String relatedparts);
 
     @Select("select distinct a.related_parts as relatedParts,a.name as alarmName,d.name  as typeName from pro_econ_alarm_rule a " +
@@ -92,6 +92,27 @@ public interface ProEconAlarmRuleMapper extends BaseMapper<ProEconAlarmRule> {
             "where related_parts is not null")
     List<AlarmRuleVo> queryTree();
 
+
+    @Select({"<script>",
+            "select a.* from pro_econ_alarm_rule a",
+            "<where>",
+            " 1=1 ",
+
+            "<if test='wpId !=null  '>",
+            "and a.station_id  = #{wpId} ",
+            "</if>",
+            "<if test='name !=null  '>",
+            "and a.name =  #{name} ",
+            "</if>",
+            "<if test='modelId !=null  '>",
+            "and a.model_id = #{modelId} ",
+            "</if>",
+            "</where>",
+
+            "</script>"})
+    List<ProEconAlarmRule> queryObject( @Param("name") String name,
+                                 @Param("wpId") String wpId,
+                                 @Param("modelId") String modelId);
     @Select(" select a.name from  pro_econ_alarm_rule a where a.related_parts = #{relatedParts}   group by a.name ")
     List<ProEconAlarmRule> quertByrelatedParts(@Param("relatedParts") String relatedParts);
 

+ 21 - 20
alarm-web/src/main/java/com/gyee/alarm/service/AlarmConfigurationService.java

@@ -4,6 +4,7 @@ package com.gyee.alarm.service;
 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.mapper.auto.ProEconAlarmRuleMapper;
 import com.gyee.alarm.model.auto.ProBasicPowerstation;
 import com.gyee.alarm.model.auto.ProEconAlarmConfiguration;
@@ -26,11 +27,12 @@ import java.util.Map;
 public class AlarmConfigurationService {
 
     @Resource
-    private IProEconAlarmConfigurationService roEconAlarmConfigurationService;
+    private IProEconAlarmConfigurationService proEconAlarmConfigurationService;
     @Resource
     private RuleUpdateEventService ruleUpdateEventService;
 
-
+    @Resource
+    private ProEconAlarmConfigurationMapper proEconAlarmConfigurationMapper;
     private boolean saveAlertrule(ProEconAlarmConfiguration alarmRule) throws Exception {
 
         boolean result = false;
@@ -39,7 +41,7 @@ public class AlarmConfigurationService {
             
             alarmRule.setId(String.valueOf(SnowflakeGenerator.generateId()));
   
-            result= roEconAlarmConfigurationService.save(alarmRule);
+            result= proEconAlarmConfigurationService.save(alarmRule);
         }
 //        if (result > 0) {
 //            int i = eventService.saveEventWarning(alarmRule, oldRule2, userData.getUserName());
@@ -53,32 +55,31 @@ public class AlarmConfigurationService {
 
         if (StringUtils.notEmp(alarmRule)) {
 
-            if (StringUtils.notEmp(alarmRule.getId())) {
-
-                ProEconAlarmConfiguration  oldRule2 = roEconAlarmConfigurationService.getById(alarmRule.getId());
-                if (oldRule2 != null) {
-
-                    result = roEconAlarmConfigurationService.updateById(alarmRule);
-                    ruleUpdateEventService.saveEventWarning(alarmRule,oldRule2);
-                }else
-                {
-                    ruleUpdateEventService.saveEventWarning(alarmRule,null);
-                    result = saveAlertrule(alarmRule);
-                }
-            }
-            else
+            List<ProEconAlarmConfiguration>  oldRulels = proEconAlarmConfigurationMapper.queryObject(alarmRule.getDescription(),alarmRule.getStationId(),alarmRule.getModelId());
+            if (!oldRulels.isEmpty()) {
+                ProEconAlarmConfiguration oldRule2=oldRulels.get(0);
+                alarmRule.setId(oldRule2.getId());
+                result = proEconAlarmConfigurationService.updateById(alarmRule);
+                ruleUpdateEventService.saveEventWarning(alarmRule,oldRule2);
+            }else
             {
-                result =  saveAlertrule(alarmRule);
+                alarmRule.setId(String.valueOf(SnowflakeGenerator.generateId()));
                 ruleUpdateEventService.saveEventWarning(alarmRule,null);
+                result = saveAlertrule(alarmRule);
             }
 
+        }else
+        {
+            alarmRule.setId(String.valueOf(SnowflakeGenerator.generateId()));
+            ruleUpdateEventService.saveEventWarning(alarmRule,null);
+            result = saveAlertrule(alarmRule);
         }
 
         return result;
     }
 
     public boolean deleteAlertrule(String id) {
-        return roEconAlarmConfigurationService.removeById(id);
+        return proEconAlarmConfigurationService.removeById(id);
     }
 
 
@@ -102,7 +103,7 @@ public class AlarmConfigurationService {
         }
 
 
-        IPage<ProEconAlarmConfiguration> alertruleIPage = roEconAlarmConfigurationService.pageQueryAll(page, name, station, modelId);
+        IPage<ProEconAlarmConfiguration> alertruleIPage = proEconAlarmConfigurationService.pageQueryAll(page, name, station, modelId);
 
         return alertruleIPage;
     }

+ 12 - 8
alarm-web/src/main/java/com/gyee/alarm/service/AlarmRuleService.java

@@ -56,25 +56,29 @@ public class AlarmRuleService {
 
         if (StringUtils.notEmp(alarmRule)) {
 
-            if (StringUtils.notEmp(alarmRule.getId())) {
-
-                ProEconAlarmRule  oldRule2 = proEconAlarmRuleMapper.selectById(alarmRule.getId());
+            List<ProEconAlarmRule>  oldRulels = proEconAlarmRuleMapper.queryObject(alarmRule.getName(),alarmRule.getStationId(),alarmRule.getModelId());
+            if(!oldRulels.isEmpty())
+            {
+                ProEconAlarmRule   oldRule2=oldRulels.get(0);
                 if (oldRule2 != null) {
 
+                    alarmRule.setId(oldRule2.getId());
                     result = proEconAlarmRuleMapper.updateByAlertruleId(alarmRule);
                     ruleUpdateEventService.saveEventAlertRule(alarmRule,oldRule2);
                 }else
                 {
+                    alarmRule.setId(String.valueOf(SnowflakeGenerator.generateId()));
+                    alarmRule.setCreateTime(new Date());
                     ruleUpdateEventService.saveEventAlertRule(alarmRule,null);
                     result = saveAlertrule(alarmRule);
                 }
-            }
-            else
+            }else
             {
-                result =  saveAlertrule(alarmRule);
+                alarmRule.setId(String.valueOf(SnowflakeGenerator.generateId()));
+                alarmRule.setCreateTime(new Date());
                 ruleUpdateEventService.saveEventAlertRule(alarmRule,null);
+                result = saveAlertrule(alarmRule);
             }
-
         }
 
         return result;
@@ -85,7 +89,7 @@ public class AlarmRuleService {
     }
 
 
-    public IPage<ProEconAlarmRule> pageQueryAll(Page page, String name, String station, String modelId, String rank, String category, String enabled, String relatedparts) {
+    public IPage<ProEconAlarmRule> pageQueryAll(Page page, String name, String station, String modelId, Integer rank, String category, Boolean enabled, String relatedparts) {
 
 
         if(StringUtils.notEmp(name))

+ 3 - 8
alarm-web/src/main/java/com/gyee/alarm/service/RuleUpdateEventService.java

@@ -153,6 +153,7 @@ public class RuleUpdateEventService {
     }
 
     public int saveEventWarning(ProEconAlarmConfiguration newWarning, ProEconAlarmConfiguration oldWarning) {
+
         HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
         String token = request.getHeader("token");
         String userId = request.getHeader("userId");
@@ -222,14 +223,8 @@ public class RuleUpdateEventService {
                                 info.setId(String.valueOf(infoId));
                                 info.setEventId(eventId);
                                 info.setFieldName(infoFiledName);
-                                if(field.getName().toUpperCase().equals("EDNAVALUE")){
-                                    info.setBeforValue(val_old != null ? "DI"+val_old.toString() : null);
-                                    info.setAfterValue(val_new != null ? "DI"+val_new.toString() : null);
-
-                                }else{
-                                    info.setBeforValue(val_old != null ? val_old.toString() : null);
-                                    info.setAfterValue(val_new != null ? val_new.toString() : null);
-                                }
+                                info.setBeforValue(val_old != null ? val_old.toString() : null);
+                                info.setAfterValue(val_new != null ? val_new.toString() : null);
 
                                 infoList.add(info);
                             }

File diff suppressed because it is too large
+ 1230 - 0
log/ota.log