Browse Source

报警统计功能

shilin 1 year ago
parent
commit
2aa0884dcc
51 changed files with 4658 additions and 1242 deletions
  1. 53 0
      alarm-custom/src/main/java/com/gyee/alarm/model/vo/AlarmCustomType.java
  2. 4 3
      alarm-custom/src/main/java/com/gyee/alarm/model/vo/AlarmSuperTalbeType.java
  3. 2 0
      alarm-custom/src/main/java/com/gyee/alarm/model/vo/AlarmTypeValue.java
  4. 1 0
      alarm-custom/src/main/java/com/gyee/alarm/model/vo/DeviceTypeValue.java
  5. 8 1
      alarm-scanner/src/main/java/com/gyee/alarm/feigns/IAlarmService.java
  6. 53 0
      alarm-scanner/src/main/java/com/gyee/alarm/model/vo/AlarmCustomType.java
  7. 4 3
      alarm-scanner/src/main/java/com/gyee/alarm/model/vo/AlarmSuperTalbeType.java
  8. 2 0
      alarm-scanner/src/main/java/com/gyee/alarm/model/vo/AlarmTypeValue.java
  9. 54 0
      alarm-scanner/src/main/java/com/gyee/alarm/model/vo/DeviceTypeValue.java
  10. 4 2
      alarm-scanner/src/main/java/com/gyee/alarm/service/AlarmScannerService.java
  11. 0 2
      alarm-scanner/src/main/java/com/gyee/alarm/task/thread/AlarmThreadPool.java
  12. 189 0
      alarm-scanner/src/main/resources/application-in.yml
  13. 6 0
      alarm-service/pom.xml
  14. 27 3
      alarm-service/src/main/java/com/gyee/alarm/controller/AlarmController.java
  15. 68 0
      alarm-service/src/main/java/com/gyee/alarm/controller/WebSocketController.java
  16. 32 5
      alarm-service/src/main/java/com/gyee/alarm/init/CacheContext.java
  17. 1 1
      alarm-service/src/main/java/com/gyee/alarm/model/vo/AlarmCustomType.java
  18. 1 0
      alarm-service/src/main/java/com/gyee/alarm/model/vo/AlarmSimpleVo.java
  19. 1 0
      alarm-service/src/main/java/com/gyee/alarm/model/vo/AlarmSuperTalbeType.java
  20. 21 0
      alarm-service/src/main/java/com/gyee/alarm/model/vo/AlarmTag.java
  21. 2 1
      alarm-service/src/main/java/com/gyee/alarm/model/vo/AlarmTypeValue.java
  22. 1 0
      alarm-service/src/main/java/com/gyee/alarm/model/vo/DeviceTypeValue.java
  23. 51 8
      alarm-service/src/main/java/com/gyee/alarm/service/AlarmBtService.java
  24. 53 8
      alarm-service/src/main/java/com/gyee/alarm/service/AlarmCtService.java
  25. 467 0
      alarm-service/src/main/java/com/gyee/alarm/service/AlarmInService.java
  26. 106 55
      alarm-service/src/main/java/com/gyee/alarm/service/AlarmWtService.java
  27. 1 1
      alarm-service/src/main/java/com/gyee/alarm/service/auto/impl/AlarmTsServiceImpl.java
  28. 30 0
      alarm-service/src/main/java/com/gyee/alarm/websocket/PushParams.java
  29. 186 0
      alarm-service/src/main/java/com/gyee/alarm/websocket/WebSocket.java
  30. 21 0
      alarm-service/src/main/java/com/gyee/alarm/websocket/WebSocketConfig.java
  31. 38 0
      alarm-service/src/main/java/com/gyee/alarm/websocket/WebSocketCustomEncoding.java
  32. 87 0
      alarm-service/src/main/java/com/gyee/alarm/websocket/WebsocketSchedule.java
  33. 2 0
      alarm-service/src/main/resources/application-jn.yml
  34. 5 3
      alarm-web/src/main/java/com/gyee/alarm/controller/AlarmConfigurationController.java
  35. 33 13
      alarm-web/src/main/java/com/gyee/alarm/controller/AlarmHistoryController.java
  36. 13 8
      alarm-web/src/main/java/com/gyee/alarm/mapper/auto/AlarmTsMapper.java
  37. 4 2
      alarm-web/src/main/java/com/gyee/alarm/mapper/auto/ProEconAlarmConfigurationMapper.java
  38. 19 0
      alarm-web/src/main/java/com/gyee/alarm/model/vo/AlarmSimpleVo.java
  39. 1 1
      alarm-web/src/main/java/com/gyee/alarm/model/vo/AlarmStatVo.java
  40. 17 1
      alarm-web/src/main/java/com/gyee/alarm/model/vo/AlarmTag.java
  41. 58 0
      alarm-web/src/main/java/com/gyee/alarm/model/vo/AlarmTime.java
  42. 6 3
      alarm-web/src/main/java/com/gyee/alarm/service/AlarmConfigurationService.java
  43. 153 62
      alarm-web/src/main/java/com/gyee/alarm/service/AlarmHistoryService.java
  44. 3 0
      alarm-web/src/main/java/com/gyee/alarm/service/auto/IAlarmTsService.java
  45. 1 1
      alarm-web/src/main/java/com/gyee/alarm/service/auto/IProEconAlarmConfigurationService.java
  46. 25 21
      alarm-web/src/main/java/com/gyee/alarm/service/auto/impl/AlarmTsServiceImpl.java
  47. 2 2
      alarm-web/src/main/java/com/gyee/alarm/service/auto/impl/ProEconAlarmConfigurationServiceImpl.java
  48. 2742 1032
      log/ota.log
  49. BIN
      log/ota.log.2023-08-18.0.gz
  50. BIN
      log/ota.log.2023-08-28.0.gz
  51. BIN
      log/ota.log.2023-08-30.0.gz

+ 53 - 0
alarm-custom/src/main/java/com/gyee/alarm/model/vo/AlarmCustomType.java

@@ -0,0 +1,53 @@
+package com.gyee.alarm.model.vo;
+
+public enum AlarmCustomType {
+
+    WT("windturbine", "设备自定义报警"),
+    Bt("booststation", "升压站报警"),
+    IN("inverter", "逆变器报警");
+
+    private String code;
+    private String name;
+
+    AlarmCustomType(String code) {
+        this.code = code;
+    }
+
+    AlarmCustomType(String code, String name) {
+        this.code = code;
+        this.name = name;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 根据code获取message
+     *
+     * @param code
+     * @return
+     */
+    public static String getNmaeByCode(String code) {
+        for (AlarmCustomType ele : values()) {
+            if (ele.getCode().equals(code)) {
+                return ele.getName();
+            }
+        }
+        return null;
+    }
+
+
+}

+ 4 - 3
alarm-custom/src/main/java/com/gyee/alarm/model/vo/AlarmSuperTalbeType.java

@@ -2,9 +2,10 @@ package com.gyee.alarm.model.vo;
 
 public enum AlarmSuperTalbeType {
 
-    WT("wt_alarms", "设备报警超级表"),
-    BT("bt_alarms", "升压站报警超级表"),
-    CT("custom_alarms", "自定义报警超级表");
+    WT("alarmWt", "设备报警超级表"),
+
+    BT("alarmBt", "升压站报警超级表"),
+    CT("alarmCt", "自定义报警超级表");
 
     private String code;
     private String name;

+ 2 - 0
alarm-custom/src/main/java/com/gyee/alarm/model/vo/AlarmTypeValue.java

@@ -3,6 +3,8 @@ package com.gyee.alarm.model.vo;
 public enum AlarmTypeValue {
 
     BT("booststation", "升压站报警"),
+
+    IN("inverter", "逆变器报警"),
     WT("windturbine", "设备报警"),
     CT("custom", "自定义报警");
 

+ 1 - 0
alarm-custom/src/main/java/com/gyee/alarm/model/vo/DeviceTypeValue.java

@@ -3,6 +3,7 @@ package com.gyee.alarm.model.vo;
 public enum DeviceTypeValue {
 
     BT("booststation", "升压站报警"),
+    IN("inverter", "逆变器报警"),
     WP("station", "场站报警"),
     WT("windturbine", "风机报警");
 

+ 8 - 1
alarm-scanner/src/main/java/com/gyee/alarm/feigns/IAlarmService.java

@@ -16,7 +16,8 @@ public interface IAlarmService {
     @RequestLine("GET /api/alarm/btTags")
     List<AlarmTag> findTagsByBt();
 
-
+    @RequestLine("GET /api/alarm/inTags")
+    List<AlarmTag> findTagsByIn();
 
     @Headers({"Content-Type: application/json", "Accept: application/json"})
     @RequestLine("POST /api/alarm/saveWtTags")
@@ -24,8 +25,14 @@ public interface IAlarmService {
     @Headers({"Content-Type: application/json", "Accept: application/json"})
     @RequestLine("POST /api/alarm/saveBtTags")
     void saveBtTags(List<AlarmTag> tasks);
+    @Headers({"Content-Type: application/json", "Accept: application/json"})
+    @RequestLine("POST /api/alarm/saveInTags")
+    void saveInTags(List<AlarmTag> tasks);
 
     @Headers({"Content-Type: application/json", "Accept: application/json"})
+    @RequestLine("POST /api/alarm/updateInTags")
+    void updateInTags(List<AlarmTag> tasks);
+    @Headers({"Content-Type: application/json", "Accept: application/json"})
     @RequestLine("POST /api/alarm/updateWtTags")
     void updateWtTags(List<AlarmTag> tasks);
     @Headers({"Content-Type: application/json", "Accept: application/json"})

+ 53 - 0
alarm-scanner/src/main/java/com/gyee/alarm/model/vo/AlarmCustomType.java

@@ -0,0 +1,53 @@
+package com.gyee.alarm.model.vo;
+
+public enum AlarmCustomType {
+
+    WT("windturbine", "设备自定义报警"),
+    Bt("booststation", "升压站报警"),
+    IN("inverter", "逆变器报警");
+
+    private String code;
+    private String name;
+
+    AlarmCustomType(String code) {
+        this.code = code;
+    }
+
+    AlarmCustomType(String code, String name) {
+        this.code = code;
+        this.name = name;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 根据code获取message
+     *
+     * @param code
+     * @return
+     */
+    public static String getNmaeByCode(String code) {
+        for (AlarmCustomType ele : values()) {
+            if (ele.getCode().equals(code)) {
+                return ele.getName();
+            }
+        }
+        return null;
+    }
+
+
+}

+ 4 - 3
alarm-scanner/src/main/java/com/gyee/alarm/model/vo/AlarmSuperTalbeType.java

@@ -2,9 +2,10 @@ package com.gyee.alarm.model.vo;
 
 public enum AlarmSuperTalbeType {
 
-    WT("wt_alarms", "设备报警超级表"),
-    BT("bt_alarms", "升压站报警超级表"),
-    CT("custom_alarms", "自定义报警超级表");
+    WT("alarmWt", "设备报警超级表"),
+
+    BT("alarmBt", "升压站报警超级表"),
+    CT("alarmCt", "自定义报警超级表");
 
     private String code;
     private String name;

+ 2 - 0
alarm-scanner/src/main/java/com/gyee/alarm/model/vo/AlarmTypeValue.java

@@ -3,6 +3,8 @@ package com.gyee.alarm.model.vo;
 public enum AlarmTypeValue {
 
     BT("booststation", "升压站报警"),
+
+    IN("inverter", "逆变器报警"),
     WT("windturbine", "设备报警"),
     CT("custom", "自定义报警");
 

+ 54 - 0
alarm-scanner/src/main/java/com/gyee/alarm/model/vo/DeviceTypeValue.java

@@ -0,0 +1,54 @@
+package com.gyee.alarm.model.vo;
+
+public enum DeviceTypeValue {
+
+    BT("booststation", "升压站报警"),
+    IN("inverter", "逆变器报警"),
+    WP("station", "场站报警"),
+    WT("windturbine", "风机报警");
+
+    private String code;
+    private String name;
+
+    DeviceTypeValue(String code) {
+        this.code = code;
+    }
+
+    DeviceTypeValue(String code, String name) {
+        this.code = code;
+        this.name = name;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 根据code获取message
+     *
+     * @param code
+     * @return
+     */
+    public static String getNmaeByCode(String code) {
+        for (DeviceTypeValue ele : values()) {
+            if (ele.getCode().equals(code)) {
+                return ele.getName();
+            }
+        }
+        return null;
+    }
+
+
+}

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

@@ -46,7 +46,7 @@ public class AlarmScannerService {
     public void init() {
 //#WT("wt_alarms", "设备报警超级表"),
 //#BT("bt_alarms", "升压站报警超级表"),
-
+//#IN("in_alarms", "逆变器报警超级表"),
         switch (alarmType){
             case "wt_alarms":
                 alarmTags =alarmService.findTagsByWt();
@@ -54,7 +54,9 @@ public class AlarmScannerService {
             case "bt_alarms":
                 alarmTags =alarmService.findTagsByBt();
                 break;
-
+            case "in_alarms":
+                alarmTags =alarmService.findTagsByIn();
+                break;
         }
     }
 

+ 0 - 2
alarm-scanner/src/main/java/com/gyee/alarm/task/thread/AlarmThreadPool.java

@@ -183,6 +183,4 @@ public class AlarmThreadPool implements Callable<String>, Serializable {
 
 	}
 
-
-
 }

+ 189 - 0
alarm-scanner/src/main/resources/application-in.yml

@@ -0,0 +1,189 @@
+
+server:
+  port: 6013
+  servlet:
+    context-path: /
+
+
+spring:
+  main:
+    allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册
+  #redis集群
+  redis:
+    #host: 127.0.0.1
+    host: 10.81.3.155
+    port: 6379
+    timeout: 100000
+    #    集群环境打开下面注释,单机不需要打开
+    #    cluster:
+    #      #集群信息
+    #      nodes: 10.83.68.151:6379,10.83.68.152:6379,10.83.68.153:6379,10.83.68.154:6379,10.83.68.155:6379,10.83.68.156:6379,10.83.68.157:6379,10.83.68.158:6379,10.83.68.159:6379
+    #      #默认值是5 一般当此值设置过大时,容易报:Too many Cluster redirections
+    #      maxRedirects: 3
+    password:
+    application:
+      name: test
+    jedis:
+      pool:
+        max-active: 8
+        min-idle: 0
+        max-idle: 8
+        max-wait: -1
+    database: 9
+  autoconfigure:
+    exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
+  datasource:
+    #type: com.alibaba.druid.pool.DruidDataSource
+    type: com.alibaba.druid.pool.DruidDataSource
+    dynamic:
+      primary: master #设置默认的数据源或者数据源组,默认值即为master
+      strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
+      datasource:
+        master:
+          url: jdbc:postgresql://10.81.3.151:5432/IMS_NEM_JN
+          username: postgres
+          password: gd123
+          driver-class-name: org.postgresql.Driver
+        slave:
+          driver-class-name: com.taosdata.jdbc.TSDBDriver
+          url: jdbc:TAOS://10.81.3.154:6030/nemjn?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8
+          username: root
+          password: taosdata
+        #配置初始化连接数大小
+      initial-size: 10
+      # 最大连接数
+      max-active: 50
+      #最小连接数
+      min-idle: 10
+      #获取连接等待超时时间
+      max-wait: 5000
+      pool-prepared-statements: true #是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭。
+      max-pool-prepared-statement-per-connection-size: 20
+      validation-query: SELECT 1 FROM DUAL
+      validation-query-timeout: 20000
+      test-on-borrow: false #申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。
+      test-on-return: false #归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。
+      test-while-idle: true #建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
+      time-between-eviction-runs-millis: 60000 #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
+      min-evictable-idle-time-millis: 300000  #一个连接在池中最小生存的时间,单位是毫秒
+      #StatViewServlet配置。(因为暴露的监控信息比较敏感,支持密码加密和访问ip限定)
+      stat-view-servlet:
+        enabled: true
+        url-pattern: /druid/*
+        #可以增加访问账号密码【去掉注释就可以】
+        #login-username: admin
+        #login-password: admin
+      filter:
+        stat:
+          log-slow-sql: true
+          slow-sql-millis: 1000
+          merge-sql: false
+        wall:
+          config:
+            multi-statement-allow: true
+  servlet:
+    multipart:
+      # 开启 multipart 上传功能
+      enabled: true
+      # 文件写入磁盘的阈值
+      file-size-threshold: 2KB
+      # 最大文件大小
+      max-file-size: 200MB
+      # 最大请求大小
+      max-request-size: 215MB
+
+mybatis-plus:
+  configuration:
+    map-underscore-to-camel-case: true
+    auto-mapping-behavior: full
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+  mapper-locations: classpath*:mapper/**/*Mapper.xml
+  global-config:
+    # 逻辑删除配置
+    db-config:
+      id-type: auto
+      # 删除前
+      logic-not-delete-value: 1
+      # 删除后
+      logic-delete-value: 0
+# 日志配置
+logging:
+  level:
+    root: info
+  charset:
+    # 输出控制台编码
+    console: UTF-8
+    # 输出文件编码
+    file: UTF-8
+  # 输出文件名及路径,不配置则不输出文件
+  file:
+    # 切记,该文件表示正在产出日志的日志文件。并不会打包,当文件大于max-file-size,会根据file-name-pattern格式打包
+    # 名称为log/ota.log文件夹会在项目根目录下,打包后会在启动包同目录下;名称为/log/ota.log的文件夹会在项目所在磁盘的跟目录下
+    name: log/ota.log
+  logback:
+    rollingpolicy:
+      # 单文件的大小,默认10M, 超过之后打包成一个日志文件
+      max-file-size: 1MB
+      # 日志保存的天数
+      max-history: 30
+      # 打包文件格式,默认: ${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz,书写格式为:文件路径/文件名.%i.文件后缀,其中%i不可省去,否则无日志显示
+      # 例如: 日期为:2021/11/5 ,则打包文件之后为: log/ota.2021-11-05.0.gz,0表示日志的第一部分,后续就是,1,2,3...
+      # 如果是压缩包,里面会多一个名log/ota.2021-11-05.0的日志文件
+      # 如下面的例子,打包之后为: log/2021-11/ota.2020-11-5.0.log,这是一个日志文件
+      file-name-pattern: log/%d{yyyy-MM}/ota.%d{yyyy-MM-dd}.%i.log
+
+#db url
+db:
+  url1: http://10.81.3.154:8011/ts
+  url2: http://10.81.3.154:8012/ts
+
+
+#参与计算的场站
+#runWindpowerstation: SXJ_KGDL_GJY_FDC_STA
+runWindpowerstation: SXJ_KGDL_NJL_FDC_STA,SXJ_KGDL_YF_FDC_STA,SXJ_KGDL_YLZ_FDC_STA,SXJ_KGDL_XWT_FDC_STA,SXJ_KGDL_PTZ_FDC_STA,SXJ_KGDL_GJY_FDC_STA,SXJ_KGDL_BHB_FDC_STA,SXJ_KGDL_HSM_FDC_STA,SXJ_KGDL_YTY_FDC_STA,SXJ_KGDL_BHB3_FDC_STA,SXJ_KGDL_SY_GDC_STA,SXJ_KGDL_PDL_FDC_STA,SXJ_KGDL_ZK_FDC_STA,SXJ_KGDL_JR_GDC_STA,SXJ_KGDL_FS_GDC_STA,SXJ_KGDL_HR_GDC_STA,SXJ_KGDL_YY_GDC_STA,SXJ_KGDL_PL_GDC_STA,SXJ_KGDL_TL_GDC_STA
+#计算状态用ai或者di
+clauStatus:
+  ai: GJY03_GC,YLZ01_GC,PTZ02_GC   #配置期次
+  di: GJY01_GC,GJY02_GC,DJY01_GC,DJY02_GC,YF01_GC,YF02_GC,HSM01_GC,PTZ01_GC,ZK01_GC,NJL01_GC,YTY01_GC,PDL01_GC
+#判断数据终端
+second: 1800
+#判断降出力
+AI110: 17.4    #叶轮转速给定
+AI178: 17.4    #转矩给定
+#AI443:容量
+
+#功率曲线拟合
+curvefitting:
+  #维度
+  dimension: 20
+  #尺度
+  scale: 0.01
+initialcode: INITIAL
+##调用区间间隔时长,需要与XXLJOB调度时长结合,保证查询区间时长大于调度时长,单位分钟
+frequency:
+  #停机
+  shutdown: 1
+  #限电
+  powerrationing: 1
+  #切入切出
+  cutinandout: 1
+urls:
+  alarm-service: http://127.0.0.1:6014
+
+#分隔10个线程
+task-count: 10
+#任务休眠间隔
+interval: 1
+
+#WT("wt_alarms", "设备报警超级表"),
+#BT("bt_alarms", "升压站报警超级表"),
+#CT("custom_alarms", "自定义报警超级表");
+alarmType: wt_alarms
+read-rows: 1000
+
+
+
+
+
+
+

+ 6 - 0
alarm-service/pom.xml

@@ -66,6 +66,12 @@
             <artifactId>spring-boot-autoconfigure</artifactId>
             <version>${springframework.boot.version}</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-websocket</artifactId>
+            <version>${springframework.boot.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>

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

@@ -6,10 +6,13 @@ import com.gyee.alarm.model.vo.AlarmSuperTalbeType;
 import com.gyee.alarm.model.vo.AlarmTag;
 import com.gyee.alarm.service.AlarmBtService;
 import com.gyee.alarm.service.AlarmCtService;
+import com.gyee.alarm.service.AlarmInService;
 import com.gyee.alarm.service.AlarmWtService;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import javax.websocket.EncodeException;
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -34,6 +37,9 @@ public class AlarmController {
     @Resource
     private AlarmCtService alarmCtService;
 
+    @Resource
+    private AlarmInService alarmInService;
+
     @GetMapping("/wtTags")
     public List<AlarmTag> findTagsByWt()
 
@@ -50,6 +56,14 @@ public class AlarmController {
         return ls;
     }
 
+    @GetMapping("/inTags")
+    public List<AlarmTag> findTagsByIn()
+
+    {
+        List<AlarmTag> ls = alarmInService.findTags(AlarmSuperTalbeType.WT.getCode());
+        return ls;
+    }
+
     @GetMapping("/ctTags")
     public List<AlarmCustomTag> findTagsByCt()
 
@@ -59,20 +73,30 @@ public class AlarmController {
     }
 
     @PostMapping("/saveWtTags")
-    public void saveWtTags(@RequestBody List<AlarmTag> alarms ) {
+    public void saveWtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException {
          alarmWtService.saveAlarms(alarms);
     }
 
     @PostMapping("/saveBtTags")
-    public void saveBtTags(@RequestBody List<AlarmTag> alarms ) {
+    public void saveBtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException {
         alarmBtService.saveAlarms(alarms);
     }
 
     @PostMapping("/saveCtTags")
-    public void saveCtTags(@RequestBody List<AlarmTag> alarms ) {
+    public void saveCtTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException {
         alarmCtService.saveAlarms(alarms);
     }
 
+    @PostMapping("/saveInTags")
+    public void saveInTags(@RequestBody List<AlarmTag> alarms ) throws EncodeException, IOException {
+        alarmInService.saveAlarms(alarms);
+    }
+
+    @PostMapping("/updateInTags")
+    public void updateInTags(@RequestBody List<AlarmTag> alarms ) {
+        alarmInService.updateAlarms(alarms);
+    }
+
     @PostMapping("/updateWtTags")
     public void updateWtTags(@RequestBody List<AlarmTag> alarms ) {
         alarmWtService.updateAlarms(alarms);

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

@@ -0,0 +1,68 @@
+package com.gyee.alarm.controller;
+
+
+import com.gyee.alarm.websocket.PushParams;
+import com.gyee.alarm.websocket.WebSocket;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import javax.websocket.EncodeException;
+import java.io.IOException;
+
+/**
+ * 功能描述:
+ * 建立WebSocket连接
+ * @Author: LXD
+ * @Date: 2022-12-01 09:55:00
+ * @since: 1.0.0
+ */
+@RestController
+@RequestMapping("/webSocketPush")
+public class WebSocketController {
+    @Autowired
+    private WebSocket webSocket;
+
+
+    @RequestMapping("/sentMessage")
+    public void sentMessage(String userId,String message){
+        try {
+            webSocket.sendMessageByUserId(userId,message);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    @RequestMapping("/sentObjectMessage")
+    public void sentObjectMessage(String userId){
+        try {
+            webSocket.sendMessageByUserId(userId,"111111");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    /***
+     * 功能描述:
+     * 根据用户ID更新ws推送的参数
+     * @Author: LXD
+     * @Date: 2022-12-01 09:21:25
+     * @Param  userId: WS中的用户ID
+     * @Param pushParams: 推送参数
+     * @return: void
+     * @since: 1.0.0
+     */
+    @RequestMapping("/changeWsParams")
+    public void changeWsParams(String userId, PushParams pushParams){
+        try {
+            webSocket.changeParamsByUserId(userId,pushParams);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (EncodeException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+}

+ 32 - 5
alarm-service/src/main/java/com/gyee/alarm/init/CacheContext.java

@@ -9,6 +9,7 @@ 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.AlarmInService;
 import com.gyee.alarm.service.AlarmWtService;
 import com.gyee.common.model.StringUtils;
 import com.gyee.alarm.model.auto.*;
@@ -92,6 +93,8 @@ public class CacheContext implements CommandLineRunner {
     @Resource
     private AlarmWtService alarmWtService;
     @Resource
+    private AlarmInService alarmInService;
+    @Resource
     private AlarmBtService alarmBtService;
     @Resource
     private IProEconAlarmRuleService proEconAlarmRuleService;
@@ -183,6 +186,10 @@ public class CacheContext implements CommandLineRunner {
     public static List<AlarmVo> alarmWtList=new ArrayList<>();
     public static Map<String,AlarmVo> alarmWtMap=new HashMap<>();
 
+
+    public static List<AlarmVo> alarmInList=new ArrayList<>();
+    public static Map<String,AlarmVo> alarmInMap=new HashMap<>();
+
     public static List<AlarmVo> alarmBtList=new ArrayList<>();
     public static Map<String,AlarmVo> alarmBtMap=new HashMap<>();
 
@@ -590,7 +597,7 @@ public class CacheContext implements CommandLineRunner {
         List<ProEconAlarmRule> customls =proEconAlarmRuleService.list().stream().filter(i -> i.getEnable()).collect(Collectors.toList());
 
         List<ProEconAlarmRule> wtCustomls=new ArrayList<>();
-        List<ProEconAlarmRule> wpCustomls=new ArrayList<>();
+        List<ProEconAlarmRule> inCustomls=new ArrayList<>();
         List<ProEconAlarmRule> btCustomls=new ArrayList<>();
         if(!customls.isEmpty())
         {
@@ -599,19 +606,19 @@ public class CacheContext implements CommandLineRunner {
                 if(vo.getCategory().equals(AlarmCustomType.WT.getCode()))
                 {
                     wtCustomls.add(vo);
-                }else  if(vo.getCategory().equals(AlarmCustomType.WP.getCode()))
+                }else  if(vo.getCategory().equals(AlarmCustomType.IN.getCode()))
                 {
-                    wpCustomls.add(vo);
+                    inCustomls.add(vo);
                 }else  if(vo.getCategory().equals(AlarmCustomType.Bt.getCode()))
                 {
-                    wpCustomls.add(vo);
+                    btCustomls.add(vo);
                 }
 
             }
         }
         alarmRulesMap.put(AlarmCustomType.Bt.getCode(),btCustomls);
         alarmRulesMap.put(AlarmCustomType.WT.getCode(),wtCustomls);
-//        alarmRulesMap.put(AlarmCustomType.WP.getCode(),wpCustomls);
+        alarmRulesMap.put(AlarmCustomType.IN.getCode(),inCustomls);
 
 
         List<ProEconAlarmConfiguration> templs = proEconAlarmConfigurationService.list().stream().filter(i -> i.getEnable()).collect(Collectors.toList());
@@ -639,6 +646,26 @@ public class CacheContext implements CommandLineRunner {
             }
         }
 
+        //风机报警初始化标签
+        alarmWtList=alarmWtService.initalAlarmVo();
+        if(!alarmWtList.isEmpty())
+        {
+            for(AlarmVo vo: alarmWtList)
+            {
+                alarmWtMap.put(vo.getTbName(),vo);
+            }
+        }
+        //逆变器报警初始化标签
+        alarmInList=alarmInService.initalAlarmVo();
+        if(!alarmInList.isEmpty())
+        {
+            for(AlarmVo vo: alarmInList)
+            {
+                alarmInMap.put(vo.getTbName(),vo);
+            }
+        }
+
+
         //设备报警初始化标签
         alarmWtList=alarmWtService.initalAlarmVo();
         if(!alarmWtList.isEmpty())

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

@@ -4,7 +4,7 @@ public enum AlarmCustomType {
 
     WT("windturbine", "设备自定义报警"),
     Bt("booststation", "升压站报警"),
-    WP("station", "场站自定义报警");
+    IN("inverter", "逆变器报警");
 
     private String code;
     private String name;

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

@@ -12,6 +12,7 @@ public class AlarmSimpleVo {
     private Timestamp ts;
     private Integer val;
     private Integer oval;
+    private  Boolean confirmed;
     private Timestamp endts;
     private Double timelong;
 

+ 1 - 0
alarm-service/src/main/java/com/gyee/alarm/model/vo/AlarmSuperTalbeType.java

@@ -3,6 +3,7 @@ package com.gyee.alarm.model.vo;
 public enum AlarmSuperTalbeType {
 
     WT("alarmWt", "设备报警超级表"),
+
     BT("alarmBt", "升压站报警超级表"),
     CT("alarmCt", "自定义报警超级表");
 

+ 21 - 0
alarm-service/src/main/java/com/gyee/alarm/model/vo/AlarmTag.java

@@ -3,6 +3,8 @@ package com.gyee.alarm.model.vo;
 import com.gyee.common.model.PointData;
 import lombok.Data;
 
+import java.sql.Timestamp;
+
 @Data
 public class AlarmTag {
 
@@ -49,6 +51,25 @@ public class AlarmTag {
      * 报警时长
      */
     private Double timeLong;
+    /**
+     * 报警描述
+     */
+    private String description;
+
+
+    private  Boolean confirmed;
+
+    private String superTalbe;
+
+    /**
+     * 报警类型 /自定义报警 custom,风机 windturbine,场站 station,升压站 booststation
+     */
+    private String alarmType;
+
+    /**
+     * 设备类型,场站 station,风机 windturbine,升压站 booststation
+     */
+    private String deviceType;
 
     /**
      * 更新并检测是否触发报警

+ 2 - 1
alarm-service/src/main/java/com/gyee/alarm/model/vo/AlarmTypeValue.java

@@ -4,7 +4,8 @@ public enum AlarmTypeValue {
 
     BT("booststation", "升压站报警"),
 
-    WP("station", "场站报警"),
+    BTE("booststationevent", "升压站报警事件"),
+    IN("inverter", "逆变器报警"),
     WT("windturbine", "设备报警"),
     CT("custom", "自定义报警");
 

+ 1 - 0
alarm-service/src/main/java/com/gyee/alarm/model/vo/DeviceTypeValue.java

@@ -3,6 +3,7 @@ package com.gyee.alarm.model.vo;
 public enum DeviceTypeValue {
 
     BT("booststation", "升压站报警"),
+    IN("inverter", "逆变器报警"),
     WP("station", "场站报警"),
     WT("windturbine", "风机报警");
 

+ 51 - 8
alarm-service/src/main/java/com/gyee/alarm/service/AlarmBtService.java

@@ -7,13 +7,18 @@ 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 com.gyee.alarm.websocket.PushParams;
+import com.gyee.alarm.websocket.WebSocket;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import javax.websocket.EncodeException;
+import java.io.IOException;
 import java.sql.SQLException;
 import java.sql.Timestamp;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 
 @Service
 
@@ -24,7 +29,11 @@ public class AlarmBtService {
     private IProEconAlarmInfoService proEconAlarmInfoService;
     @Value("${initialcode}")
     private String initialcode;
+    @Value("${pushinterval}")
+    private Double pushinterval;
 
+    @Resource
+    private WebSocket webSocket;
     public void dropSuperTable() {
         alarmTsService.dropSuperTable(AlarmSuperTalbeType.BT.getCode());
     }
@@ -83,9 +92,8 @@ public class AlarmBtService {
         List<AlarmVo> alarmVoList = new ArrayList<>();
         if (!btalarmls.isEmpty()) {
             for (ProEconAlarmConfiguration alarm : btalarmls) {
-                if (StringUtils.notEmp(initialcode) &&
-                        StringUtils.notEmp(alarm.getTagId()) &&
-                        !alarm.getTagId().equals(initialcode)) {
+                if (StringUtils.notEmp(alarm.getTagId()) &&
+                        (alarm.getAlarmType().equals(AlarmTypeValue.BT.getCode()) || alarm.getAlarmType().equals(AlarmTypeValue.BTE.getCode()))) {
                     AlarmVo vo = new AlarmVo();
                     StringBuilder tbName = new StringBuilder();
                     tbName.append(alarm.getStationId()).append("_").append(alarm.getId());
@@ -152,7 +160,7 @@ public class AlarmBtService {
     }
 
 
-    public synchronized void saveAlarms(List<AlarmTag> ls) {
+    public synchronized void saveAlarms(List<AlarmTag> ls) throws EncodeException, IOException {
 
         if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
@@ -196,6 +204,11 @@ public class AlarmBtService {
                         po.setOval(alarm.getOval().intValue());
                         po.setVal(alarm.getVal().intValue());
                         po.setIsOpen(1);
+
+                        alarm.setDescription(vo.getDescription());
+                        alarm.setAlarmType(vo.getAlarmtype());
+                        alarm.setDeviceType(vo.getDevicetype());
+                        pushData(alarm);
                         valuels.add(po);
                     }
                 }
@@ -260,15 +273,16 @@ public class AlarmBtService {
                 if(map.containsKey(alarm.getId()))
                 {
                     AlarmSimpleVo tag=map.get(alarm.getId());
-                    tag.setTs(new Timestamp(alarm.getTs()));
+                    alarm.setTs(tag.getTs().getTime());
 
                     Date begin = new Date(alarm.getEndts());
                     Date end = new Date(alarm.getTs());
 
-                    double value= DateUtils.hoursDiff(begin,end);
-                    tag.setTimelong(value);
+                    double value= DateUtils.secondsDiff(begin,end);
+                    alarm.setTimeLong(value);
+                    alarm.setConfirmed(tag.getConfirmed());
+                    alarm.setSuperTalbe(AlarmSuperTalbeType.BT.getCode());
                 }
-
             }
 
             alarmTsService.insertList(ls);
@@ -356,4 +370,33 @@ public class AlarmBtService {
 
     }
 
+    public void pushData(AlarmTag po) throws EncodeException, IOException {
+        ConcurrentHashMap<String, WebSocket> webSocketPushMap = WebSocket.webSocketMap;
+        ConcurrentHashMap<String, PushParams> webSocketPushParamsMap = WebSocket.webSocketParamsMap;
+        if(!webSocketPushMap.isEmpty()){
+            for(String key : webSocketPushMap.keySet()){
+                // 根据ws连接用户ID获取推送参数
+                PushParams pushParams = webSocketPushParamsMap.get(key);
+
+                if(webSocketPushParamsMap.contains(po.getId()))
+                {
+                    PushParams pp=webSocketPushParamsMap.get(po.getId());
+
+                    double hours=DateUtils.hoursDiff(pp.getStartTime(),new Date());
+                    if(hours>pushinterval)
+                    {
+                        webSocket.sendMessageByUserId(key,po);
+                        pp.setStartTime(new Date(po.getTs()));
+                    }
+                }else
+                {
+                    webSocket.sendMessageByUserId(key,po);
+                    PushParams pp=new PushParams();
+                    pp.setStartTime(new Date());
+                    webSocketPushParamsMap.put(po.getId(),pp);
+                }
+            }
+        }
+
+    }
 }

+ 53 - 8
alarm-service/src/main/java/com/gyee/alarm/service/AlarmCtService.java

@@ -8,13 +8,18 @@ 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 com.gyee.alarm.websocket.PushParams;
+import com.gyee.alarm.websocket.WebSocket;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import javax.websocket.EncodeException;
+import java.io.IOException;
 import java.sql.SQLException;
 import java.sql.Timestamp;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 
 @Service
 
@@ -27,6 +32,10 @@ public class AlarmCtService {
     @Value("${initialcode}")
     private String initialcode;
 
+    @Value("${pushinterval}")
+    private Double pushinterval;
+    @Resource
+    private WebSocket webSocket;
     public void dropSuperTable() {
         alarmTsService.dropSuperTable(AlarmSuperTalbeType.CT.getCode());
     }
@@ -319,7 +328,7 @@ public class AlarmCtService {
     }
 
 
-    public synchronized void saveAlarms(List<AlarmTag> ls) {
+    public synchronized void saveAlarms(List<AlarmTag> ls) throws EncodeException, IOException {
 
         if (StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
@@ -363,6 +372,11 @@ public class AlarmCtService {
 
                         po.setVal(alarm.getVal().intValue());
                         po.setIsOpen(1);
+
+                        alarm.setDescription(vo.getDescription());
+                        alarm.setAlarmType(vo.getAlarmtype());
+                        alarm.setDeviceType(vo.getDevicetype());
+                        pushData(alarm);
                         valuels.add(po);
                     }
                 }
@@ -418,18 +432,19 @@ public class AlarmCtService {
                 }
 
                 for (AlarmTag alarm : ls) {
-                    if (map.containsKey(alarm.getId())) {
-                        AlarmSimpleVo tag = map.get(alarm.getId());
-                        tag.setTs(new Timestamp(alarm.getTs()));
+                    if(map.containsKey(alarm.getId()))
+                    {
+                        AlarmSimpleVo tag=map.get(alarm.getId());
+                        alarm.setTs(tag.getTs().getTime());
 
                         Date begin = new Date(alarm.getEndts());
                         Date end = new Date(alarm.getTs());
 
-                        double value = DateUtils.hoursDiff(begin, end);
-
-                        tag.setTimelong(value);
+                        double value= DateUtils.secondsDiff(begin,end);
+                        alarm.setTimeLong(value);
+                        alarm.setConfirmed(tag.getConfirmed());
+                        alarm.setSuperTalbe(AlarmSuperTalbeType.CT.getCode());
                     }
-
                 }
 
                 alarmTsService.insertList(ls);
@@ -503,4 +518,34 @@ public class AlarmCtService {
             }
         }
     }
+
+    public void pushData(AlarmTag po) throws EncodeException, IOException {
+        ConcurrentHashMap<String, WebSocket> webSocketPushMap = WebSocket.webSocketMap;
+        ConcurrentHashMap<String, PushParams> webSocketPushParamsMap = WebSocket.webSocketParamsMap;
+        if(!webSocketPushMap.isEmpty()){
+            for(String key : webSocketPushMap.keySet()){
+                // 根据ws连接用户ID获取推送参数
+                PushParams pushParams = webSocketPushParamsMap.get(key);
+
+                if(webSocketPushParamsMap.contains(po.getId()))
+                {
+                    PushParams pp=webSocketPushParamsMap.get(po.getId());
+
+                    double hours=DateUtils.hoursDiff(pp.getStartTime(),new Date());
+                    if(hours>pushinterval)
+                    {
+                        webSocket.sendMessageByUserId(key,po);
+                        pp.setStartTime(new Date(po.getTs()));
+                    }
+                }else
+                {
+                    webSocket.sendMessageByUserId(key,po);
+                    PushParams pp=new PushParams();
+                    pp.setStartTime(new Date());
+                    webSocketPushParamsMap.put(po.getId(),pp);
+                }
+            }
+        }
+
+    }
 }

+ 467 - 0
alarm-service/src/main/java/com/gyee/alarm/service/AlarmInService.java

@@ -0,0 +1,467 @@
+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.service.auto.IAlarmTsService;
+import com.gyee.alarm.service.auto.IProEconAlarmInfoService;
+import com.gyee.alarm.util.DateUtils;
+import com.gyee.alarm.util.StringUtils;
+import com.gyee.alarm.websocket.PushParams;
+import com.gyee.alarm.websocket.WebSocket;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import javax.websocket.EncodeException;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+@Service
+
+public class AlarmInService {
+    @Resource
+    private IAlarmTsService alarmTsService;
+    @Resource
+    private IProEconAlarmInfoService proEconAlarmInfoService;
+    @Value("${initialcode}")
+    private String initialcode;
+    @Value("${pushinterval}")
+    private Double pushinterval;
+    @Resource
+    private WebSocket webSocket;
+    public void dropSuperTable()
+    {
+        alarmTsService.dropSuperTable(AlarmSuperTalbeType.WT.getCode());
+    }
+    public void createSuperTable()
+    {
+
+        alarmTsService.createSuperTable(AlarmSuperTalbeType.WT.getCode());
+    }
+
+    public void initalWtAlarm() throws SQLException {
+
+
+
+        List<AlarmVo> alarmVoList=CacheContext.alarmWtList;
+        List<AlarmTag>  alarmTags=new ArrayList<>();
+
+
+        if(!alarmVoList.isEmpty())
+        {
+            for(AlarmVo vo: alarmVoList)
+            {
+
+
+                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());
+
+                AlarmTag po=new AlarmTag();
+                po.setId(vo.getTbName());
+                po.setVal(0.0);
+                po.setTriggerType(vo.getTriggertype());
+                po.setTagId(vo.getTagid());
+                po.setOval(0.0);
+                po.setRank(vo.getRank());
+                po.setTimeLong(0.0);
+                po.setTs(new Date().getTime());
+                alarmTags.add(po);
+            }
+        }
+
+
+        alarmTsService.insertList(alarmTags);
+    }
+
+
+    public List<AlarmVo> initalAlarmVo() {
+
+        List<AlarmVo> alarmVoList=new ArrayList<>();
+        Map<String, List<ProEconAlarmConfiguration>> wtAlarmMap = CacheContext.wtAlarmMap;
+        Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
+        for (ProBasicEquipment wt : CacheContext.wtls) {
+
+            if (wtpAimap.containsKey(wt.getId())) {
+                Map<String, ProBasicEquipmentPoint> pointMap = wtpAimap.get(wt.getId());
+
+                StringBuilder sb = new StringBuilder();
+                sb.append(wt.getWindpowerstationId() + wt.getModelId());
+                if (StringUtils.notEmp(pointMap) && wtAlarmMap.containsKey(String.valueOf(sb))) {
+                    List<ProEconAlarmConfiguration> alarmls = wtAlarmMap.get(String.valueOf(sb));
+
+                    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) &&
+                                        alarm.getAlarmType().equals(AlarmTypeValue.IN.getCode())
+                                )
+                                {
+                                    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.setAlarmtype(alarm.getAlarmType());
+                                    vo.setCharacteristic(alarm.getCharacteristic());
+                                    vo.setComponents(alarm.getComponents());
+                                    vo.setDescription(alarm.getDescription());
+                                    vo.setDeviceid(wt.getId());
+                                    vo.setDevicename(wt.getName());
+                                    vo.setDevicetype(alarm.getDeviceType());
+                                    vo.setEnabled(alarm.getEnable());
+                                    vo.setLineid(wt.getLineId());
+                                    if(CacheContext.lnmap.containsKey(wt.getLineId()))
+                                    {
+                                        ProBasicLine ln=CacheContext.lnmap.get(wt.getLineId());
+                                        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(alarm.getResetTable());
+                                    vo.setStationid(wt.getWindpowerstationId());
+                                    if(CacheContext.wpmap.containsKey(wt.getWindpowerstationId()))
+                                    {
+                                        ProBasicPowerstation wp=CacheContext.wpmap.get(wt.getWindpowerstationId());
+                                        vo.setStationname(wp.getName());
+                                    }
+                                    vo.setSubcomponents(alarm.getSubcomponents());
+                                    vo.setSuffix(alarm.getSuffix());
+                                    vo.setTriggertype(alarm.getTriggerType());
+                                    vo.setUniformcode(alarm.getUniformCode());
+                                    vo.setSuperTableName(AlarmSuperTalbeType.WT.getCode());
+                                    vo.setVal(0);
+                                    alarmVoList.add(vo);
+                                }
+
+                            }
+//                            else {
+//
+//                                //临时创建表
+//                                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("GF-TZ-SYZ.038200G9911SYB99GI017DB0111PA99RAW01");
+//                                vo.setAlarmtype(alarm.getAlarmType());
+//                                vo.setCharacteristic(alarm.getCharacteristic());
+//                                vo.setComponents(alarm.getComponents());
+//                                vo.setDescription(alarm.getDescription());
+//                                vo.setDeviceid(wt.getId());
+//                                vo.setDevicename(wt.getName());
+//                                vo.setDevicetype(alarm.getDeviceType());
+//                                vo.setEnabled(alarm.getEnable());
+//                                vo.setLineid(wt.getLineId());
+//                                if(CacheContext.lnmap.containsKey(wt.getLineId()))
+//                                {
+//                                    ProBasicLine ln=CacheContext.lnmap.get(wt.getLineId());
+//                                    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(alarm.getResetTable());
+//                                vo.setStationid(wt.getWindpowerstationId());
+//                                if(CacheContext.wpmap.containsKey(wt.getWindpowerstationId()))
+//                                {
+//                                    ProBasicPowerstation wp=CacheContext.wpmap.get(wt.getWindpowerstationId());
+//                                    vo.setStationname(wp.getName());
+//                                }
+//                                vo.setSubcomponents(alarm.getSubcomponents());
+//                                vo.setSuffix(alarm.getSuffix());
+//                                vo.setTriggertype(alarm.getTriggerType());
+//                                vo.setUniformcode(alarm.getUniformCode());
+//                                vo.setSuperTableName(AlarmSuperTalbeType.WT.getCode());
+//                                vo.setVal(0);
+//                                vo.setOval(0);
+//                                alarmVoList.add(vo);
+//
+//                            }
+                        }
+                    }
+                }
+            }
+
+        }
+        return  alarmVoList;
+    }
+
+
+
+
+    public List<AlarmTag> findTags(String stbaleName)
+    {
+        List<AlarmTag> ls=new ArrayList<>();
+        if(StringUtils.notEmp(stbaleName))
+        {
+           // List<AlarmVo> vos= alarmTsService.findTags(stbaleName);
+            List<AlarmVo> vos= CacheContext.alarmWtList;
+            if(!vos.isEmpty())
+            {
+                for(AlarmVo vo:vos)
+                {
+                    AlarmTag po=new AlarmTag();
+                    po.setId(vo.getTbName());
+                    po.setOval(vo.getVal().doubleValue());
+                    po.setTriggerType(vo.getTriggertype());
+                    po.setTagId(vo.getTagid());
+                    po.setVal(vo.getVal().doubleValue());
+                    po.setRank(vo.getRank());
+
+                    ls.add(po);
+                }
+            }
+        }
+        return ls;
+    }
+
+
+    public synchronized void saveAlarms(List<AlarmTag> ls) throws EncodeException, IOException {
+
+        if(StringUtils.notEmp(ls) && !ls.isEmpty()) {
+
+            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.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.setComponents(vo.getComponents());
+                        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.setIsOpen(1);
+                        po.setVal(alarm.getVal().intValue());
+
+                        alarm.setDescription(vo.getDescription());
+                        alarm.setAlarmType(vo.getAlarmtype());
+                        alarm.setDeviceType(vo.getDevicetype());
+                        pushData(alarm);
+
+                        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);
+                }
+            }
+        }
+    }
+
+
+    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());
+                    alarm.setTs(tag.getTs().getTime());
+
+                    Date begin = new Date(alarm.getEndts());
+                    Date end = new Date(alarm.getTs());
+
+                    double value= DateUtils.secondsDiff(begin,end);
+                    alarm.setTimeLong(value);
+                    alarm.setConfirmed(tag.getConfirmed());
+                    alarm.setSuperTalbe(AlarmSuperTalbeType.WT.getCode());
+                }
+            }
+
+            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.setComponents(vo.getComponents());
+                        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);
+                        po.setVal(alarm.getVal().intValue());
+                        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() == 1000) {
+                        proEconAlarmInfoService.saveBatch(templs);
+                        templs = new ArrayList<>();
+                    }
+                }
+
+                if (!templs.isEmpty()) {
+                    proEconAlarmInfoService.saveBatch(templs);
+                }
+
+            }
+        }
+
+    }
+
+    public void pushData(AlarmTag po) throws EncodeException, IOException {
+        ConcurrentHashMap<String, WebSocket> webSocketPushMap = WebSocket.webSocketMap;
+        ConcurrentHashMap<String, PushParams> webSocketPushParamsMap = WebSocket.webSocketParamsMap;
+        if(!webSocketPushMap.isEmpty()){
+            for(String key : webSocketPushMap.keySet()){
+                // 根据ws连接用户ID获取推送参数
+                PushParams pushParams = webSocketPushParamsMap.get(key);
+
+                if(webSocketPushParamsMap.contains(po.getId()))
+                {
+                    PushParams pp=webSocketPushParamsMap.get(po.getId());
+
+                    double hours=DateUtils.hoursDiff(pp.getStartTime(),new Date());
+                    if(hours>pushinterval)
+                    {
+                        webSocket.sendMessageByUserId(key,po);
+                        pp.setStartTime(new Date(po.getTs()));
+                    }
+                }else
+                {
+                    webSocket.sendMessageByUserId(key,po);
+                    PushParams pp=new PushParams();
+                    pp.setStartTime(new Date());
+                    webSocketPushParamsMap.put(po.getId(),pp);
+                }
+            }
+        }
+
+    }
+}

+ 106 - 55
alarm-service/src/main/java/com/gyee/alarm/service/AlarmWtService.java

@@ -7,13 +7,19 @@ 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 com.gyee.alarm.websocket.PushParams;
+import com.gyee.alarm.websocket.WebSocket;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import javax.websocket.EncodeException;
+import java.io.IOException;
 import java.sql.SQLException;
 import java.sql.Timestamp;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 
 @Service
 
@@ -25,6 +31,10 @@ public class AlarmWtService {
     @Value("${initialcode}")
     private String initialcode;
 
+    @Value("${pushinterval}")
+    private Double pushinterval;
+    @Resource
+    private WebSocket webSocket;
     public void dropSuperTable()
     {
         alarmTsService.dropSuperTable(AlarmSuperTalbeType.WT.getCode());
@@ -110,7 +120,9 @@ public class AlarmWtService {
 
                                 if(StringUtils.notEmp(initialcode) &&
                                         StringUtils.notEmp(equipmentPoint.getNemCode()) &&
-                                        !equipmentPoint.getNemCode().equals(initialcode))
+                                        !equipmentPoint.getNemCode().equals(initialcode) &&
+                                        alarm.getAlarmType().equals(AlarmTypeValue.WT.getCode())
+                                )
                                 {
                                     AlarmVo vo=new AlarmVo();
                                     StringBuilder tbName = new StringBuilder();
@@ -124,7 +136,7 @@ public class AlarmWtService {
                                     vo.setDescription(alarm.getDescription());
                                     vo.setDeviceid(wt.getId());
                                     vo.setDevicename(wt.getName());
-                                    vo.setDevicetype(DeviceTypeValue.WT.getCode());
+                                    vo.setDevicetype(alarm.getDeviceType());
                                     vo.setEnabled(alarm.getEnable());
                                     vo.setLineid(wt.getLineId());
                                     if(CacheContext.lnmap.containsKey(wt.getLineId()))
@@ -156,54 +168,55 @@ public class AlarmWtService {
                                     alarmVoList.add(vo);
                                 }
 
-                            }else {
-
-                                //临时创建表
-                                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("GF-TZ-SYZ.038200G9911SYB99GI017DB0111PA99RAW01");
-                                vo.setAlarmtype(alarm.getAlarmType());
-                                vo.setCharacteristic(alarm.getCharacteristic());
-                                vo.setComponents(alarm.getComponents());
-                                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(alarm.getResetTable());
-                                vo.setStationid(wt.getWindpowerstationId());
-                                if(CacheContext.wpmap.containsKey(wt.getWindpowerstationId()))
-                                {
-                                    ProBasicPowerstation wp=CacheContext.wpmap.get(wt.getWindpowerstationId());
-                                    vo.setStationname(wp.getName());
-                                }
-                                vo.setSubcomponents(alarm.getSubcomponents());
-                                vo.setSuffix(alarm.getSuffix());
-                                vo.setTriggertype(alarm.getTriggerType());
-                                vo.setUniformcode(alarm.getUniformCode());
-                                vo.setSuperTableName(AlarmSuperTalbeType.WT.getCode());
-                                vo.setVal(0);
-                                vo.setOval(0);
-                                alarmVoList.add(vo);
-
                             }
+//                            else {
+//
+//                                //临时创建表
+//                                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("GF-TZ-SYZ.038200G9911SYB99GI017DB0111PA99RAW01");
+//                                vo.setAlarmtype(alarm.getAlarmType());
+//                                vo.setCharacteristic(alarm.getCharacteristic());
+//                                vo.setComponents(alarm.getComponents());
+//                                vo.setDescription(alarm.getDescription());
+//                                vo.setDeviceid(wt.getId());
+//                                vo.setDevicename(wt.getName());
+//                                vo.setDevicetype(alarm.getDeviceType());
+//                                vo.setEnabled(alarm.getEnable());
+//                                vo.setLineid(wt.getLineId());
+//                                if(CacheContext.lnmap.containsKey(wt.getLineId()))
+//                                {
+//                                    ProBasicLine ln=CacheContext.lnmap.get(wt.getLineId());
+//                                    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(alarm.getResetTable());
+//                                vo.setStationid(wt.getWindpowerstationId());
+//                                if(CacheContext.wpmap.containsKey(wt.getWindpowerstationId()))
+//                                {
+//                                    ProBasicPowerstation wp=CacheContext.wpmap.get(wt.getWindpowerstationId());
+//                                    vo.setStationname(wp.getName());
+//                                }
+//                                vo.setSubcomponents(alarm.getSubcomponents());
+//                                vo.setSuffix(alarm.getSuffix());
+//                                vo.setTriggertype(alarm.getTriggerType());
+//                                vo.setUniformcode(alarm.getUniformCode());
+//                                vo.setSuperTableName(AlarmSuperTalbeType.WT.getCode());
+//                                vo.setVal(0);
+//                                vo.setOval(0);
+//                                alarmVoList.add(vo);
+//
+//                            }
                         }
                     }
                 }
@@ -243,8 +256,7 @@ public class AlarmWtService {
     }
 
 
-    public synchronized void saveAlarms(List<AlarmTag> ls)
-    {
+    public synchronized void saveAlarms(List<AlarmTag> ls) throws EncodeException, IOException {
 
         if(StringUtils.notEmp(ls) && !ls.isEmpty()) {
 
@@ -287,6 +299,13 @@ public class AlarmWtService {
                         po.setOval(alarm.getOval().intValue());
                         po.setIsOpen(1);
                         po.setVal(alarm.getVal().intValue());
+
+
+                        alarm.setDescription(vo.getDescription());
+                        alarm.setAlarmType(vo.getAlarmtype());
+                        alarm.setDeviceType(vo.getDevicetype());
+                        pushData(alarm);
+
                         valuels.add(po);
                     }
                 }
@@ -344,15 +363,16 @@ public class AlarmWtService {
                 if(map.containsKey(alarm.getId()))
                 {
                     AlarmSimpleVo tag=map.get(alarm.getId());
-                    tag.setTs(new Timestamp(alarm.getTs()));
+                    alarm.setTs(tag.getTs().getTime());
 
                     Date begin = new Date(alarm.getEndts());
                     Date end = new Date(alarm.getTs());
 
-                    double value= DateUtils.hoursDiff(begin,end);
-                    tag.setTimelong(value);
+                    double value= DateUtils.secondsDiff(begin,end);
+                    alarm.setTimeLong(value);
+                    alarm.setConfirmed(tag.getConfirmed());
+                    alarm.setSuperTalbe(AlarmSuperTalbeType.WT.getCode());
                 }
-
             }
 
             alarmTsService.insertList(ls);
@@ -425,4 +445,35 @@ public class AlarmWtService {
         }
 
     }
+
+
+    public void pushData(AlarmTag po) throws EncodeException, IOException {
+        ConcurrentHashMap<String, WebSocket> webSocketPushMap = WebSocket.webSocketMap;
+        ConcurrentHashMap<String, PushParams> webSocketPushParamsMap = WebSocket.webSocketParamsMap;
+        if(!webSocketPushMap.isEmpty()){
+            for(String key : webSocketPushMap.keySet()){
+                // 根据ws连接用户ID获取推送参数
+                PushParams pushParams = webSocketPushParamsMap.get(key);
+
+                if(webSocketPushParamsMap.contains(po.getId()))
+                {
+                    PushParams pp=webSocketPushParamsMap.get(po.getId());
+
+                    double hours=DateUtils.hoursDiff(pp.getStartTime(),new Date());
+                    if(hours>pushinterval)
+                    {
+                        webSocket.sendMessageByUserId(key,po);
+                        pp.setStartTime(new Date(po.getTs()));
+                    }
+                }else
+                {
+                    webSocket.sendMessageByUserId(key,po);
+                    PushParams pp=new PushParams();
+                    pp.setStartTime(new Date());
+                    webSocketPushParamsMap.put(po.getId(),pp);
+                }
+            }
+        }
+
+    }
 }

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

@@ -98,7 +98,7 @@ 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(false).append(",")
+            sub_sb.append(tag.getTs()).append(",").append(tag.getVal().intValue()).append(",").append(tag.getConfirmed()).append(",")
                     .append(tag.getEndts()).append(",").append(tag.getTimeLong());
             sub_sb.append(" ) ");
             i++;

+ 30 - 0
alarm-service/src/main/java/com/gyee/alarm/websocket/PushParams.java

@@ -0,0 +1,30 @@
+package com.gyee.alarm.websocket;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 功能描述:
+ *
+ * @description: ws推送的参数结构
+ * @Date: 2022/12/1
+ */
+@Data
+public class PushParams {
+
+    /**
+     * 报警编号:
+     * 类型
+     */
+    private String alarmId;
+
+    /**
+     * 功能描述:
+     * 开始时间
+     */
+    private Date startTime;
+
+
+}
+

+ 186 - 0
alarm-service/src/main/java/com/gyee/alarm/websocket/WebSocket.java

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

+ 21 - 0
alarm-service/src/main/java/com/gyee/alarm/websocket/WebSocketConfig.java

@@ -0,0 +1,21 @@
+package com.gyee.alarm.websocket;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.socket.server.standard.ServerEndpointExporter;
+
+/**
+ * 功能描述:
+ * 开启websocket支持
+ * @Date: 2022-12-01 09:40:15
+ * @since: 1.0.0
+ */
+@Configuration
+public class WebSocketConfig {
+
+    // 使用boot内置tomcat时需要注入此bean
+    @Bean
+    public ServerEndpointExporter serverEndpointExporter() {
+        return new ServerEndpointExporter();
+    }
+}

+ 38 - 0
alarm-service/src/main/java/com/gyee/alarm/websocket/WebSocketCustomEncoding.java

@@ -0,0 +1,38 @@
+package com.gyee.alarm.websocket;
+
+import com.alibaba.fastjson.JSON;
+import javax.websocket.EncodeException;
+import javax.websocket.Encoder;
+import javax.websocket.EndpointConfig;
+
+/**
+ * 在 websocket 中直接发送 obj 会有问题 - No encoder specified for object of class
+ * 需要对 obj 创建解码类,实现 websocket 中的 Encoder.Text<>
+ * */
+public class WebSocketCustomEncoding implements Encoder.Text<Object> {
+    /**
+     * The Encoder interface defines how developers can provide a way to convert their
+     * custom objects into web socket messages. The Encoder interface contains
+     * subinterfaces that allow encoding algorithms to encode custom objects to:
+     * text, binary data, character stream and write to an output stream.
+     *
+     * Encoder 接口定义了如何提供一种方法将定制对象转换为 websocket 消息
+     * 可自定义对象编码为文本、二进制数据、字符流、写入输出流
+     *  Text、TextStream、Binary、BinaryStream
+     * */
+
+    @Override
+    public void init(EndpointConfig endpointConfig) {
+
+    }
+
+    @Override
+    public void destroy() {
+
+    }
+
+    @Override
+    public String encode(Object o) throws EncodeException {
+        return JSON.toJSONString(o);
+    }
+}

+ 87 - 0
alarm-service/src/main/java/com/gyee/alarm/websocket/WebsocketSchedule.java

@@ -0,0 +1,87 @@
+package com.gyee.alarm.websocket;
+
+
+import com.gyee.alarm.init.CacheContext;
+import com.gyee.alarm.model.auto.ProEconAlarmInfo;
+import com.gyee.alarm.model.vo.AlarmTag;
+import com.gyee.alarm.model.vo.AlarmTypeValue;
+import com.gyee.alarm.model.vo.AlarmVo;
+import com.gyee.alarm.model.vo.DeviceTypeValue;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import javax.websocket.EncodeException;
+import java.io.IOException;
+import java.util.Date;
+import java.util.concurrent.ConcurrentHashMap;
+
+
+/**
+ * 功能描述:
+ *
+ * @description: ws定时推送
+ * @Date: 2022/11/30
+ */
+@Configuration
+@EnableScheduling
+public class WebsocketSchedule {
+
+    @Autowired
+    private WebSocket webSocket;
+
+    // 第一次延迟1秒后执行,之后按fixedRate的规则每5秒执行一次 fixedRateString 与 fixedRate 意思相同,只是使用字符串的形式。唯一不同的是支持占位符
+    @Scheduled(initialDelay=1000, fixedRateString = "5")
+    public void pushData() throws EncodeException, IOException {
+        ConcurrentHashMap<String, WebSocket> webSocketPushMap = WebSocket.webSocketMap;
+        ConcurrentHashMap<String, PushParams> webSocketPushParamsMap = WebSocket.webSocketParamsMap;
+        if(!webSocketPushMap.isEmpty()) {
+            for (String key : webSocketPushMap.keySet()) {
+                // 根据ws连接用户ID获取推送参数
+                PushParams pushParams = webSocketPushParamsMap.get(key);
+
+                AlarmTag alarm = new AlarmTag();
+                alarm.setTs(new Date().getTime());
+                alarm.setDescription("test1");
+                alarm.setAlarmType(AlarmTypeValue.WT.getCode());
+                alarm.setDeviceType(DeviceTypeValue.WT.getCode());
+                webSocket.sendMessageByUserId(key, alarm);
+                alarm = new AlarmTag();
+                alarm.setTs(new Date().getTime());
+                alarm.setDescription("test2");
+                alarm.setAlarmType(AlarmTypeValue.IN.getCode());
+                alarm.setDeviceType(DeviceTypeValue.IN.getCode());
+                webSocket.sendMessageByUserId(key, alarm);
+
+                alarm = new AlarmTag();
+                alarm.setTs(new Date().getTime());
+                alarm.setDescription("test3");
+                alarm.setAlarmType(AlarmTypeValue.BT.getCode());
+                alarm.setDeviceType(DeviceTypeValue.BT.getCode());
+                webSocket.sendMessageByUserId(key, alarm);
+
+                alarm = new AlarmTag();
+                alarm.setTs(new Date().getTime());
+                alarm.setDescription("test4");
+                alarm.setAlarmType(AlarmTypeValue.BTE.getCode());
+                alarm.setDeviceType(DeviceTypeValue.BT.getCode());
+                webSocket.sendMessageByUserId(key, alarm);
+
+                alarm = new AlarmTag();
+                alarm.setTs(new Date().getTime());
+                alarm.setDescription("test5");
+                alarm.setAlarmType(AlarmTypeValue.CT.getCode());
+                alarm.setDeviceType(DeviceTypeValue.IN.getCode());
+                webSocket.sendMessageByUserId(key, alarm);
+
+                alarm = new AlarmTag();
+                alarm.setTs(new Date().getTime());
+                alarm.setDescription("test6");
+                alarm.setAlarmType(AlarmTypeValue.CT.getCode());
+                alarm.setDeviceType(DeviceTypeValue.WT.getCode());
+                webSocket.sendMessageByUserId(key, alarm);
+            }
+
+        }
+    }
+}

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

@@ -171,6 +171,8 @@ frequency:
 task-count: 10
 
 interval: 1
+#报警websockt重复报警推送间隔
+pushinterval: 1
 
 
 

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

@@ -108,18 +108,20 @@ public class AlarmConfigurationController {
             @ApiImplicitParam(name = "pagesize", value = "每页显示多少行", required = true, dataType = "Integer", paramType = "query"),
             @ApiImplicitParam(name = "name", value = "名称", required = false, dataType = "string", paramType = "query"),
             @ApiImplicitParam(name = "wpId", value = "风场编号", required = false, dataType = "string", paramType = "query"),
-            @ApiImplicitParam(name = "modelId", value = "型号编号", required = false, dataType = "string", paramType = "query")})
+            @ApiImplicitParam(name = "modelId", value = "型号编号", required = false, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "alarmType", value = "报警类型", required = false, dataType = "string", paramType = "query")})
 
     public AjaxResult queryByPage(HttpServletRequest request,
                                   @RequestParam(value = "pagenum") Integer pageNum,
                                   @RequestParam(value = "pagesize") Integer pageSize,
                                   @RequestParam(value = "name", required = false) String name,
                                   @RequestParam(value = "wpId", required = false) String wpId,
-                                  @RequestParam(value = "modelId", required = false) String modelId
+                                  @RequestParam(value = "modelId", required = false) String modelId,
+                                  @RequestParam(value = "alarmType", required = false) String alarmType
     ) {
         Page<ProEconAlarmConfiguration> page = new Page(pageNum, pageSize);
 
-        IPage<ProEconAlarmConfiguration> pageResult = alarmConfigurationService.pageQueryAll(page, name, wpId, modelId);
+        IPage<ProEconAlarmConfiguration> pageResult = alarmConfigurationService.pageQueryAll(page, name, wpId, modelId,alarmType);
 
 
         if (StringUtils.notEmp(pageResult)) {

+ 33 - 13
alarm-web/src/main/java/com/gyee/alarm/controller/AlarmHistoryController.java

@@ -1,9 +1,6 @@
 package com.gyee.alarm.controller;
 
-import com.gyee.alarm.model.vo.AjaxResult;
-import com.gyee.alarm.model.vo.AjaxStatus;
-import com.gyee.alarm.model.vo.AlarmStatVo;
-import com.gyee.alarm.model.vo.AlarmVo;
+import com.gyee.alarm.model.vo.*;
 import com.gyee.alarm.service.AlarmHistoryService;
 
 import com.gyee.alarm.util.DateUtils;
@@ -39,6 +36,18 @@ public class AlarmHistoryController {
     private AlarmHistoryService alarmHistoryService;
 
 
+    @GetMapping(value = "/history/updateAlarms")
+    @ApiOperation(value = "确认报警", notes = "确认报警")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "tagLs", value = "需要确认的报警", required = true, dataType = "string", paramType = "query")
+    })
+    public AjaxResult updateAlarms(@RequestBody List<AlarmTag> tagLs) throws Exception {
+
+
+       alarmHistoryService.updateAlarms(tagLs);
+        return AjaxResult.successData(AjaxStatus.success.code, "ok");
+
+    }
 
     @GetMapping(value = "/history/findAlarmlist")
     @ApiOperation(value = "报警信息查询", notes = "报警信息查询")
@@ -101,8 +110,9 @@ public class AlarmHistoryController {
             @ApiImplicitParam(name = "end", value = "结束时间", required = true, dataType = "string", paramType = "query"),
             @ApiImplicitParam(name = "stationid", value = "场站编号", required = true, dataType = "string", paramType = "query"),
             @ApiImplicitParam(name = "modelId", value = "型号编号", required = false, dataType = "string", paramType = "query"),
-            @ApiImplicitParam(name = "components", value = "部件编号", required = true, dataType = "string", paramType = "query"),
-            @ApiImplicitParam(name = "alarmIds", value = "报警编号集合", required = true, dataType = "string", paramType = "query")
+            @ApiImplicitParam(name = "components", value = "部件编号", required = false, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "alarmIds", value = "报警编号集合", required = false, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "timeType", value = "秒、分、时(s,m,h)", required = false, dataType = "string", paramType = "query")
            })
     public List<Map.Entry<String, List<AlarmStatVo>>> findWtFeatureStat(
 
@@ -110,8 +120,9 @@ public class AlarmHistoryController {
             @RequestParam(value = "end", required = true) String end,
             @RequestParam(value = "stationid", required = true) String stId,
             @RequestParam(value = "modelId", required = false) String modelId,
-            @RequestParam(value = "components", required = true) String components,
-            @RequestParam(value = "alarmIds", required = true) String alarmIds
+            @RequestParam(value = "components", required = false) String components,
+            @RequestParam(value = "alarmIds", required = false) String alarmIds,
+            @RequestParam(value = "timeType", required = false) String timeType
     ) throws ParseException {
 
 
@@ -123,7 +134,15 @@ public class AlarmHistoryController {
         {
             modelId=null;
         }
-        List<AlarmStatVo> pressureList = alarmHistoryService.findWtFeatureStat(stId,modelId, dtStart, dtEnd,components,alarmIds);
+        if(StringUtils.empty(components))
+        {
+            components=null;
+        }
+        if(StringUtils.empty(alarmIds))
+        {
+            alarmIds=null;
+        }
+        List<AlarmStatVo> pressureList = alarmHistoryService.findWtFeatureStat(stId,modelId, dtStart, dtEnd,components,alarmIds,timeType);
 
 
         //根据风机编号分组
@@ -162,7 +181,8 @@ public class AlarmHistoryController {
             @ApiImplicitParam(name = "stationid", value = "场站编号", required = true, dataType = "string", paramType = "query"),
             @ApiImplicitParam(name = "modelId", value = "型号编号", required = false, dataType = "string", paramType = "query"),
             @ApiImplicitParam(name = "components", value = "部件集合", required = true, dataType = "string", paramType = "query"),
-            @ApiImplicitParam(name = "alarmIds", value = "报警编号集合", required = true, dataType = "string", paramType = "query")
+            @ApiImplicitParam(name = "alarmIds", value = "报警编号集合", required = true, dataType = "string", paramType = "query"),
+            @ApiImplicitParam(name = "timeType", value = "秒、分、时(s,m,h)", required = false, dataType = "string", paramType = "query")
     })
     public List<Map.Entry<String, List<AlarmStatVo>>> findCtFeatureStat(
 
@@ -171,7 +191,8 @@ public class AlarmHistoryController {
             @RequestParam(value = "stationid", required = true) String stId,
             @RequestParam(value = "modelId", required = false) String modelId,
             @RequestParam(value = "components", required = true) String components,
-            @RequestParam(value = "alarmIds", required = true) String alarmIds
+            @RequestParam(value = "alarmIds", required = true) String alarmIds,
+            @RequestParam(value = "timeType", required = false) String timeType
     ) throws ParseException {
 
 
@@ -183,7 +204,7 @@ public class AlarmHistoryController {
         {
             modelId=null;
         }
-        List<AlarmStatVo> pressureList = alarmHistoryService.findCtFeatureStat(stId,modelId, dtStart, dtEnd,components,alarmIds);
+        List<AlarmStatVo> pressureList = alarmHistoryService.findCtFeatureStat(stId,modelId, dtStart, dtEnd,components,alarmIds,timeType);
 
 //
 //        Map<String, List<AlarmStatVo>> map=new TreeMap<>();
@@ -218,7 +239,6 @@ public class AlarmHistoryController {
 
         return list;
 
-
     }
 
 }

+ 13 - 8
alarm-web/src/main/java/com/gyee/alarm/mapper/auto/AlarmTsMapper.java

@@ -5,6 +5,7 @@ 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.auto.ProBasicFeatureStat;
+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;
@@ -158,25 +159,28 @@ public interface AlarmTsMapper extends BaseMapper<AlarmTs> {
 //    @Select("select deviceid as wtId,stationid as stationId,alarmid,description,components as typeCode,max(timeLong) as maxSeconds,min(timeLong) as minSeconds,avg(timeLong) as avgSeconds,sum(timeLong) as totalSeconds,count(*) as total from alarmWt where ts>=#{begin} and ts<=#{end}  and alarmtype='windturbine'  and #{begin} group by deviceid,components,stationid,alarmid,description")
 
     @Select({"<script>",
-            "select deviceid as wtId,stationid as stationId,alarmid,description,components as typeCode,max(timeLong) as maxSeconds,min(timeLong) as minSeconds,avg(timeLong) as avgSeconds,sum(timeLong) as totalSeconds,count(*) as total from alarmCt " ,
+            "select deviceid as wtId,stationid as stationId,alarmid,description,components as typeCode,max(timeLong) as maxSeconds,min(timeLong) as minSeconds,avg(timeLong) as avgSeconds,sum(timeLong) as totalSeconds,count(*) as total from alarmWt " ,
             "<where>" ,
 
             " ts &gt;= #{begin}",
             "and ts &lt;= #{end}",
             "and stationid = #{stationid}",
-            "and modelId = #{modelId}",
+
             "<if test='alarmid != null'>",
-            "and alarmid in(#{alarmid}) ",
+            "and alarmid in (${alarmid}) ",
             "</if>",
             "<if test='components != null'>",
-            "and components in(#{components}) ",
+            "and components in (${components}) ",
+            "</if>",
+            "<if test='modelId != null'>",
+            "and modelId = #{modelId}",
             "</if>",
             "</where>",
 
             " group by deviceid,components,stationid,alarmid,description ",
             " order by deviceid  ",
             "</script>"})
-    List<ProBasicFeatureStat> findWtFeatureStat( @Param("begin")long begin, @Param("end") long end, @Param("stationid") String stationid, @Param("modelId")String modelId,@Param("components") List<String> components, @Param("alarmid") List<String> alarmid);
+    List<ProBasicFeatureStat> findWtFeatureStat( @Param("begin")long begin, @Param("end") long end, @Param("stationid") String stationid, @Param("modelId")String modelId,@Param("components") String components, @Param("alarmid") String alarmid);
 
 
     @Select({"<script>",
@@ -188,10 +192,10 @@ public interface AlarmTsMapper extends BaseMapper<AlarmTs> {
             "and stationid = #{stationid}",
             "and modelId = #{modelId}",
             "<if test='alarmid != null'>",
-            "and alarmid in(#{alarmid}) ",
+            "and alarmid in(${alarmid}) ",
             "</if>",
             "<if test='components != null'>",
-            "and components in(#{components}) ",
+            "and components in(${components}) ",
             "</if>",
             "</where>",
 
@@ -200,5 +204,6 @@ public interface AlarmTsMapper extends BaseMapper<AlarmTs> {
             "</script>"})
     List<ProBasicFeatureStat> findCtFeatureStat( @Param("begin")long begin, @Param("end") long end, @Param("stationid") String stationid, @Param("modelId")String modelId, @Param("components") List<String> components, @Param("alarmid") List<String> alarmid);
 
-
+    @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);
 }

+ 4 - 2
alarm-web/src/main/java/com/gyee/alarm/mapper/auto/ProEconAlarmConfigurationMapper.java

@@ -34,14 +34,16 @@ public interface ProEconAlarmConfigurationMapper extends BaseMapper<ProEconAlarm
             "<if test='modelId !=null  '>",
             "and model_id = #{modelId} ",
             "</if>",
-
+            "<if test='alarmType !=null  '>",
+            "and alarm_type = #{alarmType} ",
+            "</if>",
             "</where>",
             " order by id ",
             "</script>"})
     IPage<ProEconAlarmConfiguration> pageQueryAll(Page page,
                                          @Param("description") String description,
                                          @Param("wpId") String wpId,
-                                         @Param("modelId") String modelId);
+                                         @Param("modelId") String modelId,@Param("alarmType")String alarmType);
 
 
     @Select({"<script>",

+ 19 - 0
alarm-web/src/main/java/com/gyee/alarm/model/vo/AlarmSimpleVo.java

@@ -0,0 +1,19 @@
+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  Boolean confirmed;
+    private Timestamp endts;
+    private Double timelong;
+
+}

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

@@ -16,7 +16,7 @@ public class AlarmStatVo implements Serializable{
     private String alertText;
 
     private long count;
-
+    private String alarmid;
     private double time;
     //关联部件编号
     private String relateParts;

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

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

+ 58 - 0
alarm-web/src/main/java/com/gyee/alarm/model/vo/AlarmTime.java

@@ -0,0 +1,58 @@
+package com.gyee.alarm.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+
+public enum AlarmTime {
+
+    H("h", "时"),
+    M("m", "分"),
+    S("s", "秒");
+
+    private String code;
+    private String name;
+
+    AlarmTime(String code) {
+        this.code = code;
+    }
+
+    AlarmTime(String code, String name) {
+        this.code = code;
+        this.name = name;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 根据code获取message
+     *
+     * @param code
+     * @return
+     */
+    public static String getNmaeByCode(String code) {
+        for (AlarmTime ele : values()) {
+            if (ele.getCode().equals(code)) {
+                return ele.getName();
+            }
+        }
+        return null;
+    }
+
+
+}

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

@@ -80,7 +80,7 @@ public class AlarmConfigurationService {
     }
 
 
-    public IPage<ProEconAlarmConfiguration> pageQueryAll(Page page, String name, String station, String modelId) {
+    public IPage<ProEconAlarmConfiguration> pageQueryAll(Page page, String name, String station, String modelId,String alarmType) {
 
 
         if(StringUtils.notEmp(name))
@@ -98,9 +98,12 @@ public class AlarmConfigurationService {
         {
             modelId=null;
         }
+        if(StringUtils.empty(alarmType))
+        {
+            alarmType=null;
+        }
 
-
-        IPage<ProEconAlarmConfiguration> alertruleIPage = proEconAlarmConfigurationService.pageQueryAll(page, name, station, modelId);
+        IPage<ProEconAlarmConfiguration> alertruleIPage = proEconAlarmConfigurationService.pageQueryAll(page, name, station, modelId,alarmType);
 
         return alertruleIPage;
     }

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

@@ -10,6 +10,7 @@ import com.gyee.alarm.init.CacheContext;
 import com.gyee.alarm.mapper.auto.AlarmTsMapper;
 import com.gyee.alarm.model.auto.*;
 import com.gyee.alarm.model.vo.*;
+import com.gyee.alarm.service.auto.IAlarmTsService;
 import com.gyee.alarm.util.DateUtils;
 import com.gyee.alarm.util.SnowflakeGenerator;
 import com.gyee.common.model.StringUtils;
@@ -19,6 +20,8 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.sql.Timestamp;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -31,9 +34,73 @@ public class AlarmHistoryService   {
 
     @Resource
     private AlarmTsMapper alarmTsMapper;
+    @Resource
+    private IAlarmTsService alarmTsService;
+
+    public  void updateAlarms(List<AlarmTag> ls) {
+
+        if (com.gyee.alarm.util.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> alarmWtls=alarmTsService.selectLastRowByTbname(AlarmSuperTalbeType.WT.getCode(),ids);
+            List<AlarmSimpleVo> alarmCtls=alarmTsService.selectLastRowByTbname(AlarmSuperTalbeType.CT.getCode(),ids);
+            List<AlarmSimpleVo> alarmBtls=alarmTsService.selectLastRowByTbname(AlarmSuperTalbeType.BT.getCode(),ids);
+            if(!alarmWtls.isEmpty())
+            {
+                for(AlarmSimpleVo vo:alarmWtls)
+                {
+                    map.put(vo.getTbName(),vo);
+                }
+            }
+
+            if(!alarmCtls.isEmpty())
+            {
+                for(AlarmSimpleVo vo:alarmCtls)
+                {
+                    map.put(vo.getTbName(),vo);
+                }
+            }
+
+            if(!alarmBtls.isEmpty())
+            {
+                for(AlarmSimpleVo vo:alarmBtls)
+                {
+                    map.put(vo.getTbName(),vo);
+                }
+            }
+
+            for (AlarmTag alarm : ls) {
+
+
+                if(map.containsKey(alarm.getId()))
+                {
+                    AlarmSimpleVo tag=map.get(alarm.getId());
+                    alarm.setTs(tag.getTs().getTime());
+
+                    Date begin = new Date(alarm.getEndts());
+                    Date end = new Date(alarm.getTs());
+
+                    double value= DateUtils.secondsDiff(begin,end);
+                    alarm.setTimeLong(value);
+                    alarm.setConfirmed(true);
+                }
+            }
 
+            alarmTsService.insertList(ls);
 
 
+        }
+
+    }
+
     @Value("${home_pagep_size}")
     private int home_pagep_size;
     /**
@@ -155,11 +222,11 @@ public class AlarmHistoryService   {
     }
 
 
-    public List<AlarmStatVo> findWtFeatureStat(String stationId,String modelId, Date startTime, Date endTime,String components,String alarmIds) {
+    public List<AlarmStatVo> findWtFeatureStat(String stationId,String modelId, Date startTime, Date endTime,String components,String alarmIds,String timeType) {
         List<AlarmStatVo> resultList = new ArrayList<>();
 
-        List<String> alarmIdList=new ArrayList();
-        List<String> componentsList=new ArrayList();
+        StringBuilder alarmIdList=new StringBuilder();
+        StringBuilder componentsList=new StringBuilder();
 
         Map<String,String> alarmIdMap=new HashMap<>();
         Map<String,String> componentsMap=new HashMap();
@@ -169,7 +236,7 @@ public class AlarmHistoryService   {
             String [] componentsStr=components.split(",");
             for(String c:componentsStr)
             {
-                componentsList.add(c);
+                componentsList.append("'").append(c).append("',");
                 componentsMap.put(c,c);
             }
 
@@ -179,13 +246,22 @@ public class AlarmHistoryService   {
             String [] alarmIdStr=alarmIds.split(",");
             for(String c:alarmIdStr)
             {
-                alarmIdList.add(c);
+                alarmIdList.append("'").append(c).append("',");
                 alarmIdMap.put(c,c);
             }
 
         }
-
-        List<ProBasicFeatureStat> fsls = alarmTsMapper.findWtFeatureStat(startTime.getTime(), endTime.getTime(),stationId,modelId,componentsList,alarmIdList);
+        String alarmId=null;
+        String component=null;
+        if(alarmIdList.length()>0)
+        {
+             alarmId=String.valueOf(alarmIdList.substring(0,alarmIdList.length()-1));
+        }
+        if(componentsList.length()>0)
+        {
+            component=String.valueOf(componentsList.substring(0,componentsList.length()-1));
+        }
+        List<ProBasicFeatureStat> fsls = alarmTsMapper.findWtFeatureStat(startTime.getTime(), endTime.getTime(),stationId,modelId,component,alarmId);
 
 
         Map<String, ProBasicFeatureStat> map = new HashMap<>();
@@ -216,11 +292,21 @@ public class AlarmHistoryService   {
                 if(CacheContext.wtAlarmMap.containsKey(String.valueOf(sb))) {
                     List<ProEconAlarmConfiguration> ls = CacheContext.wtAlarmMap.get(String.valueOf(sb));
                     for (ProEconAlarmConfiguration at : ls) {
-                        if(StringUtils.notEmp(components) && StringUtils.notEmp(alarmIdMap))
+                        if(StringUtils.notEmp(components) )
                         {
-                            if( componentsMap.containsKey(at.getComponents()) && alarmIdMap.containsKey(at.getId()))
+                            if(componentsMap.containsKey(at.getComponents()) )
                             {
-                                setWtValues(statDate, map, vos, wt, at);
+                                if(StringUtils.notEmp(alarmIdMap) && !alarmIdMap.isEmpty())
+                                {
+                                    if( alarmIdMap.containsKey(at.getId()))
+                                    {
+                                        setWtValues(statDate, map, vos, wt, at);
+                                    }
+
+                                }else
+                                {
+                                    setWtValues(statDate, map, vos, wt, at);
+                                }
                             }
                         }else
                         {
@@ -241,10 +327,30 @@ public class AlarmHistoryService   {
             d.setRelatePartsText(fs.getTypeName());
             d.setAlertText(fs.getDescription());
             d.setCount(fs.getTotal());
-            d.setTime(fs.getTotalSeconds());
+
+            if(StringUtils.notEmp(timeType))
+            {
+                if(AlarmTime.H.getCode().equals(timeType))
+                {
+                    double times= new BigDecimal(fs.getTotalSeconds()).divide(new BigDecimal(360), 2, RoundingMode.HALF_EVEN).doubleValue();
+                    d.setTime(times);
+                }else if(AlarmTime.M.getCode().equals(timeType))
+                {
+                    double times= new BigDecimal(fs.getTotalSeconds()).divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN).doubleValue();
+                    d.setTime(times);
+                }else
+                {
+                    d.setTime(fs.getTotalSeconds());
+                }
+            }else
+            {
+                d.setTime(fs.getTotalSeconds());
+            }
+
             d.setStationId(fs.getStationId());
             d.setSnapId(SnowflakeGenerator.generateId());
             d.setWindturbineId(fs.getWtId());
+            d.setAlarmid(fs.getAlarmid());
             if(CacheContext.wtmap.containsKey(fs.getWtId()))
             {
                 ProBasicEquipment wt= CacheContext.wtmap.get(fs.getWtId());
@@ -268,27 +374,6 @@ public class AlarmHistoryService   {
         }
 
 
-        for (Map.Entry<String,List<AlarmStatVo>> entry : vomap.entrySet()) {
-
-            AlarmStatVo d = new AlarmStatVo();
-            List<AlarmStatVo> templs=entry.getValue();
-            if(!templs.isEmpty())
-            {
-                BeanUtil.copyProperties(templs.get(0),d);
-
-                double time = 0;
-                long count = 0;
-                time = templs.stream().mapToDouble(AlarmStatVo::getTime).sum();
-                count = templs.stream().mapToLong(AlarmStatVo::getCount).sum();
-                d.setCount(count);
-                //总时长以分钟为单位,不到一分钟则记为一分钟
-                double finalTime = Math.ceil(time / 60.0);
-
-                d.setTime(finalTime);
-                resultList.add(d);
-            }
-
-        }
 
 
         return resultList;
@@ -324,7 +409,7 @@ public class AlarmHistoryService   {
         vos.add(fs);
     }
 
-    public List<AlarmStatVo> findCtFeatureStat(String stationId,String modelId, Date startTime, Date endTime,String components,String alarmIds) {
+    public List<AlarmStatVo> findCtFeatureStat(String stationId,String modelId, Date startTime, Date endTime,String components,String alarmIds,String timeType) {
         List<AlarmStatVo> resultList = new ArrayList<>();
 
 
@@ -382,22 +467,34 @@ public class AlarmHistoryService   {
 
                 StringBuilder sb=new StringBuilder();
                 sb.append(wt.getWindpowerstationId()).append(wt.getModelId());
-                if(CacheContext.wtAlarmMap.containsKey(String.valueOf(sb))) {
+
+                if(CacheContext.ctAlarmMap.containsKey(String.valueOf(sb))) {
+
                     List<ProEconAlarmRule> wtCustomls=CacheContext.alarmRulesMap.get(AlarmCustomType.WT.getCode());
 
                     for (ProEconAlarmRule at : wtCustomls) {
 
-
-                        if(StringUtils.notEmp(components) && StringUtils.notEmp(alarmIdMap))
+                        if(StringUtils.notEmp(components) )
                         {
-                            if(componentsMap.containsKey(at.getRelatedParts()) && alarmIdMap.containsKey(at.getId()))
+                            if(componentsMap.containsKey(at.getRelatedParts()) )
                             {
-                                setCtValues(statDate, map, vos, wt, at);
+                                if(StringUtils.notEmp(alarmIdMap) && !alarmIdMap.isEmpty())
+                                {
+                                    if( alarmIdMap.containsKey(at.getId()))
+                                    {
+                                        setCtValues(statDate, map, vos, wt, at);
+                                    }
+
+                                }else
+                                {
+                                    setCtValues(statDate, map, vos, wt, at);
+                                }
                             }
                         }else
                         {
                             setCtValues(statDate, map, vos, wt, at);
                         }
+
                     }
 
                 }
@@ -413,7 +510,24 @@ public class AlarmHistoryService   {
             d.setRelatePartsText(fs.getTypeName());
             d.setAlertText(fs.getDescription());
             d.setCount(fs.getTotal());
-            d.setTime(fs.getTotalSeconds());
+            if(StringUtils.notEmp(timeType))
+            {
+                if(AlarmTime.H.getCode().equals(timeType))
+                {
+                    double times= new BigDecimal(fs.getTotalSeconds()).divide(new BigDecimal(360), 2, RoundingMode.HALF_EVEN).doubleValue();
+                    d.setTime(times);
+                }else if(AlarmTime.M.getCode().equals(timeType))
+                {
+                    double times= new BigDecimal(fs.getTotalSeconds()).divide(new BigDecimal(60), 2, RoundingMode.HALF_EVEN).doubleValue();
+                    d.setTime(times);
+                }else
+                {
+                    d.setTime(fs.getTotalSeconds());
+                }
+            }else
+            {
+                d.setTime(fs.getTotalSeconds());
+            }
             d.setStationId(fs.getStationId());
             d.setSnapId(SnowflakeGenerator.generateId());
             d.setWindturbineId(fs.getWtId());
@@ -440,29 +554,6 @@ public class AlarmHistoryService   {
         }
 
 
-        for (Map.Entry<String,List<AlarmStatVo>> entry : vomap.entrySet()) {
-
-            AlarmStatVo d = new AlarmStatVo();
-            List<AlarmStatVo> templs=entry.getValue();
-            if(!templs.isEmpty())
-            {
-                BeanUtil.copyProperties(templs.get(0),d);
-
-                double time = 0;
-                long count = 0;
-                time = templs.stream().mapToDouble(AlarmStatVo::getTime).sum();
-                count = templs.stream().mapToLong(AlarmStatVo::getCount).sum();
-                d.setCount(count);
-                //总时长以分钟为单位,不到一分钟则记为一分钟
-                double finalTime = Math.ceil(time / 60.0);
-
-                d.setTime(finalTime);
-                resultList.add(d);
-            }
-
-        }
-
-
         return resultList;
     }
     private  static void setCtValues(Date statDate,Map<String, ProBasicFeatureStat> map, List<ProBasicFeatureStat> vos, ProBasicEquipment wt, ProEconAlarmRule at) {

+ 3 - 0
alarm-web/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,7 @@ public interface IAlarmTsService extends IService<AlarmTs> {
 
 
     public   List<AlarmVo> selectByTbName(String tbName,long limit,long offset);
+
+    public List<AlarmSimpleVo> selectLastRowByTbname(String superTableName, String tbnames);
 }
 

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

@@ -21,5 +21,5 @@ public interface IProEconAlarmConfigurationService extends IService<ProEconAlarm
     public IPage<ProEconAlarmConfiguration> pageQueryAll(Page page,
                                          String description,
                                          String wpId,
-                                         String modelId);
+                                         String modelId,String alarmType);
 }

+ 25 - 21
alarm-web/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;
@@ -96,23 +93,21 @@ public class AlarmTsServiceImpl extends ServiceImpl<AlarmTsMapper, AlarmTs> impl
         int i=0;
         for (AlarmTag tag:alarmTags) {
 
-            if(tag.getVal()==1)
-            {
-                String tableName = tag.getId();
-                StringBuilder sub_sb = new StringBuilder(tableName);
-
-                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(" ) ");
-                i++;
-                if (i==100) {
-                    alarmTsMapper.insertList(String.valueOf(sb));
-                    sb = new StringBuilder("INSERT INTO ");
-                    i=0;
-                }
-                sb.append(sub_sb);
+            String tableName = tag.getId();
+            StringBuilder sub_sb = new StringBuilder(tableName);
+
+            sub_sb.append( " values ");
+            sub_sb.append(" (");
+            sub_sb.append(tag.getTs()).append(",").append(tag.getVal().intValue()).append(",").append(tag.getConfirmed()).append(",")
+                    .append(tag.getEndts()).append(",").append(tag.getTimeLong());
+            sub_sb.append(" ) ");
+            i++;
+            if (i==100) {
+                alarmTsMapper.insertList(String.valueOf(sb));
+                sb = new StringBuilder("INSERT INTO ");
+                i=0;
             }
+            sb.append(sub_sb);
 
         }
 
@@ -122,7 +117,6 @@ public class AlarmTsServiceImpl extends ServiceImpl<AlarmTsMapper, AlarmTs> impl
         }
 
     }
-
     public List<AlarmVo> findTags(String stbaleName)
     {
         List<AlarmVo> ls=new ArrayList<>();
@@ -157,4 +151,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;
+    }
 }

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

@@ -28,12 +28,12 @@ public class ProEconAlarmConfigurationServiceImpl extends ServiceImpl<ProEconAla
     public IPage<ProEconAlarmConfiguration> pageQueryAll(Page page,
                                          String description,
                                          String wpId,
-                                         String modelId)
+                                         String modelId,String alarmType)
     {
         IPage<ProEconAlarmConfiguration> pages=  proEconAlarmConfigurationMapper.pageQueryAll(page,
                 description,
                  wpId,
-                 modelId);
+                 modelId, alarmType);
 
         return pages;
     }

File diff suppressed because it is too large
+ 2742 - 1032
log/ota.log


BIN
log/ota.log.2023-08-18.0.gz


BIN
log/ota.log.2023-08-28.0.gz


BIN
log/ota.log.2023-08-30.0.gz