Browse Source

代码提交 行权限 还未修改完成

pms 2 years ago
commit
b660bddcd4
100 changed files with 5702 additions and 0 deletions
  1. 8 0
      .idea/.gitignore
  2. 18 0
      .idea/compiler.xml
  3. 8 0
      .idea/encodings.xml
  4. 8 0
      .idea/inspectionProfiles/Project_Default.xml
  5. 20 0
      .idea/jarRepositories.xml
  6. 12 0
      .idea/misc.xml
  7. 6 0
      .idea/vcs.xml
  8. 160 0
      mainFactory/pom.xml
  9. 265 0
      mainFactory/src/main/java/org/bfkj/MainFactoryApplication.java
  10. 71 0
      mainFactory/src/main/java/org/bfkj/api/AuthManageApi.java
  11. 155 0
      mainFactory/src/main/java/org/bfkj/api/CommonApi.java
  12. 58 0
      mainFactory/src/main/java/org/bfkj/api/ControllerApi.java
  13. 545 0
      mainFactory/src/main/java/org/bfkj/application/AuthApplicationImpl.java
  14. 568 0
      mainFactory/src/main/java/org/bfkj/application/DataProcess.java
  15. 126 0
      mainFactory/src/main/java/org/bfkj/application/ServiceInputControl.java
  16. 37 0
      mainFactory/src/main/java/org/bfkj/config/AppConfig.java
  17. 18 0
      mainFactory/src/main/java/org/bfkj/config/CorsConfig.java
  18. 81 0
      mainFactory/src/main/java/org/bfkj/config/ObjectMap.java
  19. 22 0
      mainFactory/src/main/java/org/bfkj/config/SpringContextBeans.java
  20. 51 0
      mainFactory/src/main/java/org/bfkj/config/ThreadPoolConfig.java
  21. 165 0
      mainFactory/src/main/java/org/bfkj/protocol/EsAlgorithm.java
  22. 141 0
      mainFactory/src/main/java/org/bfkj/protocol/MyIbmMQ6.java
  23. 105 0
      mainFactory/src/main/java/org/bfkj/protocol/MyKafKa.java
  24. 106 0
      mainFactory/src/main/java/org/bfkj/protocol/MyRabbitMQ.java
  25. 123 0
      mainFactory/src/main/java/org/bfkj/protocol/WebAPI.java
  26. 664 0
      mainFactory/src/main/java/org/bfkj/utils/DataFormat.java
  27. 89 0
      mainFactory/src/main/java/org/bfkj/utils/LogUtils.java
  28. 488 0
      mainFactory/src/main/java/org/bfkj/utils/MapTools.java
  29. 855 0
      mainFactory/src/main/java/org/bfkj/utils/MyDbHelper.java
  30. 164 0
      mainFactory/src/main/java/org/bfkj/utils/RandomGraphic.java
  31. 65 0
      mainFactory/src/main/java/org/bfkj/utils/ScheduleTask.java
  32. 66 0
      mainFactory/src/main/java/org/bfkj/utils/ScheduleUtil.java
  33. 386 0
      mainFactory/src/main/java/org/bfkj/utils/ScriptEnginePro.java
  34. 24 0
      mainFactory/src/main/resources/application.yml
  35. BIN
      mainFactory/src/main/resources/lib/com.ibmq.mq-6.jar
  36. 15 0
      mainFactory/src/main/resources/static/config.js
  37. BIN
      mainFactory/src/main/resources/static/favicon.ico
  38. 1 0
      mainFactory/src/main/resources/static/index.html
  39. 0 0
      mainFactory/src/main/resources/static/static/css/app.4628f8d7.css
  40. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-00ca601f.fadbb86b.css
  41. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-01740904.8eda0487.css
  42. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-017af434.ac2b8daf.css
  43. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-1d27e940.72a24f8e.css
  44. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-2220f2ce.fadbb86b.css
  45. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-2c5075f5.fadbb86b.css
  46. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-3645cbb5.409d8a87.css
  47. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-37b16d4a.69407d23.css
  48. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-3a1d70dc.bf9274df.css
  49. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-3b7c86d1.f971f60b.css
  50. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-3dce7178.ac2b8daf.css
  51. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-5641bdaa.19212608.css
  52. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-5b6acc49.e73dc104.css
  53. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-62b675ea.17a7dbcc.css
  54. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-630b03b1.a0ebb076.css
  55. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-6b7d854b.ac2b8daf.css
  56. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-7236b413.ffc6d0f5.css
  57. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-7337dfab.aff7e86c.css
  58. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-7f7c5d76.f6d9060d.css
  59. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-9baba730.fadbb86b.css
  60. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-a4f67028.cfe22c71.css
  61. 1 0
      mainFactory/src/main/resources/static/static/css/chunk-a6d352ac.04a0cbbd.css
  62. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-elementUI.0ae24586.css
  63. 0 0
      mainFactory/src/main/resources/static/static/css/chunk-libs.bef63a38.css
  64. BIN
      mainFactory/src/main/resources/static/static/fonts/element-icons.535877f5.woff
  65. BIN
      mainFactory/src/main/resources/static/static/fonts/element-icons.732389de.ttf
  66. BIN
      mainFactory/src/main/resources/static/static/img/bg.7776f3f6.jpg
  67. BIN
      mainFactory/src/main/resources/static/static/img/nodata.22b989c0.png
  68. BIN
      mainFactory/src/main/resources/static/static/img/nopage.0e91ade0.png
  69. 0 0
      mainFactory/src/main/resources/static/static/js/app.54e1bfd1.js
  70. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-00ca601f.ab1768b1.js
  71. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-01740904.b5dcb857.js
  72. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-017af434.8555ead8.js
  73. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-1d27e940.71834f58.js
  74. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-1fde9e50.1b3d5d33.js
  75. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-2220f2ce.8e3c01d5.js
  76. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-23e78f69.b6459a85.js
  77. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-2c5075f5.ef5832ac.js
  78. 1 0
      mainFactory/src/main/resources/static/static/js/chunk-2d0aef25.a03a6613.js
  79. 1 0
      mainFactory/src/main/resources/static/static/js/chunk-2d0af82b.fd27a898.js
  80. 1 0
      mainFactory/src/main/resources/static/static/js/chunk-2d0c45cd.106e6b47.js
  81. 1 0
      mainFactory/src/main/resources/static/static/js/chunk-2d0c4639.ad90241c.js
  82. 1 0
      mainFactory/src/main/resources/static/static/js/chunk-2d0c48c4.9ac6abb6.js
  83. 1 0
      mainFactory/src/main/resources/static/static/js/chunk-2d208336.ffe15ccf.js
  84. 1 0
      mainFactory/src/main/resources/static/static/js/chunk-3645cbb5.face31f8.js
  85. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-37b16d4a.7dd00c08.js
  86. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-3a1d70dc.5f067858.js
  87. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-3b7c86d1.e4d02799.js
  88. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-3dce7178.3e14af77.js
  89. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-5641bdaa.7b05fbf7.js
  90. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-5b6acc49.5128e6a0.js
  91. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-62b675ea.2ac73ef4.js
  92. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-630b03b1.60aa85bc.js
  93. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-6b6701cf.d61edae6.js
  94. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-6b7d854b.01147e32.js
  95. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-7236b413.2395adc2.js
  96. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-7337dfab.8e36cf6b.js
  97. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-78d31bc0.92a6031f.js
  98. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-7f7c5d76.4fbc2e6a.js
  99. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-9baba730.ce84da5c.js
  100. 0 0
      mainFactory/src/main/resources/static/static/js/chunk-a4f67028.63893475.js

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# Zeppelin ignored files
+/ZeppelinRemoteNotebooks/

+ 18 - 0
.idea/compiler.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="CompilerConfiguration">
+    <annotationProcessing>
+      <profile name="Maven default annotation processors profile" enabled="true">
+        <sourceOutputDir name="target/generated-sources/annotations" />
+        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
+        <outputRelativeToContentRoot value="true" />
+        <module name="mainFactory" />
+      </profile>
+    </annotationProcessing>
+  </component>
+  <component name="JavacSettings">
+    <option name="ADDITIONAL_OPTIONS_OVERRIDE">
+      <module name="mainFactory" options="-parameters" />
+    </option>
+  </component>
+</project>

+ 8 - 0
.idea/encodings.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding">
+    <file url="file://$PROJECT_DIR$/mainFactory/src/main/java" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
+    <file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
+  </component>
+</project>

+ 8 - 0
.idea/inspectionProfiles/Project_Default.xml

@@ -0,0 +1,8 @@
+<component name="InspectionProjectProfileManager">
+  <profile version="1.0">
+    <option name="myName" value="Project Default" />
+    <inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
+      <option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,java.util.HashMap,remove" />
+    </inspection_tool>
+  </profile>
+</component>

+ 20 - 0
.idea/jarRepositories.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="RemoteRepositoriesConfiguration">
+    <remote-repository>
+      <option name="id" value="central" />
+      <option name="name" value="Maven Central repository" />
+      <option name="url" value="https://repo1.maven.org/maven2" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="jboss.community" />
+      <option name="name" value="JBoss Community repository" />
+      <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
+    </remote-repository>
+    <remote-repository>
+      <option name="id" value="central" />
+      <option name="name" value="Central Repository" />
+      <option name="url" value="https://maven.aliyun.com/repository/public" />
+    </remote-repository>
+  </component>
+</project>

+ 12 - 0
.idea/misc.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ExternalStorageConfigurationManager" enabled="true" />
+  <component name="MavenProjectsManager">
+    <option name="originalFiles">
+      <list>
+        <option value="$PROJECT_DIR$/pom.xml" />
+      </list>
+    </option>
+  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="graalvm-17" project-jdk-type="JavaSDK" />
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 160 - 0
mainFactory/pom.xml

@@ -0,0 +1,160 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>dataHandler</artifactId>
+        <groupId>org.bfkj</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>mainFactory</artifactId>
+
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <java.version>17</java.version>
+        <graalvm.version>22.3.1</graalvm.version>
+    </properties>
+
+    <dependencies>
+        <!-- apache commons-net 工具包 -ftp使用  -->
+        <dependency>
+            <groupId>commons-net</groupId>
+            <artifactId>commons-net</artifactId>
+            <version>3.9.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-starter-logging</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.vaadin.external.google</groupId>
+                    <artifactId>android-json</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <version>5.3.22</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-test</artifactId>
+            <version>2.7.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-jdbc</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.data</groupId>
+            <artifactId>spring-data-commons</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>8.0.31</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.xerial</groupId>
+            <artifactId>sqlite-jdbc</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.kafka</groupId>
+            <artifactId>kafka-clients</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.dom4j</groupId>
+            <artifactId>dom4j</artifactId>
+            <version>2.1.3</version>
+        </dependency>
+
+        <!--rabbitmq 9-->
+        <dependency>
+            <groupId>com.rabbitmq</groupId>
+            <artifactId>amqp-client</artifactId>
+            <version>5.7.3</version>
+        </dependency>
+        <dependency>
+            <groupId>com.ibm.mq</groupId>
+            <artifactId>com.ibm.mq.allclient</artifactId>
+            <version>9.3.2.0</version>
+        </dependency>
+
+<!--        <dependency>-->
+<!--            <groupId>com.bfkj</groupId>-->
+<!--            <artifactId>ibmq6</artifactId>-->
+<!--            <version>0.0.1</version>-->
+<!--            <scope>system</scope>-->
+<!--            <systemPath>${project.basedir}/src/main/resources/lib/com.ibmq.mq-6.jar</systemPath>-->
+<!--        </dependency>-->
+        <dependency>
+            <groupId>org.elasticsearch.client</groupId>
+            <artifactId>elasticsearch-rest-high-level-client</artifactId>
+            <version>7.15.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.elasticsearch.client</groupId>
+            <artifactId>elasticsearch-rest-client</artifactId>
+            <version>7.15.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.elasticsearch</groupId>
+            <artifactId>elasticsearch</artifactId>
+            <version>7.15.2</version>
+        </dependency>
+
+
+        <dependency>
+            <groupId>com.fasterxml.jackson.datatype</groupId>
+            <artifactId>jackson-datatype-jsr310</artifactId>
+            <version>2.13.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.openjdk.nashorn</groupId>
+            <artifactId>nashorn-core</artifactId>
+            <version>15.4</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <includeSystemScope>true</includeSystemScope>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 265 - 0
mainFactory/src/main/java/org/bfkj/MainFactoryApplication.java

@@ -0,0 +1,265 @@
+package org.bfkj;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import org.bfkj.application.DataProcess;
+import org.bfkj.application.ServiceInputControl;
+import org.bfkj.config.AppConfig;
+import org.bfkj.config.ObjectMap;
+import org.bfkj.utils.LogUtils;
+import org.bfkj.utils.MapTools;
+import org.bfkj.utils.MyDbHelper;
+import org.bfkj.utils.ScheduleUtil;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.Environment;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import java.io.File;
+import java.util.*;
+
+/**
+ * 初始化
+ */
+
+@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
+public class MainFactoryApplication {
+    /*服务初始化: 启动服务*/
+    public static void main(String[] args) {
+        String path = System.getProperty("user.dir"); //获取当前项目的路径
+        if (!checkFileDir(path)) {
+            System.out.println("配置文件夹检测失败");
+            return;
+        }
+        Map<String, String> systemDefaultParams = getSystemDefaultParams(path);
+        ConfigurableApplicationContext context = SpringApplication.run(MainFactoryApplication.class, args);
+        Environment env = context.getBean(Environment.class);
+        // {"systemParams":{}}
+        if (null != env.getProperty("systemParams") && !"".equals(env.getProperty("systemParams"))) {
+            //替换参数systemDefaultParams
+            Map<String, Object> inSystemParams = MapTools.stringToMap(env.getProperty("systemParams"));
+            for (String key : inSystemParams.keySet()) {
+                String keyValue = inSystemParams.get(key).toString().replace("path", path);
+                if (key.equals("workId") && !MapTools.isNumber(keyValue)) { //需要判断workID 只能是数字 ip:端口
+                    System.out.println("WorkId 类型异常");
+                    return;
+                }
+                ObjectMapper mapper = new ObjectMapper();
+                try {
+                    mapper.registerModule(new JavaTimeModule());
+
+                    if (MapTools.stringToMap(keyValue).isEmpty()) {
+                        systemDefaultParams.put(key, keyValue);
+                    } else {
+                        systemDefaultParams.put(key, mapper.writeValueAsString(MapTools.stringToMap(keyValue)));
+                    }
+                } catch (JsonProcessingException e) {
+                    System.out.println("程序启动,传入参数格式异常");
+                    return;
+                }
+            }
+        }
+        //调用接口,更新系统参数(AppConfig类中的方法)
+        AppConfig.setSystemParameters(systemDefaultParams);
+        //初始化本地日志数据库
+        if (!LocalInitDB()) {
+            System.out.println("初始化本地日志数据库失败");
+            return;
+        }
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            System.out.println("初始化获取MyDbHelper对象异常");
+            return;
+        }
+        if (!initDB(myDbHelper)) {
+            System.out.println("初始化远程数据库失败");
+            return;
+        }
+        Runtime.getRuntime().addShutdownHook(new Thread(MainFactoryApplication::currentWorkExit));
+        String serviceURL = AppConfig.getSystemParams("serviceURL");
+        try {
+            String sql = "select Max(deployNodeID) from deploynode where serviceURL = ? ";
+            Map<String, String> hasDeployNodeIDMap = myDbHelper.queryForObject(sql, serviceURL);
+            if (hasDeployNodeIDMap.get("code").equals("-1")) {
+                System.out.println("初始化获取机器表信息: 执行SQL失败 " + hasDeployNodeIDMap.get("message"));
+                return;
+            }
+            String workID = hasDeployNodeIDMap.get("returnData");
+            if (!"".equals(workID) && !"0".equals(workID)) {
+                AppConfig.WORK_ID = workID;
+            } else {
+                sql = "insert into deploynode(serviceURL)  values(?)";
+                Map<String, Object> returnKeyValues = myDbHelper.insertReturnKeyValues(sql, serviceURL);
+                if (returnKeyValues.get("code").equals("-1")) {
+                    System.out.println("根据serviceURL新增入库失败: " + sql + " 参数: " + serviceURL);
+                    return;
+                }
+                AppConfig.WORK_ID = returnKeyValues.get("returnData").toString();
+                if (!MapTools.isNumber(AppConfig.WORK_ID)) {
+                    System.out.println("初始化workID异常: " + AppConfig.WORK_ID);
+                    return;
+                }
+            }
+        } catch (Exception e) {
+            System.out.println("初始化workID异常: " + LogUtils.getException(e));
+            return;
+        }
+
+        Map<String,Object> serviceListResult = myDbHelper.queryByParamsReturnList("SELECT serviceID,serviceType FROM serviceinfo WHERE workId = ?", AppConfig.WORK_ID);
+        List<Map<String, Object>> serviceList = MapTools.getMapList(serviceListResult);
+        if (!serviceListResult.get("code").equals("0") ||  null == serviceList) {
+            System.out.println("初始化获取服务异常: " + serviceListResult.get("message"));
+            return;
+        }
+        int autoCount = 0;
+        for (Map<String, Object> map : serviceList) {
+            // 开启一个线程,启动主动采集
+            Object threadsObj = map.get("serviceType");
+            if (Objects.nonNull(threadsObj) && threadsObj.toString().equals("4")) {
+                autoCount++;
+                Map<String, Object> requestParams = new HashMap<>();
+                requestParams.put("serviceId", map.get("serviceID").toString());
+                ServiceInputControl.startOrStop(requestParams, "1");
+            }
+        }
+        System.out.println("本机共部署服务个数:" + serviceList.size() + ",启动主动采集个数:" + autoCount);
+    }
+
+
+    /**
+     * 获取系统默认参数
+     *
+     * @return
+     */
+    private static Map<String, String> getSystemDefaultParams(String path) {
+        Map<String, String> paramsMaps = new HashMap<>();
+        paramsMaps.put("local_db_connect", "{\"username\":\"bf_dev_epi\",\"password\":\"Bfepi2021(\", \"url\":\"jdbc:sqlite:\" " + path + File.separator + "\"businessCacheLocal.sqlite\", \"driver-class-name\":\"org.sqlite.JDBC\"}");
+        paramsMaps.put("work_id", "1");
+        paramsMaps.put("serviceURL", "127.0.0.1:8080");
+        paramsMaps.put("remote_db_connect", "{\"username\":\"bf_dev_epi\",\"password\":\"Bfepi2021(\",\"url\":\"jdbc:mysql://rm-bp12c6mmk845m73p48o.mysql.rds.aliyuncs.com:3306/test_cen\",\"driver-class-name\":\"com.mysql.cj.jdbc.Driver\"}");
+        String logPath = "jdbc:sqlite:log" + File.separator + File.separator + "log.sqlite";
+        paramsMaps.put("local_log_connect", "{\"username\":\"bf_dev_epi\",\"password\":\"Bfepi2021(\",\"url\":\"" + logPath + "\", \"driver-class-name\":\"org.sqlite.JDBC\"}");
+        return paramsMaps;
+    }
+
+    /*系统退出时 需要做的操作*/
+    private static void currentWorkExit() {
+        ServiceInputControl.ScheduleTaskMaps.values().forEach(ScheduleUtil::cancel);
+        //关闭数据库连接
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        myDbHelper.close();
+        System.out.println("系统正常退出");
+    }
+
+    /*创建文件夹*/
+    private static boolean checkFileDir(String path) {
+        //初始化默认文件创建
+        List<String> pathList = new ArrayList<String>() {{
+            add("cache");
+            add("plugins");
+            add("ftp");
+            add("log");
+        }};
+        for (String paths : pathList) {
+            /*创建文件夹*/
+            File pluginPath = new File(path + File.separator + paths);
+            if (!pluginPath.exists() && !pluginPath.mkdir()) {
+                //todo 系统目录或配置文件检测失败
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static boolean LocalInitDB() {
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.LOCAL_LOG_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            System.out.println("初始化获取MyDbHelper对象异常");
+            return false;
+        }
+        try {
+            myDbHelper.execute("CREATE TABLE if not EXISTS `log_success` (  `id` int PRIMARY KEY  NOT NULL  ,  `success` TEXT  DEFAULT NULL,  `location` TEXT DEFAULT NULL,  `logContent` TEXT,  `serviceId`INT  DEFAULT NULL,  `workId` INT  DEFAULT NULL,  `iNDataContent` TEXT DEFAULT NULL, `outDataContent` TEXT DEFAULT NULL,`calculationLocation` TEXT DEFAULT NULL, `dataObjectId` TEXT DEFAULT NULL,`event` TEXT DEFAULT NULL,`createtime` timestamp not null default current_timestamp)");
+            myDbHelper.execute("CREATE TABLE if not EXISTS `log_error` (  `id` int  PRIMARY KEY  NOT NULL   ,  `success` TEXT  DEFAULT NULL,  `location` TEXT DEFAULT NULL,  `logContent` TEXT,  `serviceId` INT  DEFAULT NULL,  `workId` INT  DEFAULT NULL,  `iNDataContent` TEXT DEFAULT NULL, `outDataContent` TEXT DEFAULT NULL,`calculationLocation` TEXT DEFAULT NULL,  `dataObjectId` TEXT DEFAULT NULL,`event` TEXT DEFAULT NULL,`createtime` timestamp not null default current_timestamp)");
+            myDbHelper.execute("CREATE TABLE if not EXISTS `log_fullData` (  `id` int(11)  NOT NULL auto_increment  PRIMARY KEY,  `dataObjectId `TEXT  DEFAULT NULL,`fullData` TEXT DEFAULT NULL)");
+        } catch (Exception e) {
+            return false;
+        }
+        return true;
+    }
+
+    public static boolean initDB(MyDbHelper myDbHelper) {
+
+        Map<String, String> hasAppMap = myDbHelper.queryForObject("select count(1) hasCount  from t_application where app_id =?", "1");
+        if (hasAppMap.get("code").equals("-1")) {
+            System.out.println("初始化数据库 查询应用信息,查询失败: " + hasAppMap.get("message"));
+            return false;
+        }
+        String hasApp = hasAppMap.get("returnData");
+        if (MapTools.isBlank(hasApp) || hasApp.equals("0")) {
+            myDbHelper.execute("ALTER TABLE `t_application` AUTO_INCREMENT=1;");
+            myDbHelper.execute("INSERT INTO `t_application` (`app_name`, `app_show_id`, `app_show_secret`, `app_code_rule`) VALUES ('底座', 'q7kdjmmaf0kerwpf', '9inu7zpllz1folzsljm498dcpi0lsog1', 'N2');");
+        }
+
+        Map<String, String> hasUserApp = myDbHelper.queryForObject("select count(1) hasUser  from t_user where user_id =?", "1");
+        if (hasUserApp.get("code").equals("-1")) {
+            System.out.println("初始化数据库 查询用户信息信息,查询失败: " + hasAppMap.get("message"));
+            return false;
+        }
+        String hasUser = hasUserApp.get("returnData");
+        if (MapTools.isBlank(hasUser) || hasUser.equals("0")) {
+            myDbHelper.execute("ALTER TABLE `t_user` AUTO_INCREMENT=1;");
+            myDbHelper.execute("INSERT INTO `t_user` (`user_name`, `user_pwd`) VALUES ( 'zhaoke', 'cab264992e7cf0de822013e569a0fec5');");
+        }
+
+        Map<String, String> hasAuthApp = myDbHelper.queryForObject("select count(1) hasAuth  from t_auth");
+        if (hasAuthApp.get("code").equals("-1")) {
+            System.out.println("初始化数据库 查询权限信息信息,查询失败: " + hasAppMap.get("message"));
+            return false;
+        }
+        String hasAuth = hasAuthApp.get("returnData");
+        if (MapTools.isBlank(hasAuth) || hasAuth.equals("0")) {
+            myDbHelper.execute("ALTER TABLE `t_auth` AUTO_INCREMENT=1;");
+            myDbHelper.execute("INSERT INTO `t_auth` (`app_id`, `auth_name`, `auth_type`, `up_auth_id`, `auth_ident`, `auth_status`, `auth_comment`, `show_type`, `show_icon`, `show_index`, `is_link`, `route_info`, `file_link`, `queryTemplateID`, `is_show`, `code`, `queryparams`) VALUES (1, '系统设置', 1, NULL, 'systemSetting', NULL, NULL, 1, NULL, NULL, NULL, '/systemSetting', NULL, NULL, 1, NULL, NULL);");
+        }
+
+        Map<String, String> hasServiceApp = myDbHelper.queryForObject("select count(1) hasService  from serviceinfo");
+        if (hasServiceApp.get("code").equals("-1")) {
+            System.out.println("初始化数据库 查询用户信息信息,查询失败: " + hasAppMap.get("message"));
+            return false;
+        }
+
+        //初始化服务
+        String hasService = hasServiceApp.get("returnData");
+        if (MapTools.isBlank(hasService) || hasService.equals("0")) {
+            myDbHelper.execute("ALTER TABLE `serviceinfo` AUTO_INCREMENT=1;");
+            myDbHelper.execute("INSERT INTO `serviceinfo` (`serviceName`, `serviceDescribe`, `serviceType`) VALUES ( '获取全部权限', '获取全部权限', 1);");
+        }
+        try {
+            //远程表日志表结构结构
+            myDbHelper.execute("CREATE TABLE if not EXISTS `log_success` (  `id` int(11)  NOT NULL auto_increment  PRIMARY KEY,  `success` varchar(8)  DEFAULT NULL,  `location` varchar(255) DEFAULT NULL,  `logContent` varchar(1024)  DEFAULT NULL,  `serviceId` int(11) DEFAULT NULL,  `workId` int(11) DEFAULT NULL,`event` varchar(2) DEFAULT NULL, `iNDataContent` varchar(2048) DEFAULT NULL, `outDataContent` varchar(2048) DEFAULT NULL,`calculationLocation` varchar(8)  DEFAULT NULL,   `dataObjectId` varchar(32) DEFAULT NULL,`createtime` datetime )");
+            myDbHelper.execute("CREATE TABLE if not EXISTS `log_error` (  `id` int(11)  NOT NULL auto_increment  PRIMARY KEY,  `success` varchar(8)  DEFAULT NULL,  `location` varchar(255) DEFAULT NULL, `logContent` varchar(1024)  DEFAULT NULL,  `serviceId` int(11) DEFAULT NULL,  `workId` int(11) DEFAULT NULL,  `event` varchar(2) DEFAULT NULL,`iNDataContent` varchar(2048) DEFAULT NULL, `outDataContent` varchar(2048) DEFAULT NULL,`calculationLocation` varchar(8)  DEFAULT NULL,  `dataObjectId` varchar(32) DEFAULT NULL,`createtime`datetime)");
+            myDbHelper.execute("CREATE TABLE if not EXISTS `log_fullData` (  `id` int(11)  NOT NULL auto_increment  PRIMARY KEY,  `dataObjectId` varchar(32) DEFAULT NULL,`fullData` longtext DEFAULT NULL)");
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    @Scheduled(cron = "0 15 * * * ?")
+    public void closeObject() {
+        long timeOut = 15 * 1000 * 60;
+        for (DataProcess dataProcess : ObjectMap.dataProcessMaps.values()) {
+            if (System.currentTimeMillis() - dataProcess.getLastActive() > timeOut) {
+                String serviceId = dataProcess.getServiceId();
+                ObjectMap.getordropInput(serviceId, false);
+            }
+        }
+        for (MyDbHelper myDbHelper : ObjectMap.myDbHelperMaps.values()) {
+            String connectStr = myDbHelper.getConnectConfig();
+            ObjectMap.getordropMyDbHelper(connectStr, false);
+        }
+    }
+}

+ 71 - 0
mainFactory/src/main/java/org/bfkj/api/AuthManageApi.java

@@ -0,0 +1,71 @@
+package org.bfkj.api;
+
+
+import jakarta.servlet.http.HttpServletRequest;
+import org.bfkj.application.AuthApplicationImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+@RestController
+@RequestMapping("foxlibc")
+//@CrossOrigin
+public class AuthManageApi {
+
+    @Autowired
+    AuthApplicationImpl authApplication;
+
+    @PostMapping("getToken")
+    public Object getToken(@RequestBody Map<String, String> params, HttpServletRequest httpServletRequest) {
+        String sessionID = httpServletRequest.getSession().getId();
+        return authApplication.getToken(params, sessionID);
+    }
+
+    // todo 新增refreshToken()
+    @PostMapping("refreshToken")
+    public Object refreshToken(@RequestBody Map<String, String> params) {
+        return authApplication.refreshToken(params);
+    }
+
+    /**
+     * 获取验证码
+     *
+     * @param params {appId:"",token:""}
+     * @return 验证码执行结果信息
+     */
+    @PostMapping("getVCode") //todo getVCode()
+    public Object getVCode(@RequestBody Map<String, Object> params) {
+        return authApplication.getVCode(params);
+    }
+
+    /**
+     * 用户登录并获取用户权限信息
+     *
+     * @param data{”token“:”“,”appid“:”“,”username“:”“,”password“:”“}
+     * @return 获取用户权限信息
+     */
+    @PostMapping("sign-in")
+    public Map<String, Object> signIn(@RequestBody Map<String, String> data) {
+        return authApplication.signIn(data);
+    }
+    @PostMapping("loginOut")
+    public Map<String, Object>loginOut(@RequestBody Map<String, String> params) {
+        return authApplication.loginOut(params);
+    }
+
+    @PostMapping("getAuth")
+    public Map<String, Object> getAuth(@RequestBody Map<String, String> params) {
+        return authApplication.getAuth(params);
+    }
+
+
+    @PostMapping("/initColumnSet")
+    public Map<String, Object> initColumnSet(@RequestBody Map<String, Object> data) {
+        return authApplication.initColumnSet(data);
+    }
+
+}

+ 155 - 0
mainFactory/src/main/java/org/bfkj/api/CommonApi.java

@@ -0,0 +1,155 @@
+package org.bfkj.api;
+
+import org.bfkj.application.AuthApplicationImpl;
+import org.bfkj.application.DataProcess;
+import org.bfkj.config.AppConfig;
+import org.bfkj.config.ObjectMap;
+import org.bfkj.utils.MapTools;
+import org.bfkj.utils.MyDbHelper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * 统一入口
+ */
+@RestController
+@RequestMapping("openApi")
+//@CrossOrigin
+public class CommonApi {
+
+    @Autowired
+    AuthApplicationImpl authApplication;
+
+    /**
+     * 服务数据恢复 : 因为日志的数据内容拆分为4个字段,所有此方法需要调整可
+     */
+    @RequestMapping("abnormalDataRecovery")
+    public Map<String,Object> abnormalDataRecovery(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
+        String verificationToke = authApplication.verificationUserToken(token);
+        if (!MapTools.isBlank(verificationToke)) {
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code","-1");
+            errMap.put("message","用户令牌验证失败:" + verificationToke);
+            return errMap;
+        }
+        return authApplication.abnormalDataRecovery(params);
+
+    }
+
+    /**
+     * 查询入口CRUD
+     */
+    @PostMapping("query")
+    @ResponseBody
+    public Object queryApi(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
+        return commonInterface(token, params, "0");
+    }
+
+    /**
+     * 新增入口CRUD
+     */
+    @PostMapping("newdata")
+    @ResponseBody
+    public Object newDataApi(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
+        return commonInterface(token, params, "1");
+    }
+
+    /**
+     * /**
+     * 更新入口CRUD
+     */
+    @PostMapping("modifydata")
+    @ResponseBody
+    public Object modifyDataApi(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
+        return commonInterface(token, params, "2");
+    }
+
+    /**
+     * /**
+     * /**
+     * 删除入口CRUD
+     */
+    @PostMapping("movedata")
+    @ResponseBody
+    public Object moveDataApi(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
+        return commonInterface(token, params, "3");
+    }
+
+    /**
+     * 统一接收处理
+     */
+    private Map<String,Object> commonInterface(Map<String, String> token, Map<String, Object> params, String defaultEvent) {
+        if (token.containsKey("token")) {
+            String appToken = token.get("token");
+            String verificationToke = authApplication.verificationToken(appToken);
+            if (!MapTools.isNumber(verificationToke)) {
+                HashMap<String, Object> errMap = new HashMap<>();
+                errMap.put("code","-1");
+                errMap.put("message","应用token验证失败:" + verificationToke);
+                return errMap;
+            }
+        } else {
+            String verificationToke = authApplication.verificationUserToken(token);
+            if (!MapTools.isBlank(verificationToke)) {
+                HashMap<String, Object> errMap = new HashMap<>();
+                errMap.put("code","-1");
+                errMap.put("message","用户令牌验证失败:" + verificationToke);
+                return errMap;
+            }
+        }
+        Object event = params.get("event");//获取参数中的事件标识
+        if (Objects.isNull(event) && !MapTools.isBlank(defaultEvent)) {//如果参数中的没有事件标识并且有默认事件标识则使用默认事件标识
+            event = defaultEvent;
+            params.put("event", defaultEvent);
+        }
+        if (!MapTools.isBlank(defaultEvent) && !event.equals(defaultEvent)) {//如果有默认事件标识且传入的事件标识与默认事件标识不相同则返回错误
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code","-1");
+            errMap.put("message","当前接口只支持event为" + defaultEvent + ",当前接收参数为:" + params);
+            return errMap;
+
+        }
+        Object serviceId = params.get("serviceId");
+        if (Objects.isNull(serviceId) || !params.containsKey("event")) {
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code","-1");
+            errMap.put("message","缺失必要的参数:服务编号serviceId或事件标识event" + params);
+            return errMap;
+        }
+        //通过服务ID 查询对应服务的服务类型是否为1,如果时则继续,否则返回
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code","-1");
+            errMap.put("message","服务:" + serviceId + " 获取数据库对象失败,异常信息 " + myDbHelper.getErrorMessage());
+            return errMap;
+        }
+        Map<String, String> hasServiceMap = myDbHelper.queryForObject("select count(1) count from serviceinfo  where serviceID=? and serviceType = 1", serviceId);
+        if (hasServiceMap.get("code").equals("-1")) {
+            System.out.println("数据接受获取服务信息,查询失败: " + hasServiceMap.get("message"));
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code","-1");
+            errMap.put("message","数据接受获取服务信息,查询失败: " + hasServiceMap.get("message"));
+            return errMap;
+        }
+        String count = hasServiceMap.get("returnData");
+        if ("".equals(count)|| "0".equals(count)) {
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code","-1");
+            errMap.put("message","服务:" + serviceId + "是采集服务不支持操作");
+            return errMap;
+        }
+        DataProcess dataProcessObj = ObjectMap.getordropInput(serviceId.toString(), true);//获取数据输出处理对象
+        if (null == dataProcessObj || !MapTools.isBlank(dataProcessObj.getErrorMessage())) {
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code","-1");
+            errMap.put("message","服务不可用:" + (null == dataProcessObj ? "" : dataProcessObj.getErrorMessage()));
+            return errMap;
+        }
+        return dataProcessObj.processData(params);
+    }
+}

+ 58 - 0
mainFactory/src/main/java/org/bfkj/api/ControllerApi.java

@@ -0,0 +1,58 @@
+package org.bfkj.api;
+
+import org.bfkj.application.AuthApplicationImpl;
+import org.bfkj.application.ServiceInputControl;
+import org.bfkj.utils.MapTools;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+//todo  控制类 API(start,stop)
+
+@RestController
+@RequestMapping("controlApi")
+public class ControllerApi {
+    @Autowired
+    AuthApplicationImpl authApplication;
+
+    /***
+     * 主动采集与被动采集的启动
+     * @param token
+     * @param params
+     * @return
+     */
+    @PostMapping("start")
+    @ResponseBody
+    public Map<String,Object> start(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
+        String verificationToke = authApplication.verificationUserToken(token);
+        if (!MapTools.isBlank(verificationToke)) {
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code","-1");
+            errMap.put("message","用户令牌验证失败:" + verificationToke);
+            return errMap;
+        }
+        //令牌校验
+        return ServiceInputControl.startOrStop(params, "1");
+    }
+    /**
+     * 主动采集与被动采集的停止
+     *
+     * @param token
+     * @param params
+     * @return
+     */
+    @PostMapping("stop")
+    @ResponseBody
+    public Map<String,Object> stop(@RequestHeader Map<String, String> token, @RequestBody Map<String, Object> params) {
+        String verificationToke = authApplication.verificationUserToken(token);
+        if (!MapTools.isBlank(verificationToke)) {
+            HashMap<String, Object> errMap = new HashMap<>();
+            errMap.put("code","-1");
+            errMap.put("message","用户令牌验证失败:" + verificationToke);
+            return errMap;
+        }
+        return ServiceInputControl.startOrStop(params, "0");
+    }
+}

+ 545 - 0
mainFactory/src/main/java/org/bfkj/application/AuthApplicationImpl.java

@@ -0,0 +1,545 @@
+package org.bfkj.application;
+
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.bfkj.config.AppConfig;
+import org.bfkj.config.ObjectMap;
+import org.bfkj.utils.LogUtils;
+import org.bfkj.utils.MapTools;
+import org.bfkj.utils.MyDbHelper;
+import org.bfkj.utils.RandomGraphic;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+@Service
+public class AuthApplicationImpl {
+
+    //统一成功信息处理
+    public Map<String, Object> processSuccess(Object returnData) {
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "0");
+        returnMap.put("returnData", returnData);
+        return returnMap;
+    }
+
+    //统一错误信息处理
+    public Map<String, Object> processFail(String errorMessage) {
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "-1");
+        returnMap.put("message", errorMessage);
+        return returnMap;
+    }
+
+
+    /**
+     * 获取应用令牌
+     *
+     * @param params
+     * @param sessionID
+     * @return
+     */
+    public Object getToken(Map<String, String> params, String sessionID) {
+        String appid = params.get("appid");
+        String appSecret = params.get("appSecret");
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            return processFail("获取数据库连接失败");
+        }
+        Map<String, Object> appInfoResult = myDbHelper.queryByParamsReturnList("select app_code_rule,app_id,app_name,app_log, app_token_effective,active_duration from t_application where  app_show_id =? AND  app_show_secret=?", appid, appSecret);
+        if (!appInfoResult.get("code").equals("0")) {
+            return processFail("查询异常" + appInfoResult.get("message"));
+        }
+        List<Map<String, Object>> appData = (List<Map<String, Object>>) appInfoResult.get("returnData");
+        if (appData.isEmpty()) {
+            return processFail("错误的appid或appSecret");
+        }
+//        无条件删除已经过期的令牌delete from 应用验证表 where app_effective > NOW()
+        myDbHelper.updateByCondition("delete from t_application_login where app_effective > NOW()", null);
+        // 生成全局唯一的应用令牌
+        String appTokenOnly = createLifeCycleCol(9999L, 9999);
+        /*当前请求ID*/
+        String serviceOnlyID = MapTools.getMD5Str(sessionID);
+        //创建当前请求的令牌
+        Map<String, Object> appInfoData = appData.get(0); //apptoken 有效时长,用户有效存活时长
+        String app_id = appInfoData.get("app_id").toString();
+        Map<String, Object> insertReturnKeyValues = myDbHelper.updateByCondition("insert into t_application_login(app_id,app_token,app_effective,session_id,request_time) values(?,?," + (Objects.nonNull(appInfoData.get("app_token_effective")) ? "" + appInfoData.get("app_token_effective") + " HOUR)" : null) + " ,?,?)", null, app_id, appTokenOnly, serviceOnlyID, MapTools.dateTostr(new Date()));
+        if (Objects.isNull(insertReturnKeyValues) || insertReturnKeyValues.get("code").equals("-1")) {
+            return processFail("创建应用Token异常");
+        }
+        Map<String, Object> listResult = myDbHelper.queryByParamsReturnList("select * from t_application_login where  app_token=?  ", appTokenOnly);
+        HashMap<String, Object> returnData = new HashMap<>();
+        returnData.put("app_token", appTokenOnly);
+        returnData.put("app_effective", ((List<Map<String, Object>>) listResult.get("returnData")).get(0).get("app_effective")); //令牌有效期
+        returnData.put("active_duration", appInfoData.get("active_duration"));
+        returnData.put("app_name", appInfoData.get("app_name"));
+        returnData.put("app_log", appInfoData.get("app_log"));
+        returnData.put("app_code_rule", appInfoData.get("app_code_rule"));
+        return processSuccess(returnData);
+    }
+
+    /**
+     * 校验应用令牌的逻辑(app_token) 返回字符串----令牌唯一性确保无需其它信息进行判断
+     *
+     * @param appToken
+     * @return
+     */
+    public String verificationToken(String appToken) {
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            return "验证令牌获取远程数据库连接失败" + myDbHelper.getErrorMessage();
+        }
+        Map<String, Object> verificationTokenResult = myDbHelper.queryByParamsReturnList("select app_id from t_application_login where app_token=? and  ( app_effective > NOW() or  app_effective is NULL )", appToken);
+        List<Map<String, Object>> returnData = MapTools.getMapList(verificationTokenResult);
+        return (!verificationTokenResult.get("code").equals("0") || Objects.isNull(returnData) || returnData.isEmpty()) ? "查询错误或令牌验证不通过" : returnData.get(0).get("app_id").toString();
+    }
+
+    /**
+     * 刷新应用令牌的逻辑:
+     *
+     * @param params
+     * @return
+     */
+    public Object refreshToken(Map<String, String> params) {
+        String app_token = params.get("app_token");
+        if (Objects.isNull(app_token)) {
+            return processFail("app_token为空,刷新失败");
+
+        }
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            return processFail("刷新应用app_token获取远程数据库连接失败" + myDbHelper.getErrorMessage());
+        }
+        String appid = verificationToken(app_token);
+        if (!MapTools.isNumber(appid)) {
+            return processFail("校验token失败: " + appid);
+        }
+        // 获取令牌有效时长
+        Map<String, Object> appTokenEffectiveResult = myDbHelper.queryByParamsReturnList("select app_token_effective from t_application where  app_id = ?", appid);
+        List<Map<String, Object>> returnData = MapTools.getMapList(appTokenEffectiveResult);
+        if (null == returnData || returnData.isEmpty()) {
+            return appTokenEffectiveResult;
+        }
+
+        Object app_token_effective = returnData.get(0).get("app_token_effective");
+        String app_effective = Objects.nonNull(app_token_effective) ? "DATE_ADD(NOW(),INTERVAL  " + app_token_effective + " HOUR)" : null;
+        try {
+            myDbHelper.updateByCondition("update t_application_login set app_effective=" + app_effective + "  where app_token=?", null, app_token);
+            Map<String, Object> listResult = myDbHelper.queryByParamsReturnList("select * from t_application_login where  app_token=?  ", app_token);
+            List<Map<String, Object>> returnD = MapTools.getMapList(listResult);
+            if (null == returnD || returnD.isEmpty()) {
+                return listResult;
+            }
+            HashMap<String, Object> returnMap = new HashMap<>();
+            returnMap.put("app_token", app_token);
+            returnMap.put("app_effective", returnD.get(0).get("app_effective"));
+            return processSuccess(returnMap);
+        } catch (Exception e) {
+            return processFail("app_token 刷新失败");
+
+        }
+    }
+
+    /**
+     * 获取验证码
+     *
+     * @param params {appId:"",token:""}
+     * @return 验证码执行结果信息
+     */
+    public Object getVCode(Map<String, Object> params) {
+        Object app_token = params.get("app_token");
+        if (Objects.isNull(app_token)) {
+            return processFail("app_token为空");
+        }
+        String appid = verificationToken(app_token.toString());
+        if (!MapTools.isNumber(appid)) {
+            return processFail("tokan校验失败:" + appid);
+        }
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            return processFail("获取验证码,获取数据库连接失败");
+        }
+        Map<String, Object> appCodeRuleResult = myDbHelper.queryByParamsReturnList("SELECT  app_code_rule ,app_code_effective   FROM t_application WHERE app_id =?", appid);
+        List<Map<String, Object>> returnD = MapTools.getMapList(appCodeRuleResult);
+        if (appCodeRuleResult.get("code").equals("-1")) {
+            return processFail("获取验证规则失败");
+        }
+        // 组建验证码规则
+        Object appRule = null;
+        int appCodeEffective = 0;
+        if (Objects.nonNull(returnD) && returnD.size() > 0) {
+            appRule = returnD.get(0).get("app_code_rule");
+            appCodeEffective = Objects.isNull(returnD.get(0).get("app_code_effective")) ? 300 : Integer.parseInt(returnD.get(0).get("app_code_effective").toString());
+        }
+        if (Objects.isNull(appRule)) {
+            return processFail("无需验证码");
+        }
+
+        String codeFormat = "";
+        //codeType == 1 ? "0123456789" : "0123456789ACDEFGHJKLMNPQRSTWXY"
+        if (appRule.toString().contains("A")) {
+            codeFormat = codeFormat + "ACDEFGHJKLMNPQRSTWXY";
+        } else if (appRule.toString().contains("N")) {
+            codeFormat = codeFormat + "0123456789";
+        } else {
+            return processFail("验证码规则不存在");
+
+        }
+        // 生成验证码
+        String appRuleStr = appRule.toString();  //A2N4
+        Map<String, Object> map = RandomGraphic.generateVerifyCode(Integer.parseInt(appRuleStr.substring(appRuleStr.length() - 1)), codeFormat);
+        if (null == map) {
+            return processFail("生成验证码失败");
+        }
+        try {
+            myDbHelper.updateByCondition("update t_application_login set app_code = ?,app_code_expire = DATE_ADD(NOW(),INTERVAL  " + appCodeEffective + " SECOND )  where app_token=?", null, map.get("verifyCode").toString(), app_token);
+            Map<String, Object> listResult = myDbHelper.queryByParamsReturnList("select * from t_application_login where  app_token=?  ", app_token);
+            List<Map<String, Object>> applicationInfo = MapTools.getMapList(listResult);
+            if (listResult.get("code").equals("-1") || null == applicationInfo) {
+                return processFail("获取验证规则失败");
+
+            }
+            return processSuccess(new HashMap<String, Object>() {{
+                put("verifyCode", map.get("verifyCodeImage"));
+                put("app_code_expire", applicationInfo.get(0).get("app_code_expire"));
+
+            }});
+        } catch (Exception e) {
+            return processFail("验证码异常:" + LogUtils.getException(e));
+        }
+    }
+
+    /**
+     * 用户登录并获取用户权限信息
+     *
+     * @param data{”token“:”“,”appid“:”“,”username“:”“,”password“:”“}
+     * @return 获取用户权限信息
+     */
+    public Map<String, Object> signIn(Map<String, String> data) {
+        String username = data.get("username");
+        String password = data.get("password");
+        String verificationCode = data.get("verifyCode");
+        String app_token = data.get("app_token");
+        String app_id = verificationToken(app_token);
+        if (!MapTools.isNumber(app_id)) {
+            return processFail("登陆token校验失败:" + app_id);
+        }
+        //校验验证码
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            return processFail("用户登陆,获取数据库连接失败");
+        }
+        Map<String, Object> applicationLogin = myDbHelper.queryByParamsReturnList("select 1 from t_application_login where app_token=? and if(app_code is null,true,app_code = ? and app_code_expire > NOW())", app_token, verificationCode);
+        List<Map<String, Object>> applicationList = MapTools.getMapList(applicationLogin);
+
+
+        if (!applicationLogin.get("code").equals("0")) {
+            return processFail("校验验证码,执行错误");
+        }
+        if (applicationList == null || applicationList.isEmpty()) {
+            return processFail("验证码错误或过期");
+        }
+        Map<String, Object> userInfoResult = myDbHelper.queryByParamsReturnList("select user_id,token_valid_duration from t_user where user_name = ?  and user_pwd =?", username, password);
+        if (!userInfoResult.get("code").equals("0")) {
+            return processFail("校验用户信息,执行异常");
+        }
+        List<Map<String, Object>> userInfoList = MapTools.getMapList(userInfoResult);
+        if (null == userInfoList || userInfoList.isEmpty()) {
+            return processFail("用户名或密码错误");
+        }
+        String userID = userInfoList.get(0).get("user_id").toString();
+        String userToken = MapTools.getMD5Str(new Date().getTime() + "");
+        try {
+            Object token_valid_duration = userInfoList.get(0).get("token_valid_duration");
+            myDbHelper.updateByCondition("update t_user set user_token = ?,user_status = 1,signInTime = NOW(),token_valid_time = if(" + Objects.isNull(token_valid_duration) + ",null, DATE_ADD(NOW(),INTERVAL   " + (Objects.isNull(token_valid_duration) ? 0 : Integer.parseInt(token_valid_duration.toString())) + " SECOND) )  where user_id= ? ", null, userToken, userID);
+            return processSuccess(new HashMap<String, Object>() {{
+                put("user_token", userToken);
+                put("user_id", userID);
+            }});
+        } catch (Exception e) {
+            return processFail("更新用户Token失败");
+        }
+    }
+
+    public String verificationUserToken(Map<String, String> params) {
+        String user_token = params.get("user_token");
+        String user_id = params.get("user_id");
+        if (Objects.isNull(user_token) || Objects.isNull(user_id)) return "user_token 或则 user_id为空";
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            return "验证user_token获取远程数据库连接失败" + myDbHelper.getErrorMessage();
+        }
+        Map<String, String> userCountMap = myDbHelper.queryForObject("select count(1) as count from t_user where user_id=? and user_token = ? and (token_valid_time > NOW() or  token_valid_time is null )", user_id, user_token);
+        if ((!userCountMap.get("code").equals("0") || Objects.isNull(userCountMap.get("returnData")) || "0".equals(userCountMap.get("returnData")))) {
+            return "查询错误或令牌验证不通过";
+        }
+        return null;
+    }
+
+    /**
+     * 用户登出
+     *
+     * @param params
+     * @return
+     */
+    public Map<String, Object> loginOut(Map<String, String> params) {
+        String errorInfo = verificationUserToken(params);
+        if (Objects.nonNull(errorInfo)) {
+            return processFail("用户登出失败: " + errorInfo);
+        }
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            return processFail("用户登出,获取远程数据库连接失败" + myDbHelper.getErrorMessage());
+        }
+        try {
+            String user_id = params.get("user_id");
+            myDbHelper.updateByCondition("update t_user set user_token = null,user_status = 0,LogoutTime = NOW() where user_id=?", null, user_id);
+            return processSuccess("用户登出成功");
+        } catch (Exception e) {
+            return processFail("用户登出失败: ");
+        }
+    }
+
+    public Map<String, Object> getAuth(Map<String, String> params) {
+        String errorInfo = verificationUserToken(params); //user_toke,user_id
+        if (Objects.nonNull(errorInfo)) {
+            return processFail("获取权限: " + errorInfo);
+        }
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            return processFail("获取用户权限,获取远程数据库连接失败" + myDbHelper.getErrorMessage());
+        }
+        String user_id = params.get("user_id");
+        if (user_id.equals("1")){ // 如果是内置管理员 则获取全部权限
+            return myDbHelper.queryByParamsReturnList(" select * from t_auth" );
+        }
+        return myDbHelper.queryByParamsReturnList(" select * from t_auth" );
+        // 从user_auth表中获取导航栏权限: select auth_id from t_user_auth  where user_id = ?
+//        return myDbHelper.queryByParamsReturnList(" select TA.* from t_user_auth  TUA LEFT JOIN t_auth TA  ON TA.auth_id = TUA.auth_id where TUA.user_id = ?",user_id);
+    }
+    public Map<String, Object> initColumnSet(Map<String, Object> data) {
+        if (!data.containsKey("auth_id")) {
+            return processFail("权限编号为空");
+        }
+        String auth_id = data.get("auth_id").toString();
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            return processFail("初始化列设置:权限编号:" + auth_id + " 获取数据库对象异常");
+        }
+
+        Map<String, Object> serviceInfoResult = myDbHelper.queryByParamsReturnList("select serviceID,serviceType from serviceinfo where serviceID = (select max(serviceID) as serviceID from t_auth where auth_id = ?) and serviceType ='1'", auth_id);
+        List<Map<String, Object>> serviceInfoList = MapTools.getMapList(serviceInfoResult);
+
+        if (!"0".equals(serviceInfoResult.get("code"))) {
+            return processFail("初始化列设置:权限编号:" + auth_id + " 获取服务列表异常");
+        }
+        if (Objects.isNull(serviceInfoList) || serviceInfoList.isEmpty()) {
+            return processFail("初始化列设置:权限编号:" + auth_id + " 未找到对应的服务或者服务为采集类,不可进行列设置初始化");
+        }
+        String serviceID = serviceInfoList.get(0).get("serviceID").toString();
+        // 通过服务获取列设置
+        List<Map<String, Object>> columnList;
+        try {
+            Map<String, Object> queryByParamsReturnMap = myDbHelper.queryByParamsReturnList("select calculation_library.*,datasourceinfo.connectConfig  from calculation_library INNER JOIN datasourceinfo on datasourceinfo.dataSourceID = calculation_library.datasource_id  where service_id=? and library_type =3 order by library_sort, library_id limit 1", serviceID);
+            if (queryByParamsReturnMap.get("code").equals("-1")) {
+                return processFail("通过服务获取列设置:SQL执行异常");
+            }
+            List<Map<String, Object>> queryByParamsReturnList = MapTools.getMapList(queryByParamsReturnMap);
+            if (Objects.isNull(queryByParamsReturnList) || queryByParamsReturnList.isEmpty()) {
+                return processFail("当前服务暂时不支持列设置初始化");
+            }
+            Map<String, Object> libraryInfo = queryByParamsReturnList.get(0);
+            Object tableName = libraryInfo.get("sourceObjectName");
+            String sql = Objects.isNull(tableName) ? (Objects.isNull(libraryInfo.get("computing_expression")) ? null : libraryInfo.get("computing_expression").toString()) : (" select * from " + tableName + " where 1 =2");
+            if (Objects.isNull(sql)) {
+                return processFail("服务配置错误");
+            }
+            //todo 获取对应的数据源 获取mydb对象
+            // 替换SQL中的符号
+            String expression = "(?<=《)([^》]+)?(?=》)";
+            Pattern regExpression = Pattern.compile(expression);  // select * from user where userid = 《userID》 select * from user where userid is null
+            Matcher parameterNames = regExpression.matcher(sql);
+            while (parameterNames.find()) {
+                String tempColumn = parameterNames.group(); //
+                sql = sql.replaceFirst("《" + tempColumn + "》", " null ");
+            }
+            String connectConfig = libraryInfo.get("connectConfig").toString();
+            MyDbHelper remoteMyDbHelper = ObjectMap.getordropMyDbHelper(connectConfig);
+            if (Objects.nonNull(remoteMyDbHelper.getErrorMessage())) {
+                return processFail("初始化列设置:权限编号:" + auth_id + " 获取数据库对象异常");
+            }
+            Map<String, Object> specialSearchDataResult = remoteMyDbHelper.getAllColumnForSet(sql);
+            if (!"0".equals(specialSearchDataResult.get("code"))) {
+                return processFail("初始化列设置:权限编号:" + auth_id + " 模拟查询异常:" + specialSearchDataResult.get("message"));
+            }
+            columnList = MapTools.getMapList(specialSearchDataResult);
+            if (Objects.isNull(columnList) || columnList.isEmpty()) {
+                return processFail("当前服务暂时不支持列设置初始化");
+            }
+
+        } catch (Exception e) {
+            return processFail("获取服务对应算法执行异常" + LogUtils.getException(e));
+        }
+
+        Map<String, Object> columnSetListResult = myDbHelper.queryByParamsReturnList("select  * from querytemplatecolumnset where serviceOutPutId=?", auth_id);
+        List<Map<String, Object>> columnSetList = MapTools.getMapList(columnSetListResult);
+        if (!"0".equals(columnSetListResult.get("code")) || null == columnSetList) {
+            return processFail("初始化列设置:权限编号:" + auth_id + " 获取权限列标志异常" + columnSetListResult.get("message"));
+        }
+
+        //初始化一个List<string> OLDColumnList--- > user(userPWD)-- 数据库元数据
+        List<String> OLDColumnList = new ArrayList<>();
+        HashMap<Object, Map<String, Object>> tempColumnSet = new HashMap<>();
+        for (Map<String, Object> currentMap : columnSetList) {
+            OLDColumnList.add(currentMap.get("columnName").toString());
+            tempColumnSet.put(currentMap.get("columnName").toString(), currentMap);
+        }
+        List<Map<String, Object>> insertList = new ArrayList<>();
+        for (Map<String, Object> columnMap : columnList) {
+            String columnName = columnMap.get("columnName").toString();
+            if (OLDColumnList.contains(columnName)) {
+                OLDColumnList.remove(columnName);
+            } else {
+                insertList.add(columnMap);
+            }
+        }
+        List<Map<String, Object>> deleteList = new ArrayList<>();
+        for (String columnName : OLDColumnList) {
+            // 通过columnName与权限ID获取到此行的数据
+            deleteList.add(tempColumnSet.get(columnName));
+        }
+
+        if (deleteList.size() > 0) {
+            String sql = " delete from querytemplatecolumnset where serviceOutPutId= ? and columnName=?";
+            List<Object[]> selectParams = new ArrayList<>();
+            for (Map<String, Object> deleteMap : deleteList) {
+                List<String> inList = new ArrayList<>();
+                inList.add(auth_id);
+                inList.add(deleteMap.get("columnName").toString());
+                selectParams.add(inList.toArray());
+            }
+            myDbHelper.updateByCondition(sql, selectParams);
+        }
+        if (insertList.size() > 0) {
+            String sql = " insert into  querytemplatecolumnset(serviceOutPutId,columnName,columnLabel) values(?,?,?)";
+            List<Object[]> insertParams = new ArrayList<>();
+            for (Map<String, Object> insertMap : insertList) {
+                List<String> inList = new ArrayList<>();
+                inList.add(auth_id);
+                inList.add(insertMap.get("columnName").toString());
+                inList.add(insertMap.get("columnLable").toString());
+                insertParams.add(inList.toArray());
+            }
+            myDbHelper.updateByCondition(sql, insertParams);
+        }
+        return myDbHelper.queryByParamsReturnList("select * from querytemplatecolumnset where serviceOutPutId=?", auth_id);
+    }
+
+    //todo 目前采集实际是定时器,真正的采集是算法库中的算法,如果从头开始计算,代表是采集到的新数据,而不是旧数据的恢复
+    // 如果需要真正的旧数据恢复,则必须从指定的算法开始,而不是从头开始
+    // 需要将dataprocess对象中的算法循环,单独抽离出来,成为一个方法,此方法默认从第一个算法开始,也可以指定从第几个算法开始
+    public Map<String, Object> abnormalDataRecovery(Map<String, Object> params) {
+        String serviceId = Objects.isNull(params.get("serviceId")) ? null : params.get("serviceId").toString();
+        Object dataObjectId = params.get("dataObjectId");
+        if (MapTools.isBlank(serviceId) && Objects.isNull(dataObjectId)) {
+            return processFail("serviceId与dataObjectId不能同时为空");
+        }
+        List<Object> pmList = new ArrayList<>();
+        pmList.add("-1"); // todo 应该从logerror中获取最后一条,此时要求dataobject
+        String sql = "select * from log_error where success = ? ";
+        if (Objects.nonNull(serviceId)) {
+            sql = sql + " and serviceId = ?";
+            pmList.add(serviceId);
+        }
+        if (Objects.nonNull(dataObjectId)) {
+            sql = sql + " and dataObjectId = ?";
+            pmList.add(dataObjectId);
+        }
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            return processFail("异常数据恢复:获取远程数据库连接失败" + myDbHelper.getErrorMessage());
+        }
+        try {
+
+            Map<String, Object> queryByParamsReturnListMap = myDbHelper.queryByParamsReturnList(sql, pmList.toArray());
+            if (!queryByParamsReturnListMap.get("code").equals("0")) {
+                return processFail("获远程日志错误: " + queryByParamsReturnListMap.get("message"));
+            }
+            List<Map<String, Object>> queryByParamsList = MapTools.getMapList(queryByParamsReturnListMap);
+            if (Objects.isNull(queryByParamsList) || queryByParamsList.isEmpty()) {
+                return processSuccess(null);
+            }
+            serviceId = queryByParamsList.get(0).get("serviceId").toString();
+            DataProcess dataProcessObj = ObjectMap.getordropInput(serviceId);//获取数据输出处理对象
+            if (null == dataProcessObj || !MapTools.isBlank(dataProcessObj.getErrorMessage())) {
+                return processFail("服务不可用:" + (null == dataProcessObj ? "" : dataProcessObj.getErrorMessage()));
+            }
+            List<Object[]> deleteIds = new ArrayList<>();
+            for (Map<String, Object> queryMap : queryByParamsList) {
+                deleteIds.add(new ArrayList<String>() {{
+                    add(queryMap.get("dataObjectId").toString());
+                }}.toArray());
+                Object iNDataContent = queryMap.get("iNDataContent");
+                Object event = queryMap.get("event");
+                if (Objects.nonNull(iNDataContent)) {
+                    ObjectMapper objectMapper = new ObjectMapper();
+                    List<Map<String, Object>> abnormalData = objectMapper.readValue(iNDataContent.toString(), List.class);
+                    dataProcessObj.execCalultion(abnormalData, queryMap.get("calculationLocation").toString(), event, queryMap.get("dataObjectId").toString(), null, null);
+                }
+            }
+            myDbHelper.updateByCondition("delete  from log_error where dataObjectId = ?", deleteIds);
+            return processSuccess(null);
+        } catch (Exception e) {
+            return processFail("异常数据恢复出现错误:" + LogUtils.getException(e));
+        }
+    }
+
+
+    /**
+     * 支持的最大机器id,结果是31 (这个移位算法可以很快计算出几位二进制数所能表示的最大十进制数)
+     */
+    private final String maxWorkerId = "4";
+    /**
+     * 支持的最大数据标识id,结果是31
+     */
+    private final String maxServiceId = "4";
+    /**
+     * 毫秒内序列(0~4095)
+     */
+    private final Long maxSequence = 999L;
+
+    private long sequence = 0L;
+
+    /**
+     * 上次生成ID的时间截
+     */
+    private long lastTimestamp = -1L;
+
+
+    public synchronized String createLifeCycleCol(Long workerId, Integer serviceId) {
+        long timestamp = System.currentTimeMillis();
+        //如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
+        //如果是同一时间生成的,则进行毫秒内序列
+        if (lastTimestamp == timestamp) {
+            sequence++;
+            //毫秒内序列溢出
+            if (sequence > maxSequence) {
+                //阻塞到下一个毫秒,获得新的时间戳
+                sequence = 0;
+                while (lastTimestamp == System.currentTimeMillis()) {
+                }
+                timestamp = System.currentTimeMillis();
+            }
+        }
+        //时间戳改变,毫秒内序列重置
+        else {
+            sequence = 0L;
+        }
+        //上次生成ID的时间截
+        lastTimestamp = timestamp;
+        //移位并通过或运算拼到一起组成64位的ID
+        return timestamp + "" + (String.format("%0" + (maxSequence.toString().length()) + "d", sequence)) + (String.format("%0" + maxWorkerId + "d", workerId)) + (String.format("%0" + maxServiceId + "d", serviceId));
+    }
+}

+ 568 - 0
mainFactory/src/main/java/org/bfkj/application/DataProcess.java

@@ -0,0 +1,568 @@
+package org.bfkj.application;
+
+
+import org.bfkj.config.AppConfig;
+import org.bfkj.config.ObjectMap;
+import org.bfkj.utils.LogUtils;
+import org.bfkj.utils.MapTools;
+import org.bfkj.utils.MyDbHelper;
+import org.bfkj.utils.ScriptEnginePro;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+
+/**
+ * z
+ * 数据收集
+ */
+public class DataProcess {
+
+    private String serviceId;//作为实例化服务对象的Key
+    private long lastActive; //服务最后活跃时间
+    private String errorMessage = null;  //当前数据输入处理对象不可用信息
+    private List<Map<String, Object>> calculationLibraryList;//输出计算库
+    private static final Map<String, Integer> serviceErrorCount = new HashMap<>();   //服务错误次数:针对脚本异常
+
+    private final Map<String, ScriptEnginePro> ScriptEngineProMaps = new HashMap<>();//用于缓存当前服务的算法引擎对象,数据库的无需缓存
+
+    private Map<String, List<String>> columnMaps = new HashMap<>(); //用于缓存对应数据库算法的SQL结构,表名、字段列表、主键
+
+    private static List<String> baseInfo = new ArrayList<>() {{
+        add("serviceId");
+        add("event");
+        add("page");
+        add("pageSize");
+    }};
+
+
+    public DataProcess(String service_Id) {//初始化构造,实例化一个服务对象
+        lastActive = System.currentTimeMillis();//默认最后活跃时间
+        serviceId = service_Id;
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            errorMessage = "获取myDbHelper对象异常: " + myDbHelper.getErrorMessage();
+            return;
+        }
+        //服务信息
+        // todo 修改: result ,检查外层是否是判断过服务是否存在,如果不在存则修改sql否则移除
+        Map<String, Object> serviceInfoResult = myDbHelper.queryByParamsReturnList("select * from serviceinfo where serviceID = ?", service_Id);//直接数据库查询
+        List<Map<String, Object>> mapList = MapTools.getMapList(serviceInfoResult);
+        if (!serviceInfoResult.get("code").equals("0") || Objects.isNull(mapList) || mapList.isEmpty()) {//查询数据库失败
+            errorMessage = !serviceInfoResult.get("code").equals("0") ? ("查询" + serviceId + "服务配置失败:" + serviceInfoResult.get("message")) : ("未配置服务:" + serviceId);
+            return;
+        }
+        //算法信息
+        String calculationListSql = "SELECT CL.*,DI.*  FROM calculation_library CL  left JOIN datasourceinfo DI ON DI.dataSourceID = CL.datasource_id WHERE CL.service_id  =? order by library_sort,library_id";
+        Map<String, Object> calculationResult = myDbHelper.queryByParamsReturnList(calculationListSql, service_Id);//直接数据库查询
+        calculationLibraryList = MapTools.getMapList(calculationResult);
+        if (!calculationResult.get("code").equals("0")) {//查询数据库失败
+            errorMessage = "查询" + service_Id + "的算法失败:" + calculationResult.get("message");
+        }
+    }
+
+    /**
+     * 关闭的连接信息
+     *
+     * @param
+     * @return
+     */
+    public void close() {//销毁当前服务对象时,需要将缓存的算法引擎实例同步销毁
+        for (ScriptEnginePro scriptEnginePro : ScriptEngineProMaps.values()) {
+            scriptEnginePro.close();
+        }
+        ScriptEngineProMaps.clear();
+    }
+
+    //统一成功信息处理
+    public Map<String, Object> processSuccess(Object returnData) {
+        if (returnData instanceof Map) {
+            Map<String, Object> resultData1 = (Map<String, Object>) returnData;
+            resultData1.put("code", "0");
+            return resultData1;
+        }
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "0");
+        returnMap.put("returnData", returnData);
+        return returnMap;
+    }
+
+    //统一错误信息处理
+    public Map<String, Object> processFail(String errorMessage, String libraryId) {
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "-1");
+        returnMap.put("message", errorMessage);
+        if (!MapTools.isBlank(libraryId)) {
+            returnMap.put("library_id", libraryId);
+        }
+        return returnMap;
+    }
+
+    //数据收集----目前应该是数据处理
+    public Map<String, Object> processData(Map<String, Object> inputData, String... user_id) { //{serviceid:1,datacontent:[{key:value},{key:value}],event:0,page:1,pagesize:10}
+        //事件判断由算法进行,不再作为入口必须条件  ?
+        if (!MapTools.isBlank(errorMessage)) {//如果当前服务存在问题,代表数据库对象不可用,此时应该重构当前对象,调用方控制
+            LogUtils.log("processData:1", "-1", null, "服务不可用" + errorMessage, serviceId, AppConfig.WORK_ID, MapTools.jacksonObjToStr(inputData), null, null, null);
+            return processFail("服务不可用" + errorMessage, null);
+        }
+        lastActive = System.currentTimeMillis();//更新最后活跃时间  //------更新当前服务的最后活跃时间,用于服务监控
+        //更新服务的活跃时间
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            LogUtils.log("processData:2", "-1", null, "数据接收错误,获取远程数据库对象: " + myDbHelper.getErrorMessage(), serviceId, AppConfig.WORK_ID, MapTools.jacksonObjToStr(inputData), null, null, null);
+            return processFail("数据接收错误,获取远程数据库对象: " + myDbHelper.getErrorMessage(), null);
+        }
+        //        更新数据库中的服务最新活跃时间
+        myDbHelper.updateByCondition("update serviceinfo set runState = 1 ,lastactive = now() where  serviceID =?", null, serviceId); // 服务表增加最后活跃时间
+        //创建生命周期ID;//默认继承
+        if (!inputData.containsKey("dataObjectId")) {
+//            生成新的生命周期ID
+            inputData.put("dataObjectId", createLifeCycleCol(Long.valueOf(AppConfig.WORK_ID), Integer.parseInt(serviceId)));
+        }
+        String dataObjectId = (String) inputData.get("dataObjectId");
+        Object event = inputData.get("event"); //  服务表新增一个字段:用于标识当前服务支持的事件,用于限制入参的事件
+        //初始化 列权限为空
+        // 如果存在用户编号 且事件为查询
+        //通过用户编号,服务编号,从用户权限表获取行列权限
+        // 如果列权限为空则 直接返回空
+        // 重新组建入口参数:添加filter(行权限)
+        if (event.equals("0") && Objects.nonNull(user_id)) {
+            Map<String, Object> addRowPermissionMap = addRowPermission(inputData, user_id[0]);
+            inputData.put("dataContent", addRowPermissionMap);
+        }
+
+        List<Map<String, Object>> calculationResult = new ArrayList<>();//定义算法全量结果列表
+        calculationResult.add(inputData);//默认接收数据为第0个算法的结果
+        Map<String, List<Map<String, Object>>> execResult = execCalultion(calculationResult, null, event, dataObjectId, inputData.get("page"), inputData.get("pageSize"));
+        calculationResult = execResult.get("calcData");//执行当前服务对应的算法库
+
+        Map<String, Object> lastResult = calculationResult.get(calculationResult.size() - 1);//获取最后一个计算结果
+        if (Objects.equals(lastResult.get("code"), "-1")) {//最后一个计算结果为-1则记录异常,否则全部记录正常
+            String libraryId = lastResult.get("library_id").toString();
+            Object message = lastResult.get("message");
+            LogUtils.log("processData:3", "-1", libraryId, Objects.nonNull(message) ? message.toString() : null, serviceId, AppConfig.WORK_ID, MapTools.jacksonObjToStr(calculationResult), dataObjectId, MapTools.jacksonObjToStr(execResult.get("calcData")), event);
+            setServiceErrorCount(libraryId, serviceId, "-1");//标记错误的算法:连续错误累加
+            return processFail(libraryId + "数据计算错误:" + lastResult.get("message"), libraryId);
+        }
+        //写入 成功日志
+        LogUtils.log("DataProcess:9999", "0", null, "数据接收后处理成功", serviceId, AppConfig.WORK_ID, MapTools.jacksonObjToStr(calculationResult), dataObjectId, MapTools.jacksonObjToStr(execResult.get("calcData")), event);  //此处无法把所有的记过集返回过去
+        // 如果列权限不为空
+        // 循环lastResult
+        // 遍历map
+        // 如果key不在列权限则删除
+        List<Map<String, Object>> collect = calculationResult.stream().filter(map -> Objects.isNull(map.get("library_id")) || !map.get("library_id").toString().contains("_N")).collect(Collectors.toList());
+        return processSuccess(collect.get(collect.size() - 1));
+    }
+
+    /**
+     * 添加行权限
+     *
+     * @param inputData
+     * @param userId
+     * @return
+     */
+    private static Map<String, Object> addRowPermission(Map<String, Object> inputData, String userId) {
+        Object dataContent = inputData.get("dataContent");
+        if (Objects.isNull(dataContent)) {// null
+            dataContent = MapTools.removeKey(inputData, baseInfo);
+        }
+        /*如果dataContent不是数组也不是map则返回inData,--不是map数组 返回InData*/
+        if (!(dataContent instanceof Map<?, ?>) && (dataContent instanceof List<?> && !(((List<?>) dataContent).get(0) instanceof Map))) {
+            return inputData;
+        }
+        if (dataContent instanceof Map<?, ?> temMap) {
+            List<Object> tempList = new ArrayList<>();
+            tempList.add(temMap);
+            dataContent = tempList;
+        }
+        List<Map<String, Object>> tempDataList = (List<Map<String, Object>>) dataContent;
+        if (!((tempDataList).get(0)).containsKey("filter")) { //[{a=1,b=2},{a=2,b=3}] ---->[{"filter":[{a=1,b=2}]},{"filter":[{a=2,b=3}]}]
+            List<Object> tempList = new ArrayList<>();
+            for (Object tempMap : tempDataList) { //[{a=1,b=2},{a=2,b=3}]
+                List<Object> tepList = new ArrayList<>(){{add(tempMap);}};
+                Map<Object, Object> tmpData = new HashMap<>();
+                tmpData.put("filter", tepList);
+                tempList.add(tmpData);
+            }
+            dataContent = tempList;
+        }
+        if (tempDataList.get(0).get("filter") instanceof Map<?, ?> filterMap) {  //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
+            List<Map<String, Object>> returnDataList = new ArrayList<>();
+            for (Map<String, Object> temp : tempDataList) {
+                List<Object> tempList = new ArrayList<>();
+                tempList.add(filterMap);
+                temp.put("filter", tempList);
+                returnDataList.add(temp);
+            }
+            dataContent = returnDataList;  // [{"filter":[{a=1,b=2}}],{"filter":[{a=2,b=3}]}]
+        }
+        List<Map<String, Object>> data = new ArrayList<>();
+        if (dataContent instanceof List<?> temList && temList.get(0) instanceof Map temMap &&  !temMap.containsKey("left")) {
+            authoParams((List<Map<String, Object>>) temList, data); //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
+        }else {
+            data = (List<Map<String, Object>>) dataContent;
+        }
+        inputData.put("dataContent",data);
+        //判断filter不为空 且 filter不包含left---{"filter":[{"user_id":""}]} ---- >[{filter:[{left:,column:},{left:,column:}
+        //更新服务的活跃时间
+//        List<Map<String,Object>> queryByParamsDataList =(List<Map<String,Object>>) queryByParamsReturnList.get("returnData");
+//        if (queryByParamsDataList.isEmpty()) return processFail("获取列权限失败:列权限为空",null);
+////            Map<String, Object> filterMap = queryByParamsDataList.get(0);
+//        Map<String,Object> dataContent =(Map<String,Object>) inputData.get("dataContent");
+//        if (!inputData.toString().contains("filter:")){
+//            //如果queryByParamsDataList是逗号分割则
+//            dataContent.put("filter",);
+//            inputData.put("dataContent",dataContent);
+//        }else {
+//            Object filter = dataContent.get("filter");
+//
+//
+//        }
+        return inputData;
+    }
+
+    private static Map<String, Object> addRowPermission2(Map<String, Object> inputData, String userId) {
+        Object dataContent = inputData.get("dataContent");
+        if (Objects.isNull(dataContent)) {// null
+            dataContent = MapTools.removeKey(inputData, baseInfo);
+        }
+        /*如果dataContent不是数组也不是map则返回inData,--不是map数组 返回InData*/
+        if (!(dataContent instanceof Map<?, ?>) && (dataContent instanceof List<?> && !(((List<?>) dataContent).get(0) instanceof Map))) {
+            return inputData;
+        }
+        if (dataContent instanceof Map<?, ?> temMap) {
+            List<Object> tempList = new ArrayList<>();
+            tempList.add(temMap);
+            dataContent = tempList;
+        }
+        List<?> tempDataList = dataContent instanceof List<?> tempDataContent ? tempDataContent:null;
+        if (Objects.nonNull(tempDataList) &&  tempDataList.get(0) instanceof Map  currentMap &&  !(currentMap.containsKey("filter"))) { //[{a=1,b=2},{a=2,b=3}] ---->[{"filter":[{a=1,b=2}]},{"filter":[{a=2,b=3}]}]
+            List<Object> tempList = new ArrayList<>();
+            for (Object tempMap : tempDataList) { //[{a=1,b=2},{a=2,b=3}]
+                List<Object> tepList = new ArrayList<>(){{add(tempMap);}};
+                Map<Object, Object> tmpData = new HashMap<>();
+                tmpData.put("filter", tepList);
+                tempList.add(tmpData);
+            }
+            dataContent = tempList;
+        }
+        if (Objects.nonNull(tempDataList) &&  tempDataList.get(0) instanceof Map  currentMap && currentMap.get("filter") instanceof Map<?, ?> filterMap) {  //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
+            List<Object> returnDataList = new ArrayList<>();
+            for (Object temp : tempDataList) {
+                if (temp instanceof Map itemMap){
+                    List<Object> tempList = new ArrayList<>();
+                    tempList.add(filterMap);
+                    itemMap.put("filter", tempList);
+                    returnDataList.add(itemMap);
+                }
+
+            }
+            dataContent = returnDataList;  // [{"filter":[{a=1,b=2}}],{"filter":[{a=2,b=3}]}]
+        }
+        List<Map<String, Object>> data = new ArrayList<>();
+        if (dataContent instanceof List<?> temList && temList.get(0) instanceof Map temMap &&  !temMap.containsKey("left")) {
+            authoParams((List<Map<String, Object>>) temList, data); //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
+        }else {
+            data = (List<Map<String, Object>>) dataContent;
+        }
+        inputData.put("dataContent",data);
+        //判断filter不为空 且 filter不包含left---{"filter":[{"user_id":""}]} ---- >[{filter:[{left:,column:},{left:,column:}
+        //更新服务的活跃时间
+//        List<Map<String,Object>> queryByParamsDataList =(List<Map<String,Object>>) queryByParamsReturnList.get("returnData");
+//        if (queryByParamsDataList.isEmpty()) return processFail("获取列权限失败:列权限为空",null);
+////            Map<String, Object> filterMap = queryByParamsDataList.get(0);
+//        Map<String,Object> dataContent =(Map<String,Object>) inputData.get("dataContent");
+//        if (!inputData.toString().contains("filter:")){
+//            //如果queryByParamsDataList是逗号分割则
+//            dataContent.put("filter",);
+//            inputData.put("dataContent",dataContent);
+//        }else {
+//            Object filter = dataContent.get("filter");
+//
+//
+//        }
+        return inputData;
+    }
+
+    public static void main(String[] args) {
+        HashMap<String, Object> objectHashMap = new HashMap<>();
+        objectHashMap.put("serviceId","1");
+        objectHashMap.put("user_id","1");
+//        objectHashMap.put("dataContent",new ArrayList<>(){{
+//            add(new HashMap<>(){{
+//                put("data","xxxx");
+//                put("data2","xxxx");
+//            }});
+//            add(new HashMap<>(){{
+//                put("data3","xxxx");
+//                put("data4","xxxx");
+//            }});
+//        }});
+
+        objectHashMap.put("dataContent",new ArrayList<>(){{
+            add(new HashMap<>(){{
+                put("filter",new ArrayList<>(){{
+                    add(new HashMap<>(){{
+                        put("a",null);
+                    }});
+                }});
+            }});
+
+        }});
+        System.out.println(addRowPermission(objectHashMap, "1"));
+    }
+
+
+
+
+    private  static  void authoParams(List<Map<String, Object>> ListInMap, List<Map<String, Object>> filterMapList) {
+        for (Map<String, Object> itemMap : ListInMap) { //[{"filter":{a=1,b=2}},{"filter":{a=2,b=3}}]
+            List<Map<String,Object>> filter = (List<Map<String,Object>>)itemMap.get("filter");
+            for (Map<String, Object> filterKey : filter) {
+                List<Object> filterValue = new ArrayList<>();
+                for (String filKey : filterKey.keySet()) {
+                    HashMap<String, Object> filterMap = new HashMap<>();
+                    Object keyValues = filterKey.get(filKey);
+                    filterMap.put("left", "");
+                    filterMap.put("column", filKey);
+                    filterMap.put("comparator", " = ");
+                    if (Objects.isNull(keyValues)) {
+                        filterMap.put("comparator", " is null ");
+                    }
+                    filterMap.put("value", keyValues);
+                    filterMap.put("right", "");
+                    filterMap.put("connector", " and ");
+                    filterValue.add(filterMap);
+                }
+                HashMap<String, Object> hashMap = new HashMap<>();
+                hashMap.put("filter",filterValue);
+                filterMapList.add(hashMap) ;
+            }
+        }
+    }
+
+    public Map<String, List<Map<String, Object>>> execCalultion(List<Map<String, Object>> inData, String beginLibraryId, Object event, String dataObjectId, Object page, Object pageSize) {
+        Map<String, List<Map<String, Object>>> returnData = new HashMap<>();
+        List<Map<String, Object>> preData = new ArrayList<>();
+        List<Map<String, Object>> calcData = Objects.isNull(inData) || inData.isEmpty() ? new ArrayList<>() : inData;
+        for (Map<String, Object> calculationLibrary : calculationLibraryList) {//循环算法库
+
+            String library_id = calculationLibrary.get("library_id").toString();//算法编号
+            if (MapTools.isNotBlank(beginLibraryId) && !beginLibraryId.equals(library_id)) {
+                continue;//如果异常恢复开始算法编号不为空且不等于当前循环的算法编号则跳过
+            }
+            beginLibraryId = null;//为避免异常恢复开始后的后续算法编号不等于当前循环的算法编号的跳过
+            String library_type = calculationLibrary.get("library_type").toString();
+            String service_id = calculationLibrary.get("service_id").toString();
+            String computing_expression = MapTools.objectToString(calculationLibrary.get("computing_expression"));
+            Object is_exec = calculationLibrary.get("is_exec");
+            Map<String, Object> currentResult;
+            if (Objects.nonNull(is_exec)) {
+                Map<String, Object> preCalMap = new HashMap<>();
+                preCalMap.put("library_id", library_id + "_N");
+                preCalMap.put("service_id", service_id);
+                preCalMap.put("library_type", 2);
+                preCalMap.put("computing_expression", is_exec); //
+                Map<String, Object> preEnginResult = execEngine(preCalMap, calcData, dataObjectId);   //todo 前置算法的结果添加到里面 ,在数据恢复时,是否会恢复成功呢
+                preEnginResult.put("library_id", library_id + "_N");// 补充算法编号,方便上层处理异常
+//                inData.add(preEnginResult);
+                preData.add(preEnginResult);
+                returnData.put("preData", preData);
+                //如果code为-1 则表示脚本计算错误 退出计算;如果code为2 则后续算法都不执行
+                if ("-1".equals(preEnginResult.get("code")) || Objects.equals("2", preEnginResult.get("returnData"))) { //执行错误
+                    return returnData;
+                }
+                setServiceErrorCount(library_id + "_N", serviceId, "0");
+                if (Objects.equals("1", preEnginResult.get("returnData"))) { //前置检查不通过,当前算法不执行,后续 还需执行
+                    continue;
+                }
+            }
+            if (library_type.equals("3")) {//数据库算法
+                String connectConfig = calculationLibrary.get("connectConfig").toString();//数据库链接字符串
+                MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(connectConfig);//获取对应连接的数据库处理对象
+                if (Objects.nonNull(myDbHelper.getErrorMessage())) {//获取出错
+                    calcData.add(processFail("算法获取数据库连接异常:" + myDbHelper.getErrorMessage(), library_id));
+                    returnData.put("calcData", calcData);
+                    return returnData;
+                }
+                Object sourceObjectName = calculationLibrary.get("sourceObjectName");//目标对象名(表名)
+                Object isActiveTable = calculationLibrary.get("isActiveTable");//是否动态表
+                Object eventStr = calculationLibrary.get("event");//指定当前算法事件
+                String eventFlag;
+                if (Objects.isNull(eventStr)) {//算法未指定事件:表名方式依赖入口否则通过SQL语句进行判断     ------------------sql语句如果换行了呢
+                    eventFlag = Objects.nonNull(sourceObjectName) ? event.toString() : AppConfig.staticEvent.get(Objects.requireNonNull(computing_expression).trim().toLowerCase().substring(0, 6));
+                } else {//算法指定事件
+                    eventFlag = eventStr.toString();
+                }
+                if (null == eventFlag) {
+//                    inData.add();
+                    calcData.add(processFail("事件标志为空", library_id));
+                    returnData.put("calcData", calcData);
+                    return returnData;
+                }
+                //算法取参
+                List<Map<String, Object>> dbPrams = new ArrayList<>();
+                Object tempDBPrams = null;
+                try {//添加try捕获异常
+                    if (Objects.isNull(calculationLibrary.get("parmIndex"))) {//未配置取参则默认取上一个算法
+                        Map<String, Object> tempMap = inData.get(inData.size() - 1);
+                        tempDBPrams = tempMap.containsKey("dataContent") ? tempMap.get("dataContent") : tempMap.get("returnData");
+                    } else {//算法取值位置表达式不为空
+                        tempDBPrams = inData;//默认等于全量参数
+                        String[] parmSplit = calculationLibrary.get("parmIndex").toString().split("\\.");//按.进行分割
+                        for (String item : parmSplit) {//循环提取参数
+                            if (MapTools.isNumber(item)) {//数字代表数组中的位置
+                                tempDBPrams = ((List) tempDBPrams).get(Integer.parseInt(item));
+                            } else {
+                                tempDBPrams = ((Map) tempDBPrams).get(item);
+                            }
+                        }
+                    }
+                    if (tempDBPrams instanceof Map) {//最终参数是Map则转换为List<Map<String, Object>>
+                        dbPrams.add((Map) tempDBPrams);
+                    } else if (tempDBPrams instanceof List) {
+                        dbPrams = (List<Map<String, Object>>) tempDBPrams;
+                    }
+                } catch (Exception e) {
+                    calcData.add(processFail("入参数据格式错误:不是List<Map<String,Object> " + tempDBPrams, library_id));
+                    returnData.put("calcData", calcData);
+                    return returnData;
+                }
+                // 事件6 在算法表中的event定义,实现自动的新增或更新
+                if (eventFlag.equals("6")) {
+                    currentResult = myDbHelper.insertOrUpdate(Objects.nonNull(sourceObjectName) ? sourceObjectName.toString() : "", dbPrams);
+                } else {
+                    currentResult = myDbHelper.generalProcess(eventFlag, Objects.nonNull(sourceObjectName) ? sourceObjectName.toString() : "", computing_expression, null, dbPrams, Objects.nonNull(isActiveTable) && Objects.equals(isActiveTable, "true"), page, pageSize);
+                }
+
+            } else {
+                currentResult = execEngine(calculationLibrary, inData, dataObjectId);
+            }
+            if (!currentResult.get("code").equals("0")) {//算法执行异常
+                currentResult.put("library_id", library_id);
+            }
+            calcData.add(currentResult);
+            returnData.put("calcData", calcData);
+            setServiceErrorCount(library_id, serviceId, "0");    ///  错误次数恢复??
+        }
+        return returnData;
+    }
+
+    /**
+     * 算法连续错误次数判定
+     *
+     * @param location
+     * @param serviceId
+     * @param success
+     */
+    public static void setServiceErrorCount(String location, String serviceId, String success) {
+        String key = String.format("processData %s_%s", location, serviceId);
+        if (!success.equals("0")) {
+            Integer errCount = DataProcess.serviceErrorCount.get(key);
+            errCount = (null == errCount) ? 1 : errCount + 1;
+            DataProcess.serviceErrorCount.put(key, errCount);
+            if (errCount > AppConfig.SERVICE_ERR_MAX) {
+                ServiceInputControl.stop(serviceId);
+            }
+        } else {
+            DataProcess.serviceErrorCount.put(key, 0);
+        }
+    }
+
+    private Map<String, Object> execEngine(Map<String, Object> currentCalMap, List<Map<String, Object>> allData, String dataObjectId) {
+        String library_id = currentCalMap.get("library_id").toString();//获取算法编号
+        if (!ScriptEngineProMaps.containsKey(library_id)) {//不存在缓存则创建
+            ScriptEngineProMaps.put(library_id, new ScriptEnginePro(currentCalMap));
+        }
+        ScriptEnginePro currentEngin = ScriptEngineProMaps.get(library_id);//依据算法编号获取算法引擎
+        if (Objects.nonNull(currentEngin) && Objects.nonNull(currentEngin.getErrorMessage())) {//获取错误引擎
+            currentEngin.close();
+            currentEngin = null;
+            ScriptEngineProMaps.remove(library_id);
+        }
+        if (Objects.isNull(currentEngin) || Objects.nonNull(currentEngin.getErrorMessage())) {
+            return processFail("创建引擎失败" + (Objects.nonNull(currentEngin) ? currentEngin.getErrorMessage() : ""), library_id);
+        }
+        return currentEngin.execScript(allData);
+    }
+
+    /**
+     * 支持的最大机器id,结果是31 (这个移位算法可以很快计算出几位二进制数所能表示的最大十进制数)
+     */
+    private final static String maxWorkerId = "4";
+    /**
+     * 支持的最大数据标识id,结果是31
+     */
+    private final static String maxServiceId = "4";
+    /**
+     * 毫秒内序列(0~4095)
+     */
+    private static final Long maxSequence = 999L;
+
+    private static long sequence = 0L;
+
+    /**
+     * 上次生成ID的时间截
+     */
+    private static long lastTimestamp = -1L;
+
+    /**
+     * 生命周期ID生成
+     *
+     * @param workerId
+     * @param serviceId
+     * @return
+     */
+    public static synchronized String createLifeCycleCol(Long workerId, Integer serviceId) {
+        long timestamp = System.currentTimeMillis();
+        //如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
+        //如果是同一时间生成的,则进行毫秒内序列
+        if (lastTimestamp == timestamp) {
+            sequence++;
+            //毫秒内序列溢出
+            if (sequence > maxSequence) {
+                //阻塞到下一个毫秒,获得新的时间戳
+                sequence = 0;
+                while (lastTimestamp == System.currentTimeMillis()) {
+                }
+                timestamp = System.currentTimeMillis();
+            }
+        }
+        //时间戳改变,毫秒内序列重置
+        else {
+            sequence = 0L;
+        }
+        //上次生成ID的时间截
+        lastTimestamp = timestamp;
+        //移位并通过或运算拼到一起组成64位的ID
+        return timestamp + "" + (String.format("%0" + (maxSequence.toString().length()) + "d", sequence)) + (String.format("%0" + maxWorkerId + "d", workerId)) + (String.format("%0" + maxServiceId + "d", serviceId));
+    }
+
+    public String getServiceId() {
+        return serviceId;
+    }
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public static long getLastTimestamp() {
+        return lastTimestamp;
+    }
+
+    public long getLastActive() {
+        return lastActive;
+    }
+
+    public List<String> getColumnMaps(String sql) {
+        return columnMaps.get(sql);
+    }
+
+    public void setColumnMaps(String sql, List<String> columnList) {
+        columnMaps.put(sql, columnList);
+    }
+
+    public void clearColumnList(String sql) {
+        columnMaps.remove(sql);
+    }
+}

+ 126 - 0
mainFactory/src/main/java/org/bfkj/application/ServiceInputControl.java

@@ -0,0 +1,126 @@
+package org.bfkj.application;
+
+import org.bfkj.config.AppConfig;
+import org.bfkj.config.ObjectMap;
+import org.bfkj.utils.*;
+
+import java.util.*;
+
+/**
+ * 服务输入控制类
+ */
+public class ServiceInputControl {
+    public static Map<String, ScheduleTask> ScheduleTaskMaps = new HashMap<>();
+
+    public static  Map<String, Object> processSuccess(Object returnData) {
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "0");
+        returnMap.put("returnData", returnData);
+        return returnMap;
+    }
+
+    //统一错误信息处理
+    public static Map<String, Object> processFail(String errorMessage) {
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "-1");
+        returnMap.put("message", errorMessage);
+        return returnMap;
+    }
+
+
+    /**
+     * 服务启动
+     *
+     * @param service_id
+     * @return
+     */
+    public static Map<String,Object> start(String service_id) {
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            return processFail("获取采集服务执行SQL异常");
+        }
+        //采集数据源及参数配置
+        Map<String,Object> collectServiceMap = myDbHelper.queryByParamsReturnList("SELECT SI.* FROM  serviceinfo SI WHERE SI.serviceType ='4'  AND serviceID = ?", service_id);
+        List<Map<String, Object>> collectServiceList = MapTools.getMapList(collectServiceMap);
+        if (!collectServiceMap.get("code").equals("0")) {
+            return processFail("获取采集服务执行SQL异常" + collectServiceMap.get("message"));
+        }
+        if (Objects.isNull(collectServiceList) || collectServiceList.isEmpty()) {
+            return processFail("采集服务不存在");
+        }
+        Map<String, Object> collectServiceMaps = collectServiceList.get(0); //采集服务
+        Integer loopCount = (null == collectServiceMaps.getOrDefault("loopCount", null)) ? null : Integer.parseInt(collectServiceMaps.get("loopCount").toString());
+        int frequencyCount = (null == collectServiceMaps.getOrDefault("frequencyCount", null)) ? 1 : Integer.parseInt(collectServiceMaps.get("frequencyCount").toString());
+        int frequencyUnit = (null == collectServiceMaps.getOrDefault("frequencyUnit", null)) ? 1 : Integer.parseInt(collectServiceMaps.get("frequencyUnit").toString());
+        int taskType = (null == collectServiceMaps.getOrDefault("taskType", null)) ? 1 : Integer.parseInt(collectServiceMaps.get("taskType").toString());
+        Object cronExpress = collectServiceMaps.get("cronExpress");
+        Date taskValidDate = MapTools.strObjToDate(collectServiceMaps.get("taskValid"));
+        Date taskInvalidDate = MapTools.strObjToDate(collectServiceMaps.get("taskInvalid"));
+        //创建定时任务:
+        ScheduleTask scheduleTask = ScheduleTaskMaps.get(service_id);
+        if (Objects.isNull(scheduleTask)) {
+            scheduleTask = new ScheduleTask(service_id, loopCount, taskValidDate, taskInvalidDate);
+            ScheduleTaskMaps.put(service_id, scheduleTask);
+        }
+        // todo 记录日志
+        boolean start = ScheduleUtil.start(scheduleTask, (frequencyCount * frequencyUnit), cronExpress, taskType);
+        LogUtils.log("start: 2", "0", null, (start ? "启动成功" : "启动失败"), service_id, AppConfig.WORK_ID, null, null, null,null);//无条件记录数据接收日志
+        if (start) {
+            return processSuccess("启动成功");
+        }
+        myDbHelper.updateByCondition("update serviceinfo set runState = 1 where  serviceID =?",null,service_id);
+        ScheduleTaskMaps.remove(service_id);
+        return processFail("启动失败");
+    }
+
+    /**
+     * 服务停止
+     *
+     * @param service_id
+     * @return
+     */
+    public static Map<String,Object> stop(String service_id) {
+        ScheduleTask scheduleTask = ScheduleTaskMaps.get(service_id);
+        if (Objects.isNull(scheduleTask)) {
+            return processFail("服务: " + service_id + " 已经停止");
+        }
+        boolean reset = ScheduleUtil.cancel(scheduleTask);
+        ScheduleTaskMaps.remove(service_id);
+        // 修改服务的状态
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            return processFail("服务:" + service_id +" 停止 获取数据库对象失败,异常信息 " + myDbHelper.getErrorMessage());
+        }
+        myDbHelper.updateByCondition("update serviceinfo set runState = 0 where  serviceID =?",null,service_id);
+        LogUtils.log("stop: 2", "0", null, (reset ? "停止成功" : "停止失败"), service_id, AppConfig.WORK_ID, null, null, null,null);//无条件记录数据接收日志
+        return processSuccess("停止" + (reset ? "成功" : "失败"));
+    }
+
+    public static Map<String,Object> startOrStop(Map<String, Object> params, String statue) {
+        String serviceId = Objects.isNull(params.get("serviceId")) ? null : params.get("serviceId").toString();
+        if (MapTools.isBlank(serviceId)) {
+            return processFail("服务" + (statue.equals("1") ? "启动" : "停止") + (MapTools.isBlank(serviceId) ? "失败:serviceId为空" : "成功"));
+        }
+
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            return processFail("startOrStop 获取数据库连接对象失败");
+
+        }
+        Map<String,Object> serviceTypeResult = myDbHelper.queryByParamsReturnList("select serviceType from serviceinfo where serviceID=?", serviceId);
+
+        List<Map<String, Object>> serviceTypeData = MapTools.getMapList(serviceTypeResult);
+        if (!serviceTypeResult.get("code").equals("0")) {
+            return processFail("startOrStop 获取服务类型:执行sql异常" + serviceTypeResult.get("message"));
+        }
+        if (Objects.nonNull(serviceTypeData) && Objects.equals("4",serviceTypeData.get(0).get("serviceType").toString())) {
+            if (statue.equals("0")) {
+                return ServiceInputControl.stop(serviceId);
+            }
+            return ServiceInputControl.start(serviceId);
+        }
+        ObjectMap.getordropMyDbHelper(serviceId, false);
+        ObjectMap.getordropInput(serviceId,false);
+        return processSuccess("重启成功");
+    }
+}

+ 37 - 0
mainFactory/src/main/java/org/bfkj/config/AppConfig.java

@@ -0,0 +1,37 @@
+package org.bfkj.config;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class AppConfig {
+    private final static Map<String, String> system_parameter = new HashMap<>(); // 全局公共变量
+    public static final String REMOTE_DB_CONNECT = "remote_db_connect";
+    public static final String LOCAL_DB_CONNECT = "local_db_connect";
+    public static final String LOCAL_LOG_CONNECT = "local_log_connect";
+    public static String WORK_ID;
+    public static Integer SERVICE_ERR_MAX = 3; //服务最大连续异常次数
+    public static HashMap<String, String> staticEvent = new HashMap<String, String>() {{
+        put("select", "0");
+        put("update", "2");
+        put("insert", "3");
+        put("delete", "3");
+    }};
+    /***
+     * 设置系统参数
+     * @param maps 本机workId
+     */
+    public static void setSystemParameters(Map<String, String> maps) {
+        WORK_ID = maps.get("work_id");
+        system_parameter.putAll(maps);
+    }
+    /**
+     * 获取系统参数
+     *
+     * @param key
+     */
+    public static String getSystemParams(String key) {
+        return system_parameter.get(key);
+    }
+}

+ 18 - 0
mainFactory/src/main/java/org/bfkj/config/CorsConfig.java

@@ -0,0 +1,18 @@
+package org.bfkj.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration // 一定不要忽略此注解
+public class CorsConfig implements WebMvcConfigurer {
+    @Override
+    public void addCorsMappings(CorsRegistry registry) {
+        registry.addMapping("/**") // 所有接口
+                .allowCredentials(true) // 是否发送 Cookie
+                .allowedOriginPatterns("*") // 支持域
+                .allowedMethods(new String[]{"GET", "POST", "PUT", "DELETE"}) // 支持方法
+                .allowedHeaders("*")
+                .exposedHeaders("*");
+    }
+}

+ 81 - 0
mainFactory/src/main/java/org/bfkj/config/ObjectMap.java

@@ -0,0 +1,81 @@
+package org.bfkj.config;
+
+
+import org.bfkj.application.DataProcess;
+import org.bfkj.utils.MyDbHelper;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * 全局变量类
+ */
+public class ObjectMap {
+
+    public static Map<String, DataProcess> dataProcessMaps = new HashMap<>(); //数据接收
+    public static Map<String, MyDbHelper> myDbHelperMaps = new HashMap<>(); //数据采集map
+
+    /*针对获取对象*/
+    // todo 修改方法名: getordropInput
+    public synchronized static DataProcess getordropInput(String serviceId, boolean isGet) {
+        if (isGet) {
+            DataProcess dataProcess = dataProcessMaps.get(serviceId);
+            if (Objects.nonNull(dataProcess) && Objects.nonNull(dataProcess.getErrorMessage())) {
+                dataProcess.close();
+                dataProcess = null;
+                dataProcessMaps.remove(serviceId);
+            }
+            if (!dataProcessMaps.containsKey(serviceId)) {
+                dataProcessMaps.put(serviceId, new DataProcess(serviceId));
+            }
+            return dataProcessMaps.get(serviceId);
+        } else {
+            DataProcess datacollect = dataProcessMaps.get(serviceId);
+            if (Objects.nonNull(datacollect)) {
+                datacollect.close();
+                datacollect = null;
+            }
+            dataProcessMaps.remove(serviceId);
+            return null;
+        }
+    }
+
+    public synchronized static DataProcess getordropInput(String serviceId) {
+        return getordropInput(serviceId, true);
+    }
+
+    /**
+     * @param connectStr 连接字符串
+     * @return
+     */
+    public synchronized static MyDbHelper getordropMyDbHelper(String connectStr) {
+        return getordropMyDbHelper(connectStr, true);
+    }
+
+    /*获取数据库对象*/
+    //todo  同步修正
+    public synchronized static MyDbHelper getordropMyDbHelper(String connectStr, boolean isGet) {
+        connectStr = connectStr.replaceAll("\\s*|\r|\n|\t", "");
+        if (isGet) {
+            MyDbHelper myDbHelper = myDbHelperMaps.get(connectStr);
+            if (Objects.nonNull(myDbHelper) && Objects.nonNull(myDbHelper.getErrorMessage())) {
+                myDbHelper.close();
+                myDbHelper = null;
+                myDbHelperMaps.remove(connectStr);
+            }
+            if (!myDbHelperMaps.containsKey(connectStr)) {
+                myDbHelperMaps.put(connectStr, new MyDbHelper(connectStr));
+            }
+            return myDbHelperMaps.get(connectStr);
+        } else {
+            MyDbHelper myDbHelper = myDbHelperMaps.get(connectStr);
+            if (Objects.nonNull(myDbHelper)) {
+                myDbHelper.close();
+                myDbHelper = null;
+            }
+            myDbHelperMaps.remove(connectStr);
+            return null;
+        }
+    }
+}

+ 22 - 0
mainFactory/src/main/java/org/bfkj/config/SpringContextBeans.java

@@ -0,0 +1,22 @@
+package org.bfkj.config;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SpringContextBeans implements ApplicationContextAware {
+
+    private static ApplicationContext applicationContext;
+
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        SpringContextBeans.applicationContext = applicationContext;
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> T getBean(String beanName) throws BeansException {
+        return (T) applicationContext.getBean(beanName);
+    }
+}

+ 51 - 0
mainFactory/src/main/java/org/bfkj/config/ThreadPoolConfig.java

@@ -0,0 +1,51 @@
+package org.bfkj.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.ThreadPoolExecutor;
+
+@EnableAsync
+@Configuration
+public class ThreadPoolConfig {
+    @Value("${service.pool.maxPoolSize}")
+    private Integer maxPoolSize;
+    @Value("${service.pool.corePoolSize}")
+    private Integer corePoolSize;
+    @Value("${service.pool.queueCapacity}")
+    private Integer queueCapacity; // #排队容量
+    @Value("${service.pool.keepAliveSeconds}")
+    private Integer keepAliveSeconds;
+    @Value("${service.pool.threadNamePrefix}")
+    private String threadNamePrefix;
+    @Value("${service.pool.waitForTasksToCompleteOnShutdown}")
+    private Boolean waitForTasksToCompleteOnShutdown;
+
+    @Bean("ThreadPoolTaskExecutor")
+    public ThreadPoolTaskExecutor asyncServiceExecutor() {
+        ThreadPoolTaskExecutor outExecutor = new ThreadPoolTaskExecutor();
+        // 设置核心线程数等于系统核数--8核
+        int availableProcessors = Runtime.getRuntime().availableProcessors();
+        outExecutor.setCorePoolSize(availableProcessors);
+        // 设置最大线程数
+        outExecutor.setMaxPoolSize(maxPoolSize);
+        outExecutor.setCorePoolSize(corePoolSize);
+        //配置队列大小
+        outExecutor.setQueueCapacity(queueCapacity);
+        // 设置线程活跃时间(秒)
+        outExecutor.setKeepAliveSeconds(keepAliveSeconds);
+        // 线程满了之后由调用者所在的线程来执行
+        // 拒绝策略:CALLER_RUNS:不在新线程中执行任务,而是由调用者所在的线程来执行
+        outExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        // 设置默认线程名称
+        outExecutor.setThreadNamePrefix(threadNamePrefix);
+        // 等待所有任务结束后再关闭线程池
+        outExecutor.setWaitForTasksToCompleteOnShutdown(waitForTasksToCompleteOnShutdown);
+        //执行初始化
+        outExecutor.initialize();
+        return outExecutor;
+    }
+}

+ 165 - 0
mainFactory/src/main/java/org/bfkj/protocol/EsAlgorithm.java

@@ -0,0 +1,165 @@
+package org.bfkj.protocol;
+
+import org.apache.http.HttpHost;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.bfkj.utils.MapTools;
+import org.elasticsearch.action.ShardOperationFailedException;
+import org.elasticsearch.action.index.IndexRequest;
+import org.elasticsearch.action.index.IndexResponse;
+import org.elasticsearch.action.support.replication.ReplicationResponse;
+import org.elasticsearch.client.RequestOptions;
+import org.elasticsearch.client.RestClient;
+import org.elasticsearch.client.RestClientBuilder;
+import org.elasticsearch.client.RestHighLevelClient;
+import org.elasticsearch.common.xcontent.XContentType;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * Es 算法
+ */
+public class EsAlgorithm {
+    private final HashMap<String, RestHighLevelClient> restHighLevelClientHashMap = new HashMap<>();
+
+    /***
+     * 创建ES客户端
+     * @param connectConfig 连接配置信息
+     * @return ES客户端
+     */
+    private Map<String, Object> getRestHighLevelClient(String connectConfig) {
+        RestHighLevelClient restHighLevelClient = restHighLevelClientHashMap.get(connectConfig);
+        if (null == restHighLevelClient) {
+            Map<String, Object> connectConfigMaps = MapTools.mapStrToMap_connect(connectConfig);
+            if (Objects.isNull(connectConfigMaps.get("scheme"))) {
+                return MapTools.processFail("请求类型为空,此值应该为http或则https");
+            }
+            if (Objects.isNull(connectConfigMaps.get("hostname"))) {
+                return MapTools.processFail("请求IP为空");
+            }
+            if (Objects.isNull(connectConfigMaps.get("port"))) {
+                return MapTools.processFail("请求端口为空");
+            }
+            String scheme = connectConfigMaps.get("scheme").toString();;
+            String hostname = connectConfigMaps.get("hostname").toString();
+            int port = Integer.parseInt(connectConfigMaps.get("hostname").toString());
+            Object account = connectConfigMaps.get("auth");
+            if (null != account && Objects.equals("true", account)) {
+                if (Objects.isNull(connectConfigMaps.get("username"))) {
+                    return MapTools.processFail("有权限验证用户名为空");
+                }
+                if (Objects.nonNull(connectConfigMaps.get("password"))) {
+                    return MapTools.processFail("有权限验证用户密码为空");
+                }
+                String username = connectConfigMaps.get("username").toString();
+                String password = connectConfigMaps.get("password").toString();
+                //有权限验证
+                final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+                credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
+                RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(hostname, port, scheme)).setHttpClientConfigCallback((httpAsyncClientBuilder) -> httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
+                restHighLevelClient = new RestHighLevelClient(restClientBuilder);
+            } else {
+                //无权限验证
+                restHighLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost(hostname, port, scheme)));
+            }
+            restHighLevelClientHashMap.put(connectConfig, restHighLevelClient);
+        }
+        return MapTools.processSuccess(null);
+    }
+
+    public Map<String, Object> sendMethod(String indexName, String connectConfig, Integer serviceId, String data) {
+        RestHighLevelClient restHighLevelClient = null;
+        try {
+            Map<String, Object> restHighLevelClientMap = getRestHighLevelClient(connectConfig);
+            if (restHighLevelClientMap.get("code").equals("-1")) return restHighLevelClientMap;
+            restHighLevelClient = restHighLevelClientHashMap.get(connectConfig);
+            IndexRequest request = new IndexRequest(indexName);
+            request.id(createLifeCycleCol(1L, serviceId));
+            request.timeout("1s");
+            request.source(data, XContentType.JSON);
+            IndexResponse indexResponse = restHighLevelClient.index(request, RequestOptions.DEFAULT);
+            ReplicationResponse.ShardInfo shardInfo = indexResponse.getShardInfo();
+            if (shardInfo.getFailed() > 0) {
+                return MapTools.processSuccess(Arrays.stream(shardInfo.getFailures()).map(ShardOperationFailedException::reason).collect(Collectors.joining(";\n")));
+            } else {
+                return MapTools.processFail("数据发送到ES异常");
+            }
+        } catch (IOException e) {
+            try {
+                Thread.sleep(1000 * 6);
+            } catch (InterruptedException ex) {
+                System.out.println("发送到ES出现异常,暂停6分钟时异常");
+            }
+            return MapTools.processFail(e.getMessage());
+        } finally {
+            try {
+                restHighLevelClientHashMap.remove(connectConfig);
+                if (null != restHighLevelClient) {
+                    restHighLevelClient.close();
+                }
+            } catch (IOException ex) {
+                System.out.println("发送到ES出现异常,暂停6分钟时异常");
+            }
+        }
+    }
+
+
+    /**
+     * 支持的最大机器id,结果是31 (这个移位算法可以很快计算出几位二进制数所能表示的最大十进制数)
+     */
+    private final static String maxWorkerId = "4";
+    /**
+     * 支持的最大数据标识id,结果是31
+     */
+    private final static String maxServiceId = "4";
+    /**
+     * 毫秒内序列(0~4095)
+     */
+    private static final Long maxSequence = 999L;
+
+    private static long sequence = 0L;
+
+    /**
+     * 上次生成ID的时间截
+     */
+    private static long lastTimestamp = -1L;
+
+    /**
+     * 生命周期ID生成
+     *
+     * @param workerId
+     * @param serviceId
+     * @return
+     */
+    public static synchronized String createLifeCycleCol(Long workerId, Integer serviceId) {
+        long timestamp = System.currentTimeMillis();
+        //如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
+        //如果是同一时间生成的,则进行毫秒内序列
+        if (lastTimestamp == timestamp) {
+            sequence++;
+            //毫秒内序列溢出
+            if (sequence > maxSequence) {
+                //阻塞到下一个毫秒,获得新的时间戳
+                sequence = 0;
+                while (lastTimestamp == System.currentTimeMillis()) {
+                }
+                timestamp = System.currentTimeMillis();
+            }
+        }
+        //时间戳改变,毫秒内序列重置
+        else {
+            sequence = 0L;
+        }
+        //上次生成ID的时间截
+        lastTimestamp = timestamp;
+        //移位并通过或运算拼到一起组成64位的ID
+        return timestamp + "" + (String.format("%0" + (maxSequence.toString().length()) + "d", sequence)) + (String.format("%0" + maxWorkerId + "d", workerId)) + (String.format("%0" + maxServiceId + "d", serviceId));
+    }
+}

+ 141 - 0
mainFactory/src/main/java/org/bfkj/protocol/MyIbmMQ6.java

@@ -0,0 +1,141 @@
+//package org.bfkj.protocol;
+//
+//import com.ibm.mq6.*;
+//import org.bfkj.utils.LogUtils;
+//import org.bfkj.utils.MapTools;
+//
+//import java.io.IOException;
+//import java.util.ArrayList;
+//import java.util.HashMap;
+//import java.util.Map;
+//import java.util.Objects;
+//
+//public class MyIbmMQ6 {
+//    private MQQueueManager mqQueueManager;
+//    /**
+//     * 采集kafka数据
+//     *
+//     * @param data 连接参数信息
+//     * @return 读取内容信息
+//     */
+//    public Map<String,Object> readMethod(String sourceObjectName,String connectConfig,Map<String, Object> data) {
+//        if (Objects.isNull(sourceObjectName) || Objects.isNull(connectConfig) || Objects.isNull(getMyConnect(connectConfig))) {
+//            HashMap<String, Object> errMap = new HashMap<>();
+//            errMap.put("code","-1");
+//            errMap.put("message","用户令牌验证失败:" + (Objects.isNull(sourceObjectName) ? "队列为空:发送数据为 " : "连接为空:发送数据为:") + data);
+//            return errMap;
+//        }
+//        Map<String, Object> connectConfigMaps = getMyConnect(connectConfig);
+//        Map<String, Object> returnDataMaps = new HashMap<>();
+//        try {
+//            mqQueueManager = getMqQueueManager(connectConfigMaps);
+//            MQQueue queue = mqQueueManager.accessQueue(connectConfigMaps.get("receiveQueueName").toString(), MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE);
+//            MQGetMessageOptions gmo = new MQGetMessageOptions();
+//            gmo.waitInterval = Objects.isNull(connectConfigMaps.get("receiveTimeout")) ? 300 : Integer.parseInt(connectConfigMaps.get("receiveTimeout").toString());
+//            int depth = queue.getCurrentDepth();
+//            if (depth > 0) {
+//                MQMessage message = new MQMessage();
+//                queue.get(message, gmo);
+//                if (message.getDataLength() > 0) {
+//                    returnDataMaps.put("dataContent", message.readStringOfByteLength(message.getDataLength()));
+//                }
+//            }
+//        } catch (MQException | IOException e) {
+//            HashMap<String, Object> errMap = new HashMap<>();
+//            errMap.put("code","-1");
+//            errMap.put("message",LogUtils.getException(e));
+//            return errMap;
+//
+//        }
+//
+//        HashMap<String, Object> successMap = new HashMap<>();
+//        successMap.put("code","0");
+//        successMap.put("returnData",new ArrayList<Map<String, Object>>() {{
+//            add(returnDataMaps);
+//        }});
+//        return successMap;
+//    }
+//
+//    /**
+//     * 数据发送到kafka
+//     *
+//     * @param sendData 发送数据,及连接信息
+//     * @return 发送结果信息
+//     */
+//    public Map<String,Object> sendMethod(String sourceObjectName,String connectConfig, Map<String, Object> sendData) {
+//        if (Objects.isNull(sourceObjectName) || Objects.isNull(connectConfig) || Objects.isNull(getMyConnect(connectConfig))) {
+//            HashMap<String, Object> errMap = new HashMap<>();
+//            errMap.put("code","-1");
+//            errMap.put("message",(Objects.isNull(sourceObjectName) ? "队列为空 " : "连接为空:发送数据为:") + sendData);
+//            return errMap;
+//        }
+//        Object data = sendData.get("dataContent");
+//        if (Objects.isNull(data)) {
+//            HashMap<String, Object> errMap = new HashMap<>();
+//            errMap.put("code","-1");
+//            errMap.put("message","数据内容为空 " + sendData);
+//            return errMap;
+//        }
+//        Map<String, Object> connectConfigMaps = getMyConnect(connectConfig);
+//        try {
+//            mqQueueManager = getMqQueueManager(connectConfigMaps);
+//            MQQueue queue = mqQueueManager.accessQueue(sourceObjectName.toString(), MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE | MQC.MQOO_FAIL_IF_QUIESCING);
+//            MQMessage mqMessage = new MQMessage();
+//            if (connectConfigMaps.containsKey("characterSet")) {
+//                mqMessage.characterSet = Integer.parseInt(connectConfigMaps.get("characterSet").toString());
+//            }
+//            mqMessage.write(data.toString().getBytes());
+//            MQPutMessageOptions pmo = new MQPutMessageOptions();
+//            queue.put(mqMessage, pmo); //发送消息
+//
+//            HashMap<String, Object> successMap = new HashMap<>();
+//            successMap.put("code","0");
+//            successMap.put("returnData",null);
+//            return successMap;
+//        } catch (MQException | IOException e) {
+//            HashMap<String, Object> errMap = new HashMap<>();
+//            errMap.put("code","-1");
+//            errMap.put("message",LogUtils.getException(e));
+//            return errMap;
+//        }
+//    }
+//
+//    private MQQueueManager getMqQueueManager(Map<String, Object> config) throws MQException {
+//        if (Objects.isNull(mqQueueManager)) {
+//            MQEnvironment.hostname = config.get("hostname").toString();
+//            MQEnvironment.channel = config.get("channel").toString();
+//            MQEnvironment.port = Integer.parseInt(config.get("port").toString());
+//            MQEnvironment.CCSID = Integer.parseInt(config.get("ccsid").toString());
+//            if (config.containsKey("username") && config.containsKey("password") && Objects.nonNull(config.get("username")) && Objects.nonNull(config.get("password"))) {
+//                MQEnvironment.password = config.get("password").toString();
+//                MQEnvironment.userID = config.get("username").toString();
+//            }
+//            mqQueueManager = new MQQueueManager(config.get("queueManager").toString());
+//        }
+//        return mqQueueManager;
+//    }
+//
+//    public Map<String, Object> getMyConnect(Object connectConfig) {
+//        if (connectConfig instanceof Map) {
+//            return (Map<String, Object>) connectConfig;
+//        } else {
+//            return MapTools.mapStrToMap_connect(connectConfig.toString());
+//        }
+//    }
+//
+//    /**
+//     * 关闭kafka信息
+//     *
+//     * @throws Exception
+//     */
+//    public void close() {
+//        if (Objects.nonNull(mqQueueManager)) {
+//            try {
+//                mqQueueManager.close();
+//            } catch (MQException e) {
+//            }
+//            mqQueueManager = null;
+//            System.out.println("mqQueueManager关闭");
+//        }
+//    }
+//}

+ 105 - 0
mainFactory/src/main/java/org/bfkj/protocol/MyKafKa.java

@@ -0,0 +1,105 @@
+package org.bfkj.protocol;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.clients.consumer.ConsumerRecords;
+import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.bfkj.utils.MapTools;
+
+import java.time.Duration;
+import java.util.*;
+
+public class MyKafKa {
+
+    private KafkaConsumer<String, Object> consumer;
+    private KafkaProducer<String, Object> producer;
+
+    /**
+     * 采集kafka数据
+     *
+     * @return 读取内容信息
+     */
+    public Map<String,Object> readMethod(String sourceObjectName, String library_id, String connectConfig) {
+        if (Objects.isNull(sourceObjectName)) {
+            return MapTools.processFail("队列为空");
+        }
+        Map<String, Object> connectConfigMaps;
+        connectConfigMaps = MapTools.mapStrToMap_connect(connectConfig);
+        if (!connectConfigMaps.containsKey("group.id")) {
+            connectConfigMaps.put("group.id", "groupid" + (String.format("%s", library_id)));
+        }
+        connectConfigMaps.put("max.poll.records", 1);
+        connectConfigMaps.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
+        connectConfigMaps.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
+
+        if (Objects.isNull(consumer)) {
+            consumer = new KafkaConsumer<>(connectConfigMaps);
+            consumer.subscribe(Collections.singleton(sourceObjectName));
+        }
+        //todo 1. 如果一次行读取多条 2.偏移修改
+        ConsumerRecords<String, Object> records = consumer.poll(Duration.ofSeconds(1));
+        int count = records.count();
+        Object message = null;
+        if (count > 0) {
+            for (ConsumerRecord<String, Object> record : records.records(sourceObjectName)) {
+                message = record.value();
+                break;
+            }
+        }
+        return MapTools.processSuccess(message);
+    }
+
+    /**
+     * 数据发送到kafka
+     *
+     * @return 发送结果信息
+     */
+    public Map<String,Object> sendMethod(String sourceObjectName, List<Object> dataContent, String connectConfig) {
+        if (Objects.isNull(sourceObjectName)) {
+            return MapTools.processFail("队列为空: " + dataContent);
+        }
+        if (Objects.isNull(dataContent)){
+            return MapTools.processSuccess(null);
+        }
+        Map<String, Object> connectConfigMaps = MapTools.mapStrToMap_connect(connectConfig);
+        connectConfigMaps.put("request.timeout.ms", 60000);
+        connectConfigMaps.put("max.request.size", 10240000);
+        connectConfigMaps.put("compression.type", "gzip");
+        connectConfigMaps.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
+        connectConfigMaps.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
+
+        if (Objects.isNull(producer)) producer = new KafkaProducer<>(connectConfigMaps);
+        ObjectMapper objectMapper = new ObjectMapper();
+        List<Object> sendResult = new ArrayList<>();
+        for (Object o : dataContent) {
+            try {
+                sendResult.add(producer.send(new ProducerRecord<>(sourceObjectName,objectMapper.writeValueAsString(o))));
+            } catch (Exception e) {
+                sendResult.add( producer.send(new ProducerRecord<>(sourceObjectName, o.toString())));
+            }
+        }
+         return MapTools.processSuccess(sendResult);
+    }
+
+    /**
+     * 关闭kafka信息
+     *
+     * @throws Exception
+     */
+    public void close() {
+        if (Objects.nonNull(consumer)) {
+            consumer.close();
+            consumer = null;
+            System.out.println("consumer关闭");
+        }
+
+        if (Objects.nonNull(producer)) {
+            producer.close();
+            producer = null;
+            System.out.println("consumer关闭");
+        }
+    }
+
+}

+ 106 - 0
mainFactory/src/main/java/org/bfkj/protocol/MyRabbitMQ.java

@@ -0,0 +1,106 @@
+package org.bfkj.protocol;
+
+import com.rabbitmq.client.Channel;
+import com.rabbitmq.client.Connection;
+import com.rabbitmq.client.ConnectionFactory;
+import com.rabbitmq.client.GetResponse;
+import org.bfkj.utils.LogUtils;
+import org.bfkj.utils.MapTools;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.TimeoutException;
+
+public class MyRabbitMQ {
+    private ConnectionFactory connectionFactory;
+
+    /**
+     * 采集kafka数据
+     *
+     * @return 读取内容信息
+     */
+    public Map<String, Object> readMethod(String sourceObjectName, String connectConfig) {
+        if (Objects.isNull(sourceObjectName) || Objects.isNull(connectConfig)) {
+            return MapTools.processFail(Objects.isNull(sourceObjectName) ? "队列为空" : "连接字符串为空");
+        }
+
+        Map<String, Object> connectConfigMaps = MapTools.mapStrToMap_connect(connectConfig);
+        try (Connection connection = createConnectFactory(connectConfigMaps).newConnection(); Channel currentChannel = connection.createChannel();) {
+            //创建消息通道
+            currentChannel.queueDeclare(sourceObjectName, true, false, false, null);
+            currentChannel.basicQos(1); //服务端在同一时刻只发送1条数据
+            GetResponse getResponse = currentChannel.basicGet(sourceObjectName, true);
+            String repBody = null;
+            if (null != getResponse) {
+                repBody = new String(getResponse.getBody());
+            }
+            return MapTools.processSuccess(repBody);
+        } catch (IOException | TimeoutException e) {
+            return MapTools.processFail(LogUtils.getException(e));
+        } finally {
+            connectionFactory = null;
+        }
+    }
+
+    public ConnectionFactory createConnectFactory(Map<String, Object> connectConfig) {
+        if (null == connectionFactory) {
+            connectionFactory = new ConnectionFactory();
+            connectionFactory.setHost(connectConfig.get("host").toString());
+            connectionFactory.setUsername(connectConfig.get("username").toString());
+            connectionFactory.setPassword(connectConfig.get("password").toString());
+            connectionFactory.setPort(Integer.parseInt(connectConfig.get("port").toString()));
+            Object virtualHost = connectConfig.get("virtualHost");
+            if (Objects.nonNull(virtualHost)) connectionFactory.setVirtualHost(virtualHost.toString());
+            connectionFactory.setConnectionTimeout(3000);
+        }
+        return connectionFactory;
+    }
+
+
+    /**
+     * 数据发送到kafka
+     *
+     * @return 发送结果信息
+     */
+    public Map<String,Object > sendMethod(String sourceObjectName, String routingKey, String data, String connectConfig, String exchangeName) {
+        if (Objects.isNull(sourceObjectName) || Objects.isNull(data)) {
+            return MapTools.processFail(Objects.isNull(sourceObjectName) ? ("队列为空 " + data) : ("数据内容为空 " + data));
+        }
+        Map<String, Object> connectConfigMaps = MapTools.mapStrToMap_connect(connectConfig);
+        ConnectionFactory connectFactory = createConnectFactory(connectConfigMaps);
+        try (Connection connection = connectFactory.newConnection()) {
+            try (Channel channel = connection.createChannel()) {
+                routingKey = (routingKey == null) ? sourceObjectName : routingKey;
+                exchangeName = (null == exchangeName) ? "" : exchangeName;
+//                AMQP.BasicProperties properties = new AMQP.BasicProperties.Builder().deliveryMode(2).contentEncoding("UTF-8").build();
+                //第一个参数是exchange参数,如果是为空字符串,那么就会发送到(AMQP default)默认的exchange,而且routingKey
+                //便是所要发送到的队列名
+                //todo 如果rabbitmq的服务端为绑定路由,那么写入不进行
+                //todo exchangeName为“” 则rabbitmq服务端不需要配置
+                //todo exchangeName为不为"" 则rabbitmq必须绑定
+                channel.basicPublish(exchangeName, routingKey, null, data.getBytes(StandardCharsets.UTF_8));
+            } catch (Exception e) {
+                return MapTools.processFail(LogUtils.getException(e));
+            }
+        } catch (IOException | TimeoutException e) {
+            return MapTools.processFail(LogUtils.getException(e));
+        } finally {
+            connectionFactory = null;
+        }
+        return MapTools.processSuccess(null);
+    }
+
+    /**
+     * 关闭kafka信息
+     *
+     * @throws Exception
+     */
+    public void close() {
+        if (Objects.nonNull(connectionFactory)) {
+            connectionFactory = null;
+        }
+    }
+}

+ 123 - 0
mainFactory/src/main/java/org/bfkj/protocol/WebAPI.java

@@ -0,0 +1,123 @@
+package org.bfkj.protocol;
+
+import org.bfkj.utils.LogUtils;
+import org.bfkj.utils.MapTools;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.StringHttpMessageConverter;
+import org.springframework.web.client.RestTemplate;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.Objects;
+
+public class WebAPI {
+
+    private RestTemplate restTemplate; //webapi请求对象
+    private String webapiURL;
+
+    private HttpHeaders webApiHeader;
+    private Object defaultBody;
+
+    private String webapiMethod;
+
+    /**
+     * webapi 执行入口函数
+     */
+    public Map<String,Object> execWebApi(Object header, String method, Object body, String connectConfig) {
+        Map<String, Object> connectConfigMaps = MapTools.mapStrToMap_connect(connectConfig);
+        Map<String,Object> restTemplateResult = initWebApiParams(connectConfigMaps); // 通过连接配置 获取restTemplate
+        if (!restTemplateResult.get("code").equals("0")) {
+            return MapTools.processFail(restTemplateResult.get("message").toString());
+        }
+        if (header instanceof Map) {
+            Map<String, Object>  temeMap=  (Map) header;
+            for (String key : temeMap.keySet()) {
+                webApiHeader.add(key, temeMap.get(key).toString());
+            }
+        }
+        if (MapTools.isNotBlank(method)) {
+            webapiMethod = method.toLowerCase();
+        }
+        if (null !=body) {
+            defaultBody = body;
+        }
+        HttpEntity<Object> request = new HttpEntity<>(defaultBody, webApiHeader);
+        try {
+            String responseEntity = null;
+            switch (webapiMethod) {
+                case "get":
+                    responseEntity = restTemplate.getForObject(webapiURL, String.class, request);
+                    break;
+                case "put":
+                    restTemplate.put(webapiURL, request);
+                    break;
+                case "delete":
+                    restTemplate.delete(webapiURL, request);
+                    break;
+                default:
+                    responseEntity = restTemplate.postForObject(webapiURL, request, String.class);
+                    break;
+            }
+            if (responseEntity == null && (webapiMethod.equals("put") || webapiMethod.equals("delete"))) {
+                return MapTools.processSuccess(null);
+
+            }
+            if (Objects.nonNull(responseEntity)) {
+                 return MapTools.processSuccess(responseEntity);
+            } else {
+                return MapTools.processFail("webapi发送请求失败 : " + responseEntity);
+            }
+        } catch (Exception e) {
+            return MapTools.processFail("restTemplate执行异常" + LogUtils.getException(e));
+        }
+    }
+
+    public Map<String,Object> initWebApiParams(Map<String, Object> connectConfig) {
+        if (restTemplate == null) {
+            if (Objects.isNull(connectConfig)) {
+                return MapTools.processFail("webapi请求配置参数为空" );
+            }
+            webapiURL = Objects.nonNull(connectConfig.get("url")) ? connectConfig.get("url").toString() : null;
+            if (Objects.isNull(webapiURL)) {
+                return MapTools.processFail("webapi请求地址为空" );
+            }
+            Object tempHeaders = connectConfig.get("headers"); //需确定返回的是一个map对象还是字符串  headers: {ContentType:"JSON"}
+            webApiHeader = new HttpHeaders();
+            if (Objects.isNull(tempHeaders)) {
+                webApiHeader.setContentType(MediaType.APPLICATION_JSON);
+            }
+            if (tempHeaders instanceof Map) {
+                Map<String, Object> tempHeader = (Map) tempHeaders;
+                if (!tempHeader.isEmpty()) {
+                    for (String key : tempHeader.keySet()) {
+                        webApiHeader.add(key, tempHeader.get(key).toString());
+                    }
+                }
+            }
+            defaultBody = connectConfig.get("body"); //需确定返回的是一个map对象还是字符串  headers: {ContentType:"JSON"}
+            Object webMethod = connectConfig.get("method"); //需确定返回的是一个map对象还是字符串  headers: {ContentType:"JSON"}
+            if (Objects.nonNull(webMethod)) {
+                webapiMethod = webMethod.toString().toLowerCase();
+            } else {
+                webapiMethod = "post";
+            }
+            restTemplate = new RestTemplate();
+            restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
+        }
+        return MapTools.processSuccess(restTemplate);
+    }
+
+    /**
+     * 关闭kafka信息
+     *
+     * @throws Exception
+     */
+    public void close() {
+        if (Objects.nonNull(restTemplate)) {
+            restTemplate = null;
+            System.out.println("restTemplate关闭");
+        }
+    }
+}

+ 664 - 0
mainFactory/src/main/java/org/bfkj/utils/DataFormat.java

@@ -0,0 +1,664 @@
+package org.bfkj.utils;
+
+
+import org.bfkj.config.ObjectMap;
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 数据格式转换
+ */
+public class DataFormat {
+    private static Map<String, String> messageRules = new HashMap<>();
+    private static Map<String, String> EMonth = new HashMap<>();
+    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+    static {
+        messageRules.put("BSM", "BSM[\\s\\S]+?ENDBSM");
+        messageRules.put("BPM", "BPM[\\s\\S]+?ENDBPM");
+        EMonth.put("JAN", "01");
+        EMonth.put("FEB", "02");
+        EMonth.put("MAR", "03");
+        EMonth.put("APR", "04");
+        EMonth.put("MAY", "05");
+        EMonth.put("JUN", "06");
+        EMonth.put("JUL", "07");
+        EMonth.put("AUG", "08");
+        EMonth.put("SEP", "09");
+        EMonth.put("OCT", "10");
+        EMonth.put("NOV", "11");
+        EMonth.put("DEC", "12");
+    }
+
+    public static Map<String, Object> processSuccess(Object returnData) {
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "0");
+        returnMap.put("returnData", returnData);
+        return returnMap;
+    }
+
+    //统一错误信息处理
+    public static Map<String, Object> processFail(String errorMessage) {
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "-1");
+        returnMap.put("message", errorMessage);
+        return returnMap;
+    }
+
+    /**
+     * @param str
+     * @return
+     */
+    private static String replaceWrap(String str) {
+        int rIndex = str.indexOf("\r");
+        int nIndex = str.indexOf("\n");
+        int index = str.indexOf("\\");
+        int tempIndex = str.length();
+        if (rIndex > 0) {
+            tempIndex = rIndex;
+        }
+        if (nIndex > 0 && nIndex < tempIndex) {
+            tempIndex = nIndex;
+        }
+        if (index > 0 && index < tempIndex) {
+            tempIndex = index;
+        }
+        return tempIndex == str.length() ? str : str.substring(0, tempIndex);
+
+
+    }
+    public static Map<String, Object> typeBToMap(String typeStr, String dataObjectId, Map<String, String> transMaps) {
+        try {
+            if (Objects.isNull(typeStr)) {
+                return MapTools.processSuccess(null);
+            }
+            if (Objects.isNull(transMaps)) {
+                transMaps = new HashMap<>();
+            }
+            //设定报文提取规则MAP,此MAP应该放到类变量中,属于常量,没必要每次调用都去创建:未来从配置文件或者数据库读取TypeB的所有数据格式,只是目前只支持BSM和BPM,未来可以加
+            List<Map<String, Object>> returnDataList = new ArrayList<>();//初始化一个最终返回的数组
+            for (String dataType : messageRules.keySet()) {//循环报文提取规则MAP:为了兼容一条字符串中既有BSM又有BPM的情况
+                List<String> messagList = MapTools.patternContent(typeStr, messageRules.get(dataType)); //使用对应的提取正则表达式进行报文提取
+                for (String signData : messagList) {//循环提取到的报文数组中每一条报文
+                    Map<String, Object> signDataMap = new HashMap<>();//创建一个当前报文的MAP
+                    signDataMap.put("dataType", dataType);//默认报文类型
+                    signDataMap.put("dataObjectId", dataObjectId); //默认生命周期ID
+                    signDataMap.put("sourceData", signData); //默认原始报文--因为要记录完整的原始报文,所以不去头不去尾
+                    String[] rowDataList = signData.split("(?=\\.[A-Z]{1}\\/)");//使用.字母/进行分组,获得行数据
+                    //获取第一行的数据:第一行,BPM为空,BSM直接使用indexOf判断即可
+                    signDataMap.put("dataState", dataType.equals("BSM") ? (rowDataList[0].contains("DEL") ? "DEL" : (rowDataList[0].contains("CHG") ? "CHG" : "ADD")) : null);
+                    List<Map<String, Object>> containerList = new ArrayList<>();//容器数组
+                    List<Map<String, Object>> luggageList = new ArrayList<>();//行李数组
+                    for (int rowNum = 1; rowNum < rowDataList.length; rowNum++) {  //循环行数据
+                        String rowDataStr = rowDataList[rowNum];//获取单行数据
+                        String rowType = rowDataStr.substring(0, 3);//头三位是行标识
+                        if (".B/.N/".contains(rowType)) {//如果是.B\.N开头则//luggageList = getluggageNumList(rowDataStr);//--单独一个方法处理
+                            List<String> luggageNumList = new ArrayList<>();//默认行李牌号数组为空数组
+                            String luggageState = null;//默认行李状态为NULL
+                            String[] colList = rowDataStr.split("\\/");//使用\进行分组,获得列数据
+                            for (int colNum = 1; colNum < colList.length; colNum++) {//循环
+                                String colValue = colList[colNum].trim();//去空格 OFF,3666149457002
+                                colValue = replaceWrap(colValue);
+                                if (MapTools.isNumber(colValue) && colValue.length() == 13) {//如果是13位数字则
+                                    String luggageNum = colValue.substring(0, 10);////获取前10位--开始行李牌号
+                                    for (int loopNum = 0; loopNum < Integer.parseInt(colValue.substring(10, 13)); loopNum++) {//循环连续行李数
+                                        luggageNum = String.format("%010d", (Long.parseLong(luggageNum) + loopNum)); //计算行李牌号,注意不足10位时前面补0:0999123456变数字后是9位
+                                        luggageNumList.add(luggageNum);//添加到行李牌号数组 3666149457,3666149458
+                                    }
+                                } else {//
+                                    luggageState = MapTools.isBlank(colValue) ? colValue.substring(0, 3) : null;//更新行李状态
+                                }
+                            }
+                            for (String luggageNum : luggageNumList) {//循环行李牌号数组
+                                Map<String, Object> luggageMap = new HashMap<>();
+                                luggageMap.put("luggageNum", luggageNum);
+                                luggageMap.put("luggageState", luggageState);
+                                luggageList.add(luggageMap);//追加到行李数组中{行李牌号,行李状态}
+                            }
+                        }
+                        //如果是.C\.E\.L\.M\.P\.Q\.R\.Q\.T开头则//去头写入当前行MAP{"对应数据库字段名",值(,号分割的字符串)
+                        if (".C/.E/.L/.M/.P/.Q/.R/.T/".contains(rowType)) {
+                            rowDataStr = rowDataStr.replace(rowType, "").trim();//去头去空格
+//                            rowDataStr = rowDataStr.indexOf("\\") > 0 ? rowDataStr.substring(0, rowDataStr.indexOf("\\") - 1) : rowDataStr;//去换行符
+                            rowDataStr = replaceWrap(rowDataStr);
+                            if (".P/".equals(rowType)) {//姓名需要去掉首位数字和分割符
+                                rowDataStr = rowDataStr.replaceAll("[(0-9)]", "").replaceAll("\\/", "");
+                            }
+                            if (Objects.nonNull(transMaps.get(rowType))) {
+                                signDataMap.put(transMaps.get(rowType), (signDataMap.containsKey(rowType) ? signDataMap.get(rowType) + "," : "") + rowDataStr);
+                            }
+                        }
+                        //如果是.D\.F\.G\.H\.I\.J\.O\.S\.W\.X\.Y开头则只记录第一个,存在则不覆盖
+                        if (".D/.F/.G/.H/.I/.J/.O/.S/.W/.X/.Y/".contains(rowType) && !signDataMap.containsKey(rowType + "1")) {
+                            String[] colList = rowDataStr.split("\\/");//使用\进行分组,获得列数据
+                            for (int colNum = 1; colNum < colList.length; colNum++) {//循环
+                                String colValue = colList[colNum].trim();//去空格
+                                colValue = replaceWrap(colValue);
+                                //如果是日期则使用日期转换方法进行转换(08APR)(注意跨年处理)".F/"".I/"".O/"有日期,".D/"".J/"有日期和时间
+                                if (".F/.I/.O/.D/.J/".contains(rowType)) {
+                                    String patternValue = MapTools.patternKey(colValue, "[0-2]{1}[0-9]{1}(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)");
+                                    if (!MapTools.isBlank(patternValue)) {
+                                        colValue = TypeBDateChange(patternValue, null);
+                                        signDataMap.put(rowType.equals(".D/") ? ".D/3" : (rowType.equals(".J/") ? ".J/4" : (rowType + "2")), colValue);//写入当前行MAP{"对应数据库字段名",值(不覆盖)}
+                                    }
+                                    if (".F/.I/.O/".contains(rowType) && MapTools.isNotBlank(colValue)) {
+                                        if (colValue.length() == 3 && !MapTools.isBlank(MapTools.patternKey(colValue, "[A-z]{3}"))) {
+                                            if (!signDataMap.containsKey(transMaps.get(rowType + "3"))) {
+                                                signDataMap.put(transMaps.get(rowType + "3"), colValue);//写入当前行MAP{"对应数据库字段名",值(不覆盖)}
+                                            }
+                                        }
+                                    }
+                                    if ((rowType + "" + colNum).equals(".J/5") || (rowType + "" + colNum).equals(".D/4")) {
+                                        colValue = TypeBDateChange(null, colValue);
+                                    }
+                                }
+                                if (".S/".contains(rowType) && MapTools.isNotBlank(colValue)) {
+                                    if ("I,V,A".contains(colValue) && colValue.length() == 1 && !signDataMap.containsKey(transMaps.get(".S/8"))) {
+                                        signDataMap.put(transMaps.get(".S/8"), colValue);//写入当前行MAP{"对应数据库字段名",值(不覆盖)}
+                                    }
+                                }
+                                if (".X/".contains(rowType) && MapTools.isNotBlank(colValue)) {
+                                    if (colValue.length() == 3) {
+                                        if ("CLR,RFJ,UCL".contains(colValue)) {
+                                            signDataMap.put(transMaps.get(".X/2"), colValue);//写入当前行MAP{"对应数据库字段名",值(不覆盖)}
+                                        }else {
+                                            signDataMap.put(transMaps.get(".X/1"), colValue);//写入当前行MAP{"对应数据库字段名",值(不覆盖)}
+                                        }
+                                    }
+                                }
+                                //如果是时间则使用时间转换方法进行转换转换(082512;082512L;082512Z,0825;0825L;0825Z)(注意没有结尾字母则是)".D/"".J/"有日期和时间
+                                //如果是日期时间则使用日期时间转换方法进行转换转换".G/"有日期时间(25NOV1600)
+                                //如果同时存在日期和时间".D/"".J/"有日期和时间
+                                String key = rowType + "" + colNum;
+                                if (".D/3.D/4.J/4.J/5".contains(rowType + "" + colNum)) {
+                                    if (!signDataMap.containsKey(key)) {
+                                        signDataMap.put(rowType + "" + colNum, colValue);//写入当前行MAP{"对应数据库字段名",值(不覆盖)}
+                                    }
+                                } else {
+                                    if (Objects.nonNull(transMaps.get(rowType + "" + colNum))) {
+                                        if (!signDataMap.containsKey(transMaps.get(key))) {
+                                            signDataMap.put(transMaps.get(rowType + "" + colNum), colValue);//写入当前行MAP{"对应数据库字段名",值(不覆盖)}
+                                        }
+                                    }
+                                }
+
+                            }
+                            // 处理D3D4 //J4J5
+//                            "D3D4": "checkInDate",
+                            if (Objects.nonNull(signDataMap.get(".D/3")) && Objects.nonNull(signDataMap.get(".D/4"))) {
+                                String d4 = signDataMap.get(".D/4").toString();
+                                signDataMap.put("checkInTimeType", d4.substring(d4.length() - 1));
+                                signDataMap.put(transMaps.get(".D/3.D/4"), (signDataMap.get(".D/3") + " " + d4.substring(0, d4.length() - 1)).trim());
+                                signDataMap.remove(".D/3");
+                                signDataMap.remove(".D/4");
+                            }
+                            if (Objects.nonNull(signDataMap.get(".J/4")) && Objects.nonNull(signDataMap.get(".J/5"))) {
+                                String J5 = signDataMap.get(".J/5").toString();
+                                signDataMap.put("processTimeType", J5.substring(J5.length() - 1));
+                                signDataMap.put(transMaps.get(".J/4.J/5"), (signDataMap.get(".J/4") + " " + J5.substring(0, J5.length() - 1)).trim());
+                                signDataMap.remove(".J/4");
+                                signDataMap.remove(".J/5");
+                            }
+                        }
+                        if (".V/".equals(rowType) && !signDataMap.containsKey(rowType + "1")) {//存在则不覆盖
+                            signDataMap.put(transMaps.get(".V/1"), rowDataStr.substring(4, 5));//写入当前行MAP{"来源标识",值}
+                            signDataMap.put(transMaps.get(".V/2"), rowDataStr.substring(5, 8));//写入当前行MAP{"来源机场",值}
+                        }
+                        if (".U/".equals(rowType)) {//如果是.U开头则----出现两个.U的需要单独处理
+                            Map<String, Object> containerMap = new HashMap<>();//创建一个当前报文的MAP
+                            String[] colList = rowDataStr.split("\\/");//使用\进行分组,获得列数据
+                            for (int colNum = 1; colNum < colList.length; colNum++) {//循环
+                                String colValue = colList[colNum];//去空格
+//                                colValue = colValue.indexOf("\\r\\n") > 0 ? colValue.substring(0, colValue.indexOf("\\r\\n") - 1) : colValue;//去换行符
+                                colValue = replaceWrap(colValue);
+                                if (Objects.nonNull(transMaps.get(rowType + "" + colNum))) {
+                                    containerMap.put(transMaps.get(rowType + "" + colNum), colValue);//写入容器MAP
+                                }
+
+                            }
+                            containerList.add(containerMap);//添加到容器数组中
+                        }
+                    }
+                    //处理容器以及行李数组
+                    if (containerList.size() == 0) {//为0时添加空MAP,方便下面的循环
+                        containerList.add(new HashMap<>());
+                    }
+                    if (containerList.size() > 2) {//最多两个容器,否则是异常数据,整个报文都作废
+                        signDataMap.put("errMessage", 1);//只需要标记错误,因为已经有原始报文存在
+                        returnDataList.add(signDataMap);//添加到返回数组中
+                    } else {
+                        for (int containerNum = 0; containerNum < containerList.size(); containerNum++) {//循环容器数组
+                            HashMap<String, Object> tempDataMapClone = MapTools.clone(signDataMap);
+                            HashMap<String, Object> tempDataMap = Objects.isNull(tempDataMapClone) ? new HashMap<>() : tempDataMapClone;  //深拷贝添加到单条报文的MAP中
+                            Map<String, Object> containerMap = containerList.get(containerNum);//获取当前容器数据
+                            if (containerNum == 0 && containerList.size() > 1) {//如果当前是第一条且容器数组大于代表第一个容器是卸下,第二个容器是
+                                containerMap.put("containerState", "OFF");//添加容器状态为OFF,代表卸下
+                            }
+                            if (!containerMap.isEmpty()) {//如果当前容器数据不是空
+                                tempDataMap.putAll(containerMap);//深拷贝添加到单条报文的MAP中
+                            }
+                            if (luggageList.size() == 0) {
+                                returnDataList.add(specialHandler(tempDataMap, dataObjectId)); //只有容器没有行李:整箱操作
+                            } else {
+                                for (Map<String, Object> tempLuggageMap : luggageList) {//循环行李数组
+                                    if (containerNum == 0 && containerList.size() > 1 && tempLuggageMap.get("luggageState") == null) {//只添加.B行李
+                                        continue;
+                                    }
+                                    if (containerNum != 0 && containerList.size() > 1 && tempLuggageMap.get("luggageState") != null) {//只添加.N行李
+                                        continue;
+                                    }
+                                    HashMap<String, Object> objectObjectHashMap = new HashMap<>();
+                                    objectObjectHashMap.putAll(tempDataMap);
+                                    objectObjectHashMap.putAll(tempLuggageMap);
+//                                    tempDataMap.putAll(tempLuggageMap);//添加行李信息
+                                    returnDataList.add(specialHandler(objectObjectHashMap, dataObjectId));//添加到返回数组中
+                                }
+                            }
+
+                        }
+                    }
+                }
+            }
+            return processSuccess(returnDataList);
+        } catch (Exception e) {
+            return processFail(LogUtils.getException(e));
+        }
+    }
+
+    /**
+     * //必要的特殊处理:
+     * //承运航班:如果有F则F否则如果有I则I否则空
+     * //起飞机场:如果有F则V否则如果有I则I否则空
+     * //降落机场:如果有F则F否则V
+     * //读取地点:如果有J则J否则如果有D则D否则有H则H
+     * //读取时间:如果有J则J否则如果有D则D否则接收时间
+     * //当前结果:如果有dataState则dataState否则有B则B否则有X则X
+     *
+     * @param inMap
+     * @return
+     */
+    public static Map<String, Object> specialHandler(HashMap<String, Object> inMap, String dataObjectId) {
+        String outAirport = inMap.containsKey("flightNo") ? "sourceAirport" : (inMap.containsKey("inflightNo") ? "inflightNo" : null);
+        inMap.put("outAirport", MapTools.isBlank(outAirport) ? null : inMap.get(outAirport));
+
+        String landAirport = inMap.containsKey("target_airport") ? "target_airport" : (inMap.containsKey("sourceAirport") ? "sourceAirport" : null);
+        inMap.put("landAirport", MapTools.isBlank(landAirport) ? null : inMap.get(landAirport));
+
+        String flightNo = inMap.containsKey("flightNo") ? "flightNo" : (inMap.containsKey("inflightNo") ? "inflightNo" : null);
+        inMap.put("flightNo", MapTools.isBlank(flightNo) ? null : inMap.get(flightNo));
+        String readAddess = inMap.containsKey("location_code") ? "location_code" : (inMap.containsKey("checkInLocation") ? "checkInLocation" : inMap.containsKey("operationArea") ? "operationArea" : null);
+        inMap.put("readAddess", MapTools.isBlank(readAddess) ? null : inMap.get(readAddess));
+        String readTime = inMap.containsKey("processing_time") ? "processing_time" : (inMap.containsKey("checkInDate") ? "checkInDate" : null);
+        inMap.put("readTime", MapTools.isBlank(readTime) ? sdf.format(new Date(MapTools.isBlank(dataObjectId) ? (System.currentTimeMillis()) : Long.parseLong(dataObjectId.substring(0, 13)))) : inMap.get(readTime));
+        String currentResult = inMap.containsKey("dataState") ? "dataState" : (inMap.containsKey("abnormalState") ? "abnormalState" : inMap.containsKey("securityInspectionResults") ? "securityInspectionResults" : null);
+        if (Objects.nonNull(inMap.get(currentResult))) {
+            inMap.put("currentResult", MapTools.isBlank(currentResult) ? null : inMap.get(currentResult));
+        }
+        // .F/.I/.O/.D/.J/
+
+
+        return inMap;
+    }
+
+    /**
+     * xml转map 定制化
+     *
+     * @param xml                     字符串
+     * @param isTwoDimensionalization 是否需要二维化
+     * @param noDiKaList              是否需要dika
+     * @param translateName           需要转义的名称
+     * @return code message returnData
+     */
+    public static Map<String, Object> customMadexmlToMap(String xml, boolean isTwoDimensionalization, List<String> noDiKaList, Map<String, String> translateName) {
+        Map<String, Object> returnMap = xmlToMapFormat(xml); //  code ,message ,returenData
+        if (returnMap.get("code").equals("-1")) return returnMap;
+        if (isTwoDimensionalization) {
+            Map<String, Object> xmlMap = (Map<String, Object>) returnMap.get("returnData");
+            returnMap = twoDimensionalizationFormat(xmlMap, noDiKaList); //  code ,message ,returenData
+        }
+        if (returnMap.get("code").equals("-1")) return returnMap;
+        if (null != translateName && !translateName.isEmpty()) {
+            Object returnData = returnMap.get("returnData"); //  code ,message ,returenData
+            if (returnData instanceof Map) {
+                List<Map<String, Object>> inData = new ArrayList<>();
+                inData.add((Map) returnData);
+                returnMap = translateMapName(inData, translateName); // code message retrunData
+            } else if (returnData instanceof List) {
+                returnMap = translateMapName((List) returnData, translateName); // code message retrunData
+            }
+        }
+        return returnMap;
+    }
+
+    /**
+     * map key值转换
+     *
+     * @param returnDataList
+     * @param translateName
+     * @return
+     */
+    public static Map<String, Object> translateMapName(List<Map<String, Object>> returnDataList, Map<String, String> translateName) {
+        try {
+            List<Map<String, Object>> dataList = new ArrayList<>();
+            for (Map<String, Object> returnData : returnDataList) {
+                Map<String, Object> temMap = new HashMap<>();
+                for (String key : returnData.keySet()) {
+                    if (translateName.containsKey(key)) {
+                        temMap.put(translateName.get(key), returnData.get(key));
+                    }
+                }
+                dataList.add(temMap);
+            }
+            return processSuccess(dataList);
+        } catch (Exception e) {
+            return processFail("translateMapName替换异常");
+        }
+    }
+
+    /**
+     * xml 转map 通用化
+     *
+     * @param xml
+     * @return
+     */
+    public static Map<String, Object> xmlToMapFormat(String xml) {
+        try {
+            xml = xml.substring(xml.contains("<") ? xml.indexOf("<") : 0, xml.lastIndexOf(">") > 0 ? xml.lastIndexOf(">") + 1 : xml.length());
+            xml = (xml.contains("<?xml") ? "" : "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n").concat(xml);
+            Document doc = DocumentHelper.parseText(xml);
+            Element root = doc.getRootElement();
+            return processSuccess(xmlToMap(root));
+        } catch (Exception e) {
+            return processFail("入参不是规则的xml :" + xml);
+        }
+    }
+
+    /**
+     * map 二维化
+     *
+     * @param inMap      需要二维化map
+     * @param noDiKaList 需要dika
+     * @return
+     */
+    public static Map<String, Object> twoDimensionalizationFormat(Map<String, Object> inMap, List<String> noDiKaList) {
+        try {
+            List<Map<String, Object>> returnDataList = twoDimensionalization(inMap, "", noDiKaList); /*生命周期未添加*/
+            return processSuccess(returnDataList);
+        } catch (Exception e) {
+            return processFail(LogUtils.getException(e));
+        }
+
+    }
+
+    public Map<String, Object> collectInsertOrUpdate(List<String> ids, String sourceTable, String sourceKey, String targetTable, List<String> uniqueList, boolean isActive, List<String> targetNull, String dbConnect) {
+        if ("".equals(dbConnect) || ids.isEmpty() || uniqueList.isEmpty()) {
+            return processSuccess(null);
+
+        }
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(dbConnect);
+        /*检测数据库中是否存在对应的表*/
+        Map<String, String> hasTableMap = myDbHelper.queryForObject("select COUNT(1) as count from information_schema.TABLES  where TABLE_NAME = ?", targetTable);
+        if (hasTableMap.get("code").equals("-1")) {
+            return processFail("算法工具类获取目标表结构执行SQL失败: " + hasTableMap.get("message"));
+        }
+        String count = hasTableMap.get("returnData");
+        if ("".equals(count) || "0".equals(count)) {
+            if (isActive) {
+                try {
+                    String tempSql = "CREATE TABLE if not EXISTS " + targetTable + " (" + targetTable + "_id int(11) NOT NULL AUTO_INCREMENT  PRIMARY KEY,`dataObjectId` VARCHAR(32) DEFAULT NULL ,`createtime` timestamp not null default current_timestamp) ";
+                    myDbHelper.execute(tempSql);
+                } catch (Exception e) {
+                    return processFail("collectInsertOrUpdate动态创建表结构失败 " + LogUtils.getException(e));
+                }
+            } else {
+                return processFail("目标表不是动态表,数据库中不存在");
+            }
+        }
+
+        /*检测数据库中是否存在对应表的唯一键*/
+        List<String> allColumn = new ArrayList<>();
+        List<String> tempUnique;
+        List<String> addIndex = new ArrayList<>();
+        tempUnique = MapTools.deepCopy(uniqueList);
+        tempUnique = (tempUnique == null) ? new ArrayList<>() : tempUnique;
+        Map<String, Object> desc_1Map = myDbHelper.queryByParamsReturnList("desc " + targetTable);
+        List<Map<String, Object>> mapList = MapTools.getMapList(desc_1Map);
+        if (!desc_1Map.get("code").equals("0") || null == mapList) {
+            return processFail("目标表不是动态表,数据库中不存在");
+        }
+        for (String unique : uniqueList) {
+            for (Map<String, Object> fieldMap : mapList) {
+                String field = fieldMap.get("Field").toString();
+                Object key = fieldMap.get("key");
+                allColumn.add(field);
+                if (field.equals(unique)) {
+                    tempUnique.remove(unique);
+                    if (Objects.isNull(key)) {
+                        addIndex.add(field);
+                    }
+                }
+            }
+        }
+        for (String field : tempUnique) {
+            myDbHelper.execute("alter table " + targetTable + " add " + field + " text ");
+        }
+        if (!addIndex.isEmpty()) {
+            myDbHelper.execute("alter table " + targetTable + " add  UNIQUE(" + String.join(",", addIndex) + ")");
+        }
+        tempUnique = MapTools.deepCopy(uniqueList);
+        try {
+            Map<String, Object> sourceDataListResult = myDbHelper.queryByParamsReturnList("select * from " + sourceTable + " where " + sourceKey + " in (" + String.join(",", ids) + ")");
+            List<Map<String, Object>> tempSourceData = MapTools.getMapList(sourceDataListResult);
+            if (!sourceDataListResult.get("code").equals("0") || null == tempSourceData) {
+                return processFail("查询数据数据失败");
+            }
+            for (Map<String, Object> currentData : tempSourceData) {
+                List<String> currentKeysList = new ArrayList<>(currentData.keySet());
+                for (String key : currentKeysList) {
+                    if (!allColumn.contains(key)) {
+                        myDbHelper.execute("alter table " + targetTable + " add " + key + " text ");
+                    }
+                }
+                List<String> uniqueKey = new ArrayList<>();
+                List<Object> uniqueValue = new ArrayList<>();
+                List<Object> columnValue = new ArrayList<>();
+                List<String> flag = new ArrayList<>();
+                for (String tpKey : currentData.keySet()) {
+                    Object tpValue = currentData.get(tpKey);
+                    if (Objects.isNull(tpValue) && !targetNull.contains(tpKey)) {
+                        currentKeysList.remove(tpKey);
+                        continue;
+                    }
+                    if (tempUnique.contains(tpKey)) {
+                        uniqueValue.add(tpValue);
+                        uniqueKey.add(tpKey);
+                        currentKeysList.remove(tpKey);
+                        continue;
+                    }
+
+                    if (tpKey.equals("createtime") || tpKey.equals(sourceKey)) {
+                        currentKeysList.remove(tpKey);
+                        continue;
+                    }
+                    flag.add("?");
+                    columnValue.add(tpValue.toString());
+                }
+                String sql = "select count(1) count from " + targetTable + " where " + String.join(" and ", updateList(uniqueKey, "=?"));
+                Map<String, String> hasTargetTableMap = myDbHelper.queryForObject(sql, uniqueValue.toArray());
+                if (hasTargetTableMap.get("code").equals("-1")) {
+                    return processFail("算法工具类获取目标表结构执行SQL失败: " + hasTargetTableMap.get("message"));
+                }
+                String targetCount = hasTargetTableMap.get("returnData");
+                if ("".equals(targetCount) || "0".equals(targetCount)) {
+                    currentKeysList.addAll(uniqueKey);
+                    for (String ignored : uniqueKey) {
+                        flag.add("?");
+                    }
+                    String tempSql = "insert into " + targetTable + "(" + String.join(",", currentKeysList) + ")" + "values  (" + String.join(",", flag) + ")";
+                    columnValue.addAll(uniqueValue);
+                    myDbHelper.updateByCondition(tempSql, null, columnValue.toArray());
+                } else {
+                    columnValue.addAll(uniqueValue);
+                    myDbHelper.updateByCondition("update " + targetTable + " set " + String.join(",", updateList(currentKeysList, "=?")) + " where " + String.join(" and ", updateList(uniqueKey, "=?")),
+                            null, columnValue.toArray());
+                }
+            }
+        } catch (Exception e) {
+            return processFail("collectInsertOrUpdate SQL 执行异常 " + LogUtils.getException(e));
+        }
+        return processSuccess(null);
+    }
+
+    private static List<Map<String, Object>> twoDimensionalization(Map<String, Object> inMap, String keyName, List<String> noDiKaList) {
+        //初始化一个返回数组List<map<string,object>> returnList
+        List<Map<String, Object>> returnList = new ArrayList<>();
+        // 默认添加一个空MAP----returnList.add(new map)//目的是确保计算迪卡乘积以及最后的单值赋值不出现问题
+        returnList.add(new HashMap<>());
+        //循环入参inMap
+        for (String currentKeyName : inMap.keySet()) {
+//            组装键名itemKeyName = (keyName为空?'':keyName) + '_' + currentKeyName
+            String itemKeyName = (Objects.equals(keyName, "") ? "" : keyName + '_') + currentKeyName;//组装键名
+            Object currentValue = inMap.get(currentKeyName);
+            if (currentValue instanceof List) {
+                List<Map<String, Object>> tempList = new ArrayList<>();
+                List<Object> list = (List<Object>) currentValue;
+                if (Objects.nonNull(noDiKaList) && noDiKaList.contains(itemKeyName)) {
+                    Map<String, Object> tempMap = new HashMap<>();
+                    tempMap.put(itemKeyName, currentValue.toString());
+                    tempList.add(tempMap);
+                } else {
+                    for (Object o : list) {
+                        if (o instanceof Map) {
+                            List<Map<String, Object>> tempListMap = twoDimensionalization((Map<String, Object>) o, itemKeyName, noDiKaList);
+                            tempListMap = dikaMap(returnList, tempListMap);//计算迪卡乘积
+                            tempList.addAll(tempListMap);
+                        } else {
+                            tempList.add(new HashMap<>() {{
+                                put(itemKeyName, o);
+                            }});
+                        }
+                    }
+                }
+                returnList = tempList;
+            } else {
+                if (currentValue instanceof Map) {
+                    List<Map<String, Object>> tempListMap = twoDimensionalization((Map<String, Object>) currentValue, itemKeyName, noDiKaList);//递归下一级
+                    List<Map<String, Object>> tempList = new ArrayList<>();
+                    if (Objects.nonNull(noDiKaList) && noDiKaList.contains(itemKeyName)) {
+                        Map<String, Object> tempMap = new HashMap<>();
+                        tempMap.put(itemKeyName, currentValue.toString());
+                        tempList.add(tempMap);
+                        returnList = tempList;
+                    } else {
+                        returnList = dikaMap(returnList, tempListMap);//计算迪卡乘积后替换当前的returnList
+                    }
+                } else {
+                    for (Map<String, Object> map : returnList) {//循环returnList
+                        map.put(itemKeyName, currentValue);////值不为MAP也不是数组则直接添加
+                    }
+                }
+            }
+        }
+        return returnList;//返回returnList
+    }
+
+    //MAP二维化辅助方法,返回List<map<string,object>>
+    private static List<Map<String, Object>> dikaMap(List<Map<String, Object>> parentList, List<Map<String, Object>> childList) {
+//        初始化一个返回数组
+        List<Map<String, Object>> returnList = new ArrayList<>();
+        for (Map<String, Object> childwMap : childList) {
+            HashMap<String,Object> childwMapClone = MapTools.clone(childwMap);
+            if (Objects.isNull(childwMapClone)) childwMapClone = new HashMap<>();
+            for (Map<String, Object> parentMap : parentList) {
+                HashMap<String,Object> parentMapClone = MapTools.clone(parentMap);
+                if (Objects.isNull(parentMapClone)){
+                    parentMapClone = new HashMap<>();
+                }
+                parentMapClone.putAll(childwMapClone);
+                returnList.add(parentMapClone);//注意使用HashMap.putall实现深拷贝
+            }
+        }
+        return returnList;
+    }
+
+    private static Map<String, Object> xmlToMap(Element element) {
+        String currentName = element.getName(); //当前节点名称
+        String currentValue = MapTools.getText(element.getTextTrim());// 当前节点值
+
+        Map<String, Object> returnMap = new HashMap<>();//初始化一个返回的结构
+        Map<String, Object> attrMap = new HashMap<>(); //初始化一个当前节点的属性结构
+        List<Attribute> attributes = element.attributes();  //属性处理
+        for (Attribute childAttribute : attributes) { //循环当前节点所有属性
+            attrMap.put(childAttribute.getName(), childAttribute.getValue());//逐个添加属性值到属性结构
+        }
+        List<Element> childNodes = element.elements(); //获取当前节点的所有子节点
+        if (childNodes.isEmpty() && !attrMap.isEmpty()) { // //无子节点且当前节点存在属性则
+            attrMap.put(currentName, currentValue); //当前节点值添加到属性中
+        }
+        for (Element childElement : childNodes) { //循环所有子节点,如果没有子节点不会进入循环
+            String childName = childElement.getName(); //获取子节点名称
+            if (attrMap.containsKey(childName)) { //已经存在相同子节点名称的值代表需要形成数组
+                Object oldValue = attrMap.get(childName); //获取已经存在的值
+                List<Object> newList = new ArrayList<>();
+                if (oldValue instanceof List) { //如果旧值已经是数组则
+                    newList = (List<Object>) oldValue; //强制转换为数组
+                } else {
+                    newList.add(oldValue); //转换为数组,旧值添加到数组中
+                }
+                newList.add(xmlToMap(childElement).get(childName));//添加子节点的数据,递归获取子节点的数据
+                attrMap.put(childName, newList);//添加到返回结构中;
+            } else {
+                attrMap.put(childName, xmlToMap(childElement).get(childName));//递归获取子节点的数据;
+            }
+        }
+        returnMap.put(currentName, attrMap.isEmpty() ? currentValue : attrMap);//添加当前节点的属性以及值(包括了子节点)
+        return returnMap;
+    }
+
+    private static String TypeBDateChange(String inDate, String inTime) {
+        //如果日期不为空
+        if (MapTools.isNotBlank(inDate)) {
+            String dayStr = inDate.trim().substring(0, 2);
+            String monthStr = EMonth.get(inDate.trim().substring(2, 5));
+            Calendar currentDate = Calendar.getInstance();
+            int yearStr = currentDate.get(Calendar.YEAR);
+            //处理跨年问题
+            int systemDay = currentDate.get(Calendar.DATE);
+            if (currentDate.get(Calendar.MONTH) + 1 == 12 && systemDay > 20 && Integer.parseInt(monthStr) == 1 && Integer.parseInt(dayStr) < 10) {
+                yearStr = yearStr + 1;
+            }
+            if (currentDate.get(Calendar.MONTH) + 1 == 1 && systemDay < 10 && Integer.parseInt(monthStr) == 12 && Integer.parseInt(dayStr) > 20) {
+                yearStr = yearStr - 1;
+            }
+            return yearStr + "-" + monthStr + "-" + dayStr;
+        }
+        if (MapTools.isNotBlank(inTime)) {
+            String dateType = inTime.substring(inTime.length() - 1);
+            dateType = MapTools.isNumber(dateType) ? "L" : dateType;
+            String h = inTime.length() > 1 ? inTime.substring(0, 2) : "00";
+            String m = inTime.length() > 3 ? inTime.substring(2, 4) : "00";
+            String s = inTime.length() > 5 ? inTime.substring(4, 6) : "00";
+            // 组合时间
+            return h + ":" + m + ":" + s + " " + dateType;
+        }
+        return null;
+    }
+
+    /**
+     * 修改list内容
+     *
+     * @param list 源list
+     * @param spc  针对每条数据添加的字符
+     * @return 新list
+     */
+    private List<String> updateList(List<String> list, String spc) {
+        return list.stream().map(x -> x + spc).collect(Collectors.toList());
+    }
+}

+ 89 - 0
mainFactory/src/main/java/org/bfkj/utils/LogUtils.java

@@ -0,0 +1,89 @@
+package org.bfkj.utils;
+
+
+import org.bfkj.config.AppConfig;
+import org.bfkj.config.ObjectMap;
+import org.bfkj.config.SpringContextBeans;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class LogUtils { // 依据服务编号ID获取服务类型,如果是异步 异常日志无条件写入到本地数据库(每个服务都有这样的一个数据库) ,在程序启动时会扫描此表,重新进行,如果成功则从此表中移除
+    public static synchronized void log(String location, String success, Object calculationLocation, String logContent, String serviceId, String workId, Object iNDataContent, String dataObjectId, Object OutDataContent, Object event) {
+        ThreadPoolTaskExecutor threadPoolTaskExecutor = SpringContextBeans.getBean("ThreadPoolTaskExecutor");
+        threadPoolTaskExecutor.submit(() -> logWrite(location, success, calculationLocation, logContent, serviceId, workId, iNDataContent, dataObjectId, OutDataContent, event));
+    }
+
+    /*
+    算法输入数据
+    算法返回结果
+    前置执行条件输出数据
+    前置执行条件返回结果
+    * */
+    public static void logWrite(String location, String success, Object calculationLocation, String logContent, String serviceId, String workId, Object iNDataContent, String dataObjectId, Object OutDataContent, Object event) {
+        String inData = MapTools.objectToString(iNDataContent);
+        String shortData = MapTools.isNotBlank(inData) ? inData.substring(0, 1024) : null;
+        List<Map<String, Object>> logParam = new ArrayList<>() {{
+            HashMap<String, Object> hashMap = new HashMap<>();
+            hashMap.put("location", location);
+            hashMap.put("success", success);
+            hashMap.put("calculationLocation", Objects.isNull(calculationLocation) ? null : calculationLocation.toString());
+            hashMap.put("logContent", logContent);
+            hashMap.put("serviceId", serviceId);
+            hashMap.put("workId", workId);
+            hashMap.put("iNDataContent", shortData);
+            hashMap.put("fullData", inData);
+            hashMap.put("OutDataContent", MapTools.objectToString(OutDataContent));
+            hashMap.put("dataObjectId", dataObjectId);
+            hashMap.put("event", Objects.isNull(event) ? null : event.toString());
+            add(hashMap);
+        }};
+        if (MapTools.isBlank(dataObjectId) && (!success.equals("0") || location.equals("start: 1"))) {
+            System.out.println("系统错误日志" + logParam); //系统错误日志
+            return;
+        }
+        String tableName = success.equals("0") ? "log_success" : "log_error";
+        String dbText = "远程数据库";
+        MyDbHelper myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.REMOTE_DB_CONNECT));
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            dbText = "本地数据库";
+            myDbHelper = ObjectMap.getordropMyDbHelper(AppConfig.getSystemParams(AppConfig.LOCAL_DB_CONNECT));
+        }
+        if (Objects.nonNull(myDbHelper.getErrorMessage())) {
+            System.out.println("记录日志: 获取" + dbText + "MyDbHelper对象失败,日志信息 :" + myDbHelper.getErrorMessage());
+        }
+        Map<String, Object> shortMap = myDbHelper.generalProcess("1", tableName, null, null, logParam, false, null, null);
+        if (!shortMap.get("code").equals("0")) {
+            System.out.println("记录日志: 写入" + dbText + "日志失败 :" + shortMap.get("message") + "\n数据:" + MapTools.objectToString(logParam));
+        }
+        if (MapTools.isNotBlank(inData) && inData.length()>1024){
+            Map<String, Object> fullMap = myDbHelper.generalProcess("1", "log_fullData", null, null, logParam, false, null, null);
+            if (!fullMap.get("code").equals("0")) {
+                System.out.println("记录日志(超长全量数据): 写入" + dbText + "日志失败 :" + fullMap.get("message") + "\n数据:" + MapTools.objectToString(logParam));
+            }
+        }
+    }
+
+    /**
+     * 获取当前行
+     *
+     * @return
+     */
+    public static String getLine() {
+        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+        return stackTrace[2].getClassName() + ":" + stackTrace[2].getLineNumber();
+    }
+
+    /**
+     * 异常位置
+     *
+     * @param e 异常信息
+     * @return
+     */
+    public static String getException(Exception e) {
+        StackTraceElement[] stackTraceElements = Arrays.copyOf(e.getStackTrace(), e.getStackTrace().length < 6 ? e.getStackTrace().length : 5);
+        return "异常消息:" + e.getMessage() + "  异常位置:" + Arrays.stream(stackTraceElements).map(it -> String.format("%s:%s:%d", it.getClassName(), it.getMethodName(), it.getLineNumber())).collect(Collectors.joining("\n"));//异常位置
+    }
+
+}

+ 488 - 0
mainFactory/src/main/java/org/bfkj/utils/MapTools.java

@@ -0,0 +1,488 @@
+package org.bfkj.utils;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.util.JSONPObject;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+
+import java.io.*;
+import java.math.BigInteger;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class MapTools implements Serializable {
+    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+    /**
+     * 字符串对象转时间
+     *
+     * @param dataStrObj
+     * @return
+     */
+    public static Date strObjToDate(Object dataStrObj) {
+        try {
+            if (Objects.isNull(dataStrObj)) {
+                return null;
+            }
+            return sdf.parse(dataStrObj.toString());
+        } catch (ParseException e) {
+            return null;
+        }
+    }
+
+    public static String dateTostr(Date date) {
+        return sdf.format(date);
+    }
+
+
+    public static String objectToString(Object object) {
+        if (Objects.nonNull(object) && !Objects.equals(object, "")) {
+            if (object instanceof List) {
+                List tempData = (List) object;
+                StringBuilder sb = new StringBuilder();
+                for (Object tempDatum : tempData) {
+                    sb.append(tempDatum).append("-");
+                }
+                return sb.toString();
+            }
+            if (object instanceof Map) {
+                HashMap<Object, Object> hashMap = new HashMap<>();
+                hashMap.putAll((Map) object);
+                return hashMap.toString();
+            }
+            return object.toString();
+        }
+        return null;
+    }
+
+    /**
+     * 正则表达式 判断字符串是否是自定类型
+     *
+     * @param str     字符串
+     * @param pattern 表达式
+     * @return
+     */
+    public static boolean isTrue(String str, String pattern) {
+        Pattern pat = Pattern.compile(pattern);
+        Matcher matcher = pat.matcher(str);
+        return matcher.find();
+    }
+
+    /**
+     * java正则提取多个结果
+     *
+     * @param str     字符串
+     * @param pattern 正则表达式
+     * @return 匹配的结果集
+     */
+    public static List<String> patternContent(String str, String pattern) {
+        // 编写正则表达式
+        // 匹配当前正则表达式
+        Matcher matcher = Pattern.compile(pattern).matcher(str);
+        // 定义当前文件的文件名称
+        List<String> arrayList = new ArrayList<>();
+        // 判断是否可以找到匹配正则表达式的字符
+        while (matcher.find()) {
+            // 将匹配当前正则表达式的字符串即文件名称进行赋值
+            arrayList.add(matcher.group());
+        }
+        // 返回
+        return arrayList;
+    }
+
+    public static String patternTableName(String str, String pattern) {
+        // 编写正则表达式
+        // 匹配当前正则表达式
+        Matcher matcher = Pattern.compile(pattern).matcher(str);
+        // 定义当前文件的文件名称
+        // 判断是否可以找到匹配正则表达式的字符
+        while (matcher.find()) {
+            // 将匹配当前正则表达式的字符串即文件名称进行赋值
+            return matcher.group(1);
+        }
+        // 返回
+        return null;
+    }
+
+
+    public static String patternKey(String str, String pattern) {
+        // 编写正则表达式
+        // 匹配当前正则表达式
+        Matcher matcher = Pattern.compile(pattern).matcher(str);
+        // 定义当前文件的文件名称
+        // 判断是否可以找到匹配正则表达式的字符
+        while (matcher.find()) {
+            // 将匹配当前正则表达式的字符串即文件名称进行赋值
+            return matcher.group();
+        }
+        // 返回
+        return null;
+    }
+
+    /**
+     * 判断字符串是否是xml
+     *
+     * @param XMLStr xml字符串
+     * @return true:false
+     */
+    public static boolean isXMl(String XMLStr) {
+        try {
+            DocumentHelper.parseText(XMLStr);//将XML字符串转为Document
+        } catch (DocumentException e) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * 获得字符串的值,如果是空字符串则为null
+     *
+     * @return xml标签值为空字符串:替换成null
+     */
+    public static String getText(String str) {
+        return MapTools.isBlank(str) ? null : str;
+    }
+
+    /**
+     * 判断字符串是覅否报文
+     *
+     * @param Str 字符串
+     * @return true:false
+     */
+    public static boolean isTypeB(String Str) {
+        Map<String, String> dataTypeMaps = new HashMap<>();
+        dataTypeMaps.put("BSM", "BSM[\\s\\S]+?ENDBSM");
+        dataTypeMaps.put("BPM", "BPM[\\s\\S]+?ENDPSM");
+        for (String dataType : dataTypeMaps.keySet()) {
+            if (isTrue(Str, dataType)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    /**
+     * list 深拷贝
+     *
+     * @param src 源list
+     * @param <T> list中数据类型
+     * @return 返回拷贝后新list的值
+     */
+    public static <T> List<T> deepCopy(List<T> src) {
+        try {
+            ByteArrayOutputStream byteout = new ByteArrayOutputStream();
+            ObjectOutputStream out = new ObjectOutputStream(byteout);
+            out.writeObject(src);
+            ByteArrayInputStream bytein = new ByteArrayInputStream(byteout.toByteArray());
+            ObjectInputStream in = new ObjectInputStream(bytein);
+            @SuppressWarnings("unchecked") List<T> dest = (List<T>) in.readObject();
+            in.close();
+            return dest;
+        } catch (ClassNotFoundException | IOException e) {
+            return null;
+        }
+    }
+
+    public static <HashMap extends Serializable> HashMap clone(Map<String, Object> obj) {
+        HashMap clonedObj = null;
+        try {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream oos = new ObjectOutputStream(baos);
+            oos.writeObject(obj);
+            ByteArrayInputStream bytein = new ByteArrayInputStream(baos.toByteArray());
+            ObjectInputStream ois = new ObjectInputStream(bytein);
+            clonedObj = (HashMap) ois.readObject();
+            ois.close();
+        } catch (Exception e) {
+            return null;
+        }
+        return clonedObj;
+    }
+
+
+    /**
+     * 取出字符串空格和换行
+     *
+     * @param str
+     * @return
+     */
+    public static String replaceBlank(String str) {
+        String dest = "";
+        if (str != null) {
+            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
+            Matcher m = p.matcher(str);
+            dest = m.replaceAll("");
+        }
+        return dest;
+    }
+
+
+    /**
+     * 从map中获取returnData获取List
+     *
+     * @param params
+     * @return
+     */
+
+    public static List<Map<String, Object>> getMapList(Map<String, Object> params) {
+        if (Objects.isNull(params.get("returnData"))) return null;
+        Object returnData = params.get("returnData");
+        if (returnData instanceof List) {
+            return (List<Map<String, Object>>) returnData;
+        } else {
+            return null;
+        }
+    }
+
+
+    public static boolean isStartWithNumber(String str) {
+        try {
+            Pattern pattern = Pattern.compile("[0-9]*");
+            Matcher isNum = pattern.matcher(str.charAt(0) + "");
+            if (!isNum.matches()) {
+                return false;
+            }
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+
+    }
+
+    /*字符串空判断*/
+    public static boolean isBlank(final String s) {
+        if (s == null || s.isEmpty()) {
+            return true;
+        }
+        for (int i = 0; i < s.length(); i++) {
+            char c = s.charAt(i);
+            if (!Character.isWhitespace(c)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /*字符串非空判断*/
+    public static boolean isNotBlank(final String s) {
+        return !isBlank(s);
+    }
+
+
+    /**
+     * 判断字符串是否是数字
+     *
+     * @param str 字符串
+     * @return 是数字:true ,否则false
+     */
+    public static boolean isNumber(String str) {
+        try {
+            Double.parseDouble(str);
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    /**
+     * 字符串转map
+     *
+     * @param mapStr map字符串: 如果不是map字符串则返回空,注意: map中不包含“”
+     * @return Map对象
+     */
+    public static Map<String, Object> stringToMap(String mapStr) {
+        Map<String, Object> map = new HashMap<>();
+        String str = "";
+        String key = "";
+        Object value = "";
+        char[] charList = mapStr.toCharArray();
+        boolean valueBegin = false;
+        for (int i = 0; i < charList.length; i++) {
+            char c = charList[i];
+            if (c == '{') {
+                if (valueBegin == true) {
+                    value = stringToMap(mapStr.substring(i, mapStr.length()));
+                    i = mapStr.indexOf('}', i) + 1;
+                    map.put(key, value);
+                }
+            } else if (c == '=') {
+                valueBegin = true;
+                key = str;
+                str = "";
+            } else if (c == ',') {
+                valueBegin = false;
+                value = str;
+                str = "";
+                map.put(key, value);
+            } else if (c == '}') {
+                if (!str.equals("")) {
+                    value = str;
+                }
+                map.put(key, value);
+                return map;
+            } else if (c != ' ') {
+                str += c;
+            }
+        }
+        return map;
+    }
+
+    /**
+     * JSON字符串转map
+     *
+     * @param mapStr 字符串:JSON字符串
+     * @return Map对象:返回map对象
+     */
+    public static Map jsonStringToMap(String mapStr) {
+        ObjectMapper mapper = new ObjectMapper();
+        try {
+            mapper.registerModule(new JavaTimeModule());
+            return mapper.readValue(mapStr, Map.class);
+        } catch (JsonProcessingException e) {
+            return null;
+        }
+    }
+
+    public static JSONPObject jsonStringToJSON(String mapStr) {
+        ObjectMapper mapper = new ObjectMapper();
+        try {
+            mapper.registerModule(new JavaTimeModule());
+            return mapper.readValue(mapStr, JSONPObject.class);
+        } catch (JsonProcessingException e) {
+            return null;
+        }
+    }
+    public static String mapToJSONString(Object mapStr) {
+        ObjectMapper mapper = new ObjectMapper();
+        try {
+            mapper.registerModule(new JavaTimeModule());
+            return mapper.writeValueAsString(mapStr);
+        } catch (JsonProcessingException e) {
+            return null;
+        }
+    }
+
+    public static String jacksonObjToStr(Object obj) { //"[1111]","[{"A":"B"}]"
+        ObjectMapper mapper = new ObjectMapper();
+        try {
+            if (null ==  obj){
+                return "";
+            }
+            mapper.registerModule(new JavaTimeModule());
+            if (!(obj instanceof String) && obj.toString().contains("{") && obj.toString().contains("}")||
+                    !(obj instanceof String) && obj.toString().contains("[") && obj.toString().contains("]")){
+                return mapper.writeValueAsString(obj);
+            }
+             return obj.toString();
+        } catch (JsonProcessingException e) {
+            return "日志数据转json字符串异常: " + e.getMessage() + ": " + obj.toString();
+        }
+    }
+
+
+    /**
+     * 验证字符串是否是map
+     *
+     * @param mapStr map字符串
+     * @return true:是map字符串,false不是map字符串
+     */
+    public static boolean isMap(String mapStr) {
+        return null != jsonStringToMap(mapStr);
+    }
+
+    /**
+     * list为空
+     *
+     * @param list list列表
+     * @param <T>  list中对象类型
+     * @return true:无元素  false : 存在元素
+     */
+    public static <T> boolean listIsEmpty(List<T> list) {
+        if (null == list) {
+            return true;
+        }
+        for (T t : list) {
+            if (t instanceof Map) {
+                for (Object value : ((Map<?, ?>) t).values()) {
+                    if (null != value) {
+                        return false;
+                    }
+                }
+            } else {
+                if (null != t) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    /**
+     * 判断list<Map>中指定元素是否为空
+     *
+     * @param list list<Map>列表
+     * @param key  指定字符串
+     * @param <T>  list中对象类型
+     * @return true: 不为空,false:为空
+     */
+    public static <T> boolean listIsEmpty(List<Map<String, Object>> list, String key) {
+        return listIsEmpty(list) || list.get(0).get(key) == null || list.get(0).get(key).toString().length() <= 0;
+    }
+
+    /**
+     * 数据库连接信息转map对象
+     *
+     * @param mapStr
+     * @return
+     */
+    public static Map<String, Object> mapStrToMap_connect(String mapStr) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        try {
+            return objectMapper.readValue(mapStr, Map.class);
+        } catch (JsonProcessingException e) {
+            return new HashMap<>();
+        }
+    }
+
+    public static Map<String, Object> processSuccess(Object returnData) {
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "0");
+        returnMap.put("returnData", returnData);
+        return returnMap;
+    }
+
+    //统一错误信息处理
+    public static Map<String, Object> processFail(String errorMessage) {
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "-1");
+        returnMap.put("message", errorMessage);
+        return returnMap;
+    }
+
+
+    public static String getMD5Str(String str) {
+        try {
+            MessageDigest md5 = MessageDigest.getInstance("md5");
+            byte[] digest = md5.digest(str.getBytes(StandardCharsets.UTF_8));
+            return new BigInteger(1, digest).toString(16);
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        }
+        //16是表示转换为16进制数
+        return null;
+    }
+
+    public static Map<String, Object> removeKey(Map<String, Object> inputData, List<String> arrayList) {
+        arrayList.forEach(inputData::remove);
+        return inputData;
+    }
+}

+ 855 - 0
mainFactory/src/main/java/org/bfkj/utils/MyDbHelper.java

@@ -0,0 +1,855 @@
+package org.bfkj.utils;
+
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+import org.bfkj.config.AppConfig;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.support.GeneratedKeyHolder;
+import org.springframework.jdbc.support.KeyHolder;
+
+import java.sql.*;
+import java.util.Date;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class MyDbHelper {
+
+    private HikariDataSource theDataSource;
+    private JdbcTemplate theJdbcTemplate;
+
+    private String connectConfig; //key
+
+    private List<String> tableList = new ArrayList<>();//当前连接对应数据库的所有表
+    private Map<String, List<String>> tableColumn = new HashMap<>();//缓存对象调用过的表的字段列表
+    private Map<String, List<String>> tablePrimaryKey = new HashMap<>();//缓存对象调用过的表的主键列表
+    private HashMap<String, Map<String, List<String>>> sqlColumn = new HashMap<>();//缓存对象调用过的表的主键列表
+    private ConcurrentHashMap<String, List<Object>> event6Map = new ConcurrentHashMap<>();
+    private Map<String, String> eventSQL = new HashMap<>() {{
+        put("0", "select * from 表名");
+        put("1", "insert into 表名(字段) values(值) ");
+        put("2", "update 表名 set 字段 ");
+        put("3", "delete from 表名 ");
+
+    }};
+    private static String errorMessage = null; //当前数据输入处理对象不可用信息
+
+    public MyDbHelper(String connectStr) { // 需要json字符串
+        Connection theConnect = null;
+        ResultSet tablesRsesult = null;
+        try {
+            connectConfig = connectStr;
+            Map<String, Object> connectMaps = MapTools.jsonStringToMap(connectStr);
+            if (connectMaps == null || Objects.isNull(connectMaps.get("url")) || Objects.isNull(connectMaps.get("driver-class-name"))) {
+                errorMessage = "数据库连接字符串非法: " + connectStr;
+                return;
+            }
+            HikariConfig config = new HikariConfig();
+            config.setMaximumPoolSize(6);//最大核心数 8*4
+            config.setKeepaliveTime(60000); //用于跟数据库保持心跳连接
+            config.setMaxLifetime(60000 * 60 * 4); //4小时 接在池中的最大生存时间,超过该时间强制逐出
+            config.addDataSourceProperty("cachePrepStmts", "true"); //是否自定义配置,为true时下面两个参数才生效
+            config.addDataSourceProperty("prepStmtCacheSize", "250"); //连接池大小默认25,官方推荐250-500
+            config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); //单条语句最大长度默认256,官方推荐2048
+            config.addDataSourceProperty("useServerPrepStmts", "true"); //新版本MySQL支持服务器端准备,开启能够得到显著性能提升
+            config.addDataSourceProperty("useLocalSessionState", "true");
+            config.addDataSourceProperty("useLocalTransactionState", "true");
+            config.addDataSourceProperty("rewriteBatchedStatements", "true");//批量新增
+            config.addDataSourceProperty("cacheResultSetMetadata", "true");
+            config.addDataSourceProperty("cacheServerConfiguration", "true");
+            config.addDataSourceProperty("elideSetAutoCommits", "true");
+            config.addDataSourceProperty("maintainTimeStats", "false");
+            if (Objects.nonNull(connectMaps.get("username"))) {
+                config.setUsername(connectMaps.get("username").toString());
+            }
+            if (Objects.nonNull(connectMaps.get("password"))) {
+                config.setPassword(connectMaps.get("password").toString());
+            }
+            config.setJdbcUrl(connectMaps.get("url").toString());
+            config.setDriverClassName(connectMaps.get("driver-class-name").toString());
+            theDataSource = new HikariDataSource(config);
+            theJdbcTemplate = new JdbcTemplate(theDataSource);
+
+            //根据
+            theConnect = theDataSource.getConnection();//用于批量新增以及获取当前数据库的相关信息
+            DatabaseMetaData tempMetaData = theConnect.getMetaData();
+            tablesRsesult = tempMetaData.getTables(theConnect.getCatalog(), theConnect.getCatalog(), null, new String[]{"TABLE"});
+            while (tablesRsesult.next()) {//缓存当前数据库的所有表名
+                tableList.add(tablesRsesult.getString("TABLE_NAME"));//获取表名
+            }
+
+        } catch (Exception e) {
+            errorMessage = LogUtils.getException(e);
+        } finally {
+            try {
+                if (tablesRsesult != null) {
+                    tablesRsesult.close();
+                }
+            } catch (SQLException e) {
+                System.out.println("MyDbHelper对象初始化时,关闭获取数据库信息的ResultSet出错: " + LogUtils.getException(e));
+            }
+            try {
+                if (theConnect != null) {
+                    theConnect.close();
+                }
+            } catch (SQLException e) {
+                System.out.println("MyDbHelper对象初始化时,关闭获取数据库信息的Connection出错:" + LogUtils.getException(e));
+            }
+        }
+    }
+
+    public void close() {
+        if (Objects.nonNull(theDataSource) && theDataSource.isRunning()) {//关闭连接池
+            theDataSource.close();
+        }
+        theJdbcTemplate = null;//无条件情况即可
+    }
+
+    //统一成功信息处理
+    public Map<String, Object> processSuccess(Object returnData, String sql, Object params) {
+        // todo 应该分析returnData是否包含code,如果包含应该合并分解--- 批量时的问题
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "0");
+        returnMap.put("returnData", returnData);
+        returnMap.put("sql", sql); //记录日志时 需要返回时去掉 dataProcess中处理
+        returnMap.put("params", MapTools.jacksonObjToStr(params));
+        return returnMap;
+    }
+
+    //统一错误信息处理
+    public Map<String, Object> processFail(String errorMessage, String sql, Object params) {
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "-1");
+        returnMap.put("message", errorMessage);
+        returnMap.put("sql", sql);
+        returnMap.put("params", MapTools.jacksonObjToStr(params));
+        return returnMap;
+    }
+
+    /*执行创建表*/
+    public Map<String, Object> execute(String sql) {
+        try {
+            theJdbcTemplate.execute(sql);
+            return processSuccess(null, sql, null);
+        } catch (Exception e) {
+            return processFail("执行创建表错误: " + LogUtils.getException(e), sql, null);
+        }
+    }
+
+    /**
+     * 根据条件查询,返回Lit<Map<String,Object>
+     *
+     * @param sql
+     * @param params
+     * @return
+     */
+    public Map<String, Object> queryByParamsReturnList(String sql, Object... params) {
+        try {
+            return processSuccess(theJdbcTemplate.queryForList(sql, params), sql, params);
+        } catch (Exception e) {
+            return processFail("根据条件查询异常" + LogUtils.getException(e), sql, params);
+        }
+    }
+
+    /**
+     * jdbcTemplate 增加、删除 、修改
+     *
+     * @param sql     执行语句
+     * @param batchPm 批量执行参数
+     * @param params  单挑执行参数
+     * @return sql执行返回结果
+     */
+    public Map<String, Object> updateByCondition(String sql, List<Object[]> batchPm, Object... params) {
+        try {
+            Object tempObject;
+            if (Objects.nonNull(batchPm) && batchPm.get(0) != null) {
+                tempObject = theJdbcTemplate.batchUpdate(sql, batchPm);
+            } else {
+                tempObject = theJdbcTemplate.update(sql, params);
+            }
+            return processSuccess(MapTools.jacksonObjToStr(tempObject), sql, (Objects.nonNull(batchPm) && batchPm.get(0) != null) ? MapTools.jacksonObjToStr(batchPm) : MapTools.jacksonObjToStr(params));
+        } catch (Exception e) {
+            return processFail("根据条件更新异常,SQL: " + LogUtils.getException(e), sql, ((Objects.nonNull(batchPm) && batchPm.get(0) != null) ? MapTools.jacksonObjToStr(batchPm) : MapTools.jacksonObjToStr(params)));
+        }
+    }
+
+
+    public synchronized Boolean updateEvent6Map(String tableName, Object updateParam, boolean isAdd) {
+        boolean isNew = false; //{tableName:[Map<String,Object>]}
+        if (!event6Map.containsKey(tableName)) {
+            event6Map.put(tableName, new ArrayList<>());
+        }
+        List<Object> tableUniqe = event6Map.get(tableName);
+        if (isAdd) {
+            if (!tableUniqe.contains(updateParam)) {
+                isNew = true;
+                tableUniqe.add(updateParam);
+            }
+            if (tableUniqe.size() > 6000) {
+                tableUniqe.remove(0);
+            }
+        } else {
+            tableUniqe.remove(updateParam);
+        }
+        return isNew;
+    }
+
+    public Map<String, Object> insertOrUpdate(String tableName, List<Map<String, Object>> paramsList) {  // [{“name”:"111"},[{Value:{},filter:{"name":"111"}]
+        List<Map<String, Object>> returnList = new ArrayList<>();
+        for (Map<String, Object> signParam : paramsList) {
+            String eventStr = "2";
+            if (updateEvent6Map(tableName, signParam.get("filter"), true)) { //不包含true
+                Map<String, Object> selectMap = generalProcess("0", null, "select 1 from " + tableName, null, paramsList, false, 1, 1);
+                if (selectMap.get("code").equals("-1")) {
+                    updateEvent6Map(tableName, signParam.get("filter"), false);
+                    returnList.add(selectMap);
+                    continue;
+                }
+                eventStr = (Objects.isNull(selectMap.get("returnData")) || ((List<?>) selectMap.get("returnData")).size() == 0) ? "1" : eventStr;
+            }
+            // 包含:
+            returnList.add(generalProcess(eventStr, tableName, null, null, new ArrayList<>() {{
+                add(signParam);
+            }}, false, null, null));
+        }
+        return returnList.size() == 1 ? returnList.get(0) : processSuccess(returnList, tableName, paramsList);
+    }
+
+
+    //统一数据处理,兼容增删改查
+    public Map<String, Object> generalProcess(String event, String tableName, String sql, String rowCountSQL, List<Map<String, Object>> paramsList, boolean isActive, Object page, Object pageSize) {
+        //-----入参检测
+        if (MapTools.isBlank(tableName) && MapTools.isBlank(sql)) {//如果表名为空 且SQL为空则返回错误
+            return processFail("generalProcess核心入口参数为空 ", null, paramsList);
+        }
+        if (MapTools.isBlank(tableName)) {//表名为空
+            String tempEvent = AppConfig.staticEvent.get(sql.trim().toLowerCase().substring(0, 6));
+            if (MapTools.isBlank(event)) {//事件为空时依据SQL确定事件
+                event = tempEvent;
+            } else {//依据SQL判断事件是否匹配
+                if (!tempEvent.equals(event)) {
+                    return processFail("generalProcess事件标志错误: event与SQL类型不匹配" + event, sql, paramsList);
+                }
+            }
+        }
+        List<Object> returnList = new ArrayList<>();
+        //初始化最终执行的参数集
+        if (MapTools.isBlank(tableName) && sql.contains("《")) {//SQL不为空且包含书名号则---无视SQL类型
+            Map<String, Object> parameterListByBookTitle = getParameterListByBookTitle(sql, paramsList, rowCountSQL);  // {"sql":{value:[],rowCountSQL:""}}
+            String querySQL = parameterListByBookTitle.get("sql").toString();
+            rowCountSQL = Objects.isNull(parameterListByBookTitle.get("rowCountSQL")) ? null : parameterListByBookTitle.get("rowCountSQL").toString();
+            List<Object[]> sqlValue = Objects.isNull(parameterListByBookTitle.get("value")) ? new ArrayList<>() : (List<Object[]>) parameterListByBookTitle.get("value");
+            return execSign(event, querySQL, rowCountSQL, page, pageSize, sqlValue, paramsList); // {"code":"",returnData:{"code":"",}}
+        } else {//表名或无书名号的SQL
+            List<String> allColumn = new ArrayList<>();//初始化所有列
+            List<String> allPrimaryKey = new ArrayList<>();//初始化所有主键
+            if (MapTools.isBlank(tableName)) {//如果SQL不为空
+                if ("0".equals(event)) {//如果是查询则---应该只有复杂select
+                    Map<String, Object> tempAllColumn = getAllColumnBySql(sql);
+                    if (tempAllColumn.get("code").equals("-1")) {
+                        return tempAllColumn;
+                    }
+                    HashMap<String, List<String>> sqlMetaData = (HashMap<String, List<String>>) tempAllColumn.get("returnData");
+                    allColumn = sqlMetaData.get("allColumn"); // a表 col1  col2  b表 col3 col4
+                    List<String> tableNameList = sqlMetaData.get("tableList");
+                    if (Objects.nonNull(tableNameList) && tableNameList.size() == 1) {
+                        tableName = tableNameList.get(0);
+                    }
+                } else {//否则---此时只有简单的insert update delete,或者根本不存在
+                    tableName = getTableBySql(sql);//从SQL语句中获取表名(使用空格进行分组,循环分组,update后不为空格的第一个就是表名)
+                }
+            }
+            if (!MapTools.isBlank(tableName)) {//如果表名不为空则:前面的SQL已经获取了表名
+                Map<String, Object> allColumnByTable = getMetaDataByTable(tableName, isActive);
+                if (allColumnByTable.get("code").equals("-1")) {
+                    return allColumnByTable;
+                }
+                allColumn = tableColumn.get(tableName);//依据表名获取所有列名
+                allPrimaryKey = tablePrimaryKey.get(tableName);//依据表名获取主键名  deployNodeID
+            }
+
+            Map<String, Map<String, Object>> modify = getModify(sql, tableName, paramsList, allColumn, allPrimaryKey, event, isActive, rowCountSQL);
+            for (String sqlStr : modify.keySet()) { // rowCountSQL : null
+                if (modify.keySet().size() == 1) {                                                       //[[],[]]
+                    return execSign(event, sqlStr, modify.get(sqlStr).get("rowCountSQL"), page, pageSize, (List<Object[]>) modify.get(sqlStr).get("valueList"), paramsList);
+                } else { //todo 目前无应用场景
+                    Map<String, Object> map = execSign(event, sqlStr, modify.get(sqlStr).get("rowCountSQL"), page, pageSize, (List<Object[]>) modify.get(sqlStr).get("valueList"), paramsList);
+                    returnList.add(map.get("returnData"));
+                }
+            }
+        }
+        return processSuccess(returnList, sql, paramsList);
+    }
+
+    private Map<String, Object> execSign(String event, String sql, Object rowCountSQL, Object page, Object pageSize, List<Object[]> parameterList, List<Map<String, Object>> paramsList) {
+        if ("0".equals(event)) {//如果是查询则
+            if (sql.lastIndexOf(")") >= sql.lastIndexOf("limit")) {//如果是查询则进行翻页默认值处理,需要加入是否是数字的判断
+                int thePage = (Objects.isNull(page) || !MapTools.isNumber(page.toString())) ? 1 : Integer.parseInt(page.toString());
+                int thePageSize = (Objects.isNull(pageSize) || !MapTools.isNumber(pageSize.toString())) ? 50 : Integer.parseInt(pageSize.toString());
+                sql = sql + ((thePage == 1 && thePageSize == 1) ? " limit 1 " : (" limit " + ((thePage - 1) * thePageSize) + " ," + thePageSize));
+            }
+            try {//执行查询
+                Map<String, Object> returnData = processSuccess(theJdbcTemplate.queryForList(sql, parameterList.get(0)), sql, parameterList.get(0));
+                if (Objects.nonNull(rowCountSQL)) {
+                    returnData.put("rowcount", theJdbcTemplate.queryForObject(rowCountSQL.toString(), Integer.class, parameterList.get(0)));
+                }
+                return returnData;
+            } catch (Exception e) {
+                return processFail("查询出现异常:" + LogUtils.getException(e), sql, parameterList);
+            }
+        }
+        if ("1".equals(event)) {//如果是新增则使用JDBC方式进行,方便获取新增后的主键
+            return JDBCBatch(sql, parameterList, paramsList);
+        }
+        return updateByCondition(sql, parameterList);
+    }
+
+    public synchronized Map<String, Object> JDBCBatch(String sql, List<Object[]> paramList, List<Map<String, Object>> paramsList) {
+        if (!sql.contains("?")) {  // Object[]
+            return processSuccess(null, sql, paramsList);
+        }
+        ResultSet currentRS = null;
+        PreparedStatement sqlPS = null;
+        Connection connection = null;
+        try {
+            connection = theDataSource.getConnection();
+            connection.setAutoCommit(false);    //[[],[]]
+            sqlPS = connection.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
+            for (Object[] list : paramList) {
+                for (int j = 0; j < list.length; j++) {
+                    sqlPS.setObject(j + 1, list[j]);
+                }
+                sqlPS.addBatch();
+            }
+            sqlPS.executeBatch();
+            connection.commit(); // List<Object[]>
+            List<String> currentPRIKeyList = tablePrimaryKey.get(getTableBySql(sql));//依据SQL获取主键名
+            if (Objects.nonNull(currentPRIKeyList) && currentPRIKeyList.size() > 0) {//主键名不为空则
+                currentRS = sqlPS.getGeneratedKeys(); //获取结果
+                int index = 0;
+                while (currentRS.next()) {//循环获取主键值
+                    int keyIndex = 1;
+                    for (String priKey : currentPRIKeyList) {
+                        Map<String, Object> indexMap = paramsList.get(index);
+                        if (indexMap.containsKey("Value") && indexMap.get("Value") instanceof Map<?, ?>) {
+                            indexMap = (Map<String, Object>) indexMap.get("Value");
+                        }
+                        indexMap.put(priKey, currentRS.getObject(keyIndex));
+                        paramsList.set(index, indexMap);
+                        keyIndex++;
+                    }
+                    index++;
+                }
+            }
+            return processSuccess(paramsList, sql, paramList);
+        } catch (Exception e) {
+            try {
+                if (connection != null) {
+                    connection.rollback();
+                }
+            } catch (SQLException ex) {
+                System.out.println("jdbc 批量新增 : 事务回滚异常信息:" + LogUtils.getException(e));
+            }
+            return processFail("dbSava执行批量Insert SQL异常 " + LogUtils.getException(e) + "事务回滚", sql, paramList);
+        } finally {
+            try {
+                if (currentRS != null) {
+                    currentRS.close();
+                }
+            } catch (SQLException e) {
+                System.out.println("jdbc 批量新增 关闭结果集异常: " + LogUtils.getException(e));
+            }
+            try {
+                if (sqlPS != null) {
+                    sqlPS.close();
+                }
+            } catch (SQLException e) {
+                System.out.println("jdbc 批量新增 关闭预编译异常: " + LogUtils.getException(e));
+            }
+            try {
+                if (connection != null) {
+                    connection.setAutoCommit(true);
+                    connection.close();
+                }
+            } catch (SQLException e) {
+                System.out.println("jdbc 批量新增 关闭连接异常: " + LogUtils.getException(e));
+            }
+        }
+    }
+
+    private Map<String, Map<String, Object>> getModify(String sql, String tableName, List<Map<String, Object>> paramsList, List<String> allColumn, List<String> allPrimaryKey, String event, boolean isActive, String rowCountSQL) {
+        // 需要处理sql,如果表名为空则 此时sql 需要组件where条件
+        if (Objects.isNull(allColumn)) allColumn = new ArrayList<>();
+        if (Objects.isNull(allPrimaryKey)) allPrimaryKey = new ArrayList<>();
+
+        if (isActive && event.equals("1")) {
+            for (Map<String, Object> itemMap : paramsList) {
+                Map<String, Object> valueMap = itemMap.containsKey("Value") ? (Map<String, Object>) itemMap.get("Value") : itemMap;
+                for (String key : valueMap.keySet()) {
+                    if (!allColumn.contains(key) && !allPrimaryKey.contains(key)) {
+                        theJdbcTemplate.execute("alter table " + tableName + " add " + key + " text ");
+                        allColumn.add(key);
+                    }
+                }
+            }
+        }
+
+        allColumn.removeAll(allPrimaryKey);
+        Map<String, Map<String, Object>> sqlMap = new HashMap<>();
+        if ("0".contains(event) && paramsList.size() > 1) {  //目前仅支持批量新增,不支持批量更新:select delete 本身不存在批量
+            List<Map<String, Object>> tempList = new ArrayList<>();
+            tempList.add(paramsList.get(0));
+            paramsList = tempList;
+        }
+        for (Map<String, Object> itemMap : paramsList) {
+            List<Object> cuList = new ArrayList<>();
+            List<String> modifyCol = new ArrayList<>();
+            List<String> modifyValue = new ArrayList<>();
+            if ("1,2".contains(event)) {
+                Map<String, Object> valueMap = itemMap.containsKey("Value") ? (Map<String, Object>) itemMap.get("Value") : itemMap;
+                if (allColumn.contains("createtime")) {
+                    valueMap.put("createtime", new Date());
+                }
+                if (event.equals("1")) {
+                    for (String column : allColumn) {
+                        cuList.add(valueMap.get(column));
+                        modifyValue.add("?");
+                    }
+                    modifyCol = allColumn;
+                } else {
+                    for (String key : valueMap.keySet()) {
+                        cuList.add(valueMap.get(key));
+                        modifyCol.add(key + "=?");
+                    }
+                }
+            }
+            String whereStr = "";
+            if (!event.equals("1")) {
+                List<Map<String, Object>> filterMapList = new ArrayList<>();
+                Object tempObj = itemMap.get("filter");  // [{filter:[{"a":""}]}]
+                if (tempObj instanceof Map || tempObj instanceof List) {
+                    if (tempObj instanceof Map) {
+                        if (((Map<String, Object>) tempObj).containsKey("left")) {
+                            filterMapList.add((Map<String, Object>) tempObj);
+                        } else {
+                            authoParams((Map<String, Object>) tempObj, filterMapList, allColumn, allPrimaryKey);
+                        }
+                    } else {
+                        if (((List<?>) tempObj).size() > 0) { // [filter:[{"A":"v","B":"D"}]]
+                            Object firstObj = ((List<?>) tempObj).get(0);
+                            if (firstObj instanceof Map<?, ?>) {
+                                if (((Map<?, ?>) firstObj).containsKey("left")) {
+                                    filterMapList = (List<Map<String, Object>>) tempObj;
+                                } else {
+                                    authoParams((Map<String, Object>) firstObj, filterMapList, allColumn, allPrimaryKey);
+                                }
+                            }
+                        }
+                    }
+                } else {
+                    authoParams(itemMap, filterMapList, allColumn, allPrimaryKey);
+                }
+                List<Map<String, Object>> prikeyFilter = new ArrayList<>();
+                List<String> prikeyCount = new ArrayList<>();
+                for (Map<String, Object> filterMap : filterMapList) {
+                    if (filterMap.containsKey("column") && allPrimaryKey.contains(filterMap.get("column").toString())) {
+                        if (!prikeyCount.contains(filterMap.get("column").toString())) {
+                            prikeyCount.add(filterMap.get("column").toString());
+                        }
+                        prikeyFilter.add(filterMap);
+                    }
+                }
+                if (prikeyFilter.size() > 0 && prikeyCount.size() == allPrimaryKey.size()) { /// 1
+                    filterMapList = prikeyFilter;
+                }
+                for (Map<String, Object> filter : filterMapList) {
+                    whereStr = whereStr.concat(filter.get("left").toString()).concat(filter.get("column").toString()).concat(filter.get("comparator").toString()).concat(filter.get("comparator").equals(" is null ") ? "" : "?").concat(filter.get("right").toString())
+                            .concat((Objects.isNull(filter.get("connector")) || filter.get("connector").toString().trim().equals("")) ? " and " : " " + filter.get("connector").toString().trim() + " ");
+                    if (!filter.get("comparator").equals(" is null ")) {
+                        cuList.add(filter.get("value"));
+                    }
+                }
+                whereStr = whereStr.trim(); // user_id =1
+                whereStr = whereStr.endsWith("and") || whereStr.endsWith(" or") ? whereStr.substring(0, whereStr.length() - 3) : whereStr;
+            }
+            String sqlStr = !MapTools.isBlank(sql) ? sql : eventSQL.get(event).replace("表名", tableName).replace("字段", String.join(",", modifyCol)).replace("值", String.join(",", modifyValue));
+            if (event.equals("0") && !MapTools.isBlank(tableName)) { // 理论上sql 不为空 可以通过allColumn 替换为count 1 来组建rowCountSQL---> select * from biao left ……
+                rowCountSQL = "select count(1) from " + tableName;
+            }
+            if (event.equals("0") && MapTools.isNotBlank(sql) && MapTools.isBlank(rowCountSQL) && allColumn.size() > 0) {
+                rowCountSQL = sql;
+                for (int index = 0; index < allColumn.size(); index++) {
+                    rowCountSQL = rowCountSQL.replace(allColumn.get(index), index == 0 ? " count(1) " : "");
+                }
+            }
+            if (!event.equals("1") && !whereStr.equals("")) { //删除,查询,更新
+                sqlStr = sqlStr.concat(sqlStr.lastIndexOf(")") >= sqlStr.lastIndexOf(" where ") ? " where " : " and ").concat("(").concat(whereStr).concat(" )");
+                if (!MapTools.isBlank(rowCountSQL)) {
+                    rowCountSQL = rowCountSQL.concat(sqlStr.lastIndexOf(")") >= sqlStr.lastIndexOf(" where ") ? " where " : " and ").concat("(").concat(whereStr).concat(")");
+                }
+            }
+            Map<String, Object> sqlMapValue = sqlMap.get(sqlStr);
+            if (Objects.isNull(sqlMapValue) || sqlMapValue.isEmpty()) {
+                sqlMapValue = new HashMap<>();
+                List<Object> vaList = new ArrayList<>();
+                vaList.add(cuList.toArray()); //
+                sqlMapValue.put("valueList", vaList);  // [[]]  // List<Object[]>   ----- // cuList.toArrayList
+                sqlMapValue.put("rowCountSQL", rowCountSQL);
+            } else {
+                List<Object> valueList = (List<Object>) sqlMapValue.get("valueList");  // Object[] ,Object[]
+                valueList.add(cuList.toArray());
+                sqlMapValue.put("valueList", valueList); // [[1,2,3,4],[]]
+
+            }
+            sqlMap.put(sqlStr, sqlMapValue);
+        }
+        return sqlMap;
+
+    }
+
+
+    private void authoParams(Map<String, Object> itemMap, List<Map<String, Object>> filterMapList, List<String> allColumn, List<String> allPrimaryKey) {
+        itemMap = Objects.isNull(itemMap) ? new HashMap<>() : itemMap;
+        for (String filterKey : itemMap.keySet()) {
+            if (!allColumn.contains(filterKey) && !allPrimaryKey.contains(filterKey)) continue;
+            HashMap<String, Object> filterMap = new HashMap<>();
+            Object keyValues = itemMap.get(filterKey);
+            filterMap.put("left", "");
+            filterMap.put("column", filterKey);
+            filterMap.put("comparator", " = ");
+            if (Objects.isNull(keyValues)) {
+                filterMap.put("comparator", " is null ");
+            }
+            filterMap.put("value", keyValues);
+            filterMap.put("right", "");
+            filterMap.put("connector", " and ");
+            filterMapList.add(filterMap);
+        }
+    }
+
+    private Map<String, Object> getMetaDataByTable(String tableName, boolean isActive) {
+        if (!MapTools.isBlank(tableName) && !tableList.contains(tableName)) {
+            if (isActive) {
+                try {
+                    String tempSql = "CREATE TABLE if not EXISTS " + tableName + " (" + tableName + "_id int(11) NOT NULL AUTO_INCREMENT  PRIMARY KEY,`dataObjectId` VARCHAR(32) DEFAULT NULL ,`createtime` datetime  ) ";
+                    theJdbcTemplate.execute(tempSql);
+                } catch (Exception e) {
+                    return processFail("动态创建表时异常:" + LogUtils.getException(e), tableName, null);
+                }
+
+            } else {
+                return processFail("表名为空或者当前数据库中不存在此表", tableName, null);
+            }
+        }
+        if (!(tableColumn.containsKey(tableName))) {
+            Connection connection = null;
+            ResultSet columnRsesult = null;
+            try {
+                connection = theDataSource.getConnection();
+                DatabaseMetaData tempMetaData = connection.getMetaData();
+                columnRsesult = tempMetaData.getColumns(connection.getCatalog(), connection.getCatalog(), tableName, null);
+                List<String> columnList = new ArrayList<>();
+                while (columnRsesult.next()) {
+                    columnList.add(columnRsesult.getString("COLUMN_NAME"));
+                }
+                tableColumn.put(tableName, columnList);
+
+
+                ResultSet primaryKeyResult = tempMetaData.getPrimaryKeys(connection.getCatalog(), connection.getCatalog(), tableName);
+                List<String> primaryKeyList = new ArrayList<>();
+                while (primaryKeyResult.next()) {
+                    String priKeyName = primaryKeyResult.getString("COLUMN_NAME");
+                    if (!primaryKeyList.contains(priKeyName)) {
+                        primaryKeyList.add(priKeyName);
+                    }
+                }
+                tablePrimaryKey.put(tableName, primaryKeyList);
+
+
+            } catch (Exception e) {
+                return processFail("获取表的所有列异常:" + LogUtils.getException(e), tableName, null);
+            } finally {
+                if (columnRsesult != null) {
+                    try {
+                        columnRsesult.close();
+                    } catch (SQLException sqle) {
+                        System.out.println("获取所有列,关闭结果集异常");
+                    }
+                }
+                if (connection != null) {
+                    try {
+                        connection.close();
+                    } catch (SQLException sqle) {
+                        System.out.println("获取所有列,关闭连接异常");
+                    }
+                }
+            }
+
+        }
+        return processSuccess(null, tableName, null);
+    }
+
+    /**
+     * 根据sql获取表名
+     *
+     * @param sql
+     * @return
+     */
+    private String getTableBySql(String sql) {
+        String[] sqlSplit = sql.trim().toLowerCase().split("\\s+");
+        if (sqlSplit[0].equals("insert")) {
+            String tableName = sqlSplit[2]; // insert into biao(col1) values ()
+            tableName = tableName.indexOf("(") > 0 ? tableName.substring(0, tableName.indexOf("(")) : tableName;
+            return tableName;
+        }
+        if (sqlSplit[0].equals("update")) {
+            return sqlSplit[1]; // update biao  set xx =?  into biao(col1) values ()
+        }
+        if (sqlSplit[0].equals("delete")) {
+            return sqlSplit[2]; // delete from  biao where id =……
+        }
+        return null;
+    }
+
+    public Map<String, Object> getAllColumnBySql(String sql) {
+        if (sql.lastIndexOf(")") >= sql.lastIndexOf("limit")) {
+            sql = sql + " limit 1";
+        }
+        if (!sqlColumn.containsKey(sql)) {
+            ResultSet rs = null;
+            Connection connection = null;
+            PreparedStatement ps = null;
+            try {
+                connection = theDataSource.getConnection();
+                ps = connection.prepareStatement(sql);
+                rs = ps.executeQuery();
+                ResultSetMetaData rsd = rs.getMetaData();
+                List<String> allColumn = new ArrayList<>();
+                List<String> tableList = new ArrayList<>();
+                for (int i = 0; i < rsd.getColumnCount(); i++) {
+                    allColumn.add(rsd.getColumnName(i + 1)); /*如果使用了as getColumnLabel得不到*/
+                    String tableName = rsd.getTableName(i + 1);
+                    if (!tableList.contains(tableName)) {
+                        tableList.add(tableName);
+                    }
+                }
+                HashMap<String, List<String>> sqlMeta = new HashMap<>();
+                sqlMeta.put("allColumn", allColumn);
+                sqlMeta.put("tableList", tableList);
+                sqlColumn.put(sql, sqlMeta);
+            } catch (SQLException e) {
+                return processFail("getAllColumnBySql 异常: " + LogUtils.getException(e), sql, null);
+            } finally {
+                if (rs != null) {
+                    try {
+                        rs.close();
+                    } catch (SQLException sqle) {
+                        System.out.println("获取所有列,关闭结果集异常");
+                    }
+                }
+                if (ps != null) {
+                    try {
+                        ps.close();
+                    } catch (SQLException sqle) {
+                        System.out.println("获取所有列,关闭预编译异常");
+                    }
+                }
+                if (connection != null) {
+                    try {
+                        connection.close();
+                    } catch (SQLException sqle) {
+                        System.out.println("获取所有列,关闭连接异常");
+                    }
+                }
+
+            }
+        }
+        return processSuccess(sqlColumn.get(sql), sql, null);
+    }
+
+    public Map<String, Object> getAllColumnForSet(String sql) {
+        if (sql.lastIndexOf(")") >= sql.lastIndexOf("limit")) {
+            sql = sql + " limit 1";
+        }
+        ResultSet rs = null;
+        Connection connection = null;
+        PreparedStatement ps = null;
+        try {
+            connection = theDataSource.getConnection();
+            ps = connection.prepareStatement(sql);
+            rs = ps.executeQuery();
+            ResultSetMetaData rsd = rs.getMetaData();
+            List<Map<String, Object>> allColumnList = new ArrayList<>();
+            for (int i = 0; i < rsd.getColumnCount(); i++) {
+                HashMap<String, Object> tempMap = new HashMap<>();
+                tempMap.put("columnName", rsd.getColumnName(i + 1));
+                tempMap.put("columnType", rsd.getColumnType(i + 1));
+                tempMap.put("columnTypeName", rsd.getColumnTypeName(i + 1));
+                tempMap.put("columnLable", rsd.getColumnLabel(i + 1));
+                allColumnList.add(tempMap);
+            }
+            return processSuccess(allColumnList, sql, null);
+        } catch (SQLException e) {
+            return processFail("getAllColumnForSet 异常: " + LogUtils.getException(e), sql, null);
+        } finally {
+            if (rs != null) {
+                try {
+                    rs.close();
+                } catch (SQLException sqle) {
+                    System.out.println("获取所有列,关闭结果集异常");
+                }
+            }
+            if (ps != null) {
+                try {
+                    ps.close();
+                } catch (SQLException sqle) {
+                    System.out.println("获取所有列,关闭预编译异常");
+                }
+            }
+            if (connection != null) {
+                try {
+                    connection.close();
+                } catch (SQLException sqle) {
+                    System.out.println("获取所有列,关闭连接异常");
+                }
+            }
+        }
+    }
+
+    private Map<String, Object> getParameterListByBookTitle(String sql, List<Map<String, Object>> paramsList, String rowCountSQL) {
+        List<Object[]> returnData = new ArrayList<>();
+        Pattern regExpression = Pattern.compile("(?<=《)([^》]+)?(?=》)");
+        Matcher parameterNames = regExpression.matcher(sql);
+        if ((sql.toLowerCase().trim().startsWith("select") || sql.toLowerCase().trim().startsWith("delete")) && paramsList.size() > 1) {
+            Map<String, Object> temMap = paramsList.get(0);
+            paramsList = new ArrayList<>() {
+                {
+                    add(temMap);
+                }
+            };
+        }
+        List<Object> signList = new ArrayList<>();
+        List<String> columnName = new ArrayList<>();
+        while (parameterNames.find()) {
+            String colName = parameterNames.group();
+            columnName.add(colName);
+            signList.add(null);
+            sql = sql.replaceFirst("《" + colName + "》", "?"); //
+            if (Objects.nonNull(rowCountSQL)) {
+                rowCountSQL = rowCountSQL.replaceFirst("《" + colName + "》", "?");
+            }
+        }
+
+        for (Map<String, Object> itemMap : paramsList) { // 理论上应该遍历itemMap 去获取对应的值
+            int paramIndex = 0;
+            for (String colName : columnName) {
+                signList.set(paramIndex, getValue(itemMap, colName));
+                paramIndex++;
+            }
+            returnData.add(signList.toArray());
+        }
+
+
+        HashMap<String, Object> objectHashMap = new HashMap<>();
+        objectHashMap.put("value", returnData);
+        objectHashMap.put("rowCountSQL", rowCountSQL);
+        objectHashMap.put("sql", sql);
+        return objectHashMap; // {"sql":{value:[],rowCountSQL:""}} -- {"sql":sql,"value:"",rowCountSQL:""}
+    }
+
+    public Object getValue(Map<?, ?> itemMap, Object itemKey) {
+        if (itemMap.containsKey(itemKey)) return itemMap.get(itemKey);
+        for (Object key : itemMap.keySet()) {
+            Object currentValue = itemMap.get(key);
+            if (currentValue instanceof Map<?, ?> currentMap) {
+                if (currentMap.containsKey("left")) {
+                    Object column = currentMap.get("column");
+                    if (key.equals(column)) {
+                        return currentMap.get("value");
+                    }
+                } else {
+                    return getValue(currentMap, key);
+                }
+            }
+            if (currentValue instanceof List<?> valueList) {
+                for (Object value : valueList) {
+                    if (value instanceof Map<?, ?> valueMap) {
+                        Object va = getValue(valueMap, key);
+                        if (Objects.nonNull(va)) {
+                            return va;
+                        }
+                    } else {
+                        break;
+                    }
+                }
+
+            }
+        }
+        return null;
+    }
+
+    /***
+     * 查询数据库条数
+     * @return
+     */
+    public Map<String, String> queryForObject(String sql, Object... params) {
+        try {
+            Integer count = theJdbcTemplate.queryForObject(sql, Integer.class, params);
+            HashMap<String, String> tempMap = new HashMap<>();
+            tempMap.put("code", "0");
+            tempMap.put("returnData", count + "");
+            return tempMap;
+        } catch (Exception e) {
+            HashMap<String, String> tempMap = new HashMap<>();
+            tempMap.put("code", "-1");
+            tempMap.put("message", "查询条数 执行异常: " + LogUtils.getException(e));
+            return tempMap;
+        }
+    }
+
+    /***
+     * jdbcTemplate 插入数据后返回,主键的值
+     * @param sql  sql语句
+     * @param params sql参数
+     * @return 插入的主键ID
+     */
+    public Map<String, Object> insertReturnKeyValues(String sql, Object... params) {
+        try {
+            KeyHolder holder = new GeneratedKeyHolder();
+            theJdbcTemplate.update(connection -> {
+                PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
+                for (Object param : params) {
+                    ps.setObject(1, param);
+                }
+                return ps;
+            }, holder);
+            HashMap<String, Object> tempMap = new HashMap<>();
+            tempMap.put("code", "0");
+            tempMap.put("returnData", Objects.requireNonNull(holder.getKey()).intValue());
+            return tempMap;
+        } catch (Exception e) {
+            HashMap<String, Object> tempMap = new HashMap<>();
+            tempMap.put("code", "-1");
+            tempMap.put("message", LogUtils.getException(e));
+            return tempMap;
+        }
+    }
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public String getConnectConfig() {
+        return connectConfig;
+    }
+
+    public HikariDataSource getTheDataSource() {
+        return theDataSource;
+    }
+
+    public JdbcTemplate getTheJdbcTemplate() {
+        return theJdbcTemplate;
+    }
+
+}

+ 164 - 0
mainFactory/src/main/java/org/bfkj/utils/RandomGraphic.java

@@ -0,0 +1,164 @@
+package org.bfkj.utils;
+
+import org.apache.tomcat.util.codec.binary.Base64;
+
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 图片工具类
+ */
+public class RandomGraphic {
+
+    private static SecureRandom random = null;
+
+    static {
+        try {
+            random = SecureRandom.getInstance("SHA1PRNG");
+        } catch (NoSuchAlgorithmException e) {
+        }
+    }
+    /**
+     * 使用指定源生成验证码
+     *
+     * @param verifySize 验证码长度
+     * @param sources    验证码字符源
+     */
+
+    public static Map<String, Object> generateVerifyCode(int verifySize, String sources) {
+        int codesLen = sources.length();
+
+        try {
+            StringBuilder verifyCode = new StringBuilder(verifySize);
+            for (int i = 0; i < verifySize; i++) {
+                verifyCode.append(sources.charAt(random.nextInt(codesLen - 1)));
+            }
+            Map<String, Object> returnData = new HashMap<>();
+            returnData.put("verifyCode", verifyCode.toString());
+            returnData.put("verifyCodeImage", outputImage(116, 40, verifyCode.toString()));
+            return returnData;
+        } catch (IOException e) {
+            return null;
+        }
+    }
+
+    /**
+     * 输出指定验证码图片流
+     */
+    public static String outputImage(int w, int h, String code) throws IOException {
+        int verifySize = code.length();
+        BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
+        Graphics2D g2 = image.createGraphics();
+        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        Color[] colors = new Color[5];
+        Color[] colorSpaces = new Color[]{Color.WHITE, Color.CYAN, Color.GRAY, Color.LIGHT_GRAY, Color.MAGENTA, Color.ORANGE, Color.PINK, Color.YELLOW};
+        float[] fractions = new float[colors.length];
+        for (int i = 0; i < colors.length; i++) {
+            colors[i] = colorSpaces[random.nextInt(colorSpaces.length)];
+            fractions[i] = random.nextFloat();
+        }
+        Arrays.sort(fractions);
+        Color c = getRandColor(200, 250);
+        g2.setColor(c);// 设置背景色
+        g2.fillRect(0, 2, w, h - 4);
+        // 绘制干扰线
+        g2.setColor(getRandColor(160, 200));// 设置线条的颜色
+        for (int i = 0; i < 20; i++) {
+            int x = random.nextInt(w - 1);
+            int y = random.nextInt(h - 1);
+            int xl = random.nextInt(6) + 1;
+            int yl = random.nextInt(12) + 1;
+            g2.drawLine(x, y, x + xl + 40, y + yl + 20);
+        }
+        // 添加噪点
+        float yawpRate = 0.05f;// 噪声率
+        int area = (int) (yawpRate * w * h);
+        for (int i = 0; i < area; i++) {
+            int x = random.nextInt(w);
+            int y = random.nextInt(h);
+            int rgb = getRandomIntColor();
+            image.setRGB(x, y, rgb);
+        }
+        shear(g2, w, h, c);// 使图片扭曲
+        g2.setColor(getRandColor(100, 160));
+        int fontSize = h - 4;
+        Font font = new Font("Algerian", Font.ITALIC, fontSize);
+        g2.setFont(font);
+        char[] chars = code.toCharArray();
+        for (int i = 0; i < verifySize; i++) {
+            AffineTransform affine = new AffineTransform();
+            affine.setToRotation(Math.PI / 4 * random.nextDouble() * (random.nextBoolean() ? 1 : -1), (w / verifySize) * i + fontSize / 2, h / 2);
+            g2.setTransform(affine);
+            g2.drawChars(chars, i, 1, ((w - 10) / verifySize) * i + 5, h / 2 + fontSize / 2 - 10);
+        }
+        g2.dispose();
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ImageIO.write(image, "GIF", out);
+        byte[] b = out.toByteArray();
+        return Base64.encodeBase64String(b).replaceAll("[\\s*\t\n\r]", "");
+    }
+
+    private static Color getRandColor(int fc, int bc) {
+        int r = fc + random.nextInt(bc - fc);
+        int g = fc + random.nextInt(bc - fc);
+        int b = fc + random.nextInt(bc - fc);
+        return new Color(r, g, b);
+    }
+
+    private static int getRandomIntColor() {
+        int[] rgb = getRandomRgb();
+        int color = 0;
+        for (int c : rgb) {
+            color = color << 8;
+            color = color | c;
+        }
+        return color;
+    }
+
+    private static int[] getRandomRgb() {
+        int[] rgb = new int[3];
+        for (int i = 0; i < 3; i++) {
+            rgb[i] = random.nextInt(255);
+        }
+        return rgb;
+    }
+
+    private static void shear(Graphics g, int w1, int h1, Color color) {
+        shearX(g, w1, h1, color);
+        shearY(g, w1, h1, color);
+    }
+
+    private static void shearX(Graphics g, int w1, int h1, Color color) {
+        int frames = 1;
+        int phase = random.nextInt(2);
+        for (int i = 0; i < h1; i++) {
+            double d = (6.2831853071795862D * (double) phase) / (double) frames;
+            g.copyArea(0, i, w1, 1, (int) d, 0);
+            g.setColor(color);
+            g.drawLine((int) d, i, 0, i);
+            g.drawLine((int) d + w1, i, w1, i);
+        }
+    }
+
+    private static void shearY(Graphics g, int w1, int h1, Color color) {
+        int period = random.nextInt(40) + 10; // 50;
+        int frames = 20;
+        int phase = 7;
+        for (int i = 0; i < w1; i++) {
+            double d = (double) (period >> 1) * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);
+            g.copyArea(i, 0, 1, h1, 0, (int) d);
+            g.setColor(color);
+            g.drawLine(i, (int) d, i, 0);
+            g.drawLine(i, (int) d + h1, i, h1);
+        }
+    }
+}

+ 65 - 0
mainFactory/src/main/java/org/bfkj/utils/ScheduleTask.java

@@ -0,0 +1,65 @@
+package org.bfkj.utils;
+
+import org.bfkj.application.DataProcess;
+import org.bfkj.application.ServiceInputControl;
+import org.bfkj.config.AppConfig;
+import org.bfkj.config.ObjectMap;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Objects;
+
+public class ScheduleTask implements Runnable {
+    private String id; // 服务ID
+
+    public String getId() {
+        return id;
+    }
+
+    Integer loopCount;
+    int count = 0;
+    public Date taskValid;
+    public Date taskInvalid;
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    /**
+     * @param id 任务ID
+     */
+    public ScheduleTask(String id, Integer loopCount, Date taskValid, Date taskInvalid) {
+        this.id = id;
+        this.loopCount = loopCount;
+        this.taskValid = taskValid;
+        this.taskInvalid = taskInvalid;
+
+    }
+
+    @Override
+    public void run() {
+        if (Objects.nonNull(taskInvalid) && taskInvalid.before(new Date())) {
+            ServiceInputControl.stop(id);
+            return;
+        }
+        if (Objects.isNull(taskValid) || taskValid.after(new Date())) {
+            if ((Objects.isNull(loopCount) || count < loopCount)) {
+                count++;
+                DataProcess dataProcess = ObjectMap.getordropInput(id);
+                if (Objects.isNull(dataProcess) || Objects.nonNull(dataProcess.getErrorMessage())) {
+                    LogUtils.log("run: 1", "-1",  null,"启动服务失败,获取采集对象异常:" + (Objects.isNull(dataProcess) ? "" : dataProcess.getErrorMessage()), id, AppConfig.WORK_ID, "服务编号:" + id, null,null,null);//无条件记录数据接收日志
+                }
+                dataProcess.processData(new HashMap<String, Object>() {{
+                    put("dataContent", "1");
+                    put("event", "1");
+                }});
+
+            } else {
+                ServiceInputControl.stop(id);
+            }
+        }
+    }
+
+    public void setLoopCount(Integer loopCount) {
+        this.loopCount = loopCount;
+    }
+}

+ 66 - 0
mainFactory/src/main/java/org/bfkj/utils/ScheduleUtil.java

@@ -0,0 +1,66 @@
+package org.bfkj.utils;
+
+import org.bfkj.config.AppConfig;
+import org.bfkj.config.ObjectMap;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+import org.springframework.scheduling.support.CronTrigger;
+
+import java.util.*;
+import java.util.concurrent.ScheduledFuture;
+
+/**
+ * 定时任务工具类
+ *
+ * @author zhongxiaojian
+ * @date 2020/4/17
+ **/
+public class ScheduleUtil {
+    private static ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
+
+    private static Map<String, ScheduledFuture<?>> scheduledFutureMap = new HashMap<>();
+
+    static {
+        threadPoolTaskScheduler.initialize();
+        System.out.println("定时任务线程池启动");
+    }
+
+    /**
+     * 启动
+     *
+     * @param scheduleTask 定时任务
+     */
+    public static boolean start(ScheduleTask scheduleTask, int cycleFrequency, Object cronExpress, int taskType) {
+        System.out.println("启动定时任务线程 taskId " + scheduleTask.getId());// 设置时间比当前时间晚了
+        ScheduledFuture<?> scheduledFuture = null;
+        if (taskType == 1) {
+            scheduledFuture = threadPoolTaskScheduler.scheduleWithFixedDelay(scheduleTask, new Date(), cycleFrequency);
+        } else {
+            if (Objects.isNull(cronExpress)) {
+                LogUtils.log("ScheduleUtil: 2", "0",  null,"定时任务表达式为空", scheduleTask.getId(), AppConfig.WORK_ID, null, null,"定时任务表达式为空",null);//无条件记录数据接收日志
+                return false;
+            }
+            scheduledFuture = threadPoolTaskScheduler.schedule(scheduleTask, new CronTrigger(cronExpress.toString()));
+        }
+        scheduledFutureMap.put(scheduleTask.getId(), scheduledFuture);
+        return true;
+    }
+
+    /**
+     * 取消
+     *
+     * @param scheduleTask 定时任务
+     */
+    public static boolean cancel(ScheduleTask scheduleTask) {
+        System.out.println("关闭定时任务线程 taskId " + scheduleTask.getId());
+        String serviceId = scheduleTask.getId();
+        ScheduledFuture<?> scheduledFuture = scheduledFutureMap.get(serviceId);
+        if (scheduledFuture != null && !scheduledFuture.isCancelled()) {
+            scheduledFuture.cancel(false);
+        }
+        scheduledFutureMap.remove(serviceId);
+        //根据服务ID获取所有算法,进行统一关闭
+        ObjectMap.getordropInput(serviceId,false);
+        return true;
+    }
+}
+

+ 386 - 0
mainFactory/src/main/java/org/bfkj/utils/ScriptEnginePro.java

@@ -0,0 +1,386 @@
+package org.bfkj.utils;
+
+import org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory;
+import org.openjdk.nashorn.api.scripting.ScriptObjectMirror;
+
+import javax.script.*;
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class ScriptEnginePro {
+    private final Map<Long, Bindings> bindingMap = new HashMap<>(50); //JS执行绑定参数Map
+    private long lastActive; //服务最后活跃时间
+    private String errorMessage = null; //初始化时,对象异常信息
+
+    /*java变量*/ Method javaMethod; //java执行函数
+    Method javaMethodClose; //java执行函数
+    Object classInstance;//java执行实例
+
+    /*JS变量*/
+    private ScriptEngine scriptEngine; //脚本执行引擎
+    private CompiledScript scriptCompile;//脚本编译
+
+
+    private final Object library_id; //算法ID
+    private final Object library_type; //算法类型: // 1. java 2. js 脚本 3. 数据库  4. webapi
+    private String computing_expression; //脚本: 1. java输出执行名称 2.JS脚本 3.sql语句 4.空
+
+    Map<String, Object> parmaNames = new HashMap<>();
+    List<Object> javaParams = new ArrayList<>();
+    Map<String, Object> jsParams = new HashMap<>();
+    private Map<String, Object> calculationLibrary;
+
+    private long threadId = Thread.currentThread().getId();//当前引擎线程编号
+
+
+    /**
+     * 引擎构造函数
+     *
+     * @param calculationLibrary 算法
+     */
+    public ScriptEnginePro(Map<String, Object> calculationLibrary) {
+        lastActive = System.currentTimeMillis();
+
+        this.calculationLibrary = calculationLibrary;
+        library_id = calculationLibrary.get("library_id");
+        library_type = calculationLibrary.get("library_type");
+        //通过数据源ID 获取到对应的信息
+        computing_expression = Objects.isNull(calculationLibrary.get("computing_expression")) ? "" : calculationLibrary.get("computing_expression").toString();
+        //初始化java执行对象
+        if (library_type.equals(1)) {
+            initJava(calculationLibrary.get("filePath"), calculationLibrary.get("className"));
+        }
+        //初始化脚本执行对象
+        if (library_type.equals(2)) { // 1. java时记录方法名 (缺 目标对象字段) 2. js时 记录脚本(后期可以运用数据源中的文件名在加载js文件,此时脚本为方法名) 3. 数据库(缺目标对象:表名) 4. webapi时脚本记录方法名
+            ScriptEngineManager m = new ScriptEngineManager();
+            NashornScriptEngineFactory factory = null;
+            for (ScriptEngineFactory f : m.getEngineFactories()) {
+                if ("OpenJDK Nashorn".equalsIgnoreCase(f.getEngineName())) {
+                    factory = (NashornScriptEngineFactory) f;
+                    break;
+                }
+            }
+            String[] stringArray = new String[]{"--no-java", "--global-per-engine"};  //引擎加速:--global-per-engine ,安全:--no-java
+            assert factory != null;
+            scriptEngine = factory.getScriptEngine(stringArray);
+            try {
+                initParam(computing_expression, 2);
+                scriptCompile = ((Compilable) scriptEngine).compile(computing_expression);
+            } catch (ScriptException e) {
+                errorMessage = "JS脚本预编译时出现错误" + LogUtils.getException(e);
+            }
+        }
+    }
+
+    public void close() {
+        //如果算法的类型是数据库 则获取jdbctempalte进行关闭;如果是其他协议则 直接调用invoke方法进行关闭
+        if (Objects.nonNull(javaMethodClose)) {
+            try {
+                javaMethodClose.invoke(classInstance);
+            } catch (IllegalAccessException | InvocationTargetException e) {
+                System.out.println("JAVA反射关闭方法调用失败: " + classInstance + "释放资源失败");
+            }
+        }
+        if (Objects.nonNull(scriptCompile)) { //针对JS
+            scriptCompile = null;
+        }
+    }
+
+    //统一成功信息处理
+    public Map<String, Object> processSuccess(Object returnData) {
+        if (returnData instanceof Map) {
+            Map<String, Object> returnData1 = (Map<String, Object>) returnData;
+            returnData1.put("code", "0");
+            return returnData1;
+        }
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "0");
+        returnMap.put("returnData", returnData);
+        return returnMap;
+    }
+
+    //统一错误信息处理
+    public Map<String, Object> processFail(String errorMessage) {
+        Map<String, Object> returnMap = new HashMap<>();//用于当前方法统一返回参数,不存在深拷贝问题
+        returnMap.put("code", "-1");
+        returnMap.put("message", errorMessage);
+        returnMap.put("library_id", library_id);
+        return returnMap;
+    }
+
+    /**
+     * 初始化JAVA执行对象
+     */
+    private void initJava(Object filePath, Object className) {
+        if (Objects.isNull(className) || Objects.isNull(computing_expression)) {
+            errorMessage = "java执行参数不全,类名:" + className + "; 方法名:" + computing_expression;
+            return;
+        }
+
+        if (Objects.nonNull(filePath)) {//加载外部JAR
+            File file = new File(System.getProperty("user.dir") + File.separator + "plugins" + File.separator + filePath);
+            if (!file.exists()) {
+                errorMessage = "外部文件加载不存在: " + System.getProperty("user.dir") + File.separator + "plugins" + File.separator + filePath;
+                return;
+            }
+            // 从URLClassLoader类中获取类所在文件夹的方法,jar也可以认为是一个文件夹
+            Method addURLMethod = null;
+            boolean accessible = false;
+            try {
+                addURLMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
+                URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
+                //获取方法的访问权限以便写回
+                accessible = addURLMethod.canAccess(null); //判读是否可以访问: true  代表可以访问
+                if (!accessible) { //判读是否可以访问,如果是false,那就必须setAccessible(true)
+                    addURLMethod.setAccessible(true);
+                }
+                // 获取系统类加载器
+                addURLMethod.invoke(classLoader, file.toURI().toURL());
+            } catch (Exception e) {
+                errorMessage = "JAR加载到环境失败" + LogUtils.getException(e);
+                return;
+            } finally {
+                if (addURLMethod != null && !accessible) {
+                    addURLMethod.setAccessible(false);
+                }
+            }
+        }
+        try {
+            initParam(computing_expression, 1); //初始化JAVA执行参数,只处理参数名,避免编译失败
+            Class<?> classExample = Class.forName(className.toString()); //
+            classInstance = classExample.getConstructor().newInstance();//类实例接口 无参数构造
+            Method[] methods = classExample.getMethods();
+            for (Method currentMethod : methods) {
+                String methodName = currentMethod.getName();
+                if (methodName.equals(computing_expression.substring(0, computing_expression.indexOf("(")))) {
+                    javaMethod = currentMethod;
+                }
+                if (methodName.equals("close")) {
+                    javaMethodClose = currentMethod;
+                }
+            }
+        } catch (Exception e) {
+            errorMessage = "方法编译异常:" + LogUtils.getException(e);
+        }
+    }
+
+    private void initParam(String computing_expression, int scriptType) {
+        Pattern regExpression = Pattern.compile("(?<=《)([^》]+)?(?=》)");
+        Matcher parameterNames = regExpression.matcher(computing_expression); //提取书名号中的参数名
+        int index = 0; //用于记录JAVA参数对应实际运行参数的位置
+        while (parameterNames.find()) {
+            String groupKey = parameterNames.group();// String.dataContent
+            parmaNames.put(groupKey, scriptType == 1 ? index++ : (groupKey.replaceAll("\\.", "")) + threadId);
+            if (scriptType == 1) {  // java参数
+                javaParams.add(null);//先初始化一个JAVA参数
+            } else {
+                jsParams.put((groupKey.replaceAll("\\.", "")) + Thread.currentThread().getId(), null);
+            }
+            computing_expression = computing_expression.replaceFirst("《" + groupKey + "》", scriptType == 1 ? "" : parmaNames.get(groupKey).toString());
+        }
+        this.computing_expression = computing_expression;
+    }
+
+
+    /**
+     * 引擎执行入口函数
+     *
+     * @param data 数据内容
+     * @return 执行后结果
+     */
+    public Map<String, Object> execScript(List<Map<String, Object>> data) {
+        lastActive = System.currentTimeMillis();
+        if (null != errorMessage) {
+            return processFail(errorMessage);
+        }
+        getParams(data); //实例化参数
+        // 1. java时记录方法名 (缺目标对象字段) 2. js时 记录脚本(后期可以运用数据源中的文件名在加载js文件,此时脚本为方法名) 3. 数据库(缺目标对象:表名) 4. webapi时脚本记录方法名
+        if (Objects.equals(library_type, 1)) {
+            try {
+                // javaMethod.invoke(classInstance, javaParams.toArray()) --- Map:{code,returnData}
+                return processSuccess(javaMethod.invoke(classInstance, javaParams.toArray()));//数组方式传参,无需参数名,按顺序对应
+            } catch (Exception e) {
+                return processFail("JAVA执行失败,执行参数:" + javaParams.toString() + ";异常信息:" + LogUtils.getException(e));
+            }
+        }
+        if (Objects.equals(library_type, 2)) {
+            Bindings bindings = bindingMap.computeIfAbsent(threadId, k -> scriptEngine.createBindings());
+            bindings.putAll(jsParams);//JS的参数是MAP,需要参数名对应
+            try {
+                Object jsReturnData = scriptCompile.eval(bindings);
+                if (jsReturnData instanceof ScriptObjectMirror) {
+                    ScriptObjectMirror scriptObjec = (ScriptObjectMirror) jsReturnData;
+                    recursionEencapsulation(scriptObjec); // List<Map<String,Object>   // {0:{},1:{}}   [{},{},{}]
+                    if (scriptObjec.isArray()) {// -- >  [{},{},{}]  []
+                        List<Object> tempList = new ArrayList<>();
+                        scriptObjec.forEach((index, o) -> tempList.add(o));
+                        jsReturnData = tempList;
+                    }
+                }
+                return processSuccess(jsReturnData);
+            } catch (ScriptException e) {
+                return processFail("JS执行失败,执行参数:" + jsParams.toString() + ";异常信息:" + LogUtils.getException(e));
+            }
+        }
+        return processFail("未支持的算法类型:" + calculationLibrary.toString());
+    }
+
+    private void getParams(List<Map<String, Object>> calculationResult) {
+        for (String paramName : parmaNames.keySet()) {    //  key: //String.1.dataContent.name   --   [{"code","message","dataContent":[]}}]
+            String[] param = paramName.split("\\.");
+            Object returnData = calculationResult; // {"code":"0","returnData":"JOSN"}
+            String dataType = param.length > 0 ? param[0] : null; //Map.L
+            String dataLocation = param.length > 1 ? param[1] : "";
+            if (dataLocation.equals("L")) {//类变量参数
+                returnData = param.length > 2 ? calculationLibrary.get(param[2]) : calculationLibrary;
+            }
+            if (dataLocation.equals("T")) {//固定参数 //JSON.T.{"BSM":""},
+                returnData = param.length > 2 ? param[2] : null;
+            }
+            if (MapTools.isNumber(dataLocation)) {//全量参数中取值
+                if (returnData instanceof List) {//如果是数组则取对应序号的值  ["abc"]
+                    returnData = ((List<?>) returnData).get(Integer.parseInt(dataLocation));  // {"code","message","dataContent":[]}}
+                }
+                for (int index = 2; index < param.length; index++) {   // todo  占时 不支持 String.1.dataContent.name
+                    if (MapTools.isNumber(param[index]) && returnData instanceof List) {
+                        returnData = ((List<?>) returnData).get(Integer.parseInt(param[index]));
+                    } else {
+                        if (!MapTools.isNumber(param[index])) {
+                            if (returnData instanceof Map) {
+                                returnData = ((Map<?, ?>) returnData).get(param[index]);
+                            } else {
+                                if (returnData instanceof String) {
+                                    String tempDataStr = returnData.toString().trim();
+                                    if ((tempDataStr.indexOf("[") == 0 && tempDataStr.lastIndexOf("]") == tempDataStr.length() - 1)) {
+                                        tempDataStr = tempDataStr.substring(1, tempDataStr.length() - 2);
+                                    }
+                                    returnData = MapTools.jsonStringToMap(tempDataStr);
+                                    if (Objects.nonNull(returnData)) {
+                                        returnData = ((Map) returnData).get(param[index]);   // dataContent:"<xml>……"
+                                    }
+                                }
+                            }
+
+                        } else {
+                            if (!dataLocation.equals("L") && !dataLocation.equals("T")) {
+                                returnData = null;//不符合参数订阅格式或者不符合实际参数
+                                break;//停止当前循环
+                            }
+                        }
+                    }
+                }
+            }
+
+            if (Objects.nonNull(returnData)) {//订阅类型转换
+                if (Objects.equals(dataType, "String")) {
+                    returnData = MapTools.jacksonObjToStr(returnData);
+                } else if (Objects.equals(dataType, "List")) {
+                    if (!(returnData instanceof List)) {
+                        ArrayList<Object> objects = new ArrayList<>();
+                        objects.add(returnData);
+                        returnData = objects;
+                    }
+                } else if (Objects.equals(dataType, "Map")) {
+                    if (returnData instanceof String) {
+                        returnData = MapTools.jsonStringToMap(returnData.toString());
+                    }
+                } else if (Objects.equals(dataType, "JSON")) {
+                    if (returnData instanceof String) {
+                        returnData = MapTools.jsonStringToJSON(returnData.toString());
+                    }else {
+                        returnData = MapTools.mapToJSONString(returnData);
+                    }
+                } else if (Objects.equals(dataType, "Boolean")) {
+                    if (returnData instanceof String) {
+                        returnData = returnData.equals("true") || returnData.equals("0");
+                    }
+                } else if (Objects.equals(dataType, "Integer")) {
+                    if (returnData instanceof String) {
+                        returnData = Integer.parseInt(returnData.toString());
+                    }
+                }
+            }
+            if (library_type.toString().equals("1")) { //java
+                javaParams.set(Integer.parseInt(parmaNames.get(paramName).toString()), returnData);
+            } else {
+                jsParams.put(parmaNames.get(paramName).toString(), returnData);  //
+            }
+        }
+    }
+
+    /**
+     * 脚本执行结果函数:   { 0:map<String,Object> ,1:map<String,Object} == > [map{},map{}]
+     *
+     * @param scriptObject 脚本执行结果
+     */
+    public void recursionEencapsulation(ScriptObjectMirror scriptObject) {
+        for (String key : scriptObject.keySet()) { // scriptObject 实际是Map 循环map的所有key--- > {"A","B"}
+            Object mirror = scriptObject.get(key); // 获取当前可以的值mirror "B"
+            if (mirror instanceof ScriptObjectMirror) {// 如果当前值是map
+                recursionEencapsulation((ScriptObjectMirror) mirror); // 继续下一层
+                Boolean isArray = isArray((ScriptObjectMirror) mirror); // 如果当前值是一个数组则 转换成List<Map<String,Object>>
+                if (isArray) {
+                    List<Object> list = parseArray((ScriptObjectMirror) mirror);
+                    scriptObject.put(key, list);
+                }
+            }
+        }
+    }
+
+
+    /**
+     * 数组判定
+     *
+     * @param scriptObject 数据内容
+     * @return true、false
+     */
+    public Boolean isArray(ScriptObjectMirror scriptObject) {
+        boolean isArray = true;
+        int index = 0;
+        for (String key : scriptObject.keySet()) {
+            if (!key.equals(index + "")) {
+                isArray = false;
+            }
+            index++;
+        }
+        return isArray;
+    }
+
+
+    /**
+     * 对象转数组
+     *
+     * @param scriptObject 对象
+     * @return list数组
+     */
+    public List<Object> parseArray(ScriptObjectMirror scriptObject) {
+        List<Object> arrayList = new ArrayList<Object>();
+        for (String key : scriptObject.keySet()) {
+            Object obj = scriptObject.get(key);
+            arrayList.add(obj);
+        }
+        return arrayList;
+    }
+
+    public long getLastActive() {
+        return lastActive;
+    }
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public Method getMethodClose() {
+        return javaMethodClose;
+    }
+
+    public Object getLibrary_id() {
+        return library_id;
+    }
+}

+ 24 - 0
mainFactory/src/main/resources/application.yml

@@ -0,0 +1,24 @@
+server:
+  port: 8082
+  servlet:
+    encoding:
+      charset: UTF-8
+      force: true
+      enabled: true
+  codec:
+    max-in-memory-size: -1
+  application:
+    name: mainFactory
+spring:
+  mvc:
+    view:
+      prefix: /
+      suffix: .html
+service:
+  pool:
+    maxPoolSize: 512
+    corePoolSize: 6
+    queueCapacity: 1024
+    keepAliveSeconds: 60
+    threadNamePrefix: logthreadpool
+    waitForTasksToCompleteOnShutdown: true

BIN
mainFactory/src/main/resources/lib/com.ibmq.mq-6.jar


+ 15 - 0
mainFactory/src/main/resources/static/config.js

@@ -0,0 +1,15 @@
+window.SERVICE_ID = {
+  sysMenuId: 1, //权限菜单
+  sysAuthId: 2, //根据用户ID或用户组ID获取权限
+  sysAllMenuId: 3, //获取全部权限
+  getUserTableId: 9, //根据账号组获取账号
+  getJqId: 10023, //获取机器维护列表
+  getTableColumnId: 18122, //获取表头
+  authTreeId: 18126, //获取表头
+  roleListId: 10024,//角色列表
+  userListId: 10026,//用户管理列表
+  userAuthorizationId: 10027,//用户授权
+  depTableId: 185, //机器维护-表头
+  serTableId: 203, //服务设置-表头
+  serTableDataId: 4 //服务设置-算法配置-获取数据源名称
+};

BIN
mainFactory/src/main/resources/static/favicon.ico


+ 1 - 0
mainFactory/src/main/resources/static/index.html

@@ -0,0 +1 @@
+<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><meta http-equiv=Content-Security-Policy content="script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline'"><meta http-equiv=X-XSS-Protection content="1;mode=block"><meta http-equiv=X-Content-Type-Options content=nosniff><link rel=icon href=favicon.ico><title>Vue3 Admin Ts</title><script src=staticConfig.js></script><script id=configJS src=config.js></script><link href=static/css/app.4628f8d7.css rel=preload as=style><link href=static/css/chunk-elementUI.0ae24586.css rel=preload as=style><link href=static/css/chunk-libs.bef63a38.css rel=preload as=style><link href=static/js/app.54e1bfd1.js rel=preload as=script><link href=static/js/chunk-elementUI.e94dd283.js rel=preload as=script><link href=static/js/chunk-libs.a2c2ce44.js rel=preload as=script><link href=static/css/chunk-elementUI.0ae24586.css rel=stylesheet><link href=static/css/chunk-libs.bef63a38.css rel=stylesheet><link href=static/css/app.4628f8d7.css rel=stylesheet></head><body><div id=app></div><script src=static/js/runtime.17699563.js></script><script src=static/js/chunk-elementUI.e94dd283.js></script><script src=static/js/chunk-libs.a2c2ce44.js></script><script src=static/js/app.54e1bfd1.js></script></body></html>

File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/app.4628f8d7.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-00ca601f.fadbb86b.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-01740904.8eda0487.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-017af434.ac2b8daf.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-1d27e940.72a24f8e.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-2220f2ce.fadbb86b.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-2c5075f5.fadbb86b.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-3645cbb5.409d8a87.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-37b16d4a.69407d23.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-3a1d70dc.bf9274df.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-3b7c86d1.f971f60b.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-3dce7178.ac2b8daf.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-5641bdaa.19212608.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-5b6acc49.e73dc104.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-62b675ea.17a7dbcc.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-630b03b1.a0ebb076.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-6b7d854b.ac2b8daf.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-7236b413.ffc6d0f5.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-7337dfab.aff7e86c.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-7f7c5d76.f6d9060d.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-9baba730.fadbb86b.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-a4f67028.cfe22c71.css


+ 1 - 0
mainFactory/src/main/resources/static/static/css/chunk-a6d352ac.04a0cbbd.css

@@ -0,0 +1 @@
+.filter-arrow[data-v-67fdfc79]{cursor:pointer;-webkit-transition:transform .3s;transition:transform .3s}.filter-arrow.arrow-expand[data-v-67fdfc79]{-webkit-transform:rotate(-180deg);transform:rotate(-180deg)}.filter-arrow.arrow-active[data-v-67fdfc79]{color:#2d7cff;font-weight:700}.btn-filter[data-v-67fdfc79]{cursor:pointer;position:relative}.btn-filter[data-v-67fdfc79]:hover{color:#2d7cff}.btn-filter[data-v-67fdfc79]:after{content:"";display:block;width:calc(100% + 4px);position:absolute;bottom:-4px;left:-2px;border-bottom:1px solid #101116}.btn-filter.btn-filter-active[data-v-67fdfc79]:after,.btn-filter[data-v-67fdfc79]:hover:after{border-bottom:2px solid #2d7cff}.el-select-dropdown__item.hover[data-v-67fdfc79]{background:#d2d6df}

File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-elementUI.0ae24586.css


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/css/chunk-libs.bef63a38.css


BIN
mainFactory/src/main/resources/static/static/fonts/element-icons.535877f5.woff


BIN
mainFactory/src/main/resources/static/static/fonts/element-icons.732389de.ttf


BIN
mainFactory/src/main/resources/static/static/img/bg.7776f3f6.jpg


BIN
mainFactory/src/main/resources/static/static/img/nodata.22b989c0.png


BIN
mainFactory/src/main/resources/static/static/img/nopage.0e91ade0.png


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/app.54e1bfd1.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-00ca601f.ab1768b1.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-01740904.b5dcb857.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-017af434.8555ead8.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-1d27e940.71834f58.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-1fde9e50.1b3d5d33.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-2220f2ce.8e3c01d5.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-23e78f69.b6459a85.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-2c5075f5.ef5832ac.js


+ 1 - 0
mainFactory/src/main/resources/static/static/js/chunk-2d0aef25.a03a6613.js

@@ -0,0 +1 @@
+(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d0aef25"],{"0bda":function(e,n,a){"use strict";a.r(n);var t=function(){var e=this,n=e.$createElement,a=e._self._c||n;return a("router-view")},u=[],r={name:"BaggageManagement"},c=r,l=a("2877"),o=Object(l["a"])(c,t,u,!1,null,null,null);n["default"]=o.exports}}]);

+ 1 - 0
mainFactory/src/main/resources/static/static/js/chunk-2d0af82b.fd27a898.js

@@ -0,0 +1 @@
+(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d0af82b"],{"0f43":function(e,n,t){"use strict";t.r(n);var l=function(){var e=this,n=e.$createElement,t=e._self._c||n;return t("FlightView")},a=[],i=t("92ca"),u={name:"DepartureFlightView",components:{FlightView:i["default"]}},c=u,r=t("2877"),o=Object(r["a"])(c,l,a,!1,null,null,null);n["default"]=o.exports}}]);

+ 1 - 0
mainFactory/src/main/resources/static/static/js/chunk-2d0c45cd.106e6b47.js

@@ -0,0 +1 @@
+(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d0c45cd"],{"3b08":function(e,n,t){"use strict";t.r(n);var a=function(){var e=this,n=e.$createElement,t=e._self._c||n;return t("router-view")},c=[],u={name:"BaggageManagement"},r=u,l=t("2877"),o=Object(l["a"])(r,a,c,!1,null,null,null);n["default"]=o.exports}}]);

+ 1 - 0
mainFactory/src/main/resources/static/static/js/chunk-2d0c4639.ad90241c.js

@@ -0,0 +1 @@
+(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d0c4639"],{"3b2f":function(e,n,t){"use strict";t.r(n);var l=function(){var e=this,n=e.$createElement,t=e._self._c||n;return t("FlightView")},i=[],c=t("92ca"),a={name:"ArrivalFlightView",components:{FlightView:c["default"]}},u=a,r=t("2877"),o=Object(r["a"])(u,l,i,!1,null,null,null);n["default"]=o.exports}}]);

+ 1 - 0
mainFactory/src/main/resources/static/static/js/chunk-2d0c48c4.9ac6abb6.js

@@ -0,0 +1 @@
+(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d0c48c4"],{"3aff":function(e,n,t){"use strict";t.r(n);var a=function(){var e=this,n=e.$createElement,t=e._self._c||n;return t("FlightView")},c=[],l=t("92ca"),i={name:"TransferDepartureFlightView",components:{FlightView:l["default"]}},r=i,u=t("2877"),s=Object(u["a"])(r,a,c,!1,null,null,null);n["default"]=s.exports}}]);

+ 1 - 0
mainFactory/src/main/resources/static/static/js/chunk-2d208336.ffe15ccf.js

@@ -0,0 +1 @@
+(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d208336"],{a47d:function(e,n,t){"use strict";t.r(n);var l=function(){var e=this,n=e.$createElement,t=e._self._c||n;return t("FlightView")},a=[],i=t("92ca"),r={name:"TransferArrivalFlightView",components:{FlightView:i["default"]}},c=r,u=t("2877"),s=Object(u["a"])(c,l,a,!1,null,null,null);n["default"]=s.exports}}]);

+ 1 - 0
mainFactory/src/main/resources/static/static/js/chunk-3645cbb5.face31f8.js

@@ -0,0 +1 @@
+(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-3645cbb5"],{7542:function(t,e,s){"use strict";s("9f06")},"8cdb":function(t,e,s){"use strict";s.r(e);var a=function(){var t=this,e=t.$createElement,s=t._self._c||e;return s("div",{staticClass:"error_404"},[t._m(0),s("el-button",{staticStyle:{"margin-top":"30px"},attrs:{size:"small",type:"primary"}},[s("a",{staticClass:"bullshit__return-home",attrs:{href:""}},[t._v("回到首页")])])],1)},n=[function(){var t=this,e=t.$createElement,a=t._self._c||e;return a("div",{staticClass:"error_404_content"},[a("img",{attrs:{src:s("a32e"),alt:"",srcset:""}})])}],r={name:"Page404",computed:{message:function(){return"The webmaster said that you can not enter this page..."}}},c=r,i=(s("7542"),s("2877")),o=Object(i["a"])(c,a,n,!1,null,"10875152",null);e["default"]=o.exports},"9f06":function(t,e,s){},a32e:function(t,e,s){t.exports=s.p+"static/img/nopage.0e91ade0.png"}}]);

File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-37b16d4a.7dd00c08.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-3a1d70dc.5f067858.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-3b7c86d1.e4d02799.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-3dce7178.3e14af77.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-5641bdaa.7b05fbf7.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-5b6acc49.5128e6a0.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-62b675ea.2ac73ef4.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-630b03b1.60aa85bc.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-6b6701cf.d61edae6.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-6b7d854b.01147e32.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-7236b413.2395adc2.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-7337dfab.8e36cf6b.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-78d31bc0.92a6031f.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-7f7c5d76.4fbc2e6a.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-9baba730.ce84da5c.js


File diff suppressed because it is too large
+ 0 - 0
mainFactory/src/main/resources/static/static/js/chunk-a4f67028.63893475.js


Some files were not shown because too many files changed in this diff