|
@@ -4,6 +4,7 @@ import com.zd.common.core.redis.RedisService;
|
|
|
import com.zd.common.core.utils.ReUtil;
|
|
import com.zd.common.core.utils.ReUtil;
|
|
|
import com.zd.laboratory.api.entity.CabinetLock;
|
|
import com.zd.laboratory.api.entity.CabinetLock;
|
|
|
import com.zd.laboratory.api.entity.CabinetV2Lock;
|
|
import com.zd.laboratory.api.entity.CabinetV2Lock;
|
|
|
|
|
+import com.zd.laboratory.mqtt.service.impl.CommonSend;
|
|
|
import com.zd.laboratory.socket.runner.TCPServer;
|
|
import com.zd.laboratory.socket.runner.TCPServer;
|
|
|
import com.zd.laboratory.socket.service.SocketService;
|
|
import com.zd.laboratory.socket.service.SocketService;
|
|
|
import com.zd.laboratory.utils.CRCCHECK;
|
|
import com.zd.laboratory.utils.CRCCHECK;
|
|
@@ -32,6 +33,8 @@ public class DeviceRemoteController {
|
|
|
private SocketService socketService;
|
|
private SocketService socketService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedisService redisService;
|
|
private RedisService redisService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CommonSend commonSend;
|
|
|
|
|
|
|
|
@Value("${sys.lockTimer:30}")
|
|
@Value("${sys.lockTimer:30}")
|
|
|
private Integer lockTimer;
|
|
private Integer lockTimer;
|
|
@@ -49,6 +52,8 @@ public class DeviceRemoteController {
|
|
|
|
|
|
|
|
@PostMapping("/V2/openLock")
|
|
@PostMapping("/V2/openLock")
|
|
|
public ResultData cabinetV2OpenLock(@RequestBody CabinetV2Lock cabinetV2Lock){
|
|
public ResultData cabinetV2OpenLock(@RequestBody CabinetV2Lock cabinetV2Lock){
|
|
|
|
|
+
|
|
|
|
|
+ // socket 方式发送
|
|
|
String instruct = CRCCHECK.getOpenLockOrder(Integer.parseInt(cabinetV2Lock.getLockId()));
|
|
String instruct = CRCCHECK.getOpenLockOrder(Integer.parseInt(cabinetV2Lock.getLockId()));
|
|
|
String relayCode = cabinetV2Lock.getRelayCode();
|
|
String relayCode = cabinetV2Lock.getRelayCode();
|
|
|
OutputStream ops = TCPServer.cacheMap.get(relayCode);
|
|
OutputStream ops = TCPServer.cacheMap.get(relayCode);
|
|
@@ -76,12 +81,49 @@ public class DeviceRemoteController {
|
|
|
return ResultData.success("开锁成功");
|
|
return ResultData.success("开锁成功");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
logger.error("柜锁连接失败:" + e.getMessage());
|
|
logger.error("柜锁连接失败:" + e.getMessage());
|
|
|
return ResultData.fail("柜锁连接失败!");
|
|
return ResultData.fail("柜锁连接失败!");
|
|
|
}
|
|
}
|
|
|
return ResultData.fail("开锁失败");
|
|
return ResultData.fail("开锁失败");
|
|
|
|
|
+
|
|
|
|
|
+ // mqtt 方式
|
|
|
|
|
+ /*String instruct = CRCCHECK.getOpenLockOrder(Integer.parseInt(cabinetV2Lock.getLockId()));
|
|
|
|
|
+ logger.info("柜锁MQTT开锁发送:" + instruct);
|
|
|
|
|
+ commonSend.send(socketService.getSteerSubscriptPrefix() + "/" + cabinetV2Lock.getRelayCode(),
|
|
|
|
|
+ ReUtil.hexStringToByteArray(instruct));
|
|
|
|
|
+
|
|
|
|
|
+ instruct = CRCCHECK.getReadLockOrder(Integer.parseInt(cabinetV2Lock.getLockId()));
|
|
|
|
|
+ int timer = lockTimer;
|
|
|
|
|
+ Integer status;
|
|
|
|
|
+ byte[] bytes = ReUtil.hexStringToByteArray(instruct);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ Thread.sleep(3000);
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ while (timer > 1){
|
|
|
|
|
+
|
|
|
|
|
+ commonSend.send(socketService.getSteerSubscriptPrefix() + "/" + cabinetV2Lock.getRelayCode(),
|
|
|
|
|
+ bytes);
|
|
|
|
|
+ timer-=2;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ Thread.sleep(1900);
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ status = redisService.getCacheObject(cabinetV2Lock.getRelayCode() + ":" + cabinetV2Lock.getLockId());
|
|
|
|
|
+ logger.info("柜锁MQTT开锁状态查询:" + instruct + ",开锁结果:" + status);
|
|
|
|
|
+ if(status != null && status == 1){
|
|
|
|
|
+ return ResultData.success("开锁成功");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResultData.fail("开锁失败");*/
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -89,23 +131,25 @@ public class DeviceRemoteController {
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("/V2/closeLock")
|
|
@PostMapping("/V2/closeLock")
|
|
|
public ResultData cabinetV2CloseLock(@RequestBody CabinetV2Lock cabinetV2Lock){
|
|
public ResultData cabinetV2CloseLock(@RequestBody CabinetV2Lock cabinetV2Lock){
|
|
|
|
|
+
|
|
|
|
|
+ // socket 方式发送
|
|
|
String instruct = CRCCHECK.getCloseLockOrder(Integer.parseInt(cabinetV2Lock.getLockId()));
|
|
String instruct = CRCCHECK.getCloseLockOrder(Integer.parseInt(cabinetV2Lock.getLockId()));
|
|
|
String relayCode = cabinetV2Lock.getRelayCode();
|
|
String relayCode = cabinetV2Lock.getRelayCode();
|
|
|
OutputStream ops = TCPServer.cacheMap.get(relayCode);
|
|
OutputStream ops = TCPServer.cacheMap.get(relayCode);
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- /*ops.write(ReUtil.hexStringToByteArray(instruct));
|
|
|
|
|
|
|
+ ops.write(ReUtil.hexStringToByteArray(instruct));
|
|
|
ops.flush();
|
|
ops.flush();
|
|
|
logger.info("柜锁关锁指令:" + instruct);
|
|
logger.info("柜锁关锁指令:" + instruct);
|
|
|
- Thread.sleep(1000);*/
|
|
|
|
|
|
|
+ Thread.sleep(1000);
|
|
|
|
|
|
|
|
instruct = CRCCHECK.getReadLockOrder(Integer.parseInt(cabinetV2Lock.getLockId()));
|
|
instruct = CRCCHECK.getReadLockOrder(Integer.parseInt(cabinetV2Lock.getLockId()));
|
|
|
ops.write(ReUtil.hexStringToByteArray(instruct));
|
|
ops.write(ReUtil.hexStringToByteArray(instruct));
|
|
|
ops.flush();
|
|
ops.flush();
|
|
|
|
|
|
|
|
- /*Thread.sleep(600);
|
|
|
|
|
|
|
+ Thread.sleep(600);
|
|
|
ops.write(ReUtil.hexStringToByteArray(instruct));
|
|
ops.write(ReUtil.hexStringToByteArray(instruct));
|
|
|
- ops.flush();*/
|
|
|
|
|
|
|
+ ops.flush();
|
|
|
|
|
|
|
|
Thread.sleep(1600);
|
|
Thread.sleep(1600);
|
|
|
Integer status = redisService.getCacheObject(relayCode + ":" + cabinetV2Lock.getLockId());
|
|
Integer status = redisService.getCacheObject(relayCode + ":" + cabinetV2Lock.getLockId());
|
|
@@ -120,5 +164,30 @@ public class DeviceRemoteController {
|
|
|
return ResultData.fail("柜锁连接失败!");
|
|
return ResultData.fail("柜锁连接失败!");
|
|
|
}
|
|
}
|
|
|
return ResultData.fail("关锁失败:请手动按压柜锁,确认已关闭!");
|
|
return ResultData.fail("关锁失败:请手动按压柜锁,确认已关闭!");
|
|
|
|
|
+
|
|
|
|
|
+ // mqtt 方式
|
|
|
|
|
+ /*String instruct = CRCCHECK.getReadLockOrder(Integer.parseInt(cabinetV2Lock.getLockId()));
|
|
|
|
|
+ int timer = lockTimer;
|
|
|
|
|
+ Integer status;
|
|
|
|
|
+ byte[] bytes = ReUtil.hexStringToByteArray(instruct);
|
|
|
|
|
+ while (timer > 1){
|
|
|
|
|
+
|
|
|
|
|
+ commonSend.send(socketService.getSteerSubscriptPrefix() + "/" + cabinetV2Lock.getRelayCode(),
|
|
|
|
|
+ bytes);
|
|
|
|
|
+ timer--;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ Thread.sleep(900);
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ status = redisService.getCacheObject(cabinetV2Lock.getRelayCode() + ":" + cabinetV2Lock.getLockId());
|
|
|
|
|
+ logger.info("柜锁MQTT关锁状态查询:" + instruct + ",开锁结果:" + status);
|
|
|
|
|
+ if(status != null && status == 1){
|
|
|
|
|
+ return ResultData.success("关锁成功");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return ResultData.fail("关锁失败");*/
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|