hecheng 3 rokov pred
rodič
commit
31c30bc8d8

+ 1 - 3
zd-api/zd-api-system/src/main/java/com/zd/system/api/chemical/RemoteStockService.java

@@ -3,12 +3,10 @@ package com.zd.system.api.chemical;
 import com.zd.common.core.constant.ServiceNameConstants;
 import com.zd.system.api.chemical.factory.RemoteStockFallbackFactory;
 import com.zd.system.api.domain.InventoryTag;
-import com.zd.system.api.laboratory.domain.RemoteLabHardware;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestParam;
 
 /**
  * 化学品库存
@@ -18,7 +16,7 @@ public interface RemoteStockService {
 
 
     @PostMapping(value = "/hxpStock/RFIDCheck")
-    public void RFIDCheck(@RequestBody InventoryTag tag);
+    public void rfidCheck(@RequestBody InventoryTag tag);
 
     @GetMapping(value = "/hxpStock/expireCheck")
     public void expireCheck();

+ 6 - 10
zd-api/zd-api-system/src/main/java/com/zd/system/api/chemical/factory/RemoteStockFallbackFactory.java

@@ -1,43 +1,39 @@
 package com.zd.system.api.chemical.factory;
 
 
-import com.zd.common.core.exception.ServiceException;
 import com.zd.system.api.chemical.RemoteStockService;
 import com.zd.system.api.domain.InventoryTag;
-import com.zd.system.api.laboratory.domain.RemoteLabHardware;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.cloud.openfeign.FallbackFactory;
 import org.springframework.stereotype.Component;
-import org.springframework.web.bind.annotation.RequestBody;
 
 @Component
 public class RemoteStockFallbackFactory implements FallbackFactory<RemoteStockService> {
-    private final static Logger logger = LoggerFactory.getLogger(RemoteStockFallbackFactory.class);
+    private static final Logger logger = LoggerFactory.getLogger(RemoteStockFallbackFactory.class);
 
     @Override
     public RemoteStockService create(Throwable throwable) {
         logger.error("化学品服务调用失败:{}", throwable.getMessage());
         return new RemoteStockService() {
-
             @Override
-            public void RFIDCheck(InventoryTag tag) {
-                throw new ServiceException("保存调用失败:" + throwable.getMessage());
+            public void rfidCheck(InventoryTag tag) {
+                logger.error("保存调用失败:{}" ,throwable.getMessage());
             }
 
             @Override
             public void expireCheck() {
-                logger.error("化学品库存过期调度失败:" + throwable.getMessage());
+                logger.error("化学品库存过期调度失败:{}" ,throwable.getMessage());
             }
 
             @Override
             public void checkOvertime() {
-                logger.error("化学品领用超时调度失败:" + throwable.getMessage());
+                logger.error("化学品领用超时调度失败:{}" ,throwable.getMessage());
             }
 
             @Override
             public void indicatorMonitoring() {
-                logger.error("定时监测实验室化学品存放风险指标:" + throwable.getMessage());
+                logger.error("定时监测实验室化学品存放风险指标:{}" , throwable.getMessage());
             }
         };
     }

+ 1 - 1
zd-modules/zd-netty/src/main/java/com/zd/netty/base/FridConsumer.java

@@ -25,7 +25,7 @@ public class FridConsumer implements Consumer<InventoryTag> {
             BeanUtils.copyProperties(tag,inventoryTag);
             sendService.send(inventoryTag);
         } catch (BeansException e) {
-            throw new ServiceException(e.getMessage());
+            log.error(e.getMessage());
         }
     }
 }

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

@@ -2,15 +2,12 @@ package com.zd.netty.init;
 
 import com.zd.common.core.constant.HttpStatus;
 import com.zd.common.core.domain.R;
-import com.zd.common.core.enums.HardwareOperate;
-import com.zd.common.core.utils.SpringUtils;
 import com.zd.netty.service.IFridService;
 import com.zd.system.api.laboratory.RemoteLaboratoryService;
 import com.zd.system.api.laboratory.domain.RemoteLabHardware;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
-import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Component;
 import org.springframework.util.StringUtils;
 
@@ -32,36 +29,31 @@ public class NettyStartListener implements ApplicationRunner {
     @Resource
     private SocketServer socketServer;
 
-    private final ThreadPoolTaskExecutor taskExecutor= SpringUtils.getBean("taskExecutor");
 
     @Override
     public void run(ApplicationArguments args) {
-        socketServer.start();
-
-        taskExecutor.execute(() -> {
-            synchronized (this) {
-                R<List<RemoteLabHardware>> listStart = laboratoryService.listStart();
-                while (listStart.getCode() != HttpStatus.SUCCESS) {
-                    try {
-                        log.error("com.zd.system.api.laboratory.RemoteLaboratoryService:远程接口调用异常");
-                        //防止laboratory模块未启动完成,故每30秒执行一次程序,直到接口可以正常访问
-                        this.wait(30 * 1000L);
-                        NettyStartListener.this.run(args);
-                    } catch (InterruptedException e) {
-                        Thread.currentThread().interrupt();
-                    }
+        synchronized (this){
+            R<List<RemoteLabHardware>> listStart = laboratoryService.listStart();
+            while (listStart.getCode() != HttpStatus.SUCCESS) {
+                try {
+                    log.error("com.zd.system.api.laboratory.RemoteLaboratoryService:远程接口调用异常");
+                    //防止laboratory模块未启动完成,故每30秒执行一次程序,直到接口可以正常访问
+                    this.wait(30 * 1000L);
+                    NettyStartListener.this.run(args);
+                } catch (InterruptedException e) {
+                    Thread.currentThread().interrupt();
                 }
-                List<RemoteLabHardware> unitVos = listStart.getData();
-                if (!unitVos.isEmpty()) {
-                    try {
-                        unitVos.stream()
-                                .filter(u -> StringUtils.hasLength(u.getIpAddress()))
-                                .forEach(u -> fridService.start(u));
-                    } catch (Exception e) {
-                        e.fillInStackTrace();
-                    }
+            }
+            List<RemoteLabHardware> unitVos = listStart.getData();
+            if (!unitVos.isEmpty()) {
+                try {
+                    unitVos.stream()
+                            .filter(u -> StringUtils.hasLength(u.getIpAddress()))
+                            .forEach(u -> fridService.start(u));
+                } catch (Exception e) {
+                    e.fillInStackTrace();
                 }
             }
-        });
+        }
     }
 }

+ 1 - 1
zd-modules/zd-netty/src/main/java/com/zd/netty/sdk/DeJuRFIDServiceImpl.java

@@ -39,7 +39,7 @@ public class DeJuRFIDServiceImpl implements IService {
     private static final String HTTP_SEPARATOR = ":";
     private static final Integer TIME_OUT = 2000;
 
-    private static final Integer MAX_RETRY=3;
+    private static final Integer MAX_RETRY = 3;
 
     private static final ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
 

+ 4 - 1
zd-modules/zd-netty/src/main/java/com/zd/netty/service/impl/FridServiceImpl.java

@@ -6,12 +6,15 @@ import com.zd.netty.service.IFridService;
 import com.zd.netty.service.IService;
 import com.zd.system.api.laboratory.domain.RemoteLabHardware;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
 
 @Service
 @Slf4j
 public class FridServiceImpl implements IFridService {
 
+    private final ThreadPoolTaskExecutor taskExecutor= SpringUtils.getBean("taskExecutor");
+
 
     private IService rfidService(Integer type) {
         return SpringUtils.getBean(ManufacturerTypeEnum.matchByValue(type).getService());
@@ -19,7 +22,7 @@ public class FridServiceImpl implements IFridService {
 
     @Override
     public void start(RemoteLabHardware hardware) {
-        rfidService(hardware.getManufacturerType()).start(hardware);
+        taskExecutor.execute(()->rfidService(hardware.getManufacturerType()).start(hardware));
     }
 
     @Override

+ 1 - 1
zd-modules/zd-netty/src/main/java/com/zd/netty/service/impl/SendServiceImpl.java

@@ -28,7 +28,7 @@ public class SendServiceImpl implements ISendService {
             log.info("气瓶服务异常:"+e.getMessage());
         }
         try {
-            remoteStockService.RFIDCheck(tag);
+            remoteStockService.rfidCheck(tag);
         } catch (Exception e) {
             log.info("化学品服务异常:"+e.getMessage());
         }