Browse Source

风机报警和升压站报警功能修改优化

shilin 1 year ago
parent
commit
b0e927734e

+ 141 - 0
alarm-service/pom.xml

@@ -13,13 +13,154 @@
     <name>alarm-service</name>
 
 
+
+    <!-- 统一管理jar包版本 -->
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+        <junit.version>4.12</junit.version>
+        <log4j.version>2.15.0</log4j.version>
+        <lombok.version>1.18.16</lombok.version>
+        <mysql.version>5.1.45</mysql.version>
+        <druid.version>1.2.5</druid.version>
+        <mybatis.spring.boot.version>1.3.2</mybatis.spring.boot.version>
+        <mybatis-plus.boot.starter.version>3.2.0</mybatis-plus.boot.starter.version>
+        <mybatis-plus.generator.version>3.3.2</mybatis-plus.generator.version>
+        <pgsql.version>42.2.5</pgsql.version>
+        <groovy.version>3.0.8</groovy.version>
+        <springframework.boot.version>2.2.2.RELEASE</springframework.boot.version>
+
     </properties>
 
+
     <dependencies>
+        <dependency>
+            <groupId>com.opencsv</groupId>
+            <artifactId>opencsv</artifactId>
+            <version>4.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+            <version>${springframework.boot.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+            <version>${springframework.boot.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <version>${springframework.boot.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+            <version>${springframework.boot.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-autoconfigure</artifactId>
+            <version>${springframework.boot.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+            <version>${lombok.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid</artifactId>
+            <version>1.1.10</version>
+        </dependency>
+        <dependency>
+            <groupId>com.oracle</groupId>
+            <artifactId>ojdbc6</artifactId>
+            <version>11.2.0.3</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.data</groupId>
+            <artifactId>spring-data-redis</artifactId>
+            <version>2.3.6.RELEASE</version>
+        </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>${mybatis-plus.boot.starter.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-generator</artifactId>
+            <version>${mybatis-plus.generator.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
+            <version>3.5.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.freemarker</groupId>
+            <artifactId>freemarker</artifactId>
+            <version>2.3.28</version>
+        </dependency>
 
         <dependency>
+            <groupId>com.gyee</groupId>
+            <artifactId>common</artifactId>
+            <version>1.0-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.17</version>
+            <scope>compile</scope>
+        </dependency>
+        <!-- ********************** plugin ********************** -->
+        <!-- groovy-all -->
+        <dependency>
+            <groupId>org.codehaus.groovy</groupId>
+            <artifactId>groovy</artifactId>
+            <version>${groovy.version}</version>
+        </dependency>
+        <!-- xxl-job-core -->
+        <dependency>
+            <groupId>com.xuxueli</groupId>
+            <artifactId>xxl-job-core</artifactId>
+            <version>2.3.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>2.8.6</version>
+        </dependency>
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-all</artifactId>
+            <version>4.1.55.Final</version>
+        </dependency>
+        <dependency>
+            <groupId>org.postgresql</groupId>
+            <artifactId>postgresql</artifactId>
+            <version>${pgsql.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>3.17</version>
+        </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.1.1</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>com.taosdata.jdbc</groupId>
             <artifactId>taos-jdbcdriver</artifactId>
             <version>3.2.2</version>

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

@@ -73,4 +73,19 @@ public class AlarmController {
         alarmCtService.saveAlarms(alarms);
     }
 
+    @PostMapping("/updateWtTags")
+    public void updateWtTags(@RequestBody List<AlarmTag> alarms ) {
+        alarmWtService.updateAlarms(alarms);
+    }
+
+    @PostMapping("/updateBtTags")
+    public void updateBtTags(@RequestBody List<AlarmTag> alarms ) {
+        alarmBtService.updateAlarms(alarms);
+    }
+
+    @PostMapping("/updateCtTags")
+    public void updateCtTags(@RequestBody List<AlarmTag> alarms ) {
+        alarmCtService.updateAlarms(alarms);
+    }
+
 }

+ 9 - 3
alarm-service/src/main/java/com/gyee/alarm/mapper/auto/AlarmTsMapper.java

@@ -4,6 +4,7 @@ package com.gyee.alarm.mapper.auto;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.gyee.alarm.model.auto.AlarmTs;
+import com.gyee.alarm.model.vo.AlarmSimpleVo;
 import com.gyee.alarm.model.vo.AlarmTsVo;
 import com.gyee.alarm.model.vo.AlarmVo;
 import org.apache.ibatis.annotations.Insert;
@@ -18,7 +19,7 @@ import java.util.List;
 public interface AlarmTsMapper extends BaseMapper<AlarmTs> {
 
 
-    @Update("CREATE STABLE if not exists ${superTableName} (ts TIMESTAMP,val INT,oval INT,confirmed BOOL) " +
+    @Update("CREATE STABLE if not exists ${superTableName} (ts TIMESTAMP,val INT,confirmed BOOL,endts TIMESTAMP,timeLong DOUBLE) " +
             "TAGS (alarmid NCHAR(100),alarmtype NCHAR(50),characteristic NCHAR(50)," +
             "components NCHAR(50),description NCHAR(500),deviceid NCHAR(50),devicename NCHAR(70)," +
             "devicetype NCHAR(50),enabled BOOL,lineid NCHAR(50),linename NCHAR(70),modelId NCHAR(50),projectid NCHAR(50)," +
@@ -75,11 +76,16 @@ public interface AlarmTsMapper extends BaseMapper<AlarmTs> {
     List<AlarmVo> findTags(@Param("stbaleName") String stbaleName);
 
 
-    @Select("select deviceid,description,count(*) as val from #{superTableName} where ts>=#{begin} and ts<=#{end}  stationid=#{stationid}  group by description,deviceid  ")
+    @Select("select deviceid,description,count(*) as val,sum(timeLong) as timeLong from #{superTableName} where ts>=#{begin} and ts<=#{end}  stationid=#{stationid}  group by description,deviceid  ")
     List<AlarmTsVo> selectByGroup(@Param("superTableName") String superTableName, @Param("stationid") String stationid, @Param("begin")long begin, @Param("end") long end);
 
 
-    @Select("select ts,val,oval,alarmid,alarmtype,characteristic,components,confirmed,description,deviceid,devicename,devicetype,enabled,lineid,linename," +
+    @Select("select ts,val,confirmed,endts,timeLong,alarmid,alarmtype,characteristic,components,confirmed,description,deviceid,devicename,devicetype,enabled,lineid,linename," +
             "modelId,projectid,projectname,rank,resettable,stationid,stationname,subcomponents,suffix,tagid,triggertype,uniformcode from #{tbName}   limit #{limit} offset #{offset} ")
     List<AlarmVo> selectByTbName(@Param("tbName") String tbName,@Param("limit") long limit,@Param("offset") long offset);
+
+
+    @Select("select last_row(*),tbname from #{superTableName} where tbname in( #{tbnames} ) group by tbname")
+    List<AlarmSimpleVo> selectLastRowByTbname(@Param("superTableName") String superTableName, @Param("tbnames") String tbnames);
+
 }

+ 1 - 0
alarm-service/src/main/java/com/gyee/alarm/model/auto/AlarmTs.java

@@ -12,5 +12,6 @@ public class AlarmTs {
     private Integer val;
     private Integer oval;
     private Boolean confirmed;
+    private Timestamp endts;
     private String tbName;
 }

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

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.activerecord.Model;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
+import java.util.Date;
+
 /**
  * <p>
  * 报警缓存表
@@ -29,7 +31,7 @@ public class ProEconAlarmInfo extends Model {
     /**
      * 最近更新时间戳
      */
-    private Long ts;
+    private Date lastUpdateTime;
 
     /**
      * 值
@@ -165,4 +167,14 @@ public class ProEconAlarmInfo extends Model {
      */
     private Integer isOpen;
 
+    /**
+     * 确认时间
+     */
+    private Date confirmedTime;
+
+    /**
+     * 关闭时间
+     */
+    private Date closeTime;
+
 }

+ 18 - 0
alarm-service/src/main/java/com/gyee/alarm/model/vo/AlarmSimpleVo.java

@@ -0,0 +1,18 @@
+package com.gyee.alarm.model.vo;
+
+
+import lombok.Data;
+
+import java.sql.Timestamp;
+
+@Data
+public class AlarmSimpleVo {
+
+    private  String tbName;
+    private Timestamp ts;
+    private Integer val;
+    private Integer oval;
+    private Timestamp endts;
+    private Double timelong;
+
+}

+ 11 - 1
alarm-service/src/main/java/com/gyee/alarm/model/vo/AlarmTag.java

@@ -42,6 +42,15 @@ public class AlarmTag {
     private Integer rank;
 
     /**
+     * 结束时间戳
+     */
+    private Long endts;
+    /**
+     * 报警时长
+     */
+    private Double timeLong;
+
+    /**
      * 更新并检测是否触发报警
      */
     public Boolean updateAndCheck(PointData pointData) {
@@ -52,7 +61,8 @@ public class AlarmTag {
         ts = pointData.getPointTime();
         oval = pointData.getPointValueInDouble();
 
-
+        endts= pointData.getPointTime();
+        val=0.0;
         if(triggerType==-1)
         {
             val=1.0;

+ 2 - 0
alarm-service/src/main/java/com/gyee/alarm/model/vo/AlarmTsVo.java

@@ -13,4 +13,6 @@ public class AlarmTsVo {
     private String deviceid;
     private Integer val;
 
+    private Double timeLong;
+
 }

+ 4 - 0
alarm-service/src/main/java/com/gyee/alarm/model/vo/AlarmVo.java

@@ -39,4 +39,8 @@ public class AlarmVo {
     private Integer val;
     private Integer oval;
 
+    private Timestamp endts;
+
+    private Double timelong;
+
 }

+ 135 - 55
alarm-service/src/main/java/com/gyee/alarm/service/AlarmBtService.java

@@ -2,18 +2,17 @@ package com.gyee.alarm.service;
 
 import com.gyee.alarm.init.CacheContext;
 import com.gyee.alarm.model.auto.*;
-import com.gyee.alarm.model.vo.AlarmSuperTalbeType;
-import com.gyee.alarm.model.vo.AlarmTag;
-import com.gyee.alarm.model.vo.AlarmVo;
-import com.gyee.alarm.model.vo.DeviceTypeValue;
+import com.gyee.alarm.model.vo.*;
 import com.gyee.alarm.service.auto.IAlarmTsService;
 import com.gyee.alarm.service.auto.IProEconAlarmInfoService;
+import com.gyee.alarm.util.DateUtils;
 import com.gyee.alarm.util.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.sql.SQLException;
+import java.sql.Timestamp;
 import java.util.*;
 
 @Service
@@ -66,6 +65,7 @@ public class AlarmBtService {
                 po.setOval(po.getVal());
                 po.setRank(vo.getRank());
                 po.setTs(new Date().getTime());
+                po.setTimeLong(0.0);
                 alarmTags.add(po);
             }
         }
@@ -164,7 +164,8 @@ public class AlarmBtService {
                         AlarmVo vo = CacheContext.alarmBtMap.get(alarm.getId());
                         ProEconAlarmInfo po = new ProEconAlarmInfo();
                         po.setTbname(vo.getTbName());
-                        po.setTs(alarm.getTs());
+
+                        po.setLastUpdateTime(new Date(alarm.getTs()));
                         po.setTagId(alarm.getTagId());
                         po.setTriggerType(alarm.getTriggerType());
                         po.setAlarmId(vo.getAlarmid());
@@ -190,73 +191,152 @@ public class AlarmBtService {
                         po.setLineidName(vo.getLinename());
                         po.setDeviceName(vo.getDevicename());
                         po.setOval(alarm.getOval().intValue());
-                        if(alarm.getVal()==1)
-                        {
-                            po.setIsOpen(1);
-                        }else if(alarm.getVal()==0)
-                        {
-                            po.setIsOpen(0);
-                        }
+                        po.setVal(alarm.getVal().intValue());
+                        po.setIsOpen(1);
                         valuels.add(po);
                     }
                 }
 
-//                List<ProEconAlarmInfo> templs = new ArrayList<>();
-//                for (ProEconAlarmInfo vo : valuels) {
-//                    templs.add(vo);
-//                    if (templs.size() == 100) {
-//                        proEconAlarmInfoService.saveOrUpdateBatch(templs);
-//                        templs = new ArrayList<>();
-//                    }
-//                }
-//
-//                if (!templs.isEmpty()) {
-//                    proEconAlarmInfoService.saveOrUpdateBatch(templs);
-//                }
-
-
-//分类,相同的报警放在一个map中的list中
-                Map<String, List<ProEconAlarmInfo>> tempmap = new HashMap<>();
+
+
+                List<String> idls = new ArrayList<>();
+                for (ProEconAlarmInfo vo : valuels) {
+                    idls.add(vo.getTbname());
+                }
+                if (!idls.isEmpty()) {
+
+                    proEconAlarmInfoService.removeByIds(idls);
+                }
+
+
+                List<ProEconAlarmInfo> templs = new ArrayList<>();
                 for (ProEconAlarmInfo vo : valuels) {
-                    if (tempmap.containsKey(vo.getTbname())) {
-                        List<ProEconAlarmInfo> templs = tempmap.get(vo.getTbname());
-                        templs.add(vo);
-                    } else {
-                        List<ProEconAlarmInfo> templs = new ArrayList<>();
-                        templs.add(vo);
-                        tempmap.put(vo.getTbname(), templs);
+                    templs.add(vo);
+                    if (templs.size() == 100) {
+                        proEconAlarmInfoService.saveBatch(templs);
+                        templs = new ArrayList<>();
                     }
                 }
-//删除,相同的报警
-                List<String> idls = new ArrayList<>();
-                for (Map.Entry<String, List<ProEconAlarmInfo>> entry : tempmap.entrySet()) {
-                    idls.add(entry.getKey());
+
+                if (!templs.isEmpty()) {
+                    proEconAlarmInfoService.saveBatch(templs);
                 }
 
-                if (!idls.isEmpty()) {
 
-                    proEconAlarmInfoService.removeByIds(idls);
+            }
+        }
+
+    }
+
+
+    public synchronized void updateAlarms(List<AlarmTag> ls) {
+
+        if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+            StringBuilder sb=new StringBuilder();
+            Map<String,AlarmSimpleVo> map=new HashMap<>();
+            for (AlarmTag alarm : ls) {
+                sb.append("'").append(alarm.getId()).append("',");
+
+            }
+
+            String ids=sb.substring(0,sb.length()-1);
+
+            List<AlarmSimpleVo> alarmls=alarmTsService.selectLastRowByTbname(AlarmSuperTalbeType.BT.getCode(),ids);
+            if(!alarmls.isEmpty())
+            {
+                for(AlarmSimpleVo vo:alarmls)
+                {
+
+                    map.put(vo.getTbName(),vo);
+
+                }
+            }
+
+            for (AlarmTag alarm : ls) {
+                if(map.containsKey(alarm.getId()))
+                {
+                    AlarmSimpleVo tag=map.get(alarm.getId());
+                    tag.setTs(new Timestamp(alarm.getTs()));
+
+                    Date begin = new Date(alarm.getEndts());
+                    Date end = new Date(alarm.getTs());
+
+                    double value= DateUtils.hoursDiff(begin,end);
+                    tag.setTimelong(value);
                 }
 
-                List<ProEconAlarmInfo> pols = new ArrayList<>();
-//保存,取项目集合中的最后一个记录进行保存
-                for (Map.Entry<String, List<ProEconAlarmInfo>> entry : tempmap.entrySet()) {
-                    List<ProEconAlarmInfo> resultls = entry.getValue();
-                    if(!resultls.isEmpty())
-                    {
-                        Collections.sort(resultls, new Comparator<ProEconAlarmInfo>() {
-                            public int compare(ProEconAlarmInfo arg0, ProEconAlarmInfo arg1) {
-                                return arg0.getTs().compareTo(arg1.getTs());
-
-                            }
-                        });
-                        pols.add(resultls.get(resultls.size() - 1));
+            }
+
+            alarmTsService.insertList(ls);
+
+
+            if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+                List<ProEconAlarmInfo> valuels = new ArrayList<>();
+                for (AlarmTag alarm : ls) {
+                    if (CacheContext.alarmBtMap.containsKey(alarm.getId())) {
+                        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.setTagId(alarm.getTagId());
+                        po.setTriggerType(alarm.getTriggerType());
+                        po.setAlarmId(vo.getAlarmid());
+                        po.setDeviceId(vo.getDeviceid());
+                        po.setSubcomponents(vo.getSuffix());
+                        po.setRank(vo.getRank());
+                        po.setConfirmed(false);
+                        po.setUniformCode(vo.getUniformcode());
+                        po.setAlarmType(vo.getAlarmtype());
+                        po.setDeviceType(vo.getDevicetype());
+                        po.setConfirmed(vo.getConfirmed());
+                        po.setSubcomponents(vo.getSubcomponents());
+                        po.setDescription(vo.getDescription());
+                        po.setModelId(vo.getModelId());
+                        po.setResetTable(vo.getResettable());
+                        po.setEnable(vo.getEnabled());
+                        po.setCharacteristic(vo.getCharacteristic());
+                        po.setStationId(vo.getStationid());
+                        po.setProjectId(vo.getProjectid());
+                        po.setLineId(vo.getLineid());
+                        po.setStationName(vo.getStationname());
+                        po.setProjectiName(vo.getProjectname());
+                        po.setLineidName(vo.getLinename());
+                        po.setDeviceName(vo.getDevicename());
+                        po.setOval(alarm.getOval().intValue());
+                        po.setVal(alarm.getVal().intValue());
+                        if(StringUtils.notEmp(alarm.getEndts()))
+                        {
+                            po.setCloseTime(new Date(alarm.getEndts()));
+                        }else
+                        {
+                            po.setCloseTime(new Date());
+                        }
+
+                        po.setIsOpen(0);
+                        valuels.add(po);
                     }
+                }
+
+                List<String> idls = new ArrayList<>();
+                for (ProEconAlarmInfo vo : valuels) {
+                    idls.add(vo.getTbname());
+                }
+                if (!idls.isEmpty()) {
 
+                    proEconAlarmInfoService.removeByIds(idls);
                 }
 
                 List<ProEconAlarmInfo> templs = new ArrayList<>();
-                for (ProEconAlarmInfo vo : pols) {
+                for (ProEconAlarmInfo vo : valuels) {
                     templs.add(vo);
                     if (templs.size() == 100) {
                         proEconAlarmInfoService.saveBatch(templs);

+ 115 - 42
alarm-service/src/main/java/com/gyee/alarm/service/AlarmCtService.java

@@ -6,12 +6,14 @@ import com.gyee.alarm.model.vo.*;
 import com.gyee.alarm.service.auto.IAlarmTsService;
 import com.gyee.alarm.service.auto.IProEconAlarmInfoService;
 import com.gyee.alarm.service.auto.IProEconAlarmRuleService;
+import com.gyee.alarm.util.DateUtils;
 import com.gyee.alarm.util.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.sql.SQLException;
+import java.sql.Timestamp;
 import java.util.*;
 
 @Service
@@ -290,7 +292,7 @@ public class AlarmCtService {
                         AlarmVo vo = CacheContext.alarmCtMap.get(alarm.getId());
                         ProEconAlarmInfo po = new ProEconAlarmInfo();
                         po.setTbname(vo.getTbName());
-                        po.setTs(alarm.getTs());
+                        po.setLastUpdateTime(new Date(alarm.getTs()));
                         po.setTagId(alarm.getTagId());
                         po.setTriggerType(alarm.getTriggerType());
                         po.setAlarmId(vo.getAlarmid());
@@ -317,59 +319,22 @@ public class AlarmCtService {
                         po.setDeviceName(vo.getDevicename());
                         po.setOval(alarm.getOval().intValue());
 
-                        if(alarm.getVal()==1)
-                        {
-                            po.setIsOpen(1);
-                        }else
-                        {
-                            po.setIsOpen(0);
-                        }
+                        po.setIsOpen(1);
                         valuels.add(po);
                     }
                 }
-
-//分类,相同的报警放在一个map中的list中
-                Map<String, List<ProEconAlarmInfo>> tempmap = new HashMap<>();
-                for (ProEconAlarmInfo vo : valuels) {
-                    if (tempmap.containsKey(vo.getTbname())) {
-                        List<ProEconAlarmInfo> templs = tempmap.get(vo.getTbname());
-                        templs.add(vo);
-                    } else {
-                        List<ProEconAlarmInfo> templs = new ArrayList<>();
-                        templs.add(vo);
-                        tempmap.put(vo.getTbname(), templs);
-                    }
-                }
-//删除,相同的报警
                 List<String> idls = new ArrayList<>();
-                for (Map.Entry<String, List<ProEconAlarmInfo>> entry : tempmap.entrySet()) {
-                    idls.add(entry.getKey());
+                for (ProEconAlarmInfo vo : valuels) {
+                    idls.add(vo.getTbname());
                 }
-
                 if (!idls.isEmpty()) {
 
                     proEconAlarmInfoService.removeByIds(idls);
                 }
 
-                List<ProEconAlarmInfo> pols = new ArrayList<>();
-//保存,取项目集合中的最后一个记录进行保存
-                for (Map.Entry<String, List<ProEconAlarmInfo>> entry : tempmap.entrySet()) {
-                    List<ProEconAlarmInfo> resultls = entry.getValue();
-                    if(!resultls.isEmpty())
-                    {
-                        Collections.sort(resultls, new Comparator<ProEconAlarmInfo>() {
-                            public int compare(ProEconAlarmInfo arg0, ProEconAlarmInfo arg1) {
-                                return arg0.getTs().compareTo(arg1.getTs());
-
-                            }
-                        });
-                        pols.add(resultls.get(resultls.size() - 1));
-                    }
-
-                }
 
                 List<ProEconAlarmInfo> templs = new ArrayList<>();
-                for (ProEconAlarmInfo vo : pols) {
+                for (ProEconAlarmInfo vo : valuels) {
                     templs.add(vo);
                     if (templs.size() == 100) {
                         proEconAlarmInfoService.saveBatch(templs);
@@ -386,4 +351,112 @@ public class AlarmCtService {
 
     }
 
+
+    public synchronized void updateAlarms(List<AlarmTag> ls) {
+
+        if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+            if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+                StringBuilder sb = new StringBuilder();
+                Map<String, AlarmSimpleVo> map = new HashMap<>();
+                for (AlarmTag alarm : ls) {
+                    sb.append("'").append(alarm.getId()).append("',");
+
+                }
+
+                String ids = sb.substring(0, sb.length() - 1);
+
+                List<AlarmSimpleVo> alarmls = alarmTsService.selectLastRowByTbname(AlarmSuperTalbeType.CT.getCode(), ids);
+                if (!alarmls.isEmpty()) {
+                    for (AlarmSimpleVo vo : alarmls) {
+                        map.put(vo.getTbName(), vo);
+                    }
+                }
+
+                for (AlarmTag alarm : ls) {
+                    if (map.containsKey(alarm.getId())) {
+                        AlarmSimpleVo tag = map.get(alarm.getId());
+                        tag.setTs(new Timestamp(alarm.getTs()));
+
+                        Date begin = new Date(alarm.getEndts());
+                        Date end = new Date(alarm.getTs());
+
+                        double value = DateUtils.hoursDiff(begin, end);
+
+                        tag.setTimelong(value);
+                    }
+
+                }
+
+                alarmTsService.insertList(ls);
+
+
+                if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+                    List<ProEconAlarmInfo> valuels = new ArrayList<>();
+                    for (AlarmTag alarm : ls) {
+                        if (CacheContext.alarmCtMap.containsKey(alarm.getId())) {
+                            AlarmVo vo = CacheContext.alarmCtMap.get(alarm.getId());
+                            ProEconAlarmInfo po = new ProEconAlarmInfo();
+                            po.setTbname(vo.getTbName());
+                            po.setLastUpdateTime(new Date(alarm.getTs()));
+                            po.setTagId(alarm.getTagId());
+                            po.setTriggerType(alarm.getTriggerType());
+                            po.setAlarmId(vo.getAlarmid());
+                            po.setDeviceId(vo.getDeviceid());
+                            po.setSubcomponents(vo.getSuffix());
+                            po.setRank(vo.getRank());
+                            po.setConfirmed(false);
+                            po.setUniformCode(vo.getUniformcode());
+                            po.setAlarmType(vo.getAlarmtype());
+                            po.setDeviceType(vo.getDevicetype());
+                            po.setConfirmed(vo.getConfirmed());
+                            po.setSubcomponents(vo.getSubcomponents());
+                            po.setDescription(vo.getDescription());
+                            po.setModelId(vo.getModelId());
+                            po.setResetTable(vo.getResettable());
+                            po.setEnable(vo.getEnabled());
+                            po.setCharacteristic(vo.getCharacteristic());
+                            po.setStationId(vo.getStationid());
+                            po.setProjectId(vo.getProjectid());
+                            po.setLineId(vo.getLineid());
+                            po.setStationName(vo.getStationname());
+                            po.setProjectiName(vo.getProjectname());
+                            po.setLineidName(vo.getLinename());
+                            po.setDeviceName(vo.getDevicename());
+                            po.setOval(alarm.getOval().intValue());
+
+                            po.setCloseTime(new Date(alarm.getEndts()));
+                            po.setIsOpen(0);
+                            valuels.add(po);
+                        }
+                    }
+                    List<String> idls = new ArrayList<>();
+                    for (ProEconAlarmInfo vo : valuels) {
+                        idls.add(vo.getTbname());
+                    }
+                    if (!idls.isEmpty()) {
+
+                        proEconAlarmInfoService.removeByIds(idls);
+                    }
+
+
+                    List<ProEconAlarmInfo> templs = new ArrayList<>();
+                    for (ProEconAlarmInfo vo : valuels) {
+                        templs.add(vo);
+                        if (templs.size() == 100) {
+                            proEconAlarmInfoService.saveBatch(templs);
+                            templs = new ArrayList<>();
+                        }
+                    }
+
+                    if (!templs.isEmpty()) {
+                        proEconAlarmInfoService.saveBatch(templs);
+                    }
+
+                }
+            }
+        }
+    }
 }

+ 129 - 80
alarm-service/src/main/java/com/gyee/alarm/service/AlarmWtService.java

@@ -2,18 +2,17 @@ package com.gyee.alarm.service;
 
 import com.gyee.alarm.init.CacheContext;
 import com.gyee.alarm.model.auto.*;
-import com.gyee.alarm.model.vo.AlarmSuperTalbeType;
-import com.gyee.alarm.model.vo.AlarmTag;
-import com.gyee.alarm.model.vo.AlarmVo;
-import com.gyee.alarm.model.vo.DeviceTypeValue;
+import com.gyee.alarm.model.vo.*;
 import com.gyee.alarm.service.auto.IAlarmTsService;
 import com.gyee.alarm.service.auto.IProEconAlarmInfoService;
+import com.gyee.alarm.util.DateUtils;
 import com.gyee.alarm.util.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.sql.SQLException;
+import java.sql.Timestamp;
 import java.util.*;
 
 @Service
@@ -68,6 +67,7 @@ public class AlarmWtService {
                 po.setTagId(vo.getTagid());
                 po.setOval(po.getVal());
                 po.setRank(vo.getRank());
+                po.setTimeLong(0.0);
                 po.setTs(new Date().getTime());
                 alarmTags.add(po);
             }
@@ -94,19 +94,20 @@ public class AlarmWtService {
 
                     if (!alarmls.isEmpty()) {
                         for (ProEconAlarmConfiguration alarm : alarmls) {
-                            if (pointMap.containsKey(alarm.getUniformCode())) {
-                                ProBasicEquipmentPoint equipmentPoint = pointMap.get(alarm.getUniformCode());
-
-                                if(StringUtils.notEmp(initialcode) &&
-                                        StringUtils.notEmp(equipmentPoint.getNemCode()) &&
-                                        !equipmentPoint.getNemCode().equals(initialcode))
-                                {
+//                            if (pointMap.containsKey(alarm.getUniformCode())) {
+//                                ProBasicEquipmentPoint equipmentPoint = pointMap.get(alarm.getUniformCode());
+//
+//                                if(StringUtils.notEmp(initialcode) &&
+//                                        StringUtils.notEmp(equipmentPoint.getNemCode()) &&
+//                                        !equipmentPoint.getNemCode().equals(initialcode))
+//                                {
                                     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(equipmentPoint.getNemCode());
+//                                    vo.setTagid(equipmentPoint.getNemCode());
+                            vo.setTagid(alarm.getTagId());
                                     vo.setAlarmtype(alarm.getAlarmType());
                                     vo.setCharacteristic(alarm.getCharacteristic());
                                     vo.setComponents(alarm.getComponents());
@@ -142,9 +143,9 @@ public class AlarmWtService {
                                     vo.setUniformcode(alarm.getUniformCode());
                                     vo.setSuperTableName(AlarmSuperTalbeType.WT.getCode());
                                     alarmVoList.add(vo);
-                                }
-
-                            }
+//                                }
+//
+//                            }
                         }
                     }
                 }
@@ -187,24 +188,20 @@ public class AlarmWtService {
     public synchronized void saveAlarms(List<AlarmTag> ls)
     {
 
-        if(StringUtils.notEmp(ls) && !ls.isEmpty())
-        {
+        if(StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
             alarmTsService.insertList(ls);
 
 
-            if(StringUtils.notEmp(ls) && !ls.isEmpty())
-            {
+            if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
-                List<ProEconAlarmInfo> valuels=new ArrayList<>();
-                for(AlarmTag alarm:ls)
-                {
-                    if(CacheContext.alarmWtMap.containsKey(alarm.getId()))
-                    {
-                        AlarmVo vo=CacheContext.alarmWtMap.get(alarm.getId());
-                        ProEconAlarmInfo po=new ProEconAlarmInfo();
+                List<ProEconAlarmInfo> valuels = new ArrayList<>();
+                for (AlarmTag alarm : ls) {
+                    if (CacheContext.alarmWtMap.containsKey(alarm.getId())) {
+                        AlarmVo vo = CacheContext.alarmWtMap.get(alarm.getId());
+                        ProEconAlarmInfo po = new ProEconAlarmInfo();
                         po.setTbname(vo.getTbName());
-                        po.setTs(alarm.getTs());
+                        po.setLastUpdateTime(new Date(alarm.getTs()));
                         po.setTagId(alarm.getTagId());
                         po.setTriggerType(alarm.getTriggerType());
                         po.setAlarmId(vo.getAlarmid());
@@ -230,76 +227,129 @@ public class AlarmWtService {
                         po.setLineidName(vo.getLinename());
                         po.setDeviceName(vo.getDevicename());
                         po.setOval(alarm.getOval().intValue());
-                        if(alarm.getVal()==1)
-                        {
-                            po.setIsOpen(1);
-                        }else if(alarm.getVal()==0)
-                        {
-                            po.setIsOpen(0);
-                        }
-
+                        po.setIsOpen(1);
                         valuels.add(po);
                     }
                 }
 
-//                List<ProEconAlarmInfo> templs=new ArrayList<>();
-//                for(ProEconAlarmInfo vo:valuels)
-//                {
-//                    templs.add(vo);
-//                    if(templs.size()==200)
-//                    {
-//                        proEconAlarmInfoService.saveOrUpdateBatch(templs);
-//                        templs=new ArrayList<>();
-//                    }
-//                }
-//
-//                if(!templs.isEmpty())
-//                {
-//                    proEconAlarmInfoService.saveOrUpdateBatch(templs);
-//                }
+                List<String> idls = new ArrayList<>();
+                for (ProEconAlarmInfo vo : valuels) {
+                    idls.add(vo.getTbname());
+                }
+                if (!idls.isEmpty()) {
+
+                    proEconAlarmInfoService.removeByIds(idls);
+                }
 
-//分类,相同的报警放在一个map中的list中
-                Map<String, List<ProEconAlarmInfo>> tempmap = new HashMap<>();
+
+                List<ProEconAlarmInfo> templs = new ArrayList<>();
                 for (ProEconAlarmInfo vo : valuels) {
-                    if (tempmap.containsKey(vo.getTbname())) {
-                        List<ProEconAlarmInfo> templs = tempmap.get(vo.getTbname());
-                        templs.add(vo);
-                    } else {
-                        List<ProEconAlarmInfo> templs = new ArrayList<>();
-                        templs.add(vo);
-                        tempmap.put(vo.getTbname(), templs);
+                    templs.add(vo);
+                    if (templs.size() == 100) {
+                        proEconAlarmInfoService.saveBatch(templs);
+                        templs = new ArrayList<>();
                     }
                 }
-//删除,相同的报警
-                List<String> idls = new ArrayList<>();
-                for (Map.Entry<String, List<ProEconAlarmInfo>> entry : tempmap.entrySet()) {
-                    idls.add(entry.getKey());
+
+                if (!templs.isEmpty()) {
+                    proEconAlarmInfoService.saveBatch(templs);
                 }
+            }
+        }
+    }
 
-                if (!idls.isEmpty()) {
 
-                    proEconAlarmInfoService.removeByIds(idls);
+    public synchronized void updateAlarms(List<AlarmTag> ls) {
+
+        if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+            StringBuilder sb=new StringBuilder();
+            Map<String, AlarmSimpleVo> map=new HashMap<>();
+            for (AlarmTag alarm : ls) {
+                sb.append("'").append(alarm.getId()).append("',");
+
+            }
+
+            String ids=sb.substring(0,sb.length()-1);
+
+            List<AlarmSimpleVo> alarmls=alarmTsService.selectLastRowByTbname(AlarmSuperTalbeType.WT.getCode(),ids);
+            if(!alarmls.isEmpty())
+            {
+                for(AlarmSimpleVo vo:alarmls)
+                {
+                    map.put(vo.getTbName(),vo);
+                }
+            }
+
+            for (AlarmTag alarm : ls) {
+                if(map.containsKey(alarm.getId()))
+                {
+                    AlarmSimpleVo tag=map.get(alarm.getId());
+                    tag.setTs(new Timestamp(alarm.getTs()));
+
+                    Date begin = new Date(alarm.getEndts());
+                    Date end = new Date(alarm.getTs());
+
+                    double value= DateUtils.hoursDiff(begin,end);
+                    tag.setTimelong(value);
                 }
 
-                List<ProEconAlarmInfo> pols = new ArrayList<>();
-//保存,取项目集合中的最后一个记录进行保存
-                for (Map.Entry<String, List<ProEconAlarmInfo>> entry : tempmap.entrySet()) {
-                    List<ProEconAlarmInfo> resultls = entry.getValue();
-                    if(!resultls.isEmpty())
-                    {
-                        Collections.sort(resultls, new Comparator<ProEconAlarmInfo>() {
-                            public int compare(ProEconAlarmInfo arg0, ProEconAlarmInfo arg1) {
-                                return arg0.getTs().compareTo(arg1.getTs());
-
-                            }
-                        });
-                        pols.add(resultls.get(resultls.size() - 1));
+            }
+
+            alarmTsService.insertList(ls);
+
+
+            if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+                List<ProEconAlarmInfo> valuels = new ArrayList<>();
+                for (AlarmTag alarm : ls) {
+                    if (CacheContext.alarmWtMap.containsKey(alarm.getId())) {
+                        AlarmVo vo = CacheContext.alarmWtMap.get(alarm.getId());
+                        ProEconAlarmInfo po = new ProEconAlarmInfo();
+                        po.setTbname(vo.getTbName());
+                        po.setLastUpdateTime(new Date(alarm.getEndts()));
+                        po.setTagId(alarm.getTagId());
+                        po.setTriggerType(alarm.getTriggerType());
+                        po.setAlarmId(vo.getAlarmid());
+                        po.setDeviceId(vo.getDeviceid());
+                        po.setSubcomponents(vo.getSuffix());
+                        po.setRank(vo.getRank());
+                        po.setConfirmed(false);
+                        po.setUniformCode(vo.getUniformcode());
+                        po.setAlarmType(vo.getAlarmtype());
+                        po.setDeviceType(vo.getDevicetype());
+                        po.setConfirmed(vo.getConfirmed());
+                        po.setSubcomponents(vo.getSubcomponents());
+                        po.setDescription(vo.getDescription());
+                        po.setModelId(vo.getModelId());
+                        po.setResetTable(vo.getResettable());
+                        po.setEnable(vo.getEnabled());
+                        po.setCharacteristic(vo.getCharacteristic());
+                        po.setStationId(vo.getStationid());
+                        po.setProjectId(vo.getProjectid());
+                        po.setLineId(vo.getLineid());
+                        po.setStationName(vo.getStationname());
+                        po.setProjectiName(vo.getProjectname());
+                        po.setLineidName(vo.getLinename());
+                        po.setDeviceName(vo.getDevicename());
+                        po.setOval(alarm.getOval().intValue());
+                        po.setCloseTime(new Date(alarm.getEndts()));
+                        po.setIsOpen(0);
+                        valuels.add(po);
                     }
+                }
 
+                List<String> idls = new ArrayList<>();
+                for (ProEconAlarmInfo vo : valuels) {
+                    idls.add(vo.getTbname());
+                }
+                if (!idls.isEmpty()) {
+
+                    proEconAlarmInfoService.removeByIds(idls);
                 }
 
                 List<ProEconAlarmInfo> templs = new ArrayList<>();
-                for (ProEconAlarmInfo vo : pols) {
+                for (ProEconAlarmInfo vo : valuels) {
                     templs.add(vo);
                     if (templs.size() == 100) {
                         proEconAlarmInfoService.saveBatch(templs);
@@ -315,5 +365,4 @@ public class AlarmWtService {
         }
 
     }
-
 }

+ 8 - 0
alarm-service/src/main/java/com/gyee/alarm/service/auto/IAlarmTsService.java

@@ -2,6 +2,7 @@ package com.gyee.alarm.service.auto;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.gyee.alarm.model.auto.AlarmTs;
+import com.gyee.alarm.model.vo.AlarmSimpleVo;
 import com.gyee.alarm.model.vo.AlarmTag;
 import com.gyee.alarm.model.vo.AlarmTsVo;
 import com.gyee.alarm.model.vo.AlarmVo;
@@ -54,5 +55,12 @@ public interface IAlarmTsService extends IService<AlarmTs> {
 
 
     public   List<AlarmVo> selectByTbName(String tbName,long limit,long offset);
+
+
+
+    public List<AlarmSimpleVo> selectLastRowByTbname(String superTableName, String tbnames);
+
+
+
 }
 

+ 17 - 5
alarm-service/src/main/java/com/gyee/alarm/service/auto/impl/AlarmTsServiceImpl.java

@@ -3,10 +3,7 @@ package com.gyee.alarm.service.auto.impl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.gyee.alarm.mapper.auto.AlarmTsMapper;
 import com.gyee.alarm.model.auto.AlarmTs;
-import com.gyee.alarm.model.vo.AlarmSuperTalbeType;
-import com.gyee.alarm.model.vo.AlarmTag;
-import com.gyee.alarm.model.vo.AlarmTsVo;
-import com.gyee.alarm.model.vo.AlarmVo;
+import com.gyee.alarm.model.vo.*;
 import com.gyee.alarm.service.auto.IAlarmTsService;
 import com.gyee.alarm.util.StringUtils;
 import org.springframework.stereotype.Service;
@@ -103,7 +100,8 @@ public class AlarmTsServiceImpl extends ServiceImpl<AlarmTsMapper, AlarmTs> impl
 
                 sub_sb.append( " values ");
                 sub_sb.append(" (");
-                sub_sb.append(tag.getTs()).append(",").append(tag.getVal().intValue()).append(",").append(tag.getOval().intValue()).append(",").append(false);
+                sub_sb.append(tag.getTs()).append(",").append(tag.getVal().intValue()).append(",").append(false).append(",")
+                        .append(tag.getEndts()).append(",").append(tag.getTimeLong());
                 sub_sb.append(" ) ");
                 i++;
                 if (i==100) {
@@ -123,6 +121,10 @@ public class AlarmTsServiceImpl extends ServiceImpl<AlarmTsMapper, AlarmTs> impl
 
     }
 
+
+
+
+
     public List<AlarmVo> findTags(String stbaleName)
     {
         List<AlarmVo> ls=new ArrayList<>();
@@ -156,4 +158,14 @@ public class AlarmTsServiceImpl extends ServiceImpl<AlarmTsMapper, AlarmTs> impl
 
         return ls;
     }
+
+    public List<AlarmSimpleVo> selectLastRowByTbname(String superTableName, String tbnames){
+        List<AlarmSimpleVo> ls=new ArrayList<>();
+        if(StringUtils.notEmp(superTableName) && StringUtils.notEmp(tbnames))
+        {
+            ls= alarmTsMapper.selectLastRowByTbname(superTableName, tbnames);
+        }
+
+        return ls;
+    }
 }

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

@@ -1,6 +1,6 @@
 
 server:
-  port: 6010
+  port: 6014
   servlet:
     context-path: /
 
@@ -134,8 +134,8 @@ logging:
 
 #db url
 db:
-  url1: http://10.81.3.154:8021/ts
-  url2: http://10.81.3.154:8022/ts
+  url1: http://10.81.3.154:8011/ts
+  url2: http://10.81.3.154:8012/ts
 
 
 #参与计算的场站

+ 7 - 7
alarm-service/src/test/java/com/gyee/AppTest.java

@@ -18,14 +18,14 @@ public class AppTest
         AlarmWtService alarmWtService= SpringUtils.getBean("alarmWtService");
         AlarmCtService alarmCtService= SpringUtils.getBean("alarmCtService");
 
-//        alarmBtService.createSuperTable();
-//        alarmBtService.initalBtAlarm();
-//
-//        alarmWtService.createSuperTable();
-//        alarmWtService.initalWtAlarm();
+        alarmBtService.createSuperTable();
+        alarmBtService.initalBtAlarm();
+
+        alarmWtService.createSuperTable();
+        alarmWtService.initalWtAlarm();
 
-        alarmCtService.createSuperTable();
-        alarmCtService.initalCtAlarm();
+//        alarmCtService.createSuperTable();
+//        alarmCtService.initalCtAlarm();
 
         System.out.println("完成!");