Prechádzať zdrojové kódy

新建保温箱子工程

zhuoning 2 rokov pred
rodič
commit
1b2f913f4b

+ 112 - 0
huimv-env-platform/huimv-env-lamp/pom.xml

@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>huimv-env-platform</artifactId>
+        <groupId>com.huimv</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.huimv</groupId>
+    <artifactId>huimv-env-lamp</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <dependencies>
+        <!-- 排除Tomcat容器 -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+            <!-- 移除掉默认支持的 Tomcat -->
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-starter-tomcat</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <!-- 添加 Undertow 容器 -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-undertow</artifactId>
+        </dependency>
+        <!-- JPA -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+        <!-- mysql -->
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+        </dependency>
+        <!--rabbitmq-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+        </dependency>
+        <!-- redis -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
+        <!-- actuator -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</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>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <!-- fastjson -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.huimv</groupId>
+            <artifactId>huimv-env-common</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-all</artifactId>
+        </dependency>
+        <!-- 一方包统一版本管理 -->
+        <dependency>
+            <groupId>com.huimv</groupId>
+            <artifactId>huimv-env-common</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <version>2.6</version>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 31 - 0
huimv-env-platform/huimv-env-lamp/src/main/java/com/huimv/env/lamp/HuimvLampInputApplication.java

@@ -0,0 +1,31 @@
+package com.huimv.env.lamp;
+
+import com.huimv.env.lamp.server.LampInputServer;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.ComponentScans;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@ComponentScans({@ComponentScan("com.huimv.env.common.utils"),
+        @ComponentScan("com.huimv.env.common.service")})
+@EntityScan(value = "com.huimv.env.common.dao.entity")
+@EnableJpaRepositories(basePackages = "com.huimv.env.common.dao.repo")
+@SpringBootApplication
+public class HuimvLampInputApplication {
+    public static void main(String[] args) throws InterruptedException {
+        ApplicationContext applicationContext = SpringApplication.run(HuimvLampInputApplication.class, args);
+        // EnvInputServer
+        applicationContext.getBean(LampInputServer.class).run();
+    }
+}

+ 74 - 0
huimv-env-platform/huimv-env-lamp/src/main/java/com/huimv/env/lamp/server/LampInputServer.java

@@ -0,0 +1,74 @@
+package com.huimv.env.lamp.server;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Component
+public class LampInputServer {
+    @Autowired
+    private LampInputServerHandler serverHandler;
+    //监听端口
+    private int port = 5001;
+    //创建构造方法
+    public LampInputServer(){
+    }
+
+    public static void main(String[] args) throws InterruptedException {
+        new LampInputServer().run();
+    }
+/**
+ *
+ * 功能描述: 启动方法前台多个服务  处理多个线程
+ *
+ * @param:
+ * @return:
+ * @auther: LiGang
+ * @date: 2019/3/26 11:31
+ */
+    /**
+     * 启动流程
+     */
+    public void run() throws InterruptedException {
+        //配置服务端线程组
+        EventLoopGroup bossGroup=new NioEventLoopGroup();
+        EventLoopGroup workGroup=new NioEventLoopGroup();
+
+        try{
+            //引导整个server的启动
+            ServerBootstrap serverBootstrap = new ServerBootstrap();
+            serverBootstrap.group(bossGroup,workGroup)
+                    .channel(NioServerSocketChannel.class)    //指定处理的连接类型
+                    .childHandler(new ChannelInitializer<SocketChannel>() {
+                        @Override
+                        protected void initChannel(SocketChannel socketChannel) throws Exception {
+                            socketChannel.pipeline().addLast(serverHandler);
+                        }
+                    });
+            System.out.println("# 耳标及采集器设备数据接收服务器已经启动,监听端口(Port):"+port);
+            System.out.println("# 准备接收数据:");
+            //绑定端口,同步等待成功
+            ChannelFuture cf = serverBootstrap.bind(port).sync();
+            // 等待服务端监听端口关闭
+            cf.channel().closeFuture().sync();
+        }finally {
+            //优雅的退出
+            bossGroup.shutdownGracefully();
+            workGroup.shutdownGracefully();
+        }
+    }
+}

+ 553 - 0
huimv-env-platform/huimv-env-lamp/src/main/java/com/huimv/env/lamp/server/LampInputServerHandler.java

@@ -0,0 +1,553 @@
+package com.huimv.env.lamp.server;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.huimv.env.common.dao.entity.EnvDeviceRegisterEntity;
+import com.huimv.env.common.service.IDeviceRegisterService;
+import com.huimv.env.common.service.ISprayConfigService;
+import com.huimv.env.common.service.ISprayTimeService;
+import com.huimv.env.common.service.ITempThresholdService;
+import com.huimv.env.common.utils.RegexUtil;
+//import com.huimv.env.input.producer.Producer;
+//import com.huimv.env.input.service.ICommandProcessorService;
+//import com.huimv.env.input.utils.DateUtil2;
+import com.huimv.env.lamp.service.LampInputHandleService;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.util.CharsetUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.sql.Timestamp;
+import java.text.ParseException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@ChannelHandler.Sharable
+@Component
+@Slf4j
+public class LampInputServerHandler extends ChannelInboundHandlerAdapter {
+    @Autowired
+    private RegexUtil regexUtil;
+//    @Autowired
+//    private ICommandProcessorService cmdProService;
+//    @Autowired
+//    private DateUtil2 dateUtil;
+//    @Autowired
+//    private Producer producer;
+    private StringBuilder askTextSb = null;
+    @Autowired
+    private ITempThresholdService tempThresholdService;
+    @Autowired
+    private ISprayConfigService sprayConfigService;
+    @Autowired
+    private ISprayTimeService sprayTimeService;
+    @Autowired
+    private IDeviceRegisterService deviceRegisterService;
+    @Resource
+    private LampInputHandleService lampInputHandleService;
+
+    //
+    public void appendClientAsk(String text) {
+        if (this.askTextSb == null) {
+            askTextSb = new StringBuilder();
+        }
+        askTextSb.append(text);
+    }
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+        ByteBuf data = (ByteBuf) msg;
+        String clientAskText = data.toString(CharsetUtil.UTF_8);
+        //保存实例内的客户端请求
+        appendClientAsk(clientAskText);
+        //临时写入耳标数据到文件
+//        writeTxt(clientAskText,"all");
+    }
+
+    @Override
+    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
+        if (askTextSb.toString().indexOf("end") != -1) {
+            // {处理客户端消息}
+            handleClientAskCmd(askTextSb.toString(), ctx);
+            //清空重置;
+            askTextSb.delete(0, askTextSb.length());
+        }
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+        if (cause.getMessage().indexOf("Connection reset") != -1) {
+            log.info("相关采集器设备正在重启:" + cause.toString());
+        }
+//        cause.printStackTrace();
+        ctx.close();
+    }
+
+    /**
+     * @Method : handleClientAskCmd
+     * @Description : 处理请求小心
+     * @Params : [clientAskText, ctx]
+     * @Return : void
+     * @Author : ZhuoNing
+     * @Date : 2022/3/28
+     * @Time : 17:36
+     */
+    private void handleClientAskCmd(String clientAskText, ChannelHandlerContext ctx) throws ParseException, IOException {
+        clientAskText = clientAskText.replaceAll("\r", "").replaceAll("\n", "");
+        //{处理非正常命令}
+//        int countPlus = regexUtil.countPlus(clientAskText);
+//        if (countPlus < 4) {
+//            System.out.println("当前数据为不完整数据,故丢弃.>>" + clientAskText);
+//        } else {
+        //--处理客户端请求数据
+        //{拆分粘包数据}
+        JSONArray askJa = parseAskCmdPackage(clientAskText);
+        for (int a = 0; a < askJa.size(); a++) {
+            String askText = askJa.getString(a);
+            //{处理请求命令}
+            askCmdActuator(askText, ctx);
+        }
+//        }
+    }
+
+    /**
+     * @Method : askCmdActuator
+     * @Description :
+     * @Params : [askText, ctx]
+     * @Return : void
+     * @Author : ZhuoNing
+     * @Date : 2022/3/23
+     * @Time : 18:08
+     */
+    private void askCmdActuator(String askText, ChannelHandlerContext ctx) throws ParseException, IOException {
+        System.out.println("======>接收设备请求:" + askText);
+        String[] dataArray = askText.split("\\+");
+        String cmdHeader = dataArray[0];
+        if (!cmdHeader.trim().equalsIgnoreCase("hm")) {
+            log.info("当前命令是非hm命令[" + askText + "]");
+            return;
+        }
+        //芯片id/设备编码
+        String idCode = dataArray[1];
+        String cmd = dataArray[2];
+        Map map = new HashMap();
+        map.put("askText", askText);
+        switch (cmd) {
+            case "1":
+                //同步时间
+                lampInputHandleService.synchronizationTime(askText, idCode, ctx);
+                break;
+            case "2":
+                //上传温度
+                lampInputHandleService.getLampTemp(askText, idCode, ctx);
+                break;
+            case "3":
+                //获取保温箱配置
+                lampInputHandleService.getLampConfig(askText, idCode, ctx);
+                break;
+//            case "4":
+//                //上传湿度数据
+//                uploadHumi(askText, idCode, ctx);
+//                break;
+//            case "5":
+//                //氨气数据上传
+//                uploadAmmonia(askText, idCode, ctx);
+//                break;
+//            case "6":
+//                //获取喷雾除臭配置
+//                getSprayConfig(askText, idCode, ctx);
+//                break;
+//            case "7":
+//                //上报喷雾除臭状态
+//                uploadSprayEquipStatus(askText, idCode, ctx);
+//                break;
+//            case "8":
+//                //水压
+//                uploadWaterGege(askText, idCode, ctx);
+//                break;
+//            case "9":
+//                //PH
+//                uploadPH(askText, idCode, ctx);
+//                break;
+//            case "10":
+//                //水表
+//                uploadWaterMeter(askText, idCode, ctx);
+//                break;
+//            case "11":
+//                //电表
+//                uploadElectricityMeter(askText, idCode, ctx);
+//                break;
+//            case "12":
+//                //获取设备开关
+//                getSparySwitch(askText, idCode, ctx);
+//                break;
+//            case "13":
+//                //上报设备状态
+//                getSparyStatus(askText, idCode, ctx);
+//                break;
+//
+//            case "14":
+//                //获取报警使能
+//                getAlarmConfig(askText, idCode, ctx);
+//                break;
+//            case "15":
+//                //短信发送
+//                uploadSendMessage(askText, idCode, ctx);
+//                break;
+//            case "16":
+//                //声光报警短信
+//                uploadAudibleAndVisualAlarmMessage(askText, idCode, ctx);
+//                break;
+//            case "17":
+//                //报警器打电话
+//                uploadTelephoneAlarm(askText, idCode, ctx);
+//                break;
+//            case "18":
+//                //高温,低温报警参数请求
+//                getTempThresholdConfig(askText, idCode, ctx);
+//                break;
+//            case "19":
+//                //平台消息推送
+//                uploadPlatformMessagePushInfo(askText, idCode, ctx);
+//                break;
+            default:
+                System.out.println("==>未知命令");
+                log.error(">>当前数据为非法数据-未知命令>>" + askText);
+        }
+    }
+
+//    //上报设备状态
+//    private void getSparyStatus(String askText, String deviceCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>上报设备状态上传请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(deviceCode)) {
+//            System.out.println("##上报设备状态上传请求-未注册设备 deviceCode=" + deviceCode);
+//            return;
+//        }
+//        //上报设备状态
+//        String answerText = "hm+118+13+1010101010101010+201702081523+6+end";
+//        log.info(">>上报设备状态上传请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//        //上报设备状态请求到消息队列
+////        producer.sendWaterGege(askText);
+//    }
+//    //获取设备开关
+//    private void getSparySwitch(String askText, String deviceCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>获取设备开关上传请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(deviceCode)) {
+//            System.out.println("##获取设备开关上传请求-未注册设备 deviceCode=" + deviceCode);
+//            return;
+//        }
+//        //TODO 获取设备开关请求
+//        String answerText = "hm+118+12+1010101010101010+6+end";
+//        log.info(">>获取设备开关上传请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//        //获取设备开关请求
+////        producer.sendWaterGege(askText);
+//    }
+//
+//    //电表
+//    private void uploadElectricityMeter(String askText, String deviceCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>电表上传请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(deviceCode)) {
+//            System.out.println("##电表上传请求-未注册设备 deviceCode=" + deviceCode);
+//            return;
+//        }
+//        //电表上传请求
+//        String answerText = "hm+11+0+7+end";
+//        log.info(">>电表上传请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//        //电表请求到消息队列
+////        producer.sendWaterGege(askText);
+//    }
+//
+//    //水表
+//    private void uploadWaterMeter(String askText, String deviceCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>水表上传请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(deviceCode)) {
+//            System.out.println("##水表上传请求-未注册设备 deviceCode=" + deviceCode);
+//            return;
+//        }
+//        //水表上传请求
+//        String answerText = "hm+10+0+7+end";
+//        log.info(">>水表上传请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//        //发送水表请求到消息队列
+////        producer.sendWaterGege(askText);
+//    }
+//
+//    //PH
+//    private void uploadPH(String askText, String deviceCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>PH上传请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(deviceCode)) {
+//            System.out.println("##PH上传请求-未注册设备 deviceCode=" + deviceCode);
+//            return;
+//        }
+//        //PH传请求
+//        String answerText = "hm+9+0+7+end";
+//        log.info(">>PH上传请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//        //发送PH请求到消息队列
+////        producer.sendWaterGege(askText);
+//    }
+//
+//    //水压
+//    private void uploadWaterGege(String askText, String deviceCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>水压上传请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(deviceCode)) {
+//            System.out.println("##水压上传请求-未注册设备 deviceCode=" + deviceCode);
+//            return;
+//        }
+//        //水压上传请求
+//        String answerText = "hm+8+0+7+end";
+//        log.info(">>水压上传请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//        //水压请求到消息队列
+//        producer.sendWaterGege(askText);
+//    }
+//
+//    //平台消息推送请求
+//    private void uploadPlatformMessagePushInfo(String askText, String idCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>平台消息推送请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(idCode)) {
+//            System.out.println("##平台消息推送请求-未注册设备 idCode=" + idCode);
+//            return;
+//        }
+//        String answerText = "hm+19+0+2+end";
+//        log.info(">>平台消息推送请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//
+//        //发送喷雾设备状态到消息队列
+//        producer.sendPushMessageToMQ(askText);
+//    }
+//
+//    //高温,低温报警参数请求
+//    private void getTempThresholdConfig(String askText, String idCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>高温,低温报警参数请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(idCode)) {
+//            System.out.println("##高温,低温报警参数请求-未注册设备 idCode=" + idCode);
+//            return;
+//        }
+//        String threshold = tempThresholdService.getTempThresholdByDeviceCode(idCode);
+//        String answerText = "hm+"+idCode+"+18+"+threshold+"+6+end";
+//        log.info(">>高温,低温报警参数请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//    }
+//
+//    //报警器打电话请求
+//    private void uploadTelephoneAlarm(String askText, String idCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>报警器打电话请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(idCode)) {
+//            System.out.println("##报警器打电话请求-未注册设备 idCode=" + idCode);
+//            return;
+//        }
+//        String answerText = "hm+17+0+2+end";
+//        log.info(">>报警器打电话请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//    }
+//
+//    //声光报警短信发送请求
+//    private void uploadAudibleAndVisualAlarmMessage(String askText, String idCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>声光报警短信发送请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(idCode)) {
+//            System.out.println("##声光报警短信发送请求-未注册设备 idCode=" + idCode);
+//            return;
+//        }
+//        String answerText = "hm+16+0+2+end";
+//        log.info(">>声光报警短信发送请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//    }
+//
+//    //短信发送请求
+//    private void uploadSendMessage(String askText, String idCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>短信发送请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(idCode)) {
+//            System.out.println("##>短信发送请求-未注册设备 idCode=" + idCode);
+//            return;
+//        }
+//        String answerText = "hm+15+0+2+end";
+//        log.info(">>>短信发送请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//    }
+//
+//    //获取报警使能请求
+//    private void getAlarmConfig(String askText, String idCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>获取报警使能请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(idCode)) {
+//            System.out.println("##获取报警使能请求-未注册设备 idCode=" + idCode);
+//            return;
+//        }
+//        //(声光报警、短信报警、语音报警) 1:关闭,2:打开
+//        String answerText = "hm+"+idCode+"+14+2(111)2(111)2(111)2(111)2(111)+0+4+end";
+//        log.info(">>获取报警使能请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//    }
+//
+//    //上报喷雾除臭状态请求
+//    private void uploadSprayEquipStatus(String askText, String idCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>上报喷雾除臭状态请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(idCode)) {
+//            System.out.println("##上报喷雾除臭状态请求-未注册设备 idCode=" + idCode);
+//            return;
+//        }
+//        String answerText = "hm+" + idCode + "+7+6+end";
+//        log.info(">>上报喷雾除臭状态请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//        //发送喷雾设备状态到消息队列
+//        producer.sendSprayEquipStatusToMQ(askText);
+//    }
+//
+//    //获取喷雾除臭配置请求
+//    private void getSprayConfig(String askText, String deviceCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>获取喷雾除臭配置请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(deviceCode)) {
+//            System.out.println("##获取喷雾除臭配置请求-未注册设备 idCode=" + deviceCode);
+//            return;
+//        }
+//        //读取设备注册信息
+//        EnvDeviceRegisterEntity envDeviceRegisterEntity = deviceRegisterService.getDeviceRegisterByDeviceCode(deviceCode);
+//        if (envDeviceRegisterEntity == null) {
+//            log.error("该设备[" + deviceCode + "]未注册.");
+//            return;
+//        }
+//        java.sql.Date todayDate = new java.sql.Date(new java.util.Date().getTime());
+//        Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
+//        String farmCode = envDeviceRegisterEntity.getFarmCode();
+//
+//        //读取喷雾配置表数据
+//        JSONObject configJo = sprayConfigService.getSprayConfigByDeviceCode(deviceCode, farmCode);
+//        int runMode = configJo.getInteger("runMode");
+//        int deviceStatus = configJo.getInteger("deviceStatus");
+//        int timeInterval = configJo.getInteger("timeInterval") * 60;
+//        //读取定时时间配置表数据
+//        String sprayTime = sprayTimeService.getSprayTimeByDeviceCode(deviceCode);
+////        String answerText = "hm+"+deviceCode+"+6+1+1+0101,60,10,10,0202,60,10,10,0303,60,10,10,0404,60,10,10+60+6+end";
+//        String answerText = "hm+" + deviceCode + "+6+" + runMode + "+" + deviceStatus + "+" + sprayTime + "+" + timeInterval + "+6+end";
+//        log.info("<<获取喷雾除臭配置请求-应答数据<<" + answerText);
+//        answerCmd(answerText, ctx);
+//    }
+//
+//    //氨气度上传请求
+//    private void uploadAmmonia(String askText, String idCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>氨气度上传请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(idCode)) {
+//            System.out.println("##氨气度上传请求-未注册设备 idCode=" + idCode);
+//            return;
+//        }
+//        String answerText = "hm+5+0+8+end";
+//        log.info(">>氨气度上传请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//
+//        //发送氨气请求到消息队列
+//        producer.sendAmmoniaAskToMQ(askText);
+//    }
+//
+//    //湿度度上传请求
+//    private void uploadHumi(String askText, String idCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>湿度度上传请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(idCode)) {
+//            System.out.println("##湿度度上传请求-未注册设备 idCode=" + idCode);
+//            return;
+//        }
+//        String answerText = "hm+4+0+8+end";
+//        log.info(">>湿度度上传请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//        //发送湿度请求到消息队列
+//        producer.sendHumiAskToMQ(askText);
+//    }
+//
+//    // 温度度上传
+//    private void uploadTemp(String askText, String deviceCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>温度度上传请求 askText>>" + askText);
+//        if (!cmdProService.isEffectiveDevice(deviceCode)) {
+//            System.out.println("##温度度上传请求-未注册设备 deviceCode=" + deviceCode);
+//            return;
+//        }
+//        //温度度上传请求
+//        String answerText = "hm+3+0+7+end";
+//        log.info(">>温度度上传请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//        //发送温度请求到消息队列
+//        producer.sendTempAskToMQ(askText);
+//    }
+//
+//    //时间同步请求
+//    private void getServerTime(String askText, String deviceCode, ChannelHandlerContext ctx) throws ParseException {
+//        System.out.println("==>时间同步请求:" + askText);
+//        if (!cmdProService.isEffectiveDevice(deviceCode)) {
+//            System.out.println("##时间同步请求-未注册设备 idCode=" + deviceCode);
+//            return;
+//        }
+//        String answerText = "hm+2+" + dateUtil.getNowText() + "+0+4+end";
+//        log.info(">>时间同步请求-应答数据>>" + answerText);
+//        answerCmd(answerText, ctx);
+//    }
+//
+//    //获取远程设备编码
+//    private void getDeviceCode(String askText, String idCode, ChannelHandlerContext ctx) {
+//        System.out.println("==>获取远程设备编码请求:" + askText.trim());
+//        //{读取设备编码}
+//        String deviceCode = cmdProService.getDeviceCodeByChipId(idCode);
+//        log.info("获取远程设备编码请求,芯片id>>" + idCode + " ,deviceCode>>" + deviceCode);
+//        if (deviceCode == null) {
+//            log.error("该设备未注册,已舍弃请求.");
+//            return;
+//        }
+//        String answerText = "hm+1+0+" + deviceCode + "+123+8+end";
+//        log.info("<<获取远程设备编码请求-应答数据:" + answerText);
+//        //{应答指令}
+//        answerCmd(answerText, ctx);
+//    }
+
+    //应答
+    public void answerCmd(String answerText, ChannelHandlerContext ctx) {
+        ctx.writeAndFlush(Unpooled.copiedBuffer(answerText.getBytes()));
+    }
+
+    //检查无效耳标
+    public boolean checkValidEarmark(String earmark) {
+        if (earmark.trim().equalsIgnoreCase("ffffffffffffffff") || earmark.trim().equalsIgnoreCase("0000000000000000")) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    //拆分粘包数据
+    public JSONArray parseAskCmdPackage(String text) {
+        String key = "end";
+        Pattern pattern = Pattern.compile(key);
+        Matcher matcher = pattern.matcher(text);
+        int count = 0;
+        while (matcher.find()) {
+            count++;
+        }
+        JSONArray dataJa = new JSONArray();
+        if (count == 1) {
+            dataJa.add(text);
+        } else {
+            for (int a = 0; a < count; a++) {
+                int p1 = text.indexOf("end");
+                dataJa.add(text.substring(0, p1 + 3));
+                text = text.substring(p1 + 3, text.length());
+            }
+        }
+        return dataJa;
+    }
+}

+ 14 - 0
huimv-env-platform/huimv-env-lamp/src/main/java/com/huimv/env/lamp/service/LampInputHandleService.java

@@ -0,0 +1,14 @@
+package com.huimv.env.lamp.service;
+
+import io.netty.channel.ChannelHandlerContext;
+
+import java.text.ParseException;
+
+public interface LampInputHandleService {
+
+    void synchronizationTime(String askText, String idCode, ChannelHandlerContext ctx) throws ParseException;
+
+    void getLampTemp(String askText, String idCode, ChannelHandlerContext ctx) throws ParseException;
+
+    void getLampConfig(String askText, String idCode, ChannelHandlerContext ctx);
+}

+ 71 - 0
huimv-env-platform/huimv-env-lamp/src/main/java/com/huimv/env/lamp/service/impl/LampInputHandleServiceImpl.java

@@ -0,0 +1,71 @@
+package com.huimv.env.lamp.service.impl;
+
+import com.huimv.env.common.service.ILampConfigService;
+import com.huimv.env.common.service.ILampTempService;
+import com.huimv.env.common.utils.DateUtil;
+import com.huimv.env.common.utils.MathUtil;
+import com.huimv.env.lamp.service.LampInputHandleService;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandlerContext;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.text.ParseException;
+
+/**
+ * @Project : huimv-env-platform
+ * @Package : ${}
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2022/10/15
+ **/
+@Service
+@Slf4j
+public class LampInputHandleServiceImpl implements LampInputHandleService {
+    @Resource
+    private DateUtil dateUtil;
+    @Resource
+    private ILampTempService lampTempService;
+    @Autowired
+    private ILampConfigService lampConfigService;
+
+    @Override
+    public void synchronizationTime(String askText, String idCode, ChannelHandlerContext ctx) throws ParseException {
+        System.out.println("同步时间");
+        String answerText = "hm+"+idCode+"+1+" + dateUtil.getNowText() + "+4+end";
+        log.info(">>时间同步请求-应答数据>>" + answerText);
+        answerCmd(answerText, ctx);
+    }
+
+    @Override
+    public void getLampTemp(String askText, String idCode, ChannelHandlerContext ctx) throws ParseException {
+        System.out.println("上传温度");
+        String[] dataArray = askText.split("\\+");
+        String tempText = dataArray[4];
+        Double temp = MathUtil.ln(Integer.parseInt(tempText));
+        String eartemp = new BigDecimal(temp).setScale(1, BigDecimal.ROUND_HALF_UP).toString();
+        DateUtil dateUtil = new DateUtil();
+        lampTempService.saveLampTemp(idCode,eartemp,dateUtil.getTodayDatetime());
+        String answerText = "hm+"+idCode+"+2+0+7+end";
+        log.info(">>上传温度请求-应答数据>>" + answerText);
+        answerCmd(answerText, ctx);
+    }
+
+    @Override
+    public void getLampConfig(String askText, String idCode, ChannelHandlerContext ctx) {
+        System.out.println("获取温度配置");
+        String configTemp = lampConfigService.getLampConfigByDeviceId(idCode);
+        String answerText = "hm+"+idCode+"+3+1+"+configTemp+"+7+end";
+        log.info(">>获取保温箱温度配置请求-应答数据>>" + answerText);
+        answerCmd(answerText, ctx);
+    }
+
+    //应答
+    public void answerCmd(String answerText, ChannelHandlerContext ctx) {
+        ctx.writeAndFlush(Unpooled.copiedBuffer(answerText.getBytes()));
+    }
+}

+ 69 - 0
huimv-env-platform/huimv-env-lamp/src/main/resources/application-dev.yml

@@ -0,0 +1,69 @@
+server:
+  port: 8090
+
+spring:
+  application:
+    name: huimv-env-input
+
+  datasource:
+    url: jdbc:mysql://192.168.1.7:3306/huimv-env-platform?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
+    username: root
+    password: hm123456
+    driver-class-name: com.mysql.cj.jdbc.Driver
+  jpa:
+    show-sql: true
+    database: mysql
+    hibernate:
+      ddl-auto: update
+    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
+    open-in-view: true
+
+  #配置rabbitMq 服务器
+#  rabbitmq:
+#    host: 10.0.0.4
+#    port: 5672
+#    username: huimv
+#    password: hm123456
+#    #虚拟host 可以不设置,使用server默认host
+#    virtual-host: /
+  rabbitmq:
+    host: 192.168.1.82
+    port: 5672
+    username: admin
+    password: admin
+    #虚拟host 可以不设置,使用server默认host
+    virtual-host: /env
+
+    #确认消息已发送到交换机(Exchange)
+#    publisher-confirms: true #(过时、弃用)
+    publisher-confirm-type: correlated
+    #确认消息已发送到队列(Queue)
+    publisher-returns: true
+
+  #redis
+  redis:
+    database: 0
+    host: 192.168.1.68
+    port: 6379
+    password: hm123456
+    timeout: 5000ms
+    jedis:
+      pool:
+        max-active: 20
+        max-wait: -1
+        max-idle: 10
+        min-idle: 0
+    lettuce:
+      pool:
+        max-active: 3
+        min-idle: 2
+        max-idle: 3
+        max-wait: 1
+      shutdown-timeout: 100
+
+management:
+  endpoints:
+    web:
+      exposure:
+        include: "*"   # * 在yaml 文件属于关键字,所以需要加引号
+

+ 104 - 0
huimv-env-platform/huimv-env-lamp/src/main/resources/application-prod.yml

@@ -0,0 +1,104 @@
+server:
+  port: 8090
+
+spring:
+  application:
+    name: huimv-env-input
+
+  datasource:
+    url: jdbc:mysql://122.112.224.199:3306/huimv-env-platform?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
+    username: root
+    password: hm123456
+    driver-class-name: com.mysql.cj.jdbc.Driver
+  jpa:
+    show-sql: true
+    database: mysql
+    hibernate:
+      ddl-auto: update
+    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
+    open-in-view: true
+
+  #配置rabbitMq 服务器
+#  rabbitmq:
+#    host: 10.0.0.4
+#    port: 5672
+#    username: huimv
+#    password: hm123456
+#    #虚拟host 可以不设置,使用server默认host
+#    virtual-host: /
+  rabbitmq:
+    host: 121.36.134.218
+    port: 5672
+    username: admin
+    password: admin
+    #虚拟host 可以不设置,使用server默认host
+    virtual-host: /env
+
+    #确认消息已发送到交换机(Exchange)
+#    publisher-confirms: true #(过时、弃用)
+    publisher-confirm-type: correlated
+    #确认消息已发送到队列(Queue)
+    publisher-returns: true
+
+  #redis
+  redis:
+    database: 0
+    host: 192.168.1.68
+    port: 6379
+    password: hm123456
+    timeout: 5000ms
+    jedis:
+      pool:
+        max-active: 20
+        max-wait: -1
+        max-idle: 10
+        min-idle: 0
+    lettuce:
+      pool:
+        max-active: 3
+        min-idle: 2
+        max-idle: 3
+        max-wait: 1
+      shutdown-timeout: 100
+
+  data:
+    redis:
+      repositories:
+        enabled: false
+
+  #是否缓存空值
+  cache:
+    redis:
+      cache-null-values: false
+
+
+
+    #server:
+#  port: 9110
+#spring:
+#  application:
+#    name: huimv-hy-autoGetData
+#
+#  datasource:
+##    url: jdbc:mysql://47.98.175.112:3306/huimv_ql_farm_haiyan?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
+#    #    url: jdbc:mysql://36.22.189.214:3306/huimv_ql_farm?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
+#        url: jdbc:mysql://192.168.1.7:3306/huimv_ql_farm?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
+#    username: root
+#    password: hm123456
+#    driver-class-name: com.mysql.cj.jdbc.Driver
+#  jpa:
+#    properties:
+#      hibernate:
+#        enable_lazy_load_no_trans: true
+#    show-sql: true
+#    database: mysql
+#    hibernate:
+#      ddl-auto: update
+#    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
+#    open-in-view: true
+management:
+  endpoints:
+    web:
+      exposure:
+        include: "*"   # * 在yaml 文件属于关键字,所以需要加引号
+

+ 32 - 0
huimv-env-platform/huimv-env-lamp/src/main/resources/application.properties

@@ -0,0 +1,32 @@
+spring.profiles.active=dev
+#spring.profiles.active=prod
+
+#\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD
+management.endpoints.web.exposure.include=*
+
+#########################################################
+###             \uFFFD\uFFFD\uFFFD\uFFFDundertow\u0221\uFFFD\uFFFDtomcat                ###
+#########################################################
+# \uFFFD\u01F7\uFFFD\uFFFD undertow \uFFFD\uFFFD\u05BE\uFFFD\uFFFD\u012C\uFFFD\uFFFD\u03AA false
+server.undertow.accesslog.enabled=false
+# \uFFFD\uFFFD\uFFFD\u00F7\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u05BE\uFFFD\uFFFD\uFFFD\uFFFD\u013F\u00BC
+server.undertow.accesslog.dir=logs
+# \u05B8\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u07F3\u0335\uFFFD I/0 \uFFFD\u07F3\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u012C\uFFFD\uFFFD\u03AA 2 \uFFFD\uFFFD\uFFFD\uFFFD CPU \uFFFD\u0138\uFFFD\uFFFD\uFFFD
+server.undertow.io-threads=
+# \u05B8\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u07F3\u0338\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u012C\uFFFD\uFFFD\u03AA I/O \uFFFD\u07F3\u0338\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD 8 \uFFFD\uFFFD
+server.undertow.worker-threads=
+# \uFFFD\uFFFD\uFFFD\uFFFD HTTP POST \uFFFD\uFFFD\uFFFD\u0775\uFFFD\uFFFD\uFFFD\uDB8E\uDD36\u0223\uFFFD\u012C\uFFFD\u03F2\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD
+server.undertow.max-http-post-size=0
+
+#########################################################
+###   Actuator Monitor  --   Actuator configuration   ###
+#########################################################
+management.security.enabled=false
+
+# \uFFFD\uFFFD\uFFFD\u0774\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD
+data.input.flow=2
+
+# \uFFFD\u01F7\uFFFD\u0434\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD(1:\u0434\uFFFD\uFFFD 0:\uFFFD\uFFFD\u0434\uFFFD\uFFFD)
+data.test.input=0
+
+

+ 24 - 0
huimv-env-platform/huimv-env-lamp/src/main/resources/assembly.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<assembly>
+    <id>jar-with-dependencies</id>
+    <formats>
+        <format>jar</format>
+    </formats>
+    <includeBaseDirectory>false</includeBaseDirectory>
+    <dependencySets>
+        <!-- 默认的配置 -->
+        <dependencySet>
+            <outputDirectory>/</outputDirectory>
+            <useProjectArtifact>true</useProjectArtifact>
+            <unpack>true</unpack>
+            <scope>runtime</scope>
+        </dependencySet>
+        <!-- 增加scope类型为system的配置 -->
+        <dependencySet>
+            <outputDirectory>/</outputDirectory>
+            <useProjectArtifact>true</useProjectArtifact>
+            <unpack>true</unpack>
+            <scope>system</scope>
+        </dependencySet>
+    </dependencySets>
+</assembly>