Kaynağa Gözat

实现庚顿数据库的标准接口类,并实现测试和bug修复

shilin 4 ay önce
ebeveyn
işleme
163d603989
37 değiştirilmiş dosya ile 6816 ekleme ve 6118 silme
  1. 4211 5767
      log/ota.log
  2. 46 86
      pom.xml
  3. 3 3
      src/main/java/com/gyee/generation/init/CacheContext.java
  4. 2 2
      src/main/java/com/gyee/generation/model/auto/ProBasicPowerstation.java
  5. 46 46
      src/main/java/com/gyee/generation/processors/StandaloneProcessor2Demo.java
  6. 48 48
      src/main/java/com/gyee/generation/processors/StandaloneProcessor3Demo.java
  7. 45 45
      src/main/java/com/gyee/generation/processors/StandaloneProcessor4Demo.java
  8. 520 51
      src/main/java/com/gyee/generation/processors/StandaloneProcessorDemo.java
  9. 209 0
      src/main/java/com/gyee/generation/service/function/RfdlService.java
  10. 1 1
      src/main/java/com/gyee/generation/service/initalcache/CacheService.java
  11. 1 1
      src/main/java/com/gyee/generation/service/initialpoint/InitialPointService.java
  12. 1 1
      src/main/java/com/gyee/generation/service/initialpoint/InitialTaosPointService.java
  13. 2 1
      src/main/java/com/gyee/generation/service/initialpoint/TaosInitalPonitService.java
  14. 1 1
      src/main/java/com/gyee/generation/util/realtimesource/TaosUtil.java
  15. 1 1
      src/main/java/com/gyee/generation/util/redis/RedisServiceImpl.java
  16. 152 0
      src/main/java/com/gyee/generation/util/rule/AlarmFunction.java
  17. 40 0
      src/main/java/com/gyee/generation/util/rule/AlarmFunctionAVG.java
  18. 51 0
      src/main/java/com/gyee/generation/util/rule/AlarmFunctionLastUpdateTime.java
  19. 113 0
      src/main/java/com/gyee/generation/util/rule/AlarmFunctionMAR.java
  20. 48 0
      src/main/java/com/gyee/generation/util/rule/AlarmFunctionMAX.java
  21. 40 0
      src/main/java/com/gyee/generation/util/rule/AlarmFunctionMIN.java
  22. 94 0
      src/main/java/com/gyee/generation/util/rule/AlarmFunctionMR.java
  23. 95 0
      src/main/java/com/gyee/generation/util/rule/AlarmFunctionRiseExceed.java
  24. 68 0
      src/main/java/com/gyee/generation/util/rule/AlarmFunctionSustain.java
  25. 229 0
      src/main/java/com/gyee/generation/util/rule/AlarmRule.java
  26. 39 0
      src/main/java/com/gyee/generation/util/rule/AlarmScript.java
  27. 43 0
      src/main/java/com/gyee/generation/util/rule/ScriptShell.java
  28. 63 0
      src/main/java/com/gyee/generation/util/rule/expression/AlarmExpression.java
  29. 221 0
      src/main/java/com/gyee/generation/util/rule/expression/Analyzer.java
  30. 56 0
      src/main/java/com/gyee/generation/util/rule/expression/DeviceTypeValue.java
  31. 53 0
      src/main/java/com/gyee/generation/util/rule/expression/FunctionValue.java
  32. 9 0
      src/main/java/com/gyee/generation/util/rule/expression/Token.java
  33. 12 0
      src/main/java/com/gyee/generation/util/rule/expression/TokenType.java
  34. 54 0
      src/main/java/com/gyee/generation/util/rule/expression/TypeValue.java
  35. 20 19
      src/main/resources/application-jn.yml
  36. 30 30
      src/test/java/com/gyee/generation/GenerationTest.java
  37. 149 15
      src/test/java/com/gyee/generation/TaosTest.java

Dosya farkı çok büyük olduğundan ihmal edildi
+ 4211 - 5767
log/ota.log


+ 46 - 86
pom.xml

@@ -13,54 +13,34 @@
 
     <properties>
 
-        <springboot.version>3.2.2</springboot.version>
+        <springboot.version>2.7.18</springboot.version>
         <powerjob.worker.starter.version>4.3.9</powerjob.worker.starter.version>
         <fastjson.version>1.2.83</fastjson.version>
-        <lombok.version>1.18.32</lombok.version>
+        <lombok.version>1.18.12</lombok.version>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
         <java.version>1.8</java.version>
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
         <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
+        <mybatis.spring.boot.version>2.3.2</mybatis.spring.boot.version>
+        <mybatis-plus.boot.starter.version>3.5.5</mybatis-plus.boot.starter.version>
+        <mybatis-plus.generator.version>3.5.5</mybatis-plus.generator.version>
 
-        <druid.version>1.2.21</druid.version>
+        <druid.version>1.2.5</druid.version>
         <mariadb.version>3.4.0</mariadb.version>
-
+        <taosdata.version>3.2.11</taosdata.version>
         <hutool.version>5.8.27</hutool.version>
-
+        <dynamic-datasource.version>4.3.0</dynamic-datasource.version>
         <netty.version>4.1.110.Final</netty.version>
         <poi.version>3.17</poi.version>
-        <freemarker.version>2.3.28</freemarker.version>
-
-
-        <taosdata.version>3.2.11</taosdata.version>
-
-        <dynamic-datasource.version>4.3.0</dynamic-datasource.version>
-        <mybatis-plus.version>3.5.5</mybatis-plus.version>
-        <mybatis-plus-generator.version>3.5.5</mybatis-plus-generator.version>
-
     </properties>
 
     <dependencies>
-
-        <!--mybatis-plus 代码生成器的模板引擎-->
-        <dependency>
-            <groupId>org.apache.velocity</groupId>
-            <artifactId>velocity-engine-core</artifactId>
-            <version>2.3</version>
-        </dependency>
-
         <dependency>
-            <groupId>org.freemarker</groupId>
-            <artifactId>freemarker</artifactId>
-            <version>${freemarker.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>com.mysql</groupId>
-            <artifactId>mysql-connector-j</artifactId>
-            <version>8.0.31</version>
+            <groupId>org.apache.groovy</groupId>
+            <artifactId>groovy</artifactId>
+            <version>4.0.22</version>
         </dependency>
         <dependency>
             <groupId>org.apache.poi</groupId>
@@ -69,46 +49,26 @@
             <scope>compile</scope>
         </dependency>
         <!-- powerjob -->
-<!--        <dependency>-->
-<!--            <groupId>tech.powerjob</groupId>-->
-<!--            <artifactId>powerjob-worker-spring-boot-starter</artifactId>-->
-<!--            <version>${powerjob.worker.starter.version}</version>-->
-<!--        </dependency>-->
-
-<!--        <dependency>-->
-<!--        <groupId>tech.powerjob</groupId>-->
-<!--        <artifactId>powerjob-official-processors</artifactId>-->
-<!--        <version>${powerjob.worker.starter.version}</version>-->
-<!--        </dependency>-->
-<!--        <dependency>-->
-<!--            <groupId>tech.powerjob</groupId>-->
-<!--            <artifactId>powerjob-worker-spring-boot-starter</artifactId>-->
-<!--            <version>${powerjob.worker.starter.version}</version>-->
-<!--        </dependency>-->
-
-
-        <!-- SpringBoot -->
         <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-web</artifactId>
-            <version>${springboot.version}</version>
+            <groupId>tech.powerjob</groupId>
+            <artifactId>powerjob-worker-spring-boot-starter</artifactId>
+            <version>${powerjob.worker.starter.version}</version>
         </dependency>
+
         <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter</artifactId>
-            <version>${springboot.version}</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.springframework.boot</groupId>
-                    <artifactId>spring-boot-starter-logging</artifactId>
-                </exclusion>
-            </exclusions>
+            <groupId>tech.powerjob</groupId>
+            <artifactId>powerjob-official-processors</artifactId>
+            <version>${powerjob.worker.starter.version}</version>
         </dependency>
+
+
+        <!-- SpringBoot -->
         <dependency>
             <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-log4j2</artifactId>
+            <artifactId>spring-boot-starter-web</artifactId>
             <version>${springboot.version}</version>
         </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-autoconfigure</artifactId>
@@ -122,6 +82,11 @@
             <scope>test</scope>
         </dependency>
 
+        <dependency>
+            <groupId>tech.powerjob</groupId>
+            <artifactId>powerjob-worker-spring-boot-starter</artifactId>
+            <version>${powerjob.worker.starter.version}</version>
+        </dependency>
 
         <dependency>
             <groupId>com.alibaba</groupId>
@@ -144,7 +109,12 @@
             <version>2.3.1</version>
         </dependency>
         -->
-
+        <!-- druid -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid</artifactId>
+            <version>${druid.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.mariadb.jdbc</groupId>
             <artifactId>mariadb-java-client</artifactId>
@@ -163,7 +133,11 @@
             <version>${hutool.version}</version>
         </dependency>
 
-
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
+            <version>${dynamic-datasource.version}</version>
+        </dependency>
 
         <dependency>
             <groupId>org.springframework.boot</groupId>
@@ -171,41 +145,27 @@
             <version>${springboot.version}</version>
         </dependency>
 
-
         <dependency>
-            <groupId>com.baomidou</groupId>
-            <artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
-            <version>${dynamic-datasource.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>com.alibaba</groupId>
-            <artifactId>druid-spring-boot-3-starter</artifactId>
-            <version>${druid.version}</version>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>${mybatis.spring.boot.version}</version>
         </dependency>
         <dependency>
             <groupId>com.baomidou</groupId>
-            <artifactId>mybatis-plus-spring-boot3-starter</artifactId>
-            <version>${mybatis-plus.version}</version>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>${mybatis-plus.boot.starter.version}</version>
         </dependency>
         <dependency>
             <groupId>com.baomidou</groupId>
-            <artifactId>mybatis-plus-generator</artifactId> <!-- 代码生成器,使用它解析表结构 -->
-            <version>${mybatis-plus-generator.version}</version>
+            <artifactId>mybatis-plus-generator</artifactId>
+            <version>${mybatis-plus.generator.version}</version>
         </dependency>
 
-
-
         <dependency>
             <groupId>io.netty</groupId>
             <artifactId>netty-all</artifactId>
             <version>${netty.version}</version>
         </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>4.13.1</version>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 
     <!-- SpringBoot专用的打包插件 -->

+ 3 - 3
src/main/java/com/gyee/generation/init/CacheContext.java

@@ -11,14 +11,14 @@ import com.gyee.generation.util.realtimesource.TaosUtil;
 import com.gyee.generation.util.realtimesource.timeseries.PointData;
 import com.gyee.generation.util.redis.RedisService;
 import com.gyee.generation.util.rule.expression.DeviceTypeValue;
-import jakarta.annotation.Resource;
+import javax.annotation.Resource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.stereotype.Component;
 
-import jakarta.annotation.Resource;
+import javax.annotation.Resource;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -142,7 +142,7 @@ public class CacheContext implements CommandLineRunner {
     @Override
     public void run(String... args) throws Exception {
         logger.info("缓存开始------------------------------------------------------------");
-
+        redisService.select(2);
 
         List<String> runWpids = Arrays.asList(runWindpowerstation.split(","));
         logger.info(runWpids.get(0) + "------------------" + runWpids.size());

+ 2 - 2
src/main/java/com/gyee/generation/model/auto/ProBasicPowerstation.java

@@ -71,12 +71,12 @@ public class ProBasicPowerstation extends Model {
     /**
      * 光伏装机容量
      */
-    private BigDecimal capacity2;
+    private BigDecimal capacity;
 
     /**
      * 光伏容量单位
      */
-    private String capacityUnit2;
+    private String capacityUnit;
 
     /**
      * 光伏装机数量集中

+ 46 - 46
src/main/java/com/gyee/generation/processors/StandaloneProcessor2Demo.java

@@ -1,46 +1,46 @@
-//package com.gyee.generation.processors;
-//
-//import lombok.extern.slf4j.Slf4j;
-//import org.springframework.stereotype.Component;
-//import tech.powerjob.official.processors.CommonBasicProcessor;
-//import tech.powerjob.worker.core.processor.ProcessResult;
-//import tech.powerjob.worker.core.processor.TaskContext;
-//import tech.powerjob.worker.core.processor.WorkflowContext;
-//import tech.powerjob.worker.log.OmsLogger;
-//
-//import java.util.Map;
-//
-///**
-// * @description: 工作流调度任务测试
-// * @author: shilin
-// * @date: 2024/5/29 9:19
-// * @param:
-// * @return:
-// **/
-//@Slf4j
-//@Component("testBaseProcessor2")
-//public class StandaloneProcessor2Demo extends CommonBasicProcessor {
-//
-//    @Override
-//    protected ProcessResult process0(TaskContext taskContext) {
-//
-//        String jobParams = taskContext.getJobParams();
-//        OmsLogger omsLogger = taskContext.getOmsLogger();
-//        try {
-//
-//            WorkflowContext workflowContext = taskContext.getWorkflowContext();
-//            workflowContext.appendData2WfContext("test2", "2");
-//
-//            Map<String, String> map=  workflowContext.fetchWorkflowContext();
-//
-//            for (Map.Entry<String, String> entry : map.entrySet()) {
-//                workflowContext.appendData2WfContext(entry.getKey(), entry.getValue());
-//                omsLogger.info("inject context, {}:{}", entry.getKey(), entry.getValue());
-//            }
-//        } catch (Exception e) {
-//            omsLogger.error("Fail to parse job params:{},it is not a valid json string!", jobParams, e);
-//            return new ProcessResult(false);
-//        }
-//        return new ProcessResult(true);
-//    }
-//}
+package com.gyee.generation.processors;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import tech.powerjob.official.processors.CommonBasicProcessor;
+import tech.powerjob.worker.core.processor.ProcessResult;
+import tech.powerjob.worker.core.processor.TaskContext;
+import tech.powerjob.worker.core.processor.WorkflowContext;
+import tech.powerjob.worker.log.OmsLogger;
+
+import java.util.Map;
+
+/**
+ * @description: 工作流调度任务测试
+ * @author: shilin
+ * @date: 2024/5/29 9:19
+ * @param:
+ * @return:
+ **/
+@Slf4j
+@Component("testBaseProcessor2")
+public class StandaloneProcessor2Demo extends CommonBasicProcessor {
+
+    @Override
+    protected ProcessResult process0(TaskContext taskContext) {
+
+        String jobParams = taskContext.getJobParams();
+        OmsLogger omsLogger = taskContext.getOmsLogger();
+        try {
+
+            WorkflowContext workflowContext = taskContext.getWorkflowContext();
+            workflowContext.appendData2WfContext("test2", "2");
+
+            Map<String, String> map=  workflowContext.fetchWorkflowContext();
+
+            for (Map.Entry<String, String> entry : map.entrySet()) {
+                workflowContext.appendData2WfContext(entry.getKey(), entry.getValue());
+                omsLogger.info("inject context, {}:{}", entry.getKey(), entry.getValue());
+            }
+        } catch (Exception e) {
+            omsLogger.error("Fail to parse job params:{},it is not a valid json string!", jobParams, e);
+            return new ProcessResult(false);
+        }
+        return new ProcessResult(true);
+    }
+}

+ 48 - 48
src/main/java/com/gyee/generation/processors/StandaloneProcessor3Demo.java

@@ -1,48 +1,48 @@
-//package com.gyee.generation.processors;
-//
-//
-//import lombok.extern.slf4j.Slf4j;
-//import org.springframework.stereotype.Component;
-//import tech.powerjob.official.processors.CommonBasicProcessor;
-//import tech.powerjob.worker.core.processor.ProcessResult;
-//import tech.powerjob.worker.core.processor.TaskContext;
-//import tech.powerjob.worker.core.processor.WorkflowContext;
-//import tech.powerjob.worker.log.OmsLogger;
-//
-//import java.util.Date;
-//import java.util.Map;
-//
-///**
-// * @description: 工作流调度任务测试
-// * @author: shilin
-// * @date: 2024/5/29 9:19
-// * @param:
-// * @return:
-// **/
-//@Slf4j
-//@Component("testBaseProcessor3")
-//public class StandaloneProcessor3Demo extends CommonBasicProcessor {
-//
-//    @Override
-//    protected ProcessResult process0(TaskContext taskContext) {
-//
-//        String jobParams = taskContext.getJobParams();
-//        OmsLogger omsLogger = taskContext.getOmsLogger();
-//        try {
-//
-//            WorkflowContext workflowContext = taskContext.getWorkflowContext();
-//
-//            workflowContext.appendData2WfContext("test3", new Date());
-//
-//            Map<String, String> map=  workflowContext.fetchWorkflowContext();
-//            for (Map.Entry<String, String> entry : map.entrySet()) {
-//                workflowContext.appendData2WfContext(entry.getKey(), entry.getValue());
-//                omsLogger.info("inject context, {}:{}", entry.getKey(), entry.getValue());
-//            }
-//        } catch (Exception e) {
-//            omsLogger.error("Fail to parse job params:{},it is not a valid json string!", jobParams, e);
-//            return new ProcessResult(false);
-//        }
-//        return new ProcessResult(true);
-//    }
-//}
+package com.gyee.generation.processors;
+
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import tech.powerjob.official.processors.CommonBasicProcessor;
+import tech.powerjob.worker.core.processor.ProcessResult;
+import tech.powerjob.worker.core.processor.TaskContext;
+import tech.powerjob.worker.core.processor.WorkflowContext;
+import tech.powerjob.worker.log.OmsLogger;
+
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * @description: 工作流调度任务测试
+ * @author: shilin
+ * @date: 2024/5/29 9:19
+ * @param:
+ * @return:
+ **/
+@Slf4j
+@Component("testBaseProcessor3")
+public class StandaloneProcessor3Demo extends CommonBasicProcessor {
+
+    @Override
+    protected ProcessResult process0(TaskContext taskContext) {
+
+        String jobParams = taskContext.getJobParams();
+        OmsLogger omsLogger = taskContext.getOmsLogger();
+        try {
+
+            WorkflowContext workflowContext = taskContext.getWorkflowContext();
+
+            workflowContext.appendData2WfContext("test3", new Date());
+
+            Map<String, String> map=  workflowContext.fetchWorkflowContext();
+            for (Map.Entry<String, String> entry : map.entrySet()) {
+                workflowContext.appendData2WfContext(entry.getKey(), entry.getValue());
+                omsLogger.info("inject context, {}:{}", entry.getKey(), entry.getValue());
+            }
+        } catch (Exception e) {
+            omsLogger.error("Fail to parse job params:{},it is not a valid json string!", jobParams, e);
+            return new ProcessResult(false);
+        }
+        return new ProcessResult(true);
+    }
+}

+ 45 - 45
src/main/java/com/gyee/generation/processors/StandaloneProcessor4Demo.java

@@ -1,45 +1,45 @@
-//package com.gyee.generation.processors;
-//
-//import lombok.extern.slf4j.Slf4j;
-//import org.springframework.stereotype.Component;
-//import tech.powerjob.official.processors.CommonBasicProcessor;
-//import tech.powerjob.worker.core.processor.ProcessResult;
-//import tech.powerjob.worker.core.processor.TaskContext;
-//import tech.powerjob.worker.core.processor.WorkflowContext;
-//import tech.powerjob.worker.log.OmsLogger;
-//
-//import java.util.Map;
-//
-///**
-// * @description: 工作流调度任务测试
-// * @author: shilin
-// * @date: 2024/5/29 9:19
-// * @param:
-// * @return:
-// **/
-//@Slf4j
-//@Component("testBaseProcessor4")
-//public class StandaloneProcessor4Demo extends CommonBasicProcessor {
-//
-//    @Override
-//    protected ProcessResult process0(TaskContext taskContext) {
-//
-//        String jobParams = taskContext.getJobParams();
-//        OmsLogger omsLogger = taskContext.getOmsLogger();
-//        try {
-//
-//            WorkflowContext workflowContext = taskContext.getWorkflowContext();
-//
-//            workflowContext.appendData2WfContext("test4", true);
-//            Map<String, String> map=  workflowContext.fetchWorkflowContext();
-//            for (Map.Entry<String, String> entry : map.entrySet()) {
-//                workflowContext.appendData2WfContext(entry.getKey(), entry.getValue());
-//                omsLogger.info("inject context, {}:{}", entry.getKey(), entry.getValue());
-//            }
-//        } catch (Exception e) {
-//            omsLogger.error("Fail to parse job params:{},it is not a valid json string!", jobParams, e);
-//            return new ProcessResult(false);
-//        }
-//        return new ProcessResult(true);
-//    }
-//}
+package com.gyee.generation.processors;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import tech.powerjob.official.processors.CommonBasicProcessor;
+import tech.powerjob.worker.core.processor.ProcessResult;
+import tech.powerjob.worker.core.processor.TaskContext;
+import tech.powerjob.worker.core.processor.WorkflowContext;
+import tech.powerjob.worker.log.OmsLogger;
+
+import java.util.Map;
+
+/**
+ * @description: 工作流调度任务测试
+ * @author: shilin
+ * @date: 2024/5/29 9:19
+ * @param:
+ * @return:
+ **/
+@Slf4j
+@Component("testBaseProcessor4")
+public class StandaloneProcessor4Demo extends CommonBasicProcessor {
+
+    @Override
+    protected ProcessResult process0(TaskContext taskContext) {
+
+        String jobParams = taskContext.getJobParams();
+        OmsLogger omsLogger = taskContext.getOmsLogger();
+        try {
+
+            WorkflowContext workflowContext = taskContext.getWorkflowContext();
+
+            workflowContext.appendData2WfContext("test4", true);
+            Map<String, String> map=  workflowContext.fetchWorkflowContext();
+            for (Map.Entry<String, String> entry : map.entrySet()) {
+                workflowContext.appendData2WfContext(entry.getKey(), entry.getValue());
+                omsLogger.info("inject context, {}:{}", entry.getKey(), entry.getValue());
+            }
+        } catch (Exception e) {
+            omsLogger.error("Fail to parse job params:{},it is not a valid json string!", jobParams, e);
+            return new ProcessResult(false);
+        }
+        return new ProcessResult(true);
+    }
+}

+ 520 - 51
src/main/java/com/gyee/generation/processors/StandaloneProcessorDemo.java

@@ -1,51 +1,520 @@
-//package com.gyee.generation.processors;
-//
-//import com.alibaba.fastjson.JSON;
-//import com.alibaba.fastjson.TypeReference;
-//import lombok.extern.slf4j.Slf4j;
-//import org.springframework.stereotype.Component;
-//import tech.powerjob.official.processors.CommonBasicProcessor;
-//import tech.powerjob.worker.core.processor.ProcessResult;
-//import tech.powerjob.worker.core.processor.TaskContext;
-//import tech.powerjob.worker.core.processor.WorkflowContext;
-//import tech.powerjob.worker.log.OmsLogger;
-//
-//import java.util.HashMap;
-//import java.util.Map;
-//
-///**
-// * @description: 工作流调度任务测试
-// * @author: shilin
-// * @date: 2024/5/29 9:19
-// * @param:
-// * @return:
-// **/
-//@Slf4j
-//@Component("testBaseProcessor")
-//public class StandaloneProcessorDemo extends CommonBasicProcessor {
-//
-//    @Override
-//    protected ProcessResult process0(TaskContext taskContext) {
-//
-//        String jobParams = taskContext.getJobParams();
-//        OmsLogger omsLogger = taskContext.getOmsLogger();
-//        try {
-//            HashMap<String, Object> data = JSON.parseObject(jobParams, new TypeReference<HashMap<String, Object>>() {
-//            });
-//            WorkflowContext workflowContext = taskContext.getWorkflowContext();
-//            for (Map.Entry<String, Object> entry : data.entrySet()) {
-//                workflowContext.appendData2WfContext(entry.getKey(), entry.getValue());
-//                omsLogger.info("inject context, {}:{}", entry.getKey(), entry.getValue());
-//            }
-//
-//            workflowContext.appendData2WfContext("test1", 1);
-////            workflowContext.appendData2WfContext("test2", "2");
-////            workflowContext.appendData2WfContext("test3", new Date());
-////            workflowContext.appendData2WfContext("test4", true);
-//        } catch (Exception e) {
-//            omsLogger.error("Fail to parse job params:{},it is not a valid json string!", jobParams, e);
-//            return new ProcessResult(false);
-//        }
-//        return new ProcessResult(true);
-//    }
-//}
+package com.gyee.generation.processors;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.TypeReference;
+import com.gyee.generation.init.CacheContext;
+import com.gyee.generation.model.auto.*;
+import com.gyee.generation.util.realtimesource.TaosUtil;
+import com.gyee.generation.util.rule.AlarmFunction;
+import com.gyee.generation.util.rule.expression.*;
+
+import javax.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+import tech.powerjob.official.processors.CommonBasicProcessor;
+import tech.powerjob.worker.core.processor.ProcessResult;
+import tech.powerjob.worker.core.processor.TaskContext;
+import tech.powerjob.worker.core.processor.WorkflowContext;
+import tech.powerjob.worker.log.OmsLogger;
+
+import java.sql.Timestamp;
+import java.util.*;
+
+
+/**
+ * @description: 工作流调度任务测试
+ * @author: shilin
+ * @date: 2024/5/29 9:19
+ * @param:
+ * @return:
+ **/
+@Slf4j
+@Component("testBaseProcessor")
+public class StandaloneProcessorDemo extends CommonBasicProcessor {
+
+    @Resource
+    private TaosUtil taosUtil;
+    @Override
+    protected ProcessResult process0(TaskContext taskContext) {
+
+        String jobParams = taskContext.getJobParams();
+        OmsLogger omsLogger = taskContext.getOmsLogger();
+        try {
+            HashMap<String, Object> data = JSON.parseObject(jobParams, new TypeReference<HashMap<String, Object>>() {
+            });
+
+            String formula=null;
+            String range=null;
+            String type=null;
+            String result=null;
+            String points=null;
+            String value=null;
+
+            WorkflowContext workflowContext = taskContext.getWorkflowContext();
+
+            for (Map.Entry<String, Object> entry : data.entrySet()) {
+
+                if(entry.getKey().equals("formula"))
+                {
+                    formula=(String)entry.getValue();
+                }
+
+                if(entry.getKey().equals("range"))
+                {
+                    range=(String)entry.getValue();
+                }
+
+                if(entry.getKey().equals("type"))
+                {
+                    type=(String)entry.getValue();
+                }
+
+                if(entry.getKey().equals("result"))
+                {
+                    result=(String)entry.getValue();
+                }
+
+                if(entry.getKey().equals("points"))
+                {
+                    points=(String)entry.getValue();
+                }
+
+                if(entry.getKey().equals("value"))
+                {
+                    value=(String)entry.getValue();
+                }
+            }
+
+
+            List<PointDataTaos> pointDataTaosLs=new ArrayList();
+
+            if(ObjectUtil.isNotEmpty(type) && StrUtil.isNotEmpty(type))
+            {
+                if(TypeValue.ASSIGN.getCode().equals(type))
+                {
+                    assign(points,range, result,value, pointDataTaosLs);
+                }else  if(TypeValue.BASIC.getCode().equals(type))
+                {
+                    if(FunctionValue.RFDL.getCode().equals(result))
+                    {
+
+                    }
+                }else  if(TypeValue.CUSTOM.getCode().equals(type))
+                {
+                    AlarmExpression alarmExpression = Analyzer.getAlarmExpression(formula);
+                    custom(range, result, alarmExpression, pointDataTaosLs);
+                }
+            }
+
+
+
+            workflowContext.appendData2WfContext("resultValue", "ok!");
+
+
+        } catch (Exception e) {
+            omsLogger.error("Fail to parse job params:{},it is not a valid json string!", jobParams, e,"error!");
+            return new ProcessResult(false);
+        }
+        return new ProcessResult(true);
+    }
+
+
+    private void assign(String points,String range, String result,String value, List<PointDataTaos> pointDataTaosLs) {
+
+
+            if(ObjectUtil.isNotEmpty(points) && StrUtil.isNotEmpty(points) && ObjectUtil.isNotEmpty(value) && StrUtil.isNotEmpty(value))
+            {
+                String[] pointids= points.split(",");
+                List<String> ls = Arrays.asList(pointids);
+
+                for(String id:ls)
+                {
+
+                    PointDataTaos pt=new PointDataTaos();
+                    pt.setId(id);
+                    pt.setTs(new Timestamp(System.currentTimeMillis()));
+                    pt.setVal(Double.valueOf(value));
+                    pt.setMetric(1);
+                    pointDataTaosLs.add(pt);
+                }
+            }else  if(ObjectUtil.isNotEmpty(range) && StrUtil.isNotEmpty(range))
+            {
+                String[] ranges= range.split(",");
+                List<String> ls = Arrays.asList(ranges);
+
+                if(!ls.isEmpty())
+                {
+                    if(ls.contains("WT"))
+                    {
+                        List<ProBasicEquipment> wtls= CacheContext.wtls;
+                        for(ProBasicEquipment wt:wtls)
+                        {
+                                if(CacheContext.eqpointmap.containsKey(wt.getNemCode()))
+                                {
+                                    Map<String, ProBasicEquipmentPoint> map=CacheContext.eqpointmap.get(wt.getNemCode());
+
+                                    equipmentCal(result, pointDataTaosLs, map,value);
+                                }
+                        }
+                    }else   if(ls.contains("LN"))
+                    {
+                        List<ProBasicLine> lnls= CacheContext.lnls;
+                        for(ProBasicLine ln:lnls)
+                        {
+
+                                if(CacheContext.linepointmap.containsKey(ln.getNemCode()))
+                                {
+                                    Map<String, ProBasicPowerstationPoint> map=CacheContext.linepointmap.get(ln.getNemCode());
+
+                                    powerstationCal(result, pointDataTaosLs, map,value);
+                                }
+
+
+                        }
+                    }else   if(ls.contains("PJ"))
+                    {
+                        List<ProBasicProject> pjls= CacheContext.pjls;
+                        for(ProBasicProject pj:pjls)
+                        {
+
+
+                                if(CacheContext.propointmap.containsKey(pj.getNemCode()))
+                                {
+                                    Map<String, ProBasicPowerstationPoint> map=CacheContext.propointmap.get(pj.getNemCode());
+
+                                    powerstationCal(result, pointDataTaosLs, map,value);
+                                }
+
+
+                        }
+                    }
+                    else   if(ls.contains("WP"))
+                    {
+                        List<ProBasicPowerstation> wpls= CacheContext.wpls;
+                        for(ProBasicPowerstation wp:wpls)
+                        {
+
+
+                                if(CacheContext.wppointmap.containsKey(wp.getNemCode()))
+                                {
+                                    Map<String, ProBasicPowerstationPoint> map=CacheContext.wppointmap.get(wp.getNemCode());
+
+                                    powerstationCal(result, pointDataTaosLs, map,value);
+                                }
+
+
+                        }
+                    }else   if(ls.contains("CP"))
+                    {
+                        List<ProBasicCompany> cpls= CacheContext.cpls;
+                        for(ProBasicCompany cp:cpls)
+                        {
+
+
+                                if(CacheContext.companypointmap.containsKey(cp.getNemCode()))
+                                {
+                                    Map<String, ProBasicPowerstationPoint> map=CacheContext.companypointmap.get(cp.getNemCode());
+
+                                    powerstationCal(result, pointDataTaosLs, map,value);
+                                }
+
+
+                        }
+                    }else   if(ls.contains("RG"))
+                    {
+                        List<ProBasicRegion> rgls= CacheContext.rgls;
+                        for(ProBasicRegion rg:rgls)
+                        {
+
+
+                                if(CacheContext.regionpointmap.containsKey(rg.getNemCode()))
+                                {
+                                    Map<String, ProBasicPowerstationPoint> map=CacheContext.regionpointmap.get(rg.getNemCode());
+
+                                    powerstationCal(result, pointDataTaosLs, map,value);
+                                }
+
+
+                        }
+                    }else   if(ls.contains("EG"))
+                    {
+                        List<ProBasicEnergyGroup> egls= CacheContext.egls;
+                        for(ProBasicEnergyGroup eg:egls)
+                        {
+
+                                if(CacheContext.grouppointmap.containsKey(eg.getNemCode()))
+                                {
+                                    Map<String, ProBasicPowerstationPoint> map=CacheContext.grouppointmap.get(eg.getNemCode());
+
+                                    powerstationCal(result, pointDataTaosLs, map,value);
+                                }
+
+
+                        }
+                    }
+
+
+
+                    if(!pointDataTaosLs.isEmpty())
+                    {
+                        taosUtil.sendSinglePoint(pointDataTaosLs);
+                    }
+
+                }
+
+            }
+        }
+    private void custom(String range, String result, AlarmExpression alarmExpression, List<PointDataTaos> pointDataTaosLs) {
+
+        AlarmFunction alarmFunction = null;
+
+        if(ObjectUtil.isNotEmpty(range) && StrUtil.isNotEmpty(range))
+        {
+            String[] ranges= range.split(",");
+            List<String> ls = Arrays.asList(ranges);
+
+            if(!ls.isEmpty())
+            {
+                if(ls.contains("WT"))
+                {
+                    List<ProBasicEquipment> wtls= CacheContext.wtls;
+                    for(ProBasicEquipment wt:wtls)
+                    {
+                        alarmFunction = new AlarmFunction(alarmExpression, DeviceTypeValue.WT, wt.getNemCode());
+                        try {
+
+                            Object obj = alarmFunction.explain();
+                            double value = 0;
+                            if (obj instanceof Double) {
+
+                                value =(Double)obj;
+                            }
+
+                            if(CacheContext.eqpointmap.containsKey(wt.getNemCode()))
+                            {
+                                Map<String, ProBasicEquipmentPoint> map=CacheContext.eqpointmap.get(wt.getNemCode());
+
+                                equipmentCal(result, pointDataTaosLs, map,String.valueOf(value));
+                            }
+                        }catch (Exception ex) {
+                            ex.printStackTrace();
+                        }
+
+                    }
+                }else   if(ls.contains("LN"))
+                {
+                    List<ProBasicLine> lnls= CacheContext.lnls;
+                    for(ProBasicLine ln:lnls)
+                    {
+                        alarmFunction = new AlarmFunction(alarmExpression, DeviceTypeValue.LN, ln.getNemCode());
+                        try {
+
+                            Object obj = alarmFunction.explain();
+                            double value = 0;
+                            if (obj instanceof Double) {
+
+                                value =(Double)obj;
+                            }
+
+                            if(CacheContext.linepointmap.containsKey(ln.getNemCode()))
+                            {
+                                Map<String, ProBasicPowerstationPoint> map=CacheContext.linepointmap.get(ln.getNemCode());
+
+                                powerstationCal(result, pointDataTaosLs, map,String.valueOf(value));
+                            }
+                        }catch (Exception ex) {
+                            ex.printStackTrace();
+                        }
+
+                    }
+                }else   if(ls.contains("PJ"))
+                {
+                    List<ProBasicProject> pjls= CacheContext.pjls;
+                    for(ProBasicProject pj:pjls)
+                    {
+                        alarmFunction = new AlarmFunction(alarmExpression, DeviceTypeValue.PJ, pj.getNemCode());
+                        try {
+
+                            Object obj = alarmFunction.explain();
+                            double value = 0;
+                            if (obj instanceof Double) {
+
+                                value =(Double)obj;
+                            }
+
+                            if(CacheContext.propointmap.containsKey(pj.getNemCode()))
+                            {
+                                Map<String, ProBasicPowerstationPoint> map=CacheContext.propointmap.get(pj.getNemCode());
+
+                                powerstationCal(result, pointDataTaosLs, map,String.valueOf(value));
+                            }
+                        }catch (Exception ex) {
+                            ex.printStackTrace();
+                        }
+
+                    }
+                }
+                else   if(ls.contains("WP"))
+                {
+                    List<ProBasicPowerstation> wpls= CacheContext.wpls;
+                    for(ProBasicPowerstation wp:wpls)
+                    {
+                        alarmFunction = new AlarmFunction(alarmExpression, DeviceTypeValue.WP, wp.getNemCode());
+                        try {
+
+                            Object obj = alarmFunction.explain();
+                            double value = 0;
+                            if (obj instanceof Double) {
+
+                                value =(Double)obj;
+                            }
+
+                            if(CacheContext.wppointmap.containsKey(wp.getNemCode()))
+                            {
+                                Map<String, ProBasicPowerstationPoint> map=CacheContext.wppointmap.get(wp.getNemCode());
+
+                                powerstationCal(result, pointDataTaosLs, map,String.valueOf(value));
+                            }
+                        }catch (Exception ex) {
+                            ex.printStackTrace();
+                        }
+
+                    }
+                }else   if(ls.contains("CP"))
+                {
+                    List<ProBasicCompany> cpls= CacheContext.cpls;
+                    for(ProBasicCompany cp:cpls)
+                    {
+                        alarmFunction = new AlarmFunction(alarmExpression, DeviceTypeValue.CP, cp.getNemCode());
+                        try {
+
+                            Object obj = alarmFunction.explain();
+                            double value = 0;
+                            if (obj instanceof Double) {
+
+                                value =(Double)obj;
+                            }
+
+                            if(CacheContext.companypointmap.containsKey(cp.getNemCode()))
+                            {
+                                Map<String, ProBasicPowerstationPoint> map=CacheContext.companypointmap.get(cp.getNemCode());
+
+                                powerstationCal(result, pointDataTaosLs, map,String.valueOf(value));
+                            }
+                        }catch (Exception ex) {
+                            ex.printStackTrace();
+                        }
+
+                    }
+                }else   if(ls.contains("RG"))
+                {
+                    List<ProBasicRegion> rgls= CacheContext.rgls;
+                    for(ProBasicRegion rg:rgls)
+                    {
+                        alarmFunction = new AlarmFunction(alarmExpression, DeviceTypeValue.RG, rg.getNemCode());
+                        try {
+
+                            Object obj = alarmFunction.explain();
+                            double value = 0;
+                            if (obj instanceof Double) {
+
+                                value =(Double)obj;
+                            }
+
+                            if(CacheContext.regionpointmap.containsKey(rg.getNemCode()))
+                            {
+                                Map<String, ProBasicPowerstationPoint> map=CacheContext.regionpointmap.get(rg.getNemCode());
+
+                                powerstationCal(result, pointDataTaosLs, map,String.valueOf(value));
+                            }
+                        }catch (Exception ex) {
+                            ex.printStackTrace();
+                        }
+
+                    }
+                }else   if(ls.contains("EG"))
+                {
+                    List<ProBasicEnergyGroup> egls= CacheContext.egls;
+                    for(ProBasicEnergyGroup eg:egls)
+                    {
+                        alarmFunction = new AlarmFunction(alarmExpression, DeviceTypeValue.EG, eg.getNemCode());
+                        try {
+
+                            Object obj = alarmFunction.explain();
+                            double value = 0;
+                            if (obj instanceof Double) {
+
+                                value =(Double)obj;
+                            }
+
+                            if(CacheContext.grouppointmap.containsKey(eg.getNemCode()))
+                            {
+                                Map<String, ProBasicPowerstationPoint> map=CacheContext.grouppointmap.get(eg.getNemCode());
+
+                                powerstationCal(result, pointDataTaosLs, map,String.valueOf(value));
+                            }
+                        }catch (Exception ex) {
+                            ex.printStackTrace();
+                        }
+
+                    }
+                }
+
+
+
+                if(!pointDataTaosLs.isEmpty())
+                {
+                    taosUtil.sendSinglePoint(pointDataTaosLs);
+                }
+
+            }
+
+        }
+    }
+
+
+    private  void powerstationCal(String result, List<PointDataTaos> pointDataTaosLs, Map<String, ProBasicPowerstationPoint> map,String value) {
+        if(map.containsKey(result)  && ObjectUtil.isNotEmpty(value) && StrUtil.isNotEmpty(value)  )
+        {
+            ProBasicPowerstationPoint point= map.get(result);
+
+            PointDataTaos pt=new PointDataTaos();
+            pt.setId(point.getNemCode());
+            pt.setTs(new Timestamp(System.currentTimeMillis()));
+            pt.setVal(Double.valueOf(value));
+            pt.setMetric(1);
+            pointDataTaosLs.add(pt);
+            if(pointDataTaosLs.size()==100)
+            {
+                taosUtil.sendSinglePoint(pointDataTaosLs);
+                pointDataTaosLs.clear();
+            }
+        }
+    }
+
+    private  void equipmentCal(String result, List<PointDataTaos> pointDataTaosLs, Map<String, ProBasicEquipmentPoint> map,String value) {
+
+
+        if(map.containsKey(result) && ObjectUtil.isNotEmpty(value) && StrUtil.isNotEmpty(value) )
+        {
+
+            ProBasicEquipmentPoint point= map.get(result);
+
+            PointDataTaos pt=new PointDataTaos();
+            pt.setId(point.getNemCode());
+            pt.setTs(new Timestamp(System.currentTimeMillis()));
+            pt.setVal(Double.valueOf(value));
+            pt.setMetric(1);
+            pointDataTaosLs.add(pt);
+
+            if(pointDataTaosLs.size()==100)
+            {
+                taosUtil.sendSinglePoint(pointDataTaosLs);
+                pointDataTaosLs.clear();
+            }
+        }
+    }
+}

+ 209 - 0
src/main/java/com/gyee/generation/service/function/RfdlService.java

@@ -0,0 +1,209 @@
+package com.gyee.generation.service.function;
+
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
+import com.gyee.generation.init.CacheContext;
+import com.gyee.generation.model.auto.*;
+import com.gyee.generation.service.auto.IProBasicCompanyService;
+import com.gyee.generation.service.auto.IProBasicRegionService;
+import com.gyee.generation.service.auto.IProEconTestingPointService;
+import com.gyee.generation.service.initialpoint.IinitialPoint;
+import com.gyee.generation.util.ExcelExport;
+import com.gyee.generation.util.realtimesource.TaosUtil;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Service
+public class RfdlService   {
+
+
+    @Resource
+    private TaosUtil taosUtil;
+
+
+
+    public void basic(String range, String result, List<PointDataTaos> pointDataTaosLs) {
+
+
+     if(ObjectUtil.isNotEmpty(range) && StrUtil.isNotEmpty(range))
+        {
+            String[] ranges= range.split(",");
+            List<String> ls = Arrays.asList(ranges);
+
+            if(!ls.isEmpty())
+            {
+                if(ls.contains("WT"))
+                {
+                    List<ProBasicEquipment> wtls= CacheContext.wtls;
+                    for(ProBasicEquipment wt:wtls)
+                    {
+                        if(CacheContext.eqpointmap.containsKey(wt.getNemCode()))
+                        {
+                            Map<String, ProBasicEquipmentPoint> map=CacheContext.eqpointmap.get(wt.getNemCode());
+
+                            equipmentCal(result, pointDataTaosLs, map);
+                        }
+                    }
+                }else   if(ls.contains("LN"))
+                {
+                    List<ProBasicLine> lnls= CacheContext.lnls;
+                    for(ProBasicLine ln:lnls)
+                    {
+
+                        if(CacheContext.linepointmap.containsKey(ln.getNemCode()))
+                        {
+                            Map<String, ProBasicPowerstationPoint> map=CacheContext.linepointmap.get(ln.getNemCode());
+
+                            powerstationCal(result, pointDataTaosLs, map);
+                        }
+
+
+                    }
+                }else   if(ls.contains("PJ"))
+                {
+                    List<ProBasicProject> pjls= CacheContext.pjls;
+                    for(ProBasicProject pj:pjls)
+                    {
+
+
+                        if(CacheContext.propointmap.containsKey(pj.getNemCode()))
+                        {
+                            Map<String, ProBasicPowerstationPoint> map=CacheContext.propointmap.get(pj.getNemCode());
+
+                            powerstationCal(result, pointDataTaosLs, map);
+                        }
+
+
+                    }
+                }
+                else   if(ls.contains("WP"))
+                {
+                    List<ProBasicPowerstation> wpls= CacheContext.wpls;
+                    for(ProBasicPowerstation wp:wpls)
+                    {
+
+
+                        if(CacheContext.wppointmap.containsKey(wp.getNemCode()))
+                        {
+                            Map<String, ProBasicPowerstationPoint> map=CacheContext.wppointmap.get(wp.getNemCode());
+
+                            powerstationCal(result, pointDataTaosLs, map);
+                        }
+
+
+                    }
+                }else   if(ls.contains("CP"))
+                {
+                    List<ProBasicCompany> cpls= CacheContext.cpls;
+                    for(ProBasicCompany cp:cpls)
+                    {
+
+
+                        if(CacheContext.companypointmap.containsKey(cp.getNemCode()))
+                        {
+                            Map<String, ProBasicPowerstationPoint> map=CacheContext.companypointmap.get(cp.getNemCode());
+
+                            powerstationCal(result, pointDataTaosLs, map);
+                        }
+
+
+                    }
+                }else   if(ls.contains("RG"))
+                {
+                    List<ProBasicRegion> rgls= CacheContext.rgls;
+                    for(ProBasicRegion rg:rgls)
+                    {
+
+
+                        if(CacheContext.regionpointmap.containsKey(rg.getNemCode()))
+                        {
+                            Map<String, ProBasicPowerstationPoint> map=CacheContext.regionpointmap.get(rg.getNemCode());
+
+                            powerstationCal(result, pointDataTaosLs, map);
+                        }
+
+
+                    }
+                }else   if(ls.contains("EG"))
+                {
+                    List<ProBasicEnergyGroup> egls= CacheContext.egls;
+                    for(ProBasicEnergyGroup eg:egls)
+                    {
+
+                        if(CacheContext.grouppointmap.containsKey(eg.getNemCode()))
+                        {
+                            Map<String, ProBasicPowerstationPoint> map=CacheContext.grouppointmap.get(eg.getNemCode());
+
+                            powerstationCal(result, pointDataTaosLs, map);
+                        }
+
+
+                    }
+                }
+
+
+
+                if(!pointDataTaosLs.isEmpty())
+                {
+                    taosUtil.sendSinglePoint(pointDataTaosLs);
+                }
+
+            }
+
+        }
+    }
+
+    private  void powerstationCal(String result, List<PointDataTaos> pointDataTaosLs, Map<String, ProBasicPowerstationPoint> map) {
+        if(map.containsKey(result) )
+        {
+            ProBasicPowerstationPoint point= map.get(result);
+
+            PointDataTaos pt=new PointDataTaos();
+            pt.setId(point.getNemCode());
+            pt.setTs(new Timestamp(System.currentTimeMillis()));
+             pt.setVal(Double.valueOf(RandomUtil.randomDouble(0,10)));
+            pt.setMetric(1);
+            pointDataTaosLs.add(pt);
+            if(pointDataTaosLs.size()==100)
+            {
+                taosUtil.sendSinglePoint(pointDataTaosLs);
+                pointDataTaosLs.clear();
+            }
+        }
+    }
+
+    private  void equipmentCal(String result, List<PointDataTaos> pointDataTaosLs, Map<String, ProBasicEquipmentPoint> map) {
+
+
+        if(map.containsKey(result) )
+        {
+
+            ProBasicEquipmentPoint point= map.get(result);
+
+            PointDataTaos pt=new PointDataTaos();
+            pt.setId(point.getNemCode());
+            pt.setTs(new Timestamp(System.currentTimeMillis()));
+            pt.setVal(Double.valueOf(RandomUtil.randomDouble(0,10)));
+            pt.setMetric(1);
+            pointDataTaosLs.add(pt);
+
+            if(pointDataTaosLs.size()==100)
+            {
+                taosUtil.sendSinglePoint(pointDataTaosLs);
+                pointDataTaosLs.clear();
+            }
+        }
+    }
+
+
+}

+ 1 - 1
src/main/java/com/gyee/generation/service/initalcache/CacheService.java

@@ -10,7 +10,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import jakarta.annotation.Resource;
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;

+ 1 - 1
src/main/java/com/gyee/generation/service/initialpoint/InitialPointService.java

@@ -11,7 +11,7 @@ import com.gyee.generation.util.ExcelExport;
 
 import org.springframework.stereotype.Service;
 
-import jakarta.annotation.Resource;
+import javax.annotation.Resource;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;

+ 1 - 1
src/main/java/com/gyee/generation/service/initialpoint/InitialTaosPointService.java

@@ -8,7 +8,7 @@ import com.gyee.generation.service.auto.IProBasicCompanyService;
 import com.gyee.generation.service.auto.IProBasicRegionService;
 import com.gyee.generation.service.auto.IProEconTestingPointService;
 import com.gyee.generation.util.ExcelExport;
-import jakarta.annotation.Resource;
+import javax.annotation.Resource;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;

+ 2 - 1
src/main/java/com/gyee/generation/service/initialpoint/TaosInitalPonitService.java

@@ -7,13 +7,14 @@ import com.gyee.generation.mapper.auto.TaosMapper;
 import com.gyee.generation.model.auto.*;
 import com.gyee.generation.model.vo.AlarmSuperTalbeType;
 import com.gyee.generation.util.realtimesource.IRealDataUtil;
-import jakarta.annotation.Resource;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 
+import javax.annotation.Resource;
 import java.util.*;
 
 @Service

+ 1 - 1
src/main/java/com/gyee/generation/util/realtimesource/TaosUtil.java

@@ -10,7 +10,7 @@ import com.gyee.generation.model.auto.PointDataTaos;
 import com.gyee.generation.model.auto.ProBasicEquipmentPoint;
 import com.gyee.generation.model.auto.ProBasicPowerstationPoint;
 import com.gyee.generation.util.realtimesource.timeseries.*;
-import jakarta.annotation.Resource;
+import javax.annotation.Resource;
 import org.springframework.beans.factory.annotation.Value;
 
 import org.springframework.stereotype.Component;

+ 1 - 1
src/main/java/com/gyee/generation/util/redis/RedisServiceImpl.java

@@ -9,7 +9,7 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.serializer.RedisSerializer;
 import org.springframework.stereotype.Service;
 
-import jakarta.annotation.Resource;
+import javax.annotation.Resource;
 import java.lang.reflect.Field;
 import java.util.*;
 import java.util.concurrent.TimeUnit;

+ 152 - 0
src/main/java/com/gyee/generation/util/rule/AlarmFunction.java

@@ -0,0 +1,152 @@
+package com.gyee.generation.util.rule;
+
+
+import com.gyee.generation.init.CacheContext;
+import com.gyee.generation.util.realtimesource.TaosUtil;
+import com.gyee.generation.util.realtimesource.timeseries.PointData;
+import com.gyee.generation.util.rule.expression.AlarmExpression;
+import com.gyee.generation.util.rule.expression.Analyzer;
+import com.gyee.generation.util.rule.expression.DeviceTypeValue;
+import javax.annotation.Resource;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Data
+@NoArgsConstructor
+@Slf4j
+@Component
+public class AlarmFunction {
+
+    private DeviceTypeValue thingType;
+
+    private String thingId;
+
+    private AlarmExpression alarmExpression;
+
+    private List<AlarmFunction> children;
+
+    private AlarmFunction parent;
+
+    //key: uniformcode
+    private Map<String, PointData> tagMap;
+
+    @Resource
+    private CacheContext cacheContext;
+  
+
+    private long lastExplainTime = 0;
+
+    private long getLatestTsDataTs() throws Exception {
+        long ts = 0;
+        if (alarmExpression.getVarList() != null && alarmExpression.getVarList().size() > 0) {
+            for (String varName : alarmExpression.getVarList()) {
+                if (varName.startsWith(Analyzer.FUNCODE))
+                    continue;
+                PointData tagInfo = getTagInfo(varName);
+                if (tagInfo != null && ts < tagInfo.getPointTime())
+                    ts = tagInfo.getPointTime();
+            }
+        }
+        if (children != null && children.size() > 0) {
+            for (AlarmFunction child : children) {
+                if (ts < child.getLatestTsDataTs())
+                    ts = child.getLatestTsDataTs();
+            }
+        }
+        return ts;
+    }
+
+    public Object explain() throws Exception {
+        long ts1 = getLatestTsDataTs();
+        if (ts1 <= lastExplainTime) {
+            return "c";
+        } else {
+            lastExplainTime = ts1;
+        }
+
+        Map<String, Object> varMap = new HashMap<>();
+        if (alarmExpression.getVarList() != null && alarmExpression.getVarList().size() > 0) {
+            for (String varName : alarmExpression.getVarList()) {
+                if (varName.startsWith(Analyzer.FUNCODE))
+                    continue;
+                PointData tagInfo = getTagInfo(varName);
+                if (tagInfo == null) {
+                    log.warn("未找到标签点!ThingId=" + this.getThingId() + ", uc=" + varName + ",rule=" + alarmExpression.getRuleId());
+                    continue;
+                }
+                double varValue = tagInfo.getPointValueInDouble();
+                varMap.put(varName, varValue);
+
+            }
+        }
+
+        if (children != null && children.size() > 0) {
+            for (AlarmFunction af : children) {
+                Object result = af.explain();
+                varMap.put(af.getAlarmExpression().getFunCode(), result);
+            }
+        }
+
+        return ScriptShell.parseExpr(alarmExpression.getExpression(), varMap);
+    }
+
+    public AlarmFunction(AlarmExpression aExpression, DeviceTypeValue tType, String tId) {
+        thingType = tType;
+        thingId = tId;
+        alarmExpression = aExpression;
+        children = new ArrayList<>();
+        if (alarmExpression.getChildren() != null && alarmExpression.getChildren().size() > 0) {
+            for (AlarmExpression subExp : alarmExpression.getChildren()) {
+                AlarmFunction aFun = null;
+                if (subExp.getFunType() != null && subExp.getFunType().equals("RiseExceed")) {
+                    aFun = new AlarmFunctionRiseExceed(subExp, tType, tId);
+                } else if (subExp.getFunType() != null && subExp.getFunType().equals("LastUpdateTime")) {
+                    aFun = new AlarmFunctionLastUpdateTime(subExp, tType, tId);
+                } else if (subExp.getFunType() != null && subExp.getFunType().equals("Sustain")) {
+                    if (subExp.getExpression().startsWith("Sustain")) {
+                        String exp = subExp.getExpression();
+                        int offset = exp.lastIndexOf(',');
+                        String exp2 = exp.substring(8, offset);
+                        subExp.setExpression(exp2);
+                        String parms = exp.substring(offset + 1, exp.length() - 1);
+                        ArrayList<String> paramlist = new ArrayList<>();
+                        paramlist.add(parms);
+                        subExp.setFunParams(paramlist);
+                    }
+                    aFun = new AlarmFunctionSustain(subExp, tType, tId);
+                }
+                else if (subExp.getFunType() != null && subExp.getFunType().equals("MAX")) {
+                    aFun = new AlarmFunctionMAX(subExp, tType, tId);
+                }
+                else if (subExp.getFunType() != null && subExp.getFunType().equals("MIN")) {
+                    aFun = new AlarmFunctionMIN(subExp, tType, tId);
+                }
+                else if (subExp.getFunType() != null && subExp.getFunType().equals("AVG")) {
+                    aFun = new AlarmFunctionAVG(subExp, tType, tId);
+                }
+                if (aFun == null) {
+                    aFun = new AlarmFunction(subExp, tType, tId);
+                }
+                aFun.setParent(this);
+                children.add(aFun);
+            }
+        }
+
+    }
+
+    protected PointData getTagInfo(String varName) throws Exception {
+
+
+        return cacheContext.getTagInfo(varName,thingId,thingType);
+
+
+    }
+
+}

+ 40 - 0
src/main/java/com/gyee/generation/util/rule/AlarmFunctionAVG.java

@@ -0,0 +1,40 @@
+package com.gyee.generation.util.rule;
+
+
+
+
+import com.gyee.generation.util.realtimesource.timeseries.PointData;
+import com.gyee.generation.util.rule.expression.AlarmExpression;
+import com.gyee.generation.util.rule.expression.DeviceTypeValue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @descrition:获取平均值,同一个风机传入多个测点(统一编码)
+ * @author:Wanghs
+ * @date:2020-04-07
+ */
+public class AlarmFunctionAVG  extends AlarmFunction{
+    public AlarmFunctionAVG(AlarmExpression alarmExpression, DeviceTypeValue tType, String tId) {
+        super(alarmExpression, tType, tId);
+    }
+
+    @Override
+    public Object explain() throws Exception {
+        if (this.getAlarmExpression().getVarList() == null || this.getAlarmExpression().getVarList().size() < 1)
+            return 0;
+
+        List<Double> valueList=new ArrayList<>();
+
+        for (int i = 0; i < this.getAlarmExpression().getVarList().size(); i++) {
+            PointData tagInfo = this.getTagInfo(this.getAlarmExpression().getVarList().get(i));
+           if(tagInfo!=null){
+               valueList.add(tagInfo.getPointValueInDouble());
+           }
+        }
+
+        return valueList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
+    }
+
+}

+ 51 - 0
src/main/java/com/gyee/generation/util/rule/AlarmFunctionLastUpdateTime.java

@@ -0,0 +1,51 @@
+package com.gyee.generation.util.rule;
+
+
+import com.gyee.generation.util.realtimesource.timeseries.PointData;
+import com.gyee.generation.util.rule.expression.AlarmExpression;
+import com.gyee.generation.util.rule.expression.DeviceTypeValue;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+
+
+// 返回测点最近数据的时间
+// 应用场景: 判定离线,状态持续时间等
+// 函数原型: LastUpdateTime(测点名)
+@Data
+@NoArgsConstructor
+public class AlarmFunctionLastUpdateTime extends AlarmFunction {
+
+    public AlarmFunctionLastUpdateTime(AlarmExpression alarmExpression, DeviceTypeValue tType, String tId) {
+        super(alarmExpression, tType, tId);
+    }
+
+    @Override
+    public Object explain() throws Exception {
+        if (this.getAlarmExpression().getVarList() == null || this.getAlarmExpression().getVarList().size() < 1)
+            return 0;
+
+        String varName = this.getAlarmExpression().getVarList().get(0);
+        PointData tagInfo = this.getTagInfo(varName);
+      /*  if (tagInfo.getBooleanTsData() != null) {
+            if (tagInfo.getBooleanTsData().getBooleanValue() == false)
+                return 0;
+        }*/
+        // long ts = tagInfo.getLastUpdateTime();
+        if (tagInfo != null) {
+            //计算最后更新时间时,由原来的数据时间戳,改为数据更新时的本地时间
+            long ts = tagInfo.getPointTime();
+            if (ts == 0)
+                return 0;
+            else {
+                long interval = new Date().getTime() - ts;
+                return Math.round(interval / 1000);
+            }
+        } else {
+            return 0;
+        }
+
+    }
+
+}

+ 113 - 0
src/main/java/com/gyee/generation/util/rule/AlarmFunctionMAR.java

@@ -0,0 +1,113 @@
+package com.gyee.generation.util.rule;
+
+
+
+import com.gyee.generation.util.realtimesource.timeseries.DoubleTsData;
+import com.gyee.generation.util.realtimesource.timeseries.PointData;
+import com.gyee.generation.util.rule.expression.AlarmExpression;
+import com.gyee.generation.util.rule.expression.DeviceTypeValue;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+import java.util.LinkedList;
+
+
+// 均值极差:
+// 应用场景: 测点的均值极差计算
+// 函数原型: MAR(测点名,时间(秒))
+@Data
+@NoArgsConstructor
+public class AlarmFunctionMAR extends AlarmFunction {
+
+    private DoubleTsData lastUpdateTsData;
+    //数据缓存
+    private LinkedList<DoubleTsData> tsDataQueue = new LinkedList<DoubleTsData>();
+    private LinkedList<DoubleTsData> avgTsDataQueue = new LinkedList<>();
+    private long interval; //时间范围,单位秒
+
+    private double totalVal = 0;
+    private int count = 0;
+
+    public AlarmFunctionMAR(AlarmExpression alarmExpression, DeviceTypeValue tType, String tId) {
+        super(alarmExpression, tType, tId);
+        String exp = alarmExpression.getExpression();
+        exp = exp.substring(3, exp.length() - 1);
+        String[] arr = exp.split(",");
+        interval = Long.valueOf(arr[1]);
+        //threshold = Double.valueOf(arr[2]);
+    }
+
+    @Override
+    public Object explain() throws Exception {
+        if (this.getAlarmExpression().getVarList() == null || this.getAlarmExpression().getVarList().size() < 1)
+            return false;
+        String varName = this.getAlarmExpression().getVarList().get(0);
+        DoubleTsData tsData = getValue(varName);
+        if (tsData == null)
+            return 0;
+        if (lastUpdateTsData == null) {
+            lastUpdateTsData = tsData;
+            tsDataQueue.offer(tsData);
+            avgTsDataQueue.offer(tsData);
+            totalVal = tsData.getDoubleValue();
+            count = 1;
+            return 0;
+        }
+
+        //如果数据时间戳在变化,最新数据时间作为基准时间
+        //否则,认为数据已不更新,取系统时间和最新数据时间较大者为基准时间
+        long ts = new Date().getTime();
+        if (tsData.getTs() > lastUpdateTsData.getTs())
+            ts = tsData.getTs();
+        else if (tsData.getTs() > ts)
+            ts = tsData.getTs();
+
+
+        DoubleTsData headTsData = tsDataQueue.peek();
+
+        while (ts - headTsData.getTs() > interval * 1000 &&
+                tsDataQueue.size() > 0) {
+
+            headTsData = tsDataQueue.poll();
+            totalVal -= headTsData.getDoubleValue();
+            count--;
+        }
+
+        tsDataQueue.offer(tsData);
+        lastUpdateTsData = tsData;
+        totalVal += tsData.getDoubleValue();
+        count++;
+
+        long avgTs = new Date().getTime();
+        double avgVal = totalVal / count;
+        DoubleTsData avgTsData = new DoubleTsData(avgTs, (short)0, avgVal);
+        avgTsDataQueue.offer(avgTsData);
+
+        DoubleTsData headTsData2 = avgTsDataQueue.peek();
+        while (avgTs - headTsData2.getTs() > interval * 1000 &&
+                avgTsDataQueue.size() > 0) {
+            headTsData2 = avgTsDataQueue.poll();
+        }
+
+        DoubleTsData minTsData = avgTsData;
+        DoubleTsData maxTsData = avgTsData;
+
+        for (int i = 0; i < avgTsDataQueue.size(); i++) {
+            if (minTsData.getDoubleValue() >= avgTsDataQueue.get(i).getDoubleValue()) {
+                minTsData = avgTsDataQueue.get(i);
+            }
+            if (maxTsData.getDoubleValue() <=  avgTsDataQueue.get(i).getDoubleValue()) {
+                maxTsData = avgTsDataQueue.get(i);
+            }
+        }
+        return maxTsData.getDoubleValue() - minTsData.getDoubleValue();
+    }
+
+
+    public DoubleTsData getValue(String varName) throws Exception {
+        PointData tagInfo = this.getTagInfo(varName);
+
+        return new DoubleTsData(tagInfo.getPointTime(), (short) 0, tagInfo.getPointValueInDouble());
+    }
+}

+ 48 - 0
src/main/java/com/gyee/generation/util/rule/AlarmFunctionMAX.java

@@ -0,0 +1,48 @@
+package com.gyee.generation.util.rule;
+
+
+
+import com.gyee.generation.util.realtimesource.timeseries.PointData;
+import com.gyee.generation.util.rule.expression.AlarmExpression;
+import com.gyee.generation.util.rule.expression.DeviceTypeValue;
+
+import java.util.Optional;
+
+/**
+ * @descrition:传入多个测点(统一编码)获取最大值
+ * @author:Wanghs
+ * @date:2020-04-07
+ */
+public class AlarmFunctionMAX extends AlarmFunction {
+    public AlarmFunctionMAX(AlarmExpression alarmExpression, DeviceTypeValue tType, String tId) {
+        super(alarmExpression, tType, tId);
+    }
+
+    @Override
+    public Object explain() throws Exception {
+        if (this.getAlarmExpression().getVarList() == null || this.getAlarmExpression().getVarList().size() < 1)
+            return 0;
+
+        Optional<Double> maxValue = Optional.empty();
+
+        for (int i = 0; i < this.getAlarmExpression().getVarList().size(); i++) {
+            PointData tagInfo = this.getTagInfo(this.getAlarmExpression().getVarList().get(i));
+
+            if (tagInfo == null) {
+                continue;
+            }
+
+            //System.out.println("@@@@@" + this.getAlarmExpression().getVarList().get(i));
+            if (!maxValue.isPresent()) {
+                maxValue = Optional.of(tagInfo.getPointValueInDouble());
+            } else {
+                if (maxValue.get() <= tagInfo.getPointValueInDouble()) {
+                    maxValue = Optional.of(tagInfo.getPointValueInDouble());
+                }
+            }
+        }
+
+        return maxValue.get().doubleValue();
+    }
+
+}

+ 40 - 0
src/main/java/com/gyee/generation/util/rule/AlarmFunctionMIN.java

@@ -0,0 +1,40 @@
+package com.gyee.generation.util.rule;
+
+
+
+
+
+import com.gyee.generation.util.realtimesource.timeseries.PointData;
+import com.gyee.generation.util.rule.expression.AlarmExpression;
+import com.gyee.generation.util.rule.expression.DeviceTypeValue;
+
+import java.util.Optional;
+
+
+public class AlarmFunctionMIN extends AlarmFunction {
+    public AlarmFunctionMIN(AlarmExpression alarmExpression, DeviceTypeValue tType, String tId) {
+        super(alarmExpression, tType, tId);
+    }
+
+    @Override
+    public Object explain() throws Exception {
+        if (this.getAlarmExpression().getVarList() == null || this.getAlarmExpression().getVarList().size() < 1)
+            return 0;
+
+        Optional<Double> minValue = Optional.empty();
+
+        for (int i = 0; i < this.getAlarmExpression().getVarList().size(); i++) {
+            PointData tagInfo = this.getTagInfo(this.getAlarmExpression().getVarList().get(i));
+            if (!minValue.isPresent()) {
+                minValue = Optional.of(tagInfo.getPointValueInDouble());
+            } else {
+                if (minValue.get() >= tagInfo.getPointValueInDouble()) {
+                    minValue = Optional.of(tagInfo.getPointValueInDouble());
+                }
+            }
+        }
+
+        return minValue.get().doubleValue();
+    }
+
+}

+ 94 - 0
src/main/java/com/gyee/generation/util/rule/AlarmFunctionMR.java

@@ -0,0 +1,94 @@
+package com.gyee.generation.util.rule;
+
+
+
+import com.gyee.generation.util.realtimesource.timeseries.DoubleTsData;
+import com.gyee.generation.util.realtimesource.timeseries.PointData;
+import com.gyee.generation.util.rule.expression.AlarmExpression;
+import com.gyee.generation.util.rule.expression.DeviceTypeValue;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+import java.util.LinkedList;
+
+
+// 移动极差:移动极差(Moving Range)是指两个或多个连续样本值中最大值与最小值之差。
+// 这种差是按这样方式计算的:每当得到一个额外的数据点时,就在样本中加上这个新的点,
+// 同时删除其中时间上“最老的”点,然后计算与这点有关的极差,因此每个极差的计算至少
+// 与前一个极差的计算共用一个点的值。
+// 一般说来,移动极差用于单值控制图,并且通常用两点(连续的点)来计算移动极差。
+// 应用场景: 测点的移动极差超限报警
+// 函数原型: MR(测点名,时间(秒))
+@Data
+@NoArgsConstructor
+public class AlarmFunctionMR extends AlarmFunction {
+
+    private DoubleTsData lastUpdateTsData;
+    //private DoubleTsData minTsData;
+    //数据缓存
+    private LinkedList<DoubleTsData> tsDataQueue = new LinkedList<DoubleTsData>();
+    private long interval; //时间范围,单位秒
+    //private double threshold; //阈值
+
+    public AlarmFunctionMR(AlarmExpression alarmExpression, DeviceTypeValue tType, String tId) {
+        super(alarmExpression, tType, tId);
+        String exp = alarmExpression.getExpression();
+        exp = exp.substring(3, exp.length() - 1);
+        String[] arr = exp.split(",");
+        interval = Long.valueOf(arr[1]);
+        //threshold = Double.valueOf(arr[2]);
+    }
+
+    @Override
+    public Object explain() throws Exception {
+        if (this.getAlarmExpression().getVarList() == null || this.getAlarmExpression().getVarList().size() < 1)
+            return false;
+        String varName = this.getAlarmExpression().getVarList().get(0);
+        DoubleTsData tsData = getValue(varName);
+        if (tsData == null)
+            return 0;
+        if (lastUpdateTsData == null) {
+            lastUpdateTsData = tsData;
+            tsDataQueue.offer(tsData);
+            return 0;
+        }
+
+        //如果数据时间戳在变化,最新数据时间作为基准时间
+        //否则,认为数据已不更新,取系统时间和最新数据时间较大者为基准时间
+        long ts = new Date().getTime();
+        if (tsData.getTs() > lastUpdateTsData.getTs())
+            ts = tsData.getTs();
+        else if (tsData.getTs() > ts)
+            ts = tsData.getTs();
+
+
+        DoubleTsData headTsData = tsDataQueue.peek();
+
+        while (ts - headTsData.getTs() > interval * 1000 &&
+                tsDataQueue.size() > 0) {
+            headTsData = tsDataQueue.poll();
+        }
+        tsDataQueue.offer(tsData);
+        lastUpdateTsData = tsData;
+        DoubleTsData minTsData = tsData;
+        DoubleTsData maxTsData = tsData;
+
+        for (int i = 0; i < tsDataQueue.size(); i++) {
+            if (minTsData.getDoubleValue() >= tsDataQueue.get(i).getDoubleValue()) {
+                minTsData = tsDataQueue.get(i);
+            }
+            if (maxTsData.getDoubleValue() <=  tsDataQueue.get(i).getDoubleValue()) {
+                maxTsData = tsDataQueue.get(i);
+            }
+        }
+        return maxTsData.getDoubleValue() - minTsData.getDoubleValue();
+    }
+
+
+    public DoubleTsData getValue(String varName) throws Exception {
+        PointData tagInfo = this.getTagInfo(varName);
+
+        return new DoubleTsData(tagInfo.getPointTime(), (short) 0, tagInfo.getPointValueInDouble());
+    }
+}

+ 95 - 0
src/main/java/com/gyee/generation/util/rule/AlarmFunctionRiseExceed.java

@@ -0,0 +1,95 @@
+package com.gyee.generation.util.rule;
+
+
+
+import com.gyee.generation.util.realtimesource.timeseries.DoubleTsData;
+import com.gyee.generation.util.realtimesource.timeseries.PointData;
+import com.gyee.generation.util.rule.expression.AlarmExpression;
+import com.gyee.generation.util.rule.expression.DeviceTypeValue;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+import java.util.LinkedList;
+
+
+// 取测点在给定的时间范围内数据上升的量是否超过阈值
+// 应用场景: 判断温升,测点值的上升速度过快等
+// 函数原型: RiseExceed(测点名,时间(秒),阈值)
+@Data
+@NoArgsConstructor
+public class AlarmFunctionRiseExceed extends AlarmFunction {
+
+    private DoubleTsData lastUpdateTsData;
+    //private DoubleTsData minTsData;
+    //数据缓存
+    private LinkedList<DoubleTsData> tsDataQueue = new LinkedList<DoubleTsData>();
+    private long interval; //时间范围,单位秒
+    private double threshold; //阈值
+
+
+    public AlarmFunctionRiseExceed(AlarmExpression alarmExpression, DeviceTypeValue tType, String tId) {
+        super(alarmExpression, tType, tId);
+        String exp = alarmExpression.getExpression();
+        exp = exp.substring(11, exp.length() - 1);
+        String[] arr = exp.split(",");
+        interval = Long.valueOf(arr[1]);
+        threshold = Double.valueOf(arr[2]);
+    }
+
+    @Override
+    public Object explain() throws Exception {
+        if (this.getAlarmExpression().getVarList() == null || this.getAlarmExpression().getVarList().size() < 1)
+            return false;
+        String varName = this.getAlarmExpression().getVarList().get(0);
+        DoubleTsData tsData = getValue(varName);
+        if (tsData == null)
+            return false;
+        if (lastUpdateTsData == null) {
+            lastUpdateTsData = tsData;
+            tsDataQueue.offer(tsData);
+            return false;
+        }
+
+        //如果数据时间戳在变化,最新数据时间作为基准时间
+        //否则,认为数据已不更新,取系统时间和最新数据时间较大者为基准时间
+        long ts = new Date().getTime();
+        if (tsData.getTs() > lastUpdateTsData.getTs())
+            ts = tsData.getTs();
+        else if (tsData.getTs() > ts)
+            ts = tsData.getTs();
+
+
+        DoubleTsData minTsData = tsDataQueue.peek();
+
+        while (ts - minTsData.getTs() > interval * 1000 &&
+                tsDataQueue.size() > 0) {
+            minTsData = tsDataQueue.poll();
+        }
+        tsDataQueue.offer(tsData);
+        for (int i = 0; i < tsDataQueue.size(); i++) {
+            if (minTsData.getDoubleValue() >= tsDataQueue.get(i).getDoubleValue()) {
+                minTsData = tsDataQueue.get(i);
+            }
+        }
+
+        while (tsDataQueue.size() > 0 &&
+                tsDataQueue.peek().getTs() < minTsData.getTs()) {
+            tsDataQueue.poll();
+        }
+
+        lastUpdateTsData = tsData;
+        if (tsData.getDoubleValue() - minTsData.getDoubleValue() > threshold) {
+            return true;
+        }
+        return false;
+    }
+
+
+    public DoubleTsData getValue(String varName) throws Exception {
+        PointData tagInfo = this.getTagInfo(varName);
+
+        return new DoubleTsData(tagInfo.getPointTime(), (short) 0, tagInfo.getPointValueInDouble());
+
+    }
+}

+ 68 - 0
src/main/java/com/gyee/generation/util/rule/AlarmFunctionSustain.java

@@ -0,0 +1,68 @@
+package com.gyee.generation.util.rule;
+
+
+
+import com.gyee.generation.util.realtimesource.timeseries.DoubleTsData;
+import com.gyee.generation.util.rule.expression.AlarmExpression;
+import com.gyee.generation.util.rule.expression.DeviceTypeValue;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+
+
+// 判定状态(表达式成立)持续的时间是否超过给定的时间
+// 应用场景: 判断状态持续的时间
+// 函数原型: Sustain(expression,时间(秒))
+@Data
+@NoArgsConstructor
+@Slf4j
+public class AlarmFunctionSustain extends AlarmFunction {
+
+    private boolean lastUpdateStatus;
+    private long lastUpdateTs;
+    private long originalTs;
+    private long interval; //时间范围,单位秒
+
+    public AlarmFunctionSustain(AlarmExpression alarmExpression, DeviceTypeValue tType, String tId) {
+        super(alarmExpression, tType, tId);
+        String val = alarmExpression.getFunParams().get(0);
+        interval = Long.valueOf(val);
+    }
+
+
+    private String firstId = "";
+
+    @Override
+    public Object explain() throws Exception {
+
+        long ts = getLastExplainTime();
+        if (originalTs == 0)
+            originalTs = ts;
+
+        lastUpdateTs = ts;
+
+        Object obj = super.explain();
+        if (obj.equals(Boolean.TRUE)) {
+            if (lastUpdateStatus == false) {
+                originalTs = ts;
+                lastUpdateStatus = true;
+                return false;
+            } else {
+                long tmp = lastUpdateTs - originalTs;
+                if (tmp > interval * 1000)
+                    return true;
+                else
+                    return false;
+            }
+        } else {
+            lastUpdateStatus = false;
+            //originalTs = ts;
+            return false;
+        }
+    }
+
+
+    public DoubleTsData getValue(String varName) {
+        return null;
+    }
+}

+ 229 - 0
src/main/java/com/gyee/generation/util/rule/AlarmRule.java

@@ -0,0 +1,229 @@
+package com.gyee.generation.util.rule;//package com.gyee.alarm.rule;
+//
+//import com.gyee.alarm.model.auto.ProBasicEquipment;
+//import com.gyee.alarm.model.auto.ProEconAlarmRule;
+//import com.gyee.alarm.rule.expression.AlarmExpression;
+//import com.gyee.alarm.rule.expression.Analyzer;
+//
+//import com.gyee.alarm.service.initalcache.CacheService;
+//import com.gyee.alarm.util.StringUtils;
+//import lombok.Data;
+//import lombok.extern.slf4j.Slf4j;
+//
+//
+//import java.util.*;
+//import java.util.stream.Collectors;
+//
+//@Slf4j
+//@Data
+//public class AlarmRule {
+//
+//    private ProEconAlarmRule proEconAlarmRule;
+//
+//    private AlarmExpression alarmExpression;
+//
+//    private List<AlarmFunction> funList;
+//
+//
+//    public AlarmRule(ProEconAlarmRule ar) {
+//        this.proEconAlarmRule = ar;
+//        funList = new ArrayList<>();
+//        try {
+//            alarmExpression = Analyzer.getAlarmExpression(ar.getExpression());
+//            alarmExpression.setRuleId(proEconAlarmRule.getId());
+//            ArrayList<String> ucs = alarmExpression.getAllUniformCodes();
+//            //1-风机 2-风场 5-升压站
+//            if ("1".equals(ar.getCategory()) ) {
+//                //获取规则所对应的风机
+//                List<ProBasicEquipment> lst = new ArrayList<>();
+//                cacheService.getWindturbineInfoMap().values().stream()
+//                        .filter((WindturbineInfo w) -> w.getWindturbine().getModelId().contains(ar.getModelId().trim())&&w.getWindturbine().getWindPowerStationId().equals(ar.getStation())).collect(Collectors.toList()).forEach(n -> lst.add(n.getWindturbine()));
+//
+//                //  String[] wtArray = ar.getWindturbine().split(",");
+//                for (ProBasicEquipment wb : lst) {
+//                    Map<String, WindturbineInfo> wtMap = cacheService.getWindturbineInfoMap();
+//                    if (StringUtils.notEmp(wb.getId()) && wtMap.containsKey(wb.getId())) {
+//                        AlarmFunction alarmFunction = new AlarmFunction(alarmExpression, ThingType.WINDTURBINE, wb.getId());
+//                        if (funList.contains(alarmFunction)) {
+//                            log.warn("重复的设备:" + wb.getId());
+//                            continue;
+//                        }
+//                        funList.add(alarmFunction);
+//                    }
+//                }
+//                //填充ucWindturbinelist
+//                if (ucs.size() > 0) {
+//                    for (String uc : ucs) {
+//                        ArrayList<String> wtList = cacheService.getUcWindturbinelist(uc);
+//                        for (ProBasicEquipment wb : lst) {
+//                            if (wtList.contains(wb.getId()) == false)
+//                                wtList.add(wb.getId());
+//                        }
+//                    }
+//                }
+//            }
+//
+//
+//            if (("2".equals(ar.getCategory()) || "5".equals(ar.getCategory())) && ar.getStation() != null) {
+//                String[] stArray = ar.getStation().split(",");
+//                for (String stId : stArray) {
+//                    Map<String, StationInfo> wtMap = cacheService.getStationInfoMap();
+//                    if (StringUtil.isNotBlank(stId) && wtMap.containsKey(stId)) {
+//                        AlarmFunction alarmFunction = new AlarmFunction(alarmExpression, ThingType.STATION, stId);
+//                        if (funList.contains(alarmFunction)) {
+//                            log.warn("重复的设备:" + stId);
+//                            continue;
+//                        }
+//                        funList.add(alarmFunction);
+//                    }
+//                }
+//
+//                //填充ucStationlist
+//                if (ucs.size() > 0) {
+//                    for (String uc : ucs) {
+//                        ArrayList<String> stList = cacheService.getUcStationlist(uc);
+//                        for (String stId : stArray) {
+//                            if (stList.contains(stId) == false)
+//                                stList.add(stId);
+//                        }
+//                    }
+//                }
+//            }
+//        } catch (Exception ex) {
+//            log.error("生成自定义报警规则失败!规则id:" + ar.getId());
+//        }
+//    }
+//
+//    //缓存报警快照,减少数据库查询次数
+//    //key: thingId
+//    private HashMap<String, AlarmSnap> snapMap;
+//
+//    //用于批量更新数据库
+//    private List<AlarmSnap> snapChangedList;
+//
+//    public void run() {
+//        if (funList != null && funList.size() > 0) {
+//
+//            if (snapChangedList == null)
+//                snapChangedList = new ArrayList<>();
+//            else
+//                snapChangedList.clear();
+//
+//            for (AlarmFunction fun : funList) {
+//                try {
+//
+//                    Object obj = fun.explain();
+//                    if (obj instanceof Boolean) {
+//                        boolean writeHistory = true;
+//                        AlarmSnap snap = getAlertSnap(fun.getThingId());
+//                        if (true == (boolean) obj) {
+//                            double interval = 0;
+////                            if (snap == null) {
+////                                snap = AlertSnapFactory.createAlertsnap(this.proEconAlarmRule, fun.getThingId());
+////                                if (snap.getStationName() == null &&
+////                                        snap.getStationId() !=  null &&
+////                                        cacheService.getStationInfoMap().containsKey(snap.getStationId())) {
+//////                                    StationInfo st = cacheService.getStationInfoMap().get(snap.getStationId());
+////                                    snap.setStationName(st.getStation().getStationName());
+////                                }
+////                            } else
+//                            if (snap.getIsOpened() != 0) {
+//                                long ts = (new Date()).getTime() - snap.getLastUpdateTime().getTime();
+//                                //TimeSpan ts = DateTime.Now.Subtract((DateTime)snap.LastUpdateTime);
+//                                interval = ts / (3600 * 1000);
+//                            }
+//
+//                            if (snap.getIsOpened() == 0 || interval > 1) {
+//                                snap.setIsOpened(1);
+//                                //snap.DataInfo = CommonMethod.StringCopy(ari.DataInfo, 2000);
+//                                //snap.setLastUpdatePerson("system");
+//                                snap.setLastUpdateTime(new Date());
+////                                if (snap.getIsConfirmed() != 0 && interval > 8)
+////                                    snap.setIsConfirmed(0);
+//
+//                                //sqlService.saveAlertSnap(snap);
+//                                snapChangedList.add(snap);
+//
+//
+//                                //AlertSnapRepository.SaveAlertSnap(snap);
+//                                //写实时库
+////                                string key = GetWindTurbineAlertPoint(windTurbine.Id);
+////                                logger.InfoFormat("写报警测点,key={0}, value={1}", key, ari.ProEconAlarmRule.EdnaValue);
+////                                eDos.SendSinglePoint(key, ari.ProEconAlarmRule.EdnaValue);
+//                                log.info(String.format("触发报警!%s,规则:%s", fun.getThingId(), proEconAlarmRule.getName()+"--"+proEconAlarmRule.getExpression()));
+//                            }
+//                        } else {
+//                            //解除报警
+//                            if (snap != null && snap.getIsOpened() != 0) {
+//                                snap.setIsOpened(0);
+//                                //snap.DataInfo = CommonMethod.StringCopy(ari.DataInfo, 2000);
+////                                snap.setIsConfirmed(0);
+////                                snap.setLastClosePerson("system");
+////                                snap.setLastCloseTime(new Date());
+//                                snap.setLastUpdateTime(new Date());
+//                                //sqlService.saveAlertSnap(snap);
+//                                snapChangedList.add(snap);
+//                                log.info(String.format("解除报警!%s,规则:%s",
+//                                        fun.getThingId(), proEconAlarmRule.getId()));
+//                            }
+//                        }
+//                    } else {
+//                        System.out.print(obj.toString());
+//                    }
+//                } catch (Exception ex) {
+//                   // ex.printStackTrace();
+//                    log.error("自定义报警规则执行时出错!"+fun.getThingId()+"--"+this.proEconAlarmRule.getId()+"----"+this.proEconAlarmRule.getName()+"------" + ex.getMessage());
+//                }
+//            }
+//
+//            if (snapChangedList.size() > 0)
+//              sqlService.saveAlertSnaps(snapChangedList);
+//        }
+//    }
+//
+//    private AlarmSnap getAlertSnap(String thingId) {
+//        if (snapMap == null)
+//            snapMap = new HashMap<>();
+//        if (snapMap.containsKey(thingId)) {
+//            return snapMap.get(thingId);
+//        } else {
+//            AlarmSnap alertsnap = findAlertSnap(thingId, this.proEconAlarmRule.getEdnaValue());
+//            if (alertsnap == null) {
+//                alertsnap = AlertSnapFactory.createAlertsnap(this.proEconAlarmRule, thingId);
+//                if (alertsnap.getStationName() == null &&
+//                        alertsnap.getStationId() != null &&
+//                        cacheService.getStationInfoMap().containsKey(alertsnap.getStationId())) {
+//                    StationInfo st = cacheService.getStationInfoMap().get(alertsnap.getStationId());
+//                    alertsnap.setStationName(st.getStation().getStationName());
+//                }
+//            }
+//            if (alertsnap.getId() != null)
+//                snapMap.put(thingId, alertsnap);
+//            if(StringUtils.isBlank(alertsnap.getCategory3()))
+//            {
+//                //如果风机报警的category3字段为空,则说明报警没有关联到相关部件,取报警规则中的Relatedparts进行赋值
+//                if(StringUtils.isNotBlank(this.proEconAlarmRule.getRelatedParts())){
+//                    alertsnap.setCategory3(this.proEconAlarmRule.getRelatedParts());
+//                }
+//            }
+//            return alertsnap;
+//        }
+//    }
+//
+//    private AlarmSnap findAlertSnap(String thingId, int alertValue) {
+//        try {
+//            if ("1".equals(this.proEconAlarmRule.getCategory())) {
+//                return sqlService.getAlertSnap(ThingType.WINDTURBINE, thingId, alertValue);
+//            }
+//
+//            return sqlService.getAlertSnap(ThingType.STATION, thingId, alertValue);
+//        } catch (Exception ex) {
+//            log.warn(String.format("thingId=%s, alertValue=%d", thingId, alertValue));
+//            log.error(ex.getMessage(), ex);
+//            return null;
+//        }
+//
+//    }
+//
+//
+//}

+ 39 - 0
src/main/java/com/gyee/generation/util/rule/AlarmScript.java

@@ -0,0 +1,39 @@
+package com.gyee.generation.util.rule;
+
+import groovy.lang.Script;
+
+public class AlarmScript extends Script {
+
+    @Override
+    public Object run() {
+        return null;
+    }
+
+    public double dataSub(double d1, double d2) {
+        return d1 - d2;
+    }
+
+    /**
+     * 数据有变化就报警
+     * @return
+     */
+//    public boolean IsChanged() {
+//        long entityId = (long)getBinding().getVariable(ScriptShell.entityIdName);
+//        String variable = (String)getBinding().getVariable(ScriptShell.variableName);
+//        TsData currentData = (TsData)getBinding().getVariable(ScriptShell.tsDataName);
+//        TsData preData = ScriptShell.getPreTsData(entityId,variable);
+//        if (preData == null) {
+//            return  true;   //如果没有前值,直接触发报警?
+//        }
+//        if (preData.getTs() >= currentData.getTs()) {
+//            return false;   //过期的数据,不触发报警
+//        }
+//        if (preData.getValue().equals(currentData.getValue())) {
+//            return false;
+//        } else {
+//            return true;    //当前值与前值不一样,触发报警
+//        }
+//
+//    }
+//
+}

+ 43 - 0
src/main/java/com/gyee/generation/util/rule/ScriptShell.java

@@ -0,0 +1,43 @@
+package com.gyee.generation.util.rule;
+
+import groovy.lang.Binding;
+import groovy.lang.GroovyShell;
+import groovy.lang.Script;
+import org.codehaus.groovy.control.CompilerConfiguration;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class ScriptShell {
+    private static final GroovyShell shell;
+    private static ConcurrentHashMap<String, Script> cache = new ConcurrentHashMap<String, Script>();
+
+    static {
+        CompilerConfiguration cfg = new CompilerConfiguration();
+        cfg.setScriptBaseClass(AlarmScript.class.getName());
+        shell = new GroovyShell(cfg);
+    }
+
+    public static Object parseExpr(String expr) {
+        Script s = getScriptFromCache(expr);
+        return s.run();
+    }
+
+    public static Object parseExpr(String expr, Map<String, Object> map) {
+        Binding binding = new Binding(map);
+        Script script = getScriptFromCache(expr);
+        script.setBinding(binding);
+        return script.run();
+    }
+
+    private static Script getScriptFromCache(String expr) {
+        if (cache.containsKey(expr)) {
+            return cache.get(expr);
+        }
+        Script script = shell.parse(expr);
+        cache.put(expr, script);
+        return script;
+    }
+
+
+}

+ 63 - 0
src/main/java/com/gyee/generation/util/rule/expression/AlarmExpression.java

@@ -0,0 +1,63 @@
+package com.gyee.generation.util.rule.expression;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+public class AlarmExpression {
+
+    private String funCode;
+
+    private String funType;
+
+    private String originalExpression;
+
+    private String expression;
+
+    private List<String> varList;
+
+    private List<AlarmExpression> children;
+
+    private AlarmExpression parent;
+
+    private String ruleId;
+
+    private ArrayList<String> funParams;
+
+//    private boolean isOpened;
+
+//    public AlarmExpression(String exp) {
+//
+//    }
+
+    public ArrayList<String> getAllUniformCodes() {
+        ArrayList<String> result = new ArrayList<>();
+        if (varList != null && varList.size() > 0) {
+            for (String var : varList) {
+                if (var.startsWith(Analyzer.FUNCODE) == false)
+                    result.add(var);
+            }
+        }
+
+        if (children != null && children.size() > 0) {
+            for (AlarmExpression subExp : children) {
+                ArrayList<String> r2 = subExp.getAllUniformCodes();
+                if (r2.size() > 0) {
+                    for (String svar : r2) {
+                        if (svar.startsWith(Analyzer.FUNCODE) == false)
+                            result.add(svar);
+                    }
+                }
+            }
+        }
+
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        return expression;
+    }
+}

+ 221 - 0
src/main/java/com/gyee/generation/util/rule/expression/Analyzer.java

@@ -0,0 +1,221 @@
+package com.gyee.generation.util.rule.expression;
+
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+
+public class Analyzer {
+
+    public static final String FUNCODE = "Function";
+
+    //自定义函数名集合
+    public static final HashSet<String> CUSTOM_FUNS = new HashSet<String>() {{
+        add("RiseExceed");
+        add("LastUpdateTime");
+        add("Sustain");
+        add("MR");
+        add("MAR");
+        add("MAX");
+        add("MIN");
+        add("AVG");
+    }};
+
+    public static AlarmExpression getAlarmExpression(String exp) {
+        ArrayList<Token> tokens = getTokens(exp);
+        return createAlarmExpression(tokens);
+    }
+
+    public static ArrayList<Token> getTokens(String exp) {
+        ArrayList<Token> tokens = new ArrayList<>();
+        int expIndex = 0;
+        int tokenIndex = 0;
+        while (expIndex < exp.length()) {
+            char currentChar = exp.charAt(expIndex);
+            //如果当前字符是一个分隔符,则认为这是一个分隔符标记
+            //给当前标记和标记类型赋值,并将指针后移
+            if (isDelim(currentChar)) {
+                Token token = new Token();
+                token.setValue(currentChar + "");
+                if (currentChar == '(') {
+                    token.setTokenType(TokenType.PARENTHESISL);
+                    //识别出函数名
+                    if (tokens.size() > 0) {
+                        Token preToken = tokens.get(tokens.size() - 1);
+                        if (preToken.getTokenType() == TokenType.VARIABE &&
+                                CUSTOM_FUNS.contains(preToken.getValue())) {
+                            preToken.setTokenType(TokenType.CUSTOMFUN);
+                        } else {
+                            preToken.setTokenType(TokenType.SYSFUN);
+                        }
+                    }
+                } else if (currentChar == ')')
+                    token.setTokenType(TokenType.PARENTHESISR);
+                else
+                    token.setTokenType(TokenType.OTHER);
+
+                if (currentChar != ' ')
+                    tokens.add(token);
+                tokenIndex = 0;
+            } else if (isVariable(currentChar)) {
+                if (tokenIndex == 0) {
+                    Token token = new Token();
+                    token.setValue(currentChar + "");
+                    if (currentChar >= '0' && currentChar <= '9')
+                        token.setTokenType(TokenType.CONST);
+                    else
+                        token.setTokenType(TokenType.VARIABE);
+                    tokens.add(token);
+                } else {
+                    Token token = tokens.get(tokens.size() - 1);
+                    token.setValue(token.getValue() + currentChar);
+                }
+                tokenIndex++;
+            } else {
+                //其他字符,忽略
+            }
+            expIndex++;
+        }
+
+        return tokens;
+    }
+
+    //判断一个字符是否为分隔符
+    public static boolean isDelim(char c) {
+        if (("+-*/><=&|! ,()".indexOf(c) != -1))
+            return true;
+        return false;
+    }
+
+    //判断一个字符是否为字母数字或小数点
+    public static boolean isVariable(char c) {
+        if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '.' || c == '_')
+            return true;
+
+        return false;
+    }
+
+    public static AlarmExpression createAlarmExpression(ArrayList<Token> tokens) {
+        AlarmExpression alarmExpression = new AlarmExpression();
+        alarmExpression.setFunCode("ROOT");
+
+        List<AlarmExpression> subFun = new ArrayList<>();
+        int funCnt = 0;
+        List<String> varList = new ArrayList<>();
+        StringBuilder sbExp = new StringBuilder();
+
+        int tokenIndex = 0;
+        while (tokenIndex < tokens.size()) {
+            Token token = tokens.get(tokenIndex);
+            if (token.getTokenType() == TokenType.VARIABE) {
+                if (varList.contains(token.getValue()) == false)
+                    varList.add(token.getValue());
+                sbExp.append(token.getValue());
+            } else if (token.getTokenType() == TokenType.CUSTOMFUN) {
+                ArrayList<Token> subTokens = getFunTokens(tokens, tokenIndex);
+                AlarmExpression subExp = createCustomFunExpression(subTokens);
+                String subFunCode = FUNCODE + funCnt++;
+                subExp.setFunCode(subFunCode);
+                subExp.setParent(alarmExpression);
+                subFun.add(subExp);
+                varList.add(subFunCode);
+                sbExp.append(subFunCode);
+
+                tokenIndex += subTokens.size();
+                continue;
+            } else {
+                sbExp.append(token.getValue());
+            }
+
+            tokenIndex++;
+        }
+
+        alarmExpression.setVarList(varList);
+        alarmExpression.setExpression(sbExp.toString());
+        alarmExpression.setChildren(subFun);
+
+        return alarmExpression;
+    }
+
+    private static AlarmExpression createCustomFunExpression(ArrayList<Token> tokens) {
+        AlarmExpression alarmExpression = new AlarmExpression();
+
+        List<AlarmExpression> subExps = new ArrayList<>();
+        int funCnt = 0;
+        List<String> varList = new ArrayList<>();
+        List<String> paramList = new ArrayList<>();
+        StringBuilder sbExp = new StringBuilder();
+        alarmExpression.setFunType(tokens.get(0).getValue());
+        sbExp.append(tokens.get(0).getValue());
+
+        int tokenIndex = 1;
+        while (tokenIndex < tokens.size()) {
+            Token token = tokens.get(tokenIndex);
+            if (token.getTokenType() == TokenType.VARIABE) {
+                if (varList.contains(token.getValue()) == false)
+                    varList.add(token.getValue());
+                sbExp.append(token.getValue());
+            } else if (token.getTokenType() == TokenType.CUSTOMFUN) {
+                ArrayList<Token> subTokens = getFunTokens(tokens, tokenIndex);
+                AlarmExpression subExp = createCustomFunExpression(subTokens);
+                subExp.setParent(alarmExpression);
+                String subFunCode = FUNCODE + funCnt++;
+                subExp.setFunCode(subFunCode);
+                subExps.add(subExp);
+                varList.add(subFunCode);
+                sbExp.append(subFunCode);
+                tokenIndex += subTokens.size();
+                continue;
+            } else {
+                sbExp.append(token.getValue());
+            }
+
+            tokenIndex++;
+        }
+
+        alarmExpression.setVarList(varList);
+        alarmExpression.setExpression(sbExp.toString());
+        alarmExpression.setChildren(subExps);
+
+        return alarmExpression;
+    }
+
+    private static ArrayList<Token> getFunTokens(ArrayList<Token> tokens, int startIndex) {
+        ArrayList<Token> result = new ArrayList<>();
+        int cntL = 0;
+        int cntR = 0;
+        while (startIndex < tokens.size()) {
+            Token token = tokens.get(startIndex);
+            result.add(token);
+            if (token.getTokenType() == TokenType.PARENTHESISL) {
+                cntL++;
+            } else if (token.getTokenType() == TokenType.PARENTHESISR) {
+                if (++cntR == cntL) {
+                    break;
+                }
+            }
+            startIndex++;
+        }
+
+        return result;
+    }
+
+
+    public static void main(String[] args) {
+        //String exp = "AI041>80 && AI_FJZT!=3";
+        //String exp = "LastUpdateTime(AI03229)>=1800 && LastUpdateTime(AI03101)>=1800 && LastUpdateTime(DI07893)>=1800 && LastUpdateTime(DI07436)>=1800 && LastUpdateTime(DI07822)>=1800";
+
+        //String exp = "Sustain(AI022 > 4.5 && AI_FJZT==0,Math.Abs(600-100),60)";
+
+        String exp = "Sustain(FJAI022 > 4.5 && FCAI_FJZT==0 && LastUpdateTime(AI03229)>=1800 && LastUpdateTime(AI03101)>=1800 ,Math.Abs(600-100),60)";
+
+        ArrayList<Token> tokens = getTokens(exp);
+        for (Token token : tokens) {
+            System.out.println(token.getValue() + "----" + token.getTokenType());
+        }
+
+        AlarmExpression alarmExpression = createAlarmExpression(tokens);
+        System.out.println(alarmExpression.getFunType());
+
+    }
+}

+ 56 - 0
src/main/java/com/gyee/generation/util/rule/expression/DeviceTypeValue.java

@@ -0,0 +1,56 @@
+package com.gyee.generation.util.rule.expression;
+
+public enum DeviceTypeValue {
+    EG("EG", "集团"),
+    RG("RG", "区域"),
+    CP("CP", "公司"),
+    WP("WP", "场站"),
+    PJ("PJ", "项目"),
+    LN("LN", "线路"),
+    WT("WT", "设备");
+
+    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;
+    }
+
+
+}

+ 53 - 0
src/main/java/com/gyee/generation/util/rule/expression/FunctionValue.java

@@ -0,0 +1,53 @@
+package com.gyee.generation.util.rule.expression;
+
+public enum FunctionValue {
+    RFDL("RFDL", "日发电量"),
+    PJFS("PJFS", "平均风速");
+
+    private String code;
+    private String name;
+
+    FunctionValue(String code) {
+        this.code = code;
+    }
+
+    FunctionValue(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 (FunctionValue ele : values()) {
+            if (ele.getCode().equals(code)) {
+                return ele.getName();
+            }
+        }
+        return null;
+    }
+
+
+
+
+}

+ 9 - 0
src/main/java/com/gyee/generation/util/rule/expression/Token.java

@@ -0,0 +1,9 @@
+package com.gyee.generation.util.rule.expression;
+
+import lombok.Data;
+
+@Data
+public class Token {
+    private String value;
+    private TokenType tokenType;
+}

+ 12 - 0
src/main/java/com/gyee/generation/util/rule/expression/TokenType.java

@@ -0,0 +1,12 @@
+package com.gyee.generation.util.rule.expression;
+
+public enum TokenType {
+    EMPTY,  //空,未赋值
+    VARIABE, //变量
+    CONST,  //常量
+    CUSTOMFUN, //自定义函数
+    SYSFUN, //标准库函数
+    PARENTHESISL, //圆括号左边
+    PARENTHESISR,  //圆括号右边
+    OTHER //其他符号,包括运算符,逗号等
+}

+ 54 - 0
src/main/java/com/gyee/generation/util/rule/expression/TypeValue.java

@@ -0,0 +1,54 @@
+package com.gyee.generation.util.rule.expression;
+
+public enum TypeValue {
+    CUSTOM("CUSTOM", "自定义"),
+    ASSIGN("ASSIGN", "常量"),
+    BASIC("BASIC", "后台计算指标");
+
+    private String code;
+    private String name;
+
+    TypeValue(String code) {
+        this.code = code;
+    }
+
+    TypeValue(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 (TypeValue ele : values()) {
+            if (ele.getCode().equals(code)) {
+                return ele.getName();
+            }
+        }
+        return null;
+    }
+
+
+
+
+}

+ 20 - 19
src/main/resources/application-jn.yml

@@ -133,26 +133,27 @@ frequency:
   #切入切出
   cutinandout: 1
 
-#powerjob:
-#  worker:
-#    #打开测试模式,不强制验证服务器连接
-#    allow-lazy-connect-server: false
-#    #应用程序名称,用于对应用程序进行分组。建议设置与项目名称相同的值。
-#    app-name: powerjob-worker-sample
-#    #是否启用PowerJob Worker,默认为true
-#    enabled: true
-#    #附加的工作流上下文的最大长度。将忽略比该值长的附加工作流上下文值。
-#    max-appended-wf-context-length: 4096
-#    #结果的最大长度。超过该值的结果将被截断。
-#    max-result-length: 4096
-#    #传输端口,默认为27777
-#    port: 27777
-#    #服务器和工作程序之间的传输协议
-#    protocol: http
-#    #PowerJob服务器节点的地址。Ip:端口或域。多个地址应使用逗号分隔。
+powerjob:
+  worker:
+    #打开测试模式,不强制验证服务器连接
+    allow-lazy-connect-server: false
+    #应用程序名称,用于对应用程序进行分组。建议设置与项目名称相同的值。
+    app-name: powerjob-worker-sample
+    #是否启用PowerJob Worker,默认为true
+    enabled: true
+    #附加的工作流上下文的最大长度。将忽略比该值长的附加工作流上下文值。
+    max-appended-wf-context-length: 4096
+    #结果的最大长度。超过该值的结果将被截断。
+    max-result-length: 4096
+    #传输端口,默认为27777
+    port: 27777
+    #服务器和工作程序之间的传输协议
+    protocol: http
+    #PowerJob服务器节点的地址。Ip:端口或域。多个地址应使用逗号分隔。
 #    server-address: 120.46.128.147:7700,120.46.128.147:7701
-#    #H2数据库的存储策略。磁盘或内存。默认值为磁盘。
-#    store-strategy: disk
+    server-address: 127.0.0.1:7700,127.0.0.1:7701
+    #H2数据库的存储策略。磁盘或内存。默认值为磁盘。
+    store-strategy: disk
 
 
 

+ 30 - 30
src/test/java/com/gyee/generation/GenerationTest.java

@@ -32,7 +32,34 @@ public class GenerationTest {
 
         SpringApplication.run(GenerationTest.class, args);
 
+//        /*************************健康管理测点导出**************************/
+//        Calendar c = Calendar.getInstance();
+//
+//
+//        Date begin = new Date();
+//        Date end = null;
+//        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+//        System.out.println(df.format(c.getTime()).toString());
+//
+////        InitialTaosPointService initialTaosPointService = SpringUtils.getBean("initialTaosPointService");
+////
+////        initialTaosPointService.initalFc();
+////        initialTaosPointService.initalFj();
+//
+//        CacheService cacheService = SpringUtils.getBean("cacheService");
+//
+//        cacheService.initRedisCache();
+//
+//        end = new Date();
+//        System.out.println(df.format(end).toString());
+//        System.out.println("完成一次!。。。。。。");
+//        System.out.println("执行用时" + DateUtil.between(begin, end, DateUnit.SECOND) + "秒");
+
+
         /*************************健康管理测点导出**************************/
+
+
+ /*************************redis缓存**************************/
         Calendar c = Calendar.getInstance();
 
 
@@ -41,44 +68,17 @@ public class GenerationTest {
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         System.out.println(df.format(c.getTime()).toString());
 
-//        InitialTaosPointService initialTaosPointService = SpringUtils.getBean("initialTaosPointService");
-//
-//        initialTaosPointService.initalFc();
-//        initialTaosPointService.initalFj();
-
-        CacheService cacheService = SpringUtils.getBean("cacheService");
 
+        CacheService cacheService= SpringUtils.getBean("cacheService");
         cacheService.initRedisCache();
 
         end = new Date();
         System.out.println(df.format(end).toString());
         System.out.println("完成一次!。。。。。。");
-        System.out.println("执行用时" + DateUtil.between(begin, end, DateUnit.SECOND) + "秒");
+//        System.out.println("执行用时" + com.gyee.generation.util.DateUtils.secondsDiff(begin, end) + "秒");
 
 
-        /*************************健康管理测点导出**************************/
-//
-//
-// /*************************redis缓存**************************/
-//        Calendar c = Calendar.getInstance();
-//
-//
-//        Date begin = new Date();
-//        Date end = null;
-//        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-//        System.out.println(df.format(c.getTime()).toString());
-//
-//
-//        CacheService cacheService= SpringUtils.getBean("cacheService");
-//        cacheService.initRedisCache();
-//
-//        end = new Date();
-//        System.out.println(df.format(end).toString());
-//        System.out.println("完成一次!。。。。。。");
-//        System.out.println("执行用时" + com.gyee.generation.util.DateUtils.secondsDiff(begin, end) + "秒");
-//
-//
-//        /*************************redis缓存**************************/
+        /*************************redis缓存**************************/
 
 
         System.out.println("启动完成");

+ 149 - 15
src/test/java/com/gyee/generation/TaosTest.java

@@ -2,8 +2,10 @@ package com.gyee.generation;
 
 
 
-import com.gyee.generation.model.auto.PointDataTaos;
-import com.gyee.generation.model.auto.ProBasicPowerstationPoint;
+import cn.hutool.Hutool;
+import cn.hutool.core.util.RandomUtil;
+import com.gyee.generation.init.CacheContext;
+import com.gyee.generation.model.auto.*;
 import com.gyee.generation.service.initialpoint.TaosInitalPonitService;
 import com.gyee.generation.util.SpringUtils;
 import com.gyee.generation.util.realtimesource.IRealDataUtil;
@@ -12,9 +14,7 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
 import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 @SpringBootApplication
 public class TaosTest
@@ -23,15 +23,149 @@ public class TaosTest
         SpringApplication.run(TaosTest.class, args);
 
         TaosInitalPonitService taosInitalPonitService= SpringUtils.getBean("taosInitalPonitService");
+        IRealDataUtil taosUtil= SpringUtils.getBean("taosUtil");
+
+
+
+                List<PointDataTaos>  taosList=new ArrayList();
+
+        for(ProBasicEquipment wt:CacheContext.wtls)
+        {
+            if(CacheContext.eqpointmap.containsKey(wt.getNemCode()))
+            {
+                Map<String, ProBasicEquipmentPoint> map=CacheContext.eqpointmap.get(wt.getNemCode());
+
+                for (Map.Entry <String, ProBasicEquipmentPoint> entry : map.entrySet()) {
+                    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
+
+                    PointDataTaos taos1=new PointDataTaos();
+                    taos1.setId(entry.getValue().getNemCode());
+                    taos1.setTs(new Timestamp(new Date().getTime()));
+                    taos1.setVal(RandomUtil.randomDouble(0,10));
+                    taos1.setMetric(1);
+                    taosList.add(taos1);
+
+                    if(taosList.size()==100)
+                    {
+                        taosUtil.sendSinglePoint(taosList);
+
+                        taosList.clear();
+                    }
+                }
+
+            }
+        }
+        if(!taosList.isEmpty())
+        {
+            taosUtil.sendSinglePoint(taosList);
+        }
+
+        taosList=new ArrayList();
+
+        for(ProBasicLine ln:CacheContext.lnls)
+        {
+            if(CacheContext.linepointmap.containsKey(ln.getNemCode()))
+            {
+                Map<String, ProBasicPowerstationPoint> map=CacheContext.linepointmap.get(ln.getNemCode());
+
+                for (Map.Entry <String, ProBasicPowerstationPoint> entry : map.entrySet()) {
+                    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
+
+                    PointDataTaos taos1=new PointDataTaos();
+                    taos1.setId(entry.getValue().getNemCode());
+                    taos1.setTs(new Timestamp(new Date().getTime()));
+                    taos1.setVal(RandomUtil.randomDouble(0,10));
+                    taos1.setMetric(1);
+                    taosList.add(taos1);
+
+                    if(taosList.size()==100)
+                    {
+                        taosUtil.sendSinglePoint(taosList);
+
+                        taosList.clear();
+                    }
+                }
+
+            }
+        }
+        if(!taosList.isEmpty())
+        {
+            taosUtil.sendSinglePoint(taosList);
+        }
+
+
+        taosList=new ArrayList();
+
+        for(ProBasicProject pj:CacheContext.pjls)
+        {
+            if(CacheContext.propointmap.containsKey(pj.getNemCode()))
+            {
+                Map<String, ProBasicPowerstationPoint> map=CacheContext.propointmap.get(pj.getNemCode());
+
+                for (Map.Entry <String, ProBasicPowerstationPoint> entry : map.entrySet()) {
+                    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
+
+                    PointDataTaos taos1=new PointDataTaos();
+                    taos1.setId(entry.getValue().getNemCode());
+                    taos1.setTs(new Timestamp(new Date().getTime()));
+                    taos1.setVal(RandomUtil.randomDouble(0,10));
+                    taos1.setMetric(1);
+                    taosList.add(taos1);
+
+                    if(taosList.size()==100)
+                    {
+                        taosUtil.sendSinglePoint(taosList);
+
+                        taosList.clear();
+                    }
+                }
+
+            }
+        }
+        if(!taosList.isEmpty())
+        {
+            taosUtil.sendSinglePoint(taosList);
+        }
+
+        taosList=new ArrayList();
+
+        for(ProBasicPowerstation wp:CacheContext.wpls)
+        {
+            if(CacheContext.wppointmap.containsKey(wp.getNemCode()))
+            {
+                Map<String, ProBasicPowerstationPoint> map=CacheContext.wppointmap.get(wp.getNemCode());
+
+                for (Map.Entry <String, ProBasicPowerstationPoint> entry : map.entrySet()) {
+                    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
+
+                    PointDataTaos taos1=new PointDataTaos();
+                    taos1.setId(entry.getValue().getNemCode());
+                    taos1.setTs(new Timestamp(new Date().getTime()));
+                    taos1.setVal(RandomUtil.randomDouble(0,10));
+                    taos1.setMetric(1);
+                    taosList.add(taos1);
 
+                    if(taosList.size()==100)
+                    {
+                        taosUtil.sendSinglePoint(taosList);
 
+                        taosList.clear();
+                    }
+                }
+
+            }
+        }
+        if(!taosList.isEmpty())
+        {
+            taosUtil.sendSinglePoint(taosList);
+        }
 //        taosInitalPonitService.initalTaosPointTable();
 //
 //        alarmCtService.createSuperTable();
 //        alarmCtService.initalCtAlarm();
 //
 //
-        IRealDataUtil taosUtil= SpringUtils.getBean("taosUtil");
+
 //
 //        String[] points={"SXJ_KGDL_FLFD_BHB_F_P1_L1_0001_AI0061",
 //                "SXJ_KGDL_FLFD_BHB_F_P1_L1_0001_AI0062",
@@ -62,15 +196,15 @@ public class TaosTest
 //
 
 //        List<PointData> ls=taosUtil.getHistoryDatasRaw( "SXJ_KGDL_FLFD_BHB_F_P1_L1_0001_AI0064",1717430400l,1717468230l);
-
-        List<PointData> ls=taosUtil.getHistStat( "SXJ_KGDL_FLFD_BHB_F_P1_L1_0001_AI0064",1717430400l,new Date().getTime()/1000,null,600l,0);
-        for(int i=0;i<ls.size();i++)
-        {
-
-            PointData value= ls.get(i);
-            System.out.println(value.getPointValueInDouble());
-        }
-
+//
+//        List<PointData> ls=taosUtil.getHistStat( "SXJ_KGDL_FLFD_BHB_F_P1_L1_0001_AI0064",1717430400l,new Date().getTime()/1000,null,600l,0);
+//        for(int i=0;i<ls.size();i++)
+//        {
+//
+//            PointData value= ls.get(i);
+//            System.out.println(value.getPointValueInDouble());
+//        }
+//
 
 
         System.out.println("完成!");