shiyue před 5 měsíci
revize
d2a03a0d03
47 změnil soubory, kde provedl 3532 přidání a 0 odebrání
  1. 361 0
      pom.xml
  2. 31 0
      src/main/java/com/energy/online/data/service/ManageAppApplication.java
  3. 25 0
      src/main/java/com/energy/online/data/service/common/base/BaseConstant.java
  4. 16 0
      src/main/java/com/energy/online/data/service/common/base/BaseController.java
  5. 44 0
      src/main/java/com/energy/online/data/service/common/base/BaseDomainWithUser.java
  6. 26 0
      src/main/java/com/energy/online/data/service/common/base/BaseException.java
  7. 12 0
      src/main/java/com/energy/online/data/service/common/base/BaseRepository.java
  8. 23 0
      src/main/java/com/energy/online/data/service/common/base/BaseService.java
  9. 60 0
      src/main/java/com/energy/online/data/service/common/base/BaseServiceImpl.java
  10. 41 0
      src/main/java/com/energy/online/data/service/common/base/NewBaseDomain.java
  11. 112 0
      src/main/java/com/energy/online/data/service/common/base/Page.java
  12. 15 0
      src/main/java/com/energy/online/data/service/common/mappers/MyMapper.java
  13. 30 0
      src/main/java/com/energy/online/data/service/controller/MeasurementController.java
  14. 44 0
      src/main/java/com/energy/online/data/service/dto/MeasurementDto.java
  15. 123 0
      src/main/java/com/energy/online/data/service/listener/J60870Client.java
  16. 183 0
      src/main/java/com/energy/online/data/service/listener/J60870ClientListener.java
  17. 15 0
      src/main/java/com/energy/online/data/service/listener/J60870Main.java
  18. 124 0
      src/main/java/com/energy/online/data/service/listener/JClient.java
  19. 102 0
      src/main/java/com/energy/online/data/service/listener/ListenerMainService.java
  20. 16 0
      src/main/java/com/energy/online/data/service/mapper/MeasurementConfMapper.java
  21. 48 0
      src/main/java/com/energy/online/data/service/mapper/MeasurementMapper.java
  22. 14 0
      src/main/java/com/energy/online/data/service/mapper/MeasurementTempMapper.java
  23. 35 0
      src/main/java/com/energy/online/data/service/po/MeasurementConfPO.java
  24. 47 0
      src/main/java/com/energy/online/data/service/po/MeasurementPO.java
  25. 52 0
      src/main/java/com/energy/online/data/service/po/MeasurementTempPO.java
  26. 61 0
      src/main/java/com/energy/online/data/service/service/J104ClinetService.java
  27. 113 0
      src/main/java/com/energy/online/data/service/service/impl/J104ClinetServiceImpl.java
  28. 131 0
      src/main/java/com/energy/online/data/service/util/BatchUtil.java
  29. 69 0
      src/main/java/com/energy/online/data/service/util/BeanTools.java
  30. 228 0
      src/main/java/com/energy/online/data/service/util/DateUtils.java
  31. 63 0
      src/main/java/com/energy/online/data/service/util/FileUtil.java
  32. 78 0
      src/main/java/com/energy/online/data/service/util/IPUtils.java
  33. 34 0
      src/main/java/com/energy/online/data/service/util/IdGeneratorUtil.java
  34. 70 0
      src/main/java/com/energy/online/data/service/util/JwtUtil.java
  35. 73 0
      src/main/java/com/energy/online/data/service/util/MD5Util.java
  36. 57 0
      src/main/java/com/energy/online/data/service/util/NetUtils.java
  37. 85 0
      src/main/java/com/energy/online/data/service/util/RandomSeriUtil.java
  38. 38 0
      src/main/java/com/energy/online/data/service/util/SpringTools.java
  39. 104 0
      src/main/java/com/energy/online/data/service/util/UUIDUtil.java
  40. 17 0
      src/main/java/com/energy/online/data/service/vo/InformationDataVo.java
  41. 125 0
      src/main/resources/application.properties
  42. 22 0
      src/main/resources/banner/banner.txt
  43. 13 0
      src/main/resources/logback.xml
  44. 162 0
      src/main/resources/logback/logback-dev.xml
  45. 164 0
      src/main/resources/logback/logback-prod.xml
  46. 162 0
      src/main/resources/logback/logback-test.xml
  47. 64 0
      src/main/resources/mybatis/measurement/MeasurementMapper.xml

+ 361 - 0
pom.xml

@@ -0,0 +1,361 @@
+<?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">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.zhzn.energy</groupId>
+    <artifactId>energy-online-data-service</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <properties>
+        <java.version>1.8</java.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
+        <swagger.version>2.6.1</swagger.version>
+        <fastjson.version>1.2.9</fastjson.version>
+        <aliyun-openservices.version>1.2.3</aliyun-openservices.version>
+        <aliyun-sdk-oss.version>2.4.0</aliyun-sdk-oss.version>
+        <docker.image.prefix>test</docker.image.prefix>
+        <spring.boot.version>2.3.2.RELEASE</spring.boot.version>
+        <spring.cloud.alibaba.version>1.5.0.RELEASE</spring.cloud.alibaba.version>
+    </properties>
+
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-dependencies</artifactId>
+        <version>2.3.2.RELEASE</version>
+    </parent>
+
+    <dependencies>
+
+        <!-- spring boot -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-jdbc</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>io.lettuce</groupId>
+                    <artifactId>lettuce-core</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>1.3.1</version>
+        </dependency>
+
+        <!-- spring boot -->
+        <dependency>
+            <groupId>redis.clients</groupId>
+            <artifactId>jedis</artifactId>
+            <version>3.1.0</version>
+        </dependency>
+
+        <!--分页-->
+        <dependency>
+            <groupId>com.github.pagehelper</groupId>
+            <artifactId>pagehelper-spring-boot-starter</artifactId>
+            <version>1.2.10</version>
+        </dependency>
+        <!--分页-->
+
+        <!-- 通用mapper -->
+        <dependency>
+            <groupId>tk.mybatis</groupId>
+            <artifactId>mapper-spring-boot-starter</artifactId>
+            <version>4.2.1</version>
+        </dependency>
+        <!-- 通用mapper -->
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid-spring-boot-starter</artifactId>
+            <version>1.1.10</version>
+        </dependency>
+
+        <!--        <dependency>-->
+        <!--            <groupId>mysql</groupId>-->
+        <!--            <artifactId>mysql-connector-java</artifactId>-->
+        <!--            <version>5.1.43</version>-->
+        <!--        </dependency>-->
+
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>5.1.47</version>
+        </dependency>
+
+        <!-- json -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>${fastjson.version}</version>
+        </dependency>
+        <!-- json -->
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>1.14.4</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.caucho</groupId>
+            <artifactId>hessian</artifactId>
+            <version>4.0.51</version>
+        </dependency>
+
+        <!-- 引入swagger依赖 -->
+
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-boot-starter</artifactId>
+            <version>3.0.0</version>
+
+        </dependency>
+
+        <dependency>
+            <groupId>io.swagger</groupId>
+            <artifactId>swagger-annotations</artifactId>
+            <version>1.5.21</version>
+        </dependency>
+        <dependency>
+            <groupId>io.swagger</groupId>
+            <artifactId>swagger-models</artifactId>
+            <version>1.5.21</version>
+        </dependency>
+
+
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-spring-boot-starter</artifactId>
+            <version>3.0.1</version>
+        </dependency>
+
+        <!-- jwt -->
+        <dependency>
+            <groupId>com.auth0</groupId>
+            <artifactId>java-jwt</artifactId>
+            <version>3.4.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.testng</groupId>
+            <artifactId>testng</artifactId>
+            <version>6.9.9</version>
+        </dependency>
+        <dependency>
+            <groupId>org.checkerframework</groupId>
+            <artifactId>checker-qual</artifactId>
+            <version>3.12.0</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.7.15</version>
+        </dependency>
+        <dependency>
+            <groupId>com.vdurmont</groupId>
+            <artifactId>emoji-java</artifactId>
+            <version>5.1.1</version>
+        </dependency>
+
+        <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <version>1.1.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.junit.vintage</groupId>
+                    <artifactId>junit-vintage-engine</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <!-- json转换 -->
+        <dependency>
+            <groupId>com.fasterxml.jackson.datatype</groupId>
+            <artifactId>jackson-datatype-joda</artifactId>
+            <version>2.9.10</version>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-fileupload</groupId>
+            <artifactId>commons-fileupload</artifactId>
+            <version>1.3.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.hibernate.validator</groupId>
+            <artifactId>hibernate-validator</artifactId>
+        </dependency>
+
+        <!-- forest 远程连接框架 -->
+        <!--<dependency>-->
+        <!--<groupId>com.dtflys.forest</groupId>-->
+        <!--<artifactId>forest-spring-boot-starter</artifactId>-->
+        <!--<version>1.5.13</version>-->
+        <!--</dependency>-->
+
+        <!-- zip压缩包 -->
+        <dependency>
+            <groupId>net.lingala.zip4j</groupId>
+            <artifactId>zip4j</artifactId>
+            <version>1.3.2</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel</artifactId>
+            <version>2.2.3</version>
+        </dependency>
+
+        <!-- 浏览器解析工具 -->
+        <dependency>
+            <groupId>eu.bitwalker</groupId>
+            <artifactId>UserAgentUtils</artifactId>
+            <version>1.21</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.10</version>
+        </dependency>
+
+        <!--  104协议  -->
+        <dependency>
+            <groupId>org.openmuc</groupId>
+            <artifactId>j60870</artifactId>
+            <version>1.4.0</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <finalName>${project.artifactId}</finalName>
+        <resources>
+            <resource>
+                <directory>src/main/resources/</directory>
+                <filtering>true</filtering>
+                <includes>
+                    <include>**/*.properties</include>
+                </includes>
+            </resource>
+            <resource>
+                <directory>src/main/resources/</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>2.0.5.RELEASE</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <mainClass>com.energy.online.data.service.ManageAppApplication</mainClass>
+                </configuration>
+            </plugin>
+            <!-- Compiler 插件, 设定JDK版本 -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>${maven-compiler-plugin.version}</version>
+                <configuration>
+                    <source>${java.version}</source>
+                    <target>${java.version}</target>
+                    <encoding>utf-8</encoding>
+                    <showWarnings>true</showWarnings>
+                    <compilerArguments>
+                        <endorseddirs>${endorsed.dir}</endorseddirs>
+                    </compilerArguments>
+                </configuration>
+            </plugin>
+
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <version>2.6</version>
+            </plugin>
+
+        </plugins>
+    </build>
+
+    <!-- 配置环境 -->
+    <profiles>
+        <profile>
+            <id>dev</id>
+            <properties>
+                <profiles.active>dev</profiles.active>
+            </properties>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+        </profile>
+        <profile>
+            <id>test</id>
+            <properties>
+                <profiles.active>test</profiles.active>
+            </properties>
+        </profile>
+        <profile>
+            <id>prod</id>
+            <properties>
+                <profiles.active>prod</profiles.active>
+            </properties>
+        </profile>
+    </profiles>
+
+
+
+
+</project>

+ 31 - 0
src/main/java/com/energy/online/data/service/ManageAppApplication.java

@@ -0,0 +1,31 @@
+package com.energy.online.data.service;
+
+import com.energy.online.data.service.common.mappers.MyMapper;
+import com.energy.online.data.service.listener.J60870ClientListener;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+import tk.mybatis.spring.annotation.MapperScan;
+
+
+@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
+@EnableAspectJAutoProxy(exposeProxy = true)
+@EnableTransactionManagement
+@EnableAsync
+@MapperScan(value = "com.energy.online.data.service.mapper", markerInterface = MyMapper.class)
+@Slf4j
+public class ManageAppApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(ManageAppApplication.class, args);
+        log.info("============= energy-online Application Service Start Success =====>");
+    }
+
+
+
+}

+ 25 - 0
src/main/java/com/energy/online/data/service/common/base/BaseConstant.java

@@ -0,0 +1,25 @@
+package com.energy.online.data.service.common.base;
+
+/**
+ * 系统常量
+ * Created by apple on 2017/5/9.
+ */
+public class BaseConstant {
+
+  /**
+   * 成功
+   */
+  public static final String SUCCESSFUL_CODE = "1";
+
+  public static final String FAILURE_CODE = "0"; //失败
+
+  public static final String AUTH_CODE = "401";//未授权客户机访问数据
+
+  public static final String PARAMETER_CODE = "400";// 错误请求 — 请求中有语法问题
+
+  public static final String CONDITIONS_CODE = "412";// 参数条件错误
+
+  public static final String PERFORM_CODE = "5011"; //服务器执行错误
+
+
+}

+ 16 - 0
src/main/java/com/energy/online/data/service/common/base/BaseController.java

@@ -0,0 +1,16 @@
+package com.energy.online.data.service.common.base;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Controller基础类
+ */
+public class BaseController {
+  /**
+   * 日志对象
+   */
+  protected Logger logger = LoggerFactory.getLogger(this.getClass());
+
+
+}

+ 44 - 0
src/main/java/com/energy/online/data/service/common/base/BaseDomainWithUser.java

@@ -0,0 +1,44 @@
+package com.energy.online.data.service.common.base;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @author shiyue
+ */
+@Data
+public class BaseDomainWithUser extends NewBaseDomain {
+
+    /*
+     * 创建人
+     */
+    private Integer createBy;
+
+    /*
+     * 创建人名称
+     */
+    private String createUser;
+
+    /*
+     * 更新人
+     */
+    private Integer updateBy;
+
+    /*
+     * 更新人名称
+     */
+    private String updateUser;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date createTime;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date updateTime;
+
+    /**
+     * 用户角色
+     */
+    private Integer roleId;
+}

+ 26 - 0
src/main/java/com/energy/online/data/service/common/base/BaseException.java

@@ -0,0 +1,26 @@
+package com.energy.online.data.service.common.base;
+
+
+/**
+ * Created by  on 1/17/17.
+ */
+public class BaseException extends RuntimeException {
+  private static final long serialVersionUID = -6336125614015879324L;
+
+  public BaseException() {
+    super();
+  }
+
+  public BaseException(String message) {
+    super(message);
+  }
+
+
+  public BaseException(Throwable cause) {
+    super(cause);
+  }
+
+  public BaseException(String message, Throwable cause) {
+    super(message, cause);
+  }
+}

+ 12 - 0
src/main/java/com/energy/online/data/service/common/base/BaseRepository.java

@@ -0,0 +1,12 @@
+package com.energy.online.data.service.common.base;
+
+/**
+ * @author
+ */
+public class BaseRepository<T> extends BaseServiceImpl<T> {
+
+    public int insertSelective(T data) {
+        return mapper.insertSelective(data);
+    }
+
+}

+ 23 - 0
src/main/java/com/energy/online/data/service/common/base/BaseService.java

@@ -0,0 +1,23 @@
+package com.energy.online.data.service.common.base;
+
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public interface BaseService<T> {
+
+  T selectByKey(Object key);
+
+  int save(T entity);
+
+  int delete(Object key);
+
+  int updateAll(T entity);
+
+  int updateNotNull(T entity);
+
+  List<T> selectByExample(Object example);
+
+
+}

+ 60 - 0
src/main/java/com/energy/online/data/service/common/base/BaseServiceImpl.java

@@ -0,0 +1,60 @@
+package com.energy.online.data.service.common.base;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import tk.mybatis.mapper.common.Mapper;
+
+import java.util.List;
+
+@Transactional(rollbackFor = Exception.class)
+public abstract class BaseServiceImpl<T> implements BaseService<T> {
+
+  private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+  @Autowired
+  protected Mapper<T> mapper;
+
+  public Mapper<T> getMapper() {
+    return mapper;
+  }
+
+  @Override
+  public T selectByKey(Object key) {
+    //说明:根据主键字段进行查询,方法参数必须包含完整的主键属性,查询条件使用等号
+    return mapper.selectByPrimaryKey(key);
+  }
+
+  @Override
+  public int save(T entity) {
+    //说明:保存一个实体,null的属性也会保存,不会使用数据库默认值
+    return mapper.insert(entity);
+  }
+
+  @Override
+  public int delete(Object key) {
+    //说明:根据主键字段进行删除,方法参数必须包含完整的主键属性
+    return mapper.deleteByPrimaryKey(key);
+  }
+
+  @Override
+  public int updateAll(T entity) {
+    //说明:根据主键更新实体全部字段,null值会被更新
+    return mapper.updateByPrimaryKey(entity);
+  }
+
+  @Override
+  public int updateNotNull(T entity) {
+    //根据主键更新属性不为null的值
+    return mapper.updateByPrimaryKeySelective(entity);
+  }
+
+  @Override
+  public List<T> selectByExample(Object example) {
+    //说明:根据Example条件进行查询
+    //重点:这个查询支持通过Example类指定查询列,通过 selectProperties方法指定查询列
+    return mapper.selectByExample(example);
+  }
+
+}

+ 41 - 0
src/main/java/com/energy/online/data/service/common/base/NewBaseDomain.java

@@ -0,0 +1,41 @@
+package com.energy.online.data.service.common.base;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.persistence.Column;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import java.util.Date;
+
+
+@Data
+@EqualsAndHashCode
+@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC)
+public class NewBaseDomain {
+
+
+    @Id
+    @GeneratedValue(generator = "JDBC")
+    @Column(name = "id")
+    @ApiModelProperty(value = "主键id")
+    private Integer id;
+
+    @ApiModelProperty(value = "创建时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone = "GMT+8")
+    private Date createTime;
+
+    @ApiModelProperty(value = "修改时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone = "GMT+8")
+    private Date updateTime;
+
+    @ApiModelProperty(value = "创建人")
+    private Integer createBy;
+
+    @ApiModelProperty(value = "修改人")
+    private Integer updateBy;
+
+}

+ 112 - 0
src/main/java/com/energy/online/data/service/common/base/Page.java

@@ -0,0 +1,112 @@
+package com.energy.online.data.service.common.base;
+
+import org.springframework.util.CollectionUtils;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.List;
+
+public class Page<T> implements Serializable {
+  private Integer pageNum = 1;
+  private Integer pageSize = 10;
+  private Long totalSize;
+  private Integer pages;
+  private List<T> list;
+
+  public Integer getPageNum() {
+    return pageNum;
+  }
+
+  public void setPageNum(Integer pageNum) {
+    this.pageNum = pageNum;
+  }
+
+  public Integer getPageSize() {
+    return pageSize;
+  }
+
+  public void setPageSize(Integer pageSize) {
+    this.pageSize = pageSize;
+  }
+
+  public Long getTotalSize() {
+    return totalSize;
+  }
+
+  public void setTotalSize(Long totalSize) {
+    this.totalSize = totalSize;
+  }
+
+  public Integer getPages() {
+    pages = (int) (totalSize / pageSize);
+    int mod = (int) (totalSize % pageSize);
+    if (mod > 0) {
+      pages += 1;
+    }
+    return pages;
+  }
+
+  public void setPages(Integer pages) {
+    this.pages = pages;
+  }
+
+  public List<T> getList() {
+    return list;
+  }
+
+  public void setList(List<T> list) {
+    if (CollectionUtils.isEmpty(list)) {
+      this.list = Collections.emptyList();
+    } else {
+      this.list = list;
+    }
+  }
+
+  public Page() {
+  }
+
+  /**
+   * 构建分页数据
+   *
+   * @param pageNum
+   * @param pageSize
+   * @param totalSize
+   * @param list
+   * @param <T>
+   * @return
+   */
+  public static <T> Page<T> build(int pageNum, int pageSize, long totalSize, List<T> list) {
+    Page<T> page = new Page<>();
+    page.setPageNum(pageNum);
+    page.setPageSize(pageSize);
+    page.setTotalSize(totalSize);
+    page.setList(list);
+    return page;
+  }
+
+  /**
+   * Page Redis List 分页工具,获取分页起始数据
+   *
+   * @param pageNum
+   * @param pageSize
+   * @return
+   */
+  public static int getPageDataStart(int pageNum, int pageSize) {
+    pageNum = pageNum <= 0 ? 1 : pageNum;
+    pageSize = pageSize <= 0 ? 10 : pageSize;
+    return (pageNum - 1) * pageSize;
+  }
+
+  /**
+   * Page Redis List 分页工具,获取分页结束数据
+   *
+   * @param pageNum
+   * @param pageSize
+   * @return
+   */
+  public static int getPageDataEnd(int pageNum, int pageSize) {
+    pageNum = pageNum <= 0 ? 1 : pageNum;
+    pageSize = pageSize <= 0 ? 10 : pageSize;
+    return pageNum * pageSize - 1;
+  }
+}

+ 15 - 0
src/main/java/com/energy/online/data/service/common/mappers/MyMapper.java

@@ -0,0 +1,15 @@
+package com.energy.online.data.service.common.mappers;
+
+import tk.mybatis.mapper.common.Mapper;
+import tk.mybatis.mapper.common.MySqlMapper;
+
+/**
+ * 继承自己的MyMapper
+ * 使用通用mapper
+ * @author shiyue
+ * @since 2017-09-06 21:53
+ */
+public interface MyMapper<T> extends Mapper<T>, MySqlMapper<T> {
+    //TODO
+    //FIXME 特别注意,该接口不能被扫描到,否则会出错
+}

+ 30 - 0
src/main/java/com/energy/online/data/service/controller/MeasurementController.java

@@ -0,0 +1,30 @@
+package com.energy.online.data.service.controller;
+
+import com.energy.online.data.service.service.J104ClinetService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+
+@Api(value = "measurement",tags = "104-Data-api")
+@RestController
+@RequestMapping("/measurement")
+public class MeasurementController {
+
+    @Autowired
+    private J104ClinetService j104ClinetService;
+
+
+    @ApiOperation(value = "")
+    @GetMapping("/processingDat")
+    public void processingDat() {
+//        j104ClinetService.processingDat(null,null,null);
+        return;
+    }
+
+
+
+
+
+}

+ 44 - 0
src/main/java/com/energy/online/data/service/dto/MeasurementDto.java

@@ -0,0 +1,44 @@
+package com.energy.online.data.service.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+@Getter
+@Setter
+public class MeasurementDto {
+
+    /**
+     * 收集时间
+     */
+    private Date receiveTime;
+
+    /**
+     * 毫秒时间
+     */
+    private Long time;
+
+    /**
+     * 地址coa地址,从站地址
+     */
+    private Integer commonAddress;
+
+    /**
+     * 数据值json
+     */
+    private String informationObjectData;
+
+    /**
+     * 大小
+     */
+    private Integer informationObjectSize;
+
+    /**
+     * ip地址
+     */
+    private String informationIp;
+
+
+
+}

+ 123 - 0
src/main/java/com/energy/online/data/service/listener/J60870Client.java

@@ -0,0 +1,123 @@
+//package com.energy.online.data.service.listener;
+//
+//import org.openmuc.j60870.ClientConnectionBuilder;
+//import org.openmuc.j60870.Connection;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//
+//import java.net.InetAddress;
+//import java.net.UnknownHostException;
+//
+////由于可能要监听多个从站,这里使用多线程处理
+//public class J60870Client implements Runnable {
+//
+//    private static final Logger log = LoggerFactory.getLogger(J60870Client.class);
+//
+//    public static String title = "104协议数据服务 - ";
+//
+//    private String addrerss;
+//
+//    int port = 2404;
+//
+//    int time = 3000;
+//    //监听类,后面代码会给出
+//    private J60870ClientListener listener;
+//    //连接类
+//    private Connection connection;
+//
+//    //连接参数,可以配置的参数有好多,比如t0,t1,t2等等
+//    private ClientConnectionBuilder clientConnectionBuilder;
+//
+//    /**
+//     *
+//     * @param addrerss
+//     */
+//    public J60870Client(String addrerss) throws UnknownHostException {
+//        this.addrerss = addrerss;
+//        init();
+//    }
+//
+//    /**
+//     *
+//     * @param addrerss
+//     * @param port
+//     */
+//    public J60870Client(String addrerss,int port) throws UnknownHostException {
+//        this.addrerss = addrerss;
+//        this.port = port;
+//        init();
+//    }
+//
+//    /**
+//     *
+//     * @param addrerss
+//     * @param port
+//     * @param time
+//     */
+//    public J60870Client(String addrerss,int port,int time) throws UnknownHostException {
+//        this.addrerss = addrerss;
+//        this.port = port;
+//        this.time = time;
+//        init();
+//    }
+//
+//    /**
+//     * 初始化
+//     */
+//    public void init() throws UnknownHostException {
+//
+//        //获取server端、从站的ip地址对象,这里使用本地ip
+//        InetAddress address = InetAddress.getByName(addrerss);
+//        //创建连接参数对象
+//        clientConnectionBuilder = new ClientConnectionBuilder(address);
+//
+//        //设置socket的连接超时时间
+//        clientConnectionBuilder.setConnectionTimeout(time);
+//
+//        //设置socket的连接超时时间
+//        clientConnectionBuilder.setPort(port);
+//
+//        log.info(title+"J60870Client Init Success By Host "+addrerss);
+//    }
+//
+//    /**
+//     * Runnable的run方法重写
+//     */
+//    @Override
+//    public void run() {
+//        try {
+//            //主站与从站连接
+//            connection = clientConnectionBuilder.build();
+//            //配置数据回调类
+//            listener = new J60870ClientListener();
+//
+//            connection.startDataTransfer(listener);
+//
+//            log.info(title+"J60870Client Run Success By Listener");
+//
+//        } catch (Exception e) {
+//
+//            e.printStackTrace();
+//
+//            log.info(title+"J60870Client Run Exception By Listener");
+//        }
+//    }
+//
+//    /**
+//     * 关闭连接
+//     */
+//    public void disconnect() {
+//        try {
+//
+//            this.connection.close();
+//
+//            log.info(title+"J60870Client Disconnect Success By Close");
+//
+//        } catch (Exception e) {
+//
+//            e.printStackTrace();
+//
+//            log.info(title+"J60870Client Disconnect Exception By Close");
+//        }
+//    }
+//}

+ 183 - 0
src/main/java/com/energy/online/data/service/listener/J60870ClientListener.java

@@ -0,0 +1,183 @@
+package com.energy.online.data.service.listener;
+
+import com.alibaba.fastjson.JSON;
+import com.beust.jcommander.internal.Lists;
+import com.energy.online.data.service.po.MeasurementTempPO;
+import com.energy.online.data.service.service.J104ClinetService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.openmuc.j60870.ASdu;
+import org.openmuc.j60870.ConnectionEventListener;
+import org.openmuc.j60870.ie.InformationElement;
+import org.openmuc.j60870.ie.InformationObject;
+import org.springframework.http.*;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.*;
+
+@Slf4j
+public class J60870ClientListener implements ConnectionEventListener {
+
+    private J104ClinetService j104ClinetService;
+
+    private String addrerss;
+
+    private Integer confId;
+
+    public J60870ClientListener(J104ClinetService j104ClinetService, String addrerss, Integer confId) {
+        this.j104ClinetService = j104ClinetService;
+        this.addrerss = addrerss;
+        this.confId = confId;
+    }
+
+    public final String title = "104协议数据服务 - ";
+
+
+    /**
+     * 监听从站发来的数据
+     *
+     * @param aSdu
+     */
+    @Override
+    public void newASdu(ASdu aSdu) {
+//        log.info(this.title + "J60870ClientListener NewASdu Get :" + aSdu.toString());
+        List<InformationObject> list = new ArrayList<>(Arrays.asList(aSdu.getInformationObjects()));
+        //  获取当前时刻,验证是否是同一秒数据,数据进行合并
+        Instant now = Instant.now();
+        // 获取当前时刻的秒数
+        long epochSecond = now.getEpochSecond();
+        Long receiptTime = j104ClinetService.getMeasurementTime(confId);
+        long receiptTimeLong = receiptTime == null ? 0 : receiptTime.longValue();
+        log.info(this.title + "J60870ClientListener NewASdu Get time ====> " + epochSecond+",接收数据大小:"+list.size());
+        // 数据库最新数据秒时间等于0或者与当前秒时间相等
+        if (receiptTimeLong == 0 || epochSecond == receiptTimeLong) {
+            // 保存临时表
+            saveMeasurementTemp(list, confId, epochSecond);
+        }
+        // 当前秒时间大于数据库最新秒时间并且数据库不等于0
+        if (epochSecond > receiptTimeLong && receiptTimeLong != 0) {
+            int commonAddress = aSdu.getCommonAddress();
+            List<MeasurementTempPO> measurementTempPOList = j104ClinetService.getMeasurementTemp(receiptTimeLong, confId);
+            log.info(JSON.toJSONString("时间秒数" + receiptTimeLong +  ", 数据长度:" + measurementTempPOList.size()));
+
+            Map<String, String> dataMap = new HashMap<>();
+            //动态创建表并入库
+            for (MeasurementTempPO po : measurementTempPOList) {
+                Integer informationObjectAddress = po.getDataPoin();
+                String informationObjectToString = po.getReceiptData();
+                dataMap.put(String.valueOf(informationObjectAddress), informationObjectToString);
+            }
+            j104ClinetService.processingDat(receiptTimeLong, dataMap, confId, commonAddress, addrerss);
+            // 删除上一秒数据
+            j104ClinetService.initDelMeasurementTemp();
+            // 保存临时表
+            saveMeasurementTemp(list, confId, epochSecond);
+        }
+    }
+
+
+    private void saveMeasurementTemp(List<InformationObject> informationObjects, Integer confId, long epochSecond) {
+        MeasurementTempPO measurementTempPO = null;
+        List<MeasurementTempPO> list = Lists.newArrayList();
+        for (InformationObject item : informationObjects) {
+            // 秒数据入库
+            measurementTempPO = new MeasurementTempPO();
+            measurementTempPO.setConfId(confId);
+            measurementTempPO.setReceiptDate(new Date());
+            measurementTempPO.setReceiptTime(epochSecond);
+            measurementTempPO.setDataPoin(item.getInformationObjectAddress());
+            measurementTempPO.setReceiptData(toString(item));
+            list.add(measurementTempPO);
+        }
+        j104ClinetService.saveMeasurementTemp(list);
+    }
+
+
+    /**
+     * 监听连接关闭
+     *
+     * @param cause
+     */
+    @Override
+    public void connectionClosed(IOException cause) {
+        log.debug(this.title + "J60870ClientListener ConnectionClosed :" + cause.getMessage());
+    }
+
+    /**
+     * ASdu类方法重写
+     *
+     * @param aSdu
+     * @return
+     */
+    public String toString(ASdu aSdu) {
+        List<String> strList = new ArrayList<>();
+        if (aSdu.getInformationObjects() != null) {
+            InformationObject[] informationObjects = aSdu.getInformationObjects();
+            String str;
+            for (int i = 0; i < informationObjects.length; ++i) {
+                str = toString(informationObjects[i]);
+                if (str != null) {
+                    strList.add(str);
+                }
+            }
+        }
+        return strList.size() > 0 ? StringUtils.join(strList, "***") : null;
+    }
+
+    /**
+     * InformationObject类方法重写
+     *
+     * @param informationObjectRecord
+     * @return
+     */
+    public String toString(InformationObject informationObjectRecord) {
+        String str;
+        InformationElement[] informationElementSet;
+        List<String> strList = new ArrayList<>();
+        String split = "Short float value:";
+        InformationElement[][] valData = informationObjectRecord.getInformationElements();
+        if (valData.length > 0) {
+            for (int i = 0; i < valData.length; ++i) {
+                informationElementSet = valData[i];
+                for (int ii = 0; ii < informationElementSet.length; ++ii) {
+                    /**
+                     * 目测可能出现的情况:
+                     * Short float value: 18.2
+                     * Quality, overflow: false, blocked: false, substituted: false, not topical: false, invalid: false
+                     */
+                    str = informationElementSet[ii].toString();
+                    if (str.contains(split)) {
+                        strList.add(str.split(split)[1].trim());
+                    }
+                }
+            }
+        }
+        return strList.size() > 0 ? StringUtils.join(strList, ",") : null;
+    }
+
+    /**
+     * 发送POST请求
+     *
+     * @param url
+     * @param params
+     * @return
+     */
+    public String sendPOSTRequest(String url, MultiValueMap<String, String> params) {
+        RestTemplate client = new RestTemplate();
+        HttpHeaders headers = new HttpHeaders();
+        HttpMethod method = HttpMethod.POST;
+        // 以表单的方式提交
+        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+        // 将请求头部和参数合成一个请求
+        HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(params, headers);
+        // 执行HTTP请求,将返回的结构使用String类格式化
+        ResponseEntity<String> response = client.exchange(url, method, requestEntity, String.class);
+        return response.getBody();
+    }
+
+
+}
+

+ 15 - 0
src/main/java/com/energy/online/data/service/listener/J60870Main.java

@@ -0,0 +1,15 @@
+//package com.energy.online.data.service.listener;
+//
+//import java.net.UnknownHostException;
+//
+//public class J60870Main {
+//
+//    public static void main(String[] args){
+//        try {
+//            new J60870Client("192.168.50.242").run();
+//        } catch (UnknownHostException e) {
+//            e.printStackTrace();
+//        }
+//    }
+//
+//}

+ 124 - 0
src/main/java/com/energy/online/data/service/listener/JClient.java

@@ -0,0 +1,124 @@
+package com.energy.online.data.service.listener;
+
+import com.energy.online.data.service.service.J104ClinetService;
+import lombok.extern.slf4j.Slf4j;
+import org.openmuc.j60870.ClientConnectionBuilder;
+import org.openmuc.j60870.Connection;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
+
+@Slf4j
+public class JClient implements Callable<String> {
+
+    public static String title = "104协议数据服务 - ";
+
+    private String addrerss;
+
+    private Integer confId;
+
+    int port = 2404;
+
+    int time = 3000;
+    //监听类,后面代码会给出
+    private J60870ClientListener listener;
+    //连接类
+    private Connection connection;
+
+    //连接参数,可以配置的参数有好多,比如t0,t1,t2等等
+    private ClientConnectionBuilder clientConnectionBuilder;
+
+    private J104ClinetService j104ClinetService;
+
+    @Override
+    public String call() throws Exception {
+
+        //主站与从站连接
+        connection = clientConnectionBuilder.build();
+        //配置数据回调类
+        listener = new J60870ClientListener(this.j104ClinetService, this.addrerss, this.confId);
+
+        connection.startDataTransfer(listener);
+
+        log.info(title + "J60870Client Run Success By Listener");
+
+        return "Success";
+    }
+
+
+    /**
+     * @param addrerss
+     */
+    public JClient(String addrerss, Integer confId, J104ClinetService j104ClinetService) throws UnknownHostException {
+        this.addrerss = addrerss;
+        this.confId = confId;
+        this.j104ClinetService = j104ClinetService;
+        init();
+    }
+
+    /**
+     * @param addrerss
+     * @param port
+     */
+    public JClient(String addrerss, Integer confId, int port, J104ClinetService j104ClinetService) throws UnknownHostException {
+        this.addrerss = addrerss;
+        this.port = port;
+        this.confId = confId;
+        this.j104ClinetService = j104ClinetService;
+        init();
+    }
+
+    /**
+     * @param addrerss
+     * @param port
+     * @param time
+     */
+    public JClient(String addrerss, Integer confId, int port, int time, J104ClinetService j104ClinetService) throws UnknownHostException {
+        this.addrerss = addrerss;
+        this.port = port;
+        this.confId = confId;
+        this.time = time;
+        this.j104ClinetService = j104ClinetService;
+        init();
+    }
+
+    /**
+     * 初始化
+     */
+    public void init() throws UnknownHostException {
+
+        //获取server端、从站的ip地址对象,这里使用本地ip
+        InetAddress address = InetAddress.getByName(addrerss);
+        //创建连接参数对象
+        clientConnectionBuilder = new ClientConnectionBuilder(address);
+
+        //设置socket的连接超时时间
+        clientConnectionBuilder.setConnectionTimeout(time);
+
+        //设置socket的连接超时时间
+        clientConnectionBuilder.setPort(port);
+
+        log.info(title + "J60870Client Init Success By Host " + addrerss);
+    }
+
+    /**
+     * 关闭连接
+     */
+    public void disconnect() {
+        try {
+
+            this.connection.close();
+
+            log.info(title + "J60870Client Disconnect Success By Close");
+
+        } catch (Exception e) {
+
+            e.printStackTrace();
+
+            log.info(title + "J60870Client Disconnect Exception By Close");
+        }
+    }
+}

+ 102 - 0
src/main/java/com/energy/online/data/service/listener/ListenerMainService.java

@@ -0,0 +1,102 @@
+package com.energy.online.data.service.listener;
+
+import cn.hutool.core.util.StrUtil;
+import com.energy.online.data.service.po.MeasurementConfPO;
+import com.energy.online.data.service.service.J104ClinetService;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.context.event.EventListener;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.net.UnknownHostException;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import static java.util.concurrent.Executors.*;
+
+@Slf4j
+@Component
+public class ListenerMainService implements ApplicationListener<ContextRefreshedEvent> {
+
+    @Autowired
+    private J104ClinetService j104ClinetService;
+
+
+    @Override
+    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
+        log.info("启动监听到 J60870Client...");
+        // 清空临时表数据
+//        j104ClinetService.initDelMeasurementTemp();
+        // 查询配置表
+        List<MeasurementConfPO> measurementConfPOS = j104ClinetService.getMeasurementConfList();
+        int taskNum = measurementConfPOS.size();
+        // 创建一个固定大小为size的线程池
+        ExecutorService executor = createOptimizedThreadPool(measurementConfPOS.size());
+        //=========================多线程,提交任务到线程池================================
+        for (int i = 0; i < taskNum; i++) {
+            final int taskNumber = i;
+            MeasurementConfPO measurementConfPO = measurementConfPOS.get(i);
+            System.out.println("Task " + taskNumber + " is running in thread: " + Thread.currentThread().getName());
+            Future<String> future = null;
+            try {
+                future = executor.submit(new JClient(measurementConfPO.getMeasurementIp(),measurementConfPO.getId(),j104ClinetService));
+            } catch (UnknownHostException e) {
+                e.printStackTrace();
+            }finally {
+                executor.shutdown();
+            }
+            try {
+                String result = future.get();
+                System.out.println("Task completed successfully with result: " + result);
+            } catch (InterruptedException e) {
+                System.out.println("Current thread was interrupted while waiting for the task to complete.");
+                Thread.currentThread().interrupt(); // 恢复中断状态
+            } catch (ExecutionException e) {
+                System.out.println("An exception was thrown by the task.");
+                Throwable cause = e.getCause();
+                if (cause instanceof RuntimeException) {
+                    System.out.println("RuntimeException: " + cause.getMessage());
+                } else if (cause instanceof IOException) {
+                    System.out.println("IOException: " + cause.getMessage());
+                } else {
+                    System.out.println("Other exception: " + cause.getClass().getName() + ", message: " + cause.getMessage());
+                }
+            }finally {
+                executor.shutdown();
+            }
+            log.info("监听地址:" + measurementConfPO.getMeasurementIp());
+        }
+
+        //=========================多进程================================
+        //=========================单进程================================
+//        String[] apponitPath = apponitPathList.get(0).split(":");
+//        executor.submit(new JClient(apponitPath[0],apponitPath[1],j104ClinetService));
+//        log.info("监听地址:" + "127.0.0.1" );
+
+    }
+
+    /**
+     * 返回线程数
+     * @param taskCount
+     * @return
+     */
+    private ExecutorService createOptimizedThreadPool(int taskCount) {
+        // 获取可用处理器核心数
+        int availableProcessors = Runtime.getRuntime().availableProcessors();
+
+        // 根据任务类型和系统资源选择合适的线程数
+        // 这里假设任务是IO密集型的,因此我们将线程数设置为核心数的两倍
+        int threadPoolSize = Math.max(availableProcessors * 2, taskCount);
+
+        return newFixedThreadPool(threadPoolSize);
+    }
+
+}

+ 16 - 0
src/main/java/com/energy/online/data/service/mapper/MeasurementConfMapper.java

@@ -0,0 +1,16 @@
+package com.energy.online.data.service.mapper;
+
+import com.energy.online.data.service.common.mappers.MyMapper;
+import com.energy.online.data.service.po.MeasurementConfPO;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface MeasurementConfMapper extends MyMapper<MeasurementConfPO> {
+
+
+
+
+
+
+
+}

+ 48 - 0
src/main/java/com/energy/online/data/service/mapper/MeasurementMapper.java

@@ -0,0 +1,48 @@
+package com.energy.online.data.service.mapper;
+
+import com.energy.online.data.service.common.mappers.MyMapper;
+import com.energy.online.data.service.dto.MeasurementDto;
+import com.energy.online.data.service.po.MeasurementPO;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface MeasurementMapper extends MyMapper<MeasurementPO> {
+
+
+    /**
+     * 通过表明查询表是否存在
+     * @param tableName
+     * @return
+     */
+    int selectTableCountByTableName(@Param("tableName") String tableName);
+
+    /**
+     * 动态创建表
+     * @param tableName
+     * @return
+     */
+    int createTable(@Param("tableName") String tableName);
+
+    /**
+     * 插入数据
+     * @param measurementDto
+     * @return
+     */
+    int insertTableData(@Param("item")MeasurementDto measurementDto,@Param("tableName") String tableName);
+
+    /**
+     * temp倒序获取time
+     * @return
+     */
+    Long selectMeasurementTempByid(@Param("confId")Integer confId);
+
+
+    /**
+     * 删除表数据
+     * @return
+     */
+    int truncateMeasurementTempTable();
+
+
+}

+ 14 - 0
src/main/java/com/energy/online/data/service/mapper/MeasurementTempMapper.java

@@ -0,0 +1,14 @@
+package com.energy.online.data.service.mapper;
+
+import com.energy.online.data.service.common.mappers.MyMapper;
+import com.energy.online.data.service.dto.MeasurementDto;
+import com.energy.online.data.service.po.MeasurementPO;
+import com.energy.online.data.service.po.MeasurementTempPO;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface MeasurementTempMapper extends MyMapper<MeasurementTempPO> {
+
+
+}

+ 35 - 0
src/main/java/com/energy/online/data/service/po/MeasurementConfPO.java

@@ -0,0 +1,35 @@
+package com.energy.online.data.service.po;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import javax.persistence.Column;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import java.util.Date;
+
+@Data
+@Table(name = "measurement_conf")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class MeasurementConfPO {
+
+    @Id
+    @GeneratedValue(generator = "JDBC")
+    @Column(name = "id")
+    @ApiModelProperty(value = "主键id")
+    private Integer id;
+
+    private String measurementIp;
+
+    private String measurement_prot;
+
+    private Integer measurementCommonAddress;
+
+    private String measurementWindField;
+
+
+}

+ 47 - 0
src/main/java/com/energy/online/data/service/po/MeasurementPO.java

@@ -0,0 +1,47 @@
+package com.energy.online.data.service.po;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import javax.persistence.Column;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import java.util.Date;
+
+@Data
+@Table(name = "measurement")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class MeasurementPO {
+
+    @Id
+    @GeneratedValue(generator = "JDBC")
+    @Column(name = "id")
+    @ApiModelProperty(value = "主键id")
+    private Long id;
+
+    /**
+     * 收集时间
+     */
+    private Date receiveTime;
+
+    /**
+     * 毫秒时间
+     */
+    private Long time;
+
+    /**
+     * 地址coa地址,从站地址
+     */
+    private Integer commonAddress;
+
+    /**
+     * 数据值json
+     */
+    private String informationObjectData;
+
+
+}

+ 52 - 0
src/main/java/com/energy/online/data/service/po/MeasurementTempPO.java

@@ -0,0 +1,52 @@
+package com.energy.online.data.service.po;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import javax.persistence.Column;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import java.util.Date;
+
+@Data
+@Table(name = "measurement_temp")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class MeasurementTempPO {
+
+
+    @Id
+    @GeneratedValue(generator = "JDBC")
+    @Column(name = "id")
+    @ApiModelProperty(value = "主键id")
+    private Long id;
+
+    /**
+     *
+     */
+    private Integer confId;
+
+    /**
+     * 毫秒时间
+     */
+    private Long receiptTime;
+
+    /**
+     * 收集时间
+     */
+    private Date receiptDate;
+
+    /**
+     * 数据点
+     */
+    private Integer dataPoin;
+
+    /**
+     * 数据值
+     */
+    private String receiptData;
+
+}

+ 61 - 0
src/main/java/com/energy/online/data/service/service/J104ClinetService.java

@@ -0,0 +1,61 @@
+package com.energy.online.data.service.service;
+
+import com.energy.online.data.service.po.MeasurementConfPO;
+import com.energy.online.data.service.po.MeasurementTempPO;
+
+import java.util.List;
+import java.util.Map;
+
+/***
+ * 104规约接口
+ */
+public interface J104ClinetService {
+
+    /**
+     * 104规约数据入库操作
+     * @param receiptTimeLong 采集时间
+     */
+     void processingDat(long receiptTimeLong,Map<String,String> dataMap,Integer confId,Integer commonAddress,String addrerss);
+
+    /**
+     * 保存临时表
+     * @param measurementTempPOList
+     * @return
+     */
+    boolean saveMeasurementTemp(List<MeasurementTempPO> measurementTempPOList);
+
+    /**
+     * 删除临时表数据(待用)
+     * @param
+     * @return
+     */
+    boolean delMeasurementTemp(Long receiptTime,Integer confId);
+
+    /**
+     * 查询临时表集合
+     * @param
+     * @return
+     */
+    List<MeasurementTempPO> getMeasurementTemp(Long receiptTime,Integer confId);
+
+
+    /**
+     * 倒序获取最新数据,通过配置表对应id(measurement_conf)内id
+     * @param confId
+     * @return
+     */
+    Long getMeasurementTime(Integer confId);
+
+    /**
+     * 查询配置表
+     * @return
+     */
+    List<MeasurementConfPO> getMeasurementConfList();
+
+    /**
+     *
+     */
+    void initDelMeasurementTemp();
+
+
+}

+ 113 - 0
src/main/java/com/energy/online/data/service/service/impl/J104ClinetServiceImpl.java

@@ -0,0 +1,113 @@
+package com.energy.online.data.service.service.impl;
+
+
+import com.alibaba.fastjson.JSON;
+import com.energy.online.data.service.dto.MeasurementDto;
+import com.energy.online.data.service.mapper.MeasurementConfMapper;
+import com.energy.online.data.service.mapper.MeasurementMapper;
+import com.energy.online.data.service.mapper.MeasurementTempMapper;
+import com.energy.online.data.service.po.MeasurementConfPO;
+import com.energy.online.data.service.po.MeasurementTempPO;
+import com.energy.online.data.service.service.J104ClinetService;
+import com.energy.online.data.service.util.DateUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+import tk.mybatis.mapper.entity.Example;
+
+import java.beans.Transient;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@Service
+public class J104ClinetServiceImpl implements J104ClinetService {
+
+    @Autowired
+    private MeasurementMapper measurementMapper;
+
+    @Autowired
+    private MeasurementTempMapper measurementTempMapper;
+
+    @Autowired
+    private MeasurementConfMapper measurementConfMapper;
+
+
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void processingDat(long receiptTimeLong,Map<String, String> dataMap, Integer confId, Integer commonAddress, String addrerss) {
+        // 当年年月日时间表名
+        String dateTime = DateUtils.convertDate2StringYMD(new Date());
+        String tableName = dateTime + "_" +  confId;
+        // 判断表是否存在
+        if (measurementMapper.selectTableCountByTableName(tableName) <= 0) {
+            measurementMapper.createTable(tableName);
+            log.info("动态创建表 ====> " + tableName);
+        }
+        if (CollectionUtils.isEmpty(dataMap)) {
+            log.error(" ==== dataMap数据为空! ==== ");
+            return;
+        }
+        MeasurementDto dto = new MeasurementDto();
+        dto.setReceiveTime(new Date());
+        dto.setCommonAddress(commonAddress);
+        dto.setTime(receiptTimeLong);
+        dto.setInformationObjectData(JSON.toJSONString(dataMap));
+        dto.setInformationObjectSize(dataMap.size());
+        dto.setInformationIp(addrerss);
+        if (measurementMapper.insertTableData(dto, tableName) > 0) {
+            log.info("104规约导入数据成功 ===>" + dto.getTime() + "秒,时间转换:" + DateUtils.convertDate2StringYMDHMS(dto.getReceiveTime()));
+        } else {
+            log.error("104规约导入数据失败,时间转换:" + DateUtils.convertDate2StringYMDHMS(dto.getReceiveTime()));
+        }
+    }
+
+    @Override
+    @Transactional
+    public boolean saveMeasurementTemp(List<MeasurementTempPO> measurementTempPOList) {
+        return measurementTempMapper.insertList(measurementTempPOList) > 0;
+    }
+
+
+    @Override
+    @Transactional
+    public boolean delMeasurementTemp(Long receiptTime,Integer confId) {
+        Example queryExample = new Example(MeasurementTempPO.class);
+        Example.Criteria criteria = queryExample.createCriteria();
+        criteria.andEqualTo("confId",confId);
+        criteria.andEqualTo("receiptTime",receiptTime);
+        return measurementTempMapper.deleteByExample(queryExample) > 0;
+    }
+
+
+    @Override
+    public List<MeasurementTempPO> getMeasurementTemp(Long receiptTime,Integer confId) {
+        MeasurementTempPO po = new MeasurementTempPO();
+        po.setReceiptTime(receiptTime);
+        po.setConfId(confId);
+        return measurementTempMapper.select(po);
+    }
+
+    @Override
+    public Long getMeasurementTime(Integer confId) {
+        return measurementMapper.selectMeasurementTempByid(confId);
+    }
+
+    @Override
+    public List<MeasurementConfPO> getMeasurementConfList() {
+        return measurementConfMapper.selectAll();
+    }
+
+
+    @Override
+    @Transactional
+    public void initDelMeasurementTemp() {
+        measurementMapper.truncateMeasurementTempTable();
+    }
+
+
+}

+ 131 - 0
src/main/java/com/energy/online/data/service/util/BatchUtil.java

@@ -0,0 +1,131 @@
+package com.energy.online.data.service.util;
+
+import java.util.*;
+import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * 批量处理工具
+ *
+ * @author wangwenbing
+ * @date 2022-03-29
+ */
+public class BatchUtil {
+
+    /**
+     * 分批处理
+     *
+     * @param data 要处理的数据
+     * @param batchNum 每次处理数量
+     * @param consumer 处理方法
+     * @param <T>
+     * @return
+     */
+    public static <T> void batchHandle(List<T> data, int batchNum, Consumer<List<T>> consumer){
+        if (data == null || data.isEmpty()) {
+            return;
+        }
+        int len = data.size();
+        int fromIdx = 0;
+        int toIdx = batchNum;
+        List<T> partialData = null;
+        while (true) {
+            toIdx = toIdx > len ? len : toIdx;
+            partialData = data.subList(fromIdx, toIdx);
+            if (partialData.isEmpty()) {
+                break;
+            }
+            fromIdx = toIdx;
+            toIdx = fromIdx + batchNum;
+            consumer.accept(partialData);
+
+        }
+    }
+
+    /**
+     * 提取新增数据
+     *
+     * @param newData
+     * @param oldData
+     * @return
+     */
+    public static <T> List<T> filterInsertData(
+            List<T> newData, List<T> oldData, Function<T, Object> keyFunction) {
+        Set<Object> newKeys = newData.stream().map(e -> keyFunction.apply(e)).collect(Collectors.toSet());
+        Set<Object> oldKeys = oldData.stream().map(e -> keyFunction.apply(e)).collect(Collectors.toSet());
+        Set<Object> needInsertKeys = new HashSet<>(newKeys);
+        needInsertKeys.removeAll(oldKeys);
+        List<T> result = new ArrayList<>();
+        newData.stream().forEach(e -> {
+            Object key = keyFunction.apply(e);
+            if (needInsertKeys.contains(key)) {
+                result.add(e);
+            }
+        });
+        return result;
+    }
+
+    /**
+     * 提取更新数据
+     *
+     * @param newData
+     * @param oldData
+     * @param keyFunction
+     * @param isChange old,new
+     * @param idSetter
+     * @param idGetter
+     * @return
+     */
+    public static <T, ID> List<T> filterUpdateData(
+            List<T> newData, List<T> oldData,
+            Function<T, Object> keyFunction,
+            BiFunction<T, T, Boolean> isChange,
+            BiConsumer<T, ID> idSetter,
+            Function<T, ID> idGetter) {
+        Set<Object> newKeys = newData.stream().map(e -> keyFunction.apply(e)).collect(Collectors.toSet());
+        Set<Object> oldKeys = oldData.stream().map(e -> keyFunction.apply(e)).collect(Collectors.toSet());
+        Map<Object, T> oldDataMap = oldData
+                .stream().collect(Collectors.toMap(e -> keyFunction.apply(e), e -> e, (o, n) -> n));
+        Set<Object> needUpdateKeys = new HashSet<>(newKeys);
+        needUpdateKeys.retainAll(oldKeys);
+        List<T> result = new ArrayList<>();
+        newData.stream().forEach(e -> {
+            Object key = keyFunction.apply(e);
+            if (needUpdateKeys.contains(key)) {
+                T oldRecord = oldDataMap.get(key);
+                if (oldRecord != null && isChange.apply(oldRecord, e)) {
+                    idSetter.accept(e, idGetter.apply(oldRecord));
+                    result.add(e);
+                }
+            }
+        });
+        return result;
+    }
+
+    /**
+     * 提取删除数据
+     *
+     * @param newData
+     * @param oldData
+     * @return
+     */
+    public static <T> List<T> filterDeleteData(
+            List<T> newData, List<T> oldData, Function<T, Object> keyFunction) {
+        Set<Object> newKeys = newData.stream().map(e -> keyFunction.apply(e)).collect(Collectors.toSet());
+        Set<Object> oldKeys = oldData.stream().map(e -> keyFunction.apply(e)).collect(Collectors.toSet());
+
+        Set<Object> needDeleteKeys = new HashSet<>(oldKeys);
+        needDeleteKeys.removeAll(newKeys);
+        List<T> result = new ArrayList<>();
+        oldData.stream().forEach(e -> {
+            Object key = keyFunction.apply(e);
+            if (needDeleteKeys.contains(key)) {
+                result.add(e);
+            }
+        });
+        return result;
+    }
+}

+ 69 - 0
src/main/java/com/energy/online/data/service/util/BeanTools.java

@@ -0,0 +1,69 @@
+package com.energy.online.data.service.util;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.bean.copier.CopyOptions;
+import cn.hutool.core.util.StrUtil;
+import org.springframework.cglib.core.ReflectUtils;
+import org.springframework.stereotype.Component;
+
+import java.beans.PropertyDescriptor;
+import java.util.HashMap;
+import java.util.Map;
+
+@Component
+public class BeanTools {
+
+    /**
+     * 驼峰转换
+     *
+     * @param source
+     * @param target
+     * @param <K>
+     * @param <T>
+     * @return
+     */
+    public <K, T> T copyAndParse(K source, Class<T> target) throws Exception {
+        T res = target.newInstance();
+        // 下划线转驼峰
+        BeanUtil.copyProperties(source, res, getCopyOptions(source.getClass()));
+        return res;
+    }
+
+    // 缓存CopyOptions(注意这个是HuTool的类,不是Cglib的)
+
+    private Map<Class, CopyOptions> cacheMap = new HashMap<>();
+
+    private CopyOptions getCopyOptions(Class source) {
+        CopyOptions options = cacheMap.get(source);
+        if (options == null) {
+            // 不加锁,我们认为重复执行不会比并发加锁带来的开销大
+            options = CopyOptions.create().setFieldMapping(buildFieldMapper(source));
+            cacheMap.put(source, options);
+        }
+        return options;
+    }
+
+    /**
+     * @param source
+     * @return
+     */
+    private Map<String, String> buildFieldMapper(Class source) {
+        PropertyDescriptor[] properties = ReflectUtils.getBeanProperties(source);
+        Map<String, String> map = new HashMap<>();
+        for (PropertyDescriptor target : properties) {
+            String name = target.getName();
+            String camel = StrUtil.toCamelCase(name);
+            if (!name.equalsIgnoreCase(camel)) {
+                map.put(name, camel);
+            }
+            String under = StrUtil.toUnderlineCase(name);
+            if (!name.equalsIgnoreCase(under)) {
+                map.put(name, under);
+            }
+        }
+        return map;
+    }
+
+
+
+}

+ 228 - 0
src/main/java/com/energy/online/data/service/util/DateUtils.java

@@ -0,0 +1,228 @@
+package com.energy.online.data.service.util;
+
+import cn.hutool.core.date.DateUtil;
+import org.springframework.util.StringUtils;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.time.*;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Date日期工具
+ */
+public class DateUtils {
+
+
+    public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
+
+    public static String YYYY_MM_DD = "yyyyMMdd";
+    public static ZoneOffset defultZoneOffset = ZoneOffset.of("+8");
+
+
+    static DateFormat dateFormat = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
+
+
+    static DateFormat dateFormatYdm = new SimpleDateFormat(YYYY_MM_DD);
+
+
+    public static LocalDateTime convertString2DataTime(String dateStr, String dateFormat) {
+        if (StringUtils.isEmpty(dateStr) || "0000-00-00 00:00:00".equals(dateStr)) {
+            return null;
+        }
+        if (StringUtils.isEmpty(dateFormat)) {
+            dateFormat = "yyyy-MM-dd HH:mm:ss";
+        }
+
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
+        return LocalDateTime.parse(dateStr, formatter);
+    }
+
+    /**
+     * String 转 Date 固定格式
+     *
+     * @param dateStr
+     * @param dateFormat 时间格式
+     * @return
+     */
+    public static Date convertString2Date(String dateStr, String dateFormat) {
+        if (StringUtils.isEmpty(dateStr) || "0000-00-00 00:00:00".equals(dateStr)) {
+            return null;
+        }
+        if (StringUtils.isEmpty(dateFormat)) {
+            dateFormat = "yyyy-MM-dd HH:mm";
+        }
+        ZoneId zoneId = ZoneId.systemDefault();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
+        LocalDateTime localDateTime = LocalDateTime.parse(dateStr, formatter);
+        ZonedDateTime zdt = localDateTime.atZone(zoneId);
+        Date date = Date.from(zdt.toInstant());
+        return date;
+    }
+
+    /**
+     * String 转 Date   年月日时分
+     *
+     * @param dateStr
+     * @return
+     */
+    public static Date convertString2DateYMDHM(String dateStr) {
+        return convertString2Date(dateStr, "yyyy-MM-dd HH:mm");
+    }
+
+    /**
+     * String 转 Date   年月日时分秒
+     *
+     * @param dateStr
+     * @return
+     */
+    public static Date convertString2LocalDateTimeYMDHMS(String dateStr) {
+        return convertString2Date(dateStr, "yyyy-MM-dd HH:mm:ss");
+    }
+
+
+    public static String convertLocalDateTime2StringYMD(LocalDateTime date) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        return formatter.format(date);
+    }
+
+
+    public static String convertDate2StringYMD(Date date) {
+
+
+        return dateFormatYdm.format(date);
+    }
+
+    public static String convertDate2StringYMDHMS(Date date) {
+
+
+        return dateFormat.format(date);
+    }
+
+    public static Date convertStringLocalDateYMD(String dateStr) {
+
+        ZoneId zoneId = ZoneId.systemDefault();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(YYYY_MM_DD);
+        LocalDate localDate = LocalDate.parse(dateStr, formatter);
+        ZonedDateTime zdt = localDate.atStartOfDay(zoneId);
+        return Date.from(zdt.toInstant());
+    }
+
+    /**
+     * 两个时间内的所有天数从大到小
+     */
+    public static List<LocalDate> getDescDateList(LocalDate startDate, LocalDate endDate) {
+        List<LocalDate> result = new ArrayList<>();
+        if (endDate.compareTo(startDate) < 0) {
+            return result;
+        }
+        while (true) {
+            result.add(endDate);
+            if (endDate.compareTo(startDate) <= 0) {
+                break;
+            }
+            endDate = endDate.plusDays(-1);
+        }
+        return result;
+    }
+
+    /**
+     * 两个时间内的所有天数 从小到大
+     */
+    public static List<LocalDate> getAscDateList(LocalDate startDate, LocalDate endDate) {
+        List<LocalDate> result = new ArrayList<>();
+        if (endDate.compareTo(startDate) < 0) {
+            return result;
+        }
+        while (true) {
+            result.add(startDate);
+            if (startDate.compareTo(endDate) >= 0) {
+                break;
+            }
+            startDate = startDate.plusDays(1);
+        }
+        return result;
+    }
+
+    /**
+     * 格式化秒数到时分秒
+     *
+     * @param totalSeconds 总秒数
+     * @return
+     */
+    public static String formateNoneNullTime(long totalSeconds) {
+
+        long hours = totalSeconds / 60 / 60;
+        long minute = totalSeconds / 60 % 60;
+        long seconds = totalSeconds % 60;
+        StringBuffer sb = new StringBuffer();
+        if (hours > 0) {
+            sb.append(String.format("%d时%02d分%02d秒", hours, minute, seconds));
+        } else {
+            if (minute > 0) {
+                sb.append(String.format("%d分%02d秒", minute, seconds));
+            } else {
+                sb.append(String.format("%d秒", seconds));
+            }
+        }
+        return sb.toString();
+    }
+
+
+    /**
+     * Date--》LocalDateTime
+     *
+     * @param date
+     * @param
+     * @return
+     */
+    public static LocalDateTime convertDate2DateTime(Date date) {
+
+        return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
+    }
+
+
+    /**
+     * Date--》LocalDate
+     *
+     * @param date
+     * @param
+     * @return
+     */
+    public static LocalDate convertDate2Date(Date date) {
+
+        return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+    }
+
+    /**
+     * 获取最近的日期
+     *
+     * @param lastDays      最近多少天
+     * @param containsToday 是否包含今天
+     * @param isAsc         正序还是倒序
+     * @return 最近的日期数组 yyyy-MM-dd格式
+     */
+    public static List<String> getLastDaysStr(int lastDays, boolean containsToday, boolean isAsc) {
+        List<String> list = new ArrayList<>();
+        LocalDateTime today = LocalDateTime.now();
+        int i = 0;
+        if (!containsToday) {
+            i = 1;
+            lastDays += 1;
+        }
+        for (; i < lastDays; i++) {
+            list.add(DateUtil.format(today.minusDays(i), YYYY_MM_DD));
+        }
+
+        if (isAsc) {
+            Collections.reverse(list);
+        }
+
+        return list;
+    }
+
+}

+ 63 - 0
src/main/java/com/energy/online/data/service/util/FileUtil.java

@@ -0,0 +1,63 @@
+package com.energy.online.data.service.util;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.*;
+import java.util.Set;
+
+/**
+ * 对文件的处理
+ */
+public class FileUtil {
+
+    /**
+     * 写入txt文件
+     *
+     * @param result
+     * @param fileName
+     * @return
+     */
+    public static boolean writeDataHubData(Set<String> result, String fileName) {
+        long start = System.currentTimeMillis();
+        String filePath = "/Users/shiyue/Downloads/yedu";
+        StringBuilder content = new StringBuilder();
+        boolean flag = false;
+        BufferedWriter out = null;
+        try {
+            if (result != null && !result.isEmpty() && StringUtils.isNotEmpty(fileName)) {
+                fileName += "_" + System.currentTimeMillis() + ".txt";
+                File pathFile = new File(filePath);
+                if (!pathFile.exists()) {
+                    pathFile.mkdirs();
+                }
+                String relFilePath = filePath + File.separator + fileName;
+                File file = new File(relFilePath);
+                if (!file.exists()) {
+                    file.createNewFile();
+                }
+                out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
+                for (String info : result) {
+                    out.write(info);
+                    out.newLine();
+                }
+                flag = true;
+                System.out.println("写入文件耗时:*********************************" + (System.currentTimeMillis() - start) + "毫秒");
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (out != null) {
+                try {
+                    out.flush();
+                    out.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            return flag;
+        }
+    }
+
+
+
+}

+ 78 - 0
src/main/java/com/energy/online/data/service/util/IPUtils.java

@@ -0,0 +1,78 @@
+package com.energy.online.data.service.util;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class IPUtils {
+
+    private static Logger logger = LoggerFactory.getLogger(IPUtils.class);
+
+    private static final String IP_UTILS_FLAG = ",";
+    private static final String UNKNOWN = "unknown";
+    private static final String LOCALHOST_IP = "0:0:0:0:0:0:0:1";
+    private static final String LOCALHOST_IP1 = "127.0.0.1";
+
+    /**
+     * 获取IP地址
+     * <p>
+     * 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址
+     * 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址
+     */
+    public static String getIpAddr(HttpServletRequest request) {
+        String ip = null;
+        try {
+            //以下两个获取在k8s中,将真实的客户端IP,放到了x-Original-Forwarded-For。而将WAF的回源地址放到了 x-Forwarded-For了。
+            ip = request.getHeader("X-Original-Forwarded-For");
+            if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
+                ip = request.getHeader("X-Forwarded-For");
+            }
+            //获取nginx等代理的ip
+            if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
+                ip = request.getHeader("x-forwarded-for");
+            }
+            if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
+                ip = request.getHeader("X-Real-IP");
+            }
+            if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
+                ip = request.getHeader("Proxy-Client-IP");
+            }
+            if (StringUtils.isEmpty(ip) || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
+                ip = request.getHeader("WL-Proxy-Client-IP");
+            }
+            if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
+                ip = request.getHeader("HTTP_CLIENT_IP");
+            }
+            if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
+                ip = request.getHeader("HTTP_X_FORWARDED_FOR");
+            }
+            //兼容k8s集群获取ip
+            if (StringUtils.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
+                ip = request.getRemoteAddr();
+                if (LOCALHOST_IP1.equalsIgnoreCase(ip) || LOCALHOST_IP.equalsIgnoreCase(ip)) {
+                    //根据网卡取本机配置的IP
+                    InetAddress iNet = null;
+                    try {
+                        iNet = InetAddress.getLocalHost();
+                    } catch (UnknownHostException e) {
+                        logger.error("getClientIp error: {}", e);
+                    }
+                    ip = iNet.getHostAddress();
+                }
+            }
+        } catch (Exception e) {
+            logger.error("IPUtils ERROR ", e);
+        }
+        //使用代理,则获取第一个IP地址
+        if (!StringUtils.isEmpty(ip) && ip.indexOf(IP_UTILS_FLAG) > 0) {
+            ip = ip.substring(0, ip.indexOf(IP_UTILS_FLAG));
+        }
+        logger.info("getIpAddr method end, ip: {}", ip);
+        return ip;
+    }
+
+}

+ 34 - 0
src/main/java/com/energy/online/data/service/util/IdGeneratorUtil.java

@@ -0,0 +1,34 @@
+package com.energy.online.data.service.util;
+
+public class IdGeneratorUtil {
+
+
+    public static final int DEC_INIT_LENGTH = 5;
+
+
+    public static final int DEC_SECOND_INIT_LENGTH = 8;
+
+    /**
+     * 默认8位数字
+     * @param number 实际数字
+     * @return
+     */
+    public static String zeroFillUtil(Long number) {
+
+        return String.format("%0" + DEC_INIT_LENGTH + "d", number);
+    }
+
+    /**
+     * @param number 实际数字
+     * @param digit  长度
+     * @return
+     */
+    public static String zeroFillUtil(Long number, Integer digit) {
+
+        return String.format("%0" + digit + "d", number);
+    }
+
+
+
+
+}

+ 70 - 0
src/main/java/com/energy/online/data/service/util/JwtUtil.java

@@ -0,0 +1,70 @@
+package com.energy.online.data.service.util;
+
+import com.auth0.jwt.JWT;
+import com.auth0.jwt.algorithms.Algorithm;
+import com.auth0.jwt.exceptions.JWTDecodeException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class JwtUtil {
+
+    /**
+     * 生成token
+     *
+     * @param userId
+     * @return
+     */
+    public static String getLoginToken(Integer userId, String userName, String phone, String password,Integer userRoleId) {
+        String sign = JWT.create()
+                .withClaim("userId", userId)
+                .withClaim("userName", userName)
+                .withClaim("userPhone", phone)
+                .withClaim("userPassword", password)
+                .withClaim("userRoleId", userRoleId)
+                .sign(Algorithm.HMAC256(password));
+        return sign;
+    }
+
+    /**
+     * 生成tokenV2
+     *
+     * @param loginUser
+     * @return
+     */
+//    public static String getLoginTokenV2(LoginUser loginUser) {
+//        String sign = JWT.create()
+//                .withClaim("loginUser", JSONObject.toJSONString(loginUser))
+//                .sign(Algorithm.HMAC256(loginUser.getUserPassword()));
+//        return sign;
+//    }
+
+//    public static void main(String[] args) {
+//        System.out.println(getLoginToken(1L,"jialx","13800138000", "123456"));
+//    }
+
+    /**
+     * 获取token信息
+     *
+     * @param token
+     * @return
+     */
+    public static Map<String, String> getJwtMap(String token) throws JWTDecodeException {
+        Map<String, String> map = new HashMap<>();
+        map.put("userId", String.valueOf(JWT.decode(token).getClaim("userId").asLong()));
+        map.put("userName", JWT.decode(token).getClaim("userName").asString());
+        map.put("userPhone", JWT.decode(token).getClaim("userPhone").asString());
+        map.put("userPassword", JWT.decode(token).getClaim("userPassword").asString());
+        map.put("userRoleId", String.valueOf(JWT.decode(token).getClaim("userRoleId").asInt()));
+        return map;
+    }
+
+//    public static LoginUser getJwtMapV2(String token) throws JWTDecodeException {
+//        String jsonLoginUser = String.valueOf(JWT.decode(token).getClaim("loginUser").asString());
+//        return JSON.parseObject(jsonLoginUser, LoginUser.class);
+//    }
+
+
+
+
+}

+ 73 - 0
src/main/java/com/energy/online/data/service/util/MD5Util.java

@@ -0,0 +1,73 @@
+package com.energy.online.data.service.util;
+
+import java.security.MessageDigest;
+
+/**
+ * @Author:sy
+ * @Description:
+ */
+public class MD5Util {
+
+    // MD5加码。32位
+    public static String MD5(String inStr) {
+        MessageDigest md5 = null;
+        try {
+            md5 = MessageDigest.getInstance("MD5");
+        } catch (Exception e) {
+            System.out.println(e.toString());
+            e.printStackTrace();
+            return "";
+        }
+        char[] charArray = inStr.toCharArray();
+        byte[] byteArray = new byte[charArray.length];
+
+        for (int i = 0; i < charArray.length; i++) {
+            byteArray[i] = (byte) charArray[i];
+        }
+
+        byte[] md5Bytes = md5.digest(byteArray);
+
+        StringBuffer hexValue = new StringBuffer();
+
+        for (int i = 0; i < md5Bytes.length; i++) {
+            int val = ((int) md5Bytes[i]) & 0xff;
+            if (val < 16)
+                hexValue.append("0");
+            hexValue.append(Integer.toHexString(val));
+        }
+
+        return hexValue.toString();
+    }
+
+    // 可逆的加密算法
+    public static String KL(String inStr) {
+        // String s = new String(inStr);
+        char[] a = inStr.toCharArray();
+        for (int i = 0; i < a.length; i++) {
+            a[i] = (char) (a[i] ^ 't');
+        }
+        String s = new String(a);
+        return s;
+    }
+
+    // 加密后解密
+    public static String JM(String inStr) {
+        char[] a = inStr.toCharArray();
+        for (int i = 0; i < a.length; i++) {
+            a[i] = (char) (a[i] ^ 't');
+        }
+        String k = new String(a);
+        return k;
+    }
+
+    // 测试主函数
+//    public static void main(String args[]) {
+//        String s = new String("a");
+//        System.out.println("原始:" + s);
+//        System.out.println("MD5后:" + MD5(s));
+//        System.out.println("MD5后再加密:" + KL(MD5(s)));
+//        System.out.println("解密为MD5后的:" + JM(KL(MD5(s))));
+//        System.out.println("判断是否相同:" + MD5(s).equals(JM(KL(MD5(s)))));
+//    }
+
+}

+ 57 - 0
src/main/java/com/energy/online/data/service/util/NetUtils.java

@@ -0,0 +1,57 @@
+package com.energy.online.data.service.util;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author chy
+ * @date 2024/7/9 14:08
+ * @desc
+ */
+public class NetUtils {
+
+
+    /**
+     * 内网前缀
+     */
+    private final static String INTRANET_PREFIX = "192.168";
+
+    /**
+     * 内网前缀
+     */
+    private final static String LOCAL_PREFIX = "127.0.0";
+
+    /**
+     * ip:port 正则
+     */
+    private final static String IP_PORT_REGEX = "^(http[s]?://)?([^:/\\s]+)(:)+[0-9]{1,}/";
+
+
+    /**
+     * 判断当前host 是否是内网
+     * @param ip
+     * @return
+     */
+    public static boolean isIntranet(String ip) {
+        if(StringUtils.isBlank(ip)){
+            return false;
+        }
+        return StringUtils.startsWithAny(ip,INTRANET_PREFIX,LOCAL_PREFIX);
+    }
+
+    /**
+     * 根据url获取IP地址与端口号
+     * @param url
+     * @return
+     */
+    public static String getIpAndPort(String url){
+        if(StringUtils.isBlank(url)){
+            return null;
+        }
+        Pattern p = Pattern.compile(IP_PORT_REGEX);
+        Matcher matcher = p.matcher(url);
+        return matcher.find() ? matcher.group() : null ;
+    }
+}

+ 85 - 0
src/main/java/com/energy/online/data/service/util/RandomSeriUtil.java

@@ -0,0 +1,85 @@
+package com.energy.online.data.service.util;
+
+import org.springframework.util.StringUtils;
+
+import java.math.BigDecimal;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ThreadLocalRandom;
+
+public class RandomSeriUtil {
+
+  /**
+   * 生成随机六位数,用作验证码
+   *
+   * @return
+   */
+  public static String genRandoms() {
+    return String.valueOf(ThreadLocalRandom.current().nextInt(100000, 999999));
+  }
+
+  /**
+   * 生成随机六位数,用作验证码
+   *
+   * @return
+   */
+  public static String genRandoms1_10() {
+    return String.valueOf(ThreadLocalRandom.current().nextInt(1, 11));
+  }
+
+
+  /**
+   * 字符串占位符
+   *
+   * @param str
+   * @param arguments
+   * @return
+   */
+  public static String formatStr(String str, Object... arguments) {
+    return MessageFormat.format(str, arguments);
+  }
+
+
+  /**
+   * 内部方法,不丢精度还原物品价格
+   *
+   * @param price
+   * @return
+   */
+  public static int getItemPrice(String price) {
+    if (StringUtils.isEmpty(price)) {
+      return 0;
+    }
+    BigDecimal temp = BigDecimal.valueOf(Double.valueOf(price));
+    temp = temp.multiply(BigDecimal.valueOf(100));
+    return temp.intValue();
+  }
+
+
+  /**
+   * 随机数
+   *
+   * @param count
+   * @return
+   */
+  public static List<Long> createRandomByCount(int count, long max) {
+    count = count * 10;
+    Set<Long> set = new HashSet<>();
+    for (int i = 0; i < count; i++) {
+      long item = genRandoms(max);
+      set.add(item);
+    }
+    List<Long> idList = new ArrayList<>(count * 2);
+    set.stream().forEach(item -> {
+      idList.add(item);
+    });
+    return idList;
+  }
+
+  public static long genRandoms(long max) {
+    return ThreadLocalRandom.current().nextLong(1, max);
+  }
+}

+ 38 - 0
src/main/java/com/energy/online/data/service/util/SpringTools.java

@@ -0,0 +1,38 @@
+package com.energy.online.data.service.util;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SpringTools implements ApplicationContextAware {
+
+    private static ApplicationContext _applicationContext;
+
+    public SpringTools() { }
+
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        if (_applicationContext == null) {
+            _applicationContext = applicationContext;
+        }
+
+    }
+
+    public static ApplicationContext getApplicationContext() {
+        return _applicationContext;
+    }
+
+    public static Object getBean(String name) {
+        return getApplicationContext().getBean(name);
+    }
+
+    public static <T> T getBean(Class<T> clazz) {
+        return getApplicationContext().getBean(clazz);
+    }
+
+    public static <T> T getBean(String name, Class<T> clazz) {
+        return getApplicationContext().getBean(name, clazz);
+    }
+}

+ 104 - 0
src/main/java/com/energy/online/data/service/util/UUIDUtil.java

@@ -0,0 +1,104 @@
+package com.energy.online.data.service.util;
+
+import org.springframework.util.StringUtils;
+
+import java.util.UUID;
+
+public class UUIDUtil {
+
+  /**
+   * 获取32位 uuid
+   *
+   * @return
+   */
+  public static String getUUID() {
+    String uuid = UUID.randomUUID().toString();
+    if (!StringUtils.isEmpty(uuid)) {
+      uuid = uuid.replaceAll("-", "");
+    }
+    return uuid;
+  }
+
+  /**
+   * 获取32位大写 uuid
+   *
+   * @return
+   */
+  public static String getUUIDUpperCase() {
+    String uuid = UUID.randomUUID().toString();
+    if (!StringUtils.isEmpty(uuid)) {
+      uuid = uuid.replaceAll("-", "");
+    }
+    return uuid.toUpperCase();
+  }
+
+  /**
+   * 获取32位小写 uuid
+   *
+   * @return
+   */
+  public static String getUUIDLowCase() {
+    String uuid = UUID.randomUUID().toString();
+    if (!StringUtils.isEmpty(uuid)) {
+      uuid = uuid.replaceAll("-", "");
+    }
+    return uuid.toLowerCase();
+  }
+
+
+  private static String[] chars = new String[]{"a", "b", "c", "d", "e", "f",
+          "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
+          "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5",
+          "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I",
+          "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
+          "W", "X", "Y", "Z"};
+
+
+  /**
+   * 生成8位UUID
+   *
+   * @return
+   */
+  public static String getShortUUID() {
+    StringBuffer shortBuffer = new StringBuffer();
+    String uuid = getUUID();
+    for (int i = 0; i < 8; i++) {
+      String str = uuid.substring(i * 4, i * 4 + 4);
+      int x = Integer.parseInt(str, 16);
+      shortBuffer.append(chars[x % 0x3E]);
+    }
+    return shortBuffer.toString();
+  }
+
+  /**
+   * 生成8位大写UUID
+   *
+   * @return
+   */
+  public static String getShortUUIDUpperCase() {
+    StringBuffer shortBuffer = new StringBuffer();
+    String uuid = getUUID();
+    for (int i = 0; i < 8; i++) {
+      String str = uuid.substring(i * 4, i * 4 + 4);
+      int x = Integer.parseInt(str, 16);
+      shortBuffer.append(chars[x % 0x3E]);
+    }
+    return shortBuffer.toString().toUpperCase();
+  }
+
+  /**
+   * 生成8位小写UUID
+   *
+   * @return
+   */
+  public static String getShortUUIDLowCase() {
+    StringBuffer shortBuffer = new StringBuffer();
+    String uuid = getUUID();
+    for (int i = 0; i < 8; i++) {
+      String str = uuid.substring(i * 4, i * 4 + 4);
+      int x = Integer.parseInt(str, 16);
+      shortBuffer.append(chars[x % 0x3E]);
+    }
+    return shortBuffer.toString().toLowerCase();
+  }
+}

+ 17 - 0
src/main/java/com/energy/online/data/service/vo/InformationDataVo.java

@@ -0,0 +1,17 @@
+package com.energy.online.data.service.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class InformationDataVo {
+
+
+    private Integer dataPoin;
+
+    private String dataValue;
+
+
+
+}

+ 125 - 0
src/main/resources/application.properties

@@ -0,0 +1,125 @@
+# 服务端口
+server.port = 16500
+#数据库设置
+spring.datasource.type = com.alibaba.druid.pool.DruidDataSource
+spring.datasource.druid.driver-class-name = com.mysql.jdbc.Driver
+#spring.datasource.druid.driver-class-name = com.mysql.cj.jdbc.Driver
+spring.datasource.druid.url = jdbc:mysql://192.168.50.235:30306/appoint?useUnicode=true&characterEncoding=UTF-8&     #allowMultiQueries=true&rewriteBatchedStatements=true&useSSL=false&allowPublicKeyRetrieval=true
+spring.datasource.druid.username = root
+spring.datasource.druid.password = admin123456
+#初始化大小
+spring.datasource.druid.initial-size = 30
+#最小
+spring.datasource.druid.min-idle = 20
+#最大
+spring.datasource.druid.max-active = 300
+#获取连接等待的超时时间
+spring.datasource.druid.max-wait = 600000
+#间隔多久进行一次检测,检测需要关闭的链接
+spring.datasource.druid.time-between-eviction-runs-millis = 60000
+#一个链接在池中最小生存时间
+spring.datasource.druid.min-evictable-idle-time-millis = 3000000
+##配置连接在池中的最大生存时间
+#spring.datasource.druid.max-evictable-idle-time-millis = 400000
+spring.datasource.druid.validation-query = SELECT 'x'
+spring.datasource.druid.test-on-borrow = false
+spring.datasource.druid.test-on-return = false
+## 启用空闲连接检测,以便回收
+spring.datasource.druid.test-while-idle = true
+## 打开PSCache,并且指定每个连接上PSCache的大小
+spring.datasource.druid.pool-prepared-statements = false
+spring.datasource.druid.max-pool-prepared-statement-per-connection-size = 20
+spring.datasource.druid.remove-abandoned = true
+spring.datasource.druid.remove-abandoned-timeout = 7200
+spring.datasource.druid.log-abandoned = false
+
+#redis-config
+spring.redis.jedis.pool.max-idle = 100
+spring.redis.jedis.pool.min-idle = 10
+spring.redis.jedis.pool.max-active = 1000
+spring.redis.jedis.pool.max-wait = 100000
+spring.redis.database = 1
+spring.redis.host = 192.168.50.233
+spring.redis.port = 6379
+spring.redis.password = 123456
+
+
+#============================应用配置=========================================
+# 项目环境
+spring.profiles.active = @profiles.active@
+# 应用名称
+spring.application.name = energy-online-data-service
+
+# 上下文路径
+server.servlet.context-path = /energy-online-data-service/
+
+#=============================tomcat配置=======================================
+#uri编码格式
+server.tomcat.uri-encoding = UTF-8
+# 最大连接数
+server.tomcat.max-connections=100000
+# 最小空闲线程数
+server.tomcat.threads.min-spare=100
+# 最大线程数
+server.tomcat.threads.max=800
+# 当tomcat启动线程达到最大时,允许的最大排队请求个数
+server.tomcat.accept-count = 1000
+# server.tomcat.basedir = /opt/projecttmp
+server.maxHttpHeaderSize = 8192
+#请求数据量
+server.tomcat.max-http-form-post-size = 200MB
+#超时时间
+server.tomcat.connection-timeout = 180000
+
+
+#=============================日志配置=======================================
+# 日志路径(环境)
+path.log = @profiles.active@
+# debug - sql显示
+logging.level.com.energy.manage.service.mappers= debug
+
+#=============================banner配置=======================================
+#banner路径
+spring.banner.location=classpath:banner/banner.txt
+
+#============================mybatis配置=========================================
+#扫描mapper.xml
+mybatis.mapper-locations = classpath*:mybatis/**/*.xml
+mybatis.type-aliases-package = com.energy.online.data.service.po
+mybatis.configuration.mapUnderscoreToCamelCase = true
+#sql日志打印
+#mybatis.configuration.log-impl = org.apache.ibatis.logging.stdout.StdOutImpl
+#mappers 多个接口时逗号隔开
+mapper.mappers = com.energy.online.data.service.common.mappers.MyMapper
+mapper.not-empty =false
+mapper.identity = MYSQL
+#分页
+pagehelper.helperDialect = mysql
+pagehelper.reasonable = true
+pagehelper.supportMethodsArguments = true
+
+#============================swagger配置=========================================
+#http://localhost/energy-manage-service/doc.html
+knife4j.enable=true
+
+#============================文件上传配置=========================================
+# 自定义配置文件上传
+spring.servlet.multipart.enabled = true
+spring.servlet.multipart.max-file-size = 314572800
+spring.servlet.multipart.max-request-size= 1048576000
+
+#============================json配置=========================================
+# 全局时间格式转化
+#spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
+#spring.jackson.time-zone=GMT+8
+spring.jackson.date-format = yyyy-MM-dd HH:mm
+spring.jackson.time-zone= GMT+8
+spring.jackson.serialization.write-dates-as-timestamps=true
+
+#============== 定时器守屋进程
+#0 0,12 * * * /path/to/your/script.sh
+#*/5 * * * * /path/to/your/script.sh
+#==============
+
+
+

+ 22 - 0
src/main/resources/banner/banner.txt

@@ -0,0 +1,22 @@
+-- Created by shiyue
+
+                                       _ooOoo_
+                                      o8888888o
+                                      88" . "88
+                                      (| -_- |)
+                                      O\  =  /O
+                                   ____/`---'\____
+                                 .'  \\|     |//  `.
+                                /  \\|||  :  |||//  \
+                               /  _||||| -:- |||||-  \
+                               |   | \\\  -  /// |   |
+                               | \_|  ''\---/''  |   |
+                               \  .-\__  `-`  ___/-. /
+                             ___`. .'  /--.--\  `. . __
+                          ."" '<  `.___\_<|>_/___.'  >'"".
+                         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
+                         \  \ `-.   \_ __\ /__ _/   .-` /  /
+                    ======`-.____`-.___\_____/___.-`____.-'======
+                                       `=---='
+                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+                             佛祖保佑               永无BUG

+ 13 - 0
src/main/resources/logback.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+               xsi:noNamespaceSchemaLocation="http://www.padual.com/java/logback.xsd">
+
+    <property resource="application.properties"/>
+    <springProperty scope="context" name="path.log" source="path.log"/>
+
+    <!-- 日志最大的历史 30天 -->
+    <property name="maxHistory" value="30"/>
+    <property name="maxFileSize" value="64 MB"/>
+    <include resource="logback/logback-${path.log}.xml"/>
+
+</configuration>

+ 162 - 0
src/main/resources/logback/logback-dev.xml

@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<included>
+    <!-- 定义日志文件 输入位置 -->
+    <springProperty name="log_dir" source="logging.path" defaultValue="./logs"/>
+    <property name="log.pattern"
+              value="%d{yyyy-MM-dd HH:mm:ss.SSS} %X{THREAD_NOTE} [%thread] %-5level %logger - %msg%n"/>
+    <property name="log.maxHistory" value="3" />
+
+    <!--# Console -->
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <!-- 典型的日志pattern -->
+        <encoder>
+            <pattern>[%-5level %d{HH:mm:ss.SSS} | %X{THREAD_NOTE} | %thread | %logger.%method] [%L] - %msg%n</pattern>
+            <charset>UTF-8</charset> <!-- 此处设置字符集 -->
+        </encoder>
+    </appender>
+
+    <!-- ERROR级别日志 -->
+    <!-- 滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 RollingFileAppender-->
+    <appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录WARN级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>ERROR</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+
+        <!-- 最常用的滚动策略,它根据时间来制定滚动策略.既负责滚动也负责出发滚动 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!--日志输出位置  可相对、和绝对路径 -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/error.log</fileNamePattern>
+            <!-- 可选节点,控制保留的归档文件的最大数量,超出数量就删除旧文件假设设置每个月滚动,且<maxHistory>是6,
+            则只保存最近6个月的文件,删除之前的旧文件。注意,删除旧文件是,那些为了归档而创建的目录也会被删除-->
+            <maxHistory>${log.maxHistory}</maxHistory>
+        </rollingPolicy>
+    </appender>
+
+    <!-- WARN级别日志 appender -->
+    <appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录WARN级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>WARN</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+
+
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 按天回滚 daily -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/warn.log
+            </fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>${log.maxHistory}</maxHistory>
+        </rollingPolicy>
+
+    </appender>
+
+    <!-- INFO级别日志 appender -->
+    <appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录INFO级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>INFO</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 按天回滚 daily -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/info.log
+            </fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>${log.maxHistory}</maxHistory>
+        </rollingPolicy>
+
+
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+    </appender>
+
+    <!-- DEBUG级别日志 appender -->
+    <appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录DEBUG级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>DEBUG</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 按天回滚 daily -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/debug.log
+            </fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>${log.maxHistory}</maxHistory>
+            >
+        </rollingPolicy>
+
+    </appender>
+
+    <!-- TRACE级别日志 appender -->
+    <appender name="TRACE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录ERROR级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>TRACE</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 按天回滚 daily -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/trace.log
+            </fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>${log.maxHistory}</maxHistory>
+
+        </rollingPolicy>
+        >
+    </appender>
+
+    <!--myibatis log configure-->
+    <logger name="com.apache.ibatis" level="TRACE"/>
+    <logger name="java.sql.Connection" level="DEBUG"/>
+    <logger name="java.sql.Statement" level="DEBUG"/>
+    <logger name="java.sql.PreparedStatement" level="DEBUG"/>
+
+    <!-- root级别   DEBUG -->
+    <root level="INFO">
+        <!-- 控制台输出 STDOUT-->
+        <appender-ref ref="STDOUT"/>
+        <appender-ref ref="DEBUG"/>
+        <!-- 文件输出 -->
+        <appender-ref ref="ERROR"/>
+        <appender-ref ref="INFO"/>
+        <appender-ref ref="WARN"/>
+        <appender-ref ref="DEBUG"/>
+        <appender-ref ref="TRACE"/>
+    </root>
+
+</included>

+ 164 - 0
src/main/resources/logback/logback-prod.xml

@@ -0,0 +1,164 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<included>
+    <!-- 定义日志文件 输入位置 -->
+    <springProperty name="log_dir" source="logging.path" defaultValue="./logs"/>
+    <property name="log.pattern"
+              value="%d{yyyy-MM-dd HH:mm:ss.SSS} %X{THREAD_NOTE} [%thread] %-5level %logger - %msg%n"/>
+    <property name="log.maxHistory" value="90" />
+
+    <!--# Console -->
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <!-- 典型的日志pattern -->
+        <encoder>
+            <pattern>[%-5level %d{HH:mm:ss.SSS} | %X{THREAD_NOTE} | %thread | %logger.%method] [%L] - %msg%n</pattern>
+            <charset>UTF-8</charset> <!-- 此处设置字符集 -->
+        </encoder>
+    </appender>
+
+    <!-- ERROR级别日志 -->
+    <!-- 滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 RollingFileAppender-->
+    <appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录WARN级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>ERROR</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+
+        <!-- 最常用的滚动策略,它根据时间来制定滚动策略.既负责滚动也负责出发滚动 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!--日志输出位置  可相对、和绝对路径 -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/error.log</fileNamePattern>
+            <!-- 可选节点,控制保留的归档文件的最大数量,超出数量就删除旧文件假设设置每个月滚动,且<maxHistory>是6,
+            则只保存最近6个月的文件,删除之前的旧文件。注意,删除旧文件是,那些为了归档而创建的目录也会被删除-->
+            <maxHistory>${log.maxHistory}</maxHistory>
+        </rollingPolicy>
+    </appender>
+
+    <!-- WARN级别日志 appender -->
+    <appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录WARN级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>WARN</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+
+
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 按天回滚 daily -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/warn.log
+            </fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>${log.maxHistory}</maxHistory>
+
+        </rollingPolicy>
+
+    </appender>
+
+    <!-- INFO级别日志 appender -->
+    <appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录INFO级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>INFO</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 按天回滚 daily -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/info.log
+            </fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>${log.maxHistory}</maxHistory>
+        </rollingPolicy>
+
+
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+    </appender>
+
+    <!-- DEBUG级别日志 appender -->
+    <appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录DEBUG级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>DEBUG</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 按天回滚 daily -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/debug.log
+            </fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>${log.maxHistory}</maxHistory>
+            >
+        </rollingPolicy>
+
+    </appender>
+
+    <!-- TRACE级别日志 appender -->
+    <appender name="TRACE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录ERROR级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>TRACE</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 按天回滚 daily -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/trace.log
+            </fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>${log.maxHistory}</maxHistory>
+
+        </rollingPolicy>
+        >
+    </appender>
+
+    <!--myibatis log configure-->
+    <logger name="com.apache.ibatis" level="TRACE"/>
+    <logger name="java.sql.Connection" level="DEBUG"/>
+    <logger name="java.sql.Statement" level="DEBUG"/>
+    <logger name="java.sql.PreparedStatement" level="DEBUG"/>
+
+    <!-- root级别   DEBUG -->
+    <root level="INFO">
+        <!-- 控制台输出 STDOUT-->
+        <appender-ref ref="STDOUT"/>
+        <appender-ref ref="DEBUG"/>
+        <!-- 文件输出 -->
+        <appender-ref ref="ERROR"/>
+        <appender-ref ref="INFO"/>
+        <appender-ref ref="WARN"/>
+        <appender-ref ref="DEBUG"/>
+        <appender-ref ref="TRACE"/>
+    </root>
+
+</included>
+

+ 162 - 0
src/main/resources/logback/logback-test.xml

@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<included>
+    <!-- 定义日志文件 输入位置 -->
+    <springProperty name="LOG_PATH" source="logging.path" defaultValue="./logs"/>
+    <property name="log.pattern"
+              value="%d{yyyy-MM-dd HH:mm:ss.SSS} %X{THREAD_NOTE} [%thread] %-5level %logger - %msg%n"/>
+    <property name="log.maxHistory" value="90" />
+
+    <!--# Console -->
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <!-- 典型的日志pattern -->
+        <encoder>
+            <pattern>[%-5level %d{HH:mm:ss.SSS} | %X{THREAD_NOTE} | %thread | %logger.%method] [%L] - %msg%n</pattern>
+            <charset>UTF-8</charset> <!-- 此处设置字符集 -->
+        </encoder>
+    </appender>
+
+    <!-- ERROR级别日志 -->
+    <!-- 滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 RollingFileAppender-->
+    <appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录WARN级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>ERROR</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+
+        <!-- 最常用的滚动策略,它根据时间来制定滚动策略.既负责滚动也负责出发滚动 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!--日志输出位置  可相对、和绝对路径 -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/error.log</fileNamePattern>
+            <!-- 可选节点,控制保留的归档文件的最大数量,超出数量就删除旧文件假设设置每个月滚动,且<maxHistory>是6,
+            则只保存最近6个月的文件,删除之前的旧文件。注意,删除旧文件是,那些为了归档而创建的目录也会被删除-->
+            <maxHistory>${log.maxHistory}</maxHistory>
+        </rollingPolicy>
+    </appender>
+
+    <!-- WARN级别日志 appender -->
+    <appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录WARN级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>WARN</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+
+
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 按天回滚 daily -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/warn.log
+            </fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>${log.maxHistory}</maxHistory>
+        </rollingPolicy>
+
+    </appender>
+
+    <!-- INFO级别日志 appender -->
+    <appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录INFO级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>INFO</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 按天回滚 daily -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/info.log
+            </fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>${log.maxHistory}</maxHistory>
+        </rollingPolicy>
+
+
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+    </appender>
+
+    <!-- DEBUG级别日志 appender -->
+    <appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录DEBUG级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>DEBUG</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 按天回滚 daily -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/debug.log
+            </fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>${log.maxHistory}</maxHistory>
+            >
+        </rollingPolicy>
+
+    </appender>
+
+    <!-- TRACE级别日志 appender -->
+    <appender name="TRACE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 过滤器,只记录ERROR级别的日志 -->
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>TRACE</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+            <!-- 此处设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 按天回滚 daily -->
+            <fileNamePattern>${log_dir}/%d{yyyy-MM-dd}/trace.log
+            </fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>${log.maxHistory}</maxHistory>
+
+        </rollingPolicy>
+      >
+    </appender>
+
+    <!--myibatis log configure-->
+    <logger name="com.apache.ibatis" level="TRACE"/>
+    <logger name="java.sql.Connection" level="DEBUG"/>
+    <logger name="java.sql.Statement" level="DEBUG"/>
+    <logger name="java.sql.PreparedStatement" level="DEBUG"/>
+
+    <!-- root级别   DEBUG -->
+    <root level="INFO">
+        <!-- 控制台输出 STDOUT-->
+        <appender-ref ref="STDOUT"/>
+        <appender-ref ref="DEBUG"/>
+        <!-- 文件输出 -->
+        <appender-ref ref="ERROR"/>
+        <appender-ref ref="INFO"/>
+        <appender-ref ref="WARN"/>
+        <appender-ref ref="DEBUG"/>
+        <appender-ref ref="TRACE"/>
+    </root>
+
+</included>

+ 64 - 0
src/main/resources/mybatis/measurement/MeasurementMapper.xml

@@ -0,0 +1,64 @@
+<?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.energy.online.data.service.mapper.MeasurementMapper">
+
+    <!-- 查询数据表是否存在 -->
+    <select id="selectTableCountByTableName" resultType="java.lang.Integer">
+        SELECT COUNT(1)
+        FROM information_schema.tables
+        WHERE
+        table_schema = 'appoint' AND table_name = #{tableName}
+    </select>
+
+    <!-- 动态创建表 -->
+    <update id="createTable" parameterType="java.lang.String">
+        CREATE TABLE IF NOT EXISTS  <![CDATA[ ${tableName} ]]> (
+        id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+        receive_time datetime DEFAULT NULL,
+        time BIGINT(20) NULL DEFAULT NULL,
+        common_address int(11) DEFAULT NULL,
+        information_object_data mediumtext,
+        information_object_size int(11) DEFAULT NULL,
+        information_ip VARCHAR(32) DEFAULT NULL,
+        PRIMARY KEY (id)
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
+    </update>
+
+
+    <!-- 插入数据 -->
+    <insert id="insertTableData">
+        insert into <![CDATA[ ${tableName} ]]>
+         (
+            `receive_time`,
+            `time`,
+            `common_address`,
+            `information_object_data`,
+            `information_object_size`,
+            `information_ip`
+        )
+        VALUES
+        (
+            #{item.receiveTime},
+            #{item.time},
+            #{item.commonAddress},
+            #{item.informationObjectData},
+             #{item.informationObjectSize},
+            #{item.informationIp}
+        )
+
+    </insert>
+
+
+
+    <select id="selectMeasurementTempByid" resultType="java.lang.Long">
+        select receipt_time as receiptTime  from measurement_temp where conf_id = #{confId}  order by id desc limit 1
+    </select>
+
+
+    <update id="truncateMeasurementTempTable">
+        truncate table measurement_temp
+    </update>
+
+
+</mapper>