Преглед на файлове

支持多数据源,设备标识序列使用嵌入式数据库

欧阳劲驰 преди 2 седмици
родител
ревизия
afd7a7b949
променени са 35 файла, в които са добавени 590 реда и са изтрити 324 реда
  1. 2 1
      custom-gateway-app/pom.xml
  2. 27 7
      custom-gateway-app/src/main/resources/application.yml
  3. 2 5
      custom-gateway-app/src/test/java/com/shkpr/service/customgateway/CustomGatewayApplicationTests.java
  4. 61 8
      custom-gateway-core/pom.xml
  5. 28 131
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/components/DeviceIdGenerator.java
  6. 53 85
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/DataSourceConfig.java
  7. 5 6
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/DeviceConfig.java
  8. 50 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/JdbcRepositoriesConfig.java
  9. 74 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/MybatisConfig.java
  10. 14 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/constants/DataSourceNames.java
  11. 1 1
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/constants/DeviceKind.java
  12. 25 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/controller/RouteController.java
  13. 35 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/DeviceSequences.java
  14. 5 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/IntegrationKey.java
  15. 35 28
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/PageRequest.java
  16. 1 1
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/mapper/DeviceKindMapper.java
  17. 1 1
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/mapper/TypeDefineMapper.java
  18. 54 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/DataSourceProperties.java
  19. 0 4
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/DeviceProperties.java
  20. 39 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/repository/embedded/DeviceSequencesRepository.java
  21. 1 1
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/service/impl/DeviceKindServiceImpl.java
  22. 1 1
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/service/impl/TypeDefineServiceImpl.java
  23. 2 2
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/utils/CallingUtil.java
  24. 48 0
      custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/HexUtil.java
  25. 1 1
      custom-gateway-core/src/main/resources/mapper/DeviceKindMapper.xml
  26. 1 1
      custom-gateway-core/src/main/resources/mapper/TypeDefineMapper.xml
  27. 0 9
      custom-gateway-zydma/pom.xml
  28. 1 1
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/components/InfoSynchronizer.java
  29. 1 1
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/components/IotCollector.java
  30. 1 1
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/mapper/PersonnelInfoMapper.java
  31. 7 5
      custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/impl/PersonnelInfoServiceImpl.java
  32. 1 1
      custom-gateway-zydma/src/main/resources/mapper/PersonnelInfoMapper.xml
  33. 12 18
      db.yml
  34. 0 3
      dev_seq.json
  35. 1 1
      pom.xml

+ 2 - 1
custom-gateway-app/pom.xml

@@ -77,7 +77,8 @@
                     <systemPropertyVariables>
                         <global.sql-config-path>../db.yml</global.sql-config-path>
                         <device.map-path>../dev_map.yml</device.map-path>
-                        <device.seq-path>../dev_seq.json</device.seq-path>
+                        <spring.datasource.multi.embedded.url>jdbc:h2:file:../data
+                        </spring.datasource.multi.embedded.url>
                     </systemPropertyVariables>
                 </configuration>
             </plugin>

+ 27 - 7
custom-gateway-app/src/main/resources/application.yml

@@ -1,9 +1,18 @@
+#web
+server:
+  port: 9011
+  servlet:
+    context-path: /custom-gw/
 #spring
 spring:
   application:
     name: KprCustomGateway
   profiles:
     active: zydma
+  #thymeleaf
+  thymeleaf:
+    prefix: classpath*:/templates/
+  #任务
   task:
     #任务线程池
     execution:
@@ -19,11 +28,23 @@ spring:
       thread-name-prefix: scheduling-
       pool:
         size: 2
-#web
-server:
-  port: 9011
-  servlet:
-    context-path: /custom-gw/
+  #数据源
+  datasource:
+    hikari:
+      maximum-pool-size: 200
+      minimum-idle: 1
+      connection-test-query: SELECT 1
+      max-lifetime: 120000
+      idle-timeout: 30000
+      connection-timeout: 30000
+      validation-timeout: 30000
+      initialization-fail-timeout: -1
+#mybatis
+mybatis:
+  configuration:
+    call-setters-on-nulls: true
+    map-underscore-to-camel-case: true
+    cache-enabled: false
 #security
 security:
   expiration: P7D
@@ -50,5 +71,4 @@ temp-file:
   max-age: PT4H
 #设备
 device:
-  map-path: ./dev_map.yml
-  seq-path: ./dev_seq.json
+  map-path: ./dev_map.yml

+ 2 - 5
custom-gateway-app/src/test/java/com/shkpr/service/customgateway/CustomGatewayApplicationTests.java

@@ -1,15 +1,12 @@
 package com.shkpr.service.customgateway;
 
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit4.SpringRunner;
 
 /**
  * 测试启动类
  */
-@SpringBootTest
-@RunWith(SpringRunner.class)
+@SpringBootTest(classes = CustomGatewayApplication.class)
 public class CustomGatewayApplicationTests {
 
     @Test

+ 61 - 8
custom-gateway-core/pom.xml

@@ -21,24 +21,26 @@
 
     <!--依赖项-->
     <dependencies>
-        <!--base-->
-        <dependency>
-            <groupId>com.global</groupId>
-            <artifactId>gbase</artifactId>
-            <version>${gbase.version}</version>
-            <scope>system</scope>
-            <systemPath>${project.basedir}/../libs/gbase.${gbase.version}.jar</systemPath>
-        </dependency>
         <!--spring-security-->
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-security</artifactId>
         </dependency>
+        <!--spring-validation-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+        </dependency>
         <!--spring-data-kv-->
         <dependency>
             <groupId>org.springframework.data</groupId>
             <artifactId>spring-data-keyvalue</artifactId>
         </dependency>
+        <!--spring-data-->
+        <dependency>
+            <groupId>org.springframework.data</groupId>
+            <artifactId>spring-data-jdbc</artifactId>
+        </dependency>
         <!--mybatis-->
         <dependency>
             <groupId>org.mybatis.spring.boot</groupId>
@@ -55,6 +57,40 @@
             <groupId>org.influxdb</groupId>
             <artifactId>influxdb-java</artifactId>
         </dependency>
+        <!--h2-->
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+        </dependency>
+        <!--Jackson-->
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.dataformat</groupId>
+            <artifactId>jackson-dataformat-yaml</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.datatype</groupId>
+            <artifactId>jackson-datatype-jsr310</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.datatype</groupId>
+            <artifactId>jackson-datatype-jdk8</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.module</groupId>
+            <artifactId>jackson-module-parameter-names</artifactId>
+        </dependency>
         <!--jjwt-->
         <dependency>
             <groupId>io.jsonwebtoken</groupId>
@@ -72,6 +108,15 @@
             <artifactId>okhttp</artifactId>
             <version>${okhttp.version}</version>
         </dependency>
+        <!--httpclient-->
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>fluent-hc</artifactId>
+        </dependency>
         <!--poi-->
         <dependency>
             <groupId>org.apache.poi</groupId>
@@ -83,6 +128,14 @@
             <artifactId>poi-ooxml</artifactId>
             <version>${poi.version}</version>
         </dependency>
+        <!--base-->
+        <dependency>
+            <groupId>com.global</groupId>
+            <artifactId>gbase</artifactId>
+            <version>${gbase.version}</version>
+            <scope>system</scope>
+            <systemPath>${project.basedir}/../libs/gbase.${gbase.version}.jar</systemPath>
+        </dependency>
     </dependencies>
 
     <!--构建脚本-->

+ 28 - 131
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/components/DeviceIdGenerator.java

@@ -1,53 +1,37 @@
 package com.shkpr.service.customgateway.core.components;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.global.base.log.LogLevelFlag;
-import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.customgateway.core.constants.AreaCode;
 import com.shkpr.service.customgateway.core.constants.DeviceKind;
-import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
 import com.shkpr.service.customgateway.core.domain.Device;
+import com.shkpr.service.customgateway.core.domain.DeviceSequences;
 import com.shkpr.service.customgateway.core.domain.DeviceTag;
+import com.shkpr.service.customgateway.core.repository.embedded.DeviceSequencesRepository;
 import org.apache.commons.lang3.StringUtils;
 
-import java.io.File;
-import java.io.IOException;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
+/**
+ * 设备id生成器
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
 public class DeviceIdGenerator {
     /**
-     * log
-     */
-    private static final String CLASS_NAME = "DeviceIdGenerator";
-    private static final String BIZ_TYPE = LogFlagBusiType.BUSI_ALL.toStrValue();
-    /**
      * 日期格式
      */
     private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMdd");
 
     /**
-     * 对象映射
+     * 序列库
      */
-    private final ObjectMapper objectMapper;
-    /**
-     * 序列文件
-     */
-    private final File sequenceFile;
-    /**
-     * 每日序列
-     */
-    private final Map<LocalDate, Integer> dailySequences;
+    private final DeviceSequencesRepository repository;
 
     public DeviceIdGenerator(Builder builder) {
-        this.objectMapper = builder.objectMapper;
-        this.sequenceFile = builder.sequenceFile;
-        this.dailySequences = new ConcurrentHashMap<>();
-        if (builder.autoLoad) this.loadSequences();
+        this.repository = builder.repository;
     }
 
 
@@ -97,137 +81,50 @@ public class DeviceIdGenerator {
      * @param date 时间
      * @return 序号
      */
-    private int getNextSequence(LocalDate date) {
-        //当前序号
-        int currentSequence = dailySequences.getOrDefault(date, 0);
-        //下一个序号
-        int nextSequence = currentSequence + 1;
-
-        //检查序号是否超出范围
-        if (nextSequence > 9999) throw new IllegalStateException("当日设备序号已用尽,无法生成新的设备ID");
-
-        //存入序号,并同步
-        dailySequences.put(date, nextSequence);
-        syncSequences();
-        return nextSequence;
-    }
-
-    /**
-     * 加载序号数据
-     */
-    private void loadSequences() {
-        try {
-            if (sequenceFile.exists() && sequenceFile.isFile()) {
-                //配置文件存在,读取并设置设备序列
-                dailySequences.putAll(objectMapper.readValue(sequenceFile,
-                        objectMapper.getTypeFactory().constructMapType(Map.class, LocalDate.class, Integer.class)));
-                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, BIZ_TYPE, CLASS_NAME,
-                        "加载设备序号数据成功");
-            } else {
-                //不存在,则同步
-                syncSequences();
-                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, BIZ_TYPE, CLASS_NAME,
-                        "配置文件不存在或为空,初始化空设备列表");
-            }
-        } catch (IOException e) {
-            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_WARN, BIZ_TYPE, CLASS_NAME,
-                    String.format("加载设备序号数据失败,error:%s", e));
+    private synchronized int getNextSequence(LocalDate date) {
+        synchronized (repository) {
+            //自增
+            repository.incrementSeqBYDate(date);
+
+            //获取序号
+            Integer seq = repository.findSeqByDate(date);
+            if (seq == null) seq = repository.save(DeviceSequences.of(null, 1)).getSeq();
+
+            //检查序号是否超出范围
+            if (9999 < seq) throw new IllegalStateException("当日设备序号已用尽,无法生成新的设备ID");
+            return seq;
         }
     }
 
-    /**
-     * 同步序号
-     */
-    private void syncSequences() {
-        try {
-            //确保父目录存在
-            File parentDir = sequenceFile.getParentFile();
-            if (parentDir != null && !parentDir.exists()) {
-                boolean made = sequenceFile.getParentFile().mkdirs();
-                if (made) LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, BIZ_TYPE, CLASS_NAME
-                        , String.format("创建设备序列文件成功:%s", sequenceFile.getAbsoluteFile()));
-            }
-
-            objectMapper.writerWithDefaultPrettyPrinter().writeValue(sequenceFile, dailySequences);
-            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, BIZ_TYPE, CLASS_NAME
-                    , "同步设备序列成功");
-        } catch (IOException e) {
-            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, BIZ_TYPE, CLASS_NAME,
-                    "保存设备序号数据失败,error:" + e.getMessage());
-        }
-    }
 
     /**
      * 构建器
      */
     public static class Builder {
         /**
-         * 映射
-         */
-        private ObjectMapper objectMapper;
-        /**
          * 序列文件
          */
-        private File sequenceFile;
-        /**
-         * 自动加序列置文件
-         */
-        private Boolean autoLoad = true;
+        private DeviceSequencesRepository repository;
+
 
         public Builder() {
-            //默认的mapper
-            this.objectMapper = new ObjectMapper();
         }
 
         /**
          * 配置文件路径
          */
-        public Builder sequenceFile(String sequencePath) {
-            this.sequenceFile = new File(sequencePath);
-            return this;
-        }
-
-        /**
-         * 配置文件对象
-         */
-        public Builder sequenceFile(File sequenceFile) {
-            this.sequenceFile = sequenceFile;
-            return this;
-        }
-
-        /**
-         * object映射
-         */
-        public Builder objectMapper(ObjectMapper objectMapper) {
-            this.objectMapper = objectMapper;
+        public Builder repository(DeviceSequencesRepository repository) {
+            this.repository = repository;
             return this;
         }
 
-        /**
-         * 是否自动加载设备列表
-         */
-        public Builder autoLoad(boolean autoLoad) {
-            this.autoLoad = autoLoad;
-            return this;
-        }
 
         /**
          * 构建
          */
         public DeviceIdGenerator build() {
             // 参数验证
-            if (sequenceFile == null) throw new IllegalStateException("配置文件路径不能为空");
-            if (objectMapper == null) throw new IllegalStateException("Object Mapper 不能为空");
-            if (autoLoad == null) autoLoad = true;
-
-            //文件验证
-            if (sequenceFile.exists()) {
-                if (!sequenceFile.isFile())
-                    throw new IllegalStateException("序列文件路径不是文件: " + sequenceFile.getAbsolutePath());
-                if (!sequenceFile.canRead() || !sequenceFile.canWrite())
-                    throw new IllegalStateException("序列文件无法读写: " + sequenceFile.getAbsolutePath());
-            } else LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, BIZ_TYPE, CLASS_NAME,
-                    "序列文件不存在,将在初始化时创建");
+            if (repository == null) throw new IllegalStateException("存储库不能为空");
 
             return new DeviceIdGenerator(this);
         }

+ 53 - 85
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/DataSourceConfig.java

@@ -1,120 +1,88 @@
 package com.shkpr.service.customgateway.core.config;
 
 import com.shkpr.service.customgateway.core.io.YamlPropertySourceFactory;
+import com.shkpr.service.customgateway.core.properties.DataSourceProperties;
+import com.zaxxer.hikari.HikariConfig;
 import com.zaxxer.hikari.HikariDataSource;
-import org.apache.ibatis.session.SqlSessionFactory;
-import org.mybatis.spring.SqlSessionFactoryBean;
-import org.mybatis.spring.SqlSessionTemplate;
-import org.mybatis.spring.annotation.MapperScan;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.beans.factory.annotation.Value;
+import org.h2.jdbcx.JdbcDataSource;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.boot.jdbc.DataSourceBuilder;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.PropertySource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.jdbc.datasource.DataSourceTransactionManager;
 
 import javax.sql.DataSource;
 
+import static com.shkpr.service.customgateway.core.constants.DataSourceNames.EMBEDDED;
+import static com.shkpr.service.customgateway.core.constants.DataSourceNames.PRIMARY;
+
 /**
- * 主要的DataSource配置
+ * 数据源配置
  *
  * @author 欧阳劲驰
  * @since 1.0.0
  */
 @Configuration
-@MapperScan(basePackages = "com.shkpr.service.customgateway.**.mapper", sqlSessionTemplateRef = "mainSqlSessionTemplate")
+@EnableConfigurationProperties(DataSourceProperties.class)
 @PropertySource(value = "file:${global.sql-config-path}", ignoreResourceNotFound = true, encoding = "UTF-8", factory = YamlPropertySourceFactory.class)
 public class DataSourceConfig {
-    @Value("${spring.datasource.data.driver-class-name:org.postgresql.Driver}")
-    private String driveClass;
-
-    @Value("${spring.datasource.data.jdbc-url:}")
-    private String url = "";
-
-    @Value("${spring.datasource.data.username:}")
-    private String username = "";
-
-    @Value("${spring.datasource.data.password:}")
-    private String password = "";
-
-    @Value("${spring.datasource.data.maximum-pool-size:200}")
-    private Integer maxPoolSize;
-
-    @Value("${spring.datasource.data.minimum-idle:1}")
-    private Integer minIdle;
-
-    @Value("${spring.datasource.data.connection-test-query:}")
-    private String connectionTestQuery;
-
-    @Value("${spring.datasource.data.max-lifetime:120000}")
-    private Long maxLifetime;
-
-    @Value("${spring.datasource.data.idle-timeout:30000}")
-    private Long idleTimeout;
-
-    @Value("${spring.datasource.data.connection-timeout:30000}")
-    private Long connectionTimeout;
-
-    @Value("${spring.datasource.data.validation-timeout:30000}")
-    private Long validTimeout;
+    final
+    DataSourceProperties dataSourceProperties;
 
-    @Value("${spring.datasource.data.init-failed-timeout:-1}")
-    private Long initFailedTimeout;
+    public DataSourceConfig(DataSourceProperties dataSourceProperties) {
+        this.dataSourceProperties = dataSourceProperties;
+    }
 
     /**
-     * @return DataSource
+     * @return 主要数据源
      */
-    @Bean(name = "mainDatasource")
-    public DataSource mainDataSource() {
-        //构建DataSource
+    @Bean(name = PRIMARY + "DataSource")
+    public DataSource primaryDataSource() {
+        //获取配置
+        DataSourceProperties.DataSource source = dataSourceProperties.getMulti().get(PRIMARY);
+        //构建数据源
         HikariDataSource dataSource = DataSourceBuilder.create()
                 .type(HikariDataSource.class)
-                .url(url)
-                .username(username)
-                .password(password)
+                .url(source.getUrl())
+                .username(source.getUsername())
+                .password(source.getPassword())
                 .build();
 
-        dataSource.setDriverClassName(driveClass);
-        dataSource.setUsername(username);
-        dataSource.setPassword(password);
-
-        dataSource.setMaximumPoolSize(maxPoolSize);
-        dataSource.setMinimumIdle(minIdle);
-        dataSource.setConnectionTestQuery(connectionTestQuery);
-        dataSource.setMaxLifetime(maxLifetime);
-        dataSource.setIdleTimeout(idleTimeout);
-        dataSource.setConnectionTimeout(connectionTimeout);
-        dataSource.setValidationTimeout(validTimeout);
-        dataSource.setInitializationFailTimeout(initFailedTimeout);
+        configHikari(dataSourceProperties.getHikari(), dataSource);
 
         return dataSource;
     }
 
-
-    @Bean("mainSqlSessionFactory")
-    public SqlSessionFactory mainSqlSessionFactoryBean(@Qualifier("mainDatasource") DataSource dataSource) throws Exception {
-        SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
-        sessionFactoryBean.setDataSource(dataSource);
-        sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
-                .getResources("classpath:mapper/*.xml"));
-        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
-        configuration.setCallSettersOnNulls(true);       //数据库中字段值为null时也要求返回
-        //驼峰映射
-        configuration.setMapUnderscoreToCamelCase(true); //开启驼峰映射
-        configuration.setCacheEnabled(false);
-        sessionFactoryBean.setConfiguration(configuration);
-        return sessionFactoryBean.getObject();
-    }
-
-    @Bean("mainSqlSessionTemplate")
-    public SqlSessionTemplate mainSqlSessionTemplate(@Qualifier("mainSqlSessionFactory") SqlSessionFactory sessionFactory) {
-        return new SqlSessionTemplate(sessionFactory);
+    /**
+     * @return 嵌入数据源
+     */
+    @Bean(name = EMBEDDED + "DataSource")
+    public DataSource embeddedDataSource() {
+        //获取配置
+        DataSourceProperties.DataSource source = dataSourceProperties.getMulti().get(EMBEDDED);
+        //构建数据源
+        return DataSourceBuilder.create()
+                .type(JdbcDataSource.class)
+                .url(source.getUrl())
+                .username(source.getUsername())
+                .password(source.getPassword())
+                .build();
     }
 
-    @Bean(name = "mainDbTransactionManager")
-    public DataSourceTransactionManager mainDbTransactionManager(@Qualifier("mainDatasource") DataSource dataSource) {
-        return new DataSourceTransactionManager(dataSource);
+    /**
+     * 配置Hikari
+     *
+     * @param config     配置
+     * @param dataSource 数据源
+     */
+    private void configHikari(HikariConfig config, HikariDataSource dataSource) {
+        dataSource.setMaximumPoolSize(config.getMaximumPoolSize());
+        dataSource.setMinimumIdle(config.getMinimumIdle());
+        dataSource.setConnectionTestQuery(config.getConnectionTestQuery());
+        dataSource.setMaxLifetime(config.getMaxLifetime());
+        dataSource.setIdleTimeout(config.getIdleTimeout());
+        dataSource.setConnectionTimeout(config.getConnectionTimeout());
+        dataSource.setValidationTimeout(config.getValidationTimeout());
+        dataSource.setInitializationFailTimeout(config.getInitializationFailTimeout());
     }
 }

+ 5 - 6
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/DeviceConfig.java

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
 import com.shkpr.service.customgateway.core.components.DeviceIdGenerator;
 import com.shkpr.service.customgateway.core.components.DeviceRegistry;
 import com.shkpr.service.customgateway.core.properties.DeviceProperties;
+import com.shkpr.service.customgateway.core.repository.embedded.DeviceSequencesRepository;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -21,11 +22,11 @@ public class DeviceConfig {
     final
     DeviceProperties deviceProperties;
     final
-    ObjectMapper objectMapper;
+    DeviceSequencesRepository deviceSequencesRepository;
 
-    public DeviceConfig(DeviceProperties deviceProperties, ObjectMapper objectMapper) {
+    public DeviceConfig(DeviceProperties deviceProperties, DeviceSequencesRepository deviceSequencesRepository) {
         this.deviceProperties = deviceProperties;
-        this.objectMapper = objectMapper;
+        this.deviceSequencesRepository = deviceSequencesRepository;
     }
 
     /**
@@ -46,9 +47,7 @@ public class DeviceConfig {
     @Bean
     public DeviceIdGenerator deviceIdGenerator() {
         return DeviceIdGenerator.builder()
-                .sequenceFile(deviceProperties.getSeqPath())
-                .objectMapper(objectMapper)
-                .autoLoad(true)
+                .repository(deviceSequencesRepository)
                 .build();
     }
 }

+ 50 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/JdbcRepositoriesConfig.java

@@ -0,0 +1,50 @@
+package com.shkpr.service.customgateway.core.config;
+
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.transaction.PlatformTransactionManager;
+
+import javax.sql.DataSource;
+
+import static com.shkpr.service.customgateway.core.constants.DataSourceNames.EMBEDDED;
+
+/**
+ * jdbc配置
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Configuration
+@EnableJdbcRepositories(
+        jdbcOperationsRef = EMBEDDED + "JdbcOperations",
+        transactionManagerRef = EMBEDDED + "TransactionManager",
+        basePackages = "com.shkpr.service.customgateway.core.repository." + EMBEDDED
+)
+public class JdbcRepositoriesConfig {
+    /**
+     * @param dataSource 数据源
+     * @return jdbc操作器
+     */
+    @Bean(EMBEDDED + "JdbcOperations")
+    public NamedParameterJdbcOperations embeddedJdbcOperations(
+            @Qualifier(EMBEDDED + "DataSource") DataSource dataSource
+    ) {
+        return new NamedParameterJdbcTemplate(dataSource);
+    }
+
+    /**
+     * @param dataSource 数据源
+     * @return 事务管理器
+     */
+    @Bean(EMBEDDED + "TransactionManager")
+    public PlatformTransactionManager embeddedTransactionManager(
+            @Qualifier(EMBEDDED + "DataSource") DataSource dataSource
+    ) {
+        return new DataSourceTransactionManager(dataSource);
+    }
+}

+ 74 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/config/MybatisConfig.java

@@ -0,0 +1,74 @@
+package com.shkpr.service.customgateway.core.config;
+
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.mybatis.spring.SqlSessionFactoryBean;
+import org.mybatis.spring.SqlSessionTemplate;
+import org.mybatis.spring.annotation.MapperScan;
+import org.mybatis.spring.boot.autoconfigure.MybatisProperties;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+
+import javax.sql.DataSource;
+
+import static com.shkpr.service.customgateway.core.constants.DataSourceNames.PRIMARY;
+
+/**
+ * mybatis配置
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Configuration
+@EnableConfigurationProperties(MybatisProperties.class)
+@MapperScan(
+        sqlSessionTemplateRef = PRIMARY + "SqlSessionTemplate",
+        basePackages = "com.shkpr.service.customgateway.**.mapper." + PRIMARY
+)
+public class MybatisConfig {
+
+    private static final ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
+
+    final
+    MybatisProperties properties;
+
+    public MybatisConfig(MybatisProperties properties) {
+        this.properties = properties;
+    }
+
+    /**
+     * @param dataSource 数据源
+     * @return SQL会话工厂
+     * @throws Exception NotInitializedException
+     */
+    @Bean(PRIMARY + "SqlSessionFactory")
+    public SqlSessionFactory mainSqlSessionFactoryBean(@Qualifier(PRIMARY + "DataSource") DataSource dataSource) throws Exception {
+        SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
+        sessionFactoryBean.setDataSource(dataSource);
+        sessionFactoryBean.setMapperLocations(resourceResolver.getResources("classpath:mapper/*.xml"));
+        sessionFactoryBean.setConfiguration(properties.getConfiguration());
+        return sessionFactoryBean.getObject();
+    }
+
+    /**
+     * @param sessionFactory SQL会话工厂
+     * @return SQL会话模版
+     */
+    @Bean(PRIMARY + "SqlSessionTemplate")
+    public SqlSessionTemplate mainSqlSessionTemplate(@Qualifier(PRIMARY + "SqlSessionFactory") SqlSessionFactory sessionFactory) {
+        return new SqlSessionTemplate(sessionFactory);
+    }
+
+    /**
+     * @param dataSource 数据源
+     * @return 事物管理器
+     */
+    @Bean(PRIMARY + "DbTransactionManager")
+    public DataSourceTransactionManager mainDbTransactionManager(@Qualifier(PRIMARY + "DataSource") DataSource dataSource) {
+        return new DataSourceTransactionManager(dataSource);
+    }
+}

+ 14 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/constants/DataSourceNames.java

@@ -0,0 +1,14 @@
+package com.shkpr.service.customgateway.core.constants;
+
+/**
+ * 数据源名称
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+public interface DataSourceNames {
+    //主要
+    String PRIMARY = "primary";
+    //嵌入
+    String EMBEDDED = "embedded";
+}

+ 1 - 1
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/constants/DeviceKind.java

@@ -18,7 +18,7 @@ import static com.shkpr.service.customgateway.core.constants.DeviceField.*;
 @AllArgsConstructor
 public enum DeviceKind {
     //流量计
-    FLOW("flow", "流量计", 2, "WaterMeter", Arrays.asList(FLOW_CUR, FLOW_TOTAL_POS, FLOW_TOTAL_REV)),
+    FLOW("flow", "流量计", 1, "WaterMeter", Arrays.asList(FLOW_CUR, FLOW_TOTAL_POS, FLOW_TOTAL_REV)),
     ;
     /**
      * 标识

+ 25 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/controller/RouteController.java

@@ -0,0 +1,25 @@
+package com.shkpr.service.customgateway.core.controller;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * 路由controller
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Controller
+@RequestMapping("/")
+public class RouteController {
+    /**
+     * 首页
+     *
+     * @return 首页路径
+     */
+    @GetMapping("/")
+    public String index() {
+        return "index";
+    }
+}

+ 35 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/DeviceSequences.java

@@ -0,0 +1,35 @@
+package com.shkpr.service.customgateway.core.domain;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.relational.core.mapping.Table;
+
+import java.time.LocalDate;
+
+/**
+ * 设备序列表
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Table("DEVICE_SEQUENCES")
+public class DeviceSequences {
+    /**
+     * 时间
+     */
+    @Id
+    private LocalDate date;
+    /**
+     * 序列
+     */
+    private Integer seq;
+
+    public static DeviceSequences of(LocalDate date, Integer seq) {
+        return new DeviceSequences(date, seq);
+    }
+}

+ 5 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/IntegrationKey.java

@@ -26,4 +26,9 @@ public class IntegrationKey {
      * Secret
      */
     private String secretKey;
+
+    public IntegrationKey(String accessKey, String secretKey) {
+        this.accessKey = accessKey;
+        this.secretKey = secretKey;
+    }
 }

+ 35 - 28
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/PageRequest.java

@@ -2,6 +2,7 @@ package com.shkpr.service.customgateway.core.domain;
 
 import lombok.Data;
 import lombok.NonNull;
+import org.jetbrains.annotations.NotNull;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
 
@@ -45,6 +46,34 @@ public class PageRequest implements Pageable {
         this.sort = sort != null ? sort : Sort.unsorted();
     }
 
+    /**
+     * 创建带排序的PageRequest
+     */
+    public static PageRequest defaultPage() {
+        return of(0, 99, Sort.unsorted());
+    }
+
+    /**
+     * 创建带排序的PageRequest
+     */
+    public static PageRequest of(int page, int size) {
+        return of(page, size, Sort.unsorted());
+    }
+
+    /**
+     * 创建带排序的PageRequest
+     */
+    public static PageRequest of(int page, int size, Sort sort) {
+        return new PageRequest(page, size, sort);
+    }
+
+    /**
+     * 创建带排序的PageRequest
+     */
+    public static PageRequest of(int page, int size, Sort.Direction direction, String... properties) {
+        return of(page, size, Sort.by(direction, properties));
+    }
+
     @Override
     public int getPageNumber() {
         return this.pageNumber;
@@ -85,35 +114,13 @@ public class PageRequest implements Pageable {
     }
 
     @Override
-    public boolean hasPrevious() {
-        return pageNumber > 0;
+    @NotNull
+    public Pageable withPage(int pageNumber) {
+        return new PageRequest(pageNumber, getPageSize(), getSort());
     }
 
-    /**
-     * 创建带排序的PageRequest
-     */
-    public static PageRequest defaultPage() {
-        return of(0, 99, Sort.unsorted());
-    }
-
-    /**
-     * 创建带排序的PageRequest
-     */
-    public static PageRequest of(int page, int size) {
-        return of(page, size, Sort.unsorted());
-    }
-
-    /**
-     * 创建带排序的PageRequest
-     */
-    public static PageRequest of(int page, int size, Sort sort) {
-        return new PageRequest(page, size, sort);
-    }
-
-    /**
-     * 创建带排序的PageRequest
-     */
-    public static PageRequest of(int page, int size, Sort.Direction direction, String... properties) {
-        return of(page, size, Sort.by(direction, properties));
+    @Override
+    public boolean hasPrevious() {
+        return pageNumber > 0;
     }
 }

+ 1 - 1
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/mapper/DeviceKindMapper.java

@@ -1,4 +1,4 @@
-package com.shkpr.service.customgateway.core.mapper;
+package com.shkpr.service.customgateway.core.mapper.primary;
 
 import com.shkpr.service.customgateway.core.domain.DeviceKind;
 import org.apache.ibatis.annotations.Mapper;

+ 1 - 1
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/mapper/TypeDefineMapper.java

@@ -1,4 +1,4 @@
-package com.shkpr.service.customgateway.core.mapper;
+package com.shkpr.service.customgateway.core.mapper.primary;
 
 import com.shkpr.service.customgateway.core.domain.TypeDefine;
 import org.apache.ibatis.annotations.Mapper;

+ 54 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/DataSourceProperties.java

@@ -0,0 +1,54 @@
+package com.shkpr.service.customgateway.core.properties;
+
+import com.zaxxer.hikari.HikariConfig;
+import lombok.*;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * DataSource属性
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@ConfigurationProperties(prefix = "spring.datasource")
+public class DataSourceProperties {
+    /**
+     * 数据源
+     */
+    private Map<String, DataSource> multi = new HashMap<>();
+
+    /**
+     * hikari配置
+     */
+    private HikariConfig hikari;
+
+    /**
+     * 数据源
+     */
+    @Data
+    public static class DataSource {
+        /**
+         * 连接地址
+         */
+        private String url;
+        /**
+         * 用户名
+         */
+        private String username;
+        /**
+         * 密码
+         */
+        private String password;
+        /**
+         * 驱动名称
+         */
+        private String driverClassName;
+    }
+}

+ 0 - 4
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/DeviceProperties.java

@@ -18,8 +18,4 @@ public class DeviceProperties {
      * 映射文件路径
      */
     private String mapPath;
-    /**
-     * 序列文件路径
-     */
-    private String seqPath;
 }

+ 39 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/repository/embedded/DeviceSequencesRepository.java

@@ -0,0 +1,39 @@
+package com.shkpr.service.customgateway.core.repository.embedded;
+
+import com.shkpr.service.customgateway.core.domain.DeviceSequences;
+import org.springframework.data.jdbc.repository.query.Modifying;
+import org.springframework.data.jdbc.repository.query.Query;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
+
+import java.time.LocalDate;
+
+/**
+ * 设备序列库
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Repository
+public interface DeviceSequencesRepository extends CrudRepository<DeviceSequences, LocalDate> {
+
+    /**
+     * 自增序列
+     *
+     * @param date 日期
+     */
+    @Modifying
+    @Query("merge into device_sequences key (date) values " +
+            "(:date, coalesce((select seq from device_sequences where date = :date), 0) + 1)")
+    void incrementSeqBYDate(@Param("date") LocalDate date);
+
+    /**
+     * 查询序列
+     *
+     * @param date 日期
+     * @return 序列
+     */
+    @Query("select seq from device_sequences where date = :date")
+    Integer findSeqByDate(@Param("date") LocalDate date);
+}

+ 1 - 1
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/service/impl/DeviceKindServiceImpl.java

@@ -1,7 +1,7 @@
 package com.shkpr.service.customgateway.core.service.impl;
 
 import com.shkpr.service.customgateway.core.domain.DeviceKind;
-import com.shkpr.service.customgateway.core.mapper.DeviceKindMapper;
+import com.shkpr.service.customgateway.core.mapper.primary.DeviceKindMapper;
 import com.shkpr.service.customgateway.core.service.DeviceKindService;
 import org.springframework.stereotype.Service;
 

+ 1 - 1
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/service/impl/TypeDefineServiceImpl.java

@@ -1,7 +1,7 @@
 package com.shkpr.service.customgateway.core.service.impl;
 
 import com.shkpr.service.customgateway.core.domain.TypeDefine;
-import com.shkpr.service.customgateway.core.mapper.TypeDefineMapper;
+import com.shkpr.service.customgateway.core.mapper.primary.TypeDefineMapper;
 import com.shkpr.service.customgateway.core.service.TypeDefineService;
 import org.springframework.stereotype.Service;
 

+ 2 - 2
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/utils/CallingUtil.java

@@ -1,4 +1,4 @@
-package com.shkpr.service.customgateway.zydma.utils;
+package com.shkpr.service.customgateway.core.utils;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
@@ -26,7 +26,7 @@ import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
- * 请求工具
+ * 对接工具
  *
  * @author 欧阳劲驰
  * @since 1.0.0

+ 48 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/HexUtil.java

@@ -0,0 +1,48 @@
+package com.shkpr.service.customgateway.core.utils;
+
+/**
+ * 16进制工具类
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+public class HexUtil {
+    /**
+     * 字节数组转字符串
+     *
+     * @param bytes 字节数组
+     * @return 字符串
+     */
+    public static String encodeHex(byte[] bytes) {
+        StringBuilder sb = new StringBuilder();
+        for (byte b : bytes) {
+            String s = Integer.toHexString(b & 0xff);
+            sb.append(s.length() == 1 ? "0" + s : s);
+        }
+        return sb.toString();
+    }
+
+    /**
+     * 字符串转字节数组
+     *
+     * @param s 字符串
+     * @return 字节数组
+     */
+    public static byte[] decodeHex(String s) {
+        //非空判断
+        if (s == null || s.isEmpty()) return null;
+        //缓存数组
+        byte[] b = new byte[s.length() >> 1];
+        //遍历字符串,每次位移长度2
+        for (int i = 0; i < s.length(); i += 2) {
+            //高位
+            int high = (Character.digit(s.charAt(i), 16) << 4);
+            //低位
+            int low = Character.digit(s.charAt(i + 1), 16);
+            //合并高低位,并加入缓存数组
+            b[i >> 1] = (byte) (high | low);
+        }
+        //返回缓存数组
+        return b;
+    }
+}

+ 1 - 1
custom-gateway-core/src/main/resources/mapper/DeviceKindMapper.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.shkpr.service.customgateway.core.mapper.DeviceKindMapper">
+<mapper namespace="com.shkpr.service.customgateway.core.mapper.primary.DeviceKindMapper">
     <select id="findByKeys" resultType="com.shkpr.service.customgateway.core.domain.DeviceKind">
         select id,
         uid,

+ 1 - 1
custom-gateway-core/src/main/resources/mapper/TypeDefineMapper.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.shkpr.service.customgateway.core.mapper.TypeDefineMapper">
+<mapper namespace="com.shkpr.service.customgateway.core.mapper.primary.TypeDefineMapper">
     <select id="findByKeys" resultType="com.shkpr.service.customgateway.core.domain.TypeDefine">
         select id,
         key,

+ 0 - 9
custom-gateway-zydma/pom.xml

@@ -27,15 +27,6 @@
             <artifactId>custom-gateway-core</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <!--httpclient-->
-        <dependency>
-            <groupId>org.apache.httpcomponents</groupId>
-            <artifactId>httpclient</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.httpcomponents</groupId>
-            <artifactId>fluent-hc</artifactId>
-        </dependency>
     </dependencies>
 
     <!--构建脚本-->

+ 1 - 1
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/components/InfoSynchronizer.java

@@ -12,7 +12,7 @@ import com.shkpr.service.customgateway.zydma.domain.MiddlePlatformResult;
 import com.shkpr.service.customgateway.zydma.domain.MiddlePlatformUser;
 import com.shkpr.service.customgateway.zydma.domain.PersonnelInfo;
 import com.shkpr.service.customgateway.zydma.service.PersonnelInfoService;
-import com.shkpr.service.customgateway.zydma.utils.CallingUtil;
+import com.shkpr.service.customgateway.core.utils.CallingUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.message.BasicHeader;
 import org.springframework.http.HttpMethod;

+ 1 - 1
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/components/IotCollector.java

@@ -10,10 +10,10 @@ import com.shkpr.service.customgateway.core.domain.Device;
 import com.shkpr.service.customgateway.core.domain.DeviceTag;
 import com.shkpr.service.customgateway.core.domain.IntegrationKey;
 import com.shkpr.service.customgateway.core.properties.CallingProperties;
+import com.shkpr.service.customgateway.core.utils.CallingUtil;
 import com.shkpr.service.customgateway.core.utils.InfluxDbUtil;
 import com.shkpr.service.customgateway.zydma.domain.IotPlatformData;
 import com.shkpr.service.customgateway.zydma.domain.IotPlatformResult;
-import com.shkpr.service.customgateway.zydma.utils.CallingUtil;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.http.Header;

+ 1 - 1
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/mapper/PersonnelInfoMapper.java

@@ -1,4 +1,4 @@
-package com.shkpr.service.customgateway.zydma.mapper;
+package com.shkpr.service.customgateway.zydma.mapper.primary;
 
 import com.shkpr.service.customgateway.zydma.domain.PersonnelInfo;
 import org.apache.ibatis.annotations.Mapper;

+ 7 - 5
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/service/impl/PersonnelInfoServiceImpl.java

@@ -2,9 +2,10 @@ package com.shkpr.service.customgateway.zydma.service.impl;
 
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
+import com.shkpr.service.customgateway.core.constants.DataSourceNames;
 import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
 import com.shkpr.service.customgateway.zydma.domain.PersonnelInfo;
-import com.shkpr.service.customgateway.zydma.mapper.PersonnelInfoMapper;
+import com.shkpr.service.customgateway.zydma.mapper.primary.PersonnelInfoMapper;
 import com.shkpr.service.customgateway.zydma.service.PersonnelInfoService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.ibatis.session.ExecutorType;
@@ -31,13 +32,14 @@ public class PersonnelInfoServiceImpl implements PersonnelInfoService {
     private final static String mStrClassName = "PersonnelInfoServiceImpl";
     private final static String mBizType = LogFlagBusiType.ZAO_YANG_DMA.toStrValue();
 
-    private final SqlSessionFactory mainSqlSessionFactory;
+    private final SqlSessionFactory sqlSessionFactory;
 
     private final PersonnelInfoMapper personnelInfoMapper;
 
 
-    public PersonnelInfoServiceImpl(@Qualifier("mainSqlSessionFactory") SqlSessionFactory mainSqlSessionFactory, PersonnelInfoMapper personnelInfoMapper) {
-        this.mainSqlSessionFactory = mainSqlSessionFactory;
+    public PersonnelInfoServiceImpl(@Qualifier(DataSourceNames.PRIMARY + "SqlSessionFactory") SqlSessionFactory sqlSessionFactory
+            , PersonnelInfoMapper personnelInfoMapper) {
+        this.sqlSessionFactory = sqlSessionFactory;
         this.personnelInfoMapper = personnelInfoMapper;
     }
 
@@ -76,7 +78,7 @@ public class PersonnelInfoServiceImpl implements PersonnelInfoService {
 
 
         //开启批处理
-        try (SqlSession sqlSession = mainSqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
+        try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
             try {
                 //设置手动提交
                 Connection conn = sqlSession.getConnection();

+ 1 - 1
custom-gateway-zydma/src/main/resources/mapper/PersonnelInfoMapper.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.shkpr.service.customgateway.zydma.mapper.PersonnelInfoMapper">
+<mapper namespace="com.shkpr.service.customgateway.zydma.mapper.primary.PersonnelInfoMapper">
     <select id="findExistentIds" resultType="java.lang.String">
         SELECT uid FROM k2_personnel_info
         WHERE uid IN

+ 12 - 18
db.yml

@@ -1,23 +1,17 @@
 spring:
   datasource:
-    data:
-      jdbc-url: jdbc:postgresql://223.75.194.87:6057/watersmart?useSSL=false&useAffectedRows=false&allowMultiQueries=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
-      username: postgres
-      password: kpr.23417.postgres
-      driver-class-name: org.postgresql.Driver
-      max-wait: 60000
-      maximum-pool-size: 200
-      minimum-idle: 1
-      validation-query: SELECT 1
-      connection-test-query: SELECT 1
-      test-on-borrow: false
-      test-on-return: false
-      test-while-idle: true
-      max-lifetime: 120000
-      idle-timeout: 30000
-      connection-timeout: 30000
-      time-between-eviction-runs-millis: 60000
-      minEvictableIdleTimeMillis: 300000
+    multi:
+      primary:
+        url: jdbc:postgresql://223.75.194.87:6057/watersmart?useSSL=false&useAffectedRows=false&allowMultiQueries=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
+        username: postgres
+        password: kpr.23417.postgres
+        driver-class-name: org.postgresql.Driver
+      embedded:
+        url: jdbc:h2:file:./data
+        driver-class-name: org.h2.Driver
+        username: sa
+        password: kpr.25535.sa
+        schema: classpath*:db/h2.schema.sql
   #influxdb
   influx:
     read-timeout: 30000

+ 0 - 3
dev_seq.json

@@ -1,3 +0,0 @@
-{
-  "2025-11-06" : 118
-}

+ 1 - 1
pom.xml

@@ -41,7 +41,7 @@
         <java.version>1.8</java.version>
 
         <gbase.version>1.0.5</gbase.version>
-        <spring.boot.version>2.1.3.RELEASE</spring.boot.version>
+        <spring.boot.version>2.7.18</spring.boot.version>
         <mybatis.spring.version>2.0.1</mybatis.spring.version>
         <postgresql.version>42.2.5</postgresql.version>
         <common.text.version>1.14.0</common.text.version>