...
|
...
|
@@ -19,7 +19,6 @@ import org.thingsboard.server.common.data.exception.ThingsboardException; |
19
|
19
|
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
20
|
20
|
import org.thingsboard.server.common.data.id.RuleChainId;
|
21
|
21
|
import org.thingsboard.server.common.data.id.TenantId;
|
22
|
|
-import org.thingsboard.server.common.data.page.PageLink;
|
23
|
22
|
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
|
24
|
23
|
import org.thingsboard.server.common.data.rule.RuleChain;
|
25
|
24
|
import org.thingsboard.server.common.data.yunteng.common.DeleteGroup;
|
...
|
...
|
@@ -49,222 +48,244 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. |
49
|
48
|
@RequestMapping("api/yt/device_profile")
|
50
|
49
|
@Api(tags = {"设备配置管理"})
|
51
|
50
|
public class YtDeviceProfileController extends BaseController {
|
52
|
|
- private final YtDeviceProfileService ytDeviceProfileService;
|
53
|
|
- private final YtDeviceScriptService javaScriptService;
|
54
|
|
- @PostMapping()
|
55
|
|
- @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:post','api:yt:deviceProfile:update'})")
|
56
|
|
- @ApiOperation("创建 | 编辑")
|
57
|
|
- public ResponseEntity<DeviceProfileDTO> saveDeviceProfile(
|
58
|
|
- @RequestBody DeviceProfileDTO deviceProfileDTO) throws ThingsboardException {
|
59
|
|
-
|
60
|
|
- boolean created = deviceProfileDTO.getId() == null;
|
61
|
|
-
|
62
|
|
- /**
|
63
|
|
- * 业务流程
|
64
|
|
- * 1/3.验证业务平台中表单数据的合法性
|
65
|
|
- * 2/3.处理TB业务逻辑
|
66
|
|
- * 3/3.处理业务平台的业务逻辑
|
67
|
|
- */
|
68
|
|
- String tenantId = getCurrentUser().getCurrentTenantId();
|
69
|
|
- deviceProfileDTO.setTenantId(tenantId);
|
70
|
|
- DeviceProfile tbDeviceProfile = buildTbDeviceProfileFromDeviceProfileDTO(deviceProfileDTO);
|
71
|
|
-
|
72
|
|
- updateTbDeviceProfile(tbDeviceProfile, created);
|
73
|
|
-
|
74
|
|
- ytDeviceProfileService.insertOrUpdate(deviceProfileDTO);
|
75
|
|
-
|
76
|
|
- return ResponseEntity.ok(deviceProfileDTO);
|
|
51
|
+ private final YtDeviceProfileService ytDeviceProfileService;
|
|
52
|
+ private final YtDeviceScriptService javaScriptService;
|
|
53
|
+
|
|
54
|
+ @PostMapping()
|
|
55
|
+ @PreAuthorize(
|
|
56
|
+ "@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:post','api:yt:deviceProfile:update'})")
|
|
57
|
+ @ApiOperation("创建 | 编辑")
|
|
58
|
+ public ResponseEntity<DeviceProfileDTO> saveDeviceProfile(
|
|
59
|
+ @RequestBody DeviceProfileDTO deviceProfileDTO) throws ThingsboardException {
|
|
60
|
+
|
|
61
|
+ boolean created = deviceProfileDTO.getId() == null;
|
|
62
|
+
|
|
63
|
+ /** 业务流程 1/3.验证业务平台中表单数据的合法性 2/3.处理TB业务逻辑 3/3.处理业务平台的业务逻辑 */
|
|
64
|
+ String tenantId = getCurrentUser().getCurrentTenantId();
|
|
65
|
+ deviceProfileDTO.setTenantId(tenantId);
|
|
66
|
+ DeviceProfile tbDeviceProfile = buildTbDeviceProfileFromDeviceProfileDTO(deviceProfileDTO);
|
|
67
|
+
|
|
68
|
+ DeviceProfile saveDeviceProfile = updateTbDeviceProfile(tbDeviceProfile, created);
|
|
69
|
+ deviceProfileDTO.setTbProfileId(saveDeviceProfile.getId().toString());
|
|
70
|
+ ytDeviceProfileService.insertOrUpdate(deviceProfileDTO);
|
|
71
|
+
|
|
72
|
+ return ResponseEntity.ok(deviceProfileDTO);
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ /**
|
|
76
|
+ * 更新thingsboard的设备配置信息
|
|
77
|
+ *
|
|
78
|
+ * @param deviceProfile 设备配置
|
|
79
|
+ * @param created 新建设备
|
|
80
|
+ * @throws ThingsboardException
|
|
81
|
+ */
|
|
82
|
+ private DeviceProfile updateTbDeviceProfile(DeviceProfile deviceProfile, boolean created)
|
|
83
|
+ throws ThingsboardException {
|
|
84
|
+ boolean isFirmwareChanged = false;
|
|
85
|
+ boolean isSoftwareChanged = false;
|
|
86
|
+ if (!created) {
|
|
87
|
+ DeviceProfile oldDeviceProfile =
|
|
88
|
+ deviceProfileService.findDeviceProfileById(getTenantId(), deviceProfile.getId());
|
|
89
|
+ if (!Objects.equals(deviceProfile.getFirmwareId(), oldDeviceProfile.getFirmwareId())) {
|
|
90
|
+ isFirmwareChanged = true;
|
|
91
|
+ }
|
|
92
|
+ if (!Objects.equals(deviceProfile.getSoftwareId(), oldDeviceProfile.getSoftwareId())) {
|
|
93
|
+ isSoftwareChanged = true;
|
|
94
|
+ }
|
|
95
|
+ if (FastIotConstants.ASSERT_DEFAULT_NAME.equals(oldDeviceProfile.getName())
|
|
96
|
+ && !Objects.equals(deviceProfile.getName(), oldDeviceProfile.getName())) {
|
|
97
|
+ throw new YtDataValidationException(
|
|
98
|
+ ErrorMessage.ASSERT_DEFAULT_NAME_NO_CHANGED.getMessage());
|
|
99
|
+ }
|
77
|
100
|
}
|
78
|
101
|
|
79
|
|
- /**
|
80
|
|
- * 更新thingsboard的设备配置信息
|
81
|
|
- *
|
82
|
|
- * @param deviceProfile 设备配置
|
83
|
|
- * @param created 新建设备
|
84
|
|
- * @throws ThingsboardException
|
85
|
|
- */
|
86
|
|
- private DeviceProfile updateTbDeviceProfile(DeviceProfile deviceProfile, boolean created) throws ThingsboardException {
|
87
|
|
- boolean isFirmwareChanged = false;
|
88
|
|
- boolean isSoftwareChanged = false;
|
89
|
|
- if (!created) {
|
90
|
|
- DeviceProfile oldDeviceProfile = deviceProfileService.findDeviceProfileById(getTenantId(), deviceProfile.getId());
|
91
|
|
- if (!Objects.equals(deviceProfile.getFirmwareId(), oldDeviceProfile.getFirmwareId())) {
|
92
|
|
- isFirmwareChanged = true;
|
93
|
|
- }
|
94
|
|
- if (!Objects.equals(deviceProfile.getSoftwareId(), oldDeviceProfile.getSoftwareId())) {
|
95
|
|
- isSoftwareChanged = true;
|
96
|
|
- }
|
97
|
|
- if (FastIotConstants.ASSERT_DEFAULT_NAME.equals(oldDeviceProfile.getName()) && !Objects.equals(deviceProfile.getName(), oldDeviceProfile.getName())) {
|
98
|
|
- throw new YtDataValidationException(ErrorMessage.ASSERT_DEFAULT_NAME_NO_CHANGED.getMessage());
|
99
|
|
- }
|
100
|
|
- }
|
101
|
|
-
|
102
|
|
- DeviceProfile savedDeviceProfile = checkNotNull(deviceProfileService.saveDeviceProfile(deviceProfile));
|
103
|
|
-
|
104
|
|
- tbClusterService.onDeviceProfileChange(savedDeviceProfile, null);
|
105
|
|
- tbClusterService.broadcastEntityStateChangeEvent(deviceProfile.getTenantId(), savedDeviceProfile.getId(),
|
106
|
|
- created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
107
|
|
-
|
108
|
|
- logEntityAction(savedDeviceProfile.getId(), savedDeviceProfile,
|
109
|
|
- null,
|
110
|
|
- created ? ActionType.ADDED : ActionType.UPDATED, null);
|
111
|
|
-
|
112
|
|
- otaPackageStateService.update(savedDeviceProfile, isFirmwareChanged, isSoftwareChanged);
|
113
|
|
-
|
114
|
|
- sendEntityNotificationMsg(getTenantId(), savedDeviceProfile.getId(),
|
115
|
|
- deviceProfile.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
|
116
|
|
- return savedDeviceProfile;
|
|
102
|
+ DeviceProfile savedDeviceProfile =
|
|
103
|
+ checkNotNull(deviceProfileService.saveDeviceProfile(deviceProfile));
|
|
104
|
+
|
|
105
|
+ tbClusterService.onDeviceProfileChange(savedDeviceProfile, null);
|
|
106
|
+ tbClusterService.broadcastEntityStateChangeEvent(
|
|
107
|
+ deviceProfile.getTenantId(),
|
|
108
|
+ savedDeviceProfile.getId(),
|
|
109
|
+ created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
|
|
110
|
+
|
|
111
|
+ logEntityAction(
|
|
112
|
+ savedDeviceProfile.getId(),
|
|
113
|
+ savedDeviceProfile,
|
|
114
|
+ null,
|
|
115
|
+ created ? ActionType.ADDED : ActionType.UPDATED,
|
|
116
|
+ null);
|
|
117
|
+
|
|
118
|
+ otaPackageStateService.update(savedDeviceProfile, isFirmwareChanged, isSoftwareChanged);
|
|
119
|
+
|
|
120
|
+ sendEntityNotificationMsg(
|
|
121
|
+ getTenantId(),
|
|
122
|
+ savedDeviceProfile.getId(),
|
|
123
|
+ deviceProfile.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
|
|
124
|
+ return savedDeviceProfile;
|
|
125
|
+ }
|
|
126
|
+
|
|
127
|
+ @GetMapping("{id}")
|
|
128
|
+ @ApiOperation("详情")
|
|
129
|
+ @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:get'})")
|
|
130
|
+ public ResponseEntity<DeviceProfileDTO> getDevice(@PathVariable("id") String id)
|
|
131
|
+ throws ThingsboardException {
|
|
132
|
+ return ResponseEntity.of(
|
|
133
|
+ ytDeviceProfileService.getDeviceProfile(getCurrentUser().getCurrentTenantId(), id));
|
|
134
|
+ }
|
|
135
|
+
|
|
136
|
+ @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
|
137
|
+ @GetMapping(params = {PAGE_SIZE, PAGE})
|
|
138
|
+ @ApiOperation("查询")
|
|
139
|
+ public YtPageData<DeviceProfileDTO> pageDeviceProfile(
|
|
140
|
+ @RequestParam(PAGE_SIZE) int pageSize,
|
|
141
|
+ @RequestParam(PAGE) int page,
|
|
142
|
+ @RequestParam(value = "name", required = false) String name,
|
|
143
|
+ @RequestParam(value = "transportType", required = false) String transportType,
|
|
144
|
+ @RequestParam(value = ORDER_FILED, required = false) String orderBy,
|
|
145
|
+ @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType)
|
|
146
|
+ throws ThingsboardException {
|
|
147
|
+ return ytDeviceProfileService.page(
|
|
148
|
+ page,
|
|
149
|
+ pageSize,
|
|
150
|
+ orderBy,
|
|
151
|
+ orderType,
|
|
152
|
+ getCurrentUser().getCurrentTenantId(),
|
|
153
|
+ name,
|
|
154
|
+ transportType);
|
|
155
|
+ }
|
|
156
|
+
|
|
157
|
+ @GetMapping("/me/list")
|
|
158
|
+ @ApiOperation("选项列表")
|
|
159
|
+ public ResponseEntity listDeviceProfile() throws ThingsboardException {
|
|
160
|
+ List<DeviceProfileDTO> results =
|
|
161
|
+ ytDeviceProfileService.findDeviceProfile(getCurrentUser().getCurrentTenantId(), null);
|
|
162
|
+ return ResponseEntity.ok(results);
|
|
163
|
+ }
|
|
164
|
+
|
|
165
|
+ @DeleteMapping
|
|
166
|
+ @ApiOperation("删除")
|
|
167
|
+ @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:delete'})")
|
|
168
|
+ public void deleteDevices(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO)
|
|
169
|
+ throws ThingsboardException {
|
|
170
|
+ String tenantId = getCurrentUser().getCurrentTenantId();
|
|
171
|
+ ytDeviceProfileService.checkDeviceProfiles(tenantId, deleteDTO.getIds());
|
|
172
|
+
|
|
173
|
+ for (String id : deleteDTO.getIds()) {
|
|
174
|
+ deleteTbDeviceProfile(id);
|
117
|
175
|
}
|
|
176
|
+ ytDeviceProfileService.deleteDeviceProfiles(tenantId, deleteDTO.getIds());
|
|
177
|
+ }
|
118
|
178
|
|
119
|
|
- @GetMapping("{id}")
|
120
|
|
- @ApiOperation("详情")
|
121
|
|
- @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:get'})")
|
122
|
|
- public ResponseEntity<DeviceProfileDTO> getDevice(@PathVariable("id") String id) throws ThingsboardException {
|
123
|
|
- return ResponseEntity.of(ytDeviceProfileService.getDeviceProfile(getCurrentUser().getCurrentTenantId(), id));
|
124
|
|
- }
|
125
|
|
- @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
|
126
|
|
- @GetMapping(params = {PAGE_SIZE, PAGE})
|
127
|
|
- @ApiOperation("查询")
|
128
|
|
- public YtPageData<DeviceProfileDTO> pageDeviceProfile(
|
129
|
|
- @RequestParam(PAGE_SIZE) int pageSize,
|
130
|
|
- @RequestParam(PAGE) int page,
|
131
|
|
- @RequestParam(value = "name", required = false) String name,
|
132
|
|
- @RequestParam(value = "transportType", required = false) String transportType,
|
133
|
|
- @RequestParam(value = ORDER_FILED, required = false) String orderBy,
|
134
|
|
- @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) throws ThingsboardException {
|
135
|
|
- return ytDeviceProfileService.page(page,pageSize,orderBy,orderType, getCurrentUser().getCurrentTenantId(),name, transportType);
|
136
|
|
- }
|
137
|
|
-
|
138
|
|
- @GetMapping("/me/list")
|
139
|
|
- @ApiOperation("选项列表")
|
140
|
|
- public ResponseEntity listDeviceProfile() throws ThingsboardException {
|
141
|
|
- List<DeviceProfileDTO> results = ytDeviceProfileService.findDeviceProfile(getCurrentUser().getCurrentTenantId());
|
142
|
|
- return ResponseEntity.ok(results);
|
143
|
|
- }
|
|
179
|
+ private void deleteTbDeviceProfile(String profileId) throws ThingsboardException {
|
|
180
|
+ DeviceProfileDTO dto = ytDeviceProfileService.findDeviceProfileById(getCurrentUser().getCurrentTenantId(), profileId);
|
|
181
|
+ if(null != dto){
|
|
182
|
+ DeviceProfileId deviceProfileId = new DeviceProfileId(toUUID(dto.getTbProfileId()));
|
|
183
|
+ DeviceProfile deviceProfile = checkDeviceProfileId(deviceProfileId, Operation.DELETE);
|
|
184
|
+ deviceProfileService.deleteDeviceProfile(getTenantId(), deviceProfileId);
|
144
|
185
|
|
145
|
|
- @DeleteMapping
|
146
|
|
- @ApiOperation("删除")
|
147
|
|
- @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:delete'})")
|
148
|
|
- public void deleteDevices(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException {
|
149
|
|
- String tenantId = getCurrentUser().getCurrentTenantId();
|
150
|
|
- ytDeviceProfileService.checkDeviceProfiles(tenantId, deleteDTO.getIds());
|
|
186
|
+ tbClusterService.onDeviceProfileDelete(deviceProfile, null);
|
|
187
|
+ tbClusterService.broadcastEntityStateChangeEvent(
|
|
188
|
+ deviceProfile.getTenantId(), deviceProfile.getId(), ComponentLifecycleEvent.DELETED);
|
151
|
189
|
|
152
|
|
- for (String id : deleteDTO.getIds()) {
|
153
|
|
- deleteTbDeviceProfile(id);
|
154
|
|
- }
|
155
|
|
- ytDeviceProfileService.deleteDeviceProfiles(tenantId,deleteDTO.getIds());
|
|
190
|
+ logEntityAction(
|
|
191
|
+ deviceProfileId, deviceProfile, null, ActionType.DELETED, null, deviceProfileId);
|
156
|
192
|
|
|
193
|
+ sendEntityNotificationMsg(getTenantId(), deviceProfile.getId(), EdgeEventActionType.DELETED);
|
157
|
194
|
}
|
158
|
|
-
|
159
|
|
- private void deleteTbDeviceProfile(String strDeviceProfileId) throws ThingsboardException {
|
160
|
|
- DeviceProfileId deviceProfileId = new DeviceProfileId(toUUID(strDeviceProfileId));
|
161
|
|
- DeviceProfile deviceProfile = checkDeviceProfileId(deviceProfileId, Operation.DELETE);
|
162
|
|
- deviceProfileService.deleteDeviceProfile(getTenantId(), deviceProfileId);
|
163
|
|
-
|
164
|
|
- tbClusterService.onDeviceProfileDelete(deviceProfile, null);
|
165
|
|
- tbClusterService.broadcastEntityStateChangeEvent(deviceProfile.getTenantId(), deviceProfile.getId(), ComponentLifecycleEvent.DELETED);
|
166
|
|
-
|
167
|
|
- logEntityAction(deviceProfileId, deviceProfile,
|
168
|
|
- null,
|
169
|
|
- ActionType.DELETED, null, deviceProfileId);
|
170
|
|
-
|
171
|
|
- sendEntityNotificationMsg(getTenantId(), deviceProfile.getId(), EdgeEventActionType.DELETED);
|
|
195
|
+ }
|
|
196
|
+
|
|
197
|
+ @GetMapping("/me/default")
|
|
198
|
+ @ApiOperation("默认设备配置")
|
|
199
|
+ public ResponseEntity<DeviceProfile> findCurrentTenantDeviceProfiles()
|
|
200
|
+ throws ThingsboardException {
|
|
201
|
+ DeviceProfile result =
|
|
202
|
+ deviceProfileService.findDefaultDeviceProfile(getCurrentUser().getTenantId());
|
|
203
|
+ return ResponseEntity.ok(result);
|
|
204
|
+ }
|
|
205
|
+
|
|
206
|
+ @PostMapping("/import")
|
|
207
|
+ @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:import'})")
|
|
208
|
+ @ApiOperation("导入配置")
|
|
209
|
+ public ResponseEntity<String> importDeviceProfile() {
|
|
210
|
+ // TODO 实现的业务功能
|
|
211
|
+ return ResponseEntity.ok("");
|
|
212
|
+ }
|
|
213
|
+
|
|
214
|
+ @PostMapping("/export")
|
|
215
|
+ @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:export'})")
|
|
216
|
+ @ApiOperation("导出")
|
|
217
|
+ public ResponseEntity<String> exportDeviceProfile() {
|
|
218
|
+ // TODO 实现的业务功能
|
|
219
|
+ return ResponseEntity.ok("");
|
|
220
|
+ }
|
|
221
|
+
|
|
222
|
+ /**
|
|
223
|
+ * 构造调用TBDeviceProfile需要的参数
|
|
224
|
+ *
|
|
225
|
+ * @param deviceProfileDTO 页面接收的参数
|
|
226
|
+ * @return 封装好的TBDeviceProfile
|
|
227
|
+ */
|
|
228
|
+ private DeviceProfile buildTbDeviceProfileFromDeviceProfileDTO(DeviceProfileDTO deviceProfileDTO)
|
|
229
|
+ throws ThingsboardException {
|
|
230
|
+ DeviceProfile tbDeviceProfile = new DeviceProfile();
|
|
231
|
+ if (StringUtils.isNotBlank(deviceProfileDTO.getId())) {
|
|
232
|
+ DeviceProfileDTO findDeviceProfile =
|
|
233
|
+ ytDeviceProfileService.findDeviceProfileById(
|
|
234
|
+ getCurrentUser().getCurrentTenantId(), deviceProfileDTO.getId());
|
|
235
|
+ if (StringUtils.isNotEmpty(findDeviceProfile.getTbProfileId())) {
|
|
236
|
+ UUID profileId = UUID.fromString(findDeviceProfile.getTbProfileId());
|
|
237
|
+ tbDeviceProfile.setId(new DeviceProfileId(profileId));
|
|
238
|
+ tbDeviceProfile.setCreatedTime(
|
|
239
|
+ deviceProfileDTO.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli());
|
|
240
|
+ }
|
|
241
|
+ } else {
|
|
242
|
+ tbDeviceProfile.setCreatedTime(
|
|
243
|
+ LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli());
|
172
|
244
|
}
|
173
|
|
-
|
174
|
|
- @GetMapping("/me/default")
|
175
|
|
- @ApiOperation("默认设备配置")
|
176
|
|
- public ResponseEntity<DeviceProfile> findCurrentTenantDeviceProfiles() throws ThingsboardException {
|
177
|
|
- DeviceProfile result = deviceProfileService.findDefaultDeviceProfile(getCurrentUser().getTenantId());
|
178
|
|
- return ResponseEntity.ok(result);
|
|
245
|
+ tbDeviceProfile.setName(deviceProfileDTO.getName());
|
|
246
|
+ tbDeviceProfile.setImage(deviceProfileDTO.getImage());
|
|
247
|
+ tbDeviceProfile.setDescription(deviceProfileDTO.getDescription());
|
|
248
|
+ tbDeviceProfile.setType(DeviceProfileType.DEFAULT);
|
|
249
|
+ UUID tenantId = UUID.fromString(deviceProfileDTO.getTenantId());
|
|
250
|
+ tbDeviceProfile.setTenantId(TenantId.fromUUID(tenantId));
|
|
251
|
+ tbDeviceProfile.setDefault(deviceProfileDTO.isDefault());
|
|
252
|
+
|
|
253
|
+ String chainStr = deviceProfileDTO.getDefaultRuleChainId();
|
|
254
|
+ // 获取当前租户的默认规则链
|
|
255
|
+ if (StringUtils.isNotBlank(chainStr)) {
|
|
256
|
+ UUID chainId = UUID.fromString(chainStr);
|
|
257
|
+ RuleChain chain =
|
|
258
|
+ ruleChainService.findRuleChainById(TenantId.SYS_TENANT_ID, new RuleChainId(chainId));
|
|
259
|
+ if (chain == null
|
|
260
|
+ || !deviceProfileDTO.getTenantId().equals(chain.getTenantId().getId().toString())) {
|
|
261
|
+ throw new YtDataValidationException(ErrorMessage.RULE_CHAIN_NOT_ENABLE.getMessage());
|
|
262
|
+ }
|
|
263
|
+ tbDeviceProfile.setDefaultRuleChainId(new RuleChainId(chainId));
|
179
|
264
|
}
|
180
|
265
|
|
181
|
|
- @PostMapping("/import")
|
182
|
|
- @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:import'})")
|
183
|
|
- @ApiOperation("导入配置")
|
184
|
|
- public ResponseEntity<String> importDeviceProfile(){
|
185
|
|
- //TODO 实现的业务功能
|
186
|
|
- return ResponseEntity.ok("");
|
187
|
|
- }
|
|
266
|
+ tbDeviceProfile.setDefaultQueueName(ServiceQueue.MAIN);
|
|
267
|
+ tbDeviceProfile.setProvisionType(DeviceProfileProvisionType.DISABLED);
|
188
|
268
|
|
189
|
|
- @PostMapping("/export")
|
190
|
|
- @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:deviceProfile:export'})")
|
191
|
|
- @ApiOperation("导出")
|
192
|
|
- public ResponseEntity<String> exportDeviceProfile(){
|
193
|
|
- //TODO 实现的业务功能
|
194
|
|
- return ResponseEntity.ok("");
|
|
269
|
+ // 传输类型默认都是Default
|
|
270
|
+ String transportType = deviceProfileDTO.getTransportType();
|
|
271
|
+ String scriptText = null;
|
|
272
|
+ if (transportType == null || DeviceTransportType.DEFAULT.name().equals(transportType)) {
|
|
273
|
+ tbDeviceProfile.setTransportType(DeviceTransportType.DEFAULT);
|
|
274
|
+ } else {
|
|
275
|
+ tbDeviceProfile.setTransportType(DeviceTransportType.valueOf(transportType));
|
195
|
276
|
}
|
196
|
277
|
|
197
|
|
-
|
198
|
|
-
|
199
|
|
- /**
|
200
|
|
- * 构造调用TBDeviceProfile需要的参数
|
201
|
|
- *
|
202
|
|
- * @param deviceProfileDTO 页面接收的参数
|
203
|
|
- * @return 封装好的TBDeviceProfile
|
204
|
|
- */
|
205
|
|
- private DeviceProfile buildTbDeviceProfileFromDeviceProfileDTO(DeviceProfileDTO deviceProfileDTO) {
|
206
|
|
- DeviceProfile tbDeviceProfile = new DeviceProfile();
|
207
|
|
- if (StringUtils.isNotBlank(deviceProfileDTO.getId())) {
|
208
|
|
- UUID profileId = UUID.fromString(deviceProfileDTO.getId());
|
209
|
|
- tbDeviceProfile.setId(new DeviceProfileId(profileId));
|
210
|
|
- tbDeviceProfile.setCreatedTime(deviceProfileDTO.getCreateTime().toInstant(ZoneOffset.of("+8")).toEpochMilli());
|
211
|
|
- }else{
|
212
|
|
- tbDeviceProfile.setCreatedTime(LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli());
|
213
|
|
- }
|
214
|
|
- tbDeviceProfile.setName(deviceProfileDTO.getName());
|
215
|
|
- tbDeviceProfile.setImage(deviceProfileDTO.getImage());
|
216
|
|
- tbDeviceProfile.setDescription(deviceProfileDTO.getDescription());
|
217
|
|
- tbDeviceProfile.setType(DeviceProfileType.DEFAULT);
|
218
|
|
- UUID tenantId = UUID.fromString(deviceProfileDTO.getTenantId());
|
219
|
|
- tbDeviceProfile.setTenantId(TenantId.fromUUID(tenantId));
|
220
|
|
- tbDeviceProfile.setDefault(deviceProfileDTO.isDefault());
|
221
|
|
-
|
222
|
|
-
|
223
|
|
- String chainStr = deviceProfileDTO.getDefaultRuleChainId();
|
224
|
|
- if(StringUtils.isBlank(chainStr)){
|
225
|
|
- throw new YtDataValidationException(ErrorMessage.RULE_CHAIN_NOT_ENABLE.getMessage());
|
226
|
|
- }
|
227
|
|
- UUID chainId = UUID.fromString(chainStr);
|
228
|
|
- RuleChain chain = ruleChainService.findRuleChainById(TenantId.SYS_TENANT_ID,new RuleChainId(chainId));
|
229
|
|
- if(chain==null || !deviceProfileDTO.getTenantId().equals(chain.getTenantId().getId().toString())){
|
230
|
|
- throw new YtDataValidationException(ErrorMessage.RULE_CHAIN_NOT_ENABLE.getMessage());
|
231
|
|
- }
|
232
|
|
-
|
233
|
|
- // 获取当前租户的默认规则链
|
234
|
|
- if (StringUtils.isNotBlank(deviceProfileDTO.getDefaultRuleChainId())) {
|
235
|
|
- tbDeviceProfile.setDefaultRuleChainId(new RuleChainId(chainId));
|
236
|
|
- }
|
237
|
|
-
|
238
|
|
- tbDeviceProfile.setDefaultQueueName(ServiceQueue.MAIN);
|
239
|
|
- tbDeviceProfile.setProvisionType(DeviceProfileProvisionType.DISABLED);
|
240
|
|
-
|
241
|
|
-
|
242
|
|
- // 传输类型默认都是Default
|
243
|
|
- String transportType = deviceProfileDTO.getTransportType();
|
244
|
|
- String scriptText=null;
|
245
|
|
- if(transportType ==null || DeviceTransportType.DEFAULT.name().equals(transportType)){
|
246
|
|
- tbDeviceProfile.setTransportType(DeviceTransportType.DEFAULT);
|
247
|
|
- }else{
|
248
|
|
- tbDeviceProfile.setTransportType(DeviceTransportType.valueOf(transportType));
|
249
|
|
- }
|
250
|
|
-
|
251
|
|
- if(DeviceTransportType.TCP.name().equals(transportType)){
|
252
|
|
- YtTcpDeviceProfileTransportConfiguration tcpDeviceProfileTransportConfiguration = (YtTcpDeviceProfileTransportConfiguration) deviceProfileDTO.getProfileData().getTransportConfiguration();
|
253
|
|
- String scriptId = tcpDeviceProfileTransportConfiguration.getScriptId();
|
254
|
|
- scriptText =javaScriptService.getScriptText(deviceProfileDTO.getTenantId(), scriptId);
|
255
|
|
- deviceProfileDTO.setScriptId(scriptId);
|
256
|
|
- }
|
257
|
|
-
|
258
|
|
- DeviceProfileData deviceProfileData = new DeviceProfileData();
|
259
|
|
- buildDeviceProfileData(transportType,deviceProfileData,deviceProfileDTO.getProfileData().getTransportConfiguration(),scriptText);
|
260
|
|
-
|
261
|
|
- if(deviceProfileDTO.getProfileData()!=null
|
262
|
|
- && deviceProfileDTO.getProfileData().getAlarms() !=null){
|
263
|
|
- deviceProfileData.setAlarms(deviceProfileDTO.getProfileData().getAlarms());
|
264
|
|
- }
|
265
|
|
-
|
266
|
|
- tbDeviceProfile.setProfileData(deviceProfileData);
|
267
|
|
-
|
268
|
|
- return tbDeviceProfile;
|
|
278
|
+ if (DeviceTransportType.TCP.name().equals(transportType)) {
|
|
279
|
+ YtTcpDeviceProfileTransportConfiguration tcpDeviceProfileTransportConfiguration =
|
|
280
|
+ (YtTcpDeviceProfileTransportConfiguration)
|
|
281
|
+ deviceProfileDTO.getProfileData().getTransportConfiguration();
|
|
282
|
+ String scriptId = tcpDeviceProfileTransportConfiguration.getScriptId();
|
|
283
|
+ scriptText = javaScriptService.getScriptText(deviceProfileDTO.getTenantId(), scriptId);
|
|
284
|
+ deviceProfileDTO.setScriptId(scriptId);
|
269
|
285
|
}
|
|
286
|
+
|
|
287
|
+ tbDeviceProfile.setProfileData(
|
|
288
|
+ buildDeviceProfileData(transportType, deviceProfileDTO.getProfileData(), scriptText));
|
|
289
|
+ return tbDeviceProfile;
|
|
290
|
+ }
|
270
|
291
|
} |
...
|
...
|
|