|
...
|
...
|
@@ -3,6 +3,8 @@ package com.zhonglai.luhui.device.protocol.plc004.analysis; |
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import com.ruoyi.common.utils.GsonConstructor;
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
import com.zhonglai.luhui.device.analysis.comm.clien.ClienConnection;
|
|
|
|
import com.zhonglai.luhui.device.analysis.comm.clien.impl.ClienConnectionImpl;
|
|
|
|
import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto;
|
|
|
|
import com.zhonglai.luhui.device.analysis.comm.factory.Topic;
|
|
|
|
import com.zhonglai.luhui.device.analysis.dto.Message;
|
|
...
|
...
|
@@ -13,6 +15,7 @@ import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory |
|
|
|
import com.zhonglai.luhui.device.protocol.factory.analysis.topic.*;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.config.ProductPayloadModelNumberCach;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.control.DeviceCommandListenService;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisResult;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto;
|
|
|
|
|
|
...
|
...
|
@@ -34,15 +37,29 @@ public class PLC004ProtocolParserFactoryImpl implements ProtocolParserFactory<by |
|
|
|
case "ONLINE":
|
|
|
|
return new Online().analysisPayload(payload);
|
|
|
|
case "ADD_POST":
|
|
|
|
return new AddPost().analysisPayload(toformatPayLoad(topic.getClientid(),payload));
|
|
|
|
return new AddPost().analysisPayload(toformatPayLoad(topic.getClientid(),GsonConstructor.get().fromJson(new String(payload),JsonObject.class)));
|
|
|
|
case "PUT_REQ":
|
|
|
|
JsonObject data = null;
|
|
|
|
if(DeviceCommandListenService.hasClienConnection(topic.getClientid()))
|
|
|
|
{
|
|
|
|
ClienConnection clienConnection = DeviceCommandListenService.getClienConnection(topic.getClientid());
|
|
|
|
if(null != clienConnection && clienConnection instanceof ClienConnectionImpl)
|
|
|
|
{
|
|
|
|
ClienConnectionImpl clienConnectionImpl = (ClienConnectionImpl) clienConnection;
|
|
|
|
if(null != clienConnectionImpl.getCommd())
|
|
|
|
{
|
|
|
|
data = GsonConstructor.get().fromJson(toformatPayLoad(topic.getClientid(),GsonConstructor.get().fromJson(new String(clienConnectionImpl.getCommd()),JsonObject.class)),JsonObject.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload),JsonObject.class);
|
|
|
|
return new AnalysisResult(false, false, null, new ApiClientRePlyDto() {
|
|
|
|
return new AnalysisResult(false, true, data, new ApiClientRePlyDto() {
|
|
|
|
@Override
|
|
|
|
public void setReplyMessage(Message message) {
|
|
|
|
if(jsonObject.has("result") && "1".equals(jsonObject.get("result").getAsString()))
|
|
|
|
{
|
|
|
|
message.setCode(MessageCode.DEFAULT_SUCCESS_CODE);
|
|
|
|
message.setMessage("操作成功");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
...
|
...
|
@@ -51,14 +68,16 @@ public class PLC004ProtocolParserFactoryImpl implements ProtocolParserFactory<by |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String toformatPayLoad(String clientid,byte[] payload)
|
|
|
|
private String toformatPayLoad(String clientid, JsonObject jsonObject)
|
|
|
|
{
|
|
|
|
JsonObject jsonObject = GsonConstructor.get().fromJson(new String(payload),JsonObject.class);
|
|
|
|
ParserDeviceHostDto parserDeviceHostDto = DeviceCach.getDeviceHost(clientid);
|
|
|
|
if(null != parserDeviceHostDto && null != parserDeviceHostDto.getIotProduct())
|
|
|
|
{
|
|
|
|
Integer iotProductid = parserDeviceHostDto.getIotProduct().getId();
|
|
|
|
|
|
|
|
if(!ProductPayloadModelNumberCach.hasProduct(iotProductid))
|
|
|
|
{
|
|
|
|
return jsonObject.toString();
|
|
|
|
}
|
|
|
|
JsonObject rj = new JsonObject();
|
|
|
|
for (String key : jsonObject.keySet())
|
|
|
|
{
|
...
|
...
|
|