开关闸控制
This commit is contained in:
@@ -56,12 +56,40 @@ public class ServerController {
|
|||||||
return service.openFloodgate(sn);
|
return service.openFloodgate(sn);
|
||||||
}
|
}
|
||||||
|
|
||||||
//锁杆&解锁
|
|
||||||
@PostMapping("/set_io_lock_status")
|
@PostMapping("/set_io_lock_status")
|
||||||
public JSONObject lock(@RequestBody JSONObject js) {
|
public JSONObject lock(@RequestBody JSONObject js) {
|
||||||
String sn = js.getString("sn");
|
String sn = js.getString("sn");
|
||||||
Integer status = js.getInteger("status");
|
Integer status = js.getInteger("status");
|
||||||
boolean publish = service.locked(sn, status);
|
Integer ioout = js.getInteger("ioout");
|
||||||
|
boolean publish = service.locked(sn, status,ioout);
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
if (publish) {
|
||||||
|
jsonObject.put("code", 200);
|
||||||
|
} else {
|
||||||
|
jsonObject.put("code", 500);
|
||||||
|
}
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
//常开
|
||||||
|
@PostMapping("/set_io_lock_open")
|
||||||
|
public JSONObject lockOpen(@RequestBody JSONObject js) {
|
||||||
|
String sn = js.getString("sn");
|
||||||
|
boolean publish = service.lockOpen(sn);
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
if (publish) {
|
||||||
|
jsonObject.put("code", 200);
|
||||||
|
} else {
|
||||||
|
jsonObject.put("code", 500);
|
||||||
|
}
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
//常关
|
||||||
|
@PostMapping("/set_io_lock_close")
|
||||||
|
public JSONObject lockClose(@RequestBody JSONObject js) {
|
||||||
|
String sn = js.getString("sn");
|
||||||
|
boolean publish = service.lockClose(sn);
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
if (publish) {
|
if (publish) {
|
||||||
jsonObject.put("code", 200);
|
jsonObject.put("code", 200);
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ public class CarMessageListener {
|
|||||||
carPassRecordService.save(record);
|
carPassRecordService.save(record);
|
||||||
|
|
||||||
//保存/删除在场数据
|
//保存/删除在场数据
|
||||||
boolean isExist = carPassGatherService.exists(new QueryWrapper<CarPassGather>().eq("license", license));
|
boolean isExist = carPassGatherService.exists(new QueryWrapper<CarPassGather>().eq("license", license).eq("park_id", carParkItem.getParkId()));
|
||||||
//入场新增数据
|
//入场新增数据
|
||||||
if (StrUtil.equals(carParkItem.getWay(), "0") && !isExist) {
|
if (StrUtil.equals(carParkItem.getWay(), "0") && !isExist) {
|
||||||
CarPassGather carPassGather = new CarPassGather();
|
CarPassGather carPassGather = new CarPassGather();
|
||||||
@@ -202,7 +202,7 @@ public class CarMessageListener {
|
|||||||
if (carParkItem.getAutoLock() == 1 && (count + 1) >= carParkItem.getCarsNum()) {
|
if (carParkItem.getAutoLock() == 1 && (count + 1) >= carParkItem.getCarsNum()) {
|
||||||
List<String> snList = carParkItemService.selectSnByParkId(carParkItem.getParkId());
|
List<String> snList = carParkItemService.selectSnByParkId(carParkItem.getParkId());
|
||||||
for (String s : snList) {
|
for (String s : snList) {
|
||||||
service.locked(s, 2);
|
service.locked(s, 2, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (StrUtil.equals(carParkItem.getWay(), "1") && isExist) {//出场删除数据
|
} else if (StrUtil.equals(carParkItem.getWay(), "1") && isExist) {//出场删除数据
|
||||||
@@ -211,7 +211,7 @@ public class CarMessageListener {
|
|||||||
if (carParkItem.getAutoLock() == 1 && count == carParkItem.getCarsNum()) {
|
if (carParkItem.getAutoLock() == 1 && count == carParkItem.getCarsNum()) {
|
||||||
List<String> snList = carParkItemService.selectSnByParkId(carParkItem.getParkId());
|
List<String> snList = carParkItemService.selectSnByParkId(carParkItem.getParkId());
|
||||||
for (String s : snList) {
|
for (String s : snList) {
|
||||||
service.locked(s, 0);
|
service.locked(s, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,10 +305,22 @@ public class CarMessageListener {
|
|||||||
log.info("IO锁定事件监听消息 -> Topic: {}, message: {}", topic, new String(message));
|
log.info("IO锁定事件监听消息 -> Topic: {}, message: {}", topic, new String(message));
|
||||||
String data = new String(message, StandardCharsets.UTF_8);
|
String data = new String(message, StandardCharsets.UTF_8);
|
||||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布获取IO锁定状态监听
|
||||||
|
*
|
||||||
|
* @param topic
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
@MqttServerFunction("device/${sn}/message/down/get_io_lock_status/reply")
|
||||||
|
public void get_io_lock_status(String topic, byte[] message) {
|
||||||
|
log.info("发布获取IO锁定状态监听消息 -> Topic: {}, message: {}", topic, new String(message));
|
||||||
|
String data = new String(message, StandardCharsets.UTF_8);
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订阅离线数据数量
|
* 订阅离线数据数量
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class ServerService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean locked(String sn, Integer status) {
|
public boolean locked(String sn, Integer status, Integer ioout) {
|
||||||
String operUrl = "device/%s/message/down/set_io_lock_status";
|
String operUrl = "device/%s/message/down/set_io_lock_status";
|
||||||
String topic = String.format(operUrl, sn);
|
String topic = String.format(operUrl, sn);
|
||||||
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
||||||
@@ -88,7 +88,7 @@ public class ServerService {
|
|||||||
deviceIOLockRequestPO.setId(uuid);
|
deviceIOLockRequestPO.setId(uuid);
|
||||||
deviceIOLockRequestPO.setSn(sn);
|
deviceIOLockRequestPO.setSn(sn);
|
||||||
deviceIOLockRequestPO.setName("set_io_lock_status");
|
deviceIOLockRequestPO.setName("set_io_lock_status");
|
||||||
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(status));
|
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(status, ioout));
|
||||||
boolean result = server.publish(sn,topic, JSON.toJSONString(deviceIOLockRequestPO).getBytes(StandardCharsets.UTF_8));
|
boolean result = server.publish(sn,topic, JSON.toJSONString(deviceIOLockRequestPO).getBytes(StandardCharsets.UTF_8));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -104,15 +104,65 @@ public class ServerService {
|
|||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject buildPayloadLocked(Integer status) {
|
private JSONObject buildPayloadLocked(Integer status, Integer ioout) {
|
||||||
JSONObject payload = new JSONObject();
|
JSONObject payload = new JSONObject();
|
||||||
payload.put("type", "set_io_lock_status");
|
payload.put("type", "set_io_lock_status");
|
||||||
JSONObject body = new JSONObject();
|
JSONObject body = new JSONObject();
|
||||||
//io口,摄像头接线口
|
//io口,摄像头接线口
|
||||||
body.put("ioout", 0);
|
body.put("ioout", ioout);
|
||||||
//0解锁 1高电平锁定(保持常抬) 2低电平锁定(保持常关)
|
//0解锁 1高电平锁定(保持常抬) 2低电平锁定(保持常关)
|
||||||
body.put("status", status);
|
body.put("status", status);
|
||||||
payload.put("body", body);
|
payload.put("body", body);
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean lockOpen(String sn) {
|
||||||
|
String operUrl = "device/%s/message/down/set_io_lock_status";
|
||||||
|
String topic = String.format(operUrl, sn);
|
||||||
|
|
||||||
|
//通道1解锁
|
||||||
|
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
||||||
|
String uuid = "lockOpen_" + UuidUtil.getUuid();
|
||||||
|
deviceIOLockRequestPO.setId(uuid);
|
||||||
|
deviceIOLockRequestPO.setSn(sn);
|
||||||
|
deviceIOLockRequestPO.setName("set_io_lock_status");
|
||||||
|
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(0, 1));
|
||||||
|
boolean result = server.publish(sn,topic, JSON.toJSONString(deviceIOLockRequestPO).getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
//通道0 锁定
|
||||||
|
|
||||||
|
DeviceIOLockRequestPO po = new DeviceIOLockRequestPO();
|
||||||
|
po.setId("lockOpen_" + UuidUtil.getUuid());
|
||||||
|
po.setSn(sn);
|
||||||
|
po.setName("set_io_lock_status");
|
||||||
|
po.setPayload(this.buildPayloadLocked(1, 0));
|
||||||
|
boolean result2 = server.publish(sn,topic, JSON.toJSONString(po).getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
return (result && result2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean lockClose(String sn) {
|
||||||
|
String operUrl = "device/%s/message/down/set_io_lock_status";
|
||||||
|
String topic = String.format(operUrl, sn);
|
||||||
|
|
||||||
|
//通道0解锁
|
||||||
|
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
||||||
|
String uuid = "lockOpen_" + UuidUtil.getUuid();
|
||||||
|
deviceIOLockRequestPO.setId(uuid);
|
||||||
|
deviceIOLockRequestPO.setSn(sn);
|
||||||
|
deviceIOLockRequestPO.setName("set_io_lock_status");
|
||||||
|
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(0, 0));
|
||||||
|
boolean result = server.publish(sn,topic, JSON.toJSONString(deviceIOLockRequestPO).getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
//通道1 锁定
|
||||||
|
|
||||||
|
DeviceIOLockRequestPO po = new DeviceIOLockRequestPO();
|
||||||
|
po.setId("lockOpen_" + UuidUtil.getUuid());
|
||||||
|
po.setSn(sn);
|
||||||
|
po.setName("set_io_lock_status");
|
||||||
|
po.setPayload(this.buildPayloadLocked(1, 1));
|
||||||
|
boolean result2 = server.publish(sn,topic, JSON.toJSONString(po).getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
return (result && result2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user