Jelajahi Sumber

Merge branch 'master' of D:\idea4\huimv.farm.datacenter with conflicts.

zhuoning 2 tahun lalu
induk
melakukan
1c5409ce9b

+ 3 - 3
huimv-farm-admin/src/main/resources/application.properties

@@ -1,7 +1,7 @@
 #spring.profiles.active=dev
 #spring.profiles.active=prod3
-spring.profiles.active=prod
-#spring.profiles.active=demo
+#spring.profiles.active=prod
+spring.profiles.active=demo
 #spring.profiles.active=yv
 
 #时间格式配置
@@ -23,7 +23,7 @@ weight.batch.prefix=W
 weight.batchCode.spacemark=-
 
 #牧场端设备数据是否同步(true/false)
-farm.device.sync=false
+farm.device.sync=true
 farm.device.addService=/farm/device/syncAddFarmDevice
 farm.device.editService=/farm/device/syncEditFarmDevice
 farm.device.removeService=/farm/device/syncRemoveFarmDevice

+ 5 - 4
huimv-farm-eartag/src/main/java/com/huimv/eartag/HuimvEartagApplication.java

@@ -1,5 +1,6 @@
 package com.huimv.eartag;
 
+import com.huimv.eartag.server.EartagServer;
 import com.huimv.eartag.server.EartagServer2;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
@@ -22,9 +23,9 @@ public class HuimvEartagApplication {
     public static void main(String[] args) throws InterruptedException {
 //        SpringApplication.run(HuimvEartagApplication.class, args);
         ApplicationContext applicationContext = SpringApplication.run(HuimvEartagApplication.class, args);
-        //EartagServer
-//        applicationContext.getBean(EartagServer.class).start();
-        //EartagServer2
-        applicationContext.getBean(EartagServer2.class).run();
+        //
+        applicationContext.getBean(EartagServer.class).run2();
+        //
+//        applicationContext.getBean(EartagServer2.class).run();
     }
 }

+ 113 - 0
huimv-farm-eartag/src/main/java/com/huimv/eartag/server/EartagServer.java

@@ -0,0 +1,113 @@
+package com.huimv.eartag.server;
+
+import cn.hutool.core.util.CharsetUtil;
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.buffer.ByteBuf;
+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.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+//import io.netty.util.CharsetUtil;
+import cn.hutool.core.util.CharsetUtil;
+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 EartagServer {
+    @Autowired
+    private EartagServerHandler2 serverHandler;
+    //监听端口
+    private int port = 8012;
+    private int port2 = 8013;
+    //创建构造方法
+    public EartagServer(){
+    }
+
+    public static void main(String[] args) throws InterruptedException {
+        new EartagServer().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)    //指定处理的连接类型
+                    .option(ChannelOption.SO_REUSEADDR, true)
+                    .childHandler(new ChannelInitializer<SocketChannel>() {
+                        @Override
+                        protected void initChannel(SocketChannel socketChannel) throws Exception {
+                            socketChannel.pipeline().addLast(serverHandler);
+                        }
+                    });
+            System.out.println("# 耳标及采集器设备数据接收服务器已经启动。#");
+            System.out.println("# 准备接收数据:");
+            //绑定端口,同步等待成功
+            ChannelFuture cf = serverBootstrap.bind(port).sync();
+            ChannelFuture cf2 = serverBootstrap.bind(port2).sync();
+            // 等待服务端监听端口关闭
+            cf.channel().closeFuture().sync();
+            cf2.channel().closeFuture().sync();
+        }finally {
+            //优雅的退出
+            bossGroup.shutdownGracefully();
+            workGroup.shutdownGracefully();
+        }
+    }
+
+    public void run2() throws InterruptedException {
+        ServerBootstrap b = new ServerBootstrap();
+        EventLoopGroup bossGroup = new NioEventLoopGroup();
+        EventLoopGroup workerGroup = new NioEventLoopGroup();
+
+        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
+                .option(ChannelOption.SO_REUSEADDR, true)
+                .childHandler(new ChannelInitializer() {
+                    @Override
+                    protected void initChannel(Channel ch) throws Exception {
+                        ch.pipeline()
+                                .addLast("logging", new LoggingHandler(LogLevel.INFO))
+                                .addLast(new SimpleChannelInboundHandler() {
+                                    @Override
+                                    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
+                                        ByteBuf data = (ByteBuf) msg;
+                                        String clientAskText = data.toString(io.netty.util.CharsetUtil.UTF_8);
+//                                        String strMsg = msg.toString(CharsetUtil.UTF_8);
+                                        System.out.println("clientAskText>>"+clientAskText);
+                                    }
+                                });
+                    }
+                });
+
+//        b.bind(port).sync();
+//        System.out.println("tcp server("+port+") is started..");
+
+        b.bind(port2).sync();
+        System.out.println("tcp server("+port2+") is started..");
+    }
+}

+ 5 - 0
huimv-farm-eartag/src/main/java/com/huimv/eartag/server/EartagServer2.java

@@ -3,6 +3,7 @@ package com.huimv.eartag.server;
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
@@ -24,6 +25,7 @@ public class EartagServer2 {
     private EartagServerHandler2 serverHandler;
     //监听端口
     private int port = 8012;
+    private int port2 = 8013;
     //创建构造方法
     public EartagServer2(){
     }
@@ -53,6 +55,7 @@ public class EartagServer2 {
             ServerBootstrap serverBootstrap = new ServerBootstrap();
             serverBootstrap.group(bossGroup,workGroup)
                     .channel(NioServerSocketChannel.class)    //指定处理的连接类型
+                    .option(ChannelOption.SO_REUSEADDR, true)
                     .childHandler(new ChannelInitializer<SocketChannel>() {
                         @Override
                         protected void initChannel(SocketChannel socketChannel) throws Exception {
@@ -63,8 +66,10 @@ public class EartagServer2 {
             System.out.println("# 准备接收数据:");
             //绑定端口,同步等待成功
             ChannelFuture cf = serverBootstrap.bind(port).sync();
+            ChannelFuture cf2 = serverBootstrap.bind(port2).sync();
             // 等待服务端监听端口关闭
             cf.channel().closeFuture().sync();
+            cf2.channel().closeFuture().sync();
         }finally {
             //优雅的退出
             bossGroup.shutdownGracefully();

+ 6 - 23
huimv-farm-eartag/src/main/java/com/huimv/eartag/server/EartagServerHandler2.java

@@ -61,7 +61,6 @@ public class EartagServerHandler2 extends ChannelInboundHandlerAdapter {
     public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
         ByteBuf data = (ByteBuf) msg;
         String clientAskText = data.toString(CharsetUtil.UTF_8);
-//        System.out.println((++num)+"次, 客户端消息clientAskText>>"+clientAskText);
         //保存实例内的客户端请求
         appendClientAsk(clientAskText);
     }
@@ -69,27 +68,19 @@ public class EartagServerHandler2 extends ChannelInboundHandlerAdapter {
     @Override
     public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
 //        ctx.writeAndFlush("111");
-//        System.out.println("EchoServerHandle channelReadComplete");
         if(askTextSb.toString().indexOf("end") != -1){
-//            System.out.println("askTextSb.内容()>>"+askTextSb.toString());
-//            System.out.println("askTextSb.内容长度>>"+askTextSb.length());
-//            System.out.println("输入完成.");
-            // 处理客户端消息
+            // 业务处理入口 //
             handleClientEartagMessage(askTextSb.toString(),ctx);
-            //清空重置;
             askTextSb.delete(0,askTextSb.length());
             num = 0;
-//            System.out.println("清空sb实例. 长度>>"+askTextSb.length());
         }
     }
 
     @Override
     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
-//        System.out.println("cause.getMessage()>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+cause.getMessage());
         if(cause.getMessage().indexOf("Connection reset") != -1){
             log.info("相关采集器设备正在重启:"+cause.toString());
         }
-//        cause.printStackTrace();
         ctx.close();
     }
 
@@ -104,39 +95,31 @@ public class EartagServerHandler2 extends ChannelInboundHandlerAdapter {
      * @Time        : 17:36
      */
     private void handleClientEartagMessage(String clientAskText, ChannelHandlerContext ctx) throws ParseException {
-//        System.out.println("## clientAskText>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "+clientAskText);
         clientAskText = clientAskText.replaceAll("\r","").replaceAll("\n","");
         System.out.println("### 服务端接收数据 >>" + clientAskText);
-        /////////////////////////////////////////////////////////////
         //TEST-saveRawData()
         if(dataTestInput == 1){
             deviceService.saveRawData(clientAskText);
         }
-        /////////////////////////////////////////////////////////////
 
         //{}
         int countPlus = regexUtil.countPlus(clientAskText);
         if (countPlus < 4) {
             System.out.println("当前数据为不完整数据,故丢弃.>>" + clientAskText);
         } else {
-            //--处理客户端请求数据
             //{拆分粘包数据}
             JSONArray askJa = getPerData(clientAskText);
-//            System.out.println("askJa.size()="+askJa.size());
             for (int a = 0; a < askJa.size(); a++) {
                 String askText = askJa.getString(a);
-//                System.out.println((a+1)+",askText"+askText);
-                /////////////////////////////////////////////////////////////
                 //TEST-saveRawData()
 //                deviceService.saveRawData(askText);
-                /////////////////////////////////////////////////////////////
-                if (dataInputFlow == 1) {
-                    //{处理请求内容}
-                    handleAskText(askText, ctx);
-                } else {
+//                if (dataInputFlow == 1) {
+//                    //{处理请求内容}
+//                    handleAskText(askText, ctx);
+//                } else {
                     //{处理请求内容2}
                     handleAskText2(askText, ctx);
-                }
+//                }
             }
         }
     }

+ 1 - 0
huimv-farm-gateway/src/main/java/com/huimv/gateway/config/CorsConfig.java

@@ -50,6 +50,7 @@ public CorsWebFilter corsFilter() {
     config.addAllowedMethod("*");
     config.addAllowedOrigin("*");
     config.addAllowedHeader("*");
+    config.addAllowedMethod("/weight");
     UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
     source.registerCorsConfiguration("/**", config);
     return new CorsWebFilter(source);

+ 10 - 2
huimv-farm-receiver/pom.xml

@@ -16,8 +16,6 @@
         <java.version>1.8</java.version>
     </properties>
     <dependencies>
-
-
         <!-- fastjson -->
         <dependency>
             <groupId>com.alibaba</groupId>
@@ -56,6 +54,16 @@
             <artifactId>java-sdk-oauth</artifactId>
             <version>1.0.8</version>
         </dependency>
+<!--        <dependency>-->
+<!--            <groupId>com.huimv</groupId>-->
+<!--            <artifactId>huimv-common</artifactId>-->
+<!--            <version>0.0.1</version>-->
+<!--        </dependency>-->
+        <dependency>
+            <groupId>com.huimv</groupId>
+            <artifactId>huimv-common</artifactId>
+            <version>0.0.6-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 
     <build>

TEMPAT SAMPAH
huimv-farm-video/huimv-farm-video-0.0.1-SNAPSHOT-execute.jar


+ 21 - 20
huimv-farm-video/pom.xml

@@ -34,11 +34,6 @@
 			<scope>compile</scope>
 		</dependency>
 		<dependency>
-			<groupId>com.huimv</groupId>
-			<artifactId>huimv-common</artifactId>
-			<version>0.0.1-SNAPSHOT</version>
-		</dependency>
-		<dependency>
 			<groupId>commons-httpclient</groupId>
 			<artifactId>commons-httpclient</artifactId>
 			<version>3.1</version>
@@ -65,25 +60,18 @@
 			<artifactId>commons-lang3</artifactId>
 			<version>3.7</version>
 		</dependency>
-		<!-- huimv.com -->
+<!--		<dependency>-->
+<!--			<groupId>net.sf.json-lib</groupId>-->
+<!--			<artifactId>json-lib</artifactId>-->
+<!--			<version>2.2.3</version>-->
+<!--			<classifier>jdk15</classifier>-->
+<!--		</dependency>-->
+
 		<dependency>
 			<groupId>com.huimv</groupId>
 			<artifactId>huimv-common</artifactId>
-			<version>0.0.1</version>
-		</dependency>
-		<dependency>
-			<groupId>net.sf.json-lib</groupId>
-			<artifactId>json-lib</artifactId>
-			<version>2.2.3</version>
-			<classifier>jdk15</classifier>
-		</dependency>
-		<!-- JPA -->
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-data-jpa</artifactId>
+			<version>0.0.6-SNAPSHOT</version>
 		</dependency>
-
-
 	</dependencies>
 
 	<build>
@@ -97,5 +85,18 @@
 			</plugin>
 		</plugins>
 	</build>
+<!--	<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>

TEMPAT SAMPAH
lib/huimv-common-0.0.1-SNAPSHOT.jar


+ 10 - 0
pom.xml

@@ -37,6 +37,11 @@
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
+<!--        <dependency>-->
+<!--            <groupId>com.huimv</groupId>-->
+<!--            <artifactId>huimv-common</artifactId>-->
+<!--            <version>0.0.1</version>-->
+<!--        </dependency>-->
         <!-- -->
 <!--        <dependency>-->
 <!--            <groupId>com.huimv</groupId>-->
@@ -100,6 +105,11 @@
             <artifactId>fastjson</artifactId>
             <version>1.2.28</version>
         </dependency>
+<!--                <dependency>-->
+<!--                    <groupId>com.huimv</groupId>-->
+<!--                    <artifactId>huimv-common</artifactId>-->
+<!--                    <version>0.0.1</version>-->
+<!--                </dependency>-->
     </dependencies>
 
     <build>