...
|
...
|
@@ -3,7 +3,6 @@ package org.thingsboard.server.dao.yunteng.impl; |
3
|
3
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
4
|
4
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
5
|
import com.fasterxml.jackson.databind.JsonNode;
|
6
|
|
-import com.fasterxml.jackson.databind.node.ObjectNode;
|
7
|
6
|
import lombok.RequiredArgsConstructor;
|
8
|
7
|
import org.apache.commons.lang3.StringUtils;
|
9
|
8
|
import org.springframework.beans.BeanUtils;
|
...
|
...
|
@@ -13,8 +12,6 @@ import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
13
|
12
|
import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
|
14
|
13
|
import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
|
15
|
14
|
import org.thingsboard.server.common.data.yunteng.dto.*;
|
16
|
|
-import org.thingsboard.server.common.data.yunteng.enums.DataTypeEnum;
|
17
|
|
-import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum;
|
18
|
15
|
import org.thingsboard.server.common.data.yunteng.enums.FunctionTypeEnum;
|
19
|
16
|
import org.thingsboard.server.common.data.yunteng.enums.StatusEnum;
|
20
|
17
|
import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil;
|
...
|
...
|
@@ -159,45 +156,41 @@ public class ThingsModelServiceImpl |
159
|
156
|
}
|
160
|
157
|
List<ThingsModelDTO> thingsModelDTOS =
|
161
|
158
|
selectByDeviceProfileId(typeEnum, tenantId, deviceProfileId);
|
162
|
|
- if(null ==thingsModelDTOS){
|
|
159
|
+ if (null == thingsModelDTOS) {
|
163
|
160
|
return jsonNode;
|
164
|
161
|
}
|
165
|
|
- DeviceTypeEnum deviceType = deviceProfileDTO.getDeviceType();
|
166
|
|
- if (typeEnum.equals(FunctionTypeEnum.properties)) {
|
167
|
|
- jsonNode = getAttributeTSL(thingsModelDTOS, deviceType);
|
168
|
|
- } else {
|
169
|
|
- if (typeEnum.equals(FunctionTypeEnum.services)) {
|
170
|
|
- List<ServiceModelDTO> serviceList = new ArrayList<>();
|
171
|
|
- if (!thingsModelDTOS.isEmpty()) {
|
172
|
|
- for (ThingsModelDTO thingsModelDTO : thingsModelDTOS) {
|
173
|
|
- ServiceModelDTO serviceDTO = new ServiceModelDTO();
|
174
|
|
- BeanUtils.copyProperties(thingsModelDTO, serviceDTO);
|
175
|
|
- JsonNode functionJson = thingsModelDTO.getFunctionJson();
|
176
|
|
- if (null != functionJson) {
|
|
162
|
+ List<Object> serviceList = new ArrayList<>();
|
|
163
|
+ if (!thingsModelDTOS.isEmpty()) {
|
|
164
|
+ for (ThingsModelDTO thingsModelDTO : thingsModelDTOS) {
|
|
165
|
+ JsonNode functionJson = thingsModelDTO.getFunctionJson();
|
|
166
|
+ if (null != functionJson) {
|
|
167
|
+ switch (typeEnum) {
|
|
168
|
+ case properties:
|
|
169
|
+ AttributeModelDTO attributeModelDTO = new AttributeModelDTO();
|
|
170
|
+ BeanUtils.copyProperties(thingsModelDTO, attributeModelDTO);
|
|
171
|
+ attributeModelDTO.setSpecs(functionJson.get("dataType"));
|
|
172
|
+ serviceList.add(attributeModelDTO);
|
|
173
|
+ break;
|
|
174
|
+ case services:
|
|
175
|
+ ServiceModelDTO serviceDTO = new ServiceModelDTO();
|
|
176
|
+ BeanUtils.copyProperties(thingsModelDTO, serviceDTO);
|
177
|
177
|
serviceDTO.setInputData(functionJson.get("inputData"));
|
178
|
178
|
serviceDTO.setOutputData(functionJson.get("outputData"));
|
179
|
|
- }
|
180
|
|
- serviceList.add(serviceDTO);
|
181
|
|
- }
|
182
|
|
- }
|
183
|
|
- jsonNode = JacksonUtil.convertValue(serviceList, JsonNode.class);
|
184
|
|
- } else {
|
185
|
|
- List<EventModelDTO> eventList = new ArrayList<>();
|
186
|
|
- if (!thingsModelDTOS.isEmpty()) {
|
187
|
|
- for (ThingsModelDTO thingsModelDTO : thingsModelDTOS) {
|
188
|
|
- EventModelDTO eventDTO = new EventModelDTO();
|
189
|
|
- BeanUtils.copyProperties(thingsModelDTO, eventDTO);
|
190
|
|
- JsonNode functionJson = thingsModelDTO.getFunctionJson();
|
191
|
|
- if (null != functionJson) {
|
|
179
|
+ serviceList.add(serviceDTO);
|
|
180
|
+ break;
|
|
181
|
+ case events:
|
|
182
|
+ EventModelDTO eventDTO = new EventModelDTO();
|
|
183
|
+ BeanUtils.copyProperties(thingsModelDTO, eventDTO);
|
192
|
184
|
eventDTO.setOutputData(functionJson.get("outputData"));
|
193
|
|
- }
|
|
185
|
+ serviceList.add(eventDTO);
|
|
186
|
+ break;
|
|
187
|
+ default:
|
|
188
|
+ break;
|
194
|
189
|
}
|
195
|
190
|
}
|
196
|
|
- jsonNode = JacksonUtil.convertValue(eventList, JsonNode.class);
|
197
|
191
|
}
|
198
|
192
|
}
|
199
|
|
-
|
200
|
|
- return jsonNode;
|
|
193
|
+ return JacksonUtil.convertValue(serviceList, JsonNode.class);
|
201
|
194
|
}
|
202
|
195
|
|
203
|
196
|
@Override
|
...
|
...
|
@@ -206,53 +199,6 @@ public class ThingsModelServiceImpl |
206
|
199
|
return baseMapper.changeTSLStatus(deviceProfileId, tenantId, status);
|
207
|
200
|
}
|
208
|
201
|
|
209
|
|
- private JsonNode getAttributeTSL(
|
210
|
|
- List<ThingsModelDTO> thingsModelDTOS, DeviceTypeEnum deviceType) {
|
211
|
|
- Map<String, List<ObjectNode>> attributeMap = new HashMap<>();
|
212
|
|
- JsonNode jsonNode;
|
213
|
|
- List<ObjectNode> list = new ArrayList<>();
|
214
|
|
- for (ThingsModelDTO model : thingsModelDTOS) {
|
215
|
|
- ObjectNode objectNode = JacksonUtil.newObjectNode();
|
216
|
|
- JsonNode dataType = model.getFunctionJson().get("dataType");
|
217
|
|
- if (null != dataType) {
|
218
|
|
- DataTypeEnum type =
|
219
|
|
- dataType.get("type") != null
|
220
|
|
- ? DataTypeEnum.valueOf(dataType.get("type").asText())
|
221
|
|
- : null;
|
222
|
|
- String identifier = model.getIdentifier();
|
223
|
|
- switch (Objects.requireNonNull(type)) {
|
224
|
|
- case INT:
|
225
|
|
- objectNode.put(identifier, 0);
|
226
|
|
- break;
|
227
|
|
- case BOOL:
|
228
|
|
- objectNode.put(identifier, "0");
|
229
|
|
- break;
|
230
|
|
- case DOUBLE:
|
231
|
|
- objectNode.put(identifier, 0.00);
|
232
|
|
- break;
|
233
|
|
- case TEXT:
|
234
|
|
- objectNode.put(identifier, "text");
|
235
|
|
- break;
|
236
|
|
- case STRUCT:
|
237
|
|
- objectNode.putPOJO(identifier, dataType.get("specs"));
|
238
|
|
- break;
|
239
|
|
- default:
|
240
|
|
- objectNode.put(identifier, "value");
|
241
|
|
- break;
|
242
|
|
- }
|
243
|
|
- }
|
244
|
|
- list.add(objectNode);
|
245
|
|
- }
|
246
|
|
- if (deviceType.equals(DeviceTypeEnum.SENSOR)) {
|
247
|
|
- attributeMap.put("网关子设备名称", list);
|
248
|
|
- jsonNode = JacksonUtil.convertValue(attributeMap, JsonNode.class);
|
249
|
|
- } else {
|
250
|
|
- jsonNode = JacksonUtil.convertValue(list, JsonNode.class);
|
251
|
|
- }
|
252
|
|
-
|
253
|
|
- return jsonNode;
|
254
|
|
- }
|
255
|
|
-
|
256
|
202
|
private boolean checkIdentifier(
|
257
|
203
|
String deviceProfileId, String identifier, boolean isAdd, String thingsModelId) {
|
258
|
204
|
TkThingsModelEntity entity =
|
...
|
...
|
|