|
|
|
package com.zhonglai.luhui.device.protocol.defaul.control;
|
|
|
|
|
|
|
|
import com.google.gson.JsonElement;
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
|
import com.ruoyi.common.utils.GsonConstructor;
|
|
|
|
import com.zhonglai.luhui.device.analysis.comm.factory.Topic;
|
|
|
|
import com.zhonglai.luhui.device.domain.IotProduct;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.control.DeviceCommandServiceFactory;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.dto.NoticeMessageDto;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.lang.reflect.Type;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 指令控制监听实现
|
|
|
|
*/
|
|
|
|
public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFactory {
|
|
|
|
private static final String topicModel = "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}/{{messageid}}";
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenServiceImpl.class);
|
|
|
|
@Override
|
|
|
|
public NoticeMessageDto read(String deviceId, JsonObject jsonObject) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public NoticeMessageDto write(String deviceId, JsonObject jsonObject) {
|
|
|
|
ParserDeviceHostDto parserDeviceHostDto = DeviceCach.getDeviceHost(deviceId);
|
|
|
|
|
|
|
|
Topic topic = getWriteTopic(deviceId,parserDeviceHostDto.getIotProduct());
|
|
|
|
NoticeMessageDto noticeMessageDto = new NoticeMessageDto();
|
|
|
|
noticeMessageDto.setTopic(topic);
|
|
|
|
noticeMessageDto.setTopicconfig(topicModel);
|
|
|
|
|
|
|
|
noticeMessageDto.setCommd(jsonObject.toString().getBytes());
|
|
|
|
|
|
|
|
return noticeMessageDto;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public NoticeMessageDto notice(String deviceId, JsonObject jsonObject) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Topic getWriteTopic(String deviceId, IotProduct iotProduct)
|
|
|
|
{
|
|
|
|
Topic topic = new Topic();
|
|
|
|
topic.setTopicType("PUT");
|
|
|
|
topic.setClientid(deviceId);
|
|
|
|
topic.setRoleid(iotProduct.getRole_id()+"");
|
|
|
|
topic.setUsername(iotProduct.getMqtt_username());
|
|
|
|
topic.setPayloadtype("Json");
|
|
|
|
topic.setMessageid(DateUtils.getNowTimeMilly()+"");
|
|
|
|
return topic;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|