Переглянути джерело

Merge branch 'master' of http://192.168.1.43:3000/git/sass-lab-distributed-java

zhuchangxue 3 роки тому
батько
коміт
67fcd27be6

+ 28 - 28
zd-modules/zd-camera/pom.xml

@@ -288,34 +288,34 @@
 			</plugin>
 			</plugin>
 
 
 			<!-- docker的maven插件 -->
 			<!-- docker的maven插件 -->
-			<plugin>
-				<groupId>com.spotify</groupId>
-				<artifactId>dockerfile-maven-plugin</artifactId>
-				<version>${docker.maven.verion}</version>
-
-				<executions>
-					<!--执行 mvn package 时 自动构建docker镜像并推送到仓库 -->
-					<execution>
-						<id>default</id>
-						<phase>package</phase>
-						<goals>
-							<goal>build</goal>
-							<goal>push</goal>
-						</goals>
-					</execution>
-				</executions>
-				<configuration>
-					<repository>${docker.registry}/${docker.namespace}/${project.artifactId}</repository>
-					<tag>latest</tag>
-					<!-- 镜像服务器账号密码  -->
-					<username>admin</username>
-					<password>zd123456..</password>
-					<!-- 构建参数,指定jar包名称 -->
-					<buildArgs>
-						<JAR_FILE>${project.artifactId}.jar</JAR_FILE>
-					</buildArgs>
-				</configuration>
-			</plugin>
+<!--			<plugin>-->
+<!--				<groupId>com.spotify</groupId>-->
+<!--				<artifactId>dockerfile-maven-plugin</artifactId>-->
+<!--				<version>${docker.maven.verion}</version>-->
+
+<!--				<executions>-->
+<!--					&lt;!&ndash;执行 mvn package 时 自动构建docker镜像并推送到仓库 &ndash;&gt;-->
+<!--					<execution>-->
+<!--						<id>default</id>-->
+<!--						<phase>package</phase>-->
+<!--						<goals>-->
+<!--							<goal>build</goal>-->
+<!--							<goal>push</goal>-->
+<!--						</goals>-->
+<!--					</execution>-->
+<!--				</executions>-->
+<!--				<configuration>-->
+<!--					<repository>${docker.registry}/${docker.namespace}/${project.artifactId}</repository>-->
+<!--					<tag>latest</tag>-->
+<!--					&lt;!&ndash; 镜像服务器账号密码  &ndash;&gt;-->
+<!--					<username>admin</username>-->
+<!--					<password>zd123456..</password>-->
+<!--					&lt;!&ndash; 构建参数,指定jar包名称 &ndash;&gt;-->
+<!--					<buildArgs>-->
+<!--						<JAR_FILE>${project.artifactId}.jar</JAR_FILE>-->
+<!--					</buildArgs>-->
+<!--				</configuration>-->
+<!--			</plugin>-->
 		</plugins>
 		</plugins>
 	</build>
 	</build>
 </project>
 </project>

+ 10 - 12
zd-modules/zd-chemical/src/main/java/com/zd/chemical/service/impl/ActAuditconfigServiceImpl.java

@@ -1,28 +1,26 @@
 package com.zd.chemical.service.impl;
 package com.zd.chemical.service.impl;
 
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.atomic.LongAdder;
-import java.util.stream.Collectors;
-
-import com.sun.xml.internal.bind.v2.util.CollisionCheckStack;
+import com.zd.chemical.domain.ActAuditconfig;
 import com.zd.chemical.domain.ActAudituser;
 import com.zd.chemical.domain.ActAudituser;
 import com.zd.chemical.domain.vo.ActAuditconfigVo;
 import com.zd.chemical.domain.vo.ActAuditconfigVo;
 import com.zd.chemical.domain.vo.ActAudituserVo;
 import com.zd.chemical.domain.vo.ActAudituserVo;
+import com.zd.chemical.mapper.ActAuditconfigMapper;
 import com.zd.chemical.mapper.ActAudituserMapper;
 import com.zd.chemical.mapper.ActAudituserMapper;
+import com.zd.chemical.service.IActAuditconfigService;
 import com.zd.common.core.utils.DateUtils;
 import com.zd.common.core.utils.DateUtils;
 import com.zd.common.core.utils.SecurityUtils;
 import com.zd.common.core.utils.SecurityUtils;
 import com.zd.common.security.utils.SaveUtil;
 import com.zd.common.security.utils.SaveUtil;
-
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
-import com.zd.chemical.mapper.ActAuditconfigMapper;
-import com.zd.chemical.domain.ActAuditconfig;
-import com.zd.chemical.service.IActAuditconfigService;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.atomic.LongAdder;
+import java.util.stream.Collectors;
 
 
 /**
 /**
  * 工作流审批Service业务层处理
  * 工作流审批Service业务层处理

+ 6 - 6
zd-modules/zd-netty/src/main/java/com/zd/netty/init/NettyStartListener.java

@@ -3,14 +3,14 @@ package com.zd.netty.init;
 import com.zd.common.core.constant.HttpStatus;
 import com.zd.common.core.constant.HttpStatus;
 import com.zd.common.core.domain.R;
 import com.zd.common.core.domain.R;
 import com.zd.common.core.enums.HardwareOperate;
 import com.zd.common.core.enums.HardwareOperate;
+import com.zd.common.core.utils.SpringUtils;
 import com.zd.netty.service.IFridService;
 import com.zd.netty.service.IFridService;
-import com.zd.netty.thread.ThreadPoolTaskConfig;
 import com.zd.system.api.laboratory.RemoteLaboratoryService;
 import com.zd.system.api.laboratory.RemoteLaboratoryService;
 import com.zd.system.api.laboratory.domain.RemoteLabHardware;
 import com.zd.system.api.laboratory.domain.RemoteLabHardware;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
 import org.springframework.boot.ApplicationRunner;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 import org.springframework.util.StringUtils;
 import org.springframework.util.StringUtils;
 
 
@@ -29,16 +29,16 @@ public class NettyStartListener implements ApplicationRunner {
     private IFridService fridService;
     private IFridService fridService;
     @Resource
     @Resource
     private RemoteLaboratoryService laboratoryService;
     private RemoteLaboratoryService laboratoryService;
-    @Autowired
-    private SocketServer socketServer;
     @Resource
     @Resource
-    private ThreadPoolTaskConfig threadPoolTaskConfig;
+    private SocketServer socketServer;
+
+    private final ThreadPoolTaskExecutor taskExecutor= SpringUtils.getBean("taskExecutor");
 
 
     @Override
     @Override
     public void run(ApplicationArguments args) {
     public void run(ApplicationArguments args) {
         socketServer.start();
         socketServer.start();
 
 
-        threadPoolTaskConfig.getAsyncExecutor().execute(() -> {
+        taskExecutor.execute(() -> {
             synchronized (this) {
             synchronized (this) {
                 R<List<RemoteLabHardware>> listStart = laboratoryService.listStart();
                 R<List<RemoteLabHardware>> listStart = laboratoryService.listStart();
                 while (listStart.getCode() != HttpStatus.SUCCESS) {
                 while (listStart.getCode() != HttpStatus.SUCCESS) {

+ 45 - 52
zd-modules/zd-netty/src/main/java/com/zd/netty/sdk/DeJuRFIDService.java

@@ -5,6 +5,7 @@ import com.gg.reader.api.dal.HandlerTagEpcLog;
 import com.gg.reader.api.dal.HandlerTagEpcOver;
 import com.gg.reader.api.dal.HandlerTagEpcOver;
 import com.gg.reader.api.protocol.gx.*;
 import com.gg.reader.api.protocol.gx.*;
 import com.zd.common.core.exception.ServiceException;
 import com.zd.common.core.exception.ServiceException;
+import com.zd.common.core.utils.SpringUtils;
 import com.zd.netty.service.ISendService;
 import com.zd.netty.service.ISendService;
 import com.zd.netty.service.IService;
 import com.zd.netty.service.IService;
 import com.zd.netty.thread.ThreadPoolTaskConfig;
 import com.zd.netty.thread.ThreadPoolTaskConfig;
@@ -12,13 +13,15 @@ import com.zd.system.api.domain.InventoryTag;
 import com.zd.system.api.laboratory.domain.RemoteLabHardware;
 import com.zd.system.api.laboratory.domain.RemoteLabHardware;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeanUtils;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 
 
 @Slf4j
 @Slf4j
 @Service
 @Service
@@ -29,8 +32,7 @@ public class DeJuRFIDService implements IService {
 
 
     private final Map<String, GClient> clientMap = new ConcurrentHashMap<>();
     private final Map<String, GClient> clientMap = new ConcurrentHashMap<>();
 
 
-    @Resource
-    private ThreadPoolTaskConfig threadPoolTaskConfig;
+    private final ScheduledExecutorService scheduledExecutorService= SpringUtils.getBean("scheduledExecutorService");
 
 
     @Override
     @Override
     public void start(RemoteLabHardware hardware) {
     public void start(RemoteLabHardware hardware) {
@@ -66,10 +68,14 @@ public class DeJuRFIDService implements IService {
                         log.info("Power configuration successful.");
                         log.info("Power configuration successful.");
                     } else {
                     } else {
                         log.info("Power configuration error.");
                         log.info("Power configuration error.");
+                        disconnect(hardware);
+                        start(hardware);
                     }
                     }
                 }
                 }
             } else {
             } else {
                 log.info("Power configuration error.");
                 log.info("Power configuration error.");
+                disconnect(hardware);
+                start(hardware);
             }
             }
 
 
             //蜂鸣器设置
             //蜂鸣器设置
@@ -107,6 +113,8 @@ public class DeJuRFIDService implements IService {
                 log.info("Inventory epc successful.");
                 log.info("Inventory epc successful.");
             } else {
             } else {
                 log.info("Inventory epc error.");
                 log.info("Inventory epc error.");
+                disconnect(hardware);
+                start(hardware);
             }
             }
         } else {
         } else {
             throw new ServiceException("Connect failure.");
             throw new ServiceException("Connect failure.");
@@ -118,22 +126,7 @@ public class DeJuRFIDService implements IService {
         String ipAddress = hardware.getIpAddress();
         String ipAddress = hardware.getIpAddress();
         if (clientMap.containsKey(ipAddress)) {
         if (clientMap.containsKey(ipAddress)) {
             GClient client = clientMap.get(ipAddress);
             GClient client = clientMap.get(ipAddress);
-            MsgAppSetGpo msgAppSetGpo=new MsgAppSetGpo();
-            msgAppSetGpo.setGpo1(0);
-            msgAppSetGpo.setGpo2(0);
-            msgAppSetGpo.setGpo3(0);
-            msgAppSetGpo.setGpo4(0);
-            msgAppSetGpo.setGpo5(0);
-            msgAppSetGpo.setGpo6(0);
-            msgAppSetGpo.setGpo7(0);
-            msgAppSetGpo.setGpo8(0);
-
-            client.sendSynMsg(msgAppSetGpo);
-            if (0 == msgAppSetGpo.getRtCode()) {
-                log.info("Gpo epc stop successful.");
-            } else {
-                log.error("Gpo epc stop error.");
-            }
+            changeGpo(0, client);
             MsgBaseStop msg = new MsgBaseStop();
             MsgBaseStop msg = new MsgBaseStop();
             // 停止读卡,空闲态
             // 停止读卡,空闲态
             client.sendSynMsg(msg);
             client.sendSynMsg(msg);
@@ -148,6 +141,35 @@ public class DeJuRFIDService implements IService {
         }
         }
     }
     }
 
 
+    private void changeGpo(int state, GClient client) {
+        MsgAppSetGpo msgAppSetGpo=new MsgAppSetGpo();
+        msgAppSetGpo.setGpo1(state);
+        msgAppSetGpo.setGpo2(state);
+        msgAppSetGpo.setGpo3(state);
+        msgAppSetGpo.setGpo4(state);
+        msgAppSetGpo.setGpo5(state);
+        msgAppSetGpo.setGpo6(state);
+        msgAppSetGpo.setGpo7(state);
+        msgAppSetGpo.setGpo8(state);
+
+        client.sendSynMsg(msgAppSetGpo);
+        String status = state == 1 ? "start" : "stop";
+        if (0 == msgAppSetGpo.getRtCode()) {
+            log.info("Gpo epc {} successful.",status);
+        } else {
+            log.error("Gpo epc {} error.",status);
+        }
+    }
+
+    public void stopGpo(GClient client){
+        scheduledExecutorService.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                changeGpo(0, client);
+            }
+        },10, TimeUnit.SECONDS);
+    }
+
     /**
     /**
      * 订阅6c标签信息上报
      * 订阅6c标签信息上报
      *
      *
@@ -158,37 +180,8 @@ public class DeJuRFIDService implements IService {
             if (logBaseEpcInfo.getResult() == 0) {
             if (logBaseEpcInfo.getResult() == 0) {
                 log.info("===========》{}",logBaseEpcInfo.getbEpc());
                 log.info("===========》{}",logBaseEpcInfo.getbEpc());
                 //灯带设置
                 //灯带设置
-                MsgAppSetGpo msgAppSetGpo=new MsgAppSetGpo();
-                msgAppSetGpo.setGpo1(1);
-                msgAppSetGpo.setGpo2(1);
-                msgAppSetGpo.setGpo3(1);
-                msgAppSetGpo.setGpo4(1);
-                msgAppSetGpo.setGpo5(1);
-                msgAppSetGpo.setGpo6(1);
-                msgAppSetGpo.setGpo7(1);
-                msgAppSetGpo.setGpo8(1);
-                client.sendSynMsg(msgAppSetGpo);
-                if (0 == msgAppSetGpo.getRtCode()) {
-                    log.info("Gpo epc successful.");
-                } else {
-                    log.error("Gpo epc error.");
-                }
-                threadPoolTaskConfig.getAsyncExecutor().execute(() -> {
-                    msgAppSetGpo.setGpo1(0);
-                    msgAppSetGpo.setGpo2(0);
-                    msgAppSetGpo.setGpo3(0);
-                    msgAppSetGpo.setGpo4(0);
-                    msgAppSetGpo.setGpo5(0);
-                    msgAppSetGpo.setGpo6(0);
-                    msgAppSetGpo.setGpo7(0);
-                    msgAppSetGpo.setGpo8(0);
-                    client.sendSynMsg(msgAppSetGpo);
-                    if (0 == msgAppSetGpo.getRtCode()) {
-                        log.info("Gpo epc stop successful.");
-                    } else {
-                        log.error("Gpo epc stop error.");
-                    }
-                },8*1000);
+                changeGpo(1, client);
+                stopGpo(client);
                 InventoryTag tag = new InventoryTag();
                 InventoryTag tag = new InventoryTag();
                 BeanUtils.copyProperties(logBaseEpcInfo, tag);
                 BeanUtils.copyProperties(logBaseEpcInfo, tag);
                 sendService.send(tag);
                 sendService.send(tag);

+ 58 - 15
zd-modules/zd-netty/src/main/java/com/zd/netty/thread/ThreadPoolTaskConfig.java

@@ -1,30 +1,34 @@
 package com.zd.netty.thread;
 package com.zd.netty.thread;
 
 
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.concurrent.BasicThreadFactory;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 
 
-import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.*;
 
 
+/**
+ * @author Administrator
+ */
 @Configuration
 @Configuration
-@EnableAsync
+@Slf4j
 public class ThreadPoolTaskConfig {
 public class ThreadPoolTaskConfig {
 
 
-    private static final int corePoolSize = 10;       		// 核心线程数(默认线程数)
-    private static final int maxPoolSize = 100;			    // 最大线程数
-    private static final int keepAliveTime = 10;			// 允许线程空闲时间(单位:默认为秒)
-    private static final int queueCapacity = 200;			// 缓冲队列数
-    private static final String threadNamePrefix = "Async-Service-"; // 线程池名前缀
+    private static final int CORE_POOL_SIZE = 10;
+    private static final int MAX_POOL_SIZE = 100;
+    private static final int KEEP_ALIVE_TIME = 10;
+    private static final int QUEUE_CAPACITY = 200;
+    private static final String THREAD_NAME_PREFIX = "Async-Service-";
 
 
-    @Bean("taskExecutor") // bean的名称,默认为首字母小写的方法名
-    public ThreadPoolTaskExecutor getAsyncExecutor(){
+    @Bean("taskExecutor")
+    public ThreadPoolTaskExecutor threadPoolTaskExecutor(){
         ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
         ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
-        executor.setCorePoolSize(corePoolSize);
-        executor.setMaxPoolSize(maxPoolSize);
-        executor.setQueueCapacity(queueCapacity);
-        executor.setKeepAliveSeconds(keepAliveTime);
-        executor.setThreadNamePrefix(threadNamePrefix);
+        executor.setCorePoolSize(CORE_POOL_SIZE);
+        executor.setMaxPoolSize(MAX_POOL_SIZE);
+        executor.setQueueCapacity(QUEUE_CAPACITY);
+        executor.setKeepAliveSeconds(KEEP_ALIVE_TIME);
+        executor.setThreadNamePrefix(THREAD_NAME_PREFIX);
 
 
         // 线程池对拒绝任务的处理策略
         // 线程池对拒绝任务的处理策略
         executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
         executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
@@ -32,4 +36,43 @@ public class ThreadPoolTaskConfig {
         executor.initialize();
         executor.initialize();
         return executor;
         return executor;
     }
     }
+
+    /**
+     * 执行定时任务
+     */
+    @Bean(name = "scheduledExecutorService")
+    public ScheduledExecutorService scheduledExecutorService() {
+        return new ScheduledThreadPoolExecutor(CORE_POOL_SIZE,
+                new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build()) {
+            @Override
+            protected void afterExecute(Runnable r, Throwable t) {
+                super.afterExecute(r, t);
+                printException(r, t);
+            }
+        };
+    }
+
+
+    /**
+     * 打印线程异常信息
+     */
+    public static void printException(Runnable r, Throwable t) {
+        if (t == null && r instanceof Future<?>) {
+            try {
+                Future<?> future = (Future<?>) r;
+                if (future.isDone()) {
+                    future.get();
+                }
+            } catch (CancellationException ce) {
+                t = ce;
+            } catch (ExecutionException ee) {
+                t = ee.getCause();
+            } catch (InterruptedException ie) {
+                Thread.currentThread().interrupt();
+            }
+        }
+        if (t != null) {
+            log.error(t.getMessage(), t);
+        }
+    }
 }
 }