|
1
|
package com.zhonglai.luhui.mqtt.service.topic;
|
1
|
package com.zhonglai.luhui.mqtt.service.topic;
|
|
2
|
|
2
|
|
|
|
|
3
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
4
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
5
|
+import com.alibaba.fastjson.JSONValidator;
|
|
|
|
6
|
+import com.ruoyi.system.domain.IotDevice;
|
|
|
|
7
|
+import com.ruoyi.system.domain.IotTerminal;
|
|
|
|
8
|
+import com.zhonglai.luhui.mqtt.comm.dao.BaseDao;
|
|
3
|
import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
|
9
|
import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
|
|
4
|
import com.zhonglai.luhui.mqtt.comm.dto.TerminalClientRePlyDto;
|
10
|
import com.zhonglai.luhui.mqtt.comm.dto.TerminalClientRePlyDto;
|
|
5
|
import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto;
|
11
|
import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto;
|
|
6
|
import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
|
12
|
import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
|
|
7
|
import com.zhonglai.luhui.mqtt.comm.factory.Topic;
|
13
|
import com.zhonglai.luhui.mqtt.comm.factory.Topic;
|
|
8
|
import com.zhonglai.luhui.mqtt.comm.service.ClienNoticeService;
|
14
|
import com.zhonglai.luhui.mqtt.comm.service.ClienNoticeService;
|
|
|
|
15
|
+import com.zhonglai.luhui.mqtt.comm.util.StringUtils;
|
|
|
|
16
|
+import com.zhonglai.luhui.mqtt.dto.topic.AddPostDto;
|
|
9
|
import com.zhonglai.luhui.mqtt.dto.topic.GetDto;
|
17
|
import com.zhonglai.luhui.mqtt.dto.topic.GetDto;
|
|
|
|
18
|
+import org.springframework.beans.BeanUtils;
|
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
19
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
11
|
import org.springframework.stereotype.Service;
|
20
|
import org.springframework.stereotype.Service;
|
|
12
|
|
21
|
|
|
|
|
22
|
+import java.util.ArrayList;
|
|
|
|
23
|
+
|
|
13
|
/**
|
24
|
/**
|
|
14
|
* 获取数据
|
25
|
* 获取数据
|
|
15
|
*/
|
26
|
*/
|
|
@@ -18,18 +29,94 @@ public class GetTopic implements BusinessAgreement<GetDto> { |
|
@@ -18,18 +29,94 @@ public class GetTopic implements BusinessAgreement<GetDto> { |
|
18
|
@Autowired
|
29
|
@Autowired
|
|
19
|
private ClienNoticeService clienNoticeService; //客户端通知服务
|
30
|
private ClienNoticeService clienNoticeService; //客户端通知服务
|
|
20
|
|
31
|
|
|
|
|
32
|
+ protected BaseDao baseDao = new BaseDao();
|
|
|
|
33
|
+
|
|
21
|
@Override
|
34
|
@Override
|
|
22
|
public ServerDto analysis(Topic topic, GetDto data) throws Exception {
|
35
|
public ServerDto analysis(Topic topic, GetDto data) throws Exception {
|
|
|
|
36
|
+ JSONObject allData = new JSONObject();
|
|
|
|
37
|
+ JSONObject rData = new JSONObject();
|
|
|
|
38
|
+
|
|
|
|
39
|
+ JSONObject jsonObject = data.getData();
|
|
|
|
40
|
+ if(null !=jsonObject && jsonObject.keySet().size()!=0)
|
|
|
|
41
|
+ {
|
|
|
|
42
|
+ for(String key:jsonObject.keySet())
|
|
|
|
43
|
+ {
|
|
|
|
44
|
+ if ("0".equals(key))
|
|
|
|
45
|
+ {
|
|
|
|
46
|
+ IotDevice iotDevice = (IotDevice) baseDao.get(IotDevice.class,topic.getClientid());
|
|
|
|
47
|
+ if(null == iotDevice)
|
|
|
|
48
|
+ {
|
|
|
|
49
|
+ return null;
|
|
|
|
50
|
+ }
|
|
|
|
51
|
+ String value = iotDevice.getThings_model_value();
|
|
|
|
52
|
+ String config = iotDevice.getThings_model_config();
|
|
|
|
53
|
+ if(StringUtils.isNotEmpty(value))
|
|
|
|
54
|
+ {
|
|
|
|
55
|
+ JSONObject jv = JSONObject.parseObject(value,JSONObject.class);
|
|
|
|
56
|
+ allData.putAll(jv);
|
|
|
|
57
|
+ }
|
|
|
|
58
|
+ if(StringUtils.isNotEmpty(config))
|
|
|
|
59
|
+ {
|
|
|
|
60
|
+ JSONObject jc = JSONObject.parseObject(config,JSONObject.class);
|
|
|
|
61
|
+ allData.putAll(jc);
|
|
|
|
62
|
+ }
|
|
|
|
63
|
+ }else {
|
|
|
|
64
|
+ IotTerminal iotTerminal = (IotTerminal) baseDao.get(IotTerminal.class,topic.getClientid()+"_"+key);
|
|
|
|
65
|
+ if(null == iotTerminal)
|
|
|
|
66
|
+ {
|
|
|
|
67
|
+ continue;
|
|
|
|
68
|
+ }
|
|
|
|
69
|
+ String value = iotTerminal.getThings_model_value();
|
|
|
|
70
|
+ String config = iotTerminal.getThings_model_config();
|
|
|
|
71
|
+ if(StringUtils.isNotEmpty(value))
|
|
|
|
72
|
+ {
|
|
|
|
73
|
+ JSONObject jv = JSONObject.parseObject(value,JSONObject.class);
|
|
|
|
74
|
+ allData.putAll(jv);
|
|
|
|
75
|
+ }
|
|
|
|
76
|
+ if(StringUtils.isNotEmpty(config))
|
|
|
|
77
|
+ {
|
|
|
|
78
|
+ JSONObject jc = JSONObject.parseObject(config,JSONObject.class);
|
|
|
|
79
|
+ allData.putAll(jc);
|
|
|
|
80
|
+ }
|
|
|
|
81
|
+ }
|
|
|
|
82
|
+ }
|
|
|
|
83
|
+
|
|
|
|
84
|
+ for(String key:jsonObject.keySet())
|
|
|
|
85
|
+ {
|
|
|
|
86
|
+ JSONObject keyJson = rData.getJSONObject(key);
|
|
|
|
87
|
+ if(null == keyJson)
|
|
|
|
88
|
+ {
|
|
|
|
89
|
+ keyJson = new JSONObject();
|
|
|
|
90
|
+ rData.put(key,keyJson);
|
|
|
|
91
|
+ }
|
|
|
|
92
|
+ String parameters = jsonObject.getString(key);
|
|
|
|
93
|
+ if(StringUtils.isNotEmpty(parameters))
|
|
|
|
94
|
+ {
|
|
|
|
95
|
+ String[] ps = parameters.split(",");
|
|
|
|
96
|
+ for(String p:ps)
|
|
|
|
97
|
+ {
|
|
|
|
98
|
+ if(allData.containsKey(p) )
|
|
|
|
99
|
+ {
|
|
|
|
100
|
+ keyJson.put(p,allData.getJSONObject(p).get("value"));
|
|
|
|
101
|
+ }
|
|
|
|
102
|
+ }
|
|
|
|
103
|
+ }
|
|
|
|
104
|
+
|
|
|
|
105
|
+ }
|
|
|
|
106
|
+ }
|
|
23
|
//回复客户端消息
|
107
|
//回复客户端消息
|
|
24
|
clienNoticeService.replyTerminalMessage(topic, new TerminalClientRePlyDto() {
|
108
|
clienNoticeService.replyTerminalMessage(topic, new TerminalClientRePlyDto() {
|
|
25
|
@Override
|
109
|
@Override
|
|
26
|
public byte[] getCommd() {
|
110
|
public byte[] getCommd() {
|
|
27
|
- return new byte[0];
|
111
|
+ return rData.toJSONString().getBytes();
|
|
28
|
}
|
112
|
}
|
|
29
|
|
113
|
|
|
30
|
@Override
|
114
|
@Override
|
|
31
|
public String getReplyCommdTopic(Topic topic) {
|
115
|
public String getReplyCommdTopic(Topic topic) {
|
|
32
|
- return null;
|
116
|
+ Topic topic1 = new Topic();
|
|
|
|
117
|
+ BeanUtils.copyProperties(topic,topic1);
|
|
|
|
118
|
+ topic1.setTopicType("GET_REQ");
|
|
|
|
119
|
+ return topic1.generateSendMessageTopic();
|
|
33
|
}
|
120
|
}
|
|
34
|
});
|
121
|
});
|
|
35
|
return null;
|
122
|
return null;
|
|
@@ -38,6 +125,11 @@ public class GetTopic implements BusinessAgreement<GetDto> { |
|
@@ -38,6 +125,11 @@ public class GetTopic implements BusinessAgreement<GetDto> { |
|
38
|
@Override
|
125
|
@Override
|
|
39
|
public GetDto toData(BusinessDto data) {
|
126
|
public GetDto toData(BusinessDto data) {
|
|
40
|
GetDto serverDto = new GetDto();
|
127
|
GetDto serverDto = new GetDto();
|
|
|
|
128
|
+ serverDto.setData((JSONObject) data.getContentData());
|
|
|
|
129
|
+ serverDto.getData().remove("id");
|
|
|
|
130
|
+ serverDto.setIotTerminalList(new ArrayList<>());
|
|
|
|
131
|
+ serverDto.setDeviceSensorDataList(new ArrayList<>());
|
|
|
|
132
|
+ serverDto.setLogDeviceOperationList(new ArrayList<>());
|
|
41
|
return serverDto;
|
133
|
return serverDto;
|
|
42
|
}
|
134
|
}
|
|
43
|
|
135
|
|