Commit f623a5786214b017dd8c3be28e5edce9341e370d
Merge remote-tracking branch 'yudao/feature/iot' into iot
# Conflicts: # yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelEvent.java # yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelService.java # yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelServiceImpl.java
Showing
3 changed files
with
41 additions
and
46 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelEvent.java
| @@ -22,16 +22,13 @@ public class ThingModelEvent { | @@ -22,16 +22,13 @@ public class ThingModelEvent { | ||
| 22 | */ | 22 | */ |
| 23 | private String name; | 23 | private String name; |
| 24 | /** | 24 | /** |
| 25 | - * 是否是标准品类的必选事件。 | ||
| 26 | - * | ||
| 27 | - * - true:是 | ||
| 28 | - * - false:否 | 25 | + * 是否是标准品类的必选事件 |
| 29 | */ | 26 | */ |
| 30 | private Boolean required; | 27 | private Boolean required; |
| 31 | /** | 28 | /** |
| 32 | * 事件类型 | 29 | * 事件类型 |
| 33 | * | 30 | * |
| 34 | - * 关联枚举 {@link IotThingModelServiceEventTypeEnum} | 31 | + * 枚举 {@link IotThingModelServiceEventTypeEnum} |
| 35 | */ | 32 | */ |
| 36 | private String type; | 33 | private String type; |
| 37 | /** | 34 | /** |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelService.java
| @@ -22,16 +22,13 @@ public class ThingModelService { | @@ -22,16 +22,13 @@ public class ThingModelService { | ||
| 22 | */ | 22 | */ |
| 23 | private String name; | 23 | private String name; |
| 24 | /** | 24 | /** |
| 25 | - * 是否是标准品类的必选服务。 | ||
| 26 | - * | ||
| 27 | - * - true:是 | ||
| 28 | - * - false:否 | 25 | + * 是否是标准品类的必选服务 |
| 29 | */ | 26 | */ |
| 30 | private Boolean required; | 27 | private Boolean required; |
| 31 | /** | 28 | /** |
| 32 | * 调用类型 | 29 | * 调用类型 |
| 33 | * | 30 | * |
| 34 | - * 关联枚举 {@link IotThingModelServiceCallTypeEnum} | 31 | + * 枚举 {@link IotThingModelServiceCallTypeEnum} |
| 35 | */ | 32 | */ |
| 36 | private String callType; | 33 | private String callType; |
| 37 | /** | 34 | /** |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelServiceImpl.java
| @@ -185,43 +185,44 @@ public class IotThingModelServiceImpl implements IotThingModelService { | @@ -185,43 +185,44 @@ public class IotThingModelServiceImpl implements IotThingModelService { | ||
| 185 | */ | 185 | */ |
| 186 | public void createDefaultEventsAndServices(Long productId, String productKey) { | 186 | public void createDefaultEventsAndServices(Long productId, String productKey) { |
| 187 | // 1. 获取当前属性列表 | 187 | // 1. 获取当前属性列表 |
| 188 | - List<IotThingModelDO> propertyList = thingModelMapper | 188 | + List<IotThingModelDO> properties = thingModelMapper |
| 189 | .selectListByProductIdAndType(productId, IotThingModelTypeEnum.PROPERTY.getType()); | 189 | .selectListByProductIdAndType(productId, IotThingModelTypeEnum.PROPERTY.getType()); |
| 190 | 190 | ||
| 191 | // 2. 生成新的事件和服务列表 | 191 | // 2. 生成新的事件和服务列表 |
| 192 | - List<IotThingModelDO> newThingModelList = new ArrayList<>(); | 192 | + List<IotThingModelDO> newThingModels = new ArrayList<>(); |
| 193 | // 2.1 生成属性上报事件 | 193 | // 2.1 生成属性上报事件 |
| 194 | - ThingModelEvent propertyPostEvent = generatePropertyPostEvent(propertyList); | 194 | + ThingModelEvent propertyPostEvent = generatePropertyPostEvent(properties); |
| 195 | if (propertyPostEvent != null) { | 195 | if (propertyPostEvent != null) { |
| 196 | - newThingModelList.add(buildEventThingModelDO(productId, productKey, propertyPostEvent, "属性上报事件")); | 196 | + newThingModels.add(buildEventThingModelDO(productId, productKey, propertyPostEvent, "属性上报事件")); |
| 197 | } | 197 | } |
| 198 | // 2.2 生成属性设置服务 | 198 | // 2.2 生成属性设置服务 |
| 199 | - ThingModelService propertySetService = generatePropertySetService(propertyList); | 199 | + ThingModelService propertySetService = generatePropertySetService(properties); |
| 200 | if (propertySetService != null) { | 200 | if (propertySetService != null) { |
| 201 | - newThingModelList.add(buildServiceThingModelDO(productId, productKey, propertySetService, "属性设置服务")); | 201 | + newThingModels.add(buildServiceThingModelDO(productId, productKey, propertySetService, "属性设置服务")); |
| 202 | } | 202 | } |
| 203 | // 2.3 生成属性获取服务 | 203 | // 2.3 生成属性获取服务 |
| 204 | - ThingModelService propertyGetService = generatePropertyGetService(propertyList); | 204 | + ThingModelService propertyGetService = generatePropertyGetService(properties); |
| 205 | if (propertyGetService != null) { | 205 | if (propertyGetService != null) { |
| 206 | - newThingModelList.add(buildServiceThingModelDO(productId, productKey, propertyGetService,"属性获取服务")); | 206 | + newThingModels.add(buildServiceThingModelDO(productId, productKey, propertyGetService, "属性获取服务")); |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | // 3.1 获取数据库中的默认的旧事件和服务列表 | 209 | // 3.1 获取数据库中的默认的旧事件和服务列表 |
| 210 | - List<IotThingModelDO> oldThingModelList = thingModelMapper.selectListByProductIdAndIdentifiersAndTypes( | 210 | + List<IotThingModelDO> oldThingModels = thingModelMapper.selectListByProductIdAndIdentifiersAndTypes( |
| 211 | productId, | 211 | productId, |
| 212 | Arrays.asList("post", "set", "get"), | 212 | Arrays.asList("post", "set", "get"), |
| 213 | Arrays.asList(IotThingModelTypeEnum.EVENT.getType(), IotThingModelTypeEnum.SERVICE.getType()) | 213 | Arrays.asList(IotThingModelTypeEnum.EVENT.getType(), IotThingModelTypeEnum.SERVICE.getType()) |
| 214 | ); | 214 | ); |
| 215 | // 3.2 创建默认的事件和服务 | 215 | // 3.2 创建默认的事件和服务 |
| 216 | - createDefaultEventsAndServices(oldThingModelList, newThingModelList); | 216 | + createDefaultEventsAndServices(oldThingModels, newThingModels); |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | /** | 219 | /** |
| 220 | * 创建默认的事件和服务 | 220 | * 创建默认的事件和服务 |
| 221 | */ | 221 | */ |
| 222 | - private void createDefaultEventsAndServices(List<IotThingModelDO> oldThingModelList, List<IotThingModelDO> newThingModelList) { | ||
| 223 | - // 1.1 使用 diffList 方法比较新旧列表 | ||
| 224 | - List<List<IotThingModelDO>> diffResult = diffList(oldThingModelList, newThingModelList, | 222 | + private void createDefaultEventsAndServices(List<IotThingModelDO> oldThingModels, |
| 223 | + List<IotThingModelDO> newThingModels) { | ||
| 224 | + // 使用 diffList 方法比较新旧列表 | ||
| 225 | + List<List<IotThingModelDO>> diffResult = diffList(oldThingModels, newThingModels, | ||
| 225 | (oldVal, newVal) -> { | 226 | (oldVal, newVal) -> { |
| 226 | // 继续使用 identifier 和 type 进行比较:这样可以准确地匹配对应的功能对象。 | 227 | // 继续使用 identifier 和 type 进行比较:这样可以准确地匹配对应的功能对象。 |
| 227 | boolean same = Objects.equals(oldVal.getIdentifier(), newVal.getIdentifier()) | 228 | boolean same = Objects.equals(oldVal.getIdentifier(), newVal.getIdentifier()) |
| @@ -231,7 +232,7 @@ public class IotThingModelServiceImpl implements IotThingModelService { | @@ -231,7 +232,7 @@ public class IotThingModelServiceImpl implements IotThingModelService { | ||
| 231 | } | 232 | } |
| 232 | return same; | 233 | return same; |
| 233 | }); | 234 | }); |
| 234 | - // 1.2 批量添加、修改、删除 | 235 | + // 批量添加、修改、删除 |
| 235 | if (CollUtil.isNotEmpty(diffResult.get(0))) { | 236 | if (CollUtil.isNotEmpty(diffResult.get(0))) { |
| 236 | thingModelMapper.insertBatch(diffResult.get(0)); | 237 | thingModelMapper.insertBatch(diffResult.get(0)); |
| 237 | } | 238 | } |
| @@ -246,8 +247,8 @@ public class IotThingModelServiceImpl implements IotThingModelService { | @@ -246,8 +247,8 @@ public class IotThingModelServiceImpl implements IotThingModelService { | ||
| 246 | /** | 247 | /** |
| 247 | * 构建事件功能对象 | 248 | * 构建事件功能对象 |
| 248 | */ | 249 | */ |
| 249 | - private IotThingModelDO buildEventThingModelDO(Long productId, String productKey, ThingModelEvent event, | ||
| 250 | - String description) { | 250 | + private IotThingModelDO buildEventThingModelDO(Long productId, String productKey, |
| 251 | + ThingModelEvent event, String description) { | ||
| 251 | return new IotThingModelDO().setProductId(productId).setProductKey(productKey) | 252 | return new IotThingModelDO().setProductId(productId).setProductKey(productKey) |
| 252 | .setIdentifier(event.getIdentifier()).setName(event.getName()).setDescription(description) | 253 | .setIdentifier(event.getIdentifier()).setName(event.getName()).setDescription(description) |
| 253 | .setType(IotThingModelTypeEnum.EVENT.getType()).setEvent(event); | 254 | .setType(IotThingModelTypeEnum.EVENT.getType()).setEvent(event); |
| @@ -256,8 +257,8 @@ public class IotThingModelServiceImpl implements IotThingModelService { | @@ -256,8 +257,8 @@ public class IotThingModelServiceImpl implements IotThingModelService { | ||
| 256 | /** | 257 | /** |
| 257 | * 构建服务功能对象 | 258 | * 构建服务功能对象 |
| 258 | */ | 259 | */ |
| 259 | - private IotThingModelDO buildServiceThingModelDO(Long productId, String productKey, ThingModelService service, | ||
| 260 | - String description) { | 260 | + private IotThingModelDO buildServiceThingModelDO(Long productId, String productKey, |
| 261 | + ThingModelService service, String description) { | ||
| 261 | return new IotThingModelDO().setProductId(productId).setProductKey(productKey) | 262 | return new IotThingModelDO().setProductId(productId).setProductKey(productKey) |
| 262 | .setIdentifier(service.getIdentifier()).setName(service.getName()).setDescription(description) | 263 | .setIdentifier(service.getIdentifier()).setName(service.getName()).setDescription(description) |
| 263 | .setType(IotThingModelTypeEnum.SERVICE.getType()).setService(service); | 264 | .setType(IotThingModelTypeEnum.SERVICE.getType()).setService(service); |
| @@ -266,64 +267,64 @@ public class IotThingModelServiceImpl implements IotThingModelService { | @@ -266,64 +267,64 @@ public class IotThingModelServiceImpl implements IotThingModelService { | ||
| 266 | /** | 267 | /** |
| 267 | * 生成属性上报事件 | 268 | * 生成属性上报事件 |
| 268 | */ | 269 | */ |
| 269 | - private ThingModelEvent generatePropertyPostEvent(List<IotThingModelDO> thingModelList) { | ||
| 270 | - // 1.1 没有属性则不生成 | ||
| 271 | - if (CollUtil.isEmpty(thingModelList)) { | 270 | + private ThingModelEvent generatePropertyPostEvent(List<IotThingModelDO> thingModels) { |
| 271 | + // 没有属性则不生成 | ||
| 272 | + if (CollUtil.isEmpty(thingModels)) { | ||
| 272 | return null; | 273 | return null; |
| 273 | } | 274 | } |
| 274 | 275 | ||
| 275 | - // 1.2 生成属性上报事件 | 276 | + // 生成属性上报事件 |
| 276 | return new ThingModelEvent().setIdentifier("post").setName("属性上报").setMethod("thing.event.property.post") | 277 | return new ThingModelEvent().setIdentifier("post").setName("属性上报").setMethod("thing.event.property.post") |
| 277 | .setType(IotThingModelServiceEventTypeEnum.INFO.getType()) | 278 | .setType(IotThingModelServiceEventTypeEnum.INFO.getType()) |
| 278 | - .setOutputParams(buildInputOutputParam(thingModelList, IotThingModelParamDirectionEnum.OUTPUT)); | 279 | + .setOutputParams(buildInputOutputParam(thingModels, IotThingModelParamDirectionEnum.OUTPUT)); |
| 279 | } | 280 | } |
| 280 | 281 | ||
| 281 | /** | 282 | /** |
| 282 | * 生成属性设置服务 | 283 | * 生成属性设置服务 |
| 283 | */ | 284 | */ |
| 284 | - private ThingModelService generatePropertySetService(List<IotThingModelDO> thingModelList) { | 285 | + private ThingModelService generatePropertySetService(List<IotThingModelDO> thingModels) { |
| 285 | // 1.1 过滤出所有可写属性 | 286 | // 1.1 过滤出所有可写属性 |
| 286 | - thingModelList = filterList(thingModelList, thingModel -> | 287 | + thingModels = filterList(thingModels, thingModel -> |
| 287 | IotThingModelAccessModeEnum.READ_WRITE.getMode().equals(thingModel.getProperty().getAccessMode())); | 288 | IotThingModelAccessModeEnum.READ_WRITE.getMode().equals(thingModel.getProperty().getAccessMode())); |
| 288 | // 1.2 没有可写属性则不生成 | 289 | // 1.2 没有可写属性则不生成 |
| 289 | - if (CollUtil.isEmpty(thingModelList)) { | 290 | + if (CollUtil.isEmpty(thingModels)) { |
| 290 | return null; | 291 | return null; |
| 291 | } | 292 | } |
| 292 | 293 | ||
| 293 | // 2. 生成属性设置服务 | 294 | // 2. 生成属性设置服务 |
| 294 | return new ThingModelService().setIdentifier("set").setName("属性设置").setMethod("thing.service.property.set") | 295 | return new ThingModelService().setIdentifier("set").setName("属性设置").setMethod("thing.service.property.set") |
| 295 | .setCallType(IotThingModelServiceCallTypeEnum.ASYNC.getType()) | 296 | .setCallType(IotThingModelServiceCallTypeEnum.ASYNC.getType()) |
| 296 | - .setInputParams(buildInputOutputParam(thingModelList, IotThingModelParamDirectionEnum.INPUT)) | 297 | + .setInputParams(buildInputOutputParam(thingModels, IotThingModelParamDirectionEnum.INPUT)) |
| 297 | .setOutputParams(Collections.emptyList()); // 属性设置服务一般不需要输出参数 | 298 | .setOutputParams(Collections.emptyList()); // 属性设置服务一般不需要输出参数 |
| 298 | } | 299 | } |
| 299 | 300 | ||
| 300 | /** | 301 | /** |
| 301 | * 生成属性获取服务 | 302 | * 生成属性获取服务 |
| 302 | */ | 303 | */ |
| 303 | - private ThingModelService generatePropertyGetService(List<IotThingModelDO> thingModelList) { | 304 | + private ThingModelService generatePropertyGetService(List<IotThingModelDO> thingModels) { |
| 304 | // 1.1 没有属性则不生成 | 305 | // 1.1 没有属性则不生成 |
| 305 | - if (CollUtil.isEmpty(thingModelList)) { | 306 | + if (CollUtil.isEmpty(thingModels)) { |
| 306 | return null; | 307 | return null; |
| 307 | } | 308 | } |
| 308 | 309 | ||
| 309 | // 1.2 生成属性获取服务 | 310 | // 1.2 生成属性获取服务 |
| 310 | return new ThingModelService().setIdentifier("get").setName("属性获取").setMethod("thing.service.property.get") | 311 | return new ThingModelService().setIdentifier("get").setName("属性获取").setMethod("thing.service.property.get") |
| 311 | .setCallType(IotThingModelServiceCallTypeEnum.ASYNC.getType()) | 312 | .setCallType(IotThingModelServiceCallTypeEnum.ASYNC.getType()) |
| 312 | - .setInputParams(buildInputOutputParam(thingModelList, IotThingModelParamDirectionEnum.INPUT)) | ||
| 313 | - .setOutputParams(buildInputOutputParam(thingModelList, IotThingModelParamDirectionEnum.OUTPUT)); | 313 | + .setInputParams(buildInputOutputParam(thingModels, IotThingModelParamDirectionEnum.INPUT)) |
| 314 | + .setOutputParams(buildInputOutputParam(thingModels, IotThingModelParamDirectionEnum.OUTPUT)); | ||
| 314 | } | 315 | } |
| 315 | 316 | ||
| 316 | /** | 317 | /** |
| 317 | * 构建输入/输出参数列表 | 318 | * 构建输入/输出参数列表 |
| 318 | * | 319 | * |
| 319 | - * @param thingModelList 属性列表 | 320 | + * @param thingModels 属性列表 |
| 320 | * @return 输入/输出参数列表 | 321 | * @return 输入/输出参数列表 |
| 321 | */ | 322 | */ |
| 322 | - private List<ThingModelParam> buildInputOutputParam(List<IotThingModelDO> thingModelList, | ||
| 323 | - IotThingModelParamDirectionEnum directionEnum) { | ||
| 324 | - return convertList(thingModelList, thingModel -> | 323 | + private List<ThingModelParam> buildInputOutputParam(List<IotThingModelDO> thingModels, |
| 324 | + IotThingModelParamDirectionEnum direction) { | ||
| 325 | + return convertList(thingModels, thingModel -> | ||
| 325 | BeanUtils.toBean(thingModel.getProperty(), ThingModelParam.class).setParaOrder(0) // TODO @puhui999: 先搞个默认值看看怎么个事 | 326 | BeanUtils.toBean(thingModel.getProperty(), ThingModelParam.class).setParaOrder(0) // TODO @puhui999: 先搞个默认值看看怎么个事 |
| 326 | - .setDirection(directionEnum.getDirection())); | 327 | + .setDirection(direction.getDirection())); |
| 327 | } | 328 | } |
| 328 | 329 | ||
| 329 | } | 330 | } |