From 8454a10cea33f74c1c82fa74f4e5fac9cd654e31 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Thu, 19 Dec 2024 11:19:10 +0800 Subject: [PATCH] 【代码优化】IOT: ThingModel 评审优化 --- yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java | 12 ++++++------ yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotProductThingModelAccessModeEnum.java | 20 ++++++++++++++++++++ yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotProductThingModelTypeEnum.java | 47 +++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thinkmodel/IotProductThinkModelAccessModeEnum.java | 20 -------------------- yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thinkmodel/IotProductThinkModelTypeEnum.java | 47 ----------------------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/deviceData/IotDeviceDataRespVO.java | 2 +- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotProductThingModelController.http | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotProductThingModelController.java | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelEvent.java | 32 ++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelProperty.java | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelRespVO.java | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelService.java | 33 +++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArgument.java | 24 ++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArrayDataSpecs.java | 34 ++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelBoolOrEnumDataSpecs.java | 30 ++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDataSpecs.java | 35 +++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDateOrTextDataSpecs.java | 30 ++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelNumericDataSpec.java | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelStructDataSpecs.java | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelPageReqVO.java | 32 ++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelRespVO.java | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelSaveReqVO.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/IotProductThingModelController.http | 187 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/IotProductThinkModelController.java | 84 ------------------------------------------------------------------------------------ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelEvent.java | 32 -------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelProperty.java | 56 -------------------------------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelRespVO.java | 50 -------------------------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelService.java | 33 --------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelArgument.java | 24 ------------------------ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelArrayDataSpecs.java | 35 ----------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelBoolOrEnumDataSpecs.java | 30 ------------------------------ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelDataSpecs.java | 35 ----------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelDateOrTextDataSpecs.java | 30 ------------------------------ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelNumericDataSpec.java | 51 --------------------------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelStructDataSpecs.java | 58 ---------------------------------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelPageReqVO.java | 32 -------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelRespVO.java | 54 ------------------------------------------------------ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelSaveReqVO.java | 53 ----------------------------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/device/IotDeviceDataConvert.java | 2 +- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thingmodel/IotProductThingModelConvert.java | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thinkmodel/IotProductThinkModelConvert.java | 62 -------------------------------------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceDataDO.java | 12 ++++++------ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/FieldParser.java | 8 ++++---- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThingModelMessage.java | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThinkModelMessage.java | 70 ---------------------------------------------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thingmodel/IotProductThingModelDO.java | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thinkmodel/IotProductThinkModelDO.java | 91 ------------------------------------------------------------------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thingmodel/IotProductThingModelMapper.java | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thinkmodel/IotProductThinkModelMapper.java | 62 -------------------------------------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceDataServiceImpl.java | 40 ++++++++++++++++++++-------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java | 6 +++--- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotSuperTableService.java | 5 +++-- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotSuperTableServiceImpl.java | 36 ++++++++++++++++++------------------ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageService.java | 18 ++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThinkModelMessageService.java | 18 ------------------ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThinkModelMessageServiceImpl.java | 227 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotProductThingModelService.java | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotProductThingModelServiceImpl.java | 442 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodel/IotProductThinkModelService.java | 79 ------------------------------------------------------------------------------- yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodel/IotProductThinkModelServiceImpl.java | 445 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 61 files changed, 2021 insertions(+), 2026 deletions(-) create mode 100644 yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotProductThingModelAccessModeEnum.java create mode 100644 yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotProductThingModelTypeEnum.java delete mode 100644 yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thinkmodel/IotProductThinkModelAccessModeEnum.java delete mode 100644 yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thinkmodel/IotProductThinkModelTypeEnum.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotProductThingModelController.http create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotProductThingModelController.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelEvent.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelProperty.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelRespVO.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelService.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArgument.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArrayDataSpecs.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelBoolOrEnumDataSpecs.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDataSpecs.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDateOrTextDataSpecs.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelNumericDataSpec.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelStructDataSpecs.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelPageReqVO.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelRespVO.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelSaveReqVO.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/IotProductThingModelController.http delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/IotProductThinkModelController.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelEvent.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelProperty.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelRespVO.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelService.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelArgument.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelArrayDataSpecs.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelBoolOrEnumDataSpecs.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelDataSpecs.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelDateOrTextDataSpecs.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelNumericDataSpec.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelStructDataSpecs.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelPageReqVO.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelRespVO.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelSaveReqVO.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thingmodel/IotProductThingModelConvert.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thinkmodel/IotProductThinkModelConvert.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThingModelMessage.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThinkModelMessage.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thingmodel/IotProductThingModelDO.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thinkmodel/IotProductThinkModelDO.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thingmodel/IotProductThingModelMapper.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thinkmodel/IotProductThinkModelMapper.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageService.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThinkModelMessageService.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThinkModelMessageServiceImpl.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotProductThingModelService.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotProductThingModelServiceImpl.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodel/IotProductThinkModelService.java delete mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodel/IotProductThinkModelServiceImpl.java diff --git a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java index 633b3cb..4539f12 100644 --- a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java +++ b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java @@ -13,14 +13,14 @@ public interface ErrorCodeConstants { ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_050_001_000, "产品不存在"); ErrorCode PRODUCT_KEY_EXISTS = new ErrorCode(1_050_001_001, "产品标识已经存在"); ErrorCode PRODUCT_STATUS_NOT_DELETE = new ErrorCode(1_050_001_002, "产品状是发布状态,不允许删除"); - ErrorCode PRODUCT_STATUS_NOT_ALLOW_FUNCTION = new ErrorCode(1_050_001_003, "产品状是发布状态,不允许操作物模型"); + ErrorCode PRODUCT_STATUS_NOT_ALLOW_THING_MODEL = new ErrorCode(1_050_001_003, "产品状是发布状态,不允许操作物模型"); // ========== 产品物模型 1-050-002-000 ============ - ErrorCode THINK_MODEL_FUNCTION_NOT_EXISTS = new ErrorCode(1_050_002_000, "产品物模型不存在"); - ErrorCode THINK_MODEL_FUNCTION_EXISTS_BY_PRODUCT_KEY = new ErrorCode(1_050_002_001, "ProductKey 对应的产品物模型已存在"); - ErrorCode THINK_MODEL_FUNCTION_IDENTIFIER_EXISTS = new ErrorCode(1_050_002_002, "存在重复的功能标识符。"); - ErrorCode THINK_MODEL_FUNCTION_NAME_EXISTS = new ErrorCode(1_050_002_003, "存在重复的功能名称。"); - ErrorCode THINK_MODEL_FUNCTION_IDENTIFIER_INVALID = new ErrorCode(1_050_002_003, "产品物模型标识无效"); + ErrorCode THING_MODEL_NOT_EXISTS = new ErrorCode(1_050_002_000, "产品物模型不存在"); + ErrorCode THING_MODEL_EXISTS_BY_PRODUCT_KEY = new ErrorCode(1_050_002_001, "ProductKey 对应的产品物模型已存在"); + ErrorCode THING_MODEL_IDENTIFIER_EXISTS = new ErrorCode(1_050_002_002, "存在重复的功能标识符。"); + ErrorCode THING_MODEL_NAME_EXISTS = new ErrorCode(1_050_002_003, "存在重复的功能名称。"); + ErrorCode THING_MODEL_IDENTIFIER_INVALID = new ErrorCode(1_050_002_003, "产品物模型标识无效"); // ========== 设备 1-050-003-000 ============ ErrorCode DEVICE_NOT_EXISTS = new ErrorCode(1_050_003_000, "设备不存在"); diff --git a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotProductThingModelAccessModeEnum.java b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotProductThingModelAccessModeEnum.java new file mode 100644 index 0000000..a755018 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotProductThingModelAccessModeEnum.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.iot.enums.thingmodel; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * IOT 访问方式枚举类 + * + * @author ahh + */ +@AllArgsConstructor +@Getter +public enum IotProductThingModelAccessModeEnum { + + READ_ONLY("r"), + READ_WRITE("rw"); + + private final String mode; + +} diff --git a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotProductThingModelTypeEnum.java b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotProductThingModelTypeEnum.java new file mode 100644 index 0000000..153e93e --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotProductThingModelTypeEnum.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.module.iot.enums.thingmodel; + +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * IOT 产品功能(物模型)类型枚举类 + * + * @author ahh + */ +@AllArgsConstructor +@Getter +public enum IotProductThingModelTypeEnum implements IntArrayValuable { + + PROPERTY(1, "属性"), + SERVICE(2, "服务"), + EVENT(3, "事件"); + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProductThingModelTypeEnum::getType).toArray(); + + /** + * 类型 + */ + private final Integer type; + /** + * 描述 + */ + private final String description; + + public static IotProductThingModelTypeEnum valueOfType(Integer type) { + for (IotProductThingModelTypeEnum value : values()) { + if (value.getType().equals(type)) { + return value; + } + } + return null; + } + + @Override + public int[] array() { + return ARRAYS; + } + +} diff --git a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thinkmodel/IotProductThinkModelAccessModeEnum.java b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thinkmodel/IotProductThinkModelAccessModeEnum.java deleted file mode 100644 index b7f6ca3..0000000 --- a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thinkmodel/IotProductThinkModelAccessModeEnum.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.thinkmodel; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * IOT 访问方式枚举类 - * - * @author ahh - */ -@AllArgsConstructor -@Getter -public enum IotProductThinkModelAccessModeEnum { - - READ_ONLY("r"), - READ_WRITE("rw"); - - private final String mode; - -} diff --git a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thinkmodel/IotProductThinkModelTypeEnum.java b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thinkmodel/IotProductThinkModelTypeEnum.java deleted file mode 100644 index 0ed00d0..0000000 --- a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thinkmodel/IotProductThinkModelTypeEnum.java +++ /dev/null @@ -1,47 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.thinkmodel; - -import cn.iocoder.yudao.framework.common.core.IntArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * IOT 产品功能(物模型)类型枚举类 - * - * @author ahh - */ -@AllArgsConstructor -@Getter -public enum IotProductThinkModelTypeEnum implements IntArrayValuable { - - PROPERTY(1, "属性"), - SERVICE(2, "服务"), - EVENT(3, "事件"); - - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProductThinkModelTypeEnum::getType).toArray(); - - /** - * 类型 - */ - private final Integer type; - /** - * 描述 - */ - private final String description; - - public static IotProductThinkModelTypeEnum valueOfType(Integer type) { - for (IotProductThinkModelTypeEnum value : values()) { - if (value.getType().equals(type)) { - return value; - } - } - return null; - } - - @Override - public int[] array() { - return ARRAYS; - } - -} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/deviceData/IotDeviceDataRespVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/deviceData/IotDeviceDataRespVO.java index ad32fb5..f25377e 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/deviceData/IotDeviceDataRespVO.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/deviceData/IotDeviceDataRespVO.java @@ -13,7 +13,7 @@ public class IotDeviceDataRespVO { private Long deviceId; @Schema(description = "物模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21816") - private Long thinkModelFunctionId; + private Long thingModelId; @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) private String productKey; diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotProductThingModelController.http b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotProductThingModelController.http new file mode 100644 index 0000000..7742705 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotProductThingModelController.http @@ -0,0 +1,187 @@ +### 请求 /iot/product-thing-model/create 接口 => 成功 +POST {{baseUrl}}/iot/product-thing-model/create +Content-Type: application/json +tenant-id: {{adminTenentId}} +Authorization: Bearer {{token}} + +{ + "productId": 12, + "productKey": "CJVS54fObwZJ9Qe5CJVS54fObwZJ9Qe5", + "identifier": "Temperature", + "name": "温度", + "description": "当前温度值", + "type": 1, + "property": { + "identifier": "Temperature", + "name": "温度", + "accessMode": "r", + "required": true, + "dataType": "int", + "dataSpecs": { + "dataType": "int", + "max": "200", + "min": "0", + "step": "10", + "defaultValue": "30", + "unit": "%", + "unitName": "百分比" + }, + "description": "当前温度值" + } +} + +### 请求 /iot/product-thing-model/create 接口 => 成功 +POST {{baseUrl}}/iot/product-thing-model/create +Content-Type: application/json +tenant-id: {{adminTenentId}} +Authorization: Bearer {{token}} + +{ + "productId": 12, + "productKey": "CJVS54fObwZJ9Qe5CJVS54fObwZJ9Qe5", + "identifier": "switch", + "name": "开关", + "description": "温度计开关", + "type": 1, + "property": { + "identifier": "switch", + "name": "开关", + "description": "温度计开关", + "accessMode": "rw", + "required": true, + "dataType": "bool", + "dataSpecsList": [ + { + "dataType": "bool", + "name": "关", + "value": 0 + }, + { + "dataType": "bool", + "name": "开", + "value": 1 + } + ] + } +} + +### 请求 /iot/product-thing-model/create 接口 => 成功 +POST {{baseUrl}}/iot/product-thing-model/create +Content-Type: application/json +tenant-id: {{adminTenentId}} +Authorization: Bearer {{token}} + +{ + "productId": 12, + "productKey": "CJVS54fObwZJ9Qe5CJVS54fObwZJ9Qe5", + "identifier": "argb", + "name": "温度计 argb 颜色", + "description": "温度计 argb 颜色", + "type": 1, + "property": { + "identifier": "argb", + "name": "温度计 argb 颜色", + "description": "温度计 argb 颜色", + "accessMode": "rw", + "required": true, + "dataType": "array", + "dataSpecs": { + "dataType": "array", + "size": 10, + "childDataType": "struct", + "dataSpecsList": [ + { + "identifier": "switch", + "name": "开关", + "description": "温度计开关", + "accessMode": "rw", + "required": true, + "dataType": "struct", + "childDataType": "bool", + "dataSpecsList": [ + { + "dataType": "bool", + "name": "关", + "value": 0 + }, + { + "dataType": "bool", + "name": "开", + "value": 1 + } + ] + }, + { + "identifier": "Temperature", + "name": "温度", + "accessMode": "r", + "required": true, + "dataType": "struct", + "childDataType": "int", + "dataSpecs": { + "dataType": "int", + "max": "200", + "min": "0", + "step": "10", + "defaultValue": "30", + "unit": "%", + "unitName": "百分比" + }, + "description": "当前温度值" + } + ] + } + } +} + +### 请求 /iot/product-thing-model/update 接口 => 成功 +PUT {{baseUrl}}/iot/product-thing-model/update +Content-Type: application/json +tenant-id: {{adminTenentId}} +Authorization: Bearer {{token}} + +{ + "id": 33, + "productId": 12, + "productKey": "CJVS54fObwZJ9Qe5CJVS54fObwZJ9Qe5", + "identifier": "switch", + "name": "开关", + "description": "温度计开关", + "type": 1, + "property": { + "identifier": "switch", + "name": "开关", + "description": "温度计开关", + "accessMode": "r", + "required": true, + "dataType": "bool", + "dataSpecsList": [ + { + "dataType": "bool", + "name": "关", + "value": 0 + }, + { + "dataType": "bool", + "name": "开", + "value": 1 + } + ] + } +} + +### 请求 /iot/product-thing-model/delete 接口 => 成功 +DELETE {{baseUrl}}/iot/product-thing-model/delete?id=36 +tenant-id: {{adminTenentId}} +Authorization: Bearer {{token}} + +### 请求 /iot/product-thing-model/get 接口 => 成功 +GET {{baseUrl}}/iot/product-thing-model/get?id=40 +tenant-id: {{adminTenentId}} +Authorization: Bearer {{token}} + + +### 请求 /iot/product-thing-model/list-by-product-id 接口 => 成功 +GET {{baseUrl}}/iot/product-thing-model/list-by-product-id?productId=1001 +tenant-id: {{adminTenentId}} +Authorization: Bearer {{token}} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotProductThingModelController.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotProductThingModelController.java new file mode 100644 index 0000000..9b94def --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotProductThingModelController.java @@ -0,0 +1,84 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotProductThingModelPageReqVO; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotProductThingModelRespVO; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotProductThingModelSaveReqVO; +import cn.iocoder.yudao.module.iot.convert.thingmodel.IotProductThingModelConvert; +import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotProductThingModelDO; +import cn.iocoder.yudao.module.iot.service.thingmodel.IotProductThingModelService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.validation.Valid; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "管理后台 - IoT 产品物模型") +@RestController +@RequestMapping("/iot/product-thing-model") +@Validated +public class IotProductThingModelController { + + @Resource + private IotProductThingModelService thingModelService; + + @PostMapping("/create") + @Operation(summary = "创建产品物模型") + @PreAuthorize("@ss.hasPermission('iot:product-thing-model:create')") + public CommonResult createProductThingModel(@Valid @RequestBody IotProductThingModelSaveReqVO createReqVO) { + return success(thingModelService.createProductThingModel(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新产品物模型") + @PreAuthorize("@ss.hasPermission('iot:product-thing-model:update')") + public CommonResult updateProductThingModel(@Valid @RequestBody IotProductThingModelSaveReqVO updateReqVO) { + thingModelService.updateProductThingModel(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除产品物模型") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('iot:product-thing-model:delete')") + public CommonResult deleteProductThingModel(@RequestParam("id") Long id) { + thingModelService.deleteProductThingModel(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得产品物模型") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('iot:product-thing-model:query')") + public CommonResult getProductThingModel(@RequestParam("id") Long id) { + IotProductThingModelDO thingModel = thingModelService.getProductThingModel(id); + return success(IotProductThingModelConvert.INSTANCE.convert(thingModel)); + } + + @GetMapping("/list-by-product-id") + @Operation(summary = "获得产品物模型") + @Parameter(name = "productId", description = "产品ID", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('iot:product-thing-model:query')") + public CommonResult> getProductThingModelListByProductId(@RequestParam("productId") Long productId) { + List list = thingModelService.getProductThingModelListByProductId(productId); + return success(IotProductThingModelConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @Operation(summary = "获得产品物模型分页") + @PreAuthorize("@ss.hasPermission('iot:product-thing-model:query')") + public CommonResult> getProductThingModelPage(@Valid IotProductThingModelPageReqVO pageReqVO) { + PageResult pageResult = thingModelService.getProductThingModelPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, IotProductThingModelRespVO.class)); + } + +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelEvent.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelEvent.java new file mode 100644 index 0000000..718c7b6 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelEvent.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model; + +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelArgument; +import lombok.Data; +import java.util.List; + +@Data +public class ThingModelEvent { + + /** + * 事件标识符 + */ + private String identifier; + /** + * 事件名称 + */ + private String name; + /** + * 事件描述 + */ + private String description; + + /** + * 事件类型 + * + * "info"、"alert"、"error" + */ + private String type; + private List outputData; + private String method; + +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelProperty.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelProperty.java new file mode 100644 index 0000000..0c9105a --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelProperty.java @@ -0,0 +1,56 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model; + +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDataSpecs; +import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelAccessModeEnum; +import lombok.Data; + +import java.util.List; + +/** + * 物模型中的属性 + * + * dataSpecs 和 dataSpecsList 之中必须传入且只能传入一个 + * + * @author HUIHUI + */ +@Data +public class ThingModelProperty { + + /** + * 属性标识符 + */ + private String identifier; + /** + * 属性名称 + */ + private String name; + /** + * 属性描述 + */ + private String description; + /** + * 云端可以对该属性进行的操作类型 + * 关联枚举 {@link IotProductThingModelAccessModeEnum} + */ + private String accessMode; + /** + * 是否是标准品类的必选服务。 + * + * - true:是 + * - false:否 + */ + private Boolean required; + /** + * 数据类型,与 dataSpecs 的 dataType 保持一致 + */ + private String dataType; + /** + * 数据类型(dataType)为非列表型(int、float、double、text、date、array)的数据规范存储在 dataSpecs 中 + */ + private ThingModelDataSpecs dataSpecs; + /** + * 数据类型(dataType)为列表型(enum、bool、struct)的数据规范存储在 dataSpecsList 中 + */ + private List dataSpecsList; + +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelRespVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelRespVO.java new file mode 100644 index 0000000..44fd24c --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelRespVO.java @@ -0,0 +1,50 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model; + +import lombok.*; + +import java.util.List; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class ThingModelRespVO { + + /** + * 产品编号 + */ + private Long id; + + /** + * 产品标识 + */ + private String productKey; + + /** + * 物模型 + */ + private Model model; + + /** + * 物模型 + */ + @Data + public static class Model { + + /** + * 属性列表 + */ + private List properties; + + /** + * 服务列表 + */ + private List services; + + /** + * 事件列表 + */ + private List events; + } +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelService.java new file mode 100644 index 0000000..ec4bd34 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelService.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model; + +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelArgument; +import lombok.Data; +import java.util.List; + +@Data +public class ThingModelService { + + /** + * 服务标识符 + */ + private String identifier; + /** + * 服务名称 + */ + private String name; + /** + * 服务描述 + */ + private String description; + + /** + * 调用类型 + * + * "sync"、"async" + */ + private String callType; + private List inputData; + private List outputData; + private String method; + +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArgument.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArgument.java new file mode 100644 index 0000000..7b3fb09 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArgument.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType; + +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty; +import lombok.Data; + +@Data +public class ThingModelArgument { + + public static final String DIRECTION_INPUT = "input"; + public static final String DIRECTION_OUTPUT = "output"; + + private String identifier; + private String name; + /** + * 物模型中的属性 + */ + private ThingModelProperty property; + /** + * 用于区分输入或输出参数,"input" 或 "output" + */ + private String direction; + private String description; + +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArrayDataSpecs.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArrayDataSpecs.java new file mode 100644 index 0000000..b8b1a29 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArrayDataSpecs.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +/** + * 物模型数据类型为数组的 DataSpec 定义 + * + * @author HUIHUI + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段,从而避免重复。 +public class ThingModelArrayDataSpecs extends ThingModelDataSpecs { + + /** + * 数组中的元素个数。 + */ + private Integer size; + /** + * 数组中的元素的数据类型。可选值:struct、int、float、double 或 text。 + */ + private String childDataType; + /** + * 数据类型(childDataType)为列表型 struct 的数据规范存储在 dataSpecsList 中。 + * 此时 struct 取值范围为:int、float、double、text、date、enum、bool + */ + private List dataSpecsList; + +} + diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelBoolOrEnumDataSpecs.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelBoolOrEnumDataSpecs.java new file mode 100644 index 0000000..3ab624c --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelBoolOrEnumDataSpecs.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 物模型数据类型为布尔型或枚举型的 DataSpec 定义 + * + * 数据类型,取值为 bool 或 enum。 + * + * @author HUIHUI + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段,从而避免重复。 +public class ThingModelBoolOrEnumDataSpecs extends ThingModelDataSpecs { + + /** + * 枚举项的名称。 + * 可包含中文、大小写英文字母、数字、下划线(_)和短划线(-)。 + * 必须以中文、英文字母或数字开头,长度不超过 20 个字符。 + */ + private String name; + /** + * 枚举值。 + */ + private Integer value; + +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDataSpecs.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDataSpecs.java new file mode 100644 index 0000000..78bfd02 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDataSpecs.java @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import lombok.Data; + +/** + * 抽象类 ThingModelDataSpecs + * + * 用于表示物模型数据的通用类型,根据具体的 "dataType" 字段动态映射到对应的子类。 + * 提供多态支持,适用于不同类型的数据结构序列化和反序列化场景。 + * + * @author HUIHUI + */ +@Data +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "dataType", visible = true) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ThingModelNumericDataSpec.class, name = "int"), + @JsonSubTypes.Type(value = ThingModelNumericDataSpec.class, name = "float"), + @JsonSubTypes.Type(value = ThingModelNumericDataSpec.class, name = "double"), + @JsonSubTypes.Type(value = ThingModelDateOrTextDataSpecs.class, name = "text"), + @JsonSubTypes.Type(value = ThingModelDateOrTextDataSpecs.class, name = "date"), + @JsonSubTypes.Type(value = ThingModelBoolOrEnumDataSpecs.class, name = "bool"), + @JsonSubTypes.Type(value = ThingModelBoolOrEnumDataSpecs.class, name = "enum"), + @JsonSubTypes.Type(value = ThingModelArrayDataSpecs.class, name = "array"), + @JsonSubTypes.Type(value = ThingModelStructDataSpecs.class, name = "struct") +}) +public abstract class ThingModelDataSpecs { + + /** + * 数据类型 + */ + private String dataType; + +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDateOrTextDataSpecs.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDateOrTextDataSpecs.java new file mode 100644 index 0000000..8d5ddff --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDateOrTextDataSpecs.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 物模型数据类型为时间型或文本型的 DataSpec 定义 + * + * 数据类型,取值为 date 或 text。 + * + * @author HUIHUI + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段,从而避免重复。 +public class ThingModelDateOrTextDataSpecs extends ThingModelDataSpecs { + + /** + * 数据长度,单位为字节。取值不能超过 2048。 + * 当 dataType 为 text 时,需传入该参数。 + */ + private Long length; + /** + * 默认值,可选参数,用于存储默认值。 + */ + private String defaultValue; + +} + diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelNumericDataSpec.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelNumericDataSpec.java new file mode 100644 index 0000000..b65d606 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelNumericDataSpec.java @@ -0,0 +1,51 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 物模型数据类型为数值的 DataSpec 定义 + * + * 数据类型,取值为 int、float 或 double。 + * + * @author HUIHUI + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段,从而避免重复。 +public class ThingModelNumericDataSpec extends ThingModelDataSpecs { + + /** + * 最大值,需转为字符串类型。值必须与 dataType 类型一致。 + * 例如,当 dataType 为 int 时,取值为 "200",而不是 200。 + */ + private String max; + /** + * 最小值,需转为字符串类型。值必须与 dataType 类型一致。 + * 例如,当 dataType 为 int 时,取值为 "0",而不是 0。 + */ + private String min; + /** + * 步长,需转为字符串类型。值必须与 dataType 类型一致。 + * 例如,当 dataType 为 int 时,取值为 "10",而不是 10。 + */ + private String step; + /** + * 精度。当 dataType 为 float 或 double 时可选传入。 + */ + private String precise; + /** + * 默认值,可传入用于存储的默认值。 + */ + private String defaultValue; + /** + * 单位的符号。 + */ + private String unit; + /** + * 单位的名称。 + */ + private String unitName; + +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelStructDataSpecs.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelStructDataSpecs.java new file mode 100644 index 0000000..e0f5bb5 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelStructDataSpecs.java @@ -0,0 +1,58 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType; + +import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelAccessModeEnum; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +/** + * 物模型数据类型为 struct 的 DataSpec 定义 + * + * @author HUIHUI + */ +@Data +@EqualsAndHashCode(callSuper = true) +@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段,从而避免重复。 +public class ThingModelStructDataSpecs extends ThingModelDataSpecs { + + /** + * 属性标识符 + */ + private String identifier; + /** + * 属性名称 + */ + private String name; + /** + * 属性描述 + */ + private String description; + /** + * 云端可以对该属性进行的操作类型 + * 关联枚举 {@link IotProductThingModelAccessModeEnum} + */ + private String accessMode; + /** + * 是否是标准品类的必选服务。 + * + * - true:是 + * - false:否 + */ + private Boolean required; + /** + * struct 数据的数据类型 + */ + private String childDataType; + /** + * 数据类型(dataType)为非列表型(int、float、double、text、date、array)的数据规范存储在 dataSpecs 中 + */ + private ThingModelDataSpecs dataSpecs; + /** + * 数据类型(dataType)为列表型(enum、bool、struct)的数据规范存储在 dataSpecsList 中 + */ + private List dataSpecsList; + +} + diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelPageReqVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelPageReqVO.java new file mode 100644 index 0000000..a15ae98 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelPageReqVO.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@Schema(description = "管理后台 - IoT 产品物模型分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class IotProductThingModelPageReqVO extends PageParam { + + @Schema(description = "功能标识") + private String identifier; + + @Schema(description = "功能名称", example = "张三") + private String name; + + @Schema(description = "功能类型", example = "1") + @InEnum(IotProductThingModelTypeEnum.class) + private Integer type; + + @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "产品ID不能为空") + private Long productId; + +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelRespVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelRespVO.java new file mode 100644 index 0000000..8d9c370 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelRespVO.java @@ -0,0 +1,54 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo; + +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - IoT 产品物模型 Response VO") +@Data +@ExcelIgnoreUnannotated +public class IotProductThingModelRespVO { + + @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "21816") + @ExcelProperty("产品ID") + private Long id; + + @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) + private Long productId; + + @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("产品标识") + private String productKey; + + @Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED) + private String identifier; + + @Schema(description = "功能名称", requiredMode = Schema.RequiredMode.REQUIRED) + private String name; + + @Schema(description = "功能描述", requiredMode = Schema.RequiredMode.REQUIRED) + private String description; + + @Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED) + private Integer type; + + @Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED) + private ThingModelProperty property; + + @Schema(description = "服务", requiredMode = Schema.RequiredMode.REQUIRED) + private ThingModelEvent event; + + @Schema(description = "事件", requiredMode = Schema.RequiredMode.REQUIRED) + private ThingModelService service; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelSaveReqVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelSaveReqVO.java new file mode 100644 index 0000000..5f2be48 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotProductThingModelSaveReqVO.java @@ -0,0 +1,53 @@ +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo; + +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService; +import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Schema(description = "管理后台 - IoT 产品物模型新增/修改 Request VO") +@Data +public class IotProductThingModelSaveReqVO { + + @Schema(description = "编号", example = "1") + private Long id; + + @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "产品ID不能为空") + private Long productId; + + @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "产品标识不能为空") + private String productKey; + + @Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "功能标识不能为空") + private String identifier; + + @Schema(description = "功能名称", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "功能名称不能为空") + private String name; + + @Schema(description = "功能描述", requiredMode = Schema.RequiredMode.REQUIRED) + private String description; + + @Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "功能类型不能为空") + @InEnum(IotProductThingModelTypeEnum.class) + private Integer type; + + @Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED) + private ThingModelProperty property; + + @Schema(description = "服务", requiredMode = Schema.RequiredMode.REQUIRED) + private ThingModelService service; + + @Schema(description = "事件", requiredMode = Schema.RequiredMode.REQUIRED) + private ThingModelEvent event; + +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/IotProductThingModelController.http b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/IotProductThingModelController.http deleted file mode 100644 index 2343eed..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/IotProductThingModelController.http +++ /dev/null @@ -1,187 +0,0 @@ -### 请求 /iot/product-think-model/create 接口 => 成功 -POST {{baseUrl}}/iot/product-think-model/create -Content-Type: application/json -tenant-id: {{adminTenentId}} -Authorization: Bearer {{token}} - -{ - "productId": 12, - "productKey": "CJVS54fObwZJ9Qe5CJVS54fObwZJ9Qe5", - "identifier": "Temperature", - "name": "温度", - "description": "当前温度值", - "type": 1, - "property": { - "identifier": "Temperature", - "name": "温度", - "accessMode": "r", - "required": true, - "dataType": "int", - "dataSpecs": { - "dataType": "int", - "max": "200", - "min": "0", - "step": "10", - "defaultValue": "30", - "unit": "%", - "unitName": "百分比" - }, - "description": "当前温度值" - } -} - -### 请求 /iot/product-think-model/create 接口 => 成功 -POST {{baseUrl}}/iot/product-think-model/create -Content-Type: application/json -tenant-id: {{adminTenentId}} -Authorization: Bearer {{token}} - -{ - "productId": 12, - "productKey": "CJVS54fObwZJ9Qe5CJVS54fObwZJ9Qe5", - "identifier": "switch", - "name": "开关", - "description": "温度计开关", - "type": 1, - "property": { - "identifier": "switch", - "name": "开关", - "description": "温度计开关", - "accessMode": "rw", - "required": true, - "dataType": "bool", - "dataSpecsList": [ - { - "dataType": "bool", - "name": "关", - "value": 0 - }, - { - "dataType": "bool", - "name": "开", - "value": 1 - } - ] - } -} - -### 请求 /iot/product-think-model/create 接口 => 成功 -POST {{baseUrl}}/iot/product-think-model/create -Content-Type: application/json -tenant-id: {{adminTenentId}} -Authorization: Bearer {{token}} - -{ - "productId": 12, - "productKey": "CJVS54fObwZJ9Qe5CJVS54fObwZJ9Qe5", - "identifier": "argb", - "name": "温度计 argb 颜色", - "description": "温度计 argb 颜色", - "type": 1, - "property": { - "identifier": "argb", - "name": "温度计 argb 颜色", - "description": "温度计 argb 颜色", - "accessMode": "rw", - "required": true, - "dataType": "array", - "dataSpecs": { - "dataType": "array", - "size": 10, - "childDataType": "struct", - "dataSpecsList": [ - { - "identifier": "switch", - "name": "开关", - "description": "温度计开关", - "accessMode": "rw", - "required": true, - "dataType": "struct", - "childDataType": "bool", - "dataSpecsList": [ - { - "dataType": "bool", - "name": "关", - "value": 0 - }, - { - "dataType": "bool", - "name": "开", - "value": 1 - } - ] - }, - { - "identifier": "Temperature", - "name": "温度", - "accessMode": "r", - "required": true, - "dataType": "struct", - "childDataType": "int", - "dataSpecs": { - "dataType": "int", - "max": "200", - "min": "0", - "step": "10", - "defaultValue": "30", - "unit": "%", - "unitName": "百分比" - }, - "description": "当前温度值" - } - ] - } - } -} - -### 请求 /iot/product-think-model/update 接口 => 成功 -PUT {{baseUrl}}/iot/product-think-model/update -Content-Type: application/json -tenant-id: {{adminTenentId}} -Authorization: Bearer {{token}} - -{ - "id": 33, - "productId": 12, - "productKey": "CJVS54fObwZJ9Qe5CJVS54fObwZJ9Qe5", - "identifier": "switch", - "name": "开关", - "description": "温度计开关", - "type": 1, - "property": { - "identifier": "switch", - "name": "开关", - "description": "温度计开关", - "accessMode": "r", - "required": true, - "dataType": "bool", - "dataSpecsList": [ - { - "dataType": "bool", - "name": "关", - "value": 0 - }, - { - "dataType": "bool", - "name": "开", - "value": 1 - } - ] - } -} - -### 请求 /iot/product-think-model/delete 接口 => 成功 -DELETE {{baseUrl}}/iot/product-think-model/delete?id=36 -tenant-id: {{adminTenentId}} -Authorization: Bearer {{token}} - -### 请求 /iot/product-think-model/get 接口 => 成功 -GET {{baseUrl}}/iot/product-think-model/get?id=40 -tenant-id: {{adminTenentId}} -Authorization: Bearer {{token}} - - -### 请求 /iot/product-think-model/list-by-product-id 接口 => 成功 -GET {{baseUrl}}/iot/product-think-model/list-by-product-id?productId=1001 -tenant-id: {{adminTenentId}} -Authorization: Bearer {{token}} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/IotProductThinkModelController.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/IotProductThinkModelController.java deleted file mode 100644 index 03408b5..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/IotProductThinkModelController.java +++ /dev/null @@ -1,84 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo.IotProductThinkModelPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo.IotProductThinkModelRespVO; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo.IotProductThinkModelSaveReqVO; -import cn.iocoder.yudao.module.iot.convert.thinkmodel.IotProductThinkModelConvert; -import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodel.IotProductThinkModelDO; -import cn.iocoder.yudao.module.iot.service.thinkmodel.IotProductThinkModelService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.validation.Valid; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - IoT 产品物模型") -@RestController -@RequestMapping("/iot/product-think-model") -@Validated -public class IotProductThinkModelController { - - @Resource - private IotProductThinkModelService thinkModelFunctionService; - - @PostMapping("/create") - @Operation(summary = "创建产品物模型") - @PreAuthorize("@ss.hasPermission('iot:product-think-model:create')") - public CommonResult createProductThinkModel(@Valid @RequestBody IotProductThinkModelSaveReqVO createReqVO) { - return success(thinkModelFunctionService.createProductThinkModel(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新产品物模型") - @PreAuthorize("@ss.hasPermission('iot:product-think-model:update')") - public CommonResult updateProductThinkModel(@Valid @RequestBody IotProductThinkModelSaveReqVO updateReqVO) { - thinkModelFunctionService.updateProductThinkModel(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除产品物模型") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('iot:product-think-model:delete')") - public CommonResult deleteProductThinkModel(@RequestParam("id") Long id) { - thinkModelFunctionService.deleteProductThinkModel(id); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得产品物模型") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('iot:product-think-model:query')") - public CommonResult getProductThinkModel(@RequestParam("id") Long id) { - IotProductThinkModelDO function = thinkModelFunctionService.getProductThinkModel(id); - return success(IotProductThinkModelConvert.INSTANCE.convert(function)); - } - - @GetMapping("/list-by-product-id") - @Operation(summary = "获得产品物模型") - @Parameter(name = "productId", description = "产品ID", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('iot:product-think-model:query')") - public CommonResult> getProductThinkModelListByProductId(@RequestParam("productId") Long productId) { - List list = thinkModelFunctionService.getProductThinkModelListByProductId(productId); - return success(IotProductThinkModelConvert.INSTANCE.convertList(list)); - } - - @GetMapping("/page") - @Operation(summary = "获得产品物模型分页") - @PreAuthorize("@ss.hasPermission('iot:product-think-model:query')") - public CommonResult> getProductThinkModelPage(@Valid IotProductThinkModelPageReqVO pageReqVO) { - PageResult pageResult = thinkModelFunctionService.getProductThinkModelPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, IotProductThinkModelRespVO.class)); - } - -} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelEvent.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelEvent.java deleted file mode 100644 index 7d16aa5..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelEvent.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model; - -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType.ThinkModelArgument; -import lombok.Data; -import java.util.List; - -@Data -public class ThinkModelEvent { - - /** - * 事件标识符 - */ - private String identifier; - /** - * 事件名称 - */ - private String name; - /** - * 事件描述 - */ - private String description; - - /** - * 事件类型 - * - * "info"、"alert"、"error" - */ - private String type; - private List outputData; - private String method; - -} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelProperty.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelProperty.java deleted file mode 100644 index a4d2e98..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelProperty.java +++ /dev/null @@ -1,56 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model; - -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType.ThinkModelDataSpecs; -import cn.iocoder.yudao.module.iot.enums.thinkmodel.IotProductThinkModelAccessModeEnum; -import lombok.Data; - -import java.util.List; - -/** - * 物模型中的属性 - * - * dataSpecs 和 dataSpecsList 之中必须传入且只能传入一个 - * - * @author HUIHUI - */ -@Data -public class ThinkModelProperty { - - /** - * 属性标识符 - */ - private String identifier; - /** - * 属性名称 - */ - private String name; - /** - * 属性描述 - */ - private String description; - /** - * 云端可以对该属性进行的操作类型 - * 关联枚举 {@link IotProductThinkModelAccessModeEnum} - */ - private String accessMode; - /** - * 是否是标准品类的必选服务。 - * - * - true:是 - * - false:否 - */ - private Boolean required; - /** - * 数据类型,与 dataSpecs 的 dataType 保持一致 - */ - private String dataType; - /** - * 数据类型(dataType)为非列表型(int、float、double、text、date、array)的数据规范存储在 dataSpecs 中 - */ - private ThinkModelDataSpecs dataSpecs; - /** - * 数据类型(dataType)为列表型(enum、bool、struct)的数据规范存储在 dataSpecsList 中 - */ - private List dataSpecsList; - -} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelRespVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelRespVO.java deleted file mode 100644 index 7eb06ce..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelRespVO.java +++ /dev/null @@ -1,50 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model; - -import lombok.*; - -import java.util.List; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@ToString -public class ThinkModelRespVO { - - /** - * 产品编号 - */ - private Long id; - - /** - * 产品标识 - */ - private String productKey; - - /** - * 物模型 - */ - private Model model; - - /** - * 物模型 - */ - @Data - public static class Model { - - /** - * 属性列表 - */ - private List properties; - - /** - * 服务列表 - */ - private List services; - - /** - * 事件列表 - */ - private List events; - } -} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelService.java deleted file mode 100644 index 851df36..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/ThinkModelService.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model; - -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType.ThinkModelArgument; -import lombok.Data; -import java.util.List; - -@Data -public class ThinkModelService { - - /** - * 服务标识符 - */ - private String identifier; - /** - * 服务名称 - */ - private String name; - /** - * 服务描述 - */ - private String description; - - /** - * 调用类型 - * - * "sync"、"async" - */ - private String callType; - private List inputData; - private List outputData; - private String method; - -} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelArgument.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelArgument.java deleted file mode 100644 index 7b293ca..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelArgument.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType; - -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelProperty; -import lombok.Data; - -@Data -public class ThinkModelArgument { - - public static final String DIRECTION_INPUT = "input"; - public static final String DIRECTION_OUTPUT = "output"; - - private String identifier; - private String name; - /** - * 物模型中的属性 - */ - private ThinkModelProperty property; - /** - * 用于区分输入或输出参数,"input" 或 "output" - */ - private String direction; - private String description; - -} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelArrayDataSpecs.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelArrayDataSpecs.java deleted file mode 100644 index ebc69f6..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelArrayDataSpecs.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -// TODO @puhui999:thingmodel 哈 = = 之前我写错单词了 -/** - * 物模型数据类型为数组的 DataSpec 定义 - * - * @author HUIHUI - */ -@Data -@EqualsAndHashCode(callSuper = true) -@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段,从而避免重复。 -public class ThinkModelArrayDataSpecs extends ThinkModelDataSpecs { - - /** - * 数组中的元素个数。 - */ - private Integer size; - /** - * 数组中的元素的数据类型。可选值:struct、int、float、double 或 text。 - */ - private String childDataType; - /** - * 数据类型(childDataType)为列表型 struct 的数据规范存储在 dataSpecsList 中。 - * 此时 struct 取值范围为:int、float、double、text、date、enum、bool - */ - private List dataSpecsList; - -} - diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelBoolOrEnumDataSpecs.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelBoolOrEnumDataSpecs.java deleted file mode 100644 index 8a44b58..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelBoolOrEnumDataSpecs.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * 物模型数据类型为布尔型或枚举型的 DataSpec 定义 - * - * 数据类型,取值为 bool 或 enum。 - * - * @author HUIHUI - */ -@Data -@EqualsAndHashCode(callSuper = true) -@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段,从而避免重复。 -public class ThinkModelBoolOrEnumDataSpecs extends ThinkModelDataSpecs { - - /** - * 枚举项的名称。 - * 可包含中文、大小写英文字母、数字、下划线(_)和短划线(-)。 - * 必须以中文、英文字母或数字开头,长度不超过 20 个字符。 - */ - private String name; - /** - * 枚举值。 - */ - private Integer value; - -} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelDataSpecs.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelDataSpecs.java deleted file mode 100644 index 2d01747..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelDataSpecs.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType; - -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import lombok.Data; - -/** - * 抽象类 ThinkModelDataSpecs - * - * 用于表示物模型数据的通用类型,根据具体的 "dataType" 字段动态映射到对应的子类。 - * 提供多态支持,适用于不同类型的数据结构序列化和反序列化场景。 - * - * @author HUIHUI - */ -@Data -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "dataType", visible = true) -@JsonSubTypes({ - @JsonSubTypes.Type(value = ThinkModelNumericDataSpec.class, name = "int"), - @JsonSubTypes.Type(value = ThinkModelNumericDataSpec.class, name = "float"), - @JsonSubTypes.Type(value = ThinkModelNumericDataSpec.class, name = "double"), - @JsonSubTypes.Type(value = ThinkModelDateOrTextDataSpecs.class, name = "text"), - @JsonSubTypes.Type(value = ThinkModelDateOrTextDataSpecs.class, name = "date"), - @JsonSubTypes.Type(value = ThinkModelBoolOrEnumDataSpecs.class, name = "bool"), - @JsonSubTypes.Type(value = ThinkModelBoolOrEnumDataSpecs.class, name = "enum"), - @JsonSubTypes.Type(value = ThinkModelArrayDataSpecs.class, name = "array"), - @JsonSubTypes.Type(value = ThinkModelStructDataSpecs.class, name = "struct") -}) -public abstract class ThinkModelDataSpecs { - - /** - * 数据类型 - */ - private String dataType; - -} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelDateOrTextDataSpecs.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelDateOrTextDataSpecs.java deleted file mode 100644 index 640316b..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelDateOrTextDataSpecs.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * 物模型数据类型为时间型或文本型的 DataSpec 定义 - * - * 数据类型,取值为 date 或 text。 - * - * @author HUIHUI - */ -@Data -@EqualsAndHashCode(callSuper = true) -@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段,从而避免重复。 -public class ThinkModelDateOrTextDataSpecs extends ThinkModelDataSpecs { - - /** - * 数据长度,单位为字节。取值不能超过 2048。 - * 当 dataType 为 text 时,需传入该参数。 - */ - private Long length; - /** - * 默认值,可选参数,用于存储默认值。 - */ - private String defaultValue; - -} - diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelNumericDataSpec.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelNumericDataSpec.java deleted file mode 100644 index 714b57b..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelNumericDataSpec.java +++ /dev/null @@ -1,51 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * 物模型数据类型为数值的 DataSpec 定义 - * - * 数据类型,取值为 int、float 或 double。 - * - * @author HUIHUI - */ -@Data -@EqualsAndHashCode(callSuper = true) -@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段,从而避免重复。 -public class ThinkModelNumericDataSpec extends ThinkModelDataSpecs { - - /** - * 最大值,需转为字符串类型。值必须与 dataType 类型一致。 - * 例如,当 dataType 为 int 时,取值为 "200",而不是 200。 - */ - private String max; - /** - * 最小值,需转为字符串类型。值必须与 dataType 类型一致。 - * 例如,当 dataType 为 int 时,取值为 "0",而不是 0。 - */ - private String min; - /** - * 步长,需转为字符串类型。值必须与 dataType 类型一致。 - * 例如,当 dataType 为 int 时,取值为 "10",而不是 10。 - */ - private String step; - /** - * 精度。当 dataType 为 float 或 double 时可选传入。 - */ - private String precise; - /** - * 默认值,可传入用于存储的默认值。 - */ - private String defaultValue; - /** - * 单位的符号。 - */ - private String unit; - /** - * 单位的名称。 - */ - private String unitName; - -} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelStructDataSpecs.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelStructDataSpecs.java deleted file mode 100644 index 8cbb9af..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/model/dataType/ThinkModelStructDataSpecs.java +++ /dev/null @@ -1,58 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType; - -import cn.iocoder.yudao.module.iot.enums.thinkmodel.IotProductThinkModelAccessModeEnum; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -/** - * 物模型数据类型为 struct 的 DataSpec 定义 - * - * @author HUIHUI - */ -@Data -@EqualsAndHashCode(callSuper = true) -@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段,从而避免重复。 -public class ThinkModelStructDataSpecs extends ThinkModelDataSpecs { - - /** - * 属性标识符 - */ - private String identifier; - /** - * 属性名称 - */ - private String name; - /** - * 属性描述 - */ - private String description; - /** - * 云端可以对该属性进行的操作类型 - * 关联枚举 {@link IotProductThinkModelAccessModeEnum} - */ - private String accessMode; - /** - * 是否是标准品类的必选服务。 - * - * - true:是 - * - false:否 - */ - private Boolean required; - /** - * struct 数据的数据类型 - */ - private String childDataType; - /** - * 数据类型(dataType)为非列表型(int、float、double、text、date、array)的数据规范存储在 dataSpecs 中 - */ - private ThinkModelDataSpecs dataSpecs; - /** - * 数据类型(dataType)为列表型(enum、bool、struct)的数据规范存储在 dataSpecsList 中 - */ - private List dataSpecsList; - -} - diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelPageReqVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelPageReqVO.java deleted file mode 100644 index afb4122..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelPageReqVO.java +++ /dev/null @@ -1,32 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.enums.thinkmodel.IotProductThinkModelTypeEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@Schema(description = "管理后台 - IoT 产品物模型分页 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class IotProductThinkModelPageReqVO extends PageParam { - - @Schema(description = "功能标识") - private String identifier; - - @Schema(description = "功能名称", example = "张三") - private String name; - - @Schema(description = "功能类型", example = "1") - @InEnum(IotProductThinkModelTypeEnum.class) - private Integer type; - - @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "产品ID不能为空") - private Long productId; - -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelRespVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelRespVO.java deleted file mode 100644 index a79cd26..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelRespVO.java +++ /dev/null @@ -1,54 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo; - -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelEvent; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelProperty; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelService; -import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; -import com.alibaba.excel.annotation.ExcelProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - IoT 产品物模型 Response VO") -@Data -@ExcelIgnoreUnannotated -public class IotProductThinkModelRespVO { - - @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "21816") - @ExcelProperty("产品ID") - private Long id; - - @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) - private Long productId; - - @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("产品标识") - private String productKey; - - @Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED) - private String identifier; - - @Schema(description = "功能名称", requiredMode = Schema.RequiredMode.REQUIRED) - private String name; - - @Schema(description = "功能描述", requiredMode = Schema.RequiredMode.REQUIRED) - private String description; - - @Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED) - private Integer type; - - @Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED) - private ThinkModelProperty property; - - @Schema(description = "服务", requiredMode = Schema.RequiredMode.REQUIRED) - private ThinkModelEvent event; - - @Schema(description = "事件", requiredMode = Schema.RequiredMode.REQUIRED) - private ThinkModelService service; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelSaveReqVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelSaveReqVO.java deleted file mode 100644 index 3cce604..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodel/vo/IotProductThinkModelSaveReqVO.java +++ /dev/null @@ -1,53 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelEvent; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelProperty; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelService; -import cn.iocoder.yudao.module.iot.enums.thinkmodel.IotProductThinkModelTypeEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -@Schema(description = "管理后台 - IoT 产品物模型新增/修改 Request VO") -@Data -public class IotProductThinkModelSaveReqVO { - - @Schema(description = "编号", example = "1") - private Long id; - - @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "产品ID不能为空") - private Long productId; - - @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "产品标识不能为空") - private String productKey; - - @Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "功能标识不能为空") - private String identifier; - - @Schema(description = "功能名称", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "功能名称不能为空") - private String name; - - @Schema(description = "功能描述", requiredMode = Schema.RequiredMode.REQUIRED) - private String description; - - @Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "功能类型不能为空") - @InEnum(IotProductThinkModelTypeEnum.class) - private Integer type; - - @Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED) - private ThinkModelProperty property; - - @Schema(description = "服务", requiredMode = Schema.RequiredMode.REQUIRED) - private ThinkModelService service; - - @Schema(description = "事件", requiredMode = Schema.RequiredMode.REQUIRED) - private ThinkModelEvent event; - -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/device/IotDeviceDataConvert.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/device/IotDeviceDataConvert.java index 22d5dda..d8f6e47 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/device/IotDeviceDataConvert.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/device/IotDeviceDataConvert.java @@ -12,7 +12,7 @@ public interface IotDeviceDataConvert { // default List convert(Map deviceData, IotDeviceDO device){ // List list = new ArrayList<>(); // deviceData.forEach((identifier, value) -> { -//// ThinkModelProperty property = ThinkModelService.INSTANCE.getProperty(device.getProductId(), identifier); +//// ThingModelProperty property = ThingModelService.INSTANCE.getProperty(device.getProductId(), identifier); //// if (Objects.isNull(property)) { //// return; //// } diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thingmodel/IotProductThingModelConvert.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thingmodel/IotProductThingModelConvert.java new file mode 100644 index 0000000..cb10c62 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thingmodel/IotProductThingModelConvert.java @@ -0,0 +1,62 @@ +package cn.iocoder.yudao.module.iot.convert.thingmodel; + +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotProductThingModelRespVO; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotProductThingModelSaveReqVO; +import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotProductThingModelDO; +import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.factory.Mappers; + +import java.util.List; +import java.util.Objects; + +@Mapper +public interface IotProductThingModelConvert { + + IotProductThingModelConvert INSTANCE = Mappers.getMapper(IotProductThingModelConvert.class); + + // 将 SaveReqVO 转换为 DO + @Mapping(target = "property", expression = "java(convertToProperty(bean))") + @Mapping(target = "event", expression = "java(convertToEvent(bean))") + @Mapping(target = "service", expression = "java(convertToService(bean))") + IotProductThingModelDO convert(IotProductThingModelSaveReqVO bean); + + // 将 DO 转换为 RespVO + @Mapping(target = "property", source = "property") + @Mapping(target = "event", source = "event") + @Mapping(target = "service", source = "service") + IotProductThingModelRespVO convert(IotProductThingModelDO bean); + + // 批量转换 + List convertList(List list); + + @Named("convertToProperty") + default ThingModelProperty convertToProperty(IotProductThingModelSaveReqVO bean) { + if (Objects.equals(bean.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) { + return bean.getProperty(); + } + return null; + } + + @Named("convertToEvent") + default ThingModelEvent convertToEvent(IotProductThingModelSaveReqVO bean) { + if (Objects.equals(bean.getType(), IotProductThingModelTypeEnum.EVENT.getType())) { + return bean.getEvent(); + } + return null; + } + + @Named("convertToService") + default ThingModelService convertToService(IotProductThingModelSaveReqVO bean) { + if (Objects.equals(bean.getType(), IotProductThingModelTypeEnum.SERVICE.getType())) { + return bean.getService(); + } + return null; + } + +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thinkmodel/IotProductThinkModelConvert.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thinkmodel/IotProductThinkModelConvert.java deleted file mode 100644 index bb5c22b..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thinkmodel/IotProductThinkModelConvert.java +++ /dev/null @@ -1,62 +0,0 @@ -package cn.iocoder.yudao.module.iot.convert.thinkmodel; - -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelEvent; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelProperty; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelService; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo.IotProductThinkModelRespVO; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo.IotProductThinkModelSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodel.IotProductThinkModelDO; -import cn.iocoder.yudao.module.iot.enums.thinkmodel.IotProductThinkModelTypeEnum; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.Named; -import org.mapstruct.factory.Mappers; - -import java.util.List; -import java.util.Objects; - -@Mapper -public interface IotProductThinkModelConvert { - - IotProductThinkModelConvert INSTANCE = Mappers.getMapper(IotProductThinkModelConvert.class); - - // 将 SaveReqVO 转换为 DO - @Mapping(target = "property", expression = "java(convertToProperty(bean))") - @Mapping(target = "event", expression = "java(convertToEvent(bean))") - @Mapping(target = "service", expression = "java(convertToService(bean))") - IotProductThinkModelDO convert(IotProductThinkModelSaveReqVO bean); - - // 将 DO 转换为 RespVO - @Mapping(target = "property", source = "property") - @Mapping(target = "event", source = "event") - @Mapping(target = "service", source = "service") - IotProductThinkModelRespVO convert(IotProductThinkModelDO bean); - - // 批量转换 - List convertList(List list); - - @Named("convertToProperty") - default ThinkModelProperty convertToProperty(IotProductThinkModelSaveReqVO bean) { - if (Objects.equals(bean.getType(), IotProductThinkModelTypeEnum.PROPERTY.getType())) { - return bean.getProperty(); - } - return null; - } - - @Named("convertToEvent") - default ThinkModelEvent convertToEvent(IotProductThinkModelSaveReqVO bean) { - if (Objects.equals(bean.getType(), IotProductThinkModelTypeEnum.EVENT.getType())) { - return bean.getEvent(); - } - return null; - } - - @Named("convertToService") - default ThinkModelService convertToService(IotProductThinkModelSaveReqVO bean) { - if (Objects.equals(bean.getType(), IotProductThinkModelTypeEnum.SERVICE.getType())) { - return bean.getService(); - } - return null; - } - -} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceDataDO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceDataDO.java index c3ed486..ab1934e 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceDataDO.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceDataDO.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.iot.dal.dataobject.device; import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodel.IotProductThinkModelDO; +import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotProductThingModelDO; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -30,9 +30,9 @@ public class IotDeviceDataDO { /** * 物模型编号 *

- * 关联 {@link IotProductThinkModelDO#getId()} + * 关联 {@link IotProductThingModelDO#getId()} */ - private Long thinkModelId; + private Long thingModelId; /** * 产品标识 @@ -51,21 +51,21 @@ public class IotDeviceDataDO { /** * 属性标识符 *

- * 关联 {@link IotProductThinkModelDO#getIdentifier()} + * 关联 {@link IotProductThingModelDO#getIdentifier()} */ private String identifier; /** * 属性名称 *

- * 关联 {@link IotProductThinkModelDO#getName()} + * 关联 {@link IotProductThingModelDO#getName()} */ private String name; /** * 数据类型 *

- * 关联 {@link IotProductThinkModelDO#getProperty()#getDataType()} + * 关联 {@link IotProductThingModelDO#getProperty()#getDataType()} */ private String dataType; diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/FieldParser.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/FieldParser.java index 81bfed0..637b222 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/FieldParser.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/FieldParser.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.iot.dal.dataobject.tdengine; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelProperty; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelRespVO; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelRespVO; import java.util.HashMap; import java.util.List; @@ -33,7 +33,7 @@ public class FieldParser { * @param property 物模型属性 * @return TdField对象 */ - public static TdFieldDO parse(ThinkModelProperty property) { + public static TdFieldDO parse(ThingModelProperty property) { String fieldName = property.getIdentifier().toLowerCase(); // 将物模型字段类型映射为td字段类型 @@ -53,7 +53,7 @@ public class FieldParser { * @param thingModel 物模型响应对象 * @return 字段列表 */ - public static List parse(ThinkModelRespVO thingModel) { + public static List parse(ThingModelRespVO thingModel) { return thingModel.getModel().getProperties().stream() .map(FieldParser::parse) .collect(Collectors.toList()); diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThingModelMessage.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThingModelMessage.java new file mode 100644 index 0000000..d5009dc --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThingModelMessage.java @@ -0,0 +1,70 @@ +package cn.iocoder.yudao.module.iot.dal.dataobject.tdengine; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.HashMap; +import java.util.Map; + +/** + * 物模型消息 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ThingModelMessage { + + /** + * 消息ID + */ + private String id; + + /** + * 扩展功能的参数 + */ + private Object sys; + + /** + * 请求方法 例如:thing.event.property.post + */ + private String method; + + /** + * 请求参数 + */ + private Object params; + + /** + * 属性上报时间戳 + */ + private Long time; + + /** + * 设备信息 + */ + private String productKey; + + /** + * 设备名称 + */ + private String deviceName; + + /** + * 设备 key + */ + private String deviceKey; + + /** + * 转换为 Map 类型 + */ + public Map dataToMap() { + Map mapData = new HashMap<>(); + if (params instanceof Map) { + ((Map) params).forEach((key, value) -> mapData.put(key.toString(), value)); + } + return mapData; + } +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThinkModelMessage.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThinkModelMessage.java deleted file mode 100644 index 22cf9e2..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThinkModelMessage.java +++ /dev/null @@ -1,70 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.tdengine; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.HashMap; -import java.util.Map; - -/** - * 物模型消息 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -public class ThinkModelMessage { - - /** - * 消息ID - */ - private String id; - - /** - * 扩展功能的参数 - */ - private Object sys; - - /** - * 请求方法 例如:thing.event.property.post - */ - private String method; - - /** - * 请求参数 - */ - private Object params; - - /** - * 属性上报时间戳 - */ - private Long time; - - /** - * 设备信息 - */ - private String productKey; - - /** - * 设备名称 - */ - private String deviceName; - - /** - * 设备 key - */ - private String deviceKey; - - /** - * 转换为 Map 类型 - */ - public Map dataToMap() { - Map mapData = new HashMap<>(); - if (params instanceof Map) { - ((Map) params).forEach((key, value) -> mapData.put(key.toString(), value)); - } - return mapData; - } -} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thingmodel/IotProductThingModelDO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thingmodel/IotProductThingModelDO.java new file mode 100644 index 0000000..3d9e5e5 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thingmodel/IotProductThingModelDO.java @@ -0,0 +1,91 @@ +package cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService; +import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; +import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * IoT 产品物模型功能 DO + *

+ * 每个 {@link IotProductDO} 和 {@link IotProductThingModelDO} 是“一对多”的关系,它的每个属性、事件、服务都对应一条记录 + * + * @author 芋道源码 + */ +@TableName(value = "iot_product_thing_model", autoResultMap = true) +@KeySequence("iot_product_thing_model_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class IotProductThingModelDO extends BaseDO { + + /** + * 物模型功能编号 + */ + @TableId + private Long id; + + /** + * 功能标识 + */ + private String identifier; + /** + * 功能名称 + */ + private String name; + /** + * 功能描述 + */ + private String description; + + /** + * 产品标识 + *

+ * 关联 {@link IotProductDO#getId()} + */ + private Long productId; + /** + * 产品标识 + *

+ * 关联 {@link IotProductDO#getProductKey()} + */ + private String productKey; + + /** + * 功能类型 + *

+ * 枚举 {@link IotProductThingModelTypeEnum} + */ + private Integer type; + + /** + * 属性 + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private ThingModelProperty property; + + /** + * 事件 + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private ThingModelEvent event; + + /** + * 服务 + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private ThingModelService service; + +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thinkmodel/IotProductThinkModelDO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thinkmodel/IotProductThinkModelDO.java deleted file mode 100644 index 76b2a63..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thinkmodel/IotProductThinkModelDO.java +++ /dev/null @@ -1,91 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodel; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelEvent; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelProperty; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelService; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.enums.thinkmodel.IotProductThinkModelTypeEnum; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * IoT 产品物模型功能 DO - *

- * 每个 {@link IotProductDO} 和 {@link IotProductThinkModelDO} 是“一对多”的关系,它的每个属性、事件、服务都对应一条记录 - * - * @author 芋道源码 - */ -@TableName(value = "iot_product_think_model", autoResultMap = true) -@KeySequence("iot_product_think_model_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotProductThinkModelDO extends BaseDO { - - /** - * 物模型功能编号 - */ - @TableId - private Long id; - - /** - * 功能标识 - */ - private String identifier; - /** - * 功能名称 - */ - private String name; - /** - * 功能描述 - */ - private String description; - - /** - * 产品标识 - *

- * 关联 {@link IotProductDO#getId()} - */ - private Long productId; - /** - * 产品标识 - *

- * 关联 {@link IotProductDO#getProductKey()} - */ - private String productKey; - - /** - * 功能类型 - *

- * 枚举 {@link IotProductThinkModelTypeEnum} - */ - private Integer type; - - /** - * 属性 - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private ThinkModelProperty property; - - /** - * 事件 - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private ThinkModelEvent event; - - /** - * 服务 - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private ThinkModelService service; - -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thingmodel/IotProductThingModelMapper.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thingmodel/IotProductThingModelMapper.java new file mode 100644 index 0000000..175f66f --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thingmodel/IotProductThingModelMapper.java @@ -0,0 +1,62 @@ +package cn.iocoder.yudao.module.iot.dal.mysql.thingmodel; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotProductThingModelPageReqVO; +import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotProductThingModelDO; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * IoT 产品物模型 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface IotProductThingModelMapper extends BaseMapperX { + + default PageResult selectPage(IotProductThingModelPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(IotProductThingModelDO::getIdentifier, reqVO.getIdentifier()) + .likeIfPresent(IotProductThingModelDO::getName, reqVO.getName()) + .eqIfPresent(IotProductThingModelDO::getType, reqVO.getType()) + .eqIfPresent(IotProductThingModelDO::getProductId, reqVO.getProductId()) + .notIn(IotProductThingModelDO::getIdentifier, "get", "set", "post") + .orderByDesc(IotProductThingModelDO::getId)); + } + + default IotProductThingModelDO selectByProductIdAndIdentifier(Long productId, String identifier) { + return selectOne(IotProductThingModelDO::getProductId, productId, + IotProductThingModelDO::getIdentifier, identifier); + } + + default List selectListByProductId(Long productId) { + return selectList(IotProductThingModelDO::getProductId, productId); + } + + default List selectListByProductIdAndType(Long productId, Integer type) { + return selectList(IotProductThingModelDO::getProductId, productId, + IotProductThingModelDO::getType, type); + } + + default List selectListByProductIdAndIdentifiersAndTypes(Long productId, + List identifiers, + List types) { + return selectList(new LambdaQueryWrapperX() + .eq(IotProductThingModelDO::getProductId, productId) + .in(IotProductThingModelDO::getIdentifier, identifiers) + .in(IotProductThingModelDO::getType, types)); + } + + default IotProductThingModelDO selectByProductIdAndName(Long productId, String name) { + return selectOne(IotProductThingModelDO::getProductId, productId, + IotProductThingModelDO::getName, name); + } + + default List selectListByProductKey(String productKey) { + return selectList(IotProductThingModelDO::getProductKey, productKey); + } + +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thinkmodel/IotProductThinkModelMapper.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thinkmodel/IotProductThinkModelMapper.java deleted file mode 100644 index de76aa6..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thinkmodel/IotProductThinkModelMapper.java +++ /dev/null @@ -1,62 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.thinkmodel; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo.IotProductThinkModelPageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodel.IotProductThinkModelDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -/** - * IoT 产品物模型 Mapper - * - * @author 芋道源码 - */ -@Mapper -public interface IotProductThinkModelMapper extends BaseMapperX { - - default PageResult selectPage(IotProductThinkModelPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(IotProductThinkModelDO::getIdentifier, reqVO.getIdentifier()) - .likeIfPresent(IotProductThinkModelDO::getName, reqVO.getName()) - .eqIfPresent(IotProductThinkModelDO::getType, reqVO.getType()) - .eqIfPresent(IotProductThinkModelDO::getProductId, reqVO.getProductId()) - .notIn(IotProductThinkModelDO::getIdentifier, "get", "set", "post") - .orderByDesc(IotProductThinkModelDO::getId)); - } - - default IotProductThinkModelDO selectByProductIdAndIdentifier(Long productId, String identifier) { - return selectOne(IotProductThinkModelDO::getProductId, productId, - IotProductThinkModelDO::getIdentifier, identifier); - } - - default List selectListByProductId(Long productId) { - return selectList(IotProductThinkModelDO::getProductId, productId); - } - - default List selectListByProductIdAndType(Long productId, Integer type) { - return selectList(IotProductThinkModelDO::getProductId, productId, - IotProductThinkModelDO::getType, type); - } - - default List selectListByProductIdAndIdentifiersAndTypes(Long productId, - List identifiers, - List types) { - return selectList(new LambdaQueryWrapperX() - .eq(IotProductThinkModelDO::getProductId, productId) - .in(IotProductThinkModelDO::getIdentifier, identifiers) - .in(IotProductThinkModelDO::getType, types)); - } - - default IotProductThinkModelDO selectByProductIdAndName(Long productId, String name) { - return selectOne(IotProductThinkModelDO::getProductId, productId, - IotProductThinkModelDO::getName, name); - } - - default List selectListByProductKey(String productKey) { - return selectList(IotProductThinkModelDO::getProductKey, productKey); - } - -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceDataServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceDataServiceImpl.java index 7178082..4cb39c0 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceDataServiceImpl.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceDataServiceImpl.java @@ -8,14 +8,14 @@ import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDevi import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO; import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectVisualDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThinkModelMessage; -import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodel.IotProductThinkModelDO; +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage; +import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotProductThingModelDO; import cn.iocoder.yudao.module.iot.dal.redis.deviceData.DeviceDataRedisDAO; import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper; import cn.iocoder.yudao.module.iot.enums.IotConstants; -import cn.iocoder.yudao.module.iot.enums.thinkmodel.IotProductThinkModelTypeEnum; -import cn.iocoder.yudao.module.iot.service.tdengine.IotThinkModelMessageService; -import cn.iocoder.yudao.module.iot.service.thinkmodel.IotProductThinkModelService; +import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum; +import cn.iocoder.yudao.module.iot.service.tdengine.IotThingModelMessageService; +import cn.iocoder.yudao.module.iot.service.thingmodel.IotProductThingModelService; import jakarta.annotation.Resource; import jakarta.validation.Valid; import lombok.extern.slf4j.Slf4j; @@ -40,9 +40,9 @@ public class IotDeviceDataServiceImpl implements IotDeviceDataService { @Resource private IotDeviceService deviceService; @Resource - private IotThinkModelMessageService thingModelMessageService; + private IotThingModelMessageService thingModelMessageService; @Resource - private IotProductThinkModelService thinkModelFunctionService; + private IotProductThingModelService thingModelService; @Resource private TdEngineDMLMapper tdEngineDMLMapper; @@ -56,7 +56,7 @@ public class IotDeviceDataServiceImpl implements IotDeviceDataService { // 2. 解析消息,保存数据 JSONObject jsonObject = new JSONObject(message); log.info("[saveDeviceData][productKey({}) deviceName({}) data({})]", productKey, deviceName, jsonObject); - ThinkModelMessage thingModelMessage = ThinkModelMessage.builder() + ThingModelMessage thingModelMessage = ThingModelMessage.builder() .id(jsonObject.getStr("id")) .sys(jsonObject.get("sys")) .method(jsonObject.getStr("method")) @@ -66,7 +66,7 @@ public class IotDeviceDataServiceImpl implements IotDeviceDataService { .deviceName(deviceName) .deviceKey(device.getDeviceKey()) .build(); - thingModelMessageService.saveThinkModelMessage(device, thingModelMessage); + thingModelMessageService.saveThingModelMessage(device, thingModelMessage); } @Override @@ -75,31 +75,31 @@ public class IotDeviceDataServiceImpl implements IotDeviceDataService { // 1. 获取设备信息 IotDeviceDO device = deviceService.getDevice(deviceDataReqVO.getDeviceId()); // 2. 获取设备属性最新数据 - List thinkModelList = thinkModelFunctionService.getProductThinkModelListByProductKey(device.getProductKey()); - thinkModelList = filterList(thinkModelList, thinkModel -> IotProductThinkModelTypeEnum.PROPERTY.getType() - .equals(thinkModel.getType())); + List thingModelList = thingModelService.getProductThingModelListByProductKey(device.getProductKey()); + thingModelList = filterList(thingModelList, thingModel -> IotProductThingModelTypeEnum.PROPERTY.getType() + .equals(thingModel.getType())); // 3. 过滤标识符和属性名称 if (deviceDataReqVO.getIdentifier() != null) { - thinkModelList = filterList(thinkModelList, thinkModel -> thinkModel.getIdentifier() + thingModelList = filterList(thingModelList, thingModel -> thingModel.getIdentifier() .toLowerCase().contains(deviceDataReqVO.getIdentifier().toLowerCase())); } if (deviceDataReqVO.getName() != null) { - thinkModelList = filterList(thinkModelList, thinkModel -> thinkModel.getName() + thingModelList = filterList(thingModelList, thingModel -> thingModel.getName() .toLowerCase().contains(deviceDataReqVO.getName().toLowerCase())); } // 4. 获取设备属性最新数据 - thinkModelList.forEach(thinkModel -> { - IotDeviceDataDO deviceData = deviceDataRedisDAO.get(device.getProductKey(), device.getDeviceName(), thinkModel.getIdentifier()); + thingModelList.forEach(thingModel -> { + IotDeviceDataDO deviceData = deviceDataRedisDAO.get(device.getProductKey(), device.getDeviceName(), thingModel.getIdentifier()); if (deviceData == null) { deviceData = new IotDeviceDataDO(); deviceData.setProductKey(device.getProductKey()); deviceData.setDeviceName(device.getDeviceName()); - deviceData.setIdentifier(thinkModel.getIdentifier()); + deviceData.setIdentifier(thingModel.getIdentifier()); deviceData.setDeviceId(deviceDataReqVO.getDeviceId()); - deviceData.setThinkModelId(thinkModel.getId()); - deviceData.setName(thinkModel.getName()); - deviceData.setDataType(thinkModel.getProperty().getDataType()); + deviceData.setThingModelId(thingModel.getId()); + deviceData.setName(thingModel.getName()); + deviceData.setDataType(thingModel.getProperty().getDataType()); } list.add(deviceData); }); diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java index b26c2c1..4fd6cff 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProduc import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; import cn.iocoder.yudao.module.iot.dal.mysql.product.IotProductMapper; import cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum; -import cn.iocoder.yudao.module.iot.service.thinkmodel.IotProductThinkModelService; +import cn.iocoder.yudao.module.iot.service.thingmodel.IotProductThingModelService; import com.baomidou.dynamic.datasource.annotation.DSTransactional; import jakarta.annotation.Resource; import org.springframework.context.annotation.Lazy; @@ -34,7 +34,7 @@ public class IotProductServiceImpl implements IotProductService { @Resource @Lazy - private IotProductThinkModelService thinkModelFunctionService; + private IotProductThingModelService thingModelService; @Override public Long createProduct(IotProductSaveReqVO createReqVO) { @@ -115,7 +115,7 @@ public class IotProductServiceImpl implements IotProductService { // 3. 产品是发布状态 if (Objects.equals(status, IotProductStatusEnum.PUBLISHED.getStatus())) { // 3.1 创建超级表数据模型 - thinkModelFunctionService.createSuperTableDataModel(id); + thingModelService.createSuperTableDataModel(id); } productMapper.updateById(updateObj); } diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotSuperTableService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotSuperTableService.java index bf76ae1..bb6d8c0 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotSuperTableService.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotSuperTableService.java @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.iot.service.tdengine; import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodel.IotProductThinkModelDO; +import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotProductThingModelDO; import java.util.List; @@ -14,5 +14,6 @@ public interface IotSuperTableService { /** * 创建超级表数据模型 */ - void createSuperTableDataModel(IotProductDO product, List functionList); + void createSuperTableDataModel(IotProductDO product, List thingModelList); + } \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotSuperTableServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotSuperTableServiceImpl.java index 59fa9d0..1727fae 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotSuperTableServiceImpl.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotSuperTableServiceImpl.java @@ -2,15 +2,15 @@ package cn.iocoder.yudao.module.iot.service.tdengine; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelProperty; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelRespVO; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelRespVO; import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.FieldParser; import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdFieldDO; import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodel.IotProductThinkModelDO; +import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotProductThingModelDO; import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper; -import cn.iocoder.yudao.module.iot.enums.thinkmodel.IotProductThinkModelTypeEnum; +import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -33,8 +33,8 @@ public class IotSuperTableServiceImpl implements IotSuperTableService { private String url; @Override - public void createSuperTableDataModel(IotProductDO product, List functionList) { - ThinkModelRespVO thingModel = buildThinkModel(product, functionList); + public void createSuperTableDataModel(IotProductDO product, List thingModelList) { + ThingModelRespVO thingModel = buildThingModel(product, thingModelList); if (thingModel.getModel() == null || CollUtil.isEmpty(thingModel.getModel().getProperties())) { log.warn("物模型属性列表为空,不创建超级表"); @@ -56,7 +56,7 @@ public class IotSuperTableServiceImpl implements IotSuperTableService { /** * 创建超级表 */ - private void createSuperTable(ThinkModelRespVO thingModel, Integer deviceType) { + private void createSuperTable(ThingModelRespVO thingModel, Integer deviceType) { // 解析物模型,获取字段列表 List schemaFields = new ArrayList<>(); schemaFields.add(TdFieldDO.builder() @@ -84,7 +84,7 @@ public class IotSuperTableServiceImpl implements IotSuperTableService { /** * 更新超级表 */ - private void updateSuperTable(ThinkModelRespVO thingModel, Integer deviceType) { + private void updateSuperTable(ThingModelRespVO thingModel, Integer deviceType) { String superTableName = getSuperTableName(deviceType, thingModel.getProductKey()); try { List oldFields = getTableFields(superTableName); @@ -210,18 +210,18 @@ public class IotSuperTableServiceImpl implements IotSuperTableService { /** * 构建物模型 */ - private ThinkModelRespVO buildThinkModel(IotProductDO product, List functionList) { - ThinkModelRespVO thingModel = new ThinkModelRespVO(); + private ThingModelRespVO buildThingModel(IotProductDO product, List thingModelList) { + ThingModelRespVO thingModel = new ThingModelRespVO(); thingModel.setId(product.getId()); thingModel.setProductKey(product.getProductKey()); - List properties = functionList.stream() - .filter(function -> IotProductThinkModelTypeEnum.PROPERTY.equals( - IotProductThinkModelTypeEnum.valueOfType(function.getType()))) - .map(this::buildThinkModelProperty) + List properties = thingModelList.stream() + .filter(item -> IotProductThingModelTypeEnum.PROPERTY.equals( + IotProductThingModelTypeEnum.valueOfType(item.getType()))) + .map(this::buildThingModelProperty) .collect(Collectors.toList()); - ThinkModelRespVO.Model model = new ThinkModelRespVO.Model(); + ThingModelRespVO.Model model = new ThingModelRespVO.Model(); model.setProperties(properties); thingModel.setModel(model); @@ -231,9 +231,9 @@ public class IotSuperTableServiceImpl implements IotSuperTableService { /** * 构建物模型属性 */ - private ThinkModelProperty buildThinkModelProperty(IotProductThinkModelDO function) { - ThinkModelProperty property = BeanUtil.copyProperties(function, ThinkModelProperty.class); - property.setDataType(function.getProperty().getDataType()); + private ThingModelProperty buildThingModelProperty(IotProductThingModelDO thingModel) { + ThingModelProperty property = BeanUtil.copyProperties(thingModel, ThingModelProperty.class); + property.setDataType(thingModel.getProperty().getDataType()); return property; } diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageService.java new file mode 100644 index 0000000..ffcb306 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageService.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.iot.service.tdengine; + +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage; + +/** + * 物模型消息 Service + */ +public interface IotThingModelMessageService { + + /** + * 保存物模型消息 + * + * @param device 设备 + * @param thingModelMessage 物模型消息 + */ + void saveThingModelMessage(IotDeviceDO device, ThingModelMessage thingModelMessage); +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java new file mode 100644 index 0000000..f5d5892 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java @@ -0,0 +1,225 @@ +package cn.iocoder.yudao.module.iot.service.tdengine; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceStatusUpdateReqVO; +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO; +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.FieldParser; +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdFieldDO; +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO; +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage; +import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotProductThingModelDO; +import cn.iocoder.yudao.module.iot.dal.redis.deviceData.DeviceDataRedisDAO; +import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper; +import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper; +import cn.iocoder.yudao.module.iot.enums.IotConstants; +import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStatusEnum; +import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum; +import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; +import cn.iocoder.yudao.module.iot.service.thingmodel.IotProductThingModelService; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; + +/** + * 物模型消息 Service 实现类 + */ +@Slf4j +@Service +public class IotThingModelMessageServiceImpl implements IotThingModelMessageService { + + private static final String TAG_NOTE = "TAG"; + private static final String NOTE = "note"; + private static final String TIME = "time"; + private static final String DEVICE_KEY = "device_key"; + private static final String DEVICE_NAME = "device_name"; + private static final String PRODUCT_KEY = "product_key"; + private static final String DEVICE_TYPE = "device_type"; + + @Value("${spring.datasource.dynamic.datasource.tdengine.url}") + private String url; + + @Resource + private IotProductThingModelService iotProductThingModelService; + @Resource + private IotDeviceService iotDeviceService; + @Resource + private TdEngineDDLMapper tdEngineDDLMapper; + @Resource + private TdEngineDMLMapper tdEngineDMLMapper; + + @Resource + private DeviceDataRedisDAO deviceDataRedisDAO; + + // TODO @haohao:这个方法,可以考虑加下 1. 2. 3. 更有层次感 + @Override + @TenantIgnore + public void saveThingModelMessage(IotDeviceDO device, ThingModelMessage thingModelMessage) { + // 1. 判断设备状态,如果为未激活状态,创建数据表并更新设备状态 + if (IotDeviceStatusEnum.INACTIVE.getStatus().equals(device.getStatus())) { + createDeviceTable(device.getDeviceType(), device.getProductKey(), device.getDeviceName(), device.getDeviceKey()); + iotDeviceService.updateDeviceStatus(new IotDeviceStatusUpdateReqVO() + .setId(device.getId()).setStatus(IotDeviceStatusEnum.ONLINE.getStatus())); + } + + // 2. 获取设备属性并进行物模型校验,过滤非物模型属性 + Map params = thingModelMessage.dataToMap(); + List thingModelList = getValidThingModelList(thingModelMessage.getProductKey()); + if (thingModelList.isEmpty()) { + return; + } + + // 3. 过滤并收集有效的属性字段,缓存设备属性 + List schemaFieldValues = filterAndCollectValidFields(params, thingModelList, device, thingModelMessage.getTime()); + if (schemaFieldValues.size() == 1) { // 仅有时间字段,无需保存 + return; + } + + // 4. 构建并保存设备属性数据 + tdEngineDMLMapper.insertData(TdTableDO.builder() + .dataBaseName(getDatabaseName()) + .tableName(getDeviceTableName(device.getProductKey(), device.getDeviceName())) + .columns(schemaFieldValues) + .build()); + } + + private List getValidThingModelList(String productKey) { + return filterList(iotProductThingModelService.getProductThingModelListByProductKey(productKey), + thingModel -> IotProductThingModelTypeEnum.PROPERTY.getType().equals(thingModel.getType())); + } + + private List filterAndCollectValidFields(Map params, List thingModelList, IotDeviceDO device, Long time) { + // 1. 获取属性标识符集合 + Set propertyIdentifiers = convertSet(thingModelList, IotProductThingModelDO::getIdentifier); + + // 2. 构建属性标识符和属性的映射 + Map thingModelMap = convertMap(thingModelList, IotProductThingModelDO::getIdentifier); + + // 3. 过滤并收集有效的属性字段 + List schemaFieldValues = new ArrayList<>(); + schemaFieldValues.add(new TdFieldDO(TIME, time)); + params.forEach((key, val) -> { + if (propertyIdentifiers.contains(key)) { + schemaFieldValues.add(new TdFieldDO(key.toLowerCase(), val)); + // 缓存设备属性 + // TODO @haohao:这个缓存的写入,可以使用的时候 cache 么?被动读 + setDeviceDataCache(device, thingModelMap.get(key), val, time); + } + }); + return schemaFieldValues; + } + + /** + * 缓存设备属性 + * + * @param device 设备信息 + * @param iotProductThingModelDO 物模型属性 + * @param val 属性值 + * @param time 时间 + */ + private void setDeviceDataCache(IotDeviceDO device, IotProductThingModelDO iotProductThingModelDO, Object val, Long time) { + IotDeviceDataDO deviceData = IotDeviceDataDO.builder() + .productKey(device.getProductKey()) + .deviceName(device.getDeviceName()) + .identifier(iotProductThingModelDO.getIdentifier()) + .value(val != null ? val.toString() : null) + .updateTime(DateUtil.toLocalDateTime(new Date(time))) + .deviceId(device.getId()) + .thingModelId(iotProductThingModelDO.getId()) + .name(iotProductThingModelDO.getName()) + .dataType(iotProductThingModelDO.getProperty().getDataType()) + .build(); + deviceDataRedisDAO.set(deviceData); + } + + /** + * 创建设备数据表 + * + * @param deviceType 设备类型 + * @param productKey 产品 Key + * @param deviceName 设备名称 + * @param deviceKey 设备 Key + */ + private void createDeviceTable(Integer deviceType, String productKey, String deviceName, String deviceKey) { + // 1. 获取超级表名和数据库名 + String superTableName = getProductPropertySTableName(deviceType, productKey); + String dataBaseName = getDatabaseName(); + + // 2. 获取超级表的结构信息 + List> maps = tdEngineDDLMapper.describeSuperTable(new TdTableDO(dataBaseName, superTableName)); + List tagsFieldValues = new ArrayList<>(); + if (maps != null) { + // 2.1 过滤出 TAG 类型的字段 + List> taggedNotesList = CollectionUtils.filterList(maps, map -> TAG_NOTE.equals(map.get(NOTE))); + + // 2.2 解析字段信息 + tagsFieldValues = FieldParser.parse(taggedNotesList.stream() + .map(map -> List.of(map.get("field"), map.get("type"), map.get("length"))) + .collect(Collectors.toList())); + + // 2.3 设置 TAG 字段的值 + for (TdFieldDO tagsFieldValue : tagsFieldValues) { + switch (tagsFieldValue.getFieldName()) { + case PRODUCT_KEY -> tagsFieldValue.setFieldValue(productKey); + case DEVICE_KEY -> tagsFieldValue.setFieldValue(deviceKey); + case DEVICE_NAME -> tagsFieldValue.setFieldValue(deviceName); + case DEVICE_TYPE -> tagsFieldValue.setFieldValue(deviceType); + } + } + } + + // 3. 创建设备数据表 + String tableName = getDeviceTableName(productKey, deviceName); + tdEngineDDLMapper.createTable(TdTableDO.builder().build() + .setDataBaseName(dataBaseName) + .setSuperTableName(superTableName) + .setTableName(tableName) + .setTags(tagsFieldValues)); + } + + /** + * 获取数据库名称 + * + * @return 数据库名称 + */ + private String getDatabaseName() { + return StrUtil.subAfter(url, "/", true); + } + + /** + * 获取产品属性表名 + * + * @param deviceType 设备类型 + * @param productKey 产品 Key + * @return 产品属性表名 + */ + private static String getProductPropertySTableName(Integer deviceType, String productKey) { + // TODO @haohao:枚举下,会好点哈。 + return switch (deviceType) { + case 1 -> String.format(IotConstants.GATEWAY_SUB_STABLE_NAME_FORMAT, productKey).toLowerCase(); + case 2 -> String.format(IotConstants.GATEWAY_STABLE_NAME_FORMAT, productKey).toLowerCase(); + default -> String.format(IotConstants.DEVICE_STABLE_NAME_FORMAT, productKey).toLowerCase(); + }; + } + + /** + * 获取设备表名 + * + * @param productKey 产品 Key + * @param deviceName 设备名称 + * @return 设备表名 + */ + private static String getDeviceTableName(String productKey, String deviceName) { + return String.format(IotConstants.DEVICE_TABLE_NAME_FORMAT, productKey.toLowerCase(), deviceName.toLowerCase()); + } + +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThinkModelMessageService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThinkModelMessageService.java deleted file mode 100644 index 67ee2b9..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThinkModelMessageService.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.tdengine; - -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThinkModelMessage; - -/** - * 物模型消息 Service - */ -public interface IotThinkModelMessageService { - - /** - * 保存物模型消息 - * - * @param device 设备 - * @param thingModelMessage 物模型消息 - */ - void saveThinkModelMessage(IotDeviceDO device, ThinkModelMessage thingModelMessage); -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThinkModelMessageServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThinkModelMessageServiceImpl.java deleted file mode 100644 index 3c2debf..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThinkModelMessageServiceImpl.java +++ /dev/null @@ -1,227 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.tdengine; - -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceStatusUpdateReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.FieldParser; -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdFieldDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThinkModelMessage; -import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodel.IotProductThinkModelDO; -import cn.iocoder.yudao.module.iot.dal.redis.deviceData.DeviceDataRedisDAO; -import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper; -import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper; -import cn.iocoder.yudao.module.iot.enums.IotConstants; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStatusEnum; -import cn.iocoder.yudao.module.iot.enums.thinkmodel.IotProductThinkModelTypeEnum; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -import cn.iocoder.yudao.module.iot.service.thinkmodel.IotProductThinkModelService; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -import java.util.*; -import java.util.stream.Collectors; - -/** - * 物模型消息 Service 实现类 - */ -@Slf4j -@Service -public class IotThinkModelMessageServiceImpl implements IotThinkModelMessageService { - - private static final String TAG_NOTE = "TAG"; - private static final String NOTE = "note"; - private static final String TIME = "time"; - private static final String DEVICE_KEY = "device_key"; - private static final String DEVICE_NAME = "device_name"; - private static final String PRODUCT_KEY = "product_key"; - private static final String DEVICE_TYPE = "device_type"; - - @Value("${spring.datasource.dynamic.datasource.tdengine.url}") - private String url; - - @Resource - private IotProductThinkModelService iotProductThinkModelService; - @Resource - private IotDeviceService iotDeviceService; - @Resource - private TdEngineDDLMapper tdEngineDDLMapper; - @Resource - private TdEngineDMLMapper tdEngineDMLMapper; - - @Resource - private DeviceDataRedisDAO deviceDataRedisDAO; - - // TODO @haohao:这个方法,可以考虑加下 1. 2. 3. 更有层次感 - @Override - @TenantIgnore - public void saveThinkModelMessage(IotDeviceDO device, ThinkModelMessage thingModelMessage) { - // 1. 判断设备状态,如果为未激活状态,创建数据表并更新设备状态 - if (IotDeviceStatusEnum.INACTIVE.getStatus().equals(device.getStatus())) { - createDeviceTable(device.getDeviceType(), device.getProductKey(), device.getDeviceName(), device.getDeviceKey()); - iotDeviceService.updateDeviceStatus(new IotDeviceStatusUpdateReqVO() - .setId(device.getId()).setStatus(IotDeviceStatusEnum.ONLINE.getStatus())); - } - - // 2. 获取设备属性并进行物模型校验,过滤非物模型属性 - Map params = thingModelMessage.dataToMap(); - List functionList = getValidFunctionList(thingModelMessage.getProductKey()); - if (functionList.isEmpty()) { - return; - } - - // 3. 过滤并收集有效的属性字段,缓存设备属性 - List schemaFieldValues = filterAndCollectValidFields(params, functionList, device, thingModelMessage.getTime()); - if (schemaFieldValues.size() == 1) { // 仅有时间字段,无需保存 - return; - } - - // 4. 构建并保存设备属性数据 - tdEngineDMLMapper.insertData(TdTableDO.builder() - .dataBaseName(getDatabaseName()) - .tableName(getDeviceTableName(device.getProductKey(), device.getDeviceName())) - .columns(schemaFieldValues) - .build()); - } - - private List getValidFunctionList(String productKey) { - return iotProductThinkModelService - .getProductThinkModelListByProductKey(productKey) - .stream() - .filter(function -> IotProductThinkModelTypeEnum.PROPERTY.getType().equals(function.getType())) - .toList(); - } - - private List filterAndCollectValidFields(Map params, List functionList, IotDeviceDO device, Long time) { - // 1. 获取属性标识符集合 - Set propertyIdentifiers = CollectionUtils.convertSet(functionList, IotProductThinkModelDO::getIdentifier); - - // 2. 构建属性标识符和属性的映射 - Map functionMap = functionList.stream() - .collect(Collectors.toMap(IotProductThinkModelDO::getIdentifier, function -> function)); - - // 3. 过滤并收集有效的属性字段 - List schemaFieldValues = new ArrayList<>(); - schemaFieldValues.add(new TdFieldDO(TIME, time)); - params.forEach((key, val) -> { - if (propertyIdentifiers.contains(key)) { - schemaFieldValues.add(new TdFieldDO(key.toLowerCase(), val)); - // 缓存设备属性 - // TODO @haohao:这个缓存的写入,可以使用的时候 cache 么?被动读 - setDeviceDataCache(device, functionMap.get(key), val, time); - } - }); - return schemaFieldValues; - } - - /** - * 缓存设备属性 - * - * @param device 设备信息 - * @param iotProductThinkModelDO 物模型属性 - * @param val 属性值 - * @param time 时间 - */ - private void setDeviceDataCache(IotDeviceDO device, IotProductThinkModelDO iotProductThinkModelDO, Object val, Long time) { - IotDeviceDataDO deviceData = IotDeviceDataDO.builder() - .productKey(device.getProductKey()) - .deviceName(device.getDeviceName()) - .identifier(iotProductThinkModelDO.getIdentifier()) - .value(val != null ? val.toString() : null) - .updateTime(DateUtil.toLocalDateTime(new Date(time))) - .deviceId(device.getId()) - .thinkModelId(iotProductThinkModelDO.getId()) - .name(iotProductThinkModelDO.getName()) - .dataType(iotProductThinkModelDO.getProperty().getDataType()) - .build(); - deviceDataRedisDAO.set(deviceData); - } - - /** - * 创建设备数据表 - * - * @param deviceType 设备类型 - * @param productKey 产品 Key - * @param deviceName 设备名称 - * @param deviceKey 设备 Key - */ - private void createDeviceTable(Integer deviceType, String productKey, String deviceName, String deviceKey) { - // 1. 获取超级表名和数据库名 - String superTableName = getProductPropertySTableName(deviceType, productKey); - String dataBaseName = getDatabaseName(); - - // 2. 获取超级表的结构信息 - List> maps = tdEngineDDLMapper.describeSuperTable(new TdTableDO(dataBaseName, superTableName)); - List tagsFieldValues = new ArrayList<>(); - if (maps != null) { - // 2.1 过滤出 TAG 类型的字段 - List> taggedNotesList = CollectionUtils.filterList(maps, map -> TAG_NOTE.equals(map.get(NOTE))); - - // 2.2 解析字段信息 - tagsFieldValues = FieldParser.parse(taggedNotesList.stream() - .map(map -> List.of(map.get("field"), map.get("type"), map.get("length"))) - .collect(Collectors.toList())); - - // 2.3 设置 TAG 字段的值 - for (TdFieldDO tagsFieldValue : tagsFieldValues) { - switch (tagsFieldValue.getFieldName()) { - case PRODUCT_KEY -> tagsFieldValue.setFieldValue(productKey); - case DEVICE_KEY -> tagsFieldValue.setFieldValue(deviceKey); - case DEVICE_NAME -> tagsFieldValue.setFieldValue(deviceName); - case DEVICE_TYPE -> tagsFieldValue.setFieldValue(deviceType); - } - } - } - - // 3. 创建设备数据表 - String tableName = getDeviceTableName(productKey, deviceName); - tdEngineDDLMapper.createTable(TdTableDO.builder().build() - .setDataBaseName(dataBaseName) - .setSuperTableName(superTableName) - .setTableName(tableName) - .setTags(tagsFieldValues)); - } - - /** - * 获取数据库名称 - * - * @return 数据库名称 - */ - private String getDatabaseName() { - return StrUtil.subAfter(url, "/", true); - } - - /** - * 获取产品属性表名 - * - * @param deviceType 设备类型 - * @param productKey 产品 Key - * @return 产品属性表名 - */ - private static String getProductPropertySTableName(Integer deviceType, String productKey) { - // TODO @haohao:枚举下,会好点哈。 - return switch (deviceType) { - case 1 -> String.format(IotConstants.GATEWAY_SUB_STABLE_NAME_FORMAT, productKey).toLowerCase(); - case 2 -> String.format(IotConstants.GATEWAY_STABLE_NAME_FORMAT, productKey).toLowerCase(); - default -> String.format(IotConstants.DEVICE_STABLE_NAME_FORMAT, productKey).toLowerCase(); - }; - } - - /** - * 获取设备表名 - * - * @param productKey 产品 Key - * @param deviceName 设备名称 - * @return 设备表名 - */ - private static String getDeviceTableName(String productKey, String deviceName) { - return String.format(IotConstants.DEVICE_TABLE_NAME_FORMAT, productKey.toLowerCase(), deviceName.toLowerCase()); - } - -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotProductThingModelService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotProductThingModelService.java new file mode 100644 index 0000000..04086d0 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotProductThingModelService.java @@ -0,0 +1,79 @@ +package cn.iocoder.yudao.module.iot.service.thingmodel; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotProductThingModelPageReqVO; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotProductThingModelSaveReqVO; +import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotProductThingModelDO; +import jakarta.validation.Valid; + +import java.util.List; + +/** + * IoT 产品物模型 Service 接口 + * + * @author 芋道源码 + */ +public interface IotProductThingModelService { + + /** + * 创建产品物模型 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createProductThingModel(@Valid IotProductThingModelSaveReqVO createReqVO); + + /** + * 更新产品物模型 + * + * @param updateReqVO 更新信息 + */ + void updateProductThingModel(@Valid IotProductThingModelSaveReqVO updateReqVO); + + /** + * 删除产品物模型 + * + * @param id 编号 + */ + void deleteProductThingModel(Long id); + + /** + * 获得产品物模型 + * + * @param id 编号 + * @return 产品物模型 + */ + IotProductThingModelDO getProductThingModel(Long id); + + /** + * 获得产品物模型列表 + * + * @param productId 产品编号 + * @return 产品物模型列表 + */ + List getProductThingModelListByProductId(Long productId); + + /** + * 获得产品物模型分页 + * + * @param pageReqVO 分页查询 + * @return 产品物模型分页 + */ + PageResult getProductThingModelPage(IotProductThingModelPageReqVO pageReqVO); + + /** + * 创建超级表数据模型 + * + * @param productId 产品编号 + */ + void createSuperTableDataModel(Long productId); + + /** + * 获得产品物模型列表 + * + * @param productKey 产品 Key + * @return 产品物模型列表 + */ + List getProductThingModelListByProductKey(String productKey); + +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotProductThingModelServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotProductThingModelServiceImpl.java new file mode 100644 index 0000000..b5c2d4e --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotProductThingModelServiceImpl.java @@ -0,0 +1,442 @@ +package cn.iocoder.yudao.module.iot.service.thingmodel; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelArgument; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelArrayDataSpecs; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDateOrTextDataSpecs; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotProductThingModelPageReqVO; +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotProductThingModelSaveReqVO; +import cn.iocoder.yudao.module.iot.convert.thingmodel.IotProductThingModelConvert; +import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; +import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotProductThingModelDO; +import cn.iocoder.yudao.module.iot.dal.mysql.thingmodel.IotProductThingModelMapper; +import cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum; +import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelAccessModeEnum; +import cn.iocoder.yudao.module.iot.enums.thingmodel.IotProductThingModelTypeEnum; +import cn.iocoder.yudao.module.iot.service.product.IotProductService; +import cn.iocoder.yudao.module.iot.service.tdengine.IotSuperTableService; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import java.util.stream.Collectors; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*; + +/** + * IoT 产品物模型 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +@Slf4j +public class IotProductThingModelServiceImpl implements IotProductThingModelService { + + @Resource + private IotProductThingModelMapper productThingModelMapper; + + @Resource + private IotProductService productService; + @Resource + private IotSuperTableService dbStructureDataService; + + @Override + @Transactional(rollbackFor = Exception.class) + public Long createProductThingModel(IotProductThingModelSaveReqVO createReqVO) { + // 1. 校验功能标识符在同一产品下是否唯一 + validateIdentifierUnique(createReqVO.getProductId(), createReqVO.getIdentifier()); + + // 2. 功能名称在同一产品下是否唯一 + validateNameUnique(createReqVO.getProductId(), createReqVO.getName()); + + // 3. 系统保留字段,不能用于标识符定义 + validateNotDefaultEventAndService(createReqVO.getIdentifier()); + + // 4. 校验产品状态,发布状态下,不允许新增功能 + validateProductStatus(createReqVO.getProductId()); + + // 5. 插入数据库 + IotProductThingModelDO thingModel = IotProductThingModelConvert.INSTANCE.convert(createReqVO); + productThingModelMapper.insert(thingModel); + + // 6. 如果创建的是属性,需要更新默认的事件和服务 + if (Objects.equals(createReqVO.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) { + createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey()); + } + return thingModel.getId(); + } + + private void validateProductStatus(Long createReqVO) { + IotProductDO product = productService.getProduct(createReqVO); + if (Objects.equals(product.getStatus(), IotProductStatusEnum.PUBLISHED.getStatus())) { + throw exception(PRODUCT_STATUS_NOT_ALLOW_THING_MODEL); + } + } + + private void validateNotDefaultEventAndService(String identifier) { + // set, get, post, property, event, time, value 是系统保留字段,不能用于标识符定义 + if (CollUtil.containsAny(Arrays.asList("set", "get", "post", "property", "event", "time", "value"), Collections.singletonList(identifier))) { + throw exception(THING_MODEL_IDENTIFIER_INVALID); + } + } + + private void validateNameUnique(Long productId, String name) { + IotProductThingModelDO thingModel = productThingModelMapper.selectByProductIdAndName(productId, name); + if (thingModel != null) { + throw exception(THING_MODEL_NAME_EXISTS); + } + } + + private void validateIdentifierUnique(Long productId, String identifier) { + IotProductThingModelDO thingModel = productThingModelMapper.selectByProductIdAndIdentifier(productId, identifier); + if (thingModel != null) { + throw exception(THING_MODEL_IDENTIFIER_EXISTS); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateProductThingModel(IotProductThingModelSaveReqVO updateReqVO) { + // 1. 校验功能是否存在 + validateProductThingModelMapperExists(updateReqVO.getId()); + + // 2. 校验功能标识符是否唯一 + validateIdentifierUniqueForUpdate(updateReqVO.getId(), updateReqVO.getProductId(), updateReqVO.getIdentifier()); + + // 3. 校验产品状态,发布状态下,不允许操作功能 + validateProductStatus(updateReqVO.getProductId()); + + // 4. 更新数据库 + IotProductThingModelDO thingModel = IotProductThingModelConvert.INSTANCE.convert(updateReqVO); + productThingModelMapper.updateById(thingModel); + + // 5. 如果更新的是属性,需要更新默认的事件和服务 + if (Objects.equals(updateReqVO.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) { + createDefaultEventsAndServices(updateReqVO.getProductId(), updateReqVO.getProductKey()); + } + } + + private void validateIdentifierUniqueForUpdate(Long id, Long productId, String identifier) { + IotProductThingModelDO thingModel = productThingModelMapper.selectByProductIdAndIdentifier(productId, identifier); + if (thingModel != null && ObjectUtil.notEqual(thingModel.getId(), id)) { + throw exception(THING_MODEL_IDENTIFIER_EXISTS); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteProductThingModel(Long id) { + // 1. 校验功能是否存在 + IotProductThingModelDO thingModel = productThingModelMapper.selectById(id); + if (thingModel == null) { + throw exception(THING_MODEL_NOT_EXISTS); + } + + // 3. 校验产品状态,发布状态下,不允许操作功能 + validateProductStatus(thingModel.getProductId()); + + // 2. 删除功能 + productThingModelMapper.deleteById(id); + + // 3. 如果删除的是属性,需要更新默认的事件和服务 + if (Objects.equals(thingModel.getType(), IotProductThingModelTypeEnum.PROPERTY.getType())) { + createDefaultEventsAndServices(thingModel.getProductId(), thingModel.getProductKey()); + } + } + + /** + * 校验功能是否存在 + * + * @param id 功能编号 + */ + private void validateProductThingModelMapperExists(Long id) { + if (productThingModelMapper.selectById(id) == null) { + throw exception(THING_MODEL_NOT_EXISTS); + } + } + + @Override + public IotProductThingModelDO getProductThingModel(Long id) { + return productThingModelMapper.selectById(id); + } + + @Override + public List getProductThingModelListByProductId(Long productId) { + return productThingModelMapper.selectListByProductId(productId); + } + + @Override + public PageResult getProductThingModelPage(IotProductThingModelPageReqVO pageReqVO) { + return productThingModelMapper.selectPage(pageReqVO); + } + + @Override + public void createSuperTableDataModel(Long productId) { + // 1. 查询产品 + IotProductDO product = productService.getProduct(productId); + + // 2. 查询产品的物模型功能列表 + List thingModelList = productThingModelMapper.selectListByProductId(productId); + + // 3. 生成 TDengine 的数据模型 + dbStructureDataService.createSuperTableDataModel(product, thingModelList); + } + + @Override + public List getProductThingModelListByProductKey(String productKey) { + return productThingModelMapper.selectListByProductKey(productKey); + } + + /** + * 创建默认的事件和服务 + */ + public void createDefaultEventsAndServices(Long productId, String productKey) { + // 1. 获取当前属性列表 + List propertyList = productThingModelMapper + .selectListByProductIdAndType(productId, IotProductThingModelTypeEnum.PROPERTY.getType()); + + // 2. 生成新的事件和服务列表 + List newThingModelList = new ArrayList<>(); + // 生成属性上报事件 + ThingModelEvent propertyPostEvent = generatePropertyPostEvent(propertyList); + if (propertyPostEvent != null) { + IotProductThingModelDO eventThingModel = buildEventThingModelDO(productId, productKey, propertyPostEvent); + newThingModelList.add(eventThingModel); + } + // 生成属性设置服务 + ThingModelService propertySetService = generatePropertySetService(propertyList); + if (propertySetService != null) { + IotProductThingModelDO setServiceThingModel = buildServiceThingModelDO(productId, productKey, propertySetService); + newThingModelList.add(setServiceThingModel); + } + // 生成属性获取服务 + ThingModelService propertyGetService = generatePropertyGetService(propertyList); + if (propertyGetService != null) { + IotProductThingModelDO getServiceThingModel = buildServiceThingModelDO(productId, productKey, propertyGetService); + newThingModelList.add(getServiceThingModel); + } + + // 3. 获取数据库中的默认的旧事件和服务列表 + List oldThingModelList = productThingModelMapper.selectListByProductIdAndIdentifiersAndTypes( + productId, + Arrays.asList("post", "set", "get"), + Arrays.asList(IotProductThingModelTypeEnum.EVENT.getType(), IotProductThingModelTypeEnum.SERVICE.getType()) + ); + + // 3.1 使用 diffList 方法比较新旧列表 + List> diffResult = diffList(oldThingModelList, newThingModelList, + // 继续使用 identifier 和 type 进行比较:这样可以准确地匹配对应的功能对象。 + (oldFunc, newFunc) -> Objects.equals(oldFunc.getIdentifier(), newFunc.getIdentifier()) + && Objects.equals(oldFunc.getType(), newFunc.getType())); + List createList = diffResult.get(0); // 需要新增的 + List updateList = diffResult.get(1); // 需要更新的 + List deleteList = diffResult.get(2); // 需要删除的 + + // 3.2 批量执行数据库操作 + // 新增数据库中的新事件和服务列表 + if (CollUtil.isNotEmpty(createList)) { + productThingModelMapper.insertBatch(createList); + } + // 更新数据库中的事件和服务列表 + if (CollUtil.isNotEmpty(updateList)) { + // 首先,为每个需要更新的对象设置其对应的 ID + updateList.forEach(updateFunc -> { + IotProductThingModelDO oldFunc = findThingModelByIdentifierAndType( + oldThingModelList, updateFunc.getIdentifier(), updateFunc.getType()); + if (oldFunc != null) { + updateFunc.setId(oldFunc.getId()); + } + }); + // 过滤掉没有设置 ID 的对象 + List validUpdateList = updateList.stream() + .filter(func -> func.getId() != null) + .collect(Collectors.toList()); + // 执行批量更新 + if (CollUtil.isNotEmpty(validUpdateList)) { + productThingModelMapper.updateBatch(validUpdateList); + } + } + + // 删除数据库中的旧事件和服务列表 + if (CollUtil.isNotEmpty(deleteList)) { + Set idsToDelete = CollectionUtils.convertSet(deleteList, IotProductThingModelDO::getId); + productThingModelMapper.deleteByIds(idsToDelete); + } + } + + /** + * 根据标识符和类型查找功能对象 + */ + private IotProductThingModelDO findThingModelByIdentifierAndType(List thingModelList, + String identifier, Integer type) { + return CollUtil.findOne(thingModelList, func -> + Objects.equals(func.getIdentifier(), identifier) && Objects.equals(func.getType(), type)); + } + + /** + * 构建事件功能对象 + */ + private IotProductThingModelDO buildEventThingModelDO(Long productId, String productKey, ThingModelEvent event) { + return new IotProductThingModelDO() + .setProductId(productId) + .setProductKey(productKey) + .setIdentifier(event.getIdentifier()) + .setName(event.getName()) + .setDescription(event.getDescription()) + .setType(IotProductThingModelTypeEnum.EVENT.getType()) + .setEvent(event); + } + + /** + * 构建服务功能对象 + */ + private IotProductThingModelDO buildServiceThingModelDO(Long productId, String productKey, ThingModelService service) { + return new IotProductThingModelDO() + .setProductId(productId) + .setProductKey(productKey) + .setIdentifier(service.getIdentifier()) + .setName(service.getName()) + .setDescription(service.getDescription()) + .setType(IotProductThingModelTypeEnum.SERVICE.getType()) + .setService(service); + } + + /** + * 生成属性上报事件 + */ + private ThingModelEvent generatePropertyPostEvent(List propertyList) { + if (CollUtil.isEmpty(propertyList)) { + return null; + } + + ThingModelEvent event = new ThingModelEvent() + .setIdentifier("post") + .setName("属性上报") + .setType("info") + .setDescription("属性上报事件") + .setMethod("thing.event.property.post"); + + // 将属性列表转换为事件的输出参数 + List outputData = new ArrayList<>(); + for (IotProductThingModelDO thingModel : propertyList) { + ThingModelArgument arg = new ThingModelArgument() + .setIdentifier(thingModel.getIdentifier()) + .setName(thingModel.getName()) + .setProperty(thingModel.getProperty()) + .setDescription(thingModel.getDescription()) + .setDirection("output"); // 设置为输出参数 + outputData.add(arg); + } + event.setOutputData(outputData); + return event; + } + + /** + * 生成属性设置服务 + */ + private ThingModelService generatePropertySetService(List propertyList) { + if (propertyList == null || propertyList.isEmpty()) { + return null; + } + + List inputData = new ArrayList<>(); + for (IotProductThingModelDO thingModel : propertyList) { + ThingModelProperty property = thingModel.getProperty(); + if (IotProductThingModelAccessModeEnum.READ_WRITE.getMode().equals(property.getAccessMode())) { + ThingModelArgument arg = new ThingModelArgument() + .setIdentifier(property.getIdentifier()) + .setName(property.getName()) + .setProperty(property) + .setDescription(property.getDescription()) + .setDirection("input"); // 设置为输入参数 + inputData.add(arg); + } + } + if (inputData.isEmpty()) { + // 如果没有可写属性,不生成属性设置服务 + return null; + } + + // 属性设置服务一般不需要输出参数 + return new ThingModelService() + .setIdentifier("set") + .setName("属性设置") + .setCallType("async") + .setDescription("属性设置服务") + .setMethod("thing.service.property.set") + .setInputData(inputData) + // 属性设置服务一般不需要输出参数 + .setOutputData(new ArrayList<>()); + } + + /** + * 生成属性获取服务 + */ + private ThingModelService generatePropertyGetService(List propertyList) { + if (propertyList == null || propertyList.isEmpty()) { + return null; + } + + List outputData = new ArrayList<>(); + for (IotProductThingModelDO thingModelDO : propertyList) { + ThingModelProperty property = thingModelDO.getProperty(); + if (ObjectUtils.equalsAny(property.getAccessMode(), + IotProductThingModelAccessModeEnum.READ_ONLY.getMode(), IotProductThingModelAccessModeEnum.READ_WRITE.getMode())) { + ThingModelArgument arg = new ThingModelArgument() + .setIdentifier(property.getIdentifier()) + .setName(property.getName()) + .setProperty(property) + .setDescription(property.getDescription()) + .setDirection("output"); // 设置为输出参数 + outputData.add(arg); + } + } + if (outputData.isEmpty()) { + // 如果没有可读属性,不生成属性获取服务 + return null; + } + + ThingModelService service = new ThingModelService() + .setIdentifier("get") + .setName("属性获取") + .setCallType("async") + .setDescription("属性获取服务") + .setMethod("thing.service.property.get"); + + // 定义输入参数:属性标识符列表 + ThingModelArgument inputArg = new ThingModelArgument() + .setIdentifier("properties") + .setName("属性标识符列表") + .setDescription("需要获取的属性标识符列表") + .setDirection("input"); // 设置为输入参数 + + // 创建数组类型,元素类型为文本类型(字符串)TODO @puhui999: 还得研究研究 + ThingModelArrayDataSpecs arrayType = new ThingModelArrayDataSpecs(); + arrayType.setDataType("array"); + inputArg.setProperty(new ThingModelProperty().setIdentifier(inputArg.getIdentifier()).setName(inputArg.getName()) + .setDescription(inputArg.getDescription()).setDataSpecs(arrayType)); + + ThingModelDateOrTextDataSpecs textType = new ThingModelDateOrTextDataSpecs(); + textType.setDataType("text"); + inputArg.setProperty(new ThingModelProperty().setIdentifier(inputArg.getIdentifier()).setName(inputArg.getName()) + .setDescription(inputArg.getDescription()).setDataSpecs(textType)); + + service.setInputData(Collections.singletonList(inputArg)); + service.setOutputData(outputData); + return service; + } + +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodel/IotProductThinkModelService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodel/IotProductThinkModelService.java deleted file mode 100644 index 34e7fc1..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodel/IotProductThinkModelService.java +++ /dev/null @@ -1,79 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.thinkmodel; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo.IotProductThinkModelPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo.IotProductThinkModelSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodel.IotProductThinkModelDO; -import jakarta.validation.Valid; - -import java.util.List; - -/** - * IoT 产品物模型 Service 接口 - * - * @author 芋道源码 - */ -public interface IotProductThinkModelService { - - /** - * 创建产品物模型 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createProductThinkModel(@Valid IotProductThinkModelSaveReqVO createReqVO); - - /** - * 更新产品物模型 - * - * @param updateReqVO 更新信息 - */ - void updateProductThinkModel(@Valid IotProductThinkModelSaveReqVO updateReqVO); - - /** - * 删除产品物模型 - * - * @param id 编号 - */ - void deleteProductThinkModel(Long id); - - /** - * 获得产品物模型 - * - * @param id 编号 - * @return 产品物模型 - */ - IotProductThinkModelDO getProductThinkModel(Long id); - - /** - * 获得产品物模型列表 - * - * @param productId 产品编号 - * @return 产品物模型列表 - */ - List getProductThinkModelListByProductId(Long productId); - - /** - * 获得产品物模型分页 - * - * @param pageReqVO 分页查询 - * @return 产品物模型分页 - */ - PageResult getProductThinkModelPage(IotProductThinkModelPageReqVO pageReqVO); - - /** - * 创建超级表数据模型 - * - * @param productId 产品编号 - */ - void createSuperTableDataModel(Long productId); - - /** - * 获得产品物模型列表 - * - * @param productKey 产品 Key - * @return 产品物模型列表 - */ - List getProductThinkModelListByProductKey(String productKey); - -} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodel/IotProductThinkModelServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodel/IotProductThinkModelServiceImpl.java deleted file mode 100644 index fa15083..0000000 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodel/IotProductThinkModelServiceImpl.java +++ /dev/null @@ -1,445 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.thinkmodel; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelEvent; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelProperty; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.ThinkModelService; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType.ThinkModelArgument; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType.ThinkModelArrayDataSpecs; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.model.dataType.ThinkModelDateOrTextDataSpecs; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo.IotProductThinkModelPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.thinkmodel.vo.IotProductThinkModelSaveReqVO; -import cn.iocoder.yudao.module.iot.convert.thinkmodel.IotProductThinkModelConvert; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodel.IotProductThinkModelDO; -import cn.iocoder.yudao.module.iot.dal.mysql.thinkmodel.IotProductThinkModelMapper; -import cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum; -import cn.iocoder.yudao.module.iot.enums.thinkmodel.IotProductThinkModelAccessModeEnum; -import cn.iocoder.yudao.module.iot.enums.thinkmodel.IotProductThinkModelTypeEnum; -import cn.iocoder.yudao.module.iot.service.product.IotProductService; -import cn.iocoder.yudao.module.iot.service.tdengine.IotSuperTableService; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; - -import java.util.*; -import java.util.stream.Collectors; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*; - -/** - * IoT 产品物模型 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Validated -@Slf4j -public class IotProductThinkModelServiceImpl implements IotProductThinkModelService { - - @Resource - private IotProductThinkModelMapper productThinkModelMapper; - - @Resource - private IotProductService productService; - @Resource - private IotSuperTableService dbStructureDataService; - - @Override - @Transactional(rollbackFor = Exception.class) - public Long createProductThinkModel(IotProductThinkModelSaveReqVO createReqVO) { - // 1. 校验功能标识符在同一产品下是否唯一 - validateIdentifierUnique(createReqVO.getProductId(), createReqVO.getIdentifier()); - - // 2. 功能名称在同一产品下是否唯一 - validateNameUnique(createReqVO.getProductId(), createReqVO.getName()); - - // 3. 系统保留字段,不能用于标识符定义 - validateNotDefaultEventAndService(createReqVO.getIdentifier()); - - // 4. 校验产品状态,发布状态下,不允许新增功能 - validateProductStatus(createReqVO.getProductId()); - - // 5. 插入数据库 - IotProductThinkModelDO function = IotProductThinkModelConvert.INSTANCE.convert(createReqVO); - productThinkModelMapper.insert(function); - - // 6. 如果创建的是属性,需要更新默认的事件和服务 - if (Objects.equals(createReqVO.getType(), IotProductThinkModelTypeEnum.PROPERTY.getType())) { - createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey()); - } - return function.getId(); - } - - private void validateProductStatus(Long createReqVO) { - IotProductDO product = productService.getProduct(createReqVO); - if (Objects.equals(product.getStatus(), IotProductStatusEnum.PUBLISHED.getStatus())) { - throw exception(PRODUCT_STATUS_NOT_ALLOW_FUNCTION); - } - } - - private void validateNotDefaultEventAndService(String identifier) { - // set, get, post, property, event, time, value 是系统保留字段,不能用于标识符定义 - if (CollUtil.containsAny(Arrays.asList("set", "get", "post", "property", "event", "time", "value"), Collections.singletonList(identifier))) { - throw exception(THINK_MODEL_FUNCTION_IDENTIFIER_INVALID); - } -// if (CollUtil.containsAny(Arrays.asList("post", "set", "get"), identifier)) { -// throw exception(THINK_MODEL_FUNCTION_IDENTIFIER_INVALID); -// } - } - - private void validateNameUnique(Long productId, String name) { - IotProductThinkModelDO function = productThinkModelMapper.selectByProductIdAndName(productId, name); - if (function != null) { - throw exception(THINK_MODEL_FUNCTION_NAME_EXISTS); - } - } - - private void validateIdentifierUnique(Long productId, String identifier) { - IotProductThinkModelDO function = productThinkModelMapper.selectByProductIdAndIdentifier(productId, identifier); - if (function != null) { - throw exception(THINK_MODEL_FUNCTION_IDENTIFIER_EXISTS); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateProductThinkModel(IotProductThinkModelSaveReqVO updateReqVO) { - // 1. 校验功能是否存在 - validateProductThinkModelMapperExists(updateReqVO.getId()); - - // 2. 校验功能标识符是否唯一 - validateIdentifierUniqueForUpdate(updateReqVO.getId(), updateReqVO.getProductId(), updateReqVO.getIdentifier()); - - // 3. 校验产品状态,发布状态下,不允许操作功能 - validateProductStatus(updateReqVO.getProductId()); - - // 4. 更新数据库 - IotProductThinkModelDO productThinkModelDO = IotProductThinkModelConvert.INSTANCE.convert(updateReqVO); - productThinkModelMapper.updateById(productThinkModelDO); - - // 5. 如果更新的是属性,需要更新默认的事件和服务 - if (Objects.equals(updateReqVO.getType(), IotProductThinkModelTypeEnum.PROPERTY.getType())) { - createDefaultEventsAndServices(updateReqVO.getProductId(), updateReqVO.getProductKey()); - } - } - - private void validateIdentifierUniqueForUpdate(Long id, Long productId, String identifier) { - IotProductThinkModelDO function = productThinkModelMapper.selectByProductIdAndIdentifier(productId, identifier); - if (function != null && ObjectUtil.notEqual(function.getId(), id)) { - throw exception(THINK_MODEL_FUNCTION_IDENTIFIER_EXISTS); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteProductThinkModel(Long id) { - // 1. 校验功能是否存在 - IotProductThinkModelDO functionDO = productThinkModelMapper.selectById(id); - if (functionDO == null) { - throw exception(THINK_MODEL_FUNCTION_NOT_EXISTS); - } - - // 3. 校验产品状态,发布状态下,不允许操作功能 - validateProductStatus(functionDO.getProductId()); - - // 2. 删除功能 - productThinkModelMapper.deleteById(id); - - // 3. 如果删除的是属性,需要更新默认的事件和服务 - if (Objects.equals(functionDO.getType(), IotProductThinkModelTypeEnum.PROPERTY.getType())) { - createDefaultEventsAndServices(functionDO.getProductId(), functionDO.getProductKey()); - } - } - - /** - * 校验功能是否存在 - * - * @param id 功能编号 - */ - private void validateProductThinkModelMapperExists(Long id) { - if (productThinkModelMapper.selectById(id) == null) { - throw exception(THINK_MODEL_FUNCTION_NOT_EXISTS); - } - } - - @Override - public IotProductThinkModelDO getProductThinkModel(Long id) { - return productThinkModelMapper.selectById(id); - } - - @Override - public List getProductThinkModelListByProductId(Long productId) { - return productThinkModelMapper.selectListByProductId(productId); - } - - @Override - public PageResult getProductThinkModelPage(IotProductThinkModelPageReqVO pageReqVO) { - return productThinkModelMapper.selectPage(pageReqVO); - } - - @Override - public void createSuperTableDataModel(Long productId) { - // 1. 查询产品 - IotProductDO product = productService.getProduct(productId); - - // 2. 查询产品的物模型功能列表 - List functionList = productThinkModelMapper.selectListByProductId(productId); - - // 3. 生成 TDengine 的数据模型 - dbStructureDataService.createSuperTableDataModel(product, functionList); - } - - @Override - public List getProductThinkModelListByProductKey(String productKey) { - return productThinkModelMapper.selectListByProductKey(productKey); - } - - /** - * 创建默认的事件和服务 - */ - public void createDefaultEventsAndServices(Long productId, String productKey) { - // 1. 获取当前属性列表 - List propertyList = productThinkModelMapper - .selectListByProductIdAndType(productId, IotProductThinkModelTypeEnum.PROPERTY.getType()); - - // 2. 生成新的事件和服务列表 - List newFunctionList = new ArrayList<>(); - // 生成属性上报事件 - ThinkModelEvent propertyPostEvent = generatePropertyPostEvent(propertyList); - if (propertyPostEvent != null) { - IotProductThinkModelDO eventFunction = buildEventFunctionDO(productId, productKey, propertyPostEvent); - newFunctionList.add(eventFunction); - } - // 生成属性设置服务 - ThinkModelService propertySetService = generatePropertySetService(propertyList); - if (propertySetService != null) { - IotProductThinkModelDO setServiceFunction = buildServiceFunctionDO(productId, productKey, propertySetService); - newFunctionList.add(setServiceFunction); - } - // 生成属性获取服务 - ThinkModelService propertyGetService = generatePropertyGetService(propertyList); - if (propertyGetService != null) { - IotProductThinkModelDO getServiceFunction = buildServiceFunctionDO(productId, productKey, propertyGetService); - newFunctionList.add(getServiceFunction); - } - - // 3. 获取数据库中的默认的旧事件和服务列表 - List oldFunctionList = productThinkModelMapper.selectListByProductIdAndIdentifiersAndTypes( - productId, - Arrays.asList("post", "set", "get"), - Arrays.asList(IotProductThinkModelTypeEnum.EVENT.getType(), IotProductThinkModelTypeEnum.SERVICE.getType()) - ); - - // 3.1 使用 diffList 方法比较新旧列表 - List> diffResult = diffList(oldFunctionList, newFunctionList, - // 继续使用 identifier 和 type 进行比较:这样可以准确地匹配对应的功能对象。 - (oldFunc, newFunc) -> Objects.equals(oldFunc.getIdentifier(), newFunc.getIdentifier()) - && Objects.equals(oldFunc.getType(), newFunc.getType())); - List createList = diffResult.get(0); // 需要新增的 - List updateList = diffResult.get(1); // 需要更新的 - List deleteList = diffResult.get(2); // 需要删除的 - - // 3.2 批量执行数据库操作 - // 新增数据库中的新事件和服务列表 - if (CollUtil.isNotEmpty(createList)) { - productThinkModelMapper.insertBatch(createList); - } - // 更新数据库中的事件和服务列表 - if (CollUtil.isNotEmpty(updateList)) { - // 首先,为每个需要更新的对象设置其对应的 ID - updateList.forEach(updateFunc -> { - IotProductThinkModelDO oldFunc = findFunctionByIdentifierAndType( - oldFunctionList, updateFunc.getIdentifier(), updateFunc.getType()); - if (oldFunc != null) { - updateFunc.setId(oldFunc.getId()); - } - }); - // 过滤掉没有设置 ID 的对象 - List validUpdateList = updateList.stream() - .filter(func -> func.getId() != null) - .collect(Collectors.toList()); - // 执行批量更新 - if (CollUtil.isNotEmpty(validUpdateList)) { - productThinkModelMapper.updateBatch(validUpdateList); - } - } - - // 删除数据库中的旧事件和服务列表 - if (CollUtil.isNotEmpty(deleteList)) { - Set idsToDelete = CollectionUtils.convertSet(deleteList, IotProductThinkModelDO::getId); - productThinkModelMapper.deleteByIds(idsToDelete); - } - } - - /** - * 根据标识符和类型查找功能对象 - */ - private IotProductThinkModelDO findFunctionByIdentifierAndType(List functionList, - String identifier, Integer type) { - return CollUtil.findOne(functionList, func -> - Objects.equals(func.getIdentifier(), identifier) && Objects.equals(func.getType(), type)); - } - - /** - * 构建事件功能对象 - */ - private IotProductThinkModelDO buildEventFunctionDO(Long productId, String productKey, ThinkModelEvent event) { - return new IotProductThinkModelDO() - .setProductId(productId) - .setProductKey(productKey) - .setIdentifier(event.getIdentifier()) - .setName(event.getName()) - .setDescription(event.getDescription()) - .setType(IotProductThinkModelTypeEnum.EVENT.getType()) - .setEvent(event); - } - - /** - * 构建服务功能对象 - */ - private IotProductThinkModelDO buildServiceFunctionDO(Long productId, String productKey, ThinkModelService service) { - return new IotProductThinkModelDO() - .setProductId(productId) - .setProductKey(productKey) - .setIdentifier(service.getIdentifier()) - .setName(service.getName()) - .setDescription(service.getDescription()) - .setType(IotProductThinkModelTypeEnum.SERVICE.getType()) - .setService(service); - } - - /** - * 生成属性上报事件 - */ - private ThinkModelEvent generatePropertyPostEvent(List propertyList) { - if (CollUtil.isEmpty(propertyList)) { - return null; - } - - ThinkModelEvent event = new ThinkModelEvent() - .setIdentifier("post") - .setName("属性上报") - .setType("info") - .setDescription("属性上报事件") - .setMethod("thing.event.property.post"); - - // 将属性列表转换为事件的输出参数 - List outputData = new ArrayList<>(); - for (IotProductThinkModelDO thinkModel : propertyList) { - ThinkModelArgument arg = new ThinkModelArgument() - .setIdentifier(thinkModel.getIdentifier()) - .setName(thinkModel.getName()) - .setProperty(thinkModel.getProperty()) - .setDescription(thinkModel.getDescription()) - .setDirection("output"); // 设置为输出参数 - outputData.add(arg); - } - event.setOutputData(outputData); - return event; - } - - /** - * 生成属性设置服务 - */ - private ThinkModelService generatePropertySetService(List propertyList) { - if (propertyList == null || propertyList.isEmpty()) { - return null; - } - - List inputData = new ArrayList<>(); - for (IotProductThinkModelDO thinkModel : propertyList) { - ThinkModelProperty property = thinkModel.getProperty(); - if (IotProductThinkModelAccessModeEnum.READ_WRITE.getMode().equals(property.getAccessMode())) { - ThinkModelArgument arg = new ThinkModelArgument() - .setIdentifier(property.getIdentifier()) - .setName(property.getName()) - .setProperty(property) - .setDescription(property.getDescription()) - .setDirection("input"); // 设置为输入参数 - inputData.add(arg); - } - } - if (inputData.isEmpty()) { - // 如果没有可写属性,不生成属性设置服务 - return null; - } - - // 属性设置服务一般不需要输出参数 - return new ThinkModelService() - .setIdentifier("set") - .setName("属性设置") - .setCallType("async") - .setDescription("属性设置服务") - .setMethod("thing.service.property.set") - .setInputData(inputData) - // 属性设置服务一般不需要输出参数 - .setOutputData(new ArrayList<>()); - } - - /** - * 生成属性获取服务 - */ - private ThinkModelService generatePropertyGetService(List propertyList) { - if (propertyList == null || propertyList.isEmpty()) { - return null; - } - - List outputData = new ArrayList<>(); - for (IotProductThinkModelDO functionDO : propertyList) { - ThinkModelProperty property = functionDO.getProperty(); - if (ObjectUtils.equalsAny(property.getAccessMode(), - IotProductThinkModelAccessModeEnum.READ_ONLY.getMode(), IotProductThinkModelAccessModeEnum.READ_WRITE.getMode())) { - ThinkModelArgument arg = new ThinkModelArgument() - .setIdentifier(property.getIdentifier()) - .setName(property.getName()) - .setProperty(property) - .setDescription(property.getDescription()) - .setDirection("output"); // 设置为输出参数 - outputData.add(arg); - } - } - if (outputData.isEmpty()) { - // 如果没有可读属性,不生成属性获取服务 - return null; - } - - ThinkModelService service = new ThinkModelService() - .setIdentifier("get") - .setName("属性获取") - .setCallType("async") - .setDescription("属性获取服务") - .setMethod("thing.service.property.get"); - - // 定义输入参数:属性标识符列表 - ThinkModelArgument inputArg = new ThinkModelArgument() - .setIdentifier("properties") - .setName("属性标识符列表") - .setDescription("需要获取的属性标识符列表") - .setDirection("input"); // 设置为输入参数 - - // 创建数组类型,元素类型为文本类型(字符串)TODO @puhui999: 还得研究研究 - ThinkModelArrayDataSpecs arrayType = new ThinkModelArrayDataSpecs(); - arrayType.setDataType("array"); - inputArg.setProperty(new ThinkModelProperty().setIdentifier(inputArg.getIdentifier()).setName(inputArg.getName()) - .setDescription(inputArg.getDescription()).setDataSpecs(arrayType)); - - ThinkModelDateOrTextDataSpecs textType = new ThinkModelDateOrTextDataSpecs(); - textType.setDataType("text"); - inputArg.setProperty(new ThinkModelProperty().setIdentifier(inputArg.getIdentifier()).setName(inputArg.getName()) - .setDescription(inputArg.getDescription()).setDataSpecs(textType)); - - service.setInputData(Collections.singletonList(inputArg)); - service.setOutputData(outputData); - return service; - } - -} -- libgit2 0.21.4