Browse Source

fix:Event直接处理tag

tags/1.0
白凤吉 4 months ago
parent
commit
36f3e16c6f
  1. 40
      src/main/java/com/qyft/ms/system/core/listener/DeviceTcpMessageEventListener.java
  2. 18
      src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java

40
src/main/java/com/qyft/ms/system/core/listener/DeviceTcpMessageEventListener.java

@ -1,44 +1,50 @@
package com.qyft.ms.system.core.listener; package com.qyft.ms.system.core.listener;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.qyft.ms.app.device.spray.SprayTaskExecutor; import com.qyft.ms.app.device.spray.SprayTaskExecutor;
import com.qyft.ms.app.device.status.DeviceStatus; import com.qyft.ms.app.device.status.DeviceStatus;
import com.qyft.ms.app.device.status.SprayTask; import com.qyft.ms.app.device.status.SprayTask;
import com.qyft.ms.system.core.event.DeviceTcpMessageEvent; import com.qyft.ms.system.core.event.DeviceTcpMessageEvent;
import com.qyft.ms.system.service.device.DeviceCommandService; import com.qyft.ms.system.service.device.DeviceCommandService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Slf4j @Slf4j
@Component @Component
@RequiredArgsConstructor
public class DeviceTcpMessageEventListener { public class DeviceTcpMessageEventListener {
private final DeviceCommandService deviceCommandService; private final DeviceCommandService deviceCommandService;
private final DeviceStatus deviceStatus; private final DeviceStatus deviceStatus;
private final SprayTaskExecutor sprayTaskExecutor; private final SprayTaskExecutor sprayTaskExecutor;
public DeviceTcpMessageEventListener(DeviceCommandService deviceCommandService, DeviceStatus deviceStatus, SprayTaskExecutor sprayTaskExecutor) {
this.deviceCommandService = deviceCommandService;
this.deviceStatus = deviceStatus;
this.sprayTaskExecutor = sprayTaskExecutor;
}
@EventListener @EventListener
public void handleDeviceTcpMessageEvent(DeviceTcpMessageEvent event) { public void handleDeviceTcpMessageEvent(DeviceTcpMessageEvent event) {
JSONObject deviceResult = event.getDeviceResult(); JSONObject deviceResult = event.getDeviceResult();
String tag = deviceResult.getStr("tag"); String tag = deviceResult.getStr("tag");
String eventType = deviceResult.getStr("event_type");
if ("system_e_stop_pressed".equals(eventType)) {//系统急停按钮被按下
sprayTaskExecutor.stopTask();//终止喷涂任务线程
SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);
deviceStatus.setPaused(false);
deviceStatus.setSuspendable(false);
deviceStatus.setStopPressed(true);
} else if ("system_e_stop_released".equals(eventType)) {//系统急停按钮被释放
deviceStatus.setStopPressed(false);
if ("ACK".equals(tag)) {
log.info("ACK {}", JSONUtil.toJsonStr(deviceResult));
deviceCommandService.completeCommandAck(deviceResult);
} else if ("RESPONSE".equals(tag)) {
log.info("RESPONSE {}", JSONUtil.toJsonStr(deviceResult));
deviceCommandService.completeCommandResponse(deviceResult);
} else if ("EVENT".equals(tag)) {
String eventType = deviceResult.getJSONObject("data").getStr("event_type");
if ("system_e_stop_pressed".equals(eventType)) {//系统急停按钮被按下
sprayTaskExecutor.stopTask();//终止喷涂任务线程
SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);
deviceStatus.setPaused(false);
deviceStatus.setSuspendable(false);
deviceStatus.setStopPressed(true);
} else if ("system_e_stop_released".equals(eventType)) {//系统急停按钮被释放
deviceStatus.setStopPressed(false);
}
} else if ("STATUS".equals(tag)) {
} }
deviceCommandService.handleDeviceResult(deviceResult);
} }
} }

18
src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java

@ -2,8 +2,6 @@ package com.qyft.ms.system.service.device;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.qyft.ms.app.device.spray.SprayTaskExecutor;
import com.qyft.ms.app.device.status.DeviceStatus;
import com.qyft.ms.system.common.constant.CommandStatus; import com.qyft.ms.system.common.constant.CommandStatus;
import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.CommandFuture;
import com.qyft.ms.system.common.device.command.CyclicNumberGenerator; import com.qyft.ms.system.common.device.command.CyclicNumberGenerator;
@ -100,22 +98,6 @@ public class DeviceCommandService {
return commandFuture; return commandFuture;
} }
public void handleDeviceResult(JSONObject deviceResult) {
String tag = deviceResult.getStr("tag");
if ("ACK".equals(tag)) {
log.info("ACK {}", JSONUtil.toJsonStr(deviceResult));
completeCommandAck(deviceResult);
} else if ("RESPONSE".equals(tag)) {
log.info("RESPONSE {}", JSONUtil.toJsonStr(deviceResult));
completeCommandResponse(deviceResult);
} else if ("EVENT".equals(tag)) {
} else if ("STATUS".equals(tag)) {
}
}
public void completeCommandAck(JSONObject deviceResult) { public void completeCommandAck(JSONObject deviceResult) {
// Integer cmdId = deviceResult.getInt("cmdId"); // Integer cmdId = deviceResult.getInt("cmdId");
// if (cmdId != null) { // if (cmdId != null) {

Loading…
Cancel
Save