|
|
|
package com.zhonglai.luhui.mqtt.service.topic;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONValidator;
|
|
|
|
import com.ruoyi.system.domain.IotDevice;
|
|
|
|
import com.ruoyi.system.domain.IotTerminal;
|
|
|
|
import com.zhonglai.luhui.mqtt.comm.dao.BaseDao;
|
|
|
|
import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
|
|
|
|
import com.zhonglai.luhui.mqtt.comm.dto.TerminalClientRePlyDto;
|
|
|
|
import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto;
|
|
|
|
import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
|
|
|
|
import com.zhonglai.luhui.mqtt.comm.factory.Topic;
|
|
|
|
import com.zhonglai.luhui.mqtt.comm.service.ClienNoticeService;
|
|
|
|
import com.zhonglai.luhui.mqtt.comm.util.StringUtils;
|
|
|
|
import com.zhonglai.luhui.mqtt.dto.topic.AddPostDto;
|
|
|
|
import com.zhonglai.luhui.mqtt.dto.topic.GetDto;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取数据
|
|
|
|
*/
|
|
...
|
...
|
@@ -18,18 +29,94 @@ public class GetTopic implements BusinessAgreement<GetDto> { |
|
|
|
@Autowired
|
|
|
|
private ClienNoticeService clienNoticeService; //客户端通知服务
|
|
|
|
|
|
|
|
protected BaseDao baseDao = new BaseDao();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ServerDto analysis(Topic topic, GetDto data) throws Exception {
|
|
|
|
JSONObject allData = new JSONObject();
|
|
|
|
JSONObject rData = new JSONObject();
|
|
|
|
|
|
|
|
JSONObject jsonObject = data.getData();
|
|
|
|
if(null !=jsonObject && jsonObject.keySet().size()!=0)
|
|
|
|
{
|
|
|
|
for(String key:jsonObject.keySet())
|
|
|
|
{
|
|
|
|
if ("0".equals(key))
|
|
|
|
{
|
|
|
|
IotDevice iotDevice = (IotDevice) baseDao.get(IotDevice.class,topic.getClientid());
|
|
|
|
if(null == iotDevice)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
String value = iotDevice.getThings_model_value();
|
|
|
|
String config = iotDevice.getThings_model_config();
|
|
|
|
if(StringUtils.isNotEmpty(value))
|
|
|
|
{
|
|
|
|
JSONObject jv = JSONObject.parseObject(value,JSONObject.class);
|
|
|
|
allData.putAll(jv);
|
|
|
|
}
|
|
|
|
if(StringUtils.isNotEmpty(config))
|
|
|
|
{
|
|
|
|
JSONObject jc = JSONObject.parseObject(config,JSONObject.class);
|
|
|
|
allData.putAll(jc);
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
IotTerminal iotTerminal = (IotTerminal) baseDao.get(IotTerminal.class,topic.getClientid()+"_"+key);
|
|
|
|
if(null == iotTerminal)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
String value = iotTerminal.getThings_model_value();
|
|
|
|
String config = iotTerminal.getThings_model_config();
|
|
|
|
if(StringUtils.isNotEmpty(value))
|
|
|
|
{
|
|
|
|
JSONObject jv = JSONObject.parseObject(value,JSONObject.class);
|
|
|
|
allData.putAll(jv);
|
|
|
|
}
|
|
|
|
if(StringUtils.isNotEmpty(config))
|
|
|
|
{
|
|
|
|
JSONObject jc = JSONObject.parseObject(config,JSONObject.class);
|
|
|
|
allData.putAll(jc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(String key:jsonObject.keySet())
|
|
|
|
{
|
|
|
|
JSONObject keyJson = rData.getJSONObject(key);
|
|
|
|
if(null == keyJson)
|
|
|
|
{
|
|
|
|
keyJson = new JSONObject();
|
|
|
|
rData.put(key,keyJson);
|
|
|
|
}
|
|
|
|
String parameters = jsonObject.getString(key);
|
|
|
|
if(StringUtils.isNotEmpty(parameters))
|
|
|
|
{
|
|
|
|
String[] ps = parameters.split(",");
|
|
|
|
for(String p:ps)
|
|
|
|
{
|
|
|
|
if(allData.containsKey(p) )
|
|
|
|
{
|
|
|
|
keyJson.put(p,allData.getJSONObject(p).get("value"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//回复客户端消息
|
|
|
|
clienNoticeService.replyTerminalMessage(topic, new TerminalClientRePlyDto() {
|
|
|
|
@Override
|
|
|
|
public byte[] getCommd() {
|
|
|
|
return new byte[0];
|
|
|
|
return rData.toJSONString().getBytes();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getReplyCommdTopic(Topic topic) {
|
|
|
|
return null;
|
|
|
|
Topic topic1 = new Topic();
|
|
|
|
BeanUtils.copyProperties(topic,topic1);
|
|
|
|
topic1.setTopicType("GET_REQ");
|
|
|
|
return topic1.generateSendMessageTopic();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return null;
|
|
...
|
...
|
@@ -38,6 +125,11 @@ public class GetTopic implements BusinessAgreement<GetDto> { |
|
|
|
@Override
|
|
|
|
public GetDto toData(BusinessDto data) {
|
|
|
|
GetDto serverDto = new GetDto();
|
|
|
|
serverDto.setData((JSONObject) data.getContentData());
|
|
|
|
serverDto.getData().remove("id");
|
|
|
|
serverDto.setIotTerminalList(new ArrayList<>());
|
|
|
|
serverDto.setDeviceSensorDataList(new ArrayList<>());
|
|
|
|
serverDto.setLogDeviceOperationList(new ArrayList<>());
|
|
|
|
return serverDto;
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|