|
@@ -7,12 +7,13 @@ import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.device.domain.model.TsbUserDeviceBind;
|
|
import com.ruoyi.device.domain.model.TsbUserDeviceBind;
|
|
|
import com.ruoyi.device.mapper.TsbUserDeviceMapper;
|
|
import com.ruoyi.device.mapper.TsbUserDeviceMapper;
|
|
|
import com.ruoyi.device.mqtt.domain.BaseJsonBody;
|
|
import com.ruoyi.device.mqtt.domain.BaseJsonBody;
|
|
|
-import com.ruoyi.device.mqtt.domain.encoder.TaxDataDown;
|
|
|
|
|
import com.ruoyi.device.mqtt.enums.CmdTypeEnum;
|
|
import com.ruoyi.device.mqtt.enums.CmdTypeEnum;
|
|
|
import com.ruoyi.device.mqtt.enums.MsgTypeEnum;
|
|
import com.ruoyi.device.mqtt.enums.MsgTypeEnum;
|
|
|
import com.ruoyi.device.mqtt.handler.DeviceOnlineManager;
|
|
import com.ruoyi.device.mqtt.handler.DeviceOnlineManager;
|
|
|
import com.ruoyi.device.mqtt.handler.HandlerManager;
|
|
import com.ruoyi.device.mqtt.handler.HandlerManager;
|
|
|
|
|
+import com.ruoyi.device.mqtt.handler.JsonCmdHandlerManager;
|
|
|
import com.ruoyi.device.mqtt.handler.encoder.IEncoder;
|
|
import com.ruoyi.device.mqtt.handler.encoder.IEncoder;
|
|
|
|
|
+import com.ruoyi.device.mqtt.handler.encoder.json.IJsonCmdDownHandler;
|
|
|
import com.ruoyi.device.mqtt.util.MsgHandlerUtil;
|
|
import com.ruoyi.device.mqtt.util.MsgHandlerUtil;
|
|
|
import com.ruoyi.device.websocket.model.TsbWebSocketMessage;
|
|
import com.ruoyi.device.websocket.model.TsbWebSocketMessage;
|
|
|
import com.ruoyi.framework.web.service.TokenService;
|
|
import com.ruoyi.framework.web.service.TokenService;
|
|
@@ -45,6 +46,9 @@ public class TsbWebSocketService
|
|
|
private HandlerManager handlerManager;
|
|
private HandlerManager handlerManager;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
|
|
+ private JsonCmdHandlerManager jsonCmdHandlerManager;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
private DeviceOnlineManager deviceOnlineManager;
|
|
private DeviceOnlineManager deviceOnlineManager;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -126,12 +130,20 @@ public class TsbWebSocketService
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 3、发送消息
|
|
|
|
|
- TaxDataDown down = tsbWebSocketMessage.getData() == null ?
|
|
|
|
|
- new TaxDataDown() : tsbWebSocketMessage.getData().toJavaObject(TaxDataDown.class);
|
|
|
|
|
- down.setDeviceType(bind.getDeviceType());
|
|
|
|
|
- down.setDeviceSn(bind.getDeviceSn());
|
|
|
|
|
- down.setCmdType(cmdType.getCmdDownType());
|
|
|
|
|
|
|
+ // 3、Web data → MQTT 下行体(保留 JSONObject 全部字段)
|
|
|
|
|
+ IJsonCmdDownHandler handler = jsonCmdHandlerManager.getDownHandlerByDownKey(cmdType.getCmdDownType());
|
|
|
|
|
+ if (handler == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ handler = jsonCmdHandlerManager.getDownHandlerByBaseKey(cmdType.getCmdType());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (handler == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ log.warn("未注册 JSON 命令处理器 cmd={}", cmdType);
|
|
|
|
|
+ TsbWebSocketUsers.sendMessageToUserByText(session,
|
|
|
|
|
+ TsbWebSocketMessage.fail(tsbWebSocketMessage.getCmdType(), "未实现的服务处理器"));
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ BaseJsonBody baseJsonBody = handler.handle(bind, tsbWebSocketMessage.getData(), cmdType);
|
|
|
log.info("Web端 -> 设备 MQTT 同步消息, userId={}, deviceSn={}", bind.getUserId(), bind.getDeviceSn());
|
|
log.info("Web端 -> 设备 MQTT 同步消息, userId={}, deviceSn={}", bind.getUserId(), bind.getDeviceSn());
|
|
|
String key = MsgHandlerUtil.getEncoderKey(MsgTypeEnum.JSON_BODY);
|
|
String key = MsgHandlerUtil.getEncoderKey(MsgTypeEnum.JSON_BODY);
|
|
|
IEncoder<BaseJsonBody> encoder = (IEncoder<BaseJsonBody>) handlerManager.getEncoder(key);
|
|
IEncoder<BaseJsonBody> encoder = (IEncoder<BaseJsonBody>) handlerManager.getEncoder(key);
|
|
@@ -142,7 +154,7 @@ public class TsbWebSocketService
|
|
|
}
|
|
}
|
|
|
log.info("MQTT 下行发送, cmdType={}, deviceType={}, deviceSn={}",
|
|
log.info("MQTT 下行发送, cmdType={}, deviceType={}, deviceSn={}",
|
|
|
cmdType.getCmdType(), bind.getDeviceType(), bind.getDeviceSn());
|
|
cmdType.getCmdType(), bind.getDeviceType(), bind.getDeviceSn());
|
|
|
- encoder.encode(down);
|
|
|
|
|
|
|
+ encoder.encode(baseJsonBody);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|