ソースを参照

Merge remote-tracking branch 'origin/master'

hecheng 3 年 前
コミット
71c9ef6857

+ 43 - 13
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/controller/device/DeviceRemoteController.java

@@ -6,8 +6,11 @@ import com.zd.common.redis.service.RedisService;
 import com.zd.laboratory.socket.runner.TCPServer;
 import com.zd.laboratory.socket.service.SocketService;
 import com.zd.laboratory.utils.CRCCHECK;
+import com.zd.system.api.domain.PlayVo;
 import com.zd.system.api.laboratory.CabinetV2Lock;
 import com.zd.system.api.laboratory.domain.CabinetLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -25,6 +28,7 @@ import java.util.concurrent.TimeUnit;
 @RestController
 @RequestMapping("/device/remote")
 public class DeviceRemoteController {
+    private static Logger logger = LoggerFactory.getLogger(DeviceRemoteController.class);
 
     @Autowired
     private SocketService socketService;
@@ -50,23 +54,39 @@ public class DeviceRemoteController {
 
         try {
             ops.write(ReUtil.hexStringToByteArray(instruct));
+            ops.flush();
+            logger.info("柜锁开锁指令:" + instruct);
 
-            Thread.sleep(1800);
+            Thread.sleep(500);
+            ops.write(ReUtil.hexStringToByteArray(instruct));
+            ops.flush();
+
+            Thread.sleep(800);
+            ops.write(ReUtil.hexStringToByteArray(instruct));
+            ops.flush();
+
+            Thread.sleep(700);
+            ops.write(ReUtil.hexStringToByteArray(instruct));
+            ops.flush();
 
-            ops.write(ReUtil.hexStringToByteArray(CRCCHECK.getReadLockOrder(Integer.parseInt(cabinetV2Lock.getLockId()))));
+            instruct = CRCCHECK.getReadLockOrder(Integer.parseInt(cabinetV2Lock.getLockId()));
+            ops.write(ReUtil.hexStringToByteArray(instruct));
+            ops.flush();
 
-            Thread.sleep(300);
+            Thread.sleep(500);
             Integer status = redisService.getCacheObject(relayCode + ":" + cabinetV2Lock.getLockId());
-            if(status != null && status == 1){
+            logger.info("柜锁开锁锁状态查询:" + instruct + ",开锁结果:" + status);
+            /*if(status != null && status == 1){
                 return R.ok("开锁成功");
-            }
+            }*/
             // TODO 因样件锁 发送开锁指令后锁未主动弹开,先不关注锁的状态
-//            return R.ok();
+            return R.ok("开锁成功");
         } catch (Exception e) {
             e.printStackTrace();
+            logger.error("柜锁连接失败:" + e.getMessage());
             return R.fail("柜锁连接失败!");
         }
-        return R.fail("开锁失败");
+        //return R.fail("开锁失败");
     }
 
     /**
@@ -80,20 +100,30 @@ public class DeviceRemoteController {
 
         try {
             ops.write(ReUtil.hexStringToByteArray(instruct));
+            ops.flush();
+            logger.info("柜锁关锁指令:" + instruct);
+            Thread.sleep(1000);
 
-            Thread.sleep(1800);
+            instruct = CRCCHECK.getReadLockOrder(Integer.parseInt(cabinetV2Lock.getLockId()));
+            ops.write(ReUtil.hexStringToByteArray(instruct));
+            ops.flush();
 
-            ops.write(ReUtil.hexStringToByteArray(CRCCHECK.getReadLockOrder(Integer.parseInt(cabinetV2Lock.getLockId()))));
+            Thread.sleep(600);
+            ops.write(ReUtil.hexStringToByteArray(instruct));
+            ops.flush();
 
-            Thread.sleep(300);
+            Thread.sleep(900);
             Integer status = redisService.getCacheObject(relayCode + ":" + cabinetV2Lock.getLockId());
-            if(status != null && status == 0){
+            logger.info("柜锁关锁状态查询:" + instruct + ",关锁结果" + status);
+            /*if(status != null && status == 0){
                 return R.ok("关锁成功");
-            }
+            }*/
+            return R.ok("关锁成功");
         } catch (Exception e) {
             e.printStackTrace();
+            logger.error("柜锁连接失败:" + e.getMessage());
             return R.fail("柜锁连接失败!");
         }
-        return R.fail("关锁失败");
+        //return R.fail("关锁失败");
     }
 }

+ 1 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/socket/service/SocketService.java

@@ -467,6 +467,6 @@ public class SocketService {
         int status = CRCCHECK.getLockStatus(data);
 
         log.info("柜锁回调:" + relayCode.get() + ":" + bit + ",回调结果" + (status == 1 ? "开启": "关闭") + ",指令:" + data);
-        redisService.setCacheObject(relayCode.get() + ":" + bit, status, 60L, TimeUnit.SECONDS);
+        redisService.setCacheObject(relayCode.get() + ":" + bit, status, 3 * 60L, TimeUnit.SECONDS);
     }
 }