diff --git a/dataManage.iml b/dataManage.iml
new file mode 100644
index 0000000..5afa10c
--- /dev/null
+++ b/dataManage.iml
@@ -0,0 +1,284 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..0abb856
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,246 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.0.6.RELEASE
+
+
+
+ com.drht
+ dataManage
+ war
+ 1.0-SNAPSHOT
+
+ dataManage
+
+
+
+ 1.8
+ Finchley.SR3
+
+ 2.5.0
+ 1.8.7
+
+ 3.3.1.tmp
+ 3.3.1.tmp
+
+
+
+ com.corundumstudio.socketio
+ netty-socketio
+ 1.7.13
+
+
+ io.netty
+ netty-common
+
+
+ io.netty
+ netty-transpor
+
+
+ io.netty
+ netty-buffer
+
+
+ io.netty
+ netty-handler
+
+
+ io.netty
+ netty-codec-http
+
+
+ io.netty
+ netty-codec
+
+
+ io.netty
+ netty-resolver
+
+
+ io.netty
+ netty-transport
+
+
+ io.netty
+ netty-transport-native-epoll
+
+
+
+
+ io.netty
+ netty-all
+ 4.1.98.Final
+
+
+ com.alibaba
+ fastjson
+ 1.2.83
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+
+
+
+
+
+
+
+
+
+ javax.servlet
+ javax.servlet-api
+ 3.1.0
+ provided
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ ${mybatis-plus.version}
+
+
+ com.drhb
+ common
+ 1.0-SNAPSHOT
+
+
+ mysql
+ mysql-connector-java
+ runtime
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+
+ cn.hutool
+ hutool-all
+ 5.3.9
+
+
+ com.google.code.gson
+ gson
+ 2.8.5
+
+
+
+ io.springfox
+ springfox-swagger2
+ ${swagger.version}
+
+
+ com.github.xiaoymin
+ swagger-bootstrap-ui
+ ${swagger.ui.version}
+
+
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ ${spring-cloud.version}
+ pom
+ import
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ 1.4.2.RELEASE
+
+
+ com.drht.datamanage.DataManageApplication
+
+
+
+
+ repackage
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ 3.2.3
+
+ false
+
+
+
+
+
+
+
+ src/main/java
+
+
+
+ **/*.xml
+
+
+
+ false
+
+
+
+
+ src/main/resources
+
+ **/*.xml
+ **/*.properties
+
+
+
+
+
+
+
+
+ nexus
+ Nexus Repository
+ http://39.98.199.134:8081/repository/maven-public/
+
+ true
+
+
+ true
+
+
+
+
+
+
+ nexus
+ Nexus Plugin Repository
+ http://39.98.199.134:8081/repository/maven-public/
+
+ true
+
+
+ true
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/drht/datamanage/App.java b/src/main/java/com/drht/datamanage/App.java
new file mode 100644
index 0000000..c2f3cc6
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/App.java
@@ -0,0 +1,75 @@
+package com.drht.datamanage;
+
+import com.drht.datamanage.handler.CheckDeviceInChannelHandler;
+import com.drht.datamanage.handler.CheckMsgInChannelHandler;
+import com.drht.datamanage.handler.ReplyDeviceInChannelHandler;
+import com.drht.datamanage.handler.SendChannelHandler;
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.*;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.codec.LineBasedFrameDecoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+import io.netty.handler.timeout.ReadTimeoutHandler;
+import lombok.extern.slf4j.Slf4j;
+
+import static io.netty.channel.ChannelOption.ALLOCATOR;
+
+/**
+ *
+ *
+ */
+@Slf4j
+public class App {
+
+ public static void run() {
+ log.info("初始化netty");
+ // accept线程组,用来接受连接
+ EventLoopGroup bossGroup = new NioEventLoopGroup(1);
+
+ // I/O线程组, 用于处理业务逻辑
+ EventLoopGroup workerGroup = new NioEventLoopGroup(1);
+
+ try {
+ // 服务端启动引导
+ ServerBootstrap b = new ServerBootstrap();
+
+ b.group(bossGroup, workerGroup) // 绑定两个线程组
+ .channel(NioServerSocketChannel.class) // 指定通道类型
+ .option(ChannelOption.SO_BACKLOG, 10) // 设置TCP连接的缓冲区
+ .option(ChannelOption.RCVBUF_ALLOCATOR,new FixedRecvByteBufAllocator(1000*1024))
+ .handler(new LoggingHandler(LogLevel.INFO)) // 设置日志级别
+ .childHandler(
+ new ChannelInitializer() {
+ @Override
+ protected void initChannel(SocketChannel socketChannel) throws Exception {
+ ChannelPipeline pipeline = socketChannel.pipeline(); // 获取处理器链
+ pipeline.addLast(new LineBasedFrameDecoder(1000*1024)); // 读取第一步处理,功能是一次读一行
+ pipeline.addLast(new StringDecoder()); // 转成字符串
+ pipeline.addLast(new StringEncoder()); // 编码成二进制
+ pipeline.addLast(new SendChannelHandler()); // 发送消息
+ pipeline.addLast(new ReadTimeoutHandler(90)); // 超时处理,90秒未接收到数据认为设备离线
+ pipeline.addLast(new CheckMsgInChannelHandler()); // 检查消息格式、crc校验等
+ pipeline.addLast(new CheckDeviceInChannelHandler()); // 检查设备是否可用
+ pipeline.addLast(new ReplyDeviceInChannelHandler()); // 回复消息
+ }
+ });
+
+ // 通过bind启动服务
+ ChannelFuture f = b.bind(7001).sync();
+ // 阻塞主线程,知道网络服务被关闭
+ f.channel().closeFuture().sync();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ workerGroup.shutdownGracefully();
+ bossGroup.shutdownGracefully();
+ }
+ }
+}
+
diff --git a/src/main/java/com/drht/datamanage/DataManageApplication.java b/src/main/java/com/drht/datamanage/DataManageApplication.java
new file mode 100644
index 0000000..4d14e3a
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/DataManageApplication.java
@@ -0,0 +1,19 @@
+package com.drht.datamanage;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+@SpringBootApplication
+@EnableFeignClients
+@Slf4j
+public class DataManageApplication{
+ public static void main(String[] args) {
+ SpringApplication.run(DataManageApplication.class, args);
+ }
+}
diff --git a/src/main/java/com/drht/datamanage/ServletInitializer.java b/src/main/java/com/drht/datamanage/ServletInitializer.java
new file mode 100644
index 0000000..8fa8cf0
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/ServletInitializer.java
@@ -0,0 +1,12 @@
+package com.drht.datamanage;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+
+public class ServletInitializer extends SpringBootServletInitializer {
+
+ @Override
+ protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+ return application.sources(DataManageApplication.class);
+ }
+
+}
diff --git a/src/main/java/com/drht/datamanage/base/Base.xml b/src/main/java/com/drht/datamanage/base/Base.xml
new file mode 100644
index 0000000..e10b9f7
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/base/Base.xml
@@ -0,0 +1,185 @@
+
+
+
+
+ ${hql}
+
+
+ ${returnClause}
+
+
+
+ ${joinon.style} JOIN ${joinon.table} ON ${joinon.table}.${joinon.field} =
+
+
+ ${table}.${joinon.field}
+ ${table}.${joinon.tofield}
+
+
+ ${joinon.totable}.${joinon.tofield}
+
+
+
+ AND ${joinon.param}
+
+
+
+
+
+
+
+
+
+ AND ${table}.${criterion.condition}
+
+
+ AND ${table}.${criterion.condition}
+ #{criterion.value}
+
+
+ AND ${table}.${criterion.condition}
+ #{criterion.value} AND #{criterion.secondValue}
+
+
+ AND ${table}.${criterion.condition}
+
+ #{listItem}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ INSERT INTO ${table}
+
+
+
+ f_${mod.varName},
+
+
+
+
+
+
+ #{mod.varValue},
+
+
+
+
+
+
+
+ UPDATE ${table}
+
+
+
+ f_${mod.varName} = #{mod.varValue},
+
+
+
+ f_${mod.varName} = f_version+1,
+
+
+
+ WHERE f_${model[0].varName} = #{model[0].varValue} and f_version=#{version}
+
+
+
+
+ UPDATE ${list[0].table}
+
+
+
+ ${mod.varName} = CASE ${list[0].model[0].varName}
+
+
+ WHEN '${i.model[0].varValue}' THEN '${i.model[index].varValue}'
+
+
+ END,
+
+
+
+ WHERE ${list[0].model[0].varName} IN
+
+ #{i.model[0].varValue}
+
+
+
+
+
+ DELETE FROM ${table}
+ WHERE f_${model[0].varName} = #{model[0].varValue}
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/drht/datamanage/cache/ChannelIntCache.java b/src/main/java/com/drht/datamanage/cache/ChannelIntCache.java
new file mode 100644
index 0000000..906f73b
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/cache/ChannelIntCache.java
@@ -0,0 +1,21 @@
+package com.drht.datamanage.cache;
+
+import io.netty.channel.ChannelHandlerContext;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ChannelIntCache {
+
+ private static Map cache=new HashMap<>();
+
+ private ChannelIntCache() {
+
+ }
+
+ public static Map getCache() {
+ return cache;
+ }
+
+
+}
diff --git a/src/main/java/com/drht/datamanage/cache/CommandInitCache.java b/src/main/java/com/drht/datamanage/cache/CommandInitCache.java
new file mode 100644
index 0000000..99074f8
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/cache/CommandInitCache.java
@@ -0,0 +1,90 @@
+package com.drht.datamanage.cache;
+
+import com.drht.datamanage.protocols.*;
+import com.drht.datamanage.service.Reply;
+import com.drht.datamanage.service.Send;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Service
+public class CommandInitCache {
+
+ private static Map replyCache=new HashMap<>();
+
+ private static Map sendCache=new HashMap<>();
+
+
+
+ private static Cn2601 cn2601;
+ private static Cn9015 cn9015;
+ private static Cn0001 cn0001;
+ private static Cn2051 cn2051;
+ private static Cn2011 cn2011;
+
+ public static Cn9015 getCn9015() {
+ return cn9015;
+ }
+
+ @Autowired
+ public void setCn9900(Cn9015 cn9015) {
+ CommandInitCache.cn9015 = cn9015;
+ }
+
+ public Cn2601 getCn2601() {
+ return cn2601;
+ }
+ @Autowired
+ public void setCn2601(Cn2601 cn2601) {
+ CommandInitCache.cn2601 = cn2601;
+ }
+
+ public Cn2011 getCn2011() {
+ return cn2011;
+ }
+ @Autowired
+ public void setCn2011(Cn2011 cn2011) {
+ CommandInitCache.cn2011 = cn2011;
+ }
+
+ public Cn2051 getCn2051() {
+ return cn2051;
+ }
+
+ @Autowired
+ public void setCn2051(Cn2051 cn2051) {
+ CommandInitCache.cn2051 = cn2051;
+ }
+
+ public static Cn0001 getCn0001() {
+ return cn0001;
+ }
+ @Autowired
+ public void setCn0001(Cn0001 cn0001) {
+ CommandInitCache.cn0001 = cn0001;
+ }
+
+ private CommandInitCache() {
+
+ }
+
+ public static Map getReplyCache() {
+ if (replyCache.size()==0){
+ replyCache=new HashMap<>();
+ sendCache=new HashMap<>();
+ replyCache.put("2601", cn2601);
+ replyCache.put("2051", cn2051);
+ replyCache.put("9015", cn9015);
+ replyCache.put("0001", cn0001);
+ replyCache.put("2011", cn2011);
+ }
+ return replyCache;
+ }
+ public static Map getSendCache() {
+ if (sendCache.size()==0){
+ }
+ return sendCache;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/drht/datamanage/cache/RequestCache.java b/src/main/java/com/drht/datamanage/cache/RequestCache.java
new file mode 100644
index 0000000..f6f2cff
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/cache/RequestCache.java
@@ -0,0 +1,5 @@
+package com.drht.datamanage.cache;
+
+public class RequestCache {
+
+}
diff --git a/src/main/java/com/drht/datamanage/config/FastJson2JsonRedisSerializer.java b/src/main/java/com/drht/datamanage/config/FastJson2JsonRedisSerializer.java
new file mode 100644
index 0000000..bb34467
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/config/FastJson2JsonRedisSerializer.java
@@ -0,0 +1,43 @@
+package com.drht.datamanage.config;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import org.springframework.data.redis.serializer.RedisSerializer;
+import org.springframework.data.redis.serializer.SerializationException;
+
+import java.nio.charset.Charset;
+
+/**
+ * @ClassName FastJson2JsonRedisSerializer
+ * @Description TODO
+ * @Author chaixueteng
+ * @Date 2020/3/24 20:16
+ */
+public class FastJson2JsonRedisSerializer implements RedisSerializer {
+ public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
+
+ private Class clazz;
+
+ public FastJson2JsonRedisSerializer(Class clazz) {
+ super();
+ this.clazz = clazz;
+ }
+
+ @Override
+ public byte[] serialize(T t) throws SerializationException {
+ if (t == null) {
+ return new byte[0];
+ }
+ return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);
+ }
+
+ @Override
+ public T deserialize(byte[] bytes) throws SerializationException {
+ if (bytes == null || bytes.length <= 0) {
+ return null;
+ }
+ String str = new String(bytes, DEFAULT_CHARSET);
+
+ return (T) JSON.parseObject(str, clazz);
+ }
+}
diff --git a/src/main/java/com/drht/datamanage/config/MyBatisPlusConfig.java b/src/main/java/com/drht/datamanage/config/MyBatisPlusConfig.java
new file mode 100644
index 0000000..953584a
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/config/MyBatisPlusConfig.java
@@ -0,0 +1,22 @@
+package com.drht.datamanage.config;
+
+import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+
+@Configuration
+@EnableTransactionManagement
+public class MyBatisPlusConfig {
+ /**
+ * 分页插件
+ */
+ @Bean
+ public PaginationInterceptor paginationInterceptor() {
+ PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
+ paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
+ return new PaginationInterceptor();
+ }
+}
diff --git a/src/main/java/com/drht/datamanage/config/SwaggerConfig.java b/src/main/java/com/drht/datamanage/config/SwaggerConfig.java
new file mode 100644
index 0000000..6fbf314
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/config/SwaggerConfig.java
@@ -0,0 +1,61 @@
+package com.drht.datamanage.config;
+
+import io.swagger.annotations.ApiOperation;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.ParameterBuilder;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.schema.ModelRef;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.service.Parameter;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Configuration
+@EnableSwagger2
+public class SwaggerConfig {
+
+
+ @Bean
+ public Docket createRestApi() {
+ List pars = ParameterBuilder();
+ return new Docket(DocumentationType.SWAGGER_2).enable(true)
+ .groupName("德润数据管理")
+ .apiInfo(apiInfo())
+ .select()
+ .apis(RequestHandlerSelectors.basePackage("com.drht.datamanage.controller"))
+ .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
+ .paths(PathSelectors.any())
+ .build()
+ .globalOperationParameters(pars);
+ }
+
+ private ApiInfo apiInfo() {
+ return new ApiInfoBuilder()
+ .title("dataManagementSystem")
+ .description("德润数据管理")
+ .version("1.0")
+ .contact("zp")
+ .build();
+ }
+
+
+ public List ParameterBuilder(){
+ ParameterBuilder ticketPar = new ParameterBuilder();
+ List pars = new ArrayList();
+ //header中的ticket参数非必填,传空也可以
+ ticketPar.name("token").description("user token")
+ .modelRef(new ModelRef("string")).parameterType("header")
+ .required(false).build();
+ //根据每个方法名也知道当前方法在设置什么参数
+ pars.add(ticketPar.build());
+ return pars;
+ }
+}
+
diff --git a/src/main/java/com/drht/datamanage/dao/HourlyDataDao.java b/src/main/java/com/drht/datamanage/dao/HourlyDataDao.java
new file mode 100644
index 0000000..c2c00f7
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/dao/HourlyDataDao.java
@@ -0,0 +1,21 @@
+package com.drht.datamanage.dao;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.drht.datamanage.model.HourlyData;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @description:
+ * @author: xuxianwei
+ * @time: 2020/9/15 15:46
+ */
+@Mapper
+public interface HourlyDataDao extends BaseMapper {
+
+}
diff --git a/src/main/java/com/drht/datamanage/dao/MinuteDataDao.java b/src/main/java/com/drht/datamanage/dao/MinuteDataDao.java
new file mode 100644
index 0000000..02eef03
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/dao/MinuteDataDao.java
@@ -0,0 +1,10 @@
+package com.drht.datamanage.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.drht.datamanage.model.MinuteData;
+import org.apache.ibatis.annotations.Mapper;
+
+
+@Mapper
+public interface MinuteDataDao extends BaseMapper {
+}
diff --git a/src/main/java/com/drht/datamanage/dao/RealTimeDataDao.java b/src/main/java/com/drht/datamanage/dao/RealTimeDataDao.java
new file mode 100644
index 0000000..ad4c32d
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/dao/RealTimeDataDao.java
@@ -0,0 +1,11 @@
+package com.drht.datamanage.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.drht.datamanage.model.MinuteData;
+import com.drht.datamanage.model.RealTimeData;
+import org.apache.ibatis.annotations.Mapper;
+
+
+@Mapper
+public interface RealTimeDataDao extends BaseMapper {
+}
diff --git a/src/main/java/com/drht/datamanage/exception/AnalysisException.java b/src/main/java/com/drht/datamanage/exception/AnalysisException.java
new file mode 100644
index 0000000..cbef690
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/exception/AnalysisException.java
@@ -0,0 +1,30 @@
+package com.drht.datamanage.exception;
+
+public class AnalysisException extends Exception {
+
+ private String msg;
+
+ private int code;
+
+ public AnalysisException(int code,String msg){
+ this.code=code;
+ this.msg=msg;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+
+ public void setMsg(String msg) {
+ this.msg = msg;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public void setCode(int code) {
+ this.code = code;
+ }
+
+}
diff --git a/src/main/java/com/drht/datamanage/exception/CommonException.java b/src/main/java/com/drht/datamanage/exception/CommonException.java
new file mode 100644
index 0000000..8a24284
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/exception/CommonException.java
@@ -0,0 +1,56 @@
+package com.drht.datamanage.exception;
+
+
+
+/**
+ * 自定义异常
+ * @author chaixueteng
+ */
+public class CommonException extends RuntimeException {
+ private int errorCode;
+ private String msg;
+
+ public CommonException(ResultCode errorCode) {
+ super(errorCode.getInfo());
+ this.errorCode = errorCode.getCode();
+ this.msg = errorCode.getInfo();
+ }
+
+ public CommonException(ResultCode errorCode, String msg) {
+ super(msg);
+ this.errorCode = errorCode.getCode();
+ this.msg = msg;
+ }
+
+ public CommonException(int errorCode, String msg) {
+ super(msg);
+ this.errorCode = errorCode;
+ this.msg = msg;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+
+ public void setMsg(String msg) {
+ this.msg = msg;
+ }
+
+ public int getErrorCode() {
+ return errorCode;
+ }
+
+ public void setErrorCode(int errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ /**
+ * 重新异常堆栈信息处理,避免遍历堆栈资源浪费,提供性能
+ * @return a reference to this {@code Throwable} instance.
+ * @see Throwable#printStackTrace()
+ */
+ @Override
+ public synchronized Throwable fillInStackTrace() {
+ return this;
+ }
+}
diff --git a/src/main/java/com/drht/datamanage/exception/ResultCode.java b/src/main/java/com/drht/datamanage/exception/ResultCode.java
new file mode 100644
index 0000000..e4b7f6c
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/exception/ResultCode.java
@@ -0,0 +1,27 @@
+package com.drht.datamanage.exception;
+
+/**
+ * 响应码枚举
+ */
+public enum ResultCode {
+
+ SUCCESS(0,"成功"),
+ FAIL(1,"失败");
+
+ private int code;
+ private String info;
+
+ ResultCode(int code, String info) {
+ this.code = code;
+ this.info = info;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public String getInfo() {
+ return info;
+ }
+
+}
diff --git a/src/main/java/com/drht/datamanage/handler/CheckDeviceInChannelHandler.java b/src/main/java/com/drht/datamanage/handler/CheckDeviceInChannelHandler.java
new file mode 100644
index 0000000..f599645
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/handler/CheckDeviceInChannelHandler.java
@@ -0,0 +1,65 @@
+package com.drht.datamanage.handler;
+
+
+import com.drht.datamanage.util.AnalysisUtil;
+import com.drht.datamanage.util.SpringContextUtil;
+import com.drht.datamanage.dao.HourlyDataDao;
+import com.drht.datamanage.exception.AnalysisException;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.SimpleChannelInboundHandler;
+import io.netty.handler.timeout.ReadTimeoutException;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.ApplicationContext;
+
+@Slf4j
+public class CheckDeviceInChannelHandler extends SimpleChannelInboundHandler {
+// @Autowired
+// private DeviceMapper deviceMapper;
+
+ // crc校验后调用检查设备是否可用
+ @Override
+ public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
+ ApplicationContext context = SpringContextUtil.context;
+ HourlyDataDao deviceMapper = (HourlyDataDao) context.getBean("hourlyDataDao");
+ //解析报文
+ String s=(String)msg;
+ AnalysisUtil.Msg msgo = AnalysisUtil.msgToJsonString(s);
+ //验证设备
+ String mn=msgo.getMN();
+// String status = deviceMapper.queryStatusByMn(mn);
+// if (!"0".equals(status)){
+// log.info("验证mn:{}的设备没通过,msg:{}",mn,"设备不在线!");
+// ctx.close();
+// return;
+// }
+ //向下传递
+ ctx.fireChannelRead(msgo);
+ }
+
+ // 数据读取完后被调用
+ @Override
+ public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
+ ctx.flush();
+ }
+
+ // 当Netty由于IO错误或者处理器在处理事件时抛出的异常时被调用
+ @Override
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+ if (cause instanceof ReadTimeoutException){
+ //超时异常
+ log.info("关闭了一个90s内没有发送任何数据的链接");
+ ctx.close();
+
+ }else if (cause instanceof AnalysisException){
+ AnalysisException e = (AnalysisException) cause;
+ //解析报文出错的异常
+ log.info("解析报文出错:code={},msg={}",e.getCode(),e.getMsg());
+ ctx.close();
+ //
+ }else{
+ //其他异常向下传递
+ ctx.fireExceptionCaught(cause);
+ }
+
+ }
+}
diff --git a/src/main/java/com/drht/datamanage/handler/CheckMsgInChannelHandler.java b/src/main/java/com/drht/datamanage/handler/CheckMsgInChannelHandler.java
new file mode 100644
index 0000000..8714844
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/handler/CheckMsgInChannelHandler.java
@@ -0,0 +1,78 @@
+package com.drht.datamanage.handler;
+
+import com.drht.datamanage.util.HelperUtil;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.SimpleChannelInboundHandler;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class CheckMsgInChannelHandler extends SimpleChannelInboundHandler {
+
+ // 检查消息合法否,crc校验
+ @Override
+ public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
+ String str=(String)msg;
+ log.info("原始数据{}",str);
+ if (!(str.contains("QN")
+ &&str.contains("PW")
+ &&str.contains("MN")
+ &&str.contains("CN")
+ &&str.contains("CP"))){
+// 不合法的包,关闭通道,记录
+ log.info("不合法{},通道关闭",str);
+ ctx.close();
+ return;
+ }
+ if (!str.startsWith("##")){
+ //包头不是##开头,记录日志关闭通道
+ log.info("不合法{},不是##开头,通道关闭",str);
+ ctx.close();
+ return;
+ }
+ //获取报文crc
+ String crc=str.substring(str.length()-4);
+ //截取掉包头与包未
+ str=str.substring(2,str.length()-4);
+
+ //crc校验
+ int checkCrc = HelperUtil.getCheckCrc(str.getBytes());
+ //转16进制并转成大写
+ String scheckCrc = String.format("%04x",checkCrc).toUpperCase();
+// if (!(scheckCrc.equals(crc.toUpperCase()))){
+// //未通过crc校验
+// log.info("不合法{},未通过crc校验,报文crc{},服务端生成的crc{},通道关闭",str,crc,scheckCrc);
+// ctx.close();
+// return;
+// }
+ log.info("第一层校验处理后{}",str);
+ ctx.fireChannelRead(str);
+
+ }
+
+ // 数据读取完后被调用
+ @Override
+ public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
+ ctx.flush();
+ }
+
+ // 当Netty由于IO错误或者处理器在处理事件时抛出的异常时被调用
+ @Override
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+ //到下一个handler处理
+ ctx.fireExceptionCaught(cause);
+
+ }
+
+ @Override
+ public void channelActive(ChannelHandlerContext ctx) throws Exception {
+ if (ctx.channel().remoteAddress().toString().startsWith("/100.")) {
+ ctx.close();
+ return;
+ }
+ super.channelActive(ctx);
+
+ }
+
+
+
+}
diff --git a/src/main/java/com/drht/datamanage/handler/ReplyDeviceInChannelHandler.java b/src/main/java/com/drht/datamanage/handler/ReplyDeviceInChannelHandler.java
new file mode 100644
index 0000000..2f60976
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/handler/ReplyDeviceInChannelHandler.java
@@ -0,0 +1,45 @@
+package com.drht.datamanage.handler;
+
+import com.drht.datamanage.util.AnalysisUtil;
+import com.drht.datamanage.cache.CommandInitCache;
+import com.drht.datamanage.service.Reply;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.SimpleChannelInboundHandler;
+import io.netty.util.internal.logging.InternalLogger;
+import io.netty.util.internal.logging.InternalLoggerFactory;
+
+import java.io.IOException;
+
+public class ReplyDeviceInChannelHandler extends SimpleChannelInboundHandler {
+ private static final InternalLogger logger = InternalLoggerFactory.getInstance(ReplyDeviceInChannelHandler.class);
+ // 检查完设备后,回复命令调用
+ @Override
+ public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
+ AnalysisUtil.Msg msgo= (AnalysisUtil.Msg) msg;
+ //根据cn分别回复
+ String cn = msgo.getCN();
+ //根据cn获取执行对象
+ Reply reply = CommandInitCache.getReplyCache().get(cn);
+ //执行业务逻辑
+ reply.rese(msgo,ctx);
+// ctx.fireChannelRead(msg);
+ }
+
+ // 数据读取完后被调用
+ @Override
+ public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
+ ctx.flush();
+ }
+
+ // 当Netty由于IO错误或者处理器在处理事件时抛出的异常时被调用
+ @Override
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+ if (cause instanceof IOException){
+ logger.error("io异常");
+ ctx.close();
+ return;
+ }
+ cause.printStackTrace();
+ ctx.close();
+ }
+}
diff --git a/src/main/java/com/drht/datamanage/handler/SendChannelHandler.java b/src/main/java/com/drht/datamanage/handler/SendChannelHandler.java
new file mode 100644
index 0000000..9aec49f
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/handler/SendChannelHandler.java
@@ -0,0 +1,20 @@
+package com.drht.datamanage.handler;
+
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelOutboundHandlerAdapter;
+import io.netty.channel.ChannelPromise;
+import io.netty.util.internal.logging.InternalLogger;
+import io.netty.util.internal.logging.InternalLoggerFactory;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class SendChannelHandler extends ChannelOutboundHandlerAdapter {
+//发送消息触发
+
+ @Override
+ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
+ log.info("发出的报文{}",msg.toString());
+ super.write(ctx, msg, promise);
+ //预留控制发送命令,短时间内不能太多
+ }
+}
diff --git a/src/main/java/com/drht/datamanage/listener/NettyServerListener.java b/src/main/java/com/drht/datamanage/listener/NettyServerListener.java
new file mode 100644
index 0000000..9a7b702
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/listener/NettyServerListener.java
@@ -0,0 +1,27 @@
+package com.drht.datamanage.listener;
+
+import com.drht.datamanage.App;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+@Component
+@Slf4j
+public class NettyServerListener implements ApplicationRunner {
+ /**
+ * 当一个applicationContext被初始化或被刷新时触发
+ */
+ @Override
+ public void run(ApplicationArguments args) throws Exception {
+ log.info("启动netty组件");
+ new Thread(new Runnable() {
+ @SneakyThrows
+ @Override
+ public void run() {
+ App.run();
+ }
+ }).start();
+ }
+}
diff --git a/src/main/java/com/drht/datamanage/model/HourlyData.java b/src/main/java/com/drht/datamanage/model/HourlyData.java
new file mode 100644
index 0000000..350bf0b
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/model/HourlyData.java
@@ -0,0 +1,88 @@
+package com.drht.datamanage.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.time.LocalDateTime;
+
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("t_hourly_data")
+@ApiModel(value="小时数据", description="小时数据")
+public class HourlyData extends Model {
+
+ private static final long serialVersionUID = 1L;
+
+ @TableId(value = "id", type = IdType.AUTO)
+ private int id;
+
+ @TableField("f_time")
+ private String f_time;
+
+ @TableField("f_cod_min")
+ private String f_cod_min; //w01018-Min
+
+ @TableField("f_cod_avg")
+ private String f_cod_avg;//w01018-Avg
+
+ @TableField("f_cod_max")
+ private String f_cod_max;//w01018-Max
+
+ @TableField("f_nitrate_min")
+ private String f_nitrate_min;//w01018-Min
+
+
+ @TableField("f_nitrate_avg")
+ private String f_nitrate_avg;//w01018-Avg
+
+
+ @TableField("f_nitrate_max")
+ private String f_nitrate_max;//w01018-Max
+
+ @TableField("f_tss_min")
+ private String f_tss_min;//w01018-Min
+
+ @TableField("f_tss_avg")
+ private String f_tss_avg;//w01018-Avg
+
+ @TableField("f_tss_max")
+ private String f_tss_max;//w01018-Max
+
+ @TableField("f_toc_min")
+ private String f_toc_min;//w01018-Min
+
+
+ @TableField("f_toc_avg")
+ private String f_toc_avg;//w01018-Avg
+
+ @TableField("f_toc_max")
+ private String f_toc_max;//w01018-Max
+
+ @TableField("f_permanganate_index_min")
+ private String f_permanganate_index_min;//w01018-Min
+
+ @TableField("f_permanganate_index_avg")
+ private String f_permanganate_index_avg;//w01018-Avg
+
+ @TableField("f_permanganate_index_max")
+ private String f_permanganate_index_max;//w01018-Max
+
+ @TableField("f_turbidity_min")
+ private String f_turbidity_min;//w01018-Min
+
+ @TableField("f_turbidity_avg")
+ private String f_turbidity_avg;//w01018-Avg
+
+ @TableField("f_turbidity_max")
+ private String f_turbidity_max;//w01018-Max
+}
diff --git a/src/main/java/com/drht/datamanage/model/MinuteData.java b/src/main/java/com/drht/datamanage/model/MinuteData.java
new file mode 100644
index 0000000..2f25a81
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/model/MinuteData.java
@@ -0,0 +1,85 @@
+package com.drht.datamanage.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("t_minute_data")
+@ApiModel(value="分钟数据", description="分钟数据")
+public class MinuteData extends Model {
+
+ private static final long serialVersionUID = 1L;
+
+ @TableId(value = "id", type = IdType.AUTO)
+ private int id;
+
+ @TableField("f_time")
+ private String f_time;
+
+ @TableField("f_cod_min")
+ private String f_cod_min; //w01018-Min
+
+ @TableField("f_cod_avg")
+ private String f_cod_avg;//w01018-Avg
+
+ @TableField("f_cod_max")
+ private String f_cod_max;//w01018-Max
+
+ @TableField("f_nitrate_min")
+ private String f_nitrate_min;//w01018-Min
+
+
+ @TableField("f_nitrate_avg")
+ private String f_nitrate_avg;//w01018-Avg
+
+
+ @TableField("f_nitrate_max")
+ private String f_nitrate_max;//w01018-Max
+
+ @TableField("f_tss_min")
+ private String f_tss_min;//w01018-Min
+
+ @TableField("f_tss_avg")
+ private String f_tss_avg;//w01018-Avg
+
+ @TableField("f_tss_max")
+ private String f_tss_max;//w01018-Max
+
+ @TableField("f_toc_min")
+ private String f_toc_min;//w01018-Min
+
+
+ @TableField("f_toc_avg")
+ private String f_toc_avg;//w01018-Avg
+
+ @TableField("f_toc_max")
+ private String f_toc_max;//w01018-Max
+
+ @TableField("f_permanganate_index_min")
+ private String f_permanganate_index_min;//w01018-Min
+
+ @TableField("f_permanganate_index_avg")
+ private String f_permanganate_index_avg;//w01018-Avg
+
+ @TableField("f_permanganate_index_max")
+ private String f_permanganate_index_max;//w01018-Max
+
+ @TableField("f_turbidity_min")
+ private String f_turbidity_min;//w01018-Min
+
+ @TableField("f_turbidity_avg")
+ private String f_turbidity_avg;//w01018-Avg
+
+ @TableField("f_turbidity_max")
+ private String f_turbidity_max;//w01018-Max
+}
diff --git a/src/main/java/com/drht/datamanage/model/RealTimeData.java b/src/main/java/com/drht/datamanage/model/RealTimeData.java
new file mode 100644
index 0000000..5b64bd9
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/model/RealTimeData.java
@@ -0,0 +1,50 @@
+package com.drht.datamanage.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("t_realtime_data")
+@ApiModel(value="实时数据", description="实时数据")
+public class RealTimeData extends Model {
+
+ private static final long serialVersionUID = 1L;
+
+ @TableId(value = "id", type = IdType.AUTO)
+ private int id;
+
+ @TableField("f_time")
+ private String f_time;
+
+ @TableField("f_cod")
+ private String f_cod;//w01018
+
+ @TableField("f_nitrate")
+ private String f_nitrate;//w21007
+
+ @TableField("f_tss")
+ private String f_tss;//w01012
+
+ @TableField("f_toc")
+ private String f_toc;//w01020
+
+
+ @TableField("f_permanganate_index")
+ private String f_permanganate_index;//w01019
+
+ @TableField("f_turbidity")
+ private String f_turbidity;//w01003
+
+ @TableField("f_raw_data")
+ private String f_raw_data;
+}
diff --git a/src/main/java/com/drht/datamanage/model/msg/CommandMsg.java b/src/main/java/com/drht/datamanage/model/msg/CommandMsg.java
new file mode 100644
index 0000000..e193ac6
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/model/msg/CommandMsg.java
@@ -0,0 +1,36 @@
+package com.drht.datamanage.model.msg;
+
+import java.util.Map;
+
+public class CommandMsg {
+
+ private String methodname;
+
+ private String requesid;
+
+ private Map methodparams;
+
+ public String getMethodname() {
+ return methodname;
+ }
+
+ public void setMethodname(String methodname) {
+ this.methodname = methodname;
+ }
+
+ public String getRequesid() {
+ return requesid;
+ }
+
+ public void setRequesid(String requesid) {
+ this.requesid = requesid;
+ }
+
+ public Map getMethodparams() {
+ return methodparams;
+ }
+
+ public void setMethodparams(Map methodparams) {
+ this.methodparams = methodparams;
+ }
+}
diff --git a/src/main/java/com/drht/datamanage/model/msg/ReplyKafkaMsg.java b/src/main/java/com/drht/datamanage/model/msg/ReplyKafkaMsg.java
new file mode 100644
index 0000000..4548fb8
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/model/msg/ReplyKafkaMsg.java
@@ -0,0 +1,25 @@
+package com.drht.datamanage.model.msg;
+
+import java.util.Map;
+
+public class ReplyKafkaMsg {
+ private boolean isrequest;
+
+ private Map data;
+
+ public boolean isIsrequest() {
+ return isrequest;
+ }
+
+ public void setIsrequest(boolean isrequest) {
+ this.isrequest = isrequest;
+ }
+
+ public Map getData() {
+ return data;
+ }
+
+ public void setData(Map data) {
+ this.data = data;
+ }
+}
diff --git a/src/main/java/com/drht/datamanage/model/msg/SendMsg.java b/src/main/java/com/drht/datamanage/model/msg/SendMsg.java
new file mode 100644
index 0000000..f1182d6
--- /dev/null
+++ b/src/main/java/com/drht/datamanage/model/msg/SendMsg.java
@@ -0,0 +1,80 @@
+package com.drht.datamanage.model.msg;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import com.drht.datamanage.util.QnUtil;
+
+public class SendMsg {
+
+
+ private String QN= QnUtil.getQN(new Date());
+ private String PW;
+ private String MN;
+ private String CN;
+ private String Flag;
+ private String ST;
+ private List