From 6ebbcaa424cf2688482061baa8d1ce97eec9a4c5 Mon Sep 17 00:00:00 2001 From: wangwei_123 <1255324804@qq.com> Date: Thu, 16 Oct 2025 10:28:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E6=8C=81=E8=A1=A8=E5=A2=9E=E5=8A=A0mq?= =?UTF-8?q?tt=EF=BC=8Ckafka?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cc-admin-master/pom.xml | 2 +- cc-admin-master/tmp/.scr/auto_export.py | 403 ----------- cc-admin-master/yudao-module-hand-mqtt/pom.xml | 63 ++ .../module/mqtt/config/BatchProcessorConfig.java | 52 ++ .../module/mqtt/config/TdengineBatchConfig.java | 89 +++ .../yudao/module/mqtt/kafka/KafkaConfig.java | 34 + .../module/mqtt/kafka/KafkaMessageConsumer.java | 58 ++ .../yudao/module/mqtt/kafka/KafkaTopicType.java | 44 ++ .../cn/iocoder/yudao/module/mqtt/mqtt/Client.java | 150 +++++ .../yudao/module/mqtt/mqtt/MqttConnectedEvent.java | 9 + .../yudao/module/mqtt/mqtt/OnMessageCallback.java | 68 ++ .../yudao/module/mqtt/mqtt/ThreadPoolConfig.java | 31 + .../mqtt/processor/DeviceMessageProcessor.java | 505 ++++++++++++++ .../hand/controller/admin/AlarmRuleController.java | 8 +- .../hand/controller/admin/AlarmTypeController.java | 8 +- .../hand/controller/admin/FactoryController.java | 107 +++ .../controller/admin/FenceAlarmController.java | 8 +- .../hand/controller/admin/FenceController.java | 12 +- .../hand/controller/admin/GasTypeController.java | 8 +- .../hand/controller/admin/HandAlarmController.java | 8 +- .../controller/admin/HandDetectorController.java | 39 +- .../controller/admin/HandTdengineController.java | 66 ++ .../yudao/module/hand/controller/package-info.java | 2 +- .../iocoder/yudao/module/hand/dal/AlarmRuleDO.java | 23 +- .../iocoder/yudao/module/hand/dal/AlarmTypeDO.java | 16 +- .../iocoder/yudao/module/hand/dal/FactoryDO.java | 97 +++ .../yudao/module/hand/dal/FenceAlarmDO.java | 37 +- .../cn/iocoder/yudao/module/hand/dal/FenceDO.java | 19 +- .../iocoder/yudao/module/hand/dal/GasTypeDO.java | 20 +- .../iocoder/yudao/module/hand/dal/HandAlarmDO.java | 31 +- .../yudao/module/hand/dal/HandDetectorDO.java | 37 +- .../yudao/module/hand/enums/AlarmLevelEnum.java | 48 ++ .../iocoder/yudao/module/hand/enums/AlarmType.java | 53 ++ .../yudao/module/hand/enums/EnableStatus.java | 14 + .../module/hand/enums/ErrorCodeConstants.java | 6 + .../yudao/module/hand/enums/FenceStatusType.java | 52 ++ .../iocoder/yudao/module/hand/enums/FenceType.java | 52 ++ .../yudao/module/hand/enums/HandAlarmType.java | 52 ++ .../yudao/module/hand/enums/MaxDirection.java | 14 + .../yudao/module/hand/enums/OnlineStatusType.java | 52 ++ .../yudao/module/hand/mapper/AlarmRuleMapper.java | 3 - .../yudao/module/hand/mapper/AlarmTypeMapper.java | 3 - .../yudao/module/hand/mapper/FactoryMapper.java | 41 ++ .../yudao/module/hand/mapper/FenceAlarmMapper.java | 3 - .../yudao/module/hand/mapper/FenceMapper.java | 3 - .../yudao/module/hand/mapper/GasTypeMapper.java | 3 - .../yudao/module/hand/mapper/HandAlarmMapper.java | 3 - .../module/hand/mapper/HandDetectorMapper.java | 12 +- .../yudao/module/hand/mapper/TdengineMapper.java | 30 + .../module/hand/service/AlarmRuleService.java | 11 +- .../module/hand/service/AlarmTypeService.java | 8 +- .../yudao/module/hand/service/FactoryService.java | 64 ++ .../module/hand/service/FenceAlarmService.java | 11 +- .../yudao/module/hand/service/FenceService.java | 16 +- .../yudao/module/hand/service/GasTypeService.java | 8 +- .../module/hand/service/HandAlarmService.java | 10 +- .../module/hand/service/HandDetectorService.java | 16 +- .../yudao/module/hand/service/TdengineService.java | 20 + .../hand/service/impl/AlarmRuleServiceImpl.java | 68 +- .../hand/service/impl/AlarmTypeServiceImpl.java | 10 +- .../hand/service/impl/FactoryServiceImpl.java | 88 +++ .../hand/service/impl/FenceAlarmServiceImpl.java | 16 +- .../module/hand/service/impl/FenceServiceImpl.java | 57 +- .../hand/service/impl/GasTypeServiceImpl.java | 13 +- .../hand/service/impl/HandAlarmServiceImpl.java | 22 +- .../hand/service/impl/HandDetectorServiceImpl.java | 184 ++++- .../hand/service/impl/TdengineServiceImpl.java | 100 +++ .../module/hand/util/BatteryConverterUtils.java | 76 +++ .../module/hand/util/CoordinateTransferUtils.java | 188 ++++++ .../yudao/module/hand/util/GeofenceUtils.java | 284 ++++++++ .../yudao/module/hand/util/RedisKeyUtil.java | 56 ++ .../iocoder/yudao/module/hand/util/RedisUtil.java | 742 +++++++++++++++++++++ .../yudao/module/hand/vo/AlarmRulePageReqVO.java | 8 +- .../yudao/module/hand/vo/AlarmRuleRespVO.java | 14 +- .../yudao/module/hand/vo/AlarmRuleSaveReqVO.java | 16 +- .../yudao/module/hand/vo/AlarmTypePageReqVO.java | 6 +- .../yudao/module/hand/vo/AlarmTypeRespVO.java | 11 +- .../yudao/module/hand/vo/AlarmTypeSaveReqVO.java | 17 +- .../yudao/module/hand/vo/FactoryPageReqVO.java | 68 ++ .../yudao/module/hand/vo/FactoryRespVO.java | 86 +++ .../yudao/module/hand/vo/FactorySaveReqVO.java | 68 ++ .../yudao/module/hand/vo/FenceAlarmPageReqVO.java | 18 +- .../yudao/module/hand/vo/FenceAlarmRespVO.java | 19 +- .../yudao/module/hand/vo/FenceAlarmSaveReqVO.java | 20 +- .../yudao/module/hand/vo/FencePageReqVO.java | 15 +- .../iocoder/yudao/module/hand/vo/FencePointVo.java | 19 + .../iocoder/yudao/module/hand/vo/FenceRespVO.java | 15 +- .../yudao/module/hand/vo/FenceSaveReqVO.java | 12 +- .../yudao/module/hand/vo/GasTypePageReqVO.java | 14 +- .../yudao/module/hand/vo/GasTypeRespVO.java | 15 +- .../yudao/module/hand/vo/GasTypeSaveReqVO.java | 12 +- .../cn/iocoder/yudao/module/hand/vo/Geofence.java | 47 ++ .../yudao/module/hand/vo/HandAlarmPageReqVO.java | 17 +- .../yudao/module/hand/vo/HandAlarmRespVO.java | 17 +- .../yudao/module/hand/vo/HandAlarmSaveReqVO.java | 29 +- .../iocoder/yudao/module/hand/vo/HandDataVo.java | 104 +++ .../module/hand/vo/HandDetectorPageReqVO.java | 18 +- .../yudao/module/hand/vo/HandDetectorRespVO.java | 16 +- .../module/hand/vo/HandDetectorSaveReqVO.java | 18 +- .../yudao/module/hand/vo/HandOriginalLog.java | 17 + .../yudao/module/hand/vo/HandTdenginePageVO.java | 19 + .../yudao/module/hand/vo/TdengineDataVo.java | 37 + .../src/main/resources/mapper/FactoryMapper.xml | 12 + .../main/resources/mapper/HandDetectorMapper.xml | 6 + .../src/main/resources/mapper/TdengineMapper.xml | 77 +++ cc-admin-master/yudao-module-iot/pom.xml | 26 - .../yudao-module-iot/yudao-module-iot-api/pom.xml | 53 -- .../iot/api/device/IotDeviceUpstreamApi.java | 93 --- .../downstream/IotDeviceConfigSetReqDTO.java | 22 - .../IotDeviceDownstreamAbstractReqDTO.java | 30 - .../downstream/IotDeviceOtaUpgradeReqDTO.java | 66 -- .../downstream/IotDevicePropertyGetReqDTO.java | 24 - .../downstream/IotDevicePropertySetReqDTO.java | 22 - .../downstream/IotDeviceServiceInvokeReqDTO.java | 26 - .../control/upstream/IotDeviceEmqxAuthReqDTO.java | 34 - .../upstream/IotDeviceEventReportReqDTO.java | 26 - .../upstream/IotDeviceOtaProgressReqDTO.java | 35 - .../control/upstream/IotDeviceOtaPullReqDTO.java | 21 - .../control/upstream/IotDeviceOtaReportReqDTO.java | 21 - .../upstream/IotDevicePropertyReportReqDTO.java | 22 - .../control/upstream/IotDeviceRegisterReqDTO.java | 12 - .../upstream/IotDeviceRegisterSubReqDTO.java | 43 -- .../upstream/IotDeviceStateUpdateReqDTO.java | 23 - .../upstream/IotDeviceTopologyAddReqDTO.java | 44 -- .../upstream/IotDeviceUpstreamAbstractReqDTO.java | 45 -- .../upstream/IotPluginInstanceHeartbeatReqDTO.java | 44 -- .../module/iot/api/device/dto/package-info.java | 4 - .../iocoder/yudao/module/iot/api/package-info.java | 6 - .../yudao/module/iot/enums/ApiConstants.java | 16 - .../yudao/module/iot/enums/DictTypeConstants.java | 22 - .../yudao/module/iot/enums/ErrorCodeConstants.java | 75 --- .../device/IotDeviceMessageIdentifierEnum.java | 44 -- .../iot/enums/device/IotDeviceMessageTypeEnum.java | 37 - .../iot/enums/device/IotDeviceStateEnum.java | 42 -- .../enums/ota/IotOtaUpgradeRecordStatusEnum.java | 38 -- .../iot/enums/ota/IotOtaUpgradeTaskScopeEnum.java | 33 - .../iot/enums/ota/IotOtaUpgradeTaskStatusEnum.java | 35 - .../iot/enums/plugin/IotPluginDeployTypeEnum.java | 37 - .../iot/enums/plugin/IotPluginStatusEnum.java | 37 - .../module/iot/enums/plugin/IotPluginTypeEnum.java | 37 - .../iot/enums/product/IotDataFormatEnum.java | 38 -- .../module/iot/enums/product/IotNetTypeEnum.java | 39 -- .../enums/product/IotProductDeviceTypeEnum.java | 59 -- .../iot/enums/product/IotProductStatusEnum.java | 37 - .../iot/enums/product/IotProtocolTypeEnum.java | 40 -- .../iot/enums/product/IotValidateTypeEnum.java | 37 - .../enums/rule/IotAlertConfigReceiveTypeEnum.java | 31 - .../iot/enums/rule/IotDataBridgeDirectionEnum.java | 30 - .../iot/enums/rule/IotDataBridgeTypeEnum.java | 42 -- .../iot/enums/rule/IotRuleSceneActionTypeEnum.java | 31 - ...SceneTriggerConditionParameterOperatorEnum.java | 64 -- .../enums/rule/IotRuleSceneTriggerTypeEnum.java | 30 - .../enums/thingmodel/IotDataSpecsDataTypeEnum.java | 37 - .../thingmodel/IotThingModelAccessModeEnum.java | 30 - .../IotThingModelParamDirectionEnum.java | 31 - .../IotThingModelServiceCallTypeEnum.java | 30 - .../IotThingModelServiceEventTypeEnum.java | 31 - .../enums/thingmodel/IotThingModelTypeEnum.java | 38 -- .../yudao-module-iot/yudao-module-iot-biz/pom.xml | 137 ---- .../cn/iocoder/yudao/module/iot/ScriptTest.java | 61 -- .../iot/api/device/IoTDeviceUpstreamApiImpl.java | 77 --- .../iocoder/yudao/module/iot/api/package-info.java | 6 - .../admin/device/IotDeviceController.http | 75 --- .../admin/device/IotDeviceController.java | 188 ------ .../admin/device/IotDeviceGroupController.java | 88 --- .../admin/device/IotDeviceLogController.java | 39 -- .../admin/device/IotDevicePropertyController.java | 95 --- .../vo/control/IotDeviceDownstreamReqVO.java | 30 - .../device/vo/control/IotDeviceUpstreamReqVO.java | 30 - .../device/vo/data/IotDeviceLogPageReqVO.java | 22 - .../admin/device/vo/data/IotDeviceLogRespVO.java | 36 - .../vo/data/IotDevicePropertyHistoryPageReqVO.java | 35 - .../device/vo/data/IotDevicePropertyRespVO.java | 20 - .../device/vo/device/IotDeviceImportExcelVO.java | 37 - .../device/vo/device/IotDeviceImportRespVO.java | 23 - .../IotDeviceMqttConnectionParamsRespVO.java | 25 - .../admin/device/vo/device/IotDevicePageReqVO.java | 34 - .../admin/device/vo/device/IotDeviceRespVO.java | 93 --- .../admin/device/vo/device/IotDeviceSaveReqVO.java | 44 -- .../vo/device/IotDeviceUpdateGroupReqVO.java | 21 - .../device/vo/group/IotDeviceGroupPageReqVO.java | 25 - .../device/vo/group/IotDeviceGroupRespVO.java | 30 - .../device/vo/group/IotDeviceGroupSaveReqVO.java | 26 - .../admin/ota/IotOtaFirmwareController.java | 62 -- .../admin/ota/IotOtaUpgradeRecordController.java | 75 --- .../admin/ota/IotOtaUpgradeTaskController.java | 64 -- .../ota/vo/firmware/IotOtaFirmwareCreateReqVO.java | 38 -- .../ota/vo/firmware/IotOtaFirmwarePageReqVO.java | 23 - .../ota/vo/firmware/IotOtaFirmwareRespVO.java | 83 --- .../ota/vo/firmware/IotOtaFirmwareUpdateReqVO.java | 24 - .../record/IotOtaUpgradeRecordPageReqVO.java | 30 - .../upgrade/record/IotOtaUpgradeRecordRespVO.java | 107 --- .../upgrade/task/IotOtaUpgradeTaskPageReqVO.java | 25 - .../vo/upgrade/task/IotOtaUpgradeTaskRespVO.java | 82 --- .../upgrade/task/IotOtaUpgradeTaskSaveReqVO.java | 61 -- .../admin/plugin/PluginConfigController.java | 90 --- .../plugin/vo/config/PluginConfigImportReqVO.java | 19 - .../plugin/vo/config/PluginConfigPageReqVO.java | 20 - .../admin/plugin/vo/config/PluginConfigRespVO.java | 54 -- .../plugin/vo/config/PluginConfigSaveReqVO.java | 56 -- .../plugin/vo/config/PluginConfigStatusReqVO.java | 19 - .../vo/instance/PluginInstancePageReqVO.java | 35 - .../plugin/vo/instance/PluginInstanceRespVO.java | 34 - .../product/IotProductCategoryController.java | 86 --- .../admin/product/IotProductController.java | 132 ---- .../vo/category/IotProductCategoryPageReqVO.java | 23 - .../vo/category/IotProductCategoryRespVO.java | 33 - .../vo/category/IotProductCategorySaveReqVO.java | 29 - .../product/vo/product/IotProductPageReqVO.java | 19 - .../admin/product/vo/product/IotProductRespVO.java | 87 --- .../product/vo/product/IotProductSaveReqVO.java | 60 -- .../admin/rule/IotDataBridgeController.java | 72 -- .../admin/rule/IotRuleSceneController.java | 27 - .../rule/vo/databridge/IotDataBridgePageReqVO.java | 29 - .../rule/vo/databridge/IotDataBridgeRespVO.java | 37 - .../rule/vo/databridge/IotDataBridgeSaveReqVO.java | 46 -- .../config/IotDataBridgeAbstractConfig.java | 35 - .../databridge/config/IotDataBridgeHttpConfig.java | 36 - .../config/IotDataBridgeKafkaMQConfig.java | 35 - .../databridge/config/IotDataBridgeMqttConfig.java | 34 - .../config/IotDataBridgeRabbitMQConfig.java | 46 -- .../config/IotDataBridgeRedisStreamMQConfig.java | 35 - .../config/IotDataBridgeRocketMQConfig.java | 39 -- .../iot/controller/admin/rule/vo/package-info.java | 2 - .../admin/statistics/IotStatisticsController.java | 79 --- .../IotStatisticsDeviceMessageSummaryRespVO.java | 19 - .../admin/statistics/vo/IotStatisticsReqVO.java | 21 - .../statistics/vo/IotStatisticsSummaryRespVO.java | 51 -- .../admin/thingmodel/IotThingModelController.http | 181 ----- .../admin/thingmodel/IotThingModelController.java | 93 --- .../admin/thingmodel/model/ThingModelEvent.java | 55 -- .../admin/thingmodel/model/ThingModelParam.java | 63 -- .../admin/thingmodel/model/ThingModelProperty.java | 63 -- .../admin/thingmodel/model/ThingModelService.java | 62 -- .../model/dataType/ThingModelArrayDataSpecs.java | 34 - .../dataType/ThingModelBoolOrEnumDataSpecs.java | 31 - .../model/dataType/ThingModelDataSpecs.java | 35 - .../dataType/ThingModelDateOrTextDataSpecs.java | 30 - .../model/dataType/ThingModelNumericDataSpec.java | 51 -- .../model/dataType/ThingModelStructDataSpecs.java | 52 -- .../thingmodel/vo/IotThingModelListReqVO.java | 27 - .../thingmodel/vo/IotThingModelPageReqVO.java | 28 - .../admin/thingmodel/vo/IotThingModelRespVO.java | 54 -- .../thingmodel/vo/IotThingModelSaveReqVO.java | 57 -- .../IotThinkModelFunctionController.http | 112 ---- .../yudao/module/iot/controller/package-info.java | 6 - .../yudao/module/iot/convert/package-info.java | 6 - .../convert/thingmodel/IotThingModelConvert.java | 50 -- .../iot/dal/dataobject/device/IotDeviceDO.java | 173 ----- .../dal/dataobject/device/IotDeviceGroupDO.java | 42 -- .../iot/dal/dataobject/device/IotDeviceLogDO.java | 95 --- .../dal/dataobject/device/IotDevicePropertyDO.java | 35 - .../iot/dal/dataobject/ota/IotOtaFirmwareDO.java | 80 --- .../dal/dataobject/ota/IotOtaUpgradeRecordDO.java | 92 --- .../dal/dataobject/ota/IotOtaUpgradeTaskDO.java | 72 -- .../dal/dataobject/plugin/IotPluginConfigDO.java | 93 --- .../dal/dataobject/plugin/IotPluginInstanceDO.java | 70 -- .../dataobject/product/IotProductCategoryDO.java | 46 -- .../iot/dal/dataobject/product/IotProductDO.java | 98 --- .../iot/dal/dataobject/rule/IotAlertConfig.java | 77 --- .../iot/dal/dataobject/rule/IotAlertRecordDO.java | 77 --- .../iot/dal/dataobject/rule/IotDataBridgeDO.java | 67 -- .../iot/dal/dataobject/rule/IotRuleSceneDO.java | 243 ------- .../dal/dataobject/thingmodel/IotThingModelDO.java | 91 --- .../iot/dal/mysql/device/IotDeviceGroupMapper.java | 35 - .../iot/dal/mysql/device/IotDeviceMapper.java | 96 --- .../iot/dal/mysql/ota/IotOtaFirmwareMapper.java | 41 -- .../dal/mysql/ota/IotOtaUpgradeRecordMapper.java | 159 ----- .../iot/dal/mysql/ota/IotOtaUpgradeTaskMapper.java | 57 -- .../dal/mysql/plugin/IotPluginConfigMapper.java | 33 - .../dal/mysql/plugin/IotPluginInstanceMapper.java | 24 - .../mysql/product/IotProductCategoryMapper.java | 38 -- .../iot/dal/mysql/product/IotProductMapper.java | 41 -- .../iot/dal/mysql/rule/IotDataBridgeMapper.java | 26 - .../iot/dal/mysql/rule/IotRuleSceneMapper.java | 10 - .../dal/mysql/thingmodel/IotThingModelMapper.java | 88 --- .../module/iot/dal/redis/RedisKeyConstants.java | 55 -- .../dal/redis/device/DevicePropertyRedisDAO.java | 50 -- .../dal/redis/device/DeviceReportTimeRedisDAO.java | 33 - .../plugin/DevicePluginProcessIdRedisDAO.java | 25 - .../iot/dal/tdengine/IotDeviceLogMapper.java | 76 --- .../iot/dal/tdengine/IotDevicePropertyMapper.java | 90 --- .../framework/job/config/IotJobConfiguration.java | 24 - .../framework/job/core/IotSchedulerManager.java | 186 ------ .../yudao/module/iot/framework/package-info.java | 6 - .../plugin/config/IotPluginConfiguration.java | 46 -- .../plugin/core/IotPluginStartRunner.java | 52 -- .../plugin/core/IotPluginStateListener.java | 21 - .../security/config/SecurityConfiguration.java | 29 - .../iot/framework/security/core/package-info.java | 4 - .../tdengine/config/TDengineTableInitRunner.java | 34 - .../tdengine/core/TDengineTableField.java | 58 -- .../tdengine/core/annotation/TDengineDS.java | 17 - .../iot/framework/tdengine/package-info.java | 4 - .../framework/web/config/IotWebConfiguration.java | 24 - .../module/iot/framework/web/package-info.java | 4 - .../iot/job/device/IotDeviceOfflineCheckJob.java | 75 --- .../iot/job/plugin/IotPluginInstancesJob.java | 39 -- .../yudao/module/iot/job/rule/IotRuleSceneJob.java | 58 -- .../device/IotDeviceLogMessageConsumer.java | 30 - .../device/IotDeviceOnlineMessageConsumer.java | 85 --- .../device/IotDevicePropertyMessageConsumer.java | 40 -- .../consumer/rule/IotRuleSceneMessageHandler.java | 30 - .../module/iot/mq/message/IotDeviceMessage.java | 76 --- .../iot/mq/producer/device/IotDeviceProducer.java | 31 - .../yudao/module/iot/mq/producer/package-info.java | 4 - .../iot/service/device/IotDeviceGroupService.java | 97 --- .../service/device/IotDeviceGroupServiceImpl.java | 94 --- .../iot/service/device/IotDeviceService.java | 222 ------ .../iot/service/device/IotDeviceServiceImpl.java | 454 ------------- .../device/control/IotDeviceDownstreamService.java | 24 - .../control/IotDeviceDownstreamServiceImpl.java | 354 ---------- .../device/control/IotDeviceUpstreamService.java | 72 -- .../control/IotDeviceUpstreamServiceImpl.java | 344 ---------- .../service/device/data/IotDeviceLogService.java | 75 --- .../device/data/IotDeviceLogServiceImpl.java | 112 ---- .../device/data/IotDevicePropertyService.java | 71 -- .../device/data/IotDevicePropertyServiceImpl.java | 200 ------ .../iot/service/ota/IotOtaFirmwareService.java | 59 -- .../iot/service/ota/IotOtaFirmwareServiceImpl.java | 104 --- .../service/ota/IotOtaUpgradeRecordService.java | 104 --- .../ota/IotOtaUpgradeRecordServiceImpl.java | 229 ------- .../iot/service/ota/IotOtaUpgradeTaskService.java | 68 -- .../service/ota/IotOtaUpgradeTaskServiceImpl.java | 207 ------ .../iot/service/plugin/IotPluginConfigService.java | 100 --- .../service/plugin/IotPluginConfigServiceImpl.java | 188 ------ .../service/plugin/IotPluginInstanceService.java | 79 --- .../plugin/IotPluginInstanceServiceImpl.java | 231 ------- .../service/product/IotProductCategoryService.java | 103 --- .../product/IotProductCategoryServiceImpl.java | 123 ---- .../iot/service/product/IotProductService.java | 106 --- .../iot/service/product/IotProductServiceImpl.java | 147 ---- .../iot/service/rule/IotDataBridgeService.java | 54 -- .../iot/service/rule/IotDataBridgeServiceImpl.java | 70 -- .../iot/service/rule/IotRuleSceneService.java | 44 -- .../iot/service/rule/IotRuleSceneServiceImpl.java | 438 ------------ .../service/rule/action/IotRuleSceneAction.java | 34 - .../rule/action/IotRuleSceneAlertAction.java | 28 - .../rule/action/IotRuleSceneDataBridgeAction.java | 60 -- .../action/IotRuleSceneDeviceControlAction.java | 56 -- .../AbstractCacheableDataBridgeExecute.java | 114 ---- .../action/databridge/IotDataBridgeExecute.java | 46 -- .../databridge/IotHttpDataBridgeExecute.java | 89 --- .../databridge/IotKafkaMQDataBridgeExecute.java | 78 --- .../databridge/IotRabbitMQDataBridgeExecute.java | 77 --- .../IotRedisStreamMQDataBridgeExecute.java | 96 --- .../databridge/IotRocketMQDataBridgeExecute.java | 65 -- .../service/thingmodel/IotThingModelService.java | 93 --- .../thingmodel/IotThingModelServiceImpl.java | 373 ----------- .../yudao/module/iot/util/MqttSignUtils.java | 69 -- .../resources/mapper/device/IotDeviceLogMapper.xml | 122 ---- .../resources/mapper/device/IotDeviceMapper.xml | 25 - .../mapper/device/IotDevicePropertyMapper.xml | 78 --- .../databridge/IotDataBridgeExecuteTest.java | 154 ----- .../yudao-module-iot-plugins/pom.xml | 27 - .../yudao-module-iot-plugin-common/pom.xml | 52 -- .../config/IotPluginCommonAutoConfiguration.java | 52 -- .../common/config/IotPluginCommonProperties.java | 59 -- .../downstream/IotDeviceDownstreamHandler.java | 55 -- .../downstream/IotDeviceDownstreamServer.java | 94 --- .../router/IotDeviceConfigSetVertxHandler.java | 73 -- .../router/IotDeviceOtaUpgradeVertxHandler.java | 78 --- .../router/IotDevicePropertyGetVertxHandler.java | 75 --- .../router/IotDevicePropertySetVertxHandler.java | 75 --- .../router/IotDeviceServiceInvokeVertxHandler.java | 80 --- .../heartbeat/IotPluginInstanceHeartbeatJob.java | 52 -- .../module/iot/plugin/common/package-info.java | 2 - .../plugin/common/pojo/IotStandardResponse.java | 94 --- .../common/upstream/IotDeviceUpstreamClient.java | 91 --- .../plugin/common/util/IotPluginCommonUtils.java | 76 --- ...rk.boot.autoconfigure.AutoConfiguration.imports | 1 - .../yudao-module-iot-plugin-emqx/plugin.properties | 6 - .../yudao-module-iot-plugin-emqx/pom.xml | 169 ----- .../src/main/assembly/assembly.xml | 31 - .../iot/plugin/emqx/IotEmqxPluginApplication.java | 22 - .../iot/plugin/emqx/config/IotEmqxPlugin.java | 64 -- .../config/IotPluginEmqxAutoConfiguration.java | 54 -- .../emqx/config/IotPluginEmqxProperties.java | 50 -- .../downstream/IotDeviceDownstreamHandlerImpl.java | 176 ----- .../emqx/upstream/IotDeviceUpstreamServer.java | 236 ------- .../upstream/router/IotDeviceAuthVertxHandler.java | 64 -- .../router/IotDeviceMqttMessageHandler.java | 296 -------- .../router/IotDeviceWebhookVertxHandler.java | 152 ----- .../src/main/resources/application.yml | 20 - .../yudao-module-iot-plugin-http/plugin.properties | 6 - .../yudao-module-iot-plugin-http/pom.xml | 165 ----- .../src/main/assembly/assembly.xml | 24 - .../iot/plugin/http/IotHttpPluginApplication.java | 22 - .../iot/plugin/http/config/IotHttpVertxPlugin.java | 60 -- .../config/IotPluginHttpAutoConfiguration.java | 31 - .../http/config/IotPluginHttpProperties.java | 17 - .../downstream/IotDeviceDownstreamHandlerImpl.java | 44 -- .../http/upstream/IotDeviceUpstreamServer.java | 83 --- .../router/IotDeviceUpstreamVertxHandler.java | 188 ------ .../src/main/resources/application.yml | 13 - .../yudao-module-iot-plugin-mqtt/plugin.properties | 7 - .../yudao-module-iot-plugin-mqtt/pom.xml | 156 ----- .../src/main/assembly/assembly.xml | 31 - .../yudao/module/iot/plugin/MqttPlugin.java | 37 - .../module/iot/plugin/MqttServerExtension.java | 232 ------- .../system/service/auth/AdminAuthServiceImpl.java | 4 - cc-admin-master/yudao-server/pom.xml | 11 +- .../src/main/resources/application-local.yaml | 53 +- .../src/main/resources/application-prod.yaml | 20 + .../src/main/resources/application.yaml | 3 +- 405 files changed, 4619 insertions(+), 20422 deletions(-) delete mode 100644 cc-admin-master/tmp/.scr/auto_export.py create mode 100644 cc-admin-master/yudao-module-hand-mqtt/pom.xml create mode 100644 cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/config/BatchProcessorConfig.java create mode 100644 cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/config/TdengineBatchConfig.java create mode 100644 cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/kafka/KafkaConfig.java create mode 100644 cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/kafka/KafkaMessageConsumer.java create mode 100644 cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/kafka/KafkaTopicType.java create mode 100644 cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/Client.java create mode 100644 cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/MqttConnectedEvent.java create mode 100644 cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/OnMessageCallback.java create mode 100644 cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/ThreadPoolConfig.java create mode 100644 cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/processor/DeviceMessageProcessor.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/FactoryController.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandTdengineController.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/FactoryDO.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/AlarmLevelEnum.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/AlarmType.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/EnableStatus.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/FenceStatusType.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/FenceType.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/HandAlarmType.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/MaxDirection.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/OnlineStatusType.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/FactoryMapper.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/TdengineMapper.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/FactoryService.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/TdengineService.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/FactoryServiceImpl.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/TdengineServiceImpl.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/BatteryConverterUtils.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/CoordinateTransferUtils.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/GeofenceUtils.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/RedisKeyUtil.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/RedisUtil.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FactoryPageReqVO.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FactoryRespVO.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FactorySaveReqVO.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FencePointVo.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/Geofence.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDataVo.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandOriginalLog.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandTdenginePageVO.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/TdengineDataVo.java create mode 100644 cc-admin-master/yudao-module-hand/src/main/resources/mapper/FactoryMapper.xml create mode 100644 cc-admin-master/yudao-module-hand/src/main/resources/mapper/TdengineMapper.xml delete mode 100644 cc-admin-master/yudao-module-iot/pom.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/pom.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/IotDeviceUpstreamApi.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceConfigSetReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceDownstreamAbstractReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceOtaUpgradeReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDevicePropertyGetReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDevicePropertySetReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceServiceInvokeReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceEmqxAuthReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceEventReportReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceOtaProgressReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceOtaPullReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceOtaReportReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDevicePropertyReportReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceRegisterReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceRegisterSubReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceStateUpdateReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceTopologyAddReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceUpstreamAbstractReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotPluginInstanceHeartbeatReqDTO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/package-info.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/package-info.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ApiConstants.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/DictTypeConstants.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/device/IotDeviceMessageIdentifierEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/device/IotDeviceMessageTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/device/IotDeviceStateEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ota/IotOtaUpgradeRecordStatusEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ota/IotOtaUpgradeTaskScopeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ota/IotOtaUpgradeTaskStatusEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginDeployTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginStatusEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotDataFormatEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotNetTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductDeviceTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductStatusEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProtocolTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotValidateTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotAlertConfigReceiveTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgeDirectionEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgeTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneActionTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneTriggerConditionParameterOperatorEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneTriggerTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotDataSpecsDataTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelAccessModeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelParamDirectionEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelServiceCallTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelServiceEventTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelTypeEnum.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/pom.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/ScriptTest.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/api/device/IoTDeviceUpstreamApiImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/api/package-info.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.http delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceGroupController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceLogController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDevicePropertyController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/control/IotDeviceDownstreamReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/control/IotDeviceUpstreamReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDeviceLogPageReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDeviceLogRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDevicePropertyHistoryPageReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDevicePropertyRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceImportExcelVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceImportRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceMqttConnectionParamsRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDevicePageReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceSaveReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceUpdateGroupReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/group/IotDeviceGroupPageReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/group/IotDeviceGroupRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/group/IotDeviceGroupSaveReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaFirmwareController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaUpgradeRecordController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaUpgradeTaskController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwareCreateReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwarePageReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwareRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwareUpdateReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/record/IotOtaUpgradeRecordPageReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/record/IotOtaUpgradeRecordRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/task/IotOtaUpgradeTaskPageReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/task/IotOtaUpgradeTaskRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/task/IotOtaUpgradeTaskSaveReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/PluginConfigController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigImportReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigPageReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigSaveReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigStatusReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/instance/PluginInstancePageReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/instance/PluginInstanceRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductCategoryController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/category/IotProductCategoryPageReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/category/IotProductCategoryRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/category/IotProductCategorySaveReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductPageReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductSaveReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/IotDataBridgeController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/IotRuleSceneController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgePageReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgeRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgeSaveReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeAbstractConfig.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeHttpConfig.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeKafkaMQConfig.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeMqttConfig.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRabbitMQConfig.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRedisStreamMQConfig.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRocketMQConfig.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/package-info.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/IotStatisticsController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsDeviceMessageSummaryRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsSummaryRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.http delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelEvent.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelParam.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelProperty.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArrayDataSpecs.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelBoolOrEnumDataSpecs.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDataSpecs.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDateOrTextDataSpecs.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelNumericDataSpec.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelStructDataSpecs.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelListReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelPageReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelRespVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelSaveReqVO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/IotThinkModelFunctionController.http delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/package-info.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/package-info.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thingmodel/IotThingModelConvert.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceGroupDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceLogDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDevicePropertyDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ota/IotOtaFirmwareDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ota/IotOtaUpgradeRecordDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ota/IotOtaUpgradeTaskDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugin/IotPluginConfigDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugin/IotPluginInstanceDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/product/IotProductCategoryDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/product/IotProductDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotAlertConfig.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotAlertRecordDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotDataBridgeDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotRuleSceneDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thingmodel/IotThingModelDO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceGroupMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaFirmwareMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaUpgradeRecordMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaUpgradeTaskMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/plugin/IotPluginConfigMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/plugin/IotPluginInstanceMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductCategoryMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/rule/IotDataBridgeMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/rule/IotRuleSceneMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thingmodel/IotThingModelMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/RedisKeyConstants.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/device/DevicePropertyRedisDAO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/device/DeviceReportTimeRedisDAO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/plugin/DevicePluginProcessIdRedisDAO.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDevicePropertyMapper.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/job/config/IotJobConfiguration.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/job/core/IotSchedulerManager.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/package-info.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/config/IotPluginConfiguration.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/core/IotPluginStartRunner.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/core/IotPluginStateListener.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/security/config/SecurityConfiguration.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/security/core/package-info.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/config/TDengineTableInitRunner.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/core/TDengineTableField.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/core/annotation/TDengineDS.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/package-info.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/web/config/IotWebConfiguration.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/web/package-info.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/device/IotDeviceOfflineCheckJob.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/plugin/IotPluginInstancesJob.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/rule/IotRuleSceneJob.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/device/IotDeviceLogMessageConsumer.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/device/IotDeviceOnlineMessageConsumer.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/device/IotDevicePropertyMessageConsumer.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/rule/IotRuleSceneMessageHandler.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/message/IotDeviceMessage.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/device/IotDeviceProducer.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/package-info.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceGroupService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceGroupServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceDownstreamService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceDownstreamServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceUpstreamService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceUpstreamServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDevicePropertyService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDevicePropertyServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaFirmwareService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaFirmwareServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeRecordService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeRecordServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeTaskService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeTaskServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginConfigService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginConfigServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginInstanceService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginInstanceServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotDataBridgeService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotDataBridgeServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotRuleSceneService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotRuleSceneServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneAction.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneAlertAction.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneDataBridgeAction.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneDeviceControlAction.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/AbstractCacheableDataBridgeExecute.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotDataBridgeExecute.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotHttpDataBridgeExecute.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotKafkaMQDataBridgeExecute.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRabbitMQDataBridgeExecute.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRedisStreamMQDataBridgeExecute.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRocketMQDataBridgeExecute.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelService.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelServiceImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/util/MqttSignUtils.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogMapper.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceMapper.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotDataBridgeExecuteTest.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/pom.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/pom.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/config/IotPluginCommonAutoConfiguration.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/config/IotPluginCommonProperties.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/IotDeviceDownstreamHandler.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/IotDeviceDownstreamServer.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDeviceConfigSetVertxHandler.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDeviceOtaUpgradeVertxHandler.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDevicePropertyGetVertxHandler.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDevicePropertySetVertxHandler.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDeviceServiceInvokeVertxHandler.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/heartbeat/IotPluginInstanceHeartbeatJob.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/package-info.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/pojo/IotStandardResponse.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/upstream/IotDeviceUpstreamClient.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/util/IotPluginCommonUtils.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/plugin.properties delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/pom.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/assembly/assembly.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/IotEmqxPluginApplication.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/config/IotEmqxPlugin.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/config/IotPluginEmqxAutoConfiguration.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/config/IotPluginEmqxProperties.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/downstream/IotDeviceDownstreamHandlerImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/IotDeviceUpstreamServer.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/router/IotDeviceAuthVertxHandler.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/router/IotDeviceMqttMessageHandler.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/router/IotDeviceWebhookVertxHandler.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/resources/application.yml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/plugin.properties delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/pom.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/assembly/assembly.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/IotHttpPluginApplication.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotHttpVertxPlugin.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotPluginHttpAutoConfiguration.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotPluginHttpProperties.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/downstream/IotDeviceDownstreamHandlerImpl.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/upstream/IotDeviceUpstreamServer.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/upstream/router/IotDeviceUpstreamVertxHandler.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/resources/application.yml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/plugin.properties delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/pom.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/src/main/assembly/assembly.xml delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/src/main/java/cn/iocoder/yudao/module/iot/plugin/MqttPlugin.java delete mode 100644 cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/src/main/java/cn/iocoder/yudao/module/iot/plugin/MqttServerExtension.java diff --git a/cc-admin-master/pom.xml b/cc-admin-master/pom.xml index c506bcc..3ccbdde 100644 --- a/cc-admin-master/pom.xml +++ b/cc-admin-master/pom.xml @@ -18,7 +18,7 @@ yudao-module-bpm yudao-module-report yudao-module-hand - + yudao-module-hand-mqtt ${project.artifactId} diff --git a/cc-admin-master/tmp/.scr/auto_export.py b/cc-admin-master/tmp/.scr/auto_export.py deleted file mode 100644 index d18707e..0000000 --- a/cc-admin-master/tmp/.scr/auto_export.py +++ /dev/null @@ -1,403 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -*- -from selenium import webdriver -from selenium.webdriver.common.by import By -from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as EC -from selenium.webdriver.common.action_chains import ActionChains -from selenium.webdriver.chrome.options import Options -import time -import sys -import getopt -import json -import os -import shutil -import platform -import re -# import traceback -import base64 -import io - -sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') - -# 默认文件下载目录 改成自己服务器的 -DEFAULT_BASE_DOWNLOAD_PATH = os.path.dirname(os.path.realpath('__file__')) + os.sep + "downloads" + os.sep -# update-begin---author:chenrui ---date:20240130 for:[QQYUN-8127]通过接口导出功能要获取token和查询参数------------ -# 临时下载目录 -TEMP_DOWNLOAD_PATH = os.sep + "temp" + os.sep -# update-end---author:chenrui ---date:20240130 for:[QQYUN-8127]通过接口导出功能要获取token和查询参数------------ - -# 默认积木报表访问地址 改成自己的 -DEFAULT_BASE_SHARE_VIEW_URL = "http://localhost:8085/jmreport/view/" - -# 结束日志标识 -LOG_END_MARK = "$JM$END$" - - -def append_common_params(payload: str, token: str) -> str: - """ - 拼接报表的通用参数 - :param payload: - :param token: - :return: - """ - if payload is None or len(payload) == 0: - return "" - if token is not None and len(token) > 0: - token = "token=" + token - if "?" in payload: - payload += "&" + token - else: - payload += "?" + token - if "?" in payload: - payload += "&directDld=1" - else: - payload += "?directDld=1" - return payload - - -def dict_2_str_payload(payload: dict) -> str: - """ - 字典数据转换为查询payload - :param payload: - :return: - """ - if payload is not None and len(payload) > 0: - return str("&".join([key + "=" + val for key, val in payload.items() if key is not None and len(key) > 0])) - else: - return "" - - -def init_args(argv=None): - """初始化参数""" - global opts - print('共有:', len(argv), '个参数。') - if len(argv) <= 0: - raise Exception('参数异常') - arg = argv[0] - if arg is not None and len(arg) > 0: - opts = json.loads(base64.b64decode(arg)) - # 批次号 - batch_no = None - # 导出类型 - export_type = 'PDF' - # 报表ids - report_ids = None - # 报表参数,与report_ids二选一 - report_params = list() - # 积木报表预览页面地址 - base_share_view_url = DEFAULT_BASE_SHARE_VIEW_URL - # 报表下载基础目录 - base_download_path = DEFAULT_BASE_DOWNLOAD_PATH - # token - token = '' - - if 'batch_no' in opts: - batch_no = opts['batch_no'] - if 'export_type' in opts: - export_type = opts['export_type'] - if 'report_ids' in opts: - report_ids = opts['report_ids'] - if 'report_params' in opts: - report_params = opts['report_params'] - if 'jimu_view_url' in opts: - base_share_view_url = opts['jimu_view_url'] - if 'base_download_path' in opts: - base_download_path = opts['base_download_path'] - if 'token' in opts: - token = opts['token'] - - if export_type.upper() == "EXCEL": - export_type = "Excel" - elif export_type.upper() == "PDF": - export_type = "PDF" - else: - export_type = "PDF" - - # 拼接报表查询参数 - reports: list[dict] = list() - if report_params is not None and len(report_params) > 0: - for report_param in report_params: - report_query = report_param['id'] - if 'params' in report_param: - params = report_param['params'] - if params is not None and len(params) > 0: - payload = dict_2_str_payload(params) - if payload is not None and len(payload) > 0: - report_query += "?" + payload - custom_export_type = export_type - if 'export_type' in report_param: - custom_export_type = report_param['export_type'] - custom_export_type = export_type if custom_export_type is None else custom_export_type - reports.append({"url": append_common_params(report_query, token), "export_type": custom_export_type}) - elif report_ids is not None and len(report_ids) > 0: - reports = [{"url": append_common_params(report_id, token), "export_type": export_type} for report_id in - report_ids] - - # 确保传入路径正确,统一修改所有的/ 和 \\为当前系统的盘符 - base_download_path = base_download_path.replace("/", os.sep).replace("\\", os.sep) - if not os.path.isabs(base_download_path): - raise Exception("导出失败,下载目录必须是绝对路径") - if "windows" in platform.platform().lower() and base_download_path.startswith("\\"): - # windows 系统下 并且没有写盘符时,拼接盘符 - run_path = os.path.dirname(os.path.realpath('__file__')) - base_download_path = os.path.splitdrive(run_path)[0] + base_download_path - - options = { - 'batch_no': batch_no, - 'export_type': export_type, - 'reports': reports, - "base_share_view_url": base_share_view_url, - "base_download_path": base_download_path - } - print("运行参数:" + json.dumps(options)) - return options - - -def auto_export(options): - print(" >>> java进入Python 脚本方法,options = ", options) - """ - 自动导出函数 - :param options: {batch_no:批次号,export_type:导出类型,reports:[{url:报表url,export_type:导出类型}]} - """ - # 整理参数 - batch_no = options['batch_no'] - - export_type = options['export_type'] - - reports = None - # 优先使用report - if "reports" in options: - reports = options['reports'] - - if not reports or reports is None: - if "report_ids" in options: - report_ids = options['report_ids'] - if not report_ids: - raise Exception('报表id不能为空') - else: - # reports 为空,将report_ids转换为reports - reports = [{"url": report_id, "export_type": export_type} for report_id in report_ids] - else: - raise Exception('报表id不能为空') - - if not batch_no or not reports: - raise Exception('批次编号或报表id不能为空') - - # 下载目录 - download_path = options["base_download_path"] + batch_no - - # 获取域名 - base_share_view_url = options["base_share_view_url"] - match = re.match(r'(http[s]?://[^/]+)', base_share_view_url) - if match: - base_url = match.group(1) - else: - base_url = "" - - # 获取webDriver - driver = build_web_driver(download_path, base_url) - - # 确保目录存在 - if os.path.exists(download_path) is False: - os.makedirs(download_path) - # update-begin---author:chenrui ---date:20240129 for:[QQYUN-8127]通过接口导出功能要获取token和查询参数------------ - else: - # 清空文件夹并重建 - shutil.rmtree(download_path) - os.makedirs(download_path) - - # 确保临时目录存在 - if os.path.exists(download_path + TEMP_DOWNLOAD_PATH) is False: - os.makedirs(download_path + TEMP_DOWNLOAD_PATH) - # update-end---author:chenrui ---date:20240129 for:[QQYUN-8127]通过接口导出功能要获取token和查询参数------------ - - downloaded_count = 0 - download_failure_rids = [] - - # 导出失败的报表标题 - failure_report_title = "" - # 开始自动导出 - for report in reports: - report_url = report['url'] - custom_export_type = report['export_type'] - if not custom_export_type: - custom_export_type = export_type - else: - if custom_export_type.upper() == "EXCEL": - custom_export_type = "Excel" - elif custom_export_type.upper() == "PDF": - custom_export_type = "PDF" - else: - custom_export_type = "PDF" - print("开始导出报表:" + report_url) - # 打开url网页 - driver.get(options["base_share_view_url"] + report_url) - # 等待数据查询完成 - export_el = WebDriverWait(driver, 10, 0.2).until_not( - EC.presence_of_element_located((By.CLASS_NAME, "ivu-spin-fullscreen")) - ) - # 等待导出按钮加载完成 - export_el = WebDriverWait(driver, 10, 0.2).until( - EC.presence_of_element_located((By.CLASS_NAME, "export")) - ) - # 获取title - title = driver.title - if len(title) > 0 and "-" in title: - title = title[:title.rindex("-")].strip() - print("报表名称:" + title) - if not download_check(download_path, title, custom_export_type.lower(), 1): - # 报表不存在,开始下载 - print("报表{}未下载,开始下载...".format(title)) - # 等待0.5秒,防止页面未完成渲染 - time.sleep(0.5) - # 鼠标移到导出按钮 - ActionChains(driver).move_to_element(export_el).perform() - # 点击导出pdf按钮 - driver.find_element(By.ID, custom_export_type).click() - # 检查是否下载完成 - if not download_check(download_path, title, custom_export_type.lower(), 30, 1): - print("报表{}下载失败".format(title)) - failure_report_title += title + " " - download_failure_rids.append(report_url) - else: - downloaded_count = downloaded_count + 1 - print("报表:" + report_url + "导出完成") - else: - # 报表存在 - downloaded_count = downloaded_count + 1 - # update-begin---author:chenrui ---date:20240129 for:统一py脚本的返回结果格式------------ - err_msg = "" - if len(reports) != downloaded_count: - err_msg = "报表[" + failure_report_title + "]导出失败" - result = { - "success": len(reports) == downloaded_count, - "message": err_msg, - "result": { - "report_count": len(reports), - "downloaded_count": downloaded_count, - "failure_rids": download_failure_rids, - "download_path": download_path, - **options - } - } - # update-end---author:chenrui ---date:20240129 for:统一py脚本的返回结果格式------------ - - # 退出浏览器 - driver.quit() - return result - - -def build_web_driver(download_path, safe_domain=""): - """ - 构建webDriver - :param safe_domain: 安全域名 - :param download_path: 下载目录 - :return: webDriver - """ - chrome_options = Options() - # 不使用沙箱 - chrome_options.add_argument('--no-sandbox') - # 将浏览器静音 - chrome_options.add_argument("--mute-audio") - # 当程序结束时,浏览器不会关闭 - # chrome_options.add_experimental_option("detach", True) - # 开启无界面浏览器(minos必须开启无界面) - chrome_options.add_argument("--headless") - # 禁用gpu - chrome_options.add_argument("--disable-gpu") - # 添加安全域名 - if safe_domain is not None and bool(safe_domain): - chrome_options.add_argument("--unsafely-treat-insecure-origin-as-secure=" + safe_domain) - if 'linux' in platform.platform().lower(): - # fix:DevToolsActivePort file doesn't - chrome_options.add_argument('--disable-dev-shm-usage') - chrome_options.add_argument('--remote-debugging-port=9222') - # 设置下载路径 - prefs = {'profile.default_content_settings.popups': 0, - 'download.prompt_for_download': False, - 'safebrowsing.disable_download_protection': True, - 'download.default_directory': download_path + TEMP_DOWNLOAD_PATH} - chrome_options.add_experimental_option('prefs', prefs) - # 忽略不安全的错误 - chrome_options.add_argument('ignore-certificate-errors') - # Chrome浏览器 - driver = webdriver.Chrome(options=chrome_options) - return driver - - -def download_check(check_path, check_file_name, check_ext, check_times=3, check_interval=5): - """ - 检测函数 - :param check_path:检测路径 - :param check_file_name: 检查文件名称 - :param check_ext:检测扩展名 - :param check_times:检测次数(默认值:3) - :param check_interval:检测时间间隔(默认值:5) - :return:返回真假 - """ - temp_check_path = check_path + TEMP_DOWNLOAD_PATH - if os.path.exists(temp_check_path) is False: - return False - else: - for number in range(0, int(check_times)): - print("验证文件{}是否存在;第{}次检测.".format(check_file_name, str(number + 1))) - # time.sleep(0.2) - # 读取目录下所有文件 - # update-begin---author:chenrui ---date:20240129 for:[QQYUN-8127]通过接口导出功能要获取token和查询参数------------ - files = os.listdir(temp_check_path) - file_number = len(files) - if file_number > 0: - # 存在多个文件,检查当前文件是否存在 - for file in files: - if str(check_file_name.strip()) in str(file): - # 文件存在 - dest_move_file_path = check_path - if os.path.exists(check_path + os.sep + str(file)): - print("文件{}存在;重命名该文件.".format(check_file_name, str(number + 1))) - filename, extension = os.path.splitext(file) - dest_move_file_path += (os.sep + filename - + "({})".format(str(int(time.time()))) - + extension) - shutil.move(temp_check_path + str(file), dest_move_file_path) - # update-end---author:chenrui ---date:20240129 for:[QQYUN-8127]通过接口导出功能要获取token和查询参数------------ - return True - # 文件不存在 - if check_times != 1 or number < check_times - 1: - time.sleep(int(check_interval)) # 休眠一会 - return False - - -if __name__ == '__main__': - """ - 入口 - """ - result = {} - try: - print(" >>> java进入Python ==> step.1 进入Main方法") - args = sys.argv[1:] - # #本地调试参数 - # args = ['-b', '1713260060264cubcWF', '-r', - # '537516331017523200?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MTM1NTgxNDQsInVzZXJuYW1lIjoiMTg2MTE3ODg1MjUifQ.JXZLzqgkuZRcbEYFn0l-L0DXZzOw3hJZIzn0y2EmzQM', - # '-t', 'PDF', '-s', 'http://localhost:8087/jmreport/view/', '-d', 'E:\\opt\\jmpydownload\\'] - print(" >>> java进入Python ==> step.2 初始化参数") - export_options = init_args(args) - print(" >>> java进入Python ==> step.3 开始执行py脚本") - result = auto_export(export_options) - print(" >>> java进入Python ==> step.4 返回执行结果") - except Exception as e: - print("异常日志:", e) - # traceback.print_exc() - msg = "" - if hasattr(e, "msg"): - msg = e.msg - else: - msg = str(e) - # update-begin---author:chenrui ---date:20240129 for:统一py脚本的返回结果格式------------ - result = { - "success": False, - "message": msg, - "result": None - } - # update-end---author:chenrui ---date:20240129 for:统一py脚本的返回结果格式------------ - print(LOG_END_MARK + json.dumps(result) + LOG_END_MARK) diff --git a/cc-admin-master/yudao-module-hand-mqtt/pom.xml b/cc-admin-master/yudao-module-hand-mqtt/pom.xml new file mode 100644 index 0000000..e2e7827 --- /dev/null +++ b/cc-admin-master/yudao-module-hand-mqtt/pom.xml @@ -0,0 +1,63 @@ + + + cn.iocoder.boot + cc-admin-master + ${revision} + + 4.0.0 + yudao-module-hand-mqtt + jar + + ${project.artifactId} + + + + + + cn.iocoder.boot + yudao-spring-boot-starter-web + + + + cn.iocoder.boot + yudao-spring-boot-starter-security + + + org.eclipse.paho + org.eclipse.paho.client.mqttv3 + + + org.springframework.kafka + spring-kafka + + + + org.apache.rocketmq + rocketmq-acl + 4.9.4 + + + + org.apache.rocketmq + rocketmq-client + 4.9.4 + + + + cn.iocoder.boot + yudao-spring-boot-starter-mybatis + + + cn.iocoder.boot + yudao-module-hand + 2.6.1-SNAPSHOT + compile + + + + + \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/config/BatchProcessorConfig.java b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/config/BatchProcessorConfig.java new file mode 100644 index 0000000..4063256 --- /dev/null +++ b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/config/BatchProcessorConfig.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.module.mqtt.config; + +import cn.iocoder.yudao.module.hand.service.TdengineService; +import cn.iocoder.yudao.module.hand.vo.TdengineDataVo; +import cn.iocoder.yudao.module.hand.vo.HandOriginalLog; +import jakarta.annotation.Resource; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; + +@Configuration +@EnableScheduling // 确保定时任务被启用 +public class BatchProcessorConfig { + + @Resource + private TdengineService tdengineService; + + // --- 为 handOriginalLog 创建一个专用的批量处理器 Bean --- + @Bean + public TdengineBatchConfig handLogBatchProcessor() { + return new TdengineBatchConfig<>( + "HandLogProcessor", // 处理器名字 + list -> tdengineService.saveHandLogBatch(list), // 【核心】将具体的保存逻辑作为 Lambda 传入 + 50000, // 队列容量 + 1000, // 批次大小 + 5000 // 执行频率 + ); + } + + @Bean + public TdengineBatchConfig handLogBatchDataProcessor() { + return new TdengineBatchConfig<>( + "handLogBatchDataProcessor", // 处理器名字 + list -> tdengineService.saveDataLogBatch(list), // 【核心】将具体的保存逻辑作为 Lambda 传入 + 50000, // 队列容量 + 1000, // 批次大小 + 5000 // 执行频率 + ); + } + + + // --- 创建一个调度器来统一调用所有处理器的 flush 方法 --- + @Scheduled(fixedRateString = "${batch.processor.flush.rate:5000}") // 从配置读取频率,默认5秒 + public void scheduleFlush() { + // 调用 handLogProcessor 的刷新方法 + handLogBatchProcessor().flush(); + handLogBatchDataProcessor().flush(); + + // 如果有其他处理器,也在这里调用 + } +} diff --git a/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/config/TdengineBatchConfig.java b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/config/TdengineBatchConfig.java new file mode 100644 index 0000000..530021a --- /dev/null +++ b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/config/TdengineBatchConfig.java @@ -0,0 +1,89 @@ +package cn.iocoder.yudao.module.mqtt.config; + +import jakarta.annotation.PreDestroy; +import lombok.extern.slf4j.Slf4j; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; + +@Slf4j +public class TdengineBatchConfig { + + // --- 这些参数可以在构造时传入,使其更灵活 --- + private final int queueCapacity; + private final int batchSize; + private final long fixedRateMs; + private final long offerTimeoutMs; + + private final String processorName; // 用于日志,区分不同的处理器实例 + private final BlockingQueue dataQueue; + private final Consumer> batchAction; // 【核心】用于处理一个批次的具体业务逻辑 + + /** + * 构造函数 + * @param processorName 处理器名称,用于日志区分 + * @param batchAction 一个函数,接收一个 List 并执行相应的批量操作(例如,写入数据库) + * @param queueCapacity 队列容量 + * @param batchSize 批次大小 + * @param fixedRateMs 执行频率 + */ + public TdengineBatchConfig(String processorName, Consumer> batchAction, + int queueCapacity, int batchSize, long fixedRateMs) { + this.processorName = processorName; + this.batchAction = batchAction; + this.queueCapacity = queueCapacity; + this.batchSize = batchSize; + this.fixedRateMs = fixedRateMs; + this.offerTimeoutMs = 100L; + this.dataQueue = new LinkedBlockingQueue<>(this.queueCapacity); + } + + public void addToBatch(T data) { + if (data == null) { + return; + } + try { + if (!dataQueue.offer(data, offerTimeoutMs, TimeUnit.MILLISECONDS)) { + log.warn("[{}] 缓冲区已满且在 {} 毫秒内无法添加,数据可能被丢弃!当前队列大小: {}", + this.processorName, this.offerTimeoutMs, dataQueue.size()); + } + } catch (InterruptedException e) { + log.error("[{}] 添加数据到缓冲区时线程被中断", this.processorName, e); + Thread.currentThread().interrupt(); + } + } + + // 注意:@Scheduled 注解不能用在非 Spring Bean 的普通类方法上。 + // 我们将在下一步的配置类中解决这个问题。 + public void flush() { + if (dataQueue.isEmpty()) { + return; + } + List batchList = new ArrayList<>(batchSize); + try { + int drainedCount = dataQueue.drainTo(batchList, batchSize); + if (drainedCount > 0) { + log.debug("[{}] 定时任务触发,准备将 {} 条数据进行批量处理...", this.processorName, drainedCount); + // 调用构造时传入的业务逻辑 + this.batchAction.accept(batchList); + log.debug("[{}] 成功批量处理 {} 条数据。", this.processorName, drainedCount); + } + } catch (Exception e) { + log.error("[{}] 批量处理数据时发生严重错误!数据量: {}", this.processorName, batchList.size(), e); + } + } + + @PreDestroy + public void onShutdown() { + log.info("[{}] 应用即将关闭,开始执行最后的缓冲区数据刷新...", this.processorName); + while (!dataQueue.isEmpty()) { + log.debug("[{}] 停机处理中,剩余 {} 条数据待处理...", this.processorName, dataQueue.size()); + flush(); + } + log.debug("[{}] 缓冲区数据已全部处理完毕。", this.processorName); + } +} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/kafka/KafkaConfig.java b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/kafka/KafkaConfig.java new file mode 100644 index 0000000..fc609e6 --- /dev/null +++ b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/kafka/KafkaConfig.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.mqtt.kafka; + +import org.apache.kafka.common.TopicPartition; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.kafka.core.KafkaOperations; +import org.springframework.kafka.listener.DeadLetterPublishingRecoverer; +import org.springframework.kafka.listener.DefaultErrorHandler; +import org.springframework.util.backoff.FixedBackOff; + +@Configuration +public class KafkaConfig { + + /** + * 配置一个通用的错误处理器. + * 它会在反序列化失败或监听器方法抛出异常时生效. + * @param operations KafkaTemplate 实例 + * @return a DefaultErrorHandler + */ + @Bean + public DefaultErrorHandler errorHandler(KafkaOperations operations) { + // 1. 创建 DeadLetterPublishingRecoverer,它负责将失败的消息推送到 DLT + // 这里我们为所有失败的消息都指定了一个通用的 DLT 主题 + DeadLetterPublishingRecoverer recoverer = new DeadLetterPublishingRecoverer(operations, + (rec, ex) -> new TopicPartition(rec.topic() + ".DLT", rec.partition())); + + // 根据业务需求选择合适的策略。 + FixedBackOff backOff = new FixedBackOff(1000L, 2L); + + // 3. 创建并返回 DefaultErrorHandler + // 当重试耗尽后,会调用 recoverer 将消息送入 DLT + return new DefaultErrorHandler(recoverer, backOff); + } +} diff --git a/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/kafka/KafkaMessageConsumer.java b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/kafka/KafkaMessageConsumer.java new file mode 100644 index 0000000..40f3524 --- /dev/null +++ b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/kafka/KafkaMessageConsumer.java @@ -0,0 +1,58 @@ +package cn.iocoder.yudao.module.mqtt.kafka; + +import cn.iocoder.yudao.module.mqtt.processor.DeviceMessageProcessor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.core.task.TaskExecutor; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.support.KafkaHeaders; +import org.springframework.messaging.handler.annotation.Header; +import org.springframework.messaging.handler.annotation.Payload; +import org.springframework.stereotype.Service; + +import static cn.iocoder.yudao.module.mqtt.kafka.KafkaTopicType.DEAD_LETTER_TOPIC; + +@Slf4j +@Service // <--- 添加这个注解! +public class KafkaMessageConsumer { + + private final TaskExecutor taskExecutor; + private final DeviceMessageProcessor deviceMessageProcessor; + private final KafkaTemplate kafkaTemplate; + + + public KafkaMessageConsumer(DeviceMessageProcessor deviceMessageProcessor, + @Qualifier("mqttExecutor") TaskExecutor taskExecutor, + KafkaTemplate kafkaTemplate) { + this.deviceMessageProcessor = deviceMessageProcessor; + this.taskExecutor = taskExecutor; + this.kafkaTemplate = kafkaTemplate; + + } + + @KafkaListener(topics = "zds_up") + public void handleMessage(@Payload String payload, + @Header(KafkaHeaders.RECEIVED_KEY) String key, + @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) { + log.debug("从 Kafka Topic 收到消息,准备处理: topic=[{}]", topic); + + // 3. 异步执行,保证kafka不阻塞 + taskExecutor.execute(() -> { + try { + // 核心业务逻辑调用 + this.deviceMessageProcessor.process(key, payload); + } catch (Exception e) { + // 1. 捕获所有运行时异常 + log.error("处理 Kafka 消息时发生严重错误!将消息发送到死信队列. Key: {}, Payload: {}", key, payload, e); + try { + // 2. 将失败的消息发送到 DLT + // 可以在消息头中添加额外信息,如原始主题、异常信息等,方便排查 + kafkaTemplate.send(DEAD_LETTER_TOPIC.getValue(), key, payload); + } catch (Exception dltEx) { + log.error("无法将消息发送到死信队列!消息可能丢失. Key: {}, Payload: {}", key, payload, dltEx); + } + } + }); + } +} diff --git a/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/kafka/KafkaTopicType.java b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/kafka/KafkaTopicType.java new file mode 100644 index 0000000..f7964f8 --- /dev/null +++ b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/kafka/KafkaTopicType.java @@ -0,0 +1,44 @@ +package cn.iocoder.yudao.module.mqtt.kafka; + +import lombok.Getter; +import java.util.Arrays; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * Kafka 主题枚举类,用于统一管理和引用 Topic 名称 + */ +@Getter // Lombok 注解,自动为所有字段生成 public 的 getter 方法,例如 getValue() +public enum KafkaTopicType { + + // 1. 常量名和值的含义保持一致,更清晰 + DEVICE_STATUS_UP("zds_up"), + DEAD_LETTER_TOPIC("zds_up_dlt"); + + // 2. 添加了 final 字段 + private final String value; + + // 3. 【核心修复】添加了私有构造函数,用于初始化 final 字段 + KafkaTopicType(String value) { + this.value = value; + } + + // --- 以下是更高效和健壮的 from 方法实现 --- + + // 4. 使用静态 Map 缓存,提高查找性能,避免每次调用都遍历 + private static final Map LOOKUP_MAP = Arrays.stream(values()) + .collect(Collectors.toMap(KafkaTopicType::getValue, Function.identity())); + + /** + * 根据字符串值查找对应的枚举常量. + * + * @param value topic 字符串值 + * @return 对应的枚举常量 + * @throws IllegalArgumentException 如果找不到匹配的常量 + */ + public static KafkaTopicType from(String value) { + + return LOOKUP_MAP.get(value); + } +} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/Client.java b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/Client.java new file mode 100644 index 0000000..871fd97 --- /dev/null +++ b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/Client.java @@ -0,0 +1,150 @@ +package cn.iocoder.yudao.module.mqtt.mqtt; + +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.paho.client.mqttv3.*; +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import java.nio.charset.StandardCharsets; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.UUID; +import java.util.concurrent.BlockingQueue; + +@Slf4j +@Component +public class Client { + + private final OnMessageCallback onMessageCallback; // 1. 注入我们新的 Kafka 生产者回调 + // --- 1. 配置注入 (保持不变) --- + @Value("${mqtt.enable:false}") + private Boolean enable; + @Value("${mqtt.url}") + private String hostUrl; + @Value("${mqtt.username:}") + private String username; + @Value("${mqtt.password:}") + private String password; + @Value("${mqtt.client.id}") + private String baseClientId; + @Value("${mqtt.connectionTimeout:10}") + private int connectionTimeout; + @Value("${mqtt.keepAliveInterval:60}") + private int keepAliveInterval; + @Value("${mqtt.cleanSession:true}") + private boolean cleanSession; + @Value("${mqtt.subscribe.topic}") + private String[] subscribeTopics; + @Value("${mqtt.subscribe.qos}") + private int[] subscribeQos; + @Value("${mqtt.default.publishQos:1}") + private int publishQos; + private IMqttClient mqttClient; + + // 2. 构造函数注入 Spring Bean + public Client(OnMessageCallback onMessageCallback) { + this.onMessageCallback = onMessageCallback; + } + + @PostConstruct + public void init() { + if (!enable) { + log.info("MQTT 功能已禁用。"); + return; + } + connect(); + } + + private void connect() { + try { + String finalClientId = baseClientId + "-" + UUID.randomUUID().toString().substring(0, 8); + mqttClient = new MqttClient(hostUrl, finalClientId, new MemoryPersistence()); + + MqttConnectOptions options = createMqttConnectOptions(); + + // 3. 将注入的回调 Bean 设置给 Paho 客户端 + mqttClient.setCallback(onMessageCallback); + log.info("正在连接到 MQTT Broker: {}", hostUrl); + mqttClient.connect(options); + + subscribeToTopics(); + + } catch (MqttException e) { + log.error("连接到 MQTT Broker 时发生初始错误: {}", e.getMessage(), e); + } + } + + private MqttConnectOptions createMqttConnectOptions() { + MqttConnectOptions options = new MqttConnectOptions(); + options.setUserName(username); + options.setPassword(password.toCharArray()); + options.setConnectionTimeout(connectionTimeout); + options.setKeepAliveInterval(keepAliveInterval); + options.setCleanSession(cleanSession); + options.setAutomaticReconnect(true); // 启用自动重连 + return options; + } + + /** + * 4. 创建一个事件监听器,用于处理连接成功事件 + * 这取代了之前传递 Runnable 的方式,实现了更好的解耦 + */ +/* @Async + @EventListener + public void handleMqttConnectionComplete(MqttConnectedEvent event) { + log.info("监听到 MQTT 连接成功事件,开始执行订阅操作..."); + subscribeToTopics(); + }*/ + private void subscribeToTopics() { + if (mqttClient == null || !mqttClient.isConnected()) { + log.error("无法订阅主题,因为 MQTT 客户端尚未连接。"); + return; + } + try { + log.info("执行 MQTT 主题订阅: {}", (Object) subscribeTopics); + mqttClient.subscribe(subscribeTopics, subscribeQos); + } catch (MqttException e) { + log.error("订阅 MQTT 主题时发生错误: {}", e.getMessage(), e); + } + } + + // --- 4. 发布和清理方法 (保持不变) --- + public void publish(String topic, String payload) { + publish(topic, payload.getBytes(), this.publishQos, false); + } + + public void publish(String topic, byte[] payload, int qos, boolean retained) { + if (mqttClient == null || !mqttClient.isConnected()) { + log.error("MQTT 客户端未连接,无法发布消息。"); + return; + } + try { + MqttMessage message = new MqttMessage(payload); + message.setQos(qos); + message.setRetained(retained); + mqttClient.publish(topic, message); + } catch (MqttException e) { + log.error("发布 MQTT 消息到主题 [{}] 时发生错误: {}", topic, e.getMessage(), e); + } + } + + @PreDestroy + public void cleanup() { + if (mqttClient != null) { + try { + if (mqttClient.isConnected()) { + mqttClient.disconnect(); + } + mqttClient.close(); + log.info("MQTT 客户端已成功关闭。"); + } catch (MqttException e) { + log.error("关闭 MQTT 客户端时发生错误: {}", e.getMessage(), e); + } + } + } +} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/MqttConnectedEvent.java b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/MqttConnectedEvent.java new file mode 100644 index 0000000..65c57b8 --- /dev/null +++ b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/MqttConnectedEvent.java @@ -0,0 +1,9 @@ +package cn.iocoder.yudao.module.mqtt.mqtt; + +import org.springframework.context.ApplicationEvent; + +public class MqttConnectedEvent extends ApplicationEvent { + public MqttConnectedEvent(Object source) { + super(source); + } +} diff --git a/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/OnMessageCallback.java b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/OnMessageCallback.java new file mode 100644 index 0000000..448de26 --- /dev/null +++ b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/OnMessageCallback.java @@ -0,0 +1,68 @@ +package cn.iocoder.yudao.module.mqtt.mqtt; + +import cn.hutool.core.util.ReUtil; +import cn.iocoder.yudao.module.mqtt.kafka.KafkaTopicType; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; +import org.eclipse.paho.client.mqttv3.MqttCallbackExtended; +import org.eclipse.paho.client.mqttv3.MqttMessage; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.concurrent.BlockingQueue; +import java.util.regex.Pattern; + +@Slf4j +@Component +public class OnMessageCallback implements MqttCallbackExtended { + private final Pattern topicPattern = Pattern.compile("([^/]+)/?(.+)?"); + @Resource + private KafkaTemplate kafkaTemplate; + @Resource + private ApplicationEventPublisher eventPublisher; + + @Override + public void connectComplete(boolean reconnect, String serverURI) { + log.info("MQTT 连接成功。是否为重连: {}, 服务器 URI: {}", reconnect, serverURI); + // 3. 发布一个 Spring 事件,通知其他组件(如 Client)连接已成功 + eventPublisher.publishEvent(new MqttConnectedEvent(this)); + } + + @Override + public void connectionLost(Throwable cause) { + log.error("MQTT 连接已断开,正在尝试自动重连...", cause); + } + + @Override + public void messageArrived(String MqttTopic, MqttMessage message) { + String payload = new String(message.getPayload()); + List groups = ReUtil.getAllGroups(topicPattern, MqttTopic, false); + + if (groups.get(1) == null) { + log.warn("无法从topic {} 中获取消息发送者ID", MqttTopic); + return; + } + String sn = groups.get(0); + String topic = groups.get(1); + KafkaTopicType from = KafkaTopicType.from(groups.get(1)); + if (null == from) { + log.warn("发送的topic无效{}", topic); + return; + } + try { + kafkaTemplate.send(topic, sn, payload); + log.debug("成功将消息转发到 Kafka Topic [{}]: payload=[{}]", topic, payload); + } catch (Exception e) { + log.error("转发消息到 Kafka Topic [{}] 时发生错误!", topic, e); + } + } + + @Override + public void deliveryComplete(IMqttDeliveryToken token) { + // no-op + } +} diff --git a/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/ThreadPoolConfig.java b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/ThreadPoolConfig.java new file mode 100644 index 0000000..71547b7 --- /dev/null +++ b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/mqtt/ThreadPoolConfig.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.mqtt.mqtt; + + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.task.TaskExecutor; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.concurrent.ThreadPoolExecutor; + +@Configuration + +public class ThreadPoolConfig { + @Bean("mqttExecutor") + public TaskExecutor taskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + // 核心线程数:CPU核心数 + executor.setCorePoolSize(Runtime.getRuntime().availableProcessors()); + // 最大线程数:CPU核心数 * 2 + executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 2); + // 队列大小 + executor.setQueueCapacity(1000); + // 线程名称前缀 + executor.setThreadNamePrefix("mqtt-executor-"); + // 拒绝策略:由调用者线程处理 + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + // 初始化 + executor.initialize(); + return executor; + } +} diff --git a/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/processor/DeviceMessageProcessor.java b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/processor/DeviceMessageProcessor.java new file mode 100644 index 0000000..9be89a0 --- /dev/null +++ b/cc-admin-master/yudao-module-hand-mqtt/src/main/java/cn/iocoder/yudao/module/mqtt/processor/DeviceMessageProcessor.java @@ -0,0 +1,505 @@ +package cn.iocoder.yudao.module.mqtt.processor; + +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.hand.dal.*; +import cn.iocoder.yudao.module.hand.enums.*; +import cn.iocoder.yudao.module.hand.service.*; +import cn.iocoder.yudao.module.hand.util.*; +import cn.iocoder.yudao.module.hand.vo.*; +import cn.iocoder.yudao.module.mqtt.config.TdengineBatchConfig; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; +import org.springframework.stereotype.Component; + +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.util.*; +import java.util.concurrent.TimeUnit; + +@Slf4j +@Component +public class DeviceMessageProcessor { + + @Resource + private RedisUtil redisUtil; + @Resource + private TdengineBatchConfig tdengineBatchProcessor; + @Resource + private TdengineBatchConfig tdengineBatchConfig; + @Resource + private HandDetectorService handDetectorService; + + @Resource + private HandAlarmService handAlarmService; + + @Resource + private AlarmRuleService alarmRuleService; + + @Resource + private RedissonClient redissonClient; + @Resource + private FenceService fenceService; + @Resource + private FenceAlarmService fenceAlarmService; + + + public void process(String topic, String payload) { + log.debug("[设备上报] 开始处理 -> 主题: {}, 内容: {}", topic, payload); + + Object tenantIdObj = redisUtil.hget(RedisKeyUtil.getDeviceTenantMappingKey(), topic); + if (tenantIdObj == null || StringUtils.isBlank(tenantIdObj.toString())) { + log.warn("[设备上报] 无法找到 SN {} 对应的租户信息,设备可能未注册。消息丢弃。", topic); + return; // 结束处理 + } + Long tenantId = Long.parseLong(tenantIdObj.toString()); + + // 保存原始日志,这个操作不涉及状态竞争,可以放在锁外 + logSave(topic, payload, tenantId); + + // topic 即为设备 sn,是锁的最佳 key + String deviceProcessLockKey = RedisKeyUtil.getDeviceProcessLockKey(tenantId, topic); + RLock lock = redissonClient.getLock(deviceProcessLockKey); + try { + // 尝试在 10 秒内获取锁,防止因锁等待导致 Kafka 消费者线程长时间阻塞 + if (!lock.tryLock(10, TimeUnit.SECONDS)) { + log.warn("未能获取设备 {} 的处理锁,消息将被丢弃或重试。", topic); + // 抛出异常,外层逻辑可以捕获并发送到死信队列 + throw new RuntimeException("获取设备锁超时: " + topic); + } + try { + // 从 Redis 中获取设备信息 + Object meterObj = redisUtil.hget(RedisKeyUtil.getTenantDeviceHashKey(tenantId), topic); + HandDataVo detector; + + if (meterObj == null) { // 缓存未命中 + // 从数据库查询 DO 对象 + HandDetectorDO one = handDetectorService.getBySn(topic); + if (one == null) { + log.warn("[数据不一致] 在租户 {} 的设备列表中未找到 SN {} 的详细信息。", tenantId, topic); + return; // 直接返回,无需再操作 + } + detector = BeanUtils.toBean(one, HandDataVo.class); + } else { // 缓存命中 + detector = BeanUtils.toBean(meterObj, HandDataVo.class); + } + + if (EnableStatus.DISABLED.value().equals(detector.getEnableStatus())) { + log.info("未启用的手持探测器 sn: {}", topic); + return; + } + // 数据解析与转换 + HandDataVo handVo = dataConvert(topic, payload, detector); + + // 获取气种的报警规则 + Map> ruleMap = alarmRuleService.selectCacheListMap(tenantId); + AlarmRuleDO alarmRule = getAlarmRule(handVo, ruleMap); + + // 气体报警逻辑处理 + HandDataVo vo = gasHandAlarm(alarmRule, handVo); + // 气体报警保存 + saveGasAlarm(vo, alarmRule); + + //围栏报警逻辑 + fanceAlarm(handVo); + + //电量报警逻辑 + batteryAlarm(handVo); + + // 无论是否发生告警,设备的状态(如电量、位置、最新值)都需要更新 + handDetectorService.updateRedisData(tenantId, topic, handVo); + handLogSave(handVo); + + } finally { + // 确保锁一定被释放 + if (lock.isHeldByCurrentThread()) { + lock.unlock(); + } + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + log.error("获取设备 {} 的锁时被中断", topic, e); + throw new RuntimeException("处理设备消息时线程被中断: " + topic, e); + } + } + + private void handLogSave(HandDataVo handVo) { + TdengineDataVo bean = BeanUtils.toBean(handVo, TdengineDataVo.class); + bean.setTenantId(handVo.getTenantId()); + bean.setTs(new Timestamp(System.currentTimeMillis())); // 直接创建Timestamp对象 + tdengineBatchConfig.addToBatch(bean); + } + + private void batteryAlarm(HandDataVo handVo) { + handVo.setBatteryStatus(EnableStatus.DISABLED.value()); // 默认状态为正常 + if (null == handVo.getBatteryAlarmValue()) { + return; + } + + if (null == handVo.getBatteryStatusAlarmId()) { + return; + } + // --- 步骤2: 计算当前电量 --- + // 只有在告警功能已配置的情况下,才继续执行后续的电量计算和判断逻辑。 + int batteryPercentage; + try { + batteryPercentage = BatteryConverterUtils.getBatteryPercentage(Integer.parseInt(handVo.getBattery())); + } catch (NumberFormatException e) { + log.error("设备电池数据格式无效,设备SN: {},原始电池值: {},异常信息: {}", + handVo.getSn(), handVo.getBattery(), e.getMessage(), e); + return; + } + + // --- 步骤3: 执行告警状态判断和转换逻辑 --- + int alarmThreshold = handVo.getBatteryAlarmValue().intValue(); // 此处调用是安全的,因为已在步骤1排除了null的可能 + boolean isCurrentlyInAlarm = Objects.equals(handVo.getBatteryStatus(), EnableStatus.ENABLED.value()); + boolean shouldBeInAlarm = batteryPercentage < alarmThreshold; + + // 场景一:从“正常”变为“告警” -> 创建新告警 + if (shouldBeInAlarm && !isCurrentlyInAlarm) { + HandAlarmSaveReqVO alarm = new HandAlarmSaveReqVO(); + alarm.setAlarmType(AlarmType.BATTERY.getType()); + alarm.setTAlarmStart(LocalDateTime.now()); + alarm.setVAlarmFirst(handVo.getFirstValue()); + alarm.setPicX(handVo.getLatitude()); + alarm.setPicY(handVo.getLongitude()); + handAlarmService.createHandAlarm(alarm); + + // 场景二:从“告警”变为“正常” -> 结束告警 + } else if (!shouldBeInAlarm && isCurrentlyInAlarm) { + HandAlarmSaveReqVO alarm = new HandAlarmSaveReqVO(); + alarm.setTAlarmEnd(LocalDateTime.now()); + // alarm.setId(handVo.getBatteryStatusAlarmId()); // 别忘了传递告警ID + handAlarmService.updateHandAlarm(alarm); + } + // 如果状态未变(持续告警或持续正常),不执行任何数据库操作。 + // 根据当前是否应该告警来设置最终的正确状态。 + if (shouldBeInAlarm) { + handVo.setBatteryStatus(EnableStatus.ENABLED.value()); + } else { + handVo.setBatteryStatus(EnableStatus.DISABLED.value()); + } + } + + private void saveGasAlarm(HandDataVo vo, AlarmRuleDO alarmRule) { + if (null == alarmRule || null == alarmRule.getAlarmLevel()) { + log.error("报警规则不存在:sn: {}", vo.getSn()); + return; + } + if (vo.getTAlarmStart() == null) {//没有开始时间不需要报警 + return; + } + //报警恢复和添加报警 + if (vo.getTAlarmEnd() != null) { + if (vo.getAlarmId() == null) { + log.error("报警恢复失败:一个已结束的报警事件在Redis中没有找到 alarmId。sn: {}", vo.getSn()); + return; + } + HandAlarmDO alarm = new HandAlarmDO(); + alarm.setTAlarmEnd(vo.getTAlarmEnd()); + alarm.setId(vo.getAlarmId()); + alarm.setVAlarmMaximum(vo.getMaxValue()); + alarm.setAlarmLevel(vo.getMaxAlarmLevel()); + alarm.setTenantId(vo.getTenantId()); + int count = handAlarmService.updateById(alarm); + if (count > 0) { + log.info("报警事件(ID: {})已结束,成功更新数据库。", alarm.getId()); + // 重置 Redis 数据 + vo.setAlarmId(null); + vo.setFirstValue(null); + vo.setMaxValue(null); + vo.setTAlarmStart(null); + vo.setTAlarmEnd(null); + vo.setMaxAlarmLevel(null); + vo.setAlarmLevel(0); // 将当前级别设为正常 + } else { + log.error("数据库更新失败:尝试结束报警事件(ID: {})时出错。", vo.getAlarmId()); + } + } else { + if (vo.getAlarmId() == null) { + HandAlarmSaveReqVO alarmDO = BeanUtils.toBean(vo, HandAlarmSaveReqVO.class); + + Long count = handAlarmService.createHandAlarm(alarmDO); + if (count > 0) { + vo.setAlarmId(count); + log.info("新报警事件已创建,数据库ID: {},并已回写至Redis。", count); + } + } else { + // -- 更新 -- + HandAlarmDO alarmToUpdate = new HandAlarmDO(); + alarmToUpdate.setId(vo.getAlarmId()); + alarmToUpdate.setVAlarmMaximum(vo.getMaxValue()); + handAlarmService.updateById(alarmToUpdate); + } + } + } + + + /** + * 围栏报警逻辑 + */ + private void fanceAlarm(HandDataVo handVo) { + if (StringUtils.isBlank(handVo.getFenceIds())) { + log.info("当前设备未绑定围栏,sn{}", handVo.getSn()); + return; + } + List list = Arrays.stream(handVo.getFenceIds().split(",")) + .map(Long::parseLong) + .toList(); + List fenceList = fenceService.getFenceList(list); + + + FenceType fenceType = FenceType.fromType(handVo.getFenceType());// 转换为枚举 + + // a. 判断点是否在任何一个围栏内 + boolean isCurrentlyInside = GeofenceUtils.isInsideAnyFence(handVo.getLongitude(), handVo.getLatitude(), fenceList); + + Boolean isViolating = switch (fenceType) { + case null -> { + log.error("围栏类型为 null,无法处理。"); + yield null; // 使用 yield 从代码块中返回一个值 + } + // "进入围栏报警" -> 违规条件是:车辆在围栏内部 + case INSIDE -> isCurrentlyInside; + + // "超出围栏报警" -> 违规条件是:车辆在围栏外部 + case OUTSIDE -> !isCurrentlyInside; + + // default 分支确保了所有未明确处理的枚举类型都能被覆盖 + default -> { + log.error("逻辑中未处理的围拦类型: {}。", fenceType); + yield null; + } + }; + // --- 3. 根据计算出的状态,执行统一的后续逻辑 --- + // 如果 isViolating 为 null (因为 fenceType 无效或为 null),则不执行任何操作。 + if (isViolating != null) { + handleAlarmLifecycle(isViolating, handVo, fenceType, fenceList); + } + + } + + /** + * 统一处理报警的开始、持续和结束。 + * + * @param isViolating 当前状态是否违规 + * @param handVo 当前位置信息,携带着报警状态 (fenceAlarmId) + * @param fenceType 围栏类型 + * @param fenceList 围栏几何对象列表 + */ + private void handleAlarmLifecycle(boolean isViolating, HandDataVo handVo, FenceType fenceType, List fenceList) { + + // 关键状态判断:根据 handVo 中是否已有报警ID,判断之前是否有正在进行的报警 + boolean hasOngoingAlarm = (handVo.getFenceAlarmId() != null); + + if (isViolating) { + // --- 场景:当前处于违规状态 --- + // 计算当前的违规距离 + double currentDistance = GeofenceUtils.fenceDistance(handVo, fenceType, fenceList); + + if (!hasOngoingAlarm) { + // 1. 【触发新报警】: 之前不报警,现在开始违规 + log.warn("触发 [{}] 类型围栏报警! sn: {}", fenceType, handVo.getSn()); + + FenceAlarmSaveReqVO newAlarm = new FenceAlarmSaveReqVO(); + newAlarm.setDetectorId(handVo.getId()); + /* newAlarm.setFenceId(fenceDO.getId());*/ + newAlarm.setType(fenceType.getType()); + newAlarm.setTAlarmStart(LocalDateTime.now()); // 记录报警开始时间 + newAlarm.setPicX(handVo.getLongitude()); + newAlarm.setPicY(handVo.getLatitude()); + newAlarm.setTenantId(handVo.getTenantId()); + + // 初始化距离 + newAlarm.setDistance(currentDistance); + newAlarm.setMaxDistance(currentDistance); + handVo.setDistance(currentDistance); + handVo.setMaxDistance(currentDistance); + + // 保存新报警,并获取返回的ID,用于更新 handVo 的状态 + Long fenceAlarm = fenceAlarmService.createFenceAlarm(newAlarm); + if (fenceAlarm != null) { + // *** 关键:更新内存/缓存中的 handVo 状态,以便下次判断 *** + handVo.setFenceAlarmId(fenceAlarm); + } + } else { + // 2. 【更新持续报警】: 之前在报警,现在仍然违规 + log.info("持续 [{}] 类型围栏报警,更新距离... fenceAlarmId: {}", fenceType, handVo.getFenceAlarmId()); + + FenceAlarmDO existingAlarm = fenceAlarmService.getFenceAlarm(handVo.getFenceAlarmId()); + if (existingAlarm == null) { + log.error("逻辑错误:handVo 中有报警ID,但数据库中找不到记录!ID: {}", handVo.getFenceAlarmId()); + // 异常处理:可以选择重置 handVo 状态,或创建新报警 + handVo.setFenceAlarmId(null); // 重置状态 + return; + } + + existingAlarm.setDistance(currentDistance); + if (existingAlarm.getMaxDistance() == null || currentDistance > existingAlarm.getMaxDistance()) { + existingAlarm.setMaxDistance(currentDistance); + handVo.setMaxDistance(currentDistance); + } + fenceAlarmService.update(existingAlarm); + } + handVo.setGasStatus(HandAlarmType.ALARM.getType()); + } else { + // --- 场景:当前处于正常状态 --- + + if (hasOngoingAlarm) { + // 3. 【结束报警】: 之前在报警,现在恢复正常 + log.warn("结束 [{}] 类型围栏报警。 fenceAlarmId: {}", fenceType, handVo.getFenceAlarmId()); + // 调用服务去结束报警(例如设置 endTime) + FenceAlarmDO fenceAlarmDO = new FenceAlarmDO(); + fenceAlarmDO.setId(handVo.getFenceAlarmId()); + fenceAlarmDO.setTAlarmEnd(LocalDateTime.now()); + fenceAlarmService.update(fenceAlarmDO); + + // *** 关键:重置内存/缓存中的 handVo 状态 *** + handVo.setFenceAlarmId(null); + handVo.setDistance(null); + handVo.setMaxDistance(null); + handVo.setGasStatus(HandAlarmType.NORMAL.getType()); + } else { + log.debug("当前状态正常,且无进行中报警,无需操作。"); + } + } + } + + + private AlarmRuleDO getAlarmRule(HandDataVo handVo, Map> ruleMap) { + double gasValue = handVo.getValue(); + Long gasTypeId = handVo.getGasTypeId(); + + List gasAlarmRuleList = ruleMap.get(gasTypeId); + + if (gasAlarmRuleList == null || gasAlarmRuleList.isEmpty()) { + log.error("无报警规则:detector={} gas type={} value={}", handVo.getSn(), handVo.getGasChemical(), gasValue); + return null; + } + + AlarmRuleDO alarmRule = null; + for (AlarmRuleDO rule : gasAlarmRuleList) { + // 最小值或最大值可为空 + if ((rule.getMin() == null || rule.getMin() <= gasValue) && (rule.getMax() == null || gasValue <= rule.getMax())) { + // 范围重复高级别报警优先 + if (alarmRule == null || alarmRule.getAlarmLevel() < rule.getAlarmLevel()) { + alarmRule = rule; + } + } + } + + return alarmRule; + } + + + /** + * 气体报警逻辑处理 + */ + private HandDataVo gasHandAlarm(AlarmRuleDO alarmRule, HandDataVo redisData) { + if (null == alarmRule) { + log.error("无报警规则:sn: {}", redisData.getSn()); + return redisData; + } + + LocalDateTime now = LocalDateTime.now(); + //离线报警结束 + if (OnlineStatusType.ONLINE.getType().equals(redisData.getOnlineStatus()) + && AlarmLevelEnum.OFFLINE.value().equals(redisData.getAlarmLevel())) { + HandAlarmDO handAlarmDO = new HandAlarmDO(); + handAlarmDO.setId(redisData.getAlarmId()); + handAlarmDO.setTAlarmEnd(now); + handAlarmService.updateById(handAlarmDO); + //删除离线报警 + redisData.setAlarmId(null); + } + + boolean isCurrentlyAlarming = redisData.getAlarmLevel() != null && redisData.getAlarmLevel() > 0; + boolean isRuleTriggeringAlarm = alarmRule.getAlarmLevel() > 0; + // 之前在报警,但现在报警恢复正常 + if (isCurrentlyAlarming && !isRuleTriggeringAlarm) { + redisData.setAlarmLevel(0); + redisData.setTAlarmEnd(now); + redisData.setGasStatus(HandAlarmType.NORMAL.getType()); + return redisData; + } + + if (alarmRule.getAlarmLevel() == 0) { + redisData.setAlarmLevel(0); + return redisData; + } + + + if (isRuleTriggeringAlarm) { + Integer newAlarmLevel = alarmRule.getAlarmLevel(); + + // 如果是首次报警 (之前不处于报警状态) + if (!isCurrentlyAlarming) { + redisData.setFirstValue(redisData.getValue()); + redisData.setTAlarmStart(now); + redisData.setMaxValue(redisData.getValue()); // 初始值 + redisData.setMaxAlarmLevel(newAlarmLevel); + } + redisData.setAlarmLevel(newAlarmLevel); + + // 报警升级 + if (redisData.getMaxAlarmLevel() == null || newAlarmLevel > redisData.getMaxAlarmLevel()) { + redisData.setMaxAlarmLevel(newAlarmLevel); + } + + // 更新最大值 + if (MaxDirection.DOWN.value().equals(alarmRule.getDirection()) && redisData.getValue() < redisData.getMaxValue() + || MaxDirection.UP.value().equals(alarmRule.getDirection()) && redisData.getValue() > redisData.getMaxValue()) { + // 更新最大值 + redisData.setMaxValue(redisData.getValue()); + } + } + redisData.setGasStatus(HandAlarmType.ALARM.getType()); + return redisData; + } + + + /** + * 数据转换 + */ + private HandDataVo dataConvert(String topic, String payload, HandDataVo detector) { + JSONObject obj = JSONUtil.parseObj(payload); + + Double value = obj.getDouble("gas", null);//气体值 + String loc = obj.getStr("loc"); + String battery = obj.getStr("battery"); + String numbersString = loc.substring(1, loc.length() - 1); + // 将字符串按逗号分割成数组 + String[] split = numbersString.split(","); + + Map wgs84ToGcj02 = CoordinateTransferUtils.wgs84ToGcj02(Double.parseDouble(split[0]), Double.parseDouble(split[1])); + + Double lon = wgs84ToGcj02.get("lon"); + Double lat = wgs84ToGcj02.get("lat"); + detector.setBattery(battery); + detector.setLongitude(lon); + detector.setLatitude(lat); + detector.setValue(value); + detector.setSn(topic); + //添加最新时间 + detector.setTime(new Date(System.currentTimeMillis())); + //添加默认状态 + detector.setOnlineStatus(OnlineStatusType.ONLINE.getType()); + + return detector; + } + + private void logSave(String topic, String payload, Long tenantId) { + HandOriginalLog handOriginalLog = new HandOriginalLog(); + handOriginalLog.setSn(topic); + handOriginalLog.setPayload(payload); + handOriginalLog.setTenantId(tenantId); + handOriginalLog.setTs(new Timestamp(System.currentTimeMillis())); // 直接创建Timestamp对象 + tdengineBatchProcessor.addToBatch(handOriginalLog); + } + + +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/AlarmRuleController.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/AlarmRuleController.java index f98d7c4..3689c9c 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/AlarmRuleController.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/AlarmRuleController.java @@ -44,7 +44,7 @@ public class AlarmRuleController { @PostMapping("/create") @Operation(summary = "创建GAS警报规则") @PreAuthorize("@ss.hasPermission('gas:alarm-rule:create')") - public CommonResult createAlarmRule(@Valid @RequestBody AlarmRuleSaveReqVO createReqVO) { + public CommonResult createAlarmRule(@Valid @RequestBody AlarmRuleSaveReqVO createReqVO) { return success(alarmRuleService.createAlarmRule(createReqVO)); } @@ -60,7 +60,7 @@ public class AlarmRuleController { @Operation(summary = "删除GAS警报规则") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('gas:alarm-rule:delete')") - public CommonResult deleteAlarmRule(@RequestParam("id") String id) { + public CommonResult deleteAlarmRule(@RequestParam("id") Long id) { alarmRuleService.deleteAlarmRule(id); return success(true); } @@ -69,7 +69,7 @@ public class AlarmRuleController { @Parameter(name = "ids", description = "编号", required = true) @Operation(summary = "批量删除GAS警报规则") @PreAuthorize("@ss.hasPermission('gas:alarm-rule:delete')") - public CommonResult deleteAlarmRuleList(@RequestParam("ids") List ids) { + public CommonResult deleteAlarmRuleList(@RequestParam("ids") List ids) { alarmRuleService.deleteAlarmRuleListByIds(ids); return success(true); } @@ -78,7 +78,7 @@ public class AlarmRuleController { @Operation(summary = "获得GAS警报规则") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('gas:alarm-rule:query')") - public CommonResult getAlarmRule(@RequestParam("id") String id) { + public CommonResult getAlarmRule(@RequestParam("id") Long id) { AlarmRuleDO alarmRule = alarmRuleService.getAlarmRule(id); return success(BeanUtils.toBean(alarmRule, AlarmRuleRespVO.class)); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/AlarmTypeController.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/AlarmTypeController.java index 8e0ea73..b0b56a8 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/AlarmTypeController.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/AlarmTypeController.java @@ -44,7 +44,7 @@ public class AlarmTypeController { @PostMapping("/create") @Operation(summary = "创建GAS警报类型") @PreAuthorize("@ss.hasPermission('gas:alarm-type:create')") - public CommonResult createAlarmType(@Valid @RequestBody AlarmTypeSaveReqVO createReqVO) { + public CommonResult createAlarmType(@Valid @RequestBody AlarmTypeSaveReqVO createReqVO) { return success(alarmTypeService.createAlarmType(createReqVO)); } @@ -60,7 +60,7 @@ public class AlarmTypeController { @Operation(summary = "删除GAS警报类型") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('gas:alarm-type:delete')") - public CommonResult deleteAlarmType(@RequestParam("id") String id) { + public CommonResult deleteAlarmType(@RequestParam("id") Long id) { alarmTypeService.deleteAlarmType(id); return success(true); } @@ -69,7 +69,7 @@ public class AlarmTypeController { @Parameter(name = "ids", description = "编号", required = true) @Operation(summary = "批量删除GAS警报类型") @PreAuthorize("@ss.hasPermission('gas:alarm-type:delete')") - public CommonResult deleteAlarmTypeList(@RequestParam("ids") List ids) { + public CommonResult deleteAlarmTypeList(@RequestParam("ids") List ids) { alarmTypeService.deleteAlarmTypeListByIds(ids); return success(true); } @@ -78,7 +78,7 @@ public class AlarmTypeController { @Operation(summary = "获得GAS警报类型") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('gas:alarm-type:query')") - public CommonResult getAlarmType(@RequestParam("id") String id) { + public CommonResult getAlarmType(@RequestParam("id") Long id) { AlarmTypeDO alarmType = alarmTypeService.getAlarmType(id); return success(BeanUtils.toBean(alarmType, AlarmTypeRespVO.class)); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/FactoryController.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/FactoryController.java new file mode 100644 index 0000000..1abf497 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/FactoryController.java @@ -0,0 +1,107 @@ +package cn.iocoder.yudao.module.hand.controller.admin; + +import cn.iocoder.yudao.module.hand.dal.FactoryDO; +import cn.iocoder.yudao.module.hand.service.FactoryService; +import cn.iocoder.yudao.module.hand.vo.FactoryPageReqVO; +import cn.iocoder.yudao.module.hand.vo.FactoryRespVO; +import cn.iocoder.yudao.module.hand.vo.FactorySaveReqVO; +import org.springframework.web.bind.annotation.*; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import jakarta.validation.constraints.*; +import jakarta.validation.*; +import jakarta.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + + + +@Tag(name = "管理后台 - GAS工厂") +@RestController +@RequestMapping("/gas/factory") +@Validated +public class FactoryController { + + @Resource + private FactoryService factoryService; + + @PostMapping("/create") + @Operation(summary = "创建GAS工厂") + @PreAuthorize("@ss.hasPermission('gas:factory:create')") + public CommonResult createFactory(@Valid @RequestBody FactorySaveReqVO createReqVO) { + return success(factoryService.createFactory(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新GAS工厂") + @PreAuthorize("@ss.hasPermission('gas:factory:update')") + public CommonResult updateFactory(@Valid @RequestBody FactorySaveReqVO updateReqVO) { + factoryService.updateFactory(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除GAS工厂") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('gas:factory:delete')") + public CommonResult deleteFactory(@RequestParam("id") Long id) { + factoryService.deleteFactory(id); + return success(true); + } + + @DeleteMapping("/delete-list") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除GAS工厂") + @PreAuthorize("@ss.hasPermission('gas:factory:delete')") + public CommonResult deleteFactoryList(@RequestParam("ids") List ids) { + factoryService.deleteFactoryListByIds(ids); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得GAS工厂") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('gas:factory:query')") + public CommonResult getFactory(@RequestParam("id") Long id) { + FactoryDO factory = factoryService.getFactory(id); + return success(BeanUtils.toBean(factory, FactoryRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得GAS工厂分页") + @PreAuthorize("@ss.hasPermission('gas:factory:query')") + public CommonResult> getFactoryPage(@Valid FactoryPageReqVO pageReqVO) { + PageResult pageResult = factoryService.getFactoryPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, FactoryRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出GAS工厂 Excel") + @PreAuthorize("@ss.hasPermission('gas:factory:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportFactoryExcel(@Valid FactoryPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = factoryService.getFactoryPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "GAS工厂.xls", "数据", FactoryRespVO.class, + BeanUtils.toBean(list, FactoryRespVO.class)); + } + +} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/FenceAlarmController.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/FenceAlarmController.java index 6312495..a60d949 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/FenceAlarmController.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/FenceAlarmController.java @@ -44,7 +44,7 @@ public class FenceAlarmController { @PostMapping("/create") @Operation(summary = "创建GAS手持探测器围栏报警") @PreAuthorize("@ss.hasPermission('gas:fence-alarm:create')") - public CommonResult createFenceAlarm(@Valid @RequestBody FenceAlarmSaveReqVO createReqVO) { + public CommonResult createFenceAlarm(@Valid @RequestBody FenceAlarmSaveReqVO createReqVO) { return success(fenceAlarmService.createFenceAlarm(createReqVO)); } @@ -60,7 +60,7 @@ public class FenceAlarmController { @Operation(summary = "删除GAS手持探测器围栏报警") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('gas:fence-alarm:delete')") - public CommonResult deleteFenceAlarm(@RequestParam("id") String id) { + public CommonResult deleteFenceAlarm(@RequestParam("id") Long id) { fenceAlarmService.deleteFenceAlarm(id); return success(true); } @@ -69,7 +69,7 @@ public class FenceAlarmController { @Parameter(name = "ids", description = "编号", required = true) @Operation(summary = "批量删除GAS手持探测器围栏报警") @PreAuthorize("@ss.hasPermission('gas:fence-alarm:delete')") - public CommonResult deleteFenceAlarmList(@RequestParam("ids") List ids) { + public CommonResult deleteFenceAlarmList(@RequestParam("ids") List ids) { fenceAlarmService.deleteFenceAlarmListByIds(ids); return success(true); } @@ -78,7 +78,7 @@ public class FenceAlarmController { @Operation(summary = "获得GAS手持探测器围栏报警") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('gas:fence-alarm:query')") - public CommonResult getFenceAlarm(@RequestParam("id") String id) { + public CommonResult getFenceAlarm(@RequestParam("id") Long id) { FenceAlarmDO fenceAlarm = fenceAlarmService.getFenceAlarm(id); return success(BeanUtils.toBean(fenceAlarm, FenceAlarmRespVO.class)); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/FenceController.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/FenceController.java index bb938ee..5670ee4 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/FenceController.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/FenceController.java @@ -5,6 +5,8 @@ import cn.iocoder.yudao.module.hand.service.FenceService; import cn.iocoder.yudao.module.hand.vo.FencePageReqVO; import cn.iocoder.yudao.module.hand.vo.FenceRespVO; import cn.iocoder.yudao.module.hand.vo.FenceSaveReqVO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import org.springframework.web.bind.annotation.*; import jakarta.annotation.Resource; import org.springframework.validation.annotation.Validated; @@ -44,7 +46,7 @@ public class FenceController { @PostMapping("/create") @Operation(summary = "创建GAS电子围栏") @PreAuthorize("@ss.hasPermission('gas:fence:create')") - public CommonResult createFence(@Valid @RequestBody FenceSaveReqVO createReqVO) { + public CommonResult createFence(@Valid @RequestBody FenceSaveReqVO createReqVO) { return success(fenceService.createFence(createReqVO)); } @@ -60,7 +62,9 @@ public class FenceController { @Operation(summary = "删除GAS电子围栏") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('gas:fence:delete')") - public CommonResult deleteFence(@RequestParam("id") String id) { + public CommonResult deleteFence(@RequestParam("id") Long id) { + + fenceService.deleteFence(id); return success(true); } @@ -69,7 +73,7 @@ public class FenceController { @Parameter(name = "ids", description = "编号", required = true) @Operation(summary = "批量删除GAS电子围栏") @PreAuthorize("@ss.hasPermission('gas:fence:delete')") - public CommonResult deleteFenceList(@RequestParam("ids") List ids) { + public CommonResult deleteFenceList(@RequestParam("ids") List ids) { fenceService.deleteFenceListByIds(ids); return success(true); } @@ -78,7 +82,7 @@ public class FenceController { @Operation(summary = "获得GAS电子围栏") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('gas:fence:query')") - public CommonResult getFence(@RequestParam("id") String id) { + public CommonResult getFence(@RequestParam("id") Long id) { FenceDO fence = fenceService.getFence(id); return success(BeanUtils.toBean(fence, FenceRespVO.class)); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/GasTypeController.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/GasTypeController.java index 95bf657..fd9f221 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/GasTypeController.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/GasTypeController.java @@ -44,7 +44,7 @@ public class GasTypeController { @PostMapping("/create") @Operation(summary = "创建GAS气体") @PreAuthorize("@ss.hasPermission('gas:type:create')") - public CommonResult createType(@Valid @RequestBody GasTypeSaveReqVO createReqVO) { + public CommonResult createType(@Valid @RequestBody GasTypeSaveReqVO createReqVO) { return success(typeService.createType(createReqVO)); } @@ -60,7 +60,7 @@ public class GasTypeController { @Operation(summary = "删除GAS气体") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('gas:type:delete')") - public CommonResult deleteType(@RequestParam("id") String id) { + public CommonResult deleteType(@RequestParam("id") Long id) { typeService.deleteType(id); return success(true); } @@ -69,7 +69,7 @@ public class GasTypeController { @Parameter(name = "ids", description = "编号", required = true) @Operation(summary = "批量删除GAS气体") @PreAuthorize("@ss.hasPermission('gas:type:delete')") - public CommonResult deleteTypeList(@RequestParam("ids") List ids) { + public CommonResult deleteTypeList(@RequestParam("ids") List ids) { typeService.deleteTypeListByIds(ids); return success(true); } @@ -78,7 +78,7 @@ public class GasTypeController { @Operation(summary = "获得GAS气体") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('gas:type:query')") - public CommonResult getType(@RequestParam("id") String id) { + public CommonResult getType(@RequestParam("id") Long id) { GasTypeDO type = typeService.getType(id); return success(BeanUtils.toBean(type, GasTypeRespVO.class)); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandAlarmController.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandAlarmController.java index cc6ff86..7960001 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandAlarmController.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandAlarmController.java @@ -43,7 +43,7 @@ public class HandAlarmController { @PostMapping("/create") @Operation(summary = "创建GAS手持探测器警报") @PreAuthorize("@ss.hasPermission('gas:hand-alarm:create')") - public CommonResult createHandAlarm(@Valid @RequestBody HandAlarmSaveReqVO createReqVO) { + public CommonResult createHandAlarm(@Valid @RequestBody HandAlarmSaveReqVO createReqVO) { return success(handAlarmService.createHandAlarm(createReqVO)); } @@ -59,7 +59,7 @@ public class HandAlarmController { @Operation(summary = "删除GAS手持探测器警报") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('gas:hand-alarm:delete')") - public CommonResult deleteHandAlarm(@RequestParam("id") String id) { + public CommonResult deleteHandAlarm(@RequestParam("id") Long id) { handAlarmService.deleteHandAlarm(id); return success(true); } @@ -68,7 +68,7 @@ public class HandAlarmController { @Parameter(name = "ids", description = "编号", required = true) @Operation(summary = "批量删除GAS手持探测器警报") @PreAuthorize("@ss.hasPermission('gas:hand-alarm:delete')") - public CommonResult deleteHandAlarmList(@RequestParam("ids") List ids) { + public CommonResult deleteHandAlarmList(@RequestParam("ids") List ids) { handAlarmService.deleteHandAlarmListByIds(ids); return success(true); } @@ -77,7 +77,7 @@ public class HandAlarmController { @Operation(summary = "获得GAS手持探测器警报") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('gas:hand-alarm:query')") - public CommonResult getHandAlarm(@RequestParam("id") String id) { + public CommonResult getHandAlarm(@RequestParam("id") Long id) { HandAlarmDO handAlarm = handAlarmService.getHandAlarm(id); return success(BeanUtils.toBean(handAlarm, HandAlarmRespVO.class)); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandDetectorController.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandDetectorController.java index 69660f5..219efd6 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandDetectorController.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandDetectorController.java @@ -1,7 +1,11 @@ package cn.iocoder.yudao.module.hand.controller.admin; +import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.module.hand.dal.HandDetectorDO; import cn.iocoder.yudao.module.hand.service.HandDetectorService; +import cn.iocoder.yudao.module.hand.util.RedisKeyUtil; +import cn.iocoder.yudao.module.hand.util.RedisUtil; +import cn.iocoder.yudao.module.hand.vo.HandDetectorPageReqVO; import cn.iocoder.yudao.module.hand.vo.HandDetectorRespVO; import cn.iocoder.yudao.module.hand.vo.HandDetectorSaveReqVO; import org.springframework.web.bind.annotation.*; @@ -22,13 +26,17 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; - +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser; +import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.HAND_DETECTOR_NOT_EXISTS; +import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.HAND_DETECTOR_REDIS_NOT_EXISTS; @Tag(name = "管理后台 - GAS手持探测器") @@ -43,14 +51,14 @@ public class HandDetectorController { @PostMapping("/create") @Operation(summary = "创建GAS手持探测器") @PreAuthorize("@ss.hasPermission('gas:hand-detector:create')") - public CommonResult createHandDetector(@Valid @RequestBody HandDetectorSaveReqVO createReqVO) { + public CommonResult createHandDetector(@Valid @RequestBody HandDetectorSaveReqVO createReqVO) { return success(handDetectorService.createHandDetector(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新GAS手持探测器") @PreAuthorize("@ss.hasPermission('gas:hand-detector:update')") - public CommonResult updateHandDetector(@Valid @RequestBody cn.iocoder.yudao.module.hand.vo.HandDetectorSaveReqVO updateReqVO) { + public CommonResult updateHandDetector(@Valid @RequestBody HandDetectorSaveReqVO updateReqVO) { handDetectorService.updateHandDetector(updateReqVO); return success(true); } @@ -59,7 +67,7 @@ public class HandDetectorController { @Operation(summary = "删除GAS手持探测器") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('gas:hand-detector:delete')") - public CommonResult deleteHandDetector(@RequestParam("id") String id) { + public CommonResult deleteHandDetector(@RequestParam("id") Long id) { handDetectorService.deleteHandDetector(id); return success(true); } @@ -68,7 +76,7 @@ public class HandDetectorController { @Parameter(name = "ids", description = "编号", required = true) @Operation(summary = "批量删除GAS手持探测器") @PreAuthorize("@ss.hasPermission('gas:hand-detector:delete')") - public CommonResult deleteHandDetectorList(@RequestParam("ids") List ids) { + public CommonResult deleteHandDetectorList(@RequestParam("ids") List ids) { handDetectorService.deleteHandDetectorListByIds(ids); return success(true); } @@ -77,7 +85,7 @@ public class HandDetectorController { @Operation(summary = "获得GAS手持探测器") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('gas:hand-detector:query')") - public CommonResult getHandDetector(@RequestParam("id") String id) { + public CommonResult getHandDetector(@RequestParam("id") Long id) { HandDetectorDO handDetector = handDetectorService.getHandDetector(id); return success(BeanUtils.toBean(handDetector, HandDetectorRespVO.class)); } @@ -85,7 +93,7 @@ public class HandDetectorController { @GetMapping("/page") @Operation(summary = "获得GAS手持探测器分页") @PreAuthorize("@ss.hasPermission('gas:hand-detector:query')") - public CommonResult> getHandDetectorPage(@Valid cn.iocoder.yudao.module.hand.vo.HandDetectorPageReqVO pageReqVO) { + public CommonResult> getHandDetectorPage(@Valid HandDetectorPageReqVO pageReqVO) { PageResult pageResult = handDetectorService.getHandDetectorPage(pageReqVO); return success(BeanUtils.toBean(pageResult,HandDetectorRespVO.class)); } @@ -94,13 +102,24 @@ public class HandDetectorController { @Operation(summary = "导出GAS手持探测器 Excel") @PreAuthorize("@ss.hasPermission('gas:hand-detector:export')") @ApiAccessLog(operateType = EXPORT) - public void exportHandDetectorExcel(@Valid cn.iocoder.yudao.module.hand.vo.HandDetectorPageReqVO pageReqVO, + public void exportHandDetectorExcel(@Valid HandDetectorPageReqVO pageReqVO, HttpServletResponse response) throws IOException { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); List list = handDetectorService.getHandDetectorPage(pageReqVO).getList(); // 导出 Excel - ExcelUtils.write(response, "GAS手持探测器.xls", "数据", cn.iocoder.yudao.module.hand.vo.HandDetectorRespVO.class, - BeanUtils.toBean(list, cn.iocoder.yudao.module.hand.vo.HandDetectorRespVO.class)); + ExcelUtils.write(response, "GAS手持探测器.xls", "数据", HandDetectorRespVO.class, + BeanUtils.toBean(list, HandDetectorRespVO.class)); } + @GetMapping("/getByHandData") + @Operation(summary = "获得GAS手持探测器实时数据") + public CommonResult> getHandData(){ + LoginUser loginUser = getLoginUser(); + if (null == loginUser){ + throw exception(HAND_DETECTOR_REDIS_NOT_EXISTS); + } + String tenantDeviceHashKey = RedisKeyUtil.getTenantDeviceHashKey(loginUser.getTenantId()); + Map handData = handDetectorService.getHandData(tenantDeviceHashKey); + return CommonResult.success(handData); + } } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandTdengineController.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandTdengineController.java new file mode 100644 index 0000000..8d22218 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/admin/HandTdengineController.java @@ -0,0 +1,66 @@ +package cn.iocoder.yudao.module.hand.controller.admin; + +import cn.iocoder.yudao.framework.security.core.LoginUser; +import cn.iocoder.yudao.module.hand.dal.HandDetectorDO; +import cn.iocoder.yudao.module.hand.service.HandDetectorService; +import cn.iocoder.yudao.module.hand.service.TdengineService; +import cn.iocoder.yudao.module.hand.util.RedisKeyUtil; +import cn.iocoder.yudao.module.hand.util.RedisUtil; +import cn.iocoder.yudao.module.hand.vo.*; +import org.springframework.web.bind.annotation.*; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import jakarta.validation.constraints.*; +import jakarta.validation.*; +import jakarta.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser; +import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.HAND_DETECTOR_NOT_EXISTS; +import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.HAND_DETECTOR_REDIS_NOT_EXISTS; + + +@Tag(name = "管理后台 - 时序数据库查询") +@RestController +@RequestMapping("/gas/tdengine") +@Validated +public class HandTdengineController { + + @Resource + private TdengineService tdengineService; + + + @GetMapping("/page") + @Operation(summary = "获取历史数据") + @PreAuthorize("@ss.hasPermission('gas:hand-td:query')") + public CommonResult> getHandDetectorPage(@Valid HandTdenginePageVO pageReqVO) { + PageResult pageResult = tdengineService.getHandDataLog(pageReqVO); + return success(pageResult); + } + @GetMapping("/originalLogPage") + @Operation(summary = "获取原始数据") + @PreAuthorize("@ss.hasPermission('gas:hand-td:queryOriginal')") + public CommonResult> originalLogPage(@Valid HandTdenginePageVO pageReqVO) { + PageResult pageResult = tdengineService.getOriginalLogPage(pageReqVO); + return success(pageResult); + } + +} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/package-info.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/package-info.java index c354f61..1be98d6 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/package-info.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/controller/package-info.java @@ -1,4 +1,4 @@ /** * infra 模块的 web 配置 */ -package cn.iocoder.yudao.module.lock.controller; +package cn.iocoder.yudao.module.hand.controller; diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/AlarmRuleDO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/AlarmRuleDO.java index 4a16bd6..9ba2b74 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/AlarmRuleDO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/AlarmRuleDO.java @@ -25,16 +25,16 @@ public class AlarmRuleDO extends BaseDO { /** * 主键ID */ - @TableId(type = IdType.INPUT) - private String id; + @TableId + private Long id; /** * 气体类型ID */ - private String gasTypeId; + private Long gasTypeId; /** * 警报类型ID */ - private String alarmTypeId; + private Long alarmTypeId; /** * 警报名称 */ @@ -71,18 +71,9 @@ public class AlarmRuleDO extends BaseDO { * 备注 */ private String remark; + /** - * 删除标志 - */ - private Integer delFlag; - /** - * 创建者 - */ - private String createBy; - /** - * 更新者 + * 租户id */ - private String updateBy; - - + private Integer tenantId; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/AlarmTypeDO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/AlarmTypeDO.java index 8af1d0f..96f9ef4 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/AlarmTypeDO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/AlarmTypeDO.java @@ -25,8 +25,8 @@ public class AlarmTypeDO extends BaseDO { /** * 主键ID */ - @TableId(type = IdType.INPUT) - private String id; + @TableId + private Long id; /** * 名称 */ @@ -52,17 +52,9 @@ public class AlarmTypeDO extends BaseDO { */ private String remark; /** - * 删除标志 + * 租户id */ - private Integer delFlag; - /** - * 创建者 - */ - private String createBy; - /** - * 更新者 - */ - private String updateBy; + private Integer tenantId; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/FactoryDO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/FactoryDO.java new file mode 100644 index 0000000..31862e5 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/FactoryDO.java @@ -0,0 +1,97 @@ +package cn.iocoder.yudao.module.hand.dal; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * GAS工厂 DO + * + * @author 超级管理员 + */ +@TableName("gas_factory") +@KeySequence("gas_factory_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class FactoryDO extends BaseDO { + + /** + * 主键ID + */ + @TableId + private Long id; + /** + * 父节点ID + */ + private Long parentId; + /** + * 层级(1:工厂;2:车间;3:班组) + */ + private Integer type; + /** + * 名称 + */ + private String name; + /** + * 城市 + */ + private String city; + /** + * 总警报数 + */ + private Integer alarmTotal; + /** + * 已处理警报数 + */ + private Integer alarmDeal; + /** + * 区域图 + */ + private String picUrl; + /** + * 区域图缩放比例 + */ + private Integer picScale; + /** + * 在区域图X坐标值 + */ + private Double picX; + /** + * 在区域图X坐标值 + */ + private Double picY; + /** + * 经度 + */ + private Double longitude; + /** + * 纬度 + */ + private Double latitude; + /** + * 区域西南坐标 + */ + private String rectSouthWest; + /** + * 区域东北坐标 + */ + private String rectNorthEast; + /** + * 排序 + */ + private Integer sortOrder; + /** + * 备注 + */ + private String remark; + + + +} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/FenceAlarmDO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/FenceAlarmDO.java index 8433d8f..1bcdf54 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/FenceAlarmDO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/FenceAlarmDO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.hand.dal; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; import java.util.*; import java.time.LocalDateTime; @@ -27,16 +28,27 @@ public class FenceAlarmDO extends BaseDO { /** * 主键ID */ - @TableId(type = IdType.INPUT) - private String id; + @TableId + private Long id; /** - * 探头ID + * 手持表ID */ - private String detectorId; + private Long detectorId; + + + /** + * 手持表ID + */ + private String name; + /** + * 手持表SN + */ + private String sn; + /** * 围栏id */ - private String fenceId; + private Long fenceId; /** * 报警类型 */ @@ -73,18 +85,9 @@ public class FenceAlarmDO extends BaseDO { * 备注 */ private String remark; + /** - * 删除标志 - */ - private Integer delFlag; - /** - * 创建者 - */ - private String createBy; - /** - * 更新者 + * 租户id */ - private String updateBy; - - + private Integer tenantId; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/FenceDO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/FenceDO.java index ada3dfc..a559562 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/FenceDO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/FenceDO.java @@ -25,8 +25,8 @@ public class FenceDO extends BaseDO { /** * 主键ID */ - @TableId(type = IdType.INPUT) - private String id; + @TableId + private Long id; /** * 围栏名称 */ @@ -47,18 +47,9 @@ public class FenceDO extends BaseDO { * 备注 */ private String remark; + /** - * 删除标志 - */ - private Integer delFlag; - /** - * 创建者 - */ - private String createBy; - /** - * 更新者 + * 租户id */ - private String updateBy; - - + private Integer tenantId; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/GasTypeDO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/GasTypeDO.java index e4a0227..4e5d237 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/GasTypeDO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/GasTypeDO.java @@ -25,8 +25,8 @@ public class GasTypeDO extends BaseDO { /** * 主键ID */ - @TableId(type = IdType.INPUT) - private String id; + @TableId + private Long id; /** * 名称 */ @@ -47,18 +47,10 @@ public class GasTypeDO extends BaseDO { * 备注 */ private String remark; - /** - * 删除标志 - */ - private Integer delFlag; - /** - * 创建者 - */ - private String createBy; - /** - * 更新者 - */ - private String updateBy; + /** + * 租户id + */ + private Integer tenantId; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/HandAlarmDO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/HandAlarmDO.java index ea741fb..573f644 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/HandAlarmDO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/HandAlarmDO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.hand.dal; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; import java.util.*; import java.time.LocalDateTime; @@ -27,8 +28,20 @@ public class HandAlarmDO extends BaseDO { /** * 主键ID */ - @TableId(type = IdType.INPUT) - private String id; + @TableId + private Long id; + + /** + * 名称 + */ + private String name; + + + /** + * 报警类型 + */ + private Integer alarmType; + /** * 警报方式/级别(0:正常状态;1:一级警报;2:二级警报;3:弹窗警报) */ @@ -77,18 +90,10 @@ public class HandAlarmDO extends BaseDO { * 备注 */ private String remark; + /** - * 删除标志 - */ - private Integer delFlag; - /** - * 创建者 - */ - private String createBy; - /** - * 更新者 + * 租户id */ - private String updateBy; - + private Long tenantId; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/HandDetectorDO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/HandDetectorDO.java index c9519d3..eb96129 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/HandDetectorDO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/dal/HandDetectorDO.java @@ -4,6 +4,8 @@ import lombok.*; import com.baomidou.mybatisplus.annotation.*; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import java.math.BigDecimal; + /** * GAS手持探测器 DO * @@ -22,8 +24,8 @@ public class HandDetectorDO extends BaseDO { /** * 主键ID */ - @TableId(type = IdType.INPUT) - private String id; + @TableId + private Long id; /** * SN */ @@ -35,11 +37,11 @@ public class HandDetectorDO extends BaseDO { /** * 围栏id */ - private String fenceId; + private String fenceIds; /** * 气体类型ID */ - private String gasTypeId; + private Long gasTypeId; /** * 气体化学式 */ @@ -52,10 +54,11 @@ public class HandDetectorDO extends BaseDO { * 测量范围中的最大值 */ private Double max; + /** - * 状态(0:未知;1:正常;2:故障;3:离线) + * 低于多少电量报警 */ - private Integer status; + private BigDecimal batteryAlarmValue; /** * 单位 */ @@ -73,14 +76,6 @@ public class HandDetectorDO extends BaseDO { */ private Integer enableStatus; /** - * 在区域图X坐标值 - */ - private Double picX; - /** - * 在区域图Y坐标值 - */ - private Double picY; - /** * 经度 */ private Double longitude; @@ -100,18 +95,10 @@ public class HandDetectorDO extends BaseDO { * 备注 */ private String remark; + /** - * 删除标志 - */ - private Integer delFlag; - /** - * 创建者 - */ - private String createBy; - /** - * 更新者 + * 租户id */ - private String updateBy; - + private Integer tenantId; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/AlarmLevelEnum.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/AlarmLevelEnum.java new file mode 100644 index 0000000..a662be9 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/AlarmLevelEnum.java @@ -0,0 +1,48 @@ +package cn.iocoder.yudao.module.hand.enums; + +import lombok.Getter; + +@Getter +public enum AlarmLevelEnum { + OFFLINE(-1,"离线报警"), + NORMAL(0,"正常状态"), + LEVEL_1(1,"一级报警"), + LEVEL_2(2,"二级报警"), + LEVEL_3(3,"弹窗警报"); + private Integer value; + private String name; + AlarmLevelEnum(Integer val, String name) { + this.value = val; + this.name = name; + } + + public Integer value() { + return value; + } + /** + * 根据value获取到枚举类名称 + * + * @param value + * @return + */ + public static String getNameByValue(Integer value) { + AlarmLevelEnum type = getByValue(value); + return null == type ? "" : type.getName(); + } + /** + * 根据value获取枚举类型 + * + * @param value + * @return + */ + public static AlarmLevelEnum getByValue(Integer value) { + if (null != value) { + for (AlarmLevelEnum type : AlarmLevelEnum.values()) { + if (type.getValue() == value) { + return type; + } + } + } + return null; + } +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/AlarmType.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/AlarmType.java new file mode 100644 index 0000000..ec11299 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/AlarmType.java @@ -0,0 +1,53 @@ +package cn.iocoder.yudao.module.hand.enums; + +import lombok.Getter; + +import java.util.Objects; + +@Getter +public enum AlarmType { + GAS(1, "气体报警"), + BATTERY(2, "电量报警"), + OFFLINE(3, "离线报警"); + + private final Integer type; + private final String name; + + AlarmType(Integer type, String name) { + this.type = type; + this.name = name; + } + + // 通过 int 值获取枚举实例 + public static AlarmType fromType(Integer type) { + for (AlarmType valveType : AlarmType.values()) { + if (Objects.equals(valveType.getType(), type)) { + return valveType; + } + } + throw new IllegalArgumentException("未知的阀门类型: " + type); + } + + // 通过 int 值获取名称 + public static String getNameByType(int type) { + AlarmType valveType = fromType(type); + return valveType.getName(); + } + + // 通过名称获取枚举实例 + public static AlarmType fromName(String name) { + for (AlarmType valveType : AlarmType.values()) { + if (valveType.getName().equals(name)) { + return valveType; + } + } + throw new IllegalArgumentException("未知的阀门名称: " + name); + } + + // 通过名称获取 int 值 + public static Integer getTypeByName(String name) { + AlarmType valveType = fromName(name); + return valveType.getType(); + } + +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/EnableStatus.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/EnableStatus.java new file mode 100644 index 0000000..8d54076 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/EnableStatus.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.hand.enums; + +public enum EnableStatus { + DISABLED(0), ENABLED(1),REPAIR(2); + private Integer value; + + EnableStatus(Integer val) { + this.value = val; + } + + public Integer value() { + return value; + } +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/ErrorCodeConstants.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/ErrorCodeConstants.java index 7120e3f..36fda56 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/ErrorCodeConstants.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/ErrorCodeConstants.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; public interface ErrorCodeConstants { + ErrorCode HAND_DETECTOR_SN_EXISTS = new ErrorCode(100001, "GAS手持探测器SN已经存在"); ErrorCode HAND_DETECTOR_NOT_EXISTS = new ErrorCode(100001, "GAS手持探测器不存在"); @@ -15,7 +16,12 @@ public interface ErrorCodeConstants { ErrorCode FENCE_NOT_EXISTS = new ErrorCode(100005, "GAS电子围栏不存在"); + ErrorCode FENCE_EXISTS_HAND_DETECTOR = new ErrorCode(100005, "围栏下仍有绑定的手持设备,请先解除关联后再进行删除操作"); + ErrorCode ALARM_TYPE_NOT_EXISTS = new ErrorCode(100006, "GAS警报类型不存在"); ErrorCode ALARM_RULE_NOT_EXISTS = new ErrorCode(100007, "GAS警报规则不存在"); + + ErrorCode FACTORY_NOT_EXISTS = new ErrorCode(1000071, "GAS工厂不存在"); + ErrorCode HAND_DETECTOR_REDIS_NOT_EXISTS = new ErrorCode(100001, "请先登录,再查看"); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/FenceStatusType.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/FenceStatusType.java new file mode 100644 index 0000000..bc24067 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/FenceStatusType.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.module.hand.enums; + +import lombok.Getter; + +import java.util.Objects; + +@Getter +public enum FenceStatusType { + DISABLED(1,"启用"), + ENABLED(2,"禁用"); + + private final Integer type; + private final String name; + + FenceStatusType(Integer type, String name) { + this.type = type; + this.name = name; + } + + // 通过 int 值获取枚举实例 + public static FenceStatusType fromType(Integer type) { + for (FenceStatusType valveType : FenceStatusType.values()) { + if (Objects.equals(valveType.getType(), type)) { + return valveType; + } + } + throw new IllegalArgumentException("未知的阀门类型: " + type); + } + + // 通过 int 值获取名称 + public static String getNameByType(int type) { + FenceStatusType valveType = fromType(type); + return valveType.getName(); + } + + // 通过名称获取枚举实例 + public static FenceStatusType fromName(String name) { + for (FenceStatusType valveType : FenceStatusType.values()) { + if (valveType.getName().equals(name)) { + return valveType; + } + } + throw new IllegalArgumentException("未知的阀门名称: " + name); + } + + // 通过名称获取 int 值 + public static Integer getTypeByName(String name) { + FenceStatusType valveType = fromName(name); + return valveType.getType(); + } + +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/FenceType.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/FenceType.java new file mode 100644 index 0000000..232c9a0 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/FenceType.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.module.hand.enums; + +import lombok.Getter; + +import java.util.Objects; + +@Getter +public enum FenceType { + OUTSIDE(1,"超出围栏报警"), + INSIDE(2,"进入围栏报警"); + + private final Integer type; + private final String name; + + FenceType(Integer type, String name) { + this.type = type; + this.name = name; + } + + // 通过 int 值获取枚举实例 + public static FenceType fromType(Integer type) { + for (FenceType valveType : FenceType.values()) { + if (Objects.equals(valveType.getType(), type)) { + return valveType; + } + } + throw new IllegalArgumentException("未知的阀门类型: " + type); + } + + // 通过 int 值获取名称 + public static String getNameByType(int type) { + FenceType valveType = fromType(type); + return valveType.getName(); + } + + // 通过名称获取枚举实例 + public static FenceType fromName(String name) { + for (FenceType valveType : FenceType.values()) { + if (valveType.getName().equals(name)) { + return valveType; + } + } + throw new IllegalArgumentException("未知的阀门名称: " + name); + } + + // 通过名称获取 int 值 + public static Integer getTypeByName(String name) { + FenceType valveType = fromName(name); + return valveType.getType(); + } + +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/HandAlarmType.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/HandAlarmType.java new file mode 100644 index 0000000..abb8a1c --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/HandAlarmType.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.module.hand.enums; + +import lombok.Getter; + +import java.util.Objects; + +@Getter +public enum HandAlarmType { + NORMAL(0, "正常"), + ALARM(1, "报警"); + + private final Integer type; + private final String name; + + HandAlarmType(Integer type, String name) { + this.type = type; + this.name = name; + } + + // 通过 int 值获取枚举实例 + public static HandAlarmType fromType(Integer type) { + for (HandAlarmType valveType : HandAlarmType.values()) { + if (Objects.equals(valveType.getType(), type)) { + return valveType; + } + } + throw new IllegalArgumentException("未知的阀门类型: " + type); + } + + // 通过 int 值获取名称 + public static String getNameByType(int type) { + HandAlarmType valveType = fromType(type); + return valveType.getName(); + } + + // 通过名称获取枚举实例 + public static HandAlarmType fromName(String name) { + for (HandAlarmType valveType : HandAlarmType.values()) { + if (valveType.getName().equals(name)) { + return valveType; + } + } + throw new IllegalArgumentException("未知的阀门名称: " + name); + } + + // 通过名称获取 int 值 + public static Integer getTypeByName(String name) { + HandAlarmType valveType = fromName(name); + return valveType.getType(); + } + +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/MaxDirection.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/MaxDirection.java new file mode 100644 index 0000000..4cb4513 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/MaxDirection.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.hand.enums; + +public enum MaxDirection { + DOWN(0), UP(1); + private Integer value; + + MaxDirection(Integer val) { + this.value = val; + } + + public Integer value() { + return value; + } +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/OnlineStatusType.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/OnlineStatusType.java new file mode 100644 index 0000000..615ab3d --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/enums/OnlineStatusType.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.module.hand.enums; + +import lombok.Getter; + +import java.util.Objects; + +@Getter +public enum OnlineStatusType { + OFFLINE(0, "离线"), + ONLINE(1, "正常"); + + private final Integer type; + private final String name; + + OnlineStatusType(Integer type, String name) { + this.type = type; + this.name = name; + } + + // 通过 int 值获取枚举实例 + public static OnlineStatusType fromType(Integer type) { + for (OnlineStatusType valveType : OnlineStatusType.values()) { + if (Objects.equals(valveType.getType(), type)) { + return valveType; + } + } + throw new IllegalArgumentException("未知的阀门类型: " + type); + } + + // 通过 int 值获取名称 + public static String getNameByType(int type) { + OnlineStatusType valveType = fromType(type); + return valveType.getName(); + } + + // 通过名称获取枚举实例 + public static OnlineStatusType fromName(String name) { + for (OnlineStatusType valveType : OnlineStatusType.values()) { + if (valveType.getName().equals(name)) { + return valveType; + } + } + throw new IllegalArgumentException("未知的阀门名称: " + name); + } + + // 通过名称获取 int 值 + public static Integer getTypeByName(String name) { + OnlineStatusType valveType = fromName(name); + return valveType.getType(); + } + +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/AlarmRuleMapper.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/AlarmRuleMapper.java index d0c552f..484b425 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/AlarmRuleMapper.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/AlarmRuleMapper.java @@ -30,10 +30,7 @@ public interface AlarmRuleMapper extends BaseMapperX { .eqIfPresent(AlarmRuleDO::getDirection, reqVO.getDirection()) .eqIfPresent(AlarmRuleDO::getSortOrder, reqVO.getSortOrder()) .eqIfPresent(AlarmRuleDO::getRemark, reqVO.getRemark()) - .eqIfPresent(AlarmRuleDO::getDelFlag, reqVO.getDelFlag()) - .eqIfPresent(AlarmRuleDO::getCreateBy, reqVO.getCreateBy()) .betweenIfPresent(AlarmRuleDO::getCreateTime, reqVO.getCreateTime()) - .eqIfPresent(AlarmRuleDO::getUpdateBy, reqVO.getUpdateBy()) .orderByDesc(AlarmRuleDO::getId)); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/AlarmTypeMapper.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/AlarmTypeMapper.java index 9d37f0c..2617dda 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/AlarmTypeMapper.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/AlarmTypeMapper.java @@ -25,10 +25,7 @@ public interface AlarmTypeMapper extends BaseMapperX { .eqIfPresent(AlarmTypeDO::getLevel, reqVO.getLevel()) .eqIfPresent(AlarmTypeDO::getSortOrder, reqVO.getSortOrder()) .eqIfPresent(AlarmTypeDO::getRemark, reqVO.getRemark()) - .eqIfPresent(AlarmTypeDO::getDelFlag, reqVO.getDelFlag()) - .eqIfPresent(AlarmTypeDO::getCreateBy, reqVO.getCreateBy()) .betweenIfPresent(AlarmTypeDO::getCreateTime, reqVO.getCreateTime()) - .eqIfPresent(AlarmTypeDO::getUpdateBy, reqVO.getUpdateBy()) .orderByDesc(AlarmTypeDO::getId)); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/FactoryMapper.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/FactoryMapper.java new file mode 100644 index 0000000..4bdf1a5 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/FactoryMapper.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.hand.mapper; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.hand.dal.FactoryDO; +import cn.iocoder.yudao.module.hand.vo.FactoryPageReqVO; +import org.apache.ibatis.annotations.Mapper; + +/** + * GAS工厂 Mapper + * + * @author 超级管理员 + */ +@Mapper +public interface FactoryMapper extends BaseMapperX { + + default PageResult selectPage(FactoryPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(FactoryDO::getParentId, reqVO.getParentId()) + .eqIfPresent(FactoryDO::getType, reqVO.getType()) + .likeIfPresent(FactoryDO::getName, reqVO.getName()) + .eqIfPresent(FactoryDO::getCity, reqVO.getCity()) + .eqIfPresent(FactoryDO::getAlarmTotal, reqVO.getAlarmTotal()) + .eqIfPresent(FactoryDO::getAlarmDeal, reqVO.getAlarmDeal()) + .eqIfPresent(FactoryDO::getPicUrl, reqVO.getPicUrl()) + .eqIfPresent(FactoryDO::getPicScale, reqVO.getPicScale()) + .eqIfPresent(FactoryDO::getPicX, reqVO.getPicX()) + .eqIfPresent(FactoryDO::getPicY, reqVO.getPicY()) + .eqIfPresent(FactoryDO::getLongitude, reqVO.getLongitude()) + .eqIfPresent(FactoryDO::getLatitude, reqVO.getLatitude()) + .eqIfPresent(FactoryDO::getRectSouthWest, reqVO.getRectSouthWest()) + .eqIfPresent(FactoryDO::getRectNorthEast, reqVO.getRectNorthEast()) + .eqIfPresent(FactoryDO::getSortOrder, reqVO.getSortOrder()) + .eqIfPresent(FactoryDO::getRemark, reqVO.getRemark()) + .orderByDesc(FactoryDO::getId)); + } + +} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/FenceAlarmMapper.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/FenceAlarmMapper.java index 65d6df1..a0fda87 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/FenceAlarmMapper.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/FenceAlarmMapper.java @@ -30,10 +30,7 @@ public interface FenceAlarmMapper extends BaseMapperX { .eqIfPresent(FenceAlarmDO::getTAlarmEnd, reqVO.getTAlarmEnd()) .eqIfPresent(FenceAlarmDO::getStatus, reqVO.getStatus()) .eqIfPresent(FenceAlarmDO::getRemark, reqVO.getRemark()) - .eqIfPresent(FenceAlarmDO::getDelFlag, reqVO.getDelFlag()) - .eqIfPresent(FenceAlarmDO::getCreateBy, reqVO.getCreateBy()) .betweenIfPresent(FenceAlarmDO::getCreateTime, reqVO.getCreateTime()) - .eqIfPresent(FenceAlarmDO::getUpdateBy, reqVO.getUpdateBy()) .orderByDesc(FenceAlarmDO::getId)); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/FenceMapper.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/FenceMapper.java index 5fd2ea3..00feafd 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/FenceMapper.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/FenceMapper.java @@ -24,10 +24,7 @@ public interface FenceMapper extends BaseMapperX { .eqIfPresent(FenceDO::getStatus, reqVO.getStatus()) .eqIfPresent(FenceDO::getType, reqVO.getType()) .eqIfPresent(FenceDO::getRemark, reqVO.getRemark()) - .eqIfPresent(FenceDO::getDelFlag, reqVO.getDelFlag()) - .eqIfPresent(FenceDO::getCreateBy, reqVO.getCreateBy()) .betweenIfPresent(FenceDO::getCreateTime, reqVO.getCreateTime()) - .eqIfPresent(FenceDO::getUpdateBy, reqVO.getUpdateBy()) .orderByDesc(FenceDO::getId)); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/GasTypeMapper.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/GasTypeMapper.java index 711133c..c7dbe6a 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/GasTypeMapper.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/GasTypeMapper.java @@ -24,10 +24,7 @@ public interface GasTypeMapper extends BaseMapperX { .eqIfPresent(GasTypeDO::getUnit, reqVO.getUnit()) .eqIfPresent(GasTypeDO::getSortOrder, reqVO.getSortOrder()) .eqIfPresent(GasTypeDO::getRemark, reqVO.getRemark()) - .eqIfPresent(GasTypeDO::getDelFlag, reqVO.getDelFlag()) - .eqIfPresent(GasTypeDO::getCreateBy, reqVO.getCreateBy()) .betweenIfPresent(GasTypeDO::getCreateTime, reqVO.getCreateTime()) - .eqIfPresent(GasTypeDO::getUpdateBy, reqVO.getUpdateBy()) .orderByDesc(GasTypeDO::getId)); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/HandAlarmMapper.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/HandAlarmMapper.java index ed857ad..997e90f 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/HandAlarmMapper.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/HandAlarmMapper.java @@ -31,10 +31,7 @@ public interface HandAlarmMapper extends BaseMapperX { .eqIfPresent(HandAlarmDO::getTAlarmEnd, reqVO.getTAlarmEnd()) .eqIfPresent(HandAlarmDO::getStatus, reqVO.getStatus()) .eqIfPresent(HandAlarmDO::getRemark, reqVO.getRemark()) - .eqIfPresent(HandAlarmDO::getDelFlag, reqVO.getDelFlag()) - .eqIfPresent(HandAlarmDO::getCreateBy, reqVO.getCreateBy()) .betweenIfPresent(HandAlarmDO::getCreateTime, reqVO.getCreateTime()) - .eqIfPresent(HandAlarmDO::getUpdateBy, reqVO.getUpdateBy()) .orderByDesc(HandAlarmDO::getId)); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/HandDetectorMapper.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/HandDetectorMapper.java index e5eb735..2c9d1eb 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/HandDetectorMapper.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/HandDetectorMapper.java @@ -5,7 +5,9 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.module.hand.dal.HandDetectorDO; import cn.iocoder.yudao.module.hand.vo.HandDetectorPageReqVO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.cursor.Cursor; /** * GAS手持探测器 Mapper @@ -19,28 +21,24 @@ public interface HandDetectorMapper extends BaseMapperX { return selectPage(reqVO, new LambdaQueryWrapperX() .eqIfPresent(HandDetectorDO::getSn, reqVO.getSn()) .likeIfPresent(HandDetectorDO::getName, reqVO.getName()) - .eqIfPresent(HandDetectorDO::getFenceId, reqVO.getFenceId()) + .eqIfPresent(HandDetectorDO::getFenceIds, reqVO.getFenceId()) .eqIfPresent(HandDetectorDO::getGasTypeId, reqVO.getGasTypeId()) .eqIfPresent(HandDetectorDO::getGasChemical, reqVO.getGasChemical()) .eqIfPresent(HandDetectorDO::getMin, reqVO.getMin()) .eqIfPresent(HandDetectorDO::getMax, reqVO.getMax()) - .eqIfPresent(HandDetectorDO::getStatus, reqVO.getStatus()) .eqIfPresent(HandDetectorDO::getUnit, reqVO.getUnit()) .eqIfPresent(HandDetectorDO::getModel, reqVO.getModel()) .eqIfPresent(HandDetectorDO::getManufacturer, reqVO.getManufacturer()) .eqIfPresent(HandDetectorDO::getEnableStatus, reqVO.getEnableStatus()) - .eqIfPresent(HandDetectorDO::getPicX, reqVO.getPicX()) - .eqIfPresent(HandDetectorDO::getPicY, reqVO.getPicY()) .eqIfPresent(HandDetectorDO::getLongitude, reqVO.getLongitude()) .eqIfPresent(HandDetectorDO::getLatitude, reqVO.getLatitude()) .eqIfPresent(HandDetectorDO::getAccuracy, reqVO.getAccuracy()) .eqIfPresent(HandDetectorDO::getSortOrder, reqVO.getSortOrder()) .eqIfPresent(HandDetectorDO::getRemark, reqVO.getRemark()) - .eqIfPresent(HandDetectorDO::getDelFlag, reqVO.getDelFlag()) - .eqIfPresent(HandDetectorDO::getCreateBy, reqVO.getCreateBy()) .betweenIfPresent(HandDetectorDO::getCreateTime, reqVO.getCreateTime()) - .eqIfPresent(HandDetectorDO::getUpdateBy, reqVO.getUpdateBy()) .orderByDesc(HandDetectorDO::getId)); } + Cursor selectCursor(QueryWrapper objectQueryWrapper); + } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/TdengineMapper.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/TdengineMapper.java new file mode 100644 index 0000000..440f5dd --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/mapper/TdengineMapper.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.hand.mapper; + + +import cn.iocoder.yudao.module.hand.vo.HandOriginalLog; +import cn.iocoder.yudao.module.hand.vo.HandTdenginePageVO; +import cn.iocoder.yudao.module.hand.vo.TdengineDataVo; +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; // 确保导入这个注解 +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + + +@Mapper +public interface TdengineMapper { + + @InterceptorIgnore(tenantLine = "true") + void insertHandLogBatch(@Param("sn") String sn,@Param("tenantId")Long tenantId, + @Param("logList") List groupedLogs); + + + @InterceptorIgnore(tenantLine = "true") + void saveDataLogBatch(@Param("sn")String sn,@Param("tenantId")Long tenantId, + @Param("dataVoList")List dataVoList); + + IPage selectPage(IPage page,@Param("vo") HandTdenginePageVO pageReqVO); + + IPage selectOriginalPage(IPage page,@Param("vo") HandTdenginePageVO pageReqVO); +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/AlarmRuleService.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/AlarmRuleService.java index 0d2ee03..221af03 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/AlarmRuleService.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/AlarmRuleService.java @@ -22,7 +22,7 @@ public interface AlarmRuleService { * @param createReqVO 创建信息 * @return 编号 */ - String createAlarmRule(@Valid AlarmRuleSaveReqVO createReqVO); + Long createAlarmRule(@Valid AlarmRuleSaveReqVO createReqVO); /** * 更新GAS警报规则 @@ -36,14 +36,14 @@ public interface AlarmRuleService { * * @param id 编号 */ - void deleteAlarmRule(String id); + void deleteAlarmRule(Long id); /** * 批量删除GAS警报规则 * * @param ids 编号 */ - void deleteAlarmRuleListByIds(List ids); + void deleteAlarmRuleListByIds(List ids); /** * 获得GAS警报规则 @@ -51,7 +51,7 @@ public interface AlarmRuleService { * @param id 编号 * @return GAS警报规则 */ - AlarmRuleDO getAlarmRule(String id); + AlarmRuleDO getAlarmRule(Long id); /** * 获得GAS警报规则分页 @@ -61,4 +61,7 @@ public interface AlarmRuleService { */ PageResult getAlarmRulePage(AlarmRulePageReqVO pageReqVO); + Map> selectCacheListMap(Long tenantId); + + } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/AlarmTypeService.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/AlarmTypeService.java index fcce337..212aee8 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/AlarmTypeService.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/AlarmTypeService.java @@ -22,7 +22,7 @@ public interface AlarmTypeService { * @param createReqVO 创建信息 * @return 编号 */ - String createAlarmType(@Valid AlarmTypeSaveReqVO createReqVO); + Long createAlarmType(@Valid AlarmTypeSaveReqVO createReqVO); /** * 更新GAS警报类型 @@ -36,14 +36,14 @@ public interface AlarmTypeService { * * @param id 编号 */ - void deleteAlarmType(String id); + void deleteAlarmType(Long id); /** * 批量删除GAS警报类型 * * @param ids 编号 */ - void deleteAlarmTypeListByIds(List ids); + void deleteAlarmTypeListByIds(List ids); /** * 获得GAS警报类型 @@ -51,7 +51,7 @@ public interface AlarmTypeService { * @param id 编号 * @return GAS警报类型 */ - AlarmTypeDO getAlarmType(String id); + AlarmTypeDO getAlarmType(Long id); /** * 获得GAS警报类型分页 diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/FactoryService.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/FactoryService.java new file mode 100644 index 0000000..705ad21 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/FactoryService.java @@ -0,0 +1,64 @@ +package cn.iocoder.yudao.module.hand.service; + +import java.util.*; + +import cn.iocoder.yudao.module.hand.dal.FactoryDO; +import cn.iocoder.yudao.module.hand.vo.FactoryPageReqVO; +import cn.iocoder.yudao.module.hand.vo.FactorySaveReqVO; +import jakarta.validation.*; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +/** + * GAS工厂 Service 接口 + * + * @author 超级管理员 + */ +public interface FactoryService { + + /** + * 创建GAS工厂 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createFactory(@Valid FactorySaveReqVO createReqVO); + + /** + * 更新GAS工厂 + * + * @param updateReqVO 更新信息 + */ + void updateFactory(@Valid FactorySaveReqVO updateReqVO); + + /** + * 删除GAS工厂 + * + * @param id 编号 + */ + void deleteFactory(Long id); + + /** + * 批量删除GAS工厂 + * + * @param ids 编号 + */ + void deleteFactoryListByIds(List ids); + + /** + * 获得GAS工厂 + * + * @param id 编号 + * @return GAS工厂 + */ + FactoryDO getFactory(Long id); + + /** + * 获得GAS工厂分页 + * + * @param pageReqVO 分页查询 + * @return GAS工厂分页 + */ + PageResult getFactoryPage(FactoryPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/FenceAlarmService.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/FenceAlarmService.java index 6c770f4..acef572 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/FenceAlarmService.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/FenceAlarmService.java @@ -22,7 +22,7 @@ public interface FenceAlarmService { * @param createReqVO 创建信息 * @return 编号 */ - String createFenceAlarm(@Valid FenceAlarmSaveReqVO createReqVO); + Long createFenceAlarm(@Valid FenceAlarmSaveReqVO createReqVO); /** * 更新GAS手持探测器围栏报警 @@ -36,14 +36,14 @@ public interface FenceAlarmService { * * @param id 编号 */ - void deleteFenceAlarm(String id); + void deleteFenceAlarm(Long id); /** * 批量删除GAS手持探测器围栏报警 * * @param ids 编号 */ - void deleteFenceAlarmListByIds(List ids); + void deleteFenceAlarmListByIds(List ids); /** * 获得GAS手持探测器围栏报警 @@ -51,7 +51,7 @@ public interface FenceAlarmService { * @param id 编号 * @return GAS手持探测器围栏报警 */ - FenceAlarmDO getFenceAlarm(String id); + FenceAlarmDO getFenceAlarm(Long id); /** * 获得GAS手持探测器围栏报警分页 @@ -61,4 +61,7 @@ public interface FenceAlarmService { */ PageResult getFenceAlarmPage(FenceAlarmPageReqVO pageReqVO); + void update( FenceAlarmDO updateReqVO); + + } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/FenceService.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/FenceService.java index fe60a3a..e1803c6 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/FenceService.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/FenceService.java @@ -5,6 +5,7 @@ import java.util.*; import cn.iocoder.yudao.module.hand.dal.FenceDO; import cn.iocoder.yudao.module.hand.vo.FencePageReqVO; import cn.iocoder.yudao.module.hand.vo.FenceSaveReqVO; +import cn.iocoder.yudao.module.hand.vo.Geofence; import jakarta.validation.*; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; @@ -22,7 +23,7 @@ public interface FenceService { * @param createReqVO 创建信息 * @return 编号 */ - String createFence(@Valid FenceSaveReqVO createReqVO); + Long createFence(@Valid FenceSaveReqVO createReqVO); /** * 更新GAS电子围栏 @@ -36,14 +37,14 @@ public interface FenceService { * * @param id 编号 */ - void deleteFence(String id); + void deleteFence(Long id); /** * 批量删除GAS电子围栏 * * @param ids 编号 */ - void deleteFenceListByIds(List ids); + void deleteFenceListByIds(List ids); /** * 获得GAS电子围栏 @@ -51,7 +52,7 @@ public interface FenceService { * @param id 编号 * @return GAS电子围栏 */ - FenceDO getFence(String id); + FenceDO getFence(Long id); /** * 获得GAS电子围栏分页 @@ -61,4 +62,11 @@ public interface FenceService { */ PageResult getFencePage(FencePageReqVO pageReqVO); + /** + * 获得GAS电子围栏列表, 用于 判断围栏是否在围栏内 + * + * @param exportReqVO 查询条件 + * @return GAS电子围栏列表 + */ + List getFenceList(List idList); } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/GasTypeService.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/GasTypeService.java index f425588..87a6da4 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/GasTypeService.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/GasTypeService.java @@ -22,7 +22,7 @@ public interface GasTypeService { * @param createReqVO 创建信息 * @return 编号 */ - String createType(@Valid GasTypeSaveReqVO createReqVO); + Long createType(@Valid GasTypeSaveReqVO createReqVO); /** * 更新GAS气体 @@ -36,14 +36,14 @@ public interface GasTypeService { * * @param id 编号 */ - void deleteType(String id); + void deleteType(Long id); /** * 批量删除GAS气体 * * @param ids 编号 */ - void deleteTypeListByIds(List ids); + void deleteTypeListByIds(List ids); /** * 获得GAS气体 @@ -51,7 +51,7 @@ public interface GasTypeService { * @param id 编号 * @return GAS气体 */ - GasTypeDO getType(String id); + GasTypeDO getType(Long id); /** * 获得GAS气体分页 diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/HandAlarmService.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/HandAlarmService.java index 736d5a6..be2982f 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/HandAlarmService.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/HandAlarmService.java @@ -7,7 +7,6 @@ import cn.iocoder.yudao.module.hand.vo.HandAlarmPageReqVO; import cn.iocoder.yudao.module.hand.vo.HandAlarmSaveReqVO; import jakarta.validation.*; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; /** * GAS手持探测器警报 Service 接口 @@ -22,7 +21,7 @@ public interface HandAlarmService { * @param createReqVO 创建信息 * @return 编号 */ - String createHandAlarm(@Valid HandAlarmSaveReqVO createReqVO); + Long createHandAlarm(@Valid HandAlarmSaveReqVO createReqVO); /** * 更新GAS手持探测器警报 @@ -36,14 +35,14 @@ public interface HandAlarmService { * * @param id 编号 */ - void deleteHandAlarm(String id); + void deleteHandAlarm(Long id); /** * 批量删除GAS手持探测器警报 * * @param ids 编号 */ - void deleteHandAlarmListByIds(List ids); + void deleteHandAlarmListByIds(List ids); /** * 获得GAS手持探测器警报 @@ -51,7 +50,7 @@ public interface HandAlarmService { * @param id 编号 * @return GAS手持探测器警报 */ - HandAlarmDO getHandAlarm(String id); + HandAlarmDO getHandAlarm(Long id); /** * 获得GAS手持探测器警报分页 @@ -61,4 +60,5 @@ public interface HandAlarmService { */ PageResult getHandAlarmPage(HandAlarmPageReqVO pageReqVO); + int updateById(HandAlarmDO alarm); } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/HandDetectorService.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/HandDetectorService.java index dfddb6b..0dfbab3 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/HandDetectorService.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/HandDetectorService.java @@ -3,8 +3,10 @@ package cn.iocoder.yudao.module.hand.service; import java.util.*; import cn.iocoder.yudao.module.hand.dal.HandDetectorDO; +import cn.iocoder.yudao.module.hand.vo.HandDataVo; import cn.iocoder.yudao.module.hand.vo.HandDetectorPageReqVO; import cn.iocoder.yudao.module.hand.vo.HandDetectorSaveReqVO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import jakarta.validation.*; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; @@ -22,7 +24,7 @@ public interface HandDetectorService { * @param createReqVO 创建信息 * @return 编号 */ - String createHandDetector(@Valid HandDetectorSaveReqVO createReqVO); + Long createHandDetector(@Valid HandDetectorSaveReqVO createReqVO); /** * 更新GAS手持探测器 @@ -36,14 +38,14 @@ public interface HandDetectorService { * * @param id 编号 */ - void deleteHandDetector(String id); + void deleteHandDetector(Long id); /** * 批量删除GAS手持探测器 * * @param ids 编号 */ - void deleteHandDetectorListByIds(List ids); + void deleteHandDetectorListByIds(List ids); /** * 获得GAS手持探测器 @@ -51,7 +53,7 @@ public interface HandDetectorService { * @param id 编号 * @return GAS手持探测器 */ - HandDetectorDO getHandDetector(String id); + HandDetectorDO getHandDetector(Long id); /** * 获得GAS手持探测器分页 @@ -61,4 +63,10 @@ public interface HandDetectorService { */ PageResult getHandDetectorPage(HandDetectorPageReqVO pageReqVO); + HandDetectorDO getBySn(String sn); + + Map getHandData(String tenantDeviceHashKey); + + void updateRedisData(Long tenantId, String topic, HandDataVo handVo); + } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/TdengineService.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/TdengineService.java new file mode 100644 index 0000000..bd9dc7e --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/TdengineService.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.hand.service; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.hand.vo.HandOriginalLog; +import cn.iocoder.yudao.module.hand.vo.HandTdenginePageVO; +import cn.iocoder.yudao.module.hand.vo.TdengineDataVo; + +import java.util.List; + +public interface TdengineService { + + void saveHandLogBatch(List batchList); + + + void saveDataLogBatch(List batchList); + + PageResult getHandDataLog(HandTdenginePageVO pageReqVO); + + PageResult getOriginalLogPage(HandTdenginePageVO pageReqVO); +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/AlarmRuleServiceImpl.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/AlarmRuleServiceImpl.java index e39afcb..1870d13 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/AlarmRuleServiceImpl.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/AlarmRuleServiceImpl.java @@ -1,17 +1,27 @@ package cn.iocoder.yudao.module.hand.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.security.core.LoginUser; +import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.module.hand.dal.AlarmRuleDO; import cn.iocoder.yudao.module.hand.mapper.AlarmRuleMapper; import cn.iocoder.yudao.module.hand.service.AlarmRuleService; +import cn.iocoder.yudao.module.hand.util.RedisKeyUtil; import cn.iocoder.yudao.module.hand.vo.AlarmRulePageReqVO; import cn.iocoder.yudao.module.hand.vo.AlarmRuleSaveReqVO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import jakarta.annotation.Resource; import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; import java.util.*; +import java.util.stream.Collectors; + import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; @@ -20,6 +30,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser; import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.ALARM_RULE_NOT_EXISTS; /** @@ -29,17 +40,21 @@ import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.ALARM_RULE_N */ @Service @Validated +@Slf4j public class AlarmRuleServiceImpl implements AlarmRuleService { @Resource private AlarmRuleMapper alarmRuleMapper; @Override - public String createAlarmRule(AlarmRuleSaveReqVO createReqVO) { + public Long createAlarmRule(AlarmRuleSaveReqVO createReqVO) { // 插入 AlarmRuleDO alarmRule = BeanUtils.toBean(createReqVO, AlarmRuleDO.class); alarmRuleMapper.insert(alarmRule); - + LoginUser loginUser = getLoginUser(); + if (loginUser != null && loginUser.getTenantId() != null){ + evictGasAlarmRuleCache(loginUser.getTenantId()); + } // 返回 return alarmRule.getId(); } @@ -51,37 +66,78 @@ public class AlarmRuleServiceImpl implements AlarmRuleService { // 更新 AlarmRuleDO updateObj = BeanUtils.toBean(updateReqVO, AlarmRuleDO.class); alarmRuleMapper.updateById(updateObj); + LoginUser loginUser = getLoginUser(); + if (loginUser != null && loginUser.getTenantId() != null){ + evictGasAlarmRuleCache(loginUser.getTenantId()); + } } @Override - public void deleteAlarmRule(String id) { + public void deleteAlarmRule(Long id) { // 校验存在 validateAlarmRuleExists(id); // 删除 alarmRuleMapper.deleteById(id); + LoginUser loginUser = getLoginUser(); + if (loginUser != null && loginUser.getTenantId() != null){ + evictGasAlarmRuleCache(loginUser.getTenantId()); + } } @Override - public void deleteAlarmRuleListByIds(List ids) { + public void deleteAlarmRuleListByIds(List ids) { // 删除 alarmRuleMapper.deleteByIds(ids); + LoginUser loginUser = getLoginUser(); + if (loginUser != null && loginUser.getTenantId() != null){ + evictGasAlarmRuleCache(loginUser.getTenantId()); } + } - private void validateAlarmRuleExists(String id) { + private void validateAlarmRuleExists(Long id) { if (alarmRuleMapper.selectById(id) == null) { throw exception(ALARM_RULE_NOT_EXISTS); } } @Override - public AlarmRuleDO getAlarmRule(String id) { + public AlarmRuleDO getAlarmRule(Long id) { return alarmRuleMapper.selectById(id); } @Override + @TenantIgnore + @Cacheable(cacheNames = RedisKeyUtil.ALARM_RULES_CACHE_NAME, + // 【关键修改】使用 #tenantId 来引用方法参数,确保缓存key与查询数据严格对应。 + key = "'gas_rules_map:' + #tenantId") + public Map> selectCacheListMap(Long tenantId) { + // --- 这段代码只会在缓存未命中时执行 --- + log.info("气体报警规则缓存未命中,租户ID: {},执行数据库查询和分组...", tenantId); + + QueryWrapper ruleDOQueryWrapper = new QueryWrapper<>(); + ruleDOQueryWrapper.lambda().eq(AlarmRuleDO::getTenantId, tenantId); + List allRules = alarmRuleMapper.selectList(ruleDOQueryWrapper); + + // 2. 按 GasTypeId 分组 + return allRules.stream() + .collect(Collectors.groupingBy(AlarmRuleDO::getGasTypeId)); + } + + @Override public PageResult getAlarmRulePage(AlarmRulePageReqVO pageReqVO) { return alarmRuleMapper.selectPage(pageReqVO); } + + /** + * 当规则发生变更时,调用此方法来清空缓存。 + */ + @CacheEvict(cacheNames = RedisKeyUtil.ALARM_RULES_CACHE_NAME, + // 【关键修改】使用 #tenantId 来引用方法参数,确保缓存key与查询数据严格对应。 + key = "'gas_rules_map:' + #tenantId") + @TenantIgnore + public void evictGasAlarmRuleCache(Long tenantId) { + log.info("成功清除气体报警规则缓存。"); + } } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/AlarmTypeServiceImpl.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/AlarmTypeServiceImpl.java index d98c541..d76ab7a 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/AlarmTypeServiceImpl.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/AlarmTypeServiceImpl.java @@ -35,7 +35,7 @@ public class AlarmTypeServiceImpl implements AlarmTypeService { private AlarmTypeMapper alarmTypeMapper; @Override - public String createAlarmType(AlarmTypeSaveReqVO createReqVO) { + public Long createAlarmType(AlarmTypeSaveReqVO createReqVO) { // 插入 AlarmTypeDO alarmType = BeanUtils.toBean(createReqVO, AlarmTypeDO.class); alarmTypeMapper.insert(alarmType); @@ -54,7 +54,7 @@ public class AlarmTypeServiceImpl implements AlarmTypeService { } @Override - public void deleteAlarmType(String id) { + public void deleteAlarmType(Long id) { // 校验存在 validateAlarmTypeExists(id); // 删除 @@ -62,20 +62,20 @@ public class AlarmTypeServiceImpl implements AlarmTypeService { } @Override - public void deleteAlarmTypeListByIds(List ids) { + public void deleteAlarmTypeListByIds(List ids) { // 删除 alarmTypeMapper.deleteByIds(ids); } - private void validateAlarmTypeExists(String id) { + private void validateAlarmTypeExists(Long id) { if (alarmTypeMapper.selectById(id) == null) { throw exception(ALARM_TYPE_NOT_EXISTS); } } @Override - public AlarmTypeDO getAlarmType(String id) { + public AlarmTypeDO getAlarmType(Long id) { return alarmTypeMapper.selectById(id); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/FactoryServiceImpl.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/FactoryServiceImpl.java new file mode 100644 index 0000000..7cce1c6 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/FactoryServiceImpl.java @@ -0,0 +1,88 @@ +package cn.iocoder.yudao.module.hand.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.module.hand.dal.FactoryDO; +import cn.iocoder.yudao.module.hand.mapper.FactoryMapper; +import cn.iocoder.yudao.module.hand.service.FactoryService; +import cn.iocoder.yudao.module.hand.vo.FactoryPageReqVO; +import cn.iocoder.yudao.module.hand.vo.FactorySaveReqVO; +import org.springframework.stereotype.Service; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; +import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.FACTORY_NOT_EXISTS; + +/** + * GAS工厂 Service 实现类 + * + * @author 超级管理员 + */ +@Service +@Validated +public class FactoryServiceImpl implements FactoryService { + + @Resource + private FactoryMapper factoryMapper; + + @Override + public Long createFactory(FactorySaveReqVO createReqVO) { + // 插入 + FactoryDO factory = BeanUtils.toBean(createReqVO, FactoryDO.class); + factoryMapper.insert(factory); + + // 返回 + return factory.getId(); + } + + @Override + public void updateFactory(FactorySaveReqVO updateReqVO) { + // 校验存在 + validateFactoryExists(updateReqVO.getId()); + // 更新 + FactoryDO updateObj = BeanUtils.toBean(updateReqVO, FactoryDO.class); + factoryMapper.updateById(updateObj); + } + + @Override + public void deleteFactory(Long id) { + // 校验存在 + validateFactoryExists(id); + // 删除 + factoryMapper.deleteById(id); + } + + @Override + public void deleteFactoryListByIds(List ids) { + // 删除 + factoryMapper.deleteByIds(ids); + } + + + private void validateFactoryExists(Long id) { + if (factoryMapper.selectById(id) == null) { + throw exception(FACTORY_NOT_EXISTS); + } + } + + @Override + public FactoryDO getFactory(Long id) { + return factoryMapper.selectById(id); + } + + @Override + public PageResult getFactoryPage(FactoryPageReqVO pageReqVO) { + return factoryMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/FenceAlarmServiceImpl.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/FenceAlarmServiceImpl.java index fc78624..6092a0f 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/FenceAlarmServiceImpl.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/FenceAlarmServiceImpl.java @@ -34,7 +34,7 @@ public class FenceAlarmServiceImpl implements FenceAlarmService { private FenceAlarmMapper fenceAlarmMapper; @Override - public String createFenceAlarm(FenceAlarmSaveReqVO createReqVO) { + public Long createFenceAlarm(FenceAlarmSaveReqVO createReqVO) { // 插入 FenceAlarmDO fenceAlarm = BeanUtils.toBean(createReqVO, FenceAlarmDO.class); fenceAlarmMapper.insert(fenceAlarm); @@ -53,7 +53,7 @@ public class FenceAlarmServiceImpl implements FenceAlarmService { } @Override - public void deleteFenceAlarm(String id) { + public void deleteFenceAlarm(Long id) { // 校验存在 validateFenceAlarmExists(id); // 删除 @@ -61,20 +61,20 @@ public class FenceAlarmServiceImpl implements FenceAlarmService { } @Override - public void deleteFenceAlarmListByIds(List ids) { + public void deleteFenceAlarmListByIds(List ids) { // 删除 fenceAlarmMapper.deleteByIds(ids); } - private void validateFenceAlarmExists(String id) { + private void validateFenceAlarmExists(Long id) { if (fenceAlarmMapper.selectById(id) == null) { throw exception(FENCE_ALARM_NOT_EXISTS); } } @Override - public FenceAlarmDO getFenceAlarm(String id) { + public FenceAlarmDO getFenceAlarm(Long id) { return fenceAlarmMapper.selectById(id); } @@ -83,4 +83,10 @@ public class FenceAlarmServiceImpl implements FenceAlarmService { return fenceAlarmMapper.selectPage(pageReqVO); } + @Override + public void update(FenceAlarmDO updateReqVO) { + + fenceAlarmMapper.updateById(updateReqVO); + } + } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/FenceServiceImpl.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/FenceServiceImpl.java index a2586d6..70d7115 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/FenceServiceImpl.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/FenceServiceImpl.java @@ -1,17 +1,28 @@ package cn.iocoder.yudao.module.hand.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; import cn.iocoder.yudao.module.hand.dal.FenceDO; +import cn.iocoder.yudao.module.hand.dal.HandDetectorDO; +import cn.iocoder.yudao.module.hand.enums.FenceStatusType; import cn.iocoder.yudao.module.hand.mapper.FenceMapper; +import cn.iocoder.yudao.module.hand.mapper.HandDetectorMapper; import cn.iocoder.yudao.module.hand.service.FenceService; +import cn.iocoder.yudao.module.hand.util.GeofenceUtils; +import cn.iocoder.yudao.module.hand.util.RedisUtil; import cn.iocoder.yudao.module.hand.vo.FencePageReqVO; import cn.iocoder.yudao.module.hand.vo.FenceSaveReqVO; +import cn.iocoder.yudao.module.hand.vo.Geofence; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import jakarta.annotation.Resource; import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; import java.util.*; +import java.util.stream.Collectors; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; @@ -21,6 +32,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; +import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.FENCE_EXISTS_HAND_DETECTOR; import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.FENCE_NOT_EXISTS; /** @@ -35,8 +47,13 @@ public class FenceServiceImpl implements FenceService { @Resource private FenceMapper fenceMapper; + @Resource + private HandDetectorMapper handDetectorMapper; + + @Resource + private RedisUtil redisUtil; @Override - public String createFence(FenceSaveReqVO createReqVO) { + public Long createFence(FenceSaveReqVO createReqVO) { // 插入 FenceDO fence = BeanUtils.toBean(createReqVO, FenceDO.class); fenceMapper.insert(fence); @@ -55,28 +72,36 @@ public class FenceServiceImpl implements FenceService { } @Override - public void deleteFence(String id) { + public void deleteFence(Long id) { // 校验存在 validateFenceExists(id); + + + QueryWrapper objectQueryWrapper = new QueryWrapper<>(); + objectQueryWrapper.eq("fence_id",id); + List list = handDetectorMapper.selectList(objectQueryWrapper); + if (CollectionUtils.isNotEmpty(list)){ + throw exception(FENCE_EXISTS_HAND_DETECTOR); + } // 删除 fenceMapper.deleteById(id); } @Override - public void deleteFenceListByIds(List ids) { + public void deleteFenceListByIds(List ids) { // 删除 fenceMapper.deleteByIds(ids); } - private void validateFenceExists(String id) { + private void validateFenceExists(Long id) { if (fenceMapper.selectById(id) == null) { throw exception(FENCE_NOT_EXISTS); } } @Override - public FenceDO getFence(String id) { + public FenceDO getFence(Long id) { return fenceMapper.selectById(id); } @@ -85,4 +110,26 @@ public class FenceServiceImpl implements FenceService { return fenceMapper.selectPage(pageReqVO); } + @Override + @TenantIgnore + public List getFenceList(List idList) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in("id",idList); + queryWrapper.eq("status", FenceStatusType.DISABLED.getType()); + List fenceDOS = fenceMapper.selectList(queryWrapper); + + List allGeofences = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(fenceDOS)){ + for (FenceDO fenceDO : fenceDOS) { + // 关键:调用 parseFences 方法,它会处理JSON解析和Geofence对象的创建 + // 它返回的是一个 List,因为一个 fenceDO 可能包含多个多边形 + List fencesFromCurrentDO = GeofenceUtils.parseFences(fenceDO.getFenceRange()); + // 将从当前 fenceDO 解析出的所有围栏,添加到总列表中 + allGeofences.addAll(fencesFromCurrentDO); + } + + } + return allGeofences; + } + } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/GasTypeServiceImpl.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/GasTypeServiceImpl.java index 5cb2e62..fbf4303 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/GasTypeServiceImpl.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/GasTypeServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.module.hand.dal.GasTypeDO; import cn.iocoder.yudao.module.hand.mapper.GasTypeMapper; import cn.iocoder.yudao.module.hand.service.GasTypeService; +import cn.iocoder.yudao.module.hand.util.RedisKeyUtil; import cn.iocoder.yudao.module.hand.vo.GasTypePageReqVO; import cn.iocoder.yudao.module.hand.vo.GasTypeSaveReqVO; import org.springframework.stereotype.Service; @@ -17,6 +18,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import javax.cache.annotation.CachePut; + import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; @@ -35,7 +38,7 @@ public class GasTypeServiceImpl implements GasTypeService { private GasTypeMapper typeMapper; @Override - public String createType(GasTypeSaveReqVO createReqVO) { + public Long createType(GasTypeSaveReqVO createReqVO) { // 插入 GasTypeDO type = BeanUtils.toBean(createReqVO, GasTypeDO.class); typeMapper.insert(type); @@ -54,7 +57,7 @@ public class GasTypeServiceImpl implements GasTypeService { } @Override - public void deleteType(String id) { + public void deleteType(Long id) { // 校验存在 validateTypeExists(id); // 删除 @@ -62,20 +65,20 @@ public class GasTypeServiceImpl implements GasTypeService { } @Override - public void deleteTypeListByIds(List ids) { + public void deleteTypeListByIds(List ids) { // 删除 typeMapper.deleteByIds(ids); } - private void validateTypeExists(String id) { + private void validateTypeExists(Long id) { if (typeMapper.selectById(id) == null) { throw exception(TYPE_NOT_EXISTS); } } @Override - public GasTypeDO getType(String id) { + public GasTypeDO getType(Long id) { return typeMapper.selectById(id); } diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/HandAlarmServiceImpl.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/HandAlarmServiceImpl.java index c1d8fb1..f99359d 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/HandAlarmServiceImpl.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/HandAlarmServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.hand.service.impl; -import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.module.hand.dal.HandAlarmDO; import cn.iocoder.yudao.module.hand.mapper.HandAlarmMapper; import cn.iocoder.yudao.module.hand.service.HandAlarmService; @@ -12,14 +11,13 @@ import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; import java.util.*; + import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.HAND_ALARM_NOT_EXISTS; /** @@ -35,7 +33,7 @@ public class HandAlarmServiceImpl implements HandAlarmService { private HandAlarmMapper handAlarmMapper; @Override - public String createHandAlarm(HandAlarmSaveReqVO createReqVO) { + public Long createHandAlarm(HandAlarmSaveReqVO createReqVO) { // 插入 HandAlarmDO handAlarm = BeanUtils.toBean(createReqVO, HandAlarmDO.class); handAlarmMapper.insert(handAlarm); @@ -54,7 +52,7 @@ public class HandAlarmServiceImpl implements HandAlarmService { } @Override - public void deleteHandAlarm(String id) { + public void deleteHandAlarm(Long id) { // 校验存在 validateHandAlarmExists(id); // 删除 @@ -62,20 +60,20 @@ public class HandAlarmServiceImpl implements HandAlarmService { } @Override - public void deleteHandAlarmListByIds(List ids) { + public void deleteHandAlarmListByIds(List ids) { // 删除 handAlarmMapper.deleteByIds(ids); - } + } - private void validateHandAlarmExists(String id) { + private void validateHandAlarmExists(Long id) { if (handAlarmMapper.selectById(id) == null) { throw exception(HAND_ALARM_NOT_EXISTS); } } @Override - public HandAlarmDO getHandAlarm(String id) { + public HandAlarmDO getHandAlarm(Long id) { return handAlarmMapper.selectById(id); } @@ -84,4 +82,10 @@ public class HandAlarmServiceImpl implements HandAlarmService { return handAlarmMapper.selectPage(pageReqVO); } + @Override + @Transactional(rollbackFor = Exception.class) + public int updateById(HandAlarmDO alarm) { + return handAlarmMapper.updateById(alarm); + } + } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/HandDetectorServiceImpl.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/HandDetectorServiceImpl.java index 7e4e171..0208acd 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/HandDetectorServiceImpl.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/HandDetectorServiceImpl.java @@ -1,22 +1,43 @@ package cn.iocoder.yudao.module.hand.service.impl; +import cn.iocoder.yudao.framework.common.exception.ServiceException; +import cn.iocoder.yudao.framework.security.core.LoginUser; +import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; import cn.iocoder.yudao.module.hand.dal.HandDetectorDO; import cn.iocoder.yudao.module.hand.mapper.HandDetectorMapper; import cn.iocoder.yudao.module.hand.service.HandDetectorService; +import cn.iocoder.yudao.module.hand.util.RedisKeyUtil; +import cn.iocoder.yudao.module.hand.util.RedisUtil; +import cn.iocoder.yudao.module.hand.vo.HandDataVo; import cn.iocoder.yudao.module.hand.vo.HandDetectorPageReqVO; import cn.iocoder.yudao.module.hand.vo.HandDetectorSaveReqVO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import jakarta.annotation.PostConstruct; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.cursor.Cursor; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.stereotype.Service; import jakarta.annotation.Resource; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; +import java.time.Duration; import java.util.*; + import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser; import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.HAND_DETECTOR_NOT_EXISTS; +import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.HAND_DETECTOR_SN_EXISTS; /** * GAS手持探测器 Service 实现类 @@ -25,53 +46,179 @@ import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.HAND_DETECTO */ @Service @Validated +@Slf4j public class HandDetectorServiceImpl implements HandDetectorService { @Resource private HandDetectorMapper handDetectorMapper; + @Resource + private SqlSessionFactory sqlSessionFactory; + @Resource + private RedisUtil redisUtil; + + + // 定义批量处理的大小,防止一次性加载过多数据到内存中 + private static final int BATCH_SIZE = 1000; + + @PostConstruct + @TenantIgnore + public void initDeviceTenantMappingCache() { + log.info("[缓存预热] 开始初始化 [设备SN -> 租户ID] 映射缓存 (流式查询模式)..."); + long totalCount = 0; + + try { + String redisKey = RedisKeyUtil.getDeviceTenantMappingKey(); + redisUtil.del(redisKey); + log.info("[缓存预热] 已清空旧的映射缓存,Key: {}", redisKey); + // 【核心改造】使用 try-with-resources 确保 SqlSession 和 Cursor 被自动关闭 + try (SqlSession sqlSession = sqlSessionFactory.openSession(); + // 【关键修复】从手动创建的 sqlSession 中获取 Mapper 实例,而不是使用注入的那个 + Cursor cursor = sqlSession.getMapper(HandDetectorMapper.class).selectCursor(new QueryWrapper<>())) { + + Map batchMap = new HashMap<>(BATCH_SIZE); + + // 像迭代器一样遍历 Cursor,每次只从数据库连接中取少量数据 + for (HandDetectorDO device : cursor) { + if (device.getSn() != null && device.getTenantId() != null) { + batchMap.put(device.getSn(), device.getTenantId().toString()); + } + totalCount++; + + // 达到批次大小,执行写入 + if (batchMap.size() >= BATCH_SIZE) { + redisUtil.hmset(redisKey, batchMap); + log.info("[缓存预热] 成功写入 {} 条映射数据到 Redis...", batchMap.size()); + batchMap.clear(); + } + } + // 处理最后一个不足 BATCH_SIZE 的批次 + if (!batchMap.isEmpty()) { + redisUtil.hmset(redisKey, batchMap); + log.info("[缓存预热] 成功写入最后 {} 条映射数据到 Redis...", batchMap.size()); + } + + } // try-with-resources 会在此处自动关闭 cursor 和 sqlSession + log.info("[缓存预热] [设备SN -> 租户ID] 映射缓存初始化完成,共处理 {} 条数据。", totalCount); + } catch (Exception e) { + log.error("[缓存预热] 初始化映射缓存时发生严重错误!", e); + } + } @Override - public String createHandDetector(HandDetectorSaveReqVO createReqVO) { + @Transactional(rollbackFor = Exception.class) + public Long createHandDetector(HandDetectorSaveReqVO createReqVO) { + LoginUser loginUser = getLoginUser(); + if (loginUser == null) { + return null; + } + + // 校验SN是否已存在(排除自身) + validateSnUnique(createReqVO.getSn(), null); // 插入 HandDetectorDO handDetector = BeanUtils.toBean(createReqVO, HandDetectorDO.class); handDetectorMapper.insert(handDetector); + redisUtil.hset( + RedisKeyUtil.getDeviceTenantMappingKey(), // 获取全局映射的Key + createReqVO.getSn(), // 设备的SN作为field + loginUser.getTenantId() // 租户ID作为value + ); // 返回 return handDetector.getId(); } + private void validateSnUnique(String sn, Long excludeId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(HandDetectorDO::getSn, sn); + + if (excludeId != null) { + wrapper.ne(HandDetectorDO::getId, excludeId); + } + + Long count = handDetectorMapper.selectCount(wrapper); + if (count > 0) { + throw exception(HAND_DETECTOR_SN_EXISTS); + } + } + @Override + @Transactional(rollbackFor = Exception.class) public void updateHandDetector(HandDetectorSaveReqVO updateReqVO) { + LoginUser loginUser = getLoginUser(); + if (loginUser == null) { + return; + } // 校验存在 - validateHandDetectorExists(updateReqVO.getId()); + HandDetectorDO handDetectorDO = validateHandDetectorExists(updateReqVO.getId()); + + + // 获取旧的SN + String oldSn = handDetectorDO.getSn(); + String newSn = updateReqVO.getSn(); + + // 如果SN有变化,需要校验唯一性并清理旧缓存 + boolean snChanged = !oldSn.equals(newSn); + if (snChanged) { + // 校验SN是否已存在(排除自身) + validateSnUnique(newSn, updateReqVO.getId()); + // 1. 从全局设备与租户的映射中删除旧的SN + redisUtil.hdel(RedisKeyUtil.getDeviceTenantMappingKey(), oldSn); + // 2. 从租户自己的设备信息缓存中删除旧的SN + String tenantDeviceKey = RedisKeyUtil.getTenantDeviceHashKey(loginUser.getTenantId()); + redisUtil.hdel(tenantDeviceKey, oldSn); + } // 更新 HandDetectorDO updateObj = BeanUtils.toBean(updateReqVO, HandDetectorDO.class); handDetectorMapper.updateById(updateObj); + + redisUtil.hset( + RedisKeyUtil.getDeviceTenantMappingKey(), // 获取全局映射的Key + updateReqVO.getSn(), // 设备的SN作为field + loginUser.getTenantId() // 租户ID作为value + ); + // 2. 更新租户自己的设备信息缓存 + String tenantDeviceKey = RedisKeyUtil.getTenantDeviceHashKey(loginUser.getTenantId()); + redisUtil.hset(tenantDeviceKey, updateReqVO.getSn(), updateObj); + } @Override - public void deleteHandDetector(String id) { + public void deleteHandDetector(Long id) { + LoginUser loginUser = getLoginUser(); + if (null == loginUser) { + return; + } // 校验存在 validateHandDetectorExists(id); // 删除 handDetectorMapper.deleteById(id); + String deviceSn = handDetectorMapper.selectOne(HandDetectorDO::getId, id).getSn(); + // 2. 从全局映射缓存中删除 + redisUtil.hdel(RedisKeyUtil.getDeviceTenantMappingKey(), deviceSn); + + // 3. 从租户自己的设备信息缓存中删除 + String tenantDeviceKey = RedisKeyUtil.getTenantDeviceHashKey(loginUser.getTenantId()); + redisUtil.hdel(tenantDeviceKey, deviceSn); } @Override - public void deleteHandDetectorListByIds(List ids) { + public void deleteHandDetectorListByIds(List ids) { // 删除 handDetectorMapper.deleteByIds(ids); - } + } + + private HandDetectorDO validateHandDetectorExists(Long id) { + HandDetectorDO handDetectorDO = handDetectorMapper.selectById(id); - private void validateHandDetectorExists(String id) { - if (handDetectorMapper.selectById(id) == null) { + if (handDetectorDO == null) { throw exception(HAND_DETECTOR_NOT_EXISTS); } + return handDetectorDO; } @Override - public HandDetectorDO getHandDetector(String id) { + public HandDetectorDO getHandDetector(Long id) { return handDetectorMapper.selectById(id); } @@ -80,4 +227,25 @@ public class HandDetectorServiceImpl implements HandDetectorService { return handDetectorMapper.selectPage(pageReqVO); } + @Override + @TenantIgnore + public HandDetectorDO getBySn(String sn) { + + return handDetectorMapper.selectOne(HandDetectorDO::getSn, sn); + } + + @Override + @TenantIgnore + public Map getHandData(String tenantDeviceHashKey) { + + return redisUtil.hmget(tenantDeviceHashKey); + } + + @Override + @TenantIgnore + public void updateRedisData(Long tenantId, String topic, HandDataVo handVo) { + redisUtil.hset(RedisKeyUtil.getTenantDeviceHashKey(tenantId), topic, handVo); + + } + } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/TdengineServiceImpl.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/TdengineServiceImpl.java new file mode 100644 index 0000000..aeec4f0 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/service/impl/TdengineServiceImpl.java @@ -0,0 +1,100 @@ +package cn.iocoder.yudao.module.hand.service.impl; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.hand.mapper.TdengineMapper; +import cn.iocoder.yudao.module.hand.service.TdengineService; +import cn.iocoder.yudao.module.hand.vo.HandOriginalLog; +import cn.iocoder.yudao.module.hand.vo.HandTdenginePageVO; +import cn.iocoder.yudao.module.hand.vo.TdengineDataVo; +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import jakarta.annotation.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Service +@Validated +@DS("tdengine") +public class TdengineServiceImpl implements TdengineService { + + private static final Logger log = LoggerFactory.getLogger(TdengineServiceImpl.class); + @Resource + private TdengineMapper tdengineMapper; + + @Override + public void saveHandLogBatch(List batchList) { + + if (batchList.isEmpty()) { + return; + } + // 1. 按设备SN分组 + Map> groupedBySn = batchList.stream() + .collect(Collectors.groupingBy(HandOriginalLog::getSn)); + + // 遍历Map,每个Entry对应一个子表 + for (Map.Entry> entry : groupedBySn.entrySet()) { + String sn = entry.getKey(); + List logs = entry.getValue(); + + Long tenantId = logs.get(0).getTenantId(); + tdengineMapper.insertHandLogBatch(sn, tenantId, logs); + + } + } + + @Override + public void saveDataLogBatch(List batchList) { + if (batchList.isEmpty()) { + return; + } + // 1. 按设备SN分组 + Map> groupedBySn = batchList.stream() + .collect(Collectors.groupingBy(TdengineDataVo::getSn)); + + // 遍历Map,每个Entry对应一个子表 + for (Map.Entry> entry : groupedBySn.entrySet()) { + String sn = entry.getKey(); + List logs = entry.getValue(); + Long tenantId = logs.get(0).getTenantId(); + + tdengineMapper.saveDataLogBatch(sn, tenantId, logs); + + } + } + + @Override + public PageResult getHandDataLog(HandTdenginePageVO pageReqVO) { + IPage page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()); + + IPage resultPage = tdengineMapper.selectPage(page, pageReqVO); + + List doList = resultPage.getRecords(); + + if (doList == null || doList.isEmpty()) { + return PageResult.empty(resultPage.getTotal()); + } + + return new PageResult<>(doList, resultPage.getTotal()); + } + + @Override + public PageResult getOriginalLogPage(HandTdenginePageVO pageReqVO) { + IPage page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()); + + IPage resultPage = tdengineMapper.selectOriginalPage(page, pageReqVO); + + List doList = resultPage.getRecords(); + if (doList == null || doList.isEmpty()) { + return PageResult.empty(resultPage.getTotal()); + } + + return new PageResult<>(doList, resultPage.getTotal()); + } +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/BatteryConverterUtils.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/BatteryConverterUtils.java new file mode 100644 index 0000000..5f52d94 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/BatteryConverterUtils.java @@ -0,0 +1,76 @@ +package cn.iocoder.yudao.module.hand.util; + +public class BatteryConverterUtils { + + // 定义电压-电量映射点 (电压单位: 毫伏 mV) + // 这些值是基于常见的单节锂电池放电曲线估算的 + // [电压, 电量百分比] + private static final int[][] VOLTAGE_MAP = { + {4200, 100}, // 充满电 + {4150, 95}, + {4100, 90}, + {4050, 85}, + {4000, 80}, + {3950, 75}, + {3900, 70}, + {3850, 65}, + {3800, 60}, + {3750, 50}, + {3700, 40}, + {3650, 30}, + {3600, 20}, + {3500, 10}, + {3400, 5}, + {3300, 0} // 电量耗尽 + }; + + /** + * 将电池电压 (mV) 转换为电量百分比 (%) + * + * @param millivolts 当前电池电压,单位为毫伏 + * @return 估算的电量百分比 (0-100) + */ + public static int getBatteryPercentage(int millivolts) { + // 处理边界情况 + if (millivolts >= VOLTAGE_MAP[0][0]) { + return 100; + } + if (millivolts <= VOLTAGE_MAP[VOLTAGE_MAP.length - 1][0]) { + return 0; + } + + // 查找电压所在的区间 + for (int i = 0; i < VOLTAGE_MAP.length - 1; i++) { + int upperVoltage = VOLTAGE_MAP[i][0]; + int upperPercentage = VOLTAGE_MAP[i][1]; + int lowerVoltage = VOLTAGE_MAP[i + 1][0]; + int lowerPercentage = VOLTAGE_MAP[i + 1][1]; + + if (millivolts <= upperVoltage && millivolts > lowerVoltage) { + // 在找到的区间内进行线性插值计算 + // 公式: y = y1 + (x - x1) * (y2 - y1) / (x2 - x1) + // 这里: x=millivolts, x1=lowerVoltage, x2=upperVoltage + // y=percentage, y1=lowerPercentage, y2=upperPercentage + double percentage = lowerPercentage + + ((double)(millivolts - lowerVoltage) * (upperPercentage - lowerPercentage)) / + (double)(upperVoltage - lowerVoltage); + return (int) Math.round(percentage); + } + } + + // 如果出现意外情况,返回0 + return 0; + } + + public static void main(String[] args) { + int batteryVoltage = 4126; // 输入您设备的值 + int percentage = getBatteryPercentage(batteryVoltage); + System.out.println("电压 " + batteryVoltage + "mV 约等于 " + percentage + "% 的电量。"); + + // 其他测试用例 + System.out.println("电压 4200mV 约等于 " + getBatteryPercentage(4200) + "% 的电量。"); + System.out.println("电压 3750mV 约等于 " + getBatteryPercentage(3750) + "% 的电量。"); + System.out.println("电压 3300mV 约等于 " + getBatteryPercentage(3300) + "% 的电量。"); + System.out.println("电压 3980mV 约等于 " + getBatteryPercentage(3980) + "% 的电量。"); + } +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/CoordinateTransferUtils.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/CoordinateTransferUtils.java new file mode 100644 index 0000000..fb7bc80 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/CoordinateTransferUtils.java @@ -0,0 +1,188 @@ +package cn.iocoder.yudao.module.hand.util; + + +import java.math.BigDecimal; +import java.math.MathContext; +import java.math.RoundingMode; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.function.Consumer; +import java.util.function.Supplier; + +public class CoordinateTransferUtils { + /** + * 国内坐标边界 + */ + private static final double MIN_LON = 72.004D; + private static final double MAX_LON = 137.8347D; + private static final double MIN_LAT = 0.8293D; + private static final double MAX_LAT = 55.8271D; + + /** + * PI 圆周率 + */ + private static final double PI = 3.14159265358979324D; + + /** + * A WGS 长轴半径 + */ + private static final double A = 6378245.0D; + + /** + * EE WGS 偏心率的平方 + */ + private static final double EE = 0.00669342162296594323D; + + + + /** + * WGS84转换GCJ02核心方法 + * + * @param fromLon 转换前的经度 + * @param fromLat 转换前的纬度 + * @return 转换后的经纬度map对象 + */ + public static Map wgs84ToGcj02(double fromLon, double fromLat) { + HashMap transformRes = new HashMap<>(2); + // 国外坐标不用进行加密 + if (outOfChina(fromLon, fromLat)) { + transformRes.put("lon", fromLon); + transformRes.put("lat", fromLat); + return transformRes; + } + // 计算转换后的经纬度坐标 + double dLat = transformLat(fromLon - 105.0, fromLat - 35.0); + double dLon = transformLon(fromLon - 105.0, fromLat - 35.0); + double radLat = fromLat / 180.0 * PI; + double magic = Math.sin(radLat); + magic = 1 - EE * magic * magic; + double sqrtMagic = Math.sqrt(magic); + dLat = (dLat * 180.0) / ((A * (1 - EE)) / (magic * sqrtMagic) * PI); + dLon = (dLon * 180.0) / (A / sqrtMagic * Math.cos(radLat) * PI); + double mgLat = fromLat + dLat; + double mgLon = fromLon + dLon; + transformRes.put("lon", new BigDecimal(mgLon + "", new MathContext(9, RoundingMode.HALF_UP)).doubleValue()); + transformRes.put("lat", new BigDecimal(mgLat + "", new MathContext(9, RoundingMode.HALF_UP)).doubleValue()); + + return transformRes; + } + + /** + * GCJ02转换WGS84 + * + * @param lon 转换前的经度 + * @param lat 转换后的纬度 + * @return 转换后的经纬度map对象 + */ + public static Map gcj02ToWgs84(double lon, double lat) { + Map transformRes = new HashMap<>(2); + double longitude = lon * 2 - wgs84ToGcj02(lon, lat).get("lon"); + double latitude = lat * 2 - wgs84ToGcj02(lon, lat).get("lat"); + transformRes.put("lon", longitude); + transformRes.put("lat", latitude); + return transformRes; + } + + /** + * GCJ02转换BD09 + * + * @param gcjLat GCL纬度坐标 + * @param gcjLng GCL经度坐标 + */ + public static Map Gcj02ToBd09(double gcjLat, double gcjLng) { + Map transformRes = new HashMap<>(2); + double z = Math.sqrt(gcjLng * gcjLng + gcjLat * gcjLat) + 0.00002 * Math.sin(gcjLat * PI); + double theta = Math.atan2(gcjLat, gcjLng) + 0.000003 * Math.cos(gcjLng * PI); + transformRes.put("lon", z * Math.cos(theta) + 0.0065); + transformRes.put("lat", z * Math.sin(theta) + 0.006); + return transformRes; + } + + /** + * BD09转换GCJ02 + * + * @param bdLat 百度纬度坐标 + * @param bdLng 百度经度坐标 + */ + public static Map bd09ToGcj02(double bdLat, double bdLng) { + Map transformRes = new HashMap<>(2); + double x = bdLng - 0.0065, y = bdLat - 0.006; + double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * PI); + double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * PI); + + transformRes.put("lon", z * Math.cos(theta)); + transformRes.put("lat", z * Math.sin(theta)); + return transformRes; + } + + /** + * WGS84转换GCJ02优化(处理转换前经纬度坐标为null问题) + * + * @param fromLon 转换前的经度 + * @param fromLat 转换前的纬度 + * @param toLon 转换后的经度 + * @param toLat 转换后的纬度 + */ + private static void wgs84ToGcj02(Supplier fromLon, Supplier fromLat, Consumer toLon, Consumer toLat) { + wgs84ToGcj02(Optional.ofNullable(fromLon.get()).orElse(BigDecimal.ZERO), Optional.ofNullable(fromLat.get()).orElse(BigDecimal.ZERO), toLon, toLat); + } + + /** + * WGS84转换GCJ02优化(处理转换后经纬度坐标) + * + * @param fromLon 转换前的经度 + * @param fromLat 转换前的纬度 + * @param toLon 转换后的经度 + * @param toLat 转换后的纬度 + */ + private static void wgs84ToGcj02(BigDecimal fromLon, BigDecimal fromLat, Consumer toLon, Consumer toLat) { + final Map transformRes = wgs84ToGcj02(fromLon.doubleValue(), fromLat.doubleValue()); + toLon.accept(new BigDecimal(transformRes.get("lon") + "")); + toLat.accept(new BigDecimal(transformRes.get("lat") + "")); + } + + /** + * 坐标是否在国外 + * + * @param lon 经度 + * @param lat 纬度 + * @return true 国外坐标 false 国内坐标 + */ + private static boolean outOfChina(double lon, double lat) { + if (lon < MIN_LON || lon > MAX_LON) { + return true; + } + return lat < MIN_LAT || lat > MAX_LAT; + } + + /** + * 转换经度坐标 + * + * @param x 偏移后的经度 + * @param y 偏移后的纬度 + * @return double 转换经度坐标 + */ + private static double transformLat(double x, double y) { + double transform = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x)); + transform += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0; + transform += (20.0 * Math.sin(y * PI) + 40.0 * Math.sin(y / 3.0 * PI)) * 2.0 / 3.0; + transform += (160.0 * Math.sin(y / 12.0 * PI) + 320 * Math.sin(y * PI / 30.0)) * 2.0 / 3.0; + return transform; + } + /** + * 转换纬度坐标 + * + * @param x 偏移后的经度 + * @param y 偏移后的纬度 + * @return double 转换纬度坐标 + */ + private static double transformLon(double x, double y) { + double transform = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x)); + transform += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0; + transform += (20.0 * Math.sin(x * PI) + 40.0 * Math.sin(x / 3.0 * PI)) * 2.0 / 3.0; + transform += (150.0 * Math.sin(x / 12.0 * PI) + 300.0 * Math.sin(x / 30.0 * PI)) * 2.0 / 3.0; + return transform; + } + +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/GeofenceUtils.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/GeofenceUtils.java new file mode 100644 index 0000000..6c9bf71 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/GeofenceUtils.java @@ -0,0 +1,284 @@ +package cn.iocoder.yudao.module.hand.util; + +import cn.iocoder.yudao.module.hand.enums.FenceType; +import cn.iocoder.yudao.module.hand.vo.FencePointVo; +import cn.iocoder.yudao.module.hand.vo.Geofence; +import cn.iocoder.yudao.module.hand.vo.HandDataVo; +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; +import lombok.extern.slf4j.Slf4j; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * 高性能地理围栏计算工具类 (Optimized Geofence Calculation Utility) + * + *

核心优化:

+ *
    + *
  1. 引入 Geofence 对象: 封装了多边形顶点及其预计算的“包围盒”(Bounding Box)。
  2. + *
  3. 包围盒快速排斥: 在进行昂贵的精确计算前,先进行廉价的矩形范围判断,能过滤掉绝大多数不相关的围栏。
  4. + *
  5. 距离计算剪枝 (Pruning): 在计算最短距离时,利用点到包围盒的距离,提前跳过那些不可能存在最短距离的围栏。
  6. + *
+ * + *

使用流程:

+ *
{@code
+ *   // 1. 从JSON或其他数据源创建Geofence列表(这个过程会自动计算包围盒)
+ *   List geofences = GeofenceUtils.parseFences(fenceDO.getFenceRange());
+ *
+ *   // 2. 使用优化后的方法进行高效计算
+ *   boolean isInside = GeofenceUtils.isInsideAnyFence(longitude, latitude, geofences);
+ *   double distance = GeofenceUtils.calculateDistanceToFences(longitude, latitude, geofences);
+ * }
+ */ +@Slf4j +public final class GeofenceUtils { + + private static final double METERS_PER_DEGREE_LATITUDE = 111132.954; + private static final Gson GSON_INSTANCE = new Gson(); + // 私有构造函数,防止实例化工具类 + private GeofenceUtils() { + } + + /** + * 从JSON字符串解析并创建Geofence对象列表。 + * 这是推荐的初始化围栏数据的方式。 + * + * @param fenceRangeJson 符合`double[][][]`格式的JSON字符串 + * @return Geofence对象列表,如果解析失败或无有效多边形则返回空列表 + */ + public static List parseFences(String fenceRangeJson) { + if (fenceRangeJson == null || fenceRangeJson.trim().isEmpty()) { + return Collections.emptyList(); + } + try { + List geofences = new ArrayList<>(); + double[][][] coordinates = GSON_INSTANCE.fromJson(fenceRangeJson, double[][][].class); + if (coordinates == null) return Collections.emptyList(); + + for (double[][] polygonCoordinates : coordinates) { + List polygon = new ArrayList<>(); + for (double[] coordinate : polygonCoordinates) { + polygon.add(new FencePointVo(coordinate[0], coordinate[1])); + } + // 确保多边形有效才创建Geofence对象 + if (polygon.size() >= 3) { + geofences.add(new Geofence(polygon)); + } + } + return geofences; + } catch (JsonSyntaxException e) { + // 在实际项目中,这里应该记录日志 + log.error("解析围栏JSON失败{} ", e.getMessage()); + return Collections.emptyList(); + } + } + + + /** + * 检查点是否在任何一个电子围栏内部(高性能版)。 + * + * @param x 点的经度 + * @param y 点的纬度 + * @param geofences Geofence对象列表 + * @return 如果点在任何一个围栏内,返回 true + */ + public static boolean isInsideAnyFence(double x, double y, List geofences) { + if (geofences == null || geofences.isEmpty()) { + return false; + } + for (Geofence fence : geofences) { + // 第一步:快速包围盒排斥。如果点不在包围盒内,则绝不可能在多边形内。 + if (fence.isPointInBoundingBox(x, y)) { + // 第二步:通过包围盒测试后,再进行精确的多边形判断。 + if (isPointInsidePolygon(x, y, fence.getVertices())) { + return true; + } + } + } + return false; + } + + /** + * 计算点到一组围栏边界的最短距离(高性能版)。 + * + * @param x 点的经度 + * @param y 点的纬度 + * @param geofences Geofence对象列表 + * @return 点到所有围栏边界的最短距离(米) + */ + public static double calculateDistanceToFences(double x, double y, List geofences) { + if (geofences == null || geofences.isEmpty()) { + return Double.POSITIVE_INFINITY; + } + // 预先计算一次转换因子 + double metersPerDegreeLongitude = METERS_PER_DEGREE_LATITUDE * Math.cos(Math.toRadians(y)); + double minDistance = Double.MAX_VALUE; + + // 优化:先检查是否在内部,如果在则直接返回0 + if (isInsideAnyFence(x, y, geofences)) { + return 0.0; + } + + for (Geofence fence : geofences) { + // *** 核心优化:剪枝 (Pruning) *** + // 计算点到该围栏包围盒的距离。 + double distToBox = pointToBoundingBoxDistanceInMeters(x, y, fence, metersPerDegreeLongitude); + // 如果点到包围盒的距离已经比当前找到的最小距离还要大, + // 那么这个围栏内的任何一条边都不可能提供更短的距离,直接跳过。 + if (distToBox >= minDistance) { + continue; + } + + // 通过剪枝测试后,再对这个围栏的每条边进行精确计算 + List polygon = fence.getVertices(); + for (int i = 0, j = polygon.size() - 1; i < polygon.size(); j = i++) { + FencePointVo p1 = polygon.get(i); + FencePointVo p2 = polygon.get(j); + double distance = pointToLineSegmentDistanceInMeters(x, y, p1, p2, metersPerDegreeLongitude); + minDistance = Math.min(minDistance, distance); + } + } + return minDistance; + } + + /** + * 核心判断逻辑:点是否在单个多边形内部(射线法)。 + */ + private static boolean isPointInsidePolygon(double x, double y, List polygon) { + if (isPointOnPolygonBoundary(x, y, polygon)) { + return true; + } + int intersectCount = 0; + for (int i = 0, j = polygon.size() - 1; i < polygon.size(); j = i++) { + FencePointVo p1 = polygon.get(i); + FencePointVo p2 = polygon.get(j); + if ((p1.y > y) != (p2.y > y)) { + double xIntersection = (p2.x - p1.x) * (y - p1.y) / (p2.y - p1.y) + p1.x; + if (x < xIntersection) { + intersectCount++; + } + } + } + return (intersectCount % 2) == 1; + } + + /** + * 判断点是否在多边形的边界上。 + */ + private static boolean isPointOnPolygonBoundary(double x, double y, List polygon) { + for (int i = 0, j = polygon.size() - 1; i < polygon.size(); j = i++) { + FencePointVo p1 = polygon.get(i); + FencePointVo p2 = polygon.get(j); + double crossProduct = (y - p1.y) * (p2.x - p1.x) - (x - p1.x) * (p2.y - p1.y); + if (Math.abs(crossProduct) < 1E-9) { // 容忍浮点误差 + if (Math.min(p1.x, p2.x) <= x && x <= Math.max(p1.x, p2.x) && + Math.min(p1.y, p2.y) <= y && y <= Math.max(p1.y, p2.y)) { + return true; + } + } + } + return false; + } + + /** + * 计算点到线段的最短距离(米)。 + */ + private static double pointToLineSegmentDistanceInMeters(double px, double py, FencePointVo p1, FencePointVo p2, double metersPerDegreeLongitude) { + double p2_m_x = (p2.x - p1.x) * metersPerDegreeLongitude; + double p2_m_y = (p2.y - p1.y) * METERS_PER_DEGREE_LATITUDE; + double p_m_x = (px - p1.x) * metersPerDegreeLongitude; + double p_m_y = (py - p1.y) * METERS_PER_DEGREE_LATITUDE; + double lineLenSq = p2_m_x * p2_m_x + p2_m_y * p2_m_y; + if (lineLenSq == 0) { + return Math.sqrt(p_m_x * p_m_x + p_m_y * p_m_y); + } + double t = Math.max(0, Math.min(1, ((p_m_x * p2_m_x) + (p_m_y * p_m_y)) / lineLenSq)); + double nearestX = t * p2_m_x; + double nearestY = t * p2_m_y; + double dx = p_m_x - nearestX; + double dy = p_m_y - nearestY; + return Math.sqrt(dx * dx + dy * dy); + } + + /** + * 计算点到包围盒的最短距离(米),用于剪枝。 + */ + private static double pointToBoundingBoxDistanceInMeters(double px, double py, Geofence fence, double metersPerDegreeLongitude) { + double dx = 0.0, dy = 0.0; + if (px < fence.getMaxX()) dx = fence.getMaxX() - px; + else if (px > fence.getMaxX()) dx = px - fence.getMaxX(); + if (py < fence.getMinY()) dy = fence.getMinY() - py; + else if (py > fence.getMinY()) dy = py - fence.getMinY(); + + // 将经纬度差转换为米 + double dx_meters = dx * metersPerDegreeLongitude; + double dy_meters = dy * METERS_PER_DEGREE_LATITUDE; + + return Math.sqrt(dx_meters * dx_meters + dy_meters * dy_meters); + } + + /** + * 计算一个点到一组围栏最近边界的“物理”距离(单位:米)。 + * + *

与 calculateDistanceToFences 的关键区别:

+ *

此方法 总是 会计算并返回点到最近边界的实际最短距离, + * 无论这个点是在围栏的内部还是外部。

+ * + *

例如,如果点在围栏内部,它会返回一个大于0的值,表示该点距离“逃出”围栏的最近距离。

+ * + * @param x 点的经度 + * @param y 点的纬度 + * @param geofences Geofence对象列表 + * @return 点到所有围栏边界的物理最短距离(米)。 + */ + public static double calculateDistanceToNearestBoundary(double x, double y, List geofences) { + if (geofences == null || geofences.isEmpty()) { + return Double.POSITIVE_INFINITY; + } + + double minDistance = Double.MAX_VALUE; + // 预先计算一次转换因子 + double metersPerDegreeLongitude = METERS_PER_DEGREE_LATITUDE * Math.cos(Math.toRadians(y)); + + for (Geofence fence : geofences) { + // 剪枝优化对于外部点仍然有效,对于内部点虽然效果减弱,但无害且在多围栏场景下依然有用 + double distToBox = pointToBoundingBoxDistanceInMeters(x, y, fence, metersPerDegreeLongitude); + if (distToBox >= minDistance) { + continue; + } + + // 核心逻辑:直接遍历所有边并计算距离 + List polygon = fence.getVertices(); + for (int i = 0, j = polygon.size() - 1; i < polygon.size(); j = i++) { + FencePointVo p1 = polygon.get(i); + FencePointVo p2 = polygon.get(j); + double distance = pointToLineSegmentDistanceInMeters(x, y, p1, p2, metersPerDegreeLongitude); + minDistance = Math.min(minDistance, distance); + } + } + return minDistance; + } + + /** + * 计算违规距离。 + * + * @param handVo 手部数据对象 + * @param fenceType 围栏类型 + * @param fenceList 围栏列表 + * @return 违规距离(米) + */ + public static double fenceDistance(HandDataVo handVo, FenceType fenceType, List fenceList) { + if (fenceType == FenceType.INSIDE) { + // 规则是“必须在内”,违规意味着“在外面”,所以计算点到围栏的外部距离。 + // 此方法专为外部点设计。calculateDistanceToNearestBoundary + return GeofenceUtils.calculateDistanceToNearestBoundary(handVo.getLongitude(), handVo.getLatitude(), fenceList); + } else { // 规则是OUTSIDE + // 违规意味着“在里面”,所以计算点到边界的内部深度。 + // 此方法能处理内部点。 + + return GeofenceUtils.calculateDistanceToFences(handVo.getLongitude(), handVo.getLatitude(), fenceList); + } + } +} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/RedisKeyUtil.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/RedisKeyUtil.java new file mode 100644 index 0000000..57a61f3 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/RedisKeyUtil.java @@ -0,0 +1,56 @@ +package cn.iocoder.yudao.module.hand.util; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.*; +import org.springframework.data.redis.core.script.DefaultRedisScript; +import org.springframework.data.redis.core.script.RedisScript; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.util.*; +import java.util.concurrent.TimeUnit; + +/** + * redis 工具类 + * + * @Author Scott + */ +@Data +public class RedisKeyUtil { + + public static final String REDIS_KEY_PREFIX = "hand_detectorKey"; + + public static final String ALARM_RULES_CACHE_NAME = "alarm_rulesKey"; + + public static final String DEVICE_TENANT_MAPPING_KEY = "device:tenant:mapping"; + + // 基础前缀 + public static final String DEVICE_INFO_PREFIX = "device:info"; + + public static final String LOCK_PREFIX = "lock:device"; + + /** + * 获取特定租户下的设备信息 Hash Key + * 结构示例: device:info:{tenantId} -> field为sn + */ + public static String getTenantDeviceHashKey(Long tenantId) { + return DEVICE_INFO_PREFIX + ":" + tenantId; + } + + /** + * 获取处理锁 Key (加入租户维度更安全) + * 结构示例: lock:device:{tenantId}:{sn} + */ + public static String getDeviceProcessLockKey(Long tenantId, String sn) { + return LOCK_PREFIX + ":" + tenantId + ":" + sn; + } + + public static String getDeviceTenantMappingKey() { + return DEVICE_TENANT_MAPPING_KEY; + + } +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/RedisUtil.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/RedisUtil.java new file mode 100644 index 0000000..036f833 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/util/RedisUtil.java @@ -0,0 +1,742 @@ +package cn.iocoder.yudao.module.hand.util; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.*; +import org.springframework.data.redis.core.script.DefaultRedisScript; +import org.springframework.data.redis.core.script.RedisScript; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.util.*; +import java.util.concurrent.TimeUnit; + +/** + * redis 工具类 + * @Author Scott + * + */ +@Component +@Slf4j +public class RedisUtil { + + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private StringRedisTemplate stringRedisTemplate; + + /** + * 指定缓存失效时间 + * + * @param key 键 + * @param time 时间(秒) + * @return + */ + public boolean expire(String key, long time) { + try { + if (time > 0) { + redisTemplate.expire(key, time, TimeUnit.SECONDS); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 根据key 获取过期时间 + * + * @param key 键 不能为null + * @return 时间(秒) 返回0代表为永久有效 + */ + public long getExpire(String key) { + return redisTemplate.getExpire(key, TimeUnit.SECONDS); + } + + /** + * 判断key是否存在 + * + * @param key 键 + * @return true 存在 false不存在 + */ + public boolean hasKey(String key) { + try { + return redisTemplate.hasKey(key); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 删除缓存 + * + * @param key 可以传一个值 或多个 + */ + @SuppressWarnings("unchecked") + public void del(String... key) { + if (key != null && key.length > 0) { + if (key.length == 1) { + redisTemplate.delete(key[0]); + } else { + redisTemplate.delete((Collection) CollectionUtils.arrayToList(key)); + } + } + } + + // ============================String============================= + /** + * 普通缓存获取 + * + * @param key 键 + * @return 值 + */ + public Object get(String key) { + return key == null ? null : redisTemplate.opsForValue().get(key); + } + + /** + * 普通缓存放入 + * + * @param key 键 + * @param value 值 + * @return true成功 false失败 + */ + public boolean set(String key, Object value) { + try { + redisTemplate.opsForValue().set(key, value); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + + } + + /** + * 普通缓存放入并设置时间 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 + * @return true成功 false 失败 + */ + public boolean set(String key, Object value, long time) { + try { + if (time > 0) { + redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); + } else { + set(key, value); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 递增 + * + * @param key 键 + * @param delta 要增加几(大于0) + * @return + */ + public long incr(String key, long delta) { + if (delta < 0) { + throw new RuntimeException("递增因子必须大于0"); + } + return redisTemplate.opsForValue().increment(key, delta); + } + + /** + * 递减 + * + * @param key 键 + * @param delta 要减少几(小于0) + * @return + */ + public long decr(String key, long delta) { + if (delta < 0) { + throw new RuntimeException("递减因子必须大于0"); + } + return redisTemplate.opsForValue().increment(key, -delta); + } + + // ================================Map================================= + /** + * HashGet + * + * @param key 键 不能为null + * @param item 项 不能为null + * @return 值 + */ + public Object hget(String key, String item) { + return redisTemplate.opsForHash().get(key, item); + } + + /** + * 获取hashKey对应的所有键值 + * + * @param key 键 + * @return 对应的多个键值 + */ + public Map hmget(String key) { + return redisTemplate.opsForHash().entries(key); + } + /** + * 获取hashKey对应的所有键值 + * + * @param key 键 + * @return 对应的多个键值 + */ + public Object hmget(String key,String item) { + Map entries = redisTemplate.opsForHash().entries(key); + return entries.get(item); + } + + /** + * HashSet + * + * @param key 键 + * @param map 对应多个键值 + * @return true 成功 false 失败 + */ + public boolean hmset(String key, Map map) { + try { + redisTemplate.opsForHash().putAll(key, map); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * HashSet 并设置时间 + * + * @param key 键 + * @param map 对应多个键值 + * @param time 时间(秒) + * @return true成功 false失败 + */ + public boolean hmset(String key, Map map, long time) { + try { + redisTemplate.opsForHash().putAll(key, map); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 向一张hash表中放入数据,如果不存在将创建 + * + * @param key 键 + * @param item 项 + * @param value 值 + * @return true 成功 false失败 + */ + public boolean hset(String key, String item, Object value) { + try { + redisTemplate.opsForHash().put(key, item, value); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 向一张hash表中放入数据,如果不存在将创建 + * + * @param key 键 + * @param item 项 + * @param value 值 + * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 + * @return true 成功 false失败 + */ + public boolean hset(String key, String item, Object value, long time) { + try { + redisTemplate.opsForHash().put(key, item, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 删除hash表中的值 + * + * @param key 键 不能为null + * @param item 项 可以使多个 不能为null + */ + public void hdel(String key, Object... item) { + redisTemplate.opsForHash().delete(key, item); + } + + /** + * 判断hash表中是否有该项的值 + * + * @param key 键 不能为null + * @param item 项 不能为null + * @return true 存在 false不存在 + */ + public boolean hHasKey(String key, String item) { + return redisTemplate.opsForHash().hasKey(key, item); + } + + /** + * hash递增 如果不存在,就会创建一个 并把新增后的值返回 + * + * @param key 键 + * @param item 项 + * @param by 要增加几(大于0) + * @return + */ + public double hincr(String key, String item, double by) { + return redisTemplate.opsForHash().increment(key, item, by); + } + + /** + * hash递减 + * + * @param key 键 + * @param item 项 + * @param by 要减少记(小于0) + * @return + */ + public double hdecr(String key, String item, double by) { + return redisTemplate.opsForHash().increment(key, item, -by); + } + + // ============================set============================= + /** + * 根据key获取Set中的所有值 + * + * @param key 键 + * @return + */ + public Set sGet(String key) { + try { + return redisTemplate.opsForSet().members(key); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 根据value从一个set中查询,是否存在 + * + * @param key 键 + * @param value 值 + * @return true 存在 false不存在 + */ + public boolean sHasKey(String key, Object value) { + try { + return redisTemplate.opsForSet().isMember(key, value); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 将数据放入set缓存 + * + * @param key 键 + * @param values 值 可以是多个 + * @return 成功个数 + */ + public long sSet(String key, Object... values) { + try { + return redisTemplate.opsForSet().add(key, values); + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + /** + * 将set数据放入缓存 + * + * @param key 键 + * @param time 时间(秒) + * @param values 值 可以是多个 + * @return 成功个数 + */ + public long sSetAndTime(String key, long time, Object... values) { + try { + Long count = redisTemplate.opsForSet().add(key, values); + if (time > 0) { + expire(key, time); + } + return count; + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + /** + * 获取set缓存的长度 + * + * @param key 键 + * @return + */ + public long sGetSetSize(String key) { + try { + return redisTemplate.opsForSet().size(key); + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + /** + * 移除值为value的 + * + * @param key 键 + * @param values 值 可以是多个 + * @return 移除的个数 + */ + public long setRemove(String key, Object... values) { + try { + Long count = redisTemplate.opsForSet().remove(key, values); + return count; + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + // ===============================list================================= + + /** + * 获取list缓存的内容 + * + * @param key 键 + * @param start 开始 + * @param end 结束 0 到 -1代表所有值 + * @return + */ + public List lGet(String key, long start, long end) { + try { + return redisTemplate.opsForList().range(key, start, end); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 获取list缓存的长度 + * + * @param key 键 + * @return + */ + public long lGetListSize(String key) { + try { + return redisTemplate.opsForList().size(key); + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + /** + * 通过索引 获取list中的值 + * + * @param key 键 + * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 + * @return + */ + public Object lGetIndex(String key, long index) { + try { + return redisTemplate.opsForList().index(key, index); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @return + */ + public boolean lSet(String key, Object value) { + try { + redisTemplate.opsForList().rightPush(key, value); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) + * @return + */ + public boolean lSet(String key, Object value, long time) { + try { + redisTemplate.opsForList().rightPush(key, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @return + */ + public boolean lSet(String key, List value) { + try { + redisTemplate.opsForList().rightPushAll(key, value); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } +// +// /** +// * list缓存全量更新,先删后存 +// * +// * @param key 键 +// * @param value 值 +// * @return +// */ +// public boolean lDelAndSet(String key, List value) { +// try { +// redisTemplate.execute(new SessionCallback() { +// @Override +// public Object execute(RedisOperations operations) throws DataAccessException { +// operations.multi(); +// +// operations.delete(key); +// redisTemplate.opsForList().rightPushAll(key, value); +// +// operations.exec(); +// return null; +// } +// }); +// return true; +// } catch (Exception e) { +// e.printStackTrace(); +// return false; +// } +// } + + /** + * list缓存全量更新,先删后存 + * + * @param key 键 + * @param value 值 + * @return + */ + public boolean lDelAndSet(String key, List value) { + try { + String script = "redis.call('del', KEYS[1]) " + + "for i = 1, #ARGV do " + + " redis.call('rpush', KEYS[1], ARGV[i]) " + + "end "; + RedisScript redisScript = new DefaultRedisScript<>(script, Void.class); + redisTemplate.execute(redisScript, Collections.singletonList(key), value.toArray()); + + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) + * @return + */ + public boolean lSet(String key, List value, long time) { + try { + redisTemplate.opsForList().rightPushAll(key, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 根据索引修改list中的某条数据 + * + * @param key 键 + * @param index 索引 + * @param value 值 + * @return + */ + public boolean lUpdateIndex(String key, long index, Object value) { + try { + redisTemplate.opsForList().set(key, index, value); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 移除N个值为value + * + * @param key 键 + * @param count 移除多少个 + * @param value 值 + * @return 移除的个数 + */ + public long lRemove(String key, long count, Object value) { + try { + Long remove = redisTemplate.opsForList().remove(key, count, value); + return remove; + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + /** + * removing all values not within the slice between ``start`` and ``end`` + * + * @param key 键 + * @param start 开始 + * @param end 结束 0 到 -1代表所有值 + */ + public boolean lTrim(String key, long start, long end) { + try { + redisTemplate.opsForList().trim(key, start, end); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + + /** + * 查找匹配key + * + * @param pattern key + * @return / + */ + public List scan(String pattern) { + ScanOptions options = ScanOptions.scanOptions().match(pattern).build(); + RedisConnectionFactory factory = redisTemplate.getConnectionFactory(); + RedisConnection rc = Objects.requireNonNull(factory).getConnection(); + Cursor cursor = rc.scan(options); + List result = new ArrayList<>(); + while (cursor.hasNext()) { + result.add(new String(cursor.next())); + } + try { + RedisConnectionUtils.releaseConnection(rc, factory); + } catch (Exception e) { + log.error(e.getMessage(), e); + } + return result; + } + + // =============================== message queue ================================= + + /** + * 消息入队列 + * + * @param queue + * @param message + * @return + */ + public Long queuePut(String queue, Object message) { + try { + return redisTemplate.opsForList().leftPush(queue, message); + } catch (Exception e) { + log.error(e.getMessage(), e); + return 0L; + } + } + + /** + * 消息出队列 + * + * @param queue + * @return + */ + public Object queueGet(String queue) { + try { + return redisTemplate.opsForList().rightPop(queue, 1, TimeUnit.SECONDS); + } catch (Exception e) { + log.error(e.getMessage(), e); + return null; + } + } + + // =============================== lock ================================= + /** + * 创建锁 + * + * @param key 锁的Key + * @param releaseTime 锁过期时间,防止死锁 + * @return + */ + public boolean lock(String key, long releaseTime) { + // 尝试获取锁 + Boolean success = redisTemplate.opsForValue().setIfAbsent(key, 1, releaseTime, TimeUnit.SECONDS); + // 判断结果 + return success != null && success; + } + + /** + * 根据key释放锁 + * + * @param key + */ + public void deleteLock(String key) { + // 删除key即可释放锁 + redisTemplate.delete(key); + } + + public void flushDb() { + redisTemplate.execute((RedisCallback) connection -> { + connection.flushDb(); // 清空当前数据库 + return null; + }); + } +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmRulePageReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmRulePageReqVO.java index 63ade7b..447f6b7 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmRulePageReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmRulePageReqVO.java @@ -14,10 +14,10 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ public class AlarmRulePageReqVO extends PageParam { @Schema(description = "气体类型ID", example = "2833") - private String gasTypeId; + private Long gasTypeId; @Schema(description = "警报类型ID", example = "12917") - private String alarmTypeId; + private Long alarmTypeId; @Schema(description = "警报名称", example = "赵六") private String alarmName; @@ -50,13 +50,13 @@ public class AlarmRulePageReqVO extends PageParam { private Integer delFlag; @Schema(description = "创建者") - private String createBy; + private String creator; @Schema(description = "创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] createTime; @Schema(description = "更新者") - private String updateBy; + private String updater; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmRuleRespVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmRuleRespVO.java index 359c24c..8519d18 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmRuleRespVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmRuleRespVO.java @@ -14,15 +14,15 @@ public class AlarmRuleRespVO { @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "4303") @ExcelProperty("主键ID") - private String id; + private Long id; @Schema(description = "气体类型ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2833") @ExcelProperty("气体类型ID") - private String gasTypeId; + private Long gasTypeId; @Schema(description = "警报类型ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12917") @ExcelProperty("警报类型ID") - private String alarmTypeId; + private Long alarmTypeId; @Schema(description = "警报名称", example = "赵六") @ExcelProperty("警报名称") @@ -60,20 +60,14 @@ public class AlarmRuleRespVO { @ExcelProperty("备注") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("删除标志") - private Integer delFlag; @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) @ExcelProperty("创建者") - private String createBy; + private String creator; @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @ExcelProperty("创建时间") private LocalDateTime createTime; - @Schema(description = "更新者") - @ExcelProperty("更新者") - private String updateBy; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmRuleSaveReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmRuleSaveReqVO.java index fd21c17..7e0e8dd 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmRuleSaveReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmRuleSaveReqVO.java @@ -10,15 +10,15 @@ import jakarta.validation.constraints.*; public class AlarmRuleSaveReqVO { @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "4303") - private String id; + private Long id; @Schema(description = "气体类型ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2833") @NotEmpty(message = "气体类型ID不能为空") - private String gasTypeId; + private Long gasTypeId; @Schema(description = "警报类型ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12917") @NotEmpty(message = "警报类型ID不能为空") - private String alarmTypeId; + private Long alarmTypeId; @Schema(description = "警报名称", example = "赵六") private String alarmName; @@ -49,15 +49,5 @@ public class AlarmRuleSaveReqVO { @Schema(description = "备注", example = "你说的对") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "删除标志不能为空") - private Integer delFlag; - - @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "创建者不能为空") - private String createBy; - - @Schema(description = "更新者") - private String updateBy; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmTypePageReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmTypePageReqVO.java index cddb572..b0a1b40 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmTypePageReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmTypePageReqVO.java @@ -31,17 +31,13 @@ public class AlarmTypePageReqVO extends PageParam { @Schema(description = "备注", example = "随便") private String remark; - @Schema(description = "删除标志") - private Integer delFlag; @Schema(description = "创建者") - private String createBy; + private String creator; @Schema(description = "创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] createTime; - @Schema(description = "更新者") - private String updateBy; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmTypeRespVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmTypeRespVO.java index 8969456..622eee7 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmTypeRespVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmTypeRespVO.java @@ -14,7 +14,7 @@ public class AlarmTypeRespVO { @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "18440") @ExcelProperty("主键ID") - private String id; + private Long id; @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") @ExcelProperty("名称") @@ -40,20 +40,13 @@ public class AlarmTypeRespVO { @ExcelProperty("备注") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("删除标志") - private Integer delFlag; - @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) @ExcelProperty("创建者") - private String createBy; + private String creator; @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @ExcelProperty("创建时间") private LocalDateTime createTime; - @Schema(description = "更新者") - @ExcelProperty("更新者") - private String updateBy; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmTypeSaveReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmTypeSaveReqVO.java index d497744..80eb99e 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmTypeSaveReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/AlarmTypeSaveReqVO.java @@ -10,7 +10,7 @@ import jakarta.validation.constraints.*; public class AlarmTypeSaveReqVO { @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "18440") - private String id; + private Long id; @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") @NotEmpty(message = "名称不能为空") @@ -27,22 +27,7 @@ public class AlarmTypeSaveReqVO { @NotNull(message = "警报方式/级别(0:正常状态;1:一级警报;2:二级警报;3:弹窗警报)不能为空") private Integer level; - @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "排序不能为空") - private Integer sortOrder; - @Schema(description = "备注", example = "随便") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "删除标志不能为空") - private Integer delFlag; - - @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "创建者不能为空") - private String createBy; - - @Schema(description = "更新者") - private String updateBy; - } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FactoryPageReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FactoryPageReqVO.java new file mode 100644 index 0000000..aadd9bc --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FactoryPageReqVO.java @@ -0,0 +1,68 @@ +package cn.iocoder.yudao.module.hand.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - GAS工厂分页 Request VO") +@Data +public class FactoryPageReqVO extends PageParam { + + @Schema(description = "父节点ID", example = "997") + private Long parentId; + + @Schema(description = "层级(1:工厂;2:车间;3:班组)", example = "1") + private Integer type; + + @Schema(description = "名称", example = "王五") + private String name; + + @Schema(description = "城市") + private String city; + + @Schema(description = "总警报数") + private Integer alarmTotal; + + @Schema(description = "已处理警报数") + private Integer alarmDeal; + + @Schema(description = "区域图", example = "https://www.iocoder.cn") + private String picUrl; + + @Schema(description = "区域图缩放比例") + private Integer picScale; + + @Schema(description = "在区域图X坐标值") + private Double picX; + + @Schema(description = "在区域图X坐标值") + private Double picY; + + @Schema(description = "经度") + private Double longitude; + + @Schema(description = "纬度") + private Double latitude; + + @Schema(description = "区域西南坐标") + private String rectSouthWest; + + @Schema(description = "区域东北坐标") + private String rectNorthEast; + + @Schema(description = "排序") + private Integer sortOrder; + + @Schema(description = "备注", example = "你猜") + private String remark; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FactoryRespVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FactoryRespVO.java new file mode 100644 index 0000000..5026b60 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FactoryRespVO.java @@ -0,0 +1,86 @@ +package cn.iocoder.yudao.module.hand.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - GAS工厂 Response VO") +@Data +@ExcelIgnoreUnannotated +public class FactoryRespVO { + + @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "19786") + @ExcelProperty("主键ID") + private Long id; + + @Schema(description = "父节点ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "997") + @ExcelProperty("父节点ID") + private Long parentId; + + @Schema(description = "层级(1:工厂;2:车间;3:班组)", example = "1") + @ExcelProperty("层级(1:工厂;2:车间;3:班组)") + private Integer type; + + @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") + @ExcelProperty("名称") + private String name; + + @Schema(description = "城市") + @ExcelProperty("城市") + private String city; + + @Schema(description = "总警报数", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("总警报数") + private Integer alarmTotal; + + @Schema(description = "已处理警报数", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("已处理警报数") + private Integer alarmDeal; + + @Schema(description = "区域图", example = "https://www.iocoder.cn") + @ExcelProperty("区域图") + private String picUrl; + + @Schema(description = "区域图缩放比例") + @ExcelProperty("区域图缩放比例") + private Integer picScale; + + @Schema(description = "在区域图X坐标值") + @ExcelProperty("在区域图X坐标值") + private Double picX; + + @Schema(description = "在区域图X坐标值") + @ExcelProperty("在区域图X坐标值") + private Double picY; + + @Schema(description = "经度") + @ExcelProperty("经度") + private Double longitude; + + @Schema(description = "纬度") + @ExcelProperty("纬度") + private Double latitude; + + @Schema(description = "区域西南坐标") + @ExcelProperty("区域西南坐标") + private String rectSouthWest; + + @Schema(description = "区域东北坐标") + @ExcelProperty("区域东北坐标") + private String rectNorthEast; + + @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("排序") + private Integer sortOrder; + + @Schema(description = "备注", example = "你猜") + @ExcelProperty("备注") + private String remark; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; +} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FactorySaveReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FactorySaveReqVO.java new file mode 100644 index 0000000..da5f722 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FactorySaveReqVO.java @@ -0,0 +1,68 @@ +package cn.iocoder.yudao.module.hand.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import jakarta.validation.constraints.*; + +@Schema(description = "管理后台 - GAS工厂新增/修改 Request VO") +@Data +public class FactorySaveReqVO { + + @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "19786") + private Long id; + + @Schema(description = "父节点ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "997") + @NotNull(message = "父节点ID不能为空") + private Long parentId; + + @Schema(description = "层级(1:工厂;2:车间;3:班组)", example = "1") + private Integer type; + + @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") + @NotEmpty(message = "名称不能为空") + private String name; + + @Schema(description = "城市") + private String city; + + @Schema(description = "总警报数", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "总警报数不能为空") + private Integer alarmTotal; + + @Schema(description = "已处理警报数", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "已处理警报数不能为空") + private Integer alarmDeal; + + @Schema(description = "区域图", example = "https://www.iocoder.cn") + private String picUrl; + + @Schema(description = "区域图缩放比例") + private Integer picScale; + + @Schema(description = "在区域图X坐标值") + private Double picX; + + @Schema(description = "在区域图X坐标值") + private Double picY; + + @Schema(description = "经度") + private Double longitude; + + @Schema(description = "纬度") + private Double latitude; + + @Schema(description = "区域西南坐标") + private String rectSouthWest; + + @Schema(description = "区域东北坐标") + private String rectNorthEast; + + @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "排序不能为空") + private Integer sortOrder; + + @Schema(description = "备注", example = "你猜") + private String remark; + +} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceAlarmPageReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceAlarmPageReqVO.java index c194227..1066289 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceAlarmPageReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceAlarmPageReqVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.hand.vo; +import com.alibaba.excel.annotation.ExcelProperty; import lombok.*; import java.util.*; import io.swagger.v3.oas.annotations.media.Schema; @@ -14,10 +15,10 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ public class FenceAlarmPageReqVO extends PageParam { @Schema(description = "探头ID", example = "32133") - private String detectorId; + private Long detectorId; @Schema(description = "围栏id", example = "31072") - private String fenceId; + private Long fenceId; @Schema(description = "报警类型", example = "2") private Integer type; @@ -46,17 +47,8 @@ public class FenceAlarmPageReqVO extends PageParam { @Schema(description = "备注", example = "随便") private String remark; - @Schema(description = "删除标志") - private Integer delFlag; - - @Schema(description = "创建者") - private String createBy; - - @Schema(description = "创建时间") + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] createTime; - - @Schema(description = "更新者") - private String updateBy; - } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceAlarmRespVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceAlarmRespVO.java index 67d2418..23567af 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceAlarmRespVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceAlarmRespVO.java @@ -14,15 +14,15 @@ public class FenceAlarmRespVO { @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12756") @ExcelProperty("主键ID") - private String id; + private Long id; @Schema(description = "探头ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "32133") @ExcelProperty("探头ID") - private String detectorId; + private Long detectorId; @Schema(description = "围栏id", requiredMode = Schema.RequiredMode.REQUIRED, example = "31072") @ExcelProperty("围栏id") - private String fenceId; + private Long fenceId; @Schema(description = "报警类型", example = "2") @ExcelProperty("报警类型") @@ -60,20 +60,7 @@ public class FenceAlarmRespVO { @ExcelProperty("备注") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("删除标志") - private Integer delFlag; - - @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建者") - private String createBy; - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @ExcelProperty("创建时间") private LocalDateTime createTime; - - @Schema(description = "更新者") - @ExcelProperty("更新者") - private String updateBy; - } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceAlarmSaveReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceAlarmSaveReqVO.java index d4ff864..bf89d27 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceAlarmSaveReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceAlarmSaveReqVO.java @@ -2,9 +2,12 @@ package cn.iocoder.yudao.module.hand.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; + import java.util.*; + import jakarta.validation.constraints.*; import org.springframework.format.annotation.DateTimeFormat; + import java.time.LocalDateTime; @Schema(description = "管理后台 - GAS手持探测器围栏报警新增/修改 Request VO") @@ -12,11 +15,11 @@ import java.time.LocalDateTime; public class FenceAlarmSaveReqVO { @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12756") - private String id; + private Long id; @Schema(description = "探头ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "32133") @NotEmpty(message = "探头ID不能为空") - private String detectorId; + private Long detectorId; @Schema(description = "围栏id", requiredMode = Schema.RequiredMode.REQUIRED, example = "31072") @NotEmpty(message = "围栏id不能为空") @@ -51,15 +54,6 @@ public class FenceAlarmSaveReqVO { @NotEmpty(message = "备注不能为空") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "删除标志不能为空") - private Integer delFlag; - - @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "创建者不能为空") - private String createBy; - - @Schema(description = "更新者") - private String updateBy; - + @Schema(description = "租户id") + private Long tenantId; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FencePageReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FencePageReqVO.java index f2d9265..c4bdf01 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FencePageReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FencePageReqVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.hand.vo; +import com.alibaba.excel.annotation.ExcelProperty; import lombok.*; import java.util.*; import io.swagger.v3.oas.annotations.media.Schema; @@ -28,17 +29,7 @@ public class FencePageReqVO extends PageParam { @Schema(description = "备注", example = "你说的对") private String remark; - @Schema(description = "删除标志") - private Integer delFlag; - - @Schema(description = "创建者") - private String createBy; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") private LocalDateTime[] createTime; - - @Schema(description = "更新者") - private String updateBy; - } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FencePointVo.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FencePointVo.java new file mode 100644 index 0000000..76c50b7 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FencePointVo.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.hand.vo; + +import lombok.Data; + +@Data +public class FencePointVo { + public double x;//经度 + public double y;//纬度 + + //public Long fenceId; + + public FencePointVo() { + } + + public FencePointVo(double x, double y) { + this.x = x; + this.y = y; + } +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceRespVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceRespVO.java index 5721357..51636d2 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceRespVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceRespVO.java @@ -14,7 +14,7 @@ public class FenceRespVO { @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12448") @ExcelProperty("主键ID") - private String id; + private Long id; @Schema(description = "围栏名称", example = "王五") @ExcelProperty("围栏名称") @@ -36,20 +36,7 @@ public class FenceRespVO { @ExcelProperty("备注") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("删除标志") - private Integer delFlag; - - @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建者") - private String createBy; - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @ExcelProperty("创建时间") private LocalDateTime createTime; - - @Schema(description = "更新者") - @ExcelProperty("更新者") - private String updateBy; - } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceSaveReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceSaveReqVO.java index 15c8a09..6139c14 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceSaveReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/FenceSaveReqVO.java @@ -10,7 +10,7 @@ import jakarta.validation.constraints.*; public class FenceSaveReqVO { @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "12448") - private String id; + private Long id; @Schema(description = "围栏名称", example = "王五") private String name; @@ -27,15 +27,5 @@ public class FenceSaveReqVO { @Schema(description = "备注", example = "你说的对") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "删除标志不能为空") - private Integer delFlag; - - @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "创建者不能为空") - private String createBy; - - @Schema(description = "更新者") - private String updateBy; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/GasTypePageReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/GasTypePageReqVO.java index 7763e52..aabb3d6 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/GasTypePageReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/GasTypePageReqVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.hand.vo; +import com.alibaba.excel.annotation.ExcelProperty; import lombok.*; import java.util.*; import io.swagger.v3.oas.annotations.media.Schema; @@ -28,17 +29,8 @@ public class GasTypePageReqVO extends PageParam { @Schema(description = "备注", example = "你说的对") private String remark; - @Schema(description = "删除标志") - private Integer delFlag; - - @Schema(description = "创建者") - private String createBy; - - @Schema(description = "创建时间") + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] createTime; - - @Schema(description = "更新者") - private String updateBy; - } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/GasTypeRespVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/GasTypeRespVO.java index 357fff4..4374684 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/GasTypeRespVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/GasTypeRespVO.java @@ -14,7 +14,7 @@ public class GasTypeRespVO { @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25168") @ExcelProperty("主键ID") - private String id; + private Long id; @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") @ExcelProperty("名称") @@ -36,20 +36,7 @@ public class GasTypeRespVO { @ExcelProperty("备注") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("删除标志") - private Integer delFlag; - - @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建者") - private String createBy; - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @ExcelProperty("创建时间") private LocalDateTime createTime; - - @Schema(description = "更新者") - @ExcelProperty("更新者") - private String updateBy; - } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/GasTypeSaveReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/GasTypeSaveReqVO.java index 47d9ca8..0e4d495 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/GasTypeSaveReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/GasTypeSaveReqVO.java @@ -10,7 +10,7 @@ import jakarta.validation.constraints.*; public class GasTypeSaveReqVO { @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25168") - private String id; + private Long id; @Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") @NotEmpty(message = "名称不能为空") @@ -30,15 +30,5 @@ public class GasTypeSaveReqVO { @Schema(description = "备注", example = "你说的对") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "删除标志不能为空") - private Integer delFlag; - - @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "创建者不能为空") - private String createBy; - - @Schema(description = "更新者") - private String updateBy; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/Geofence.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/Geofence.java new file mode 100644 index 0000000..27a6e7e --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/Geofence.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.module.hand.vo; + +import lombok.Data; + +import java.util.Collections; +import java.util.List; +@Data +public class Geofence { + private final List vertices; + private final double minX, minY, maxX, maxY; // 包围盒 + + public Geofence(List vertices) { + if (vertices == null || vertices.size() < 3) { + throw new IllegalArgumentException("一个多边形至少需要3个顶点。"); + } + this.vertices = Collections.unmodifiableList(vertices); + + // 在构造时一次性计算包围盒 + double tempMinX = Double.MAX_VALUE; + double tempMinY = Double.MAX_VALUE; + double tempMaxX = -Double.MAX_VALUE; + double tempMaxY = -Double.MAX_VALUE; + + for (FencePointVo point : vertices) { + tempMinX = Math.min(tempMinX, point.x); + tempMinY = Math.min(tempMinY, point.y); + tempMaxX = Math.max(tempMaxX, point.x); + tempMaxY = Math.max(tempMaxY, point.y); + } + this.minX = tempMinX; + this.minY = tempMinY; + this.maxX = tempMaxX; + this.maxY = tempMaxY; + } + + /** + * 判断一个点是否在当前围栏的包围盒内。 + * 这是一个快速的初步检查。 + */ + public boolean isPointInBoundingBox(double x, double y) { + return x >= this.minX && x <= this.maxX && y >= this.minY && y <= this.maxY; + } + + public List getVertices() { + return vertices; + } +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandAlarmPageReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandAlarmPageReqVO.java index 31993f8..2059334 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandAlarmPageReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandAlarmPageReqVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.hand.vo; +import com.alibaba.excel.annotation.ExcelProperty; import lombok.*; import java.util.*; import io.swagger.v3.oas.annotations.media.Schema; @@ -13,6 +14,9 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data public class HandAlarmPageReqVO extends PageParam { + @Schema(description = "持有人姓名", example = "赵六") + private String name; + @Schema(description = "警报方式/级别(0:正常状态;1:一级警报;2:二级警报;3:弹窗警报)") private Integer alarmLevel; @@ -49,17 +53,8 @@ public class HandAlarmPageReqVO extends PageParam { @Schema(description = "备注", example = "随便") private String remark; - @Schema(description = "删除标志") - private Integer delFlag; - - @Schema(description = "创建者") - private String createBy; - - @Schema(description = "创建时间") + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] createTime; - - @Schema(description = "更新者") - private String updateBy; - } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandAlarmRespVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandAlarmRespVO.java index 0539ffd..1bb056f 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandAlarmRespVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandAlarmRespVO.java @@ -12,9 +12,12 @@ import com.alibaba.excel.annotation.*; @ExcelIgnoreUnannotated public class HandAlarmRespVO { + @Schema(description = "持有人姓名", example = "赵六") + private String name; + @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "17955") @ExcelProperty("主键ID") - private String id; + private Long id; @Schema(description = "警报方式/级别(0:正常状态;1:一级警报;2:二级警报;3:弹窗警报)", requiredMode = Schema.RequiredMode.REQUIRED) @ExcelProperty("警报方式/级别(0:正常状态;1:一级警报;2:二级警报;3:弹窗警报)") @@ -64,20 +67,8 @@ public class HandAlarmRespVO { @ExcelProperty("备注") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("删除标志") - private Integer delFlag; - - @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建者") - private String createBy; @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @ExcelProperty("创建时间") private LocalDateTime createTime; - - @Schema(description = "更新者") - @ExcelProperty("更新者") - private String updateBy; - } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandAlarmSaveReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandAlarmSaveReqVO.java index 5e55290..db6c7d7 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandAlarmSaveReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandAlarmSaveReqVO.java @@ -2,9 +2,12 @@ package cn.iocoder.yudao.module.hand.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; + import java.util.*; + import jakarta.validation.constraints.*; import org.springframework.format.annotation.DateTimeFormat; + import java.time.LocalDateTime; @Schema(description = "管理后台 - GAS手持探测器警报新增/修改 Request VO") @@ -12,12 +15,19 @@ import java.time.LocalDateTime; public class HandAlarmSaveReqVO { @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "17955") - private String id; + private Long id; + + @Schema(description = "持有人姓名", example = "赵六") + private String name; @Schema(description = "警报方式/级别(0:正常状态;1:一级警报;2:二级警报;3:弹窗警报)", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "警报方式/级别(0:正常状态;1:一级警报;2:二级警报;3:弹窗警报)不能为空") private Integer alarmLevel; + @Schema(description = "报警类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "报警类型不能为空") + private Integer alarmType; + @Schema(description = "气体类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotEmpty(message = "气体类型不能为空") private String gasType; @@ -48,22 +58,13 @@ public class HandAlarmSaveReqVO { @Schema(description = "结束时间") private LocalDateTime tAlarmEnd; - @Schema(description = "状态(0:待处理;1:处理中;1:已处理)", example = "1") - private Integer status; - @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") @NotEmpty(message = "备注不能为空") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "删除标志不能为空") - private Integer delFlag; - - @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "创建者不能为空") - private String createBy; - - @Schema(description = "更新者") - private String updateBy; + /** + * 租户id + */ + private Integer tenantId; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDataVo.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDataVo.java new file mode 100644 index 0000000..95b3bea --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDataVo.java @@ -0,0 +1,104 @@ +package cn.iocoder.yudao.module.hand.vo; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.Date; + +@Data +@JsonIgnoreProperties(ignoreUnknown = true) +public class HandDataVo { + + @Schema(description = "id") + private Long id; + + @Schema(description = "设备sn") + private String sn; + + @Schema(description = "电量") + private String battery; + + @Schema(description = "数据") + private Double value; + + @Schema(description = "经度") + private Double longitude; + + @Schema(description = "纬度") + private Double latitude; + + @Schema(description = "更新时间") + private Date time; + + @Schema(description = "持有人姓名") + private String name; + + @Schema(description = "围栏id") + private String fenceIds; + + @Schema(description = "围栏类型(1:超出报警,2:进入报警)") + private Integer fenceType; + + @Schema(description = "气体类型ID") + private Long gasTypeId; + + @Schema(description = "气体化学式") + private String gasChemical; + + @Schema(description = "低于多少电量报警") + private BigDecimal batteryAlarmValue; + + @Schema(description = "数值除数") + private Integer accuracy; + + @Schema(description = "报警等级") + private Integer alarmLevel; + + @Schema(description = "最大报警等级") + private Integer maxAlarmLevel; + + @Schema(description = "首次报警") + private Double firstValue; + + @Schema(description = "最大报警值") + private Double maxValue; + + + @Schema(description = "报警开始时间") + private LocalDateTime tAlarmStart; + @Schema(description = "报警结束时间") + private LocalDateTime tAlarmEnd; + + @Schema(description = "气体报警状态(0:正常;1:报警)") + private Integer gasStatus; + @Schema(description = "气体报警Id") + private Long alarmId; + + @Schema(description = "电池报警状态(0:正常;1:报警)") + private Integer batteryStatus; + private Integer batteryStatusAlarmId; + + @Schema(description = "电子围栏报警状态(0:正常;1:报警)") + private Integer fenceStatus; + @Schema(description = "电子围栏报警Id") + private Long fenceAlarmId; + + @Schema(description = "在线状态(0:离线;1:在线)") + private Integer onlineStatus; + + + @Schema(description = "启用状态(0:备用;1:启用)") + private Integer enableStatus; + + @Schema(description = "超出围栏米数") + private Double distance; + + @Schema(description = "最远超出米数") + private Double maxDistance; + + @Schema(description = "租户id") + private Long tenantId; +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDetectorPageReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDetectorPageReqVO.java index 8f15b15..da34f08 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDetectorPageReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDetectorPageReqVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.hand.vo; +import com.alibaba.excel.annotation.ExcelProperty; import lombok.*; import io.swagger.v3.oas.annotations.media.Schema; import cn.iocoder.yudao.framework.common.pojo.PageParam; @@ -19,10 +20,10 @@ public class HandDetectorPageReqVO extends PageParam { private String name; @Schema(description = "围栏id", example = "15853") - private String fenceId; + private Long fenceId; @Schema(description = "气体类型ID", example = "31358") - private String gasTypeId; + private Long gasTypeId; @Schema(description = "气体化学式") private String gasChemical; @@ -69,17 +70,8 @@ public class HandDetectorPageReqVO extends PageParam { @Schema(description = "备注", example = "你猜") private String remark; - @Schema(description = "删除标志") - private Integer delFlag; - - @Schema(description = "创建者") - private String createBy; - - @Schema(description = "创建时间") + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] createTime; - - @Schema(description = "更新者") - private String updateBy; - } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDetectorRespVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDetectorRespVO.java index 805c634..92e6d63 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDetectorRespVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDetectorRespVO.java @@ -13,7 +13,7 @@ public class HandDetectorRespVO { @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24178") @ExcelProperty("主键ID") - private String id; + private Long id; @Schema(description = "SN") @ExcelProperty("SN") @@ -25,11 +25,11 @@ public class HandDetectorRespVO { @Schema(description = "围栏id", example = "15853") @ExcelProperty("围栏id") - private String fenceId; + private Long fenceId; @Schema(description = "气体类型ID", example = "31358") @ExcelProperty("气体类型ID") - private String gasTypeId; + private Long gasTypeId; @Schema(description = "气体化学式") @ExcelProperty("气体化学式") @@ -91,20 +91,10 @@ public class HandDetectorRespVO { @ExcelProperty("备注") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("删除标志") - private Integer delFlag; - - @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建者") - private String createBy; @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @ExcelProperty("创建时间") private LocalDateTime createTime; - @Schema(description = "更新者") - @ExcelProperty("更新者") - private String updateBy; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDetectorSaveReqVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDetectorSaveReqVO.java index ab54171..49e159e 100644 --- a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDetectorSaveReqVO.java +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandDetectorSaveReqVO.java @@ -9,7 +9,7 @@ import jakarta.validation.constraints.*; public class HandDetectorSaveReqVO { @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24178") - private String id; + private Long id; @Schema(description = "SN") private String sn; @@ -18,10 +18,10 @@ public class HandDetectorSaveReqVO { private String name; @Schema(description = "围栏id", example = "15853") - private String fenceId; + private Long fenceId; @Schema(description = "气体类型ID", example = "31358") - private String gasTypeId; + private Long gasTypeId; @Schema(description = "气体化学式") private String gasChemical; @@ -32,9 +32,6 @@ public class HandDetectorSaveReqVO { @Schema(description = "测量范围中的最大值") private Double max; - @Schema(description = "状态(0:未知;1:正常;2:故障;3:离线)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "状态(0:未知;1:正常;2:故障;3:离线)不能为空") - private Integer status; @Schema(description = "单位") private String unit; @@ -46,7 +43,6 @@ public class HandDetectorSaveReqVO { private String manufacturer; @Schema(description = "启用状态(0:备用;1:启用)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "启用状态(0:备用;1:启用)不能为空") private Integer enableStatus; @Schema(description = "在区域图X坐标值") @@ -70,15 +66,7 @@ public class HandDetectorSaveReqVO { @Schema(description = "备注", example = "你猜") private String remark; - @Schema(description = "删除标志", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "删除标志不能为空") - private Integer delFlag; - @Schema(description = "创建者", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "创建者不能为空") - private String createBy; - @Schema(description = "更新者") - private String updateBy; } \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandOriginalLog.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandOriginalLog.java new file mode 100644 index 0000000..07b3031 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandOriginalLog.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.module.hand.vo; + +import lombok.Data; +import java.sql.Timestamp; // 确保导入的是 java.sql.Timestamp + + +@Data +public class HandOriginalLog { + + private String sn; + + private String payload; + + private Timestamp ts; + + private Long tenantId; +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandTdenginePageVO.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandTdenginePageVO.java new file mode 100644 index 0000000..45986c8 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/HandTdenginePageVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.hand.vo; + +import ch.qos.logback.core.model.TimestampModel; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import lombok.Data; + +import java.sql.Timestamp; + +@Data +public class HandTdenginePageVO extends PageParam { + + private String sn; + + private Timestamp startTime; + + private Timestamp endTime; + + +} diff --git a/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/TdengineDataVo.java b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/TdengineDataVo.java new file mode 100644 index 0000000..8cdfff9 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/java/cn/iocoder/yudao/module/hand/vo/TdengineDataVo.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.hand.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.util.Date; + +@Data +public class TdengineDataVo { + + @Schema(description = "设备sn") + private String sn; + + @Schema(description = "电量") + private String battery; + + @Schema(description = "数据") + private Double value; + + @Schema(description = "经度") + private Double longitude; + + @Schema(description = "纬度") + private Double latitude; + + @Schema(description = "更新时间") + private Timestamp ts; + + @Schema(description = "持有人姓名") + private String name; + + @Schema(description = "租户id") + private Long tenantId; +} diff --git a/cc-admin-master/yudao-module-hand/src/main/resources/mapper/FactoryMapper.xml b/cc-admin-master/yudao-module-hand/src/main/resources/mapper/FactoryMapper.xml new file mode 100644 index 0000000..2bf2899 --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/resources/mapper/FactoryMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/resources/mapper/HandDetectorMapper.xml b/cc-admin-master/yudao-module-hand/src/main/resources/mapper/HandDetectorMapper.xml index 478592d..e29b7eb 100644 --- a/cc-admin-master/yudao-module-hand/src/main/resources/mapper/HandDetectorMapper.xml +++ b/cc-admin-master/yudao-module-hand/src/main/resources/mapper/HandDetectorMapper.xml @@ -9,4 +9,10 @@ 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ --> + + \ No newline at end of file diff --git a/cc-admin-master/yudao-module-hand/src/main/resources/mapper/TdengineMapper.xml b/cc-admin-master/yudao-module-hand/src/main/resources/mapper/TdengineMapper.xml new file mode 100644 index 0000000..3ff60cf --- /dev/null +++ b/cc-admin-master/yudao-module-hand/src/main/resources/mapper/TdengineMapper.xml @@ -0,0 +1,77 @@ + + + + + + + + + INSERT INTO hand_original_log_${sn} + USING hand_original_log + TAGS(#{sn}, #{tenantId}) + (ts, payload) + VALUES + + (#{log.ts}, #{log.payload}) + + + + + INSERT INTO device_data_log_#{sn} + USING device_data_log + TAGS(#{sn}, #{tenantId}) + (ts, battery, `value`, longitude, latitude, `name`) + VALUES + + (#{log.ts}, #{log.battery}, #{log.value}, #{log.longitude}, #{log.latitude}, #{log.name}) + + + + + + + + \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/pom.xml b/cc-admin-master/yudao-module-iot/pom.xml deleted file mode 100644 index fd2fd48..0000000 --- a/cc-admin-master/yudao-module-iot/pom.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - cc-admin-master - cn.iocoder.boot - ${revision} - - - yudao-module-iot-api - yudao-module-iot-biz - yudao-module-iot-plugins - - 4.0.0 - - yudao-module-iot - pom - - ${project.artifactId} - - 物联网模块 - - - - \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/pom.xml b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/pom.xml deleted file mode 100644 index 4a31c9b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - yudao-module-iot - cn.iocoder.boot - ${revision} - - 4.0.0 - yudao-module-iot-api - jar - - ${project.artifactId} - - - 物联网 模块 API,暴露给其它模块调用 - - - - - cn.iocoder.boot - yudao-common - - - - - org.springframework - spring-web - provided - - - - - com.fasterxml.jackson.core - jackson-databind - provided - - - - org.pf4j - pf4j-spring - - - - - org.springframework.boot - spring-boot-starter-validation - true - - - - diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/IotDeviceUpstreamApi.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/IotDeviceUpstreamApi.java deleted file mode 100644 index e88706a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/IotDeviceUpstreamApi.java +++ /dev/null @@ -1,93 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.*; -import cn.iocoder.yudao.module.iot.enums.ApiConstants; -import jakarta.validation.Valid; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; - -/** - * 设备数据 Upstream 上行 API - * - * 目的:设备 -> 插件 -> 服务端 - * - * @author haohao - */ -public interface IotDeviceUpstreamApi { - - String PREFIX = ApiConstants.PREFIX + "/device/upstream"; - - // ========== 设备相关 ========== - - /** - * 更新设备状态 - * - * @param updateReqDTO 更新设备状态 DTO - */ - @PostMapping(PREFIX + "/update-state") - CommonResult updateDeviceState(@Valid @RequestBody IotDeviceStateUpdateReqDTO updateReqDTO); - - /** - * 上报设备属性数据 - * - * @param reportReqDTO 上报设备属性数据 DTO - */ - @PostMapping(PREFIX + "/report-property") - CommonResult reportDeviceProperty(@Valid @RequestBody IotDevicePropertyReportReqDTO reportReqDTO); - - /** - * 上报设备事件数据 - * - * @param reportReqDTO 设备事件 - */ - @PostMapping(PREFIX + "/report-event") - CommonResult reportDeviceEvent(@Valid @RequestBody IotDeviceEventReportReqDTO reportReqDTO); - - // TODO @芋艿:这个需要 plugins 接入下 - /** - * 注册设备 - * - * @param registerReqDTO 注册设备 DTO - */ - @PostMapping(PREFIX + "/register") - CommonResult registerDevice(@Valid @RequestBody IotDeviceRegisterReqDTO registerReqDTO); - - // TODO @芋艿:这个需要 plugins 接入下 - /** - * 注册子设备 - * - * @param registerReqDTO 注册子设备 DTO - */ - @PostMapping(PREFIX + "/register-sub") - CommonResult registerSubDevice(@Valid @RequestBody IotDeviceRegisterSubReqDTO registerReqDTO); - - // TODO @芋艿:这个需要 plugins 接入下 - /** - * 注册设备拓扑 - * - * @param addReqDTO 注册设备拓扑 DTO - */ - @PostMapping(PREFIX + "/add-topology") - CommonResult addDeviceTopology(@Valid @RequestBody IotDeviceTopologyAddReqDTO addReqDTO); - - // TODO @芋艿:考虑 http 认证 - /** - * 认证 Emqx 连接 - * - * @param authReqDTO 认证 Emqx 连接 DTO - */ - @PostMapping(PREFIX + "/authenticate-emqx-connection") - CommonResult authenticateEmqxConnection(@Valid @RequestBody IotDeviceEmqxAuthReqDTO authReqDTO); - - // ========== 插件相关 ========== - - /** - * 心跳插件实例 - * - * @param heartbeatReqDTO 心跳插件实例 DTO - */ - @PostMapping(PREFIX + "/heartbeat-plugin-instance") - CommonResult heartbeatPluginInstance(@Valid @RequestBody IotPluginInstanceHeartbeatReqDTO heartbeatReqDTO); - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceConfigSetReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceConfigSetReqDTO.java deleted file mode 100644 index 9624b67..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceConfigSetReqDTO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.downstream; - -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -import java.util.Map; - -/** - * IoT 设备【配置】设置 Request DTO - * - * @author 芋道源码 - */ -@Data -public class IotDeviceConfigSetReqDTO extends IotDeviceDownstreamAbstractReqDTO { - - /** - * 配置 - */ - @NotNull(message = "配置不能为空") - private Map config; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceDownstreamAbstractReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceDownstreamAbstractReqDTO.java deleted file mode 100644 index e78bea6..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceDownstreamAbstractReqDTO.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.downstream; - -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; - -/** - * IoT 设备下行的抽象 Request DTO - * - * @author 芋道源码 - */ -@Data -public abstract class IotDeviceDownstreamAbstractReqDTO { - - /** - * 请求编号 - */ - private String requestId; - - /** - * 产品标识 - */ - @NotEmpty(message = "产品标识不能为空") - private String productKey; - /** - * 设备名称 - */ - @NotEmpty(message = "设备名称不能为空") - private String deviceName; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceOtaUpgradeReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceOtaUpgradeReqDTO.java deleted file mode 100644 index 8eccec4..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceOtaUpgradeReqDTO.java +++ /dev/null @@ -1,66 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.downstream; - -import cn.hutool.core.map.MapUtil; -import lombok.Data; - -import java.util.Map; - -/** - * IoT 设备【OTA】升级下发 Request DTO(更新固件消息) - * - * @author 芋道源码 - */ -@Data -public class IotDeviceOtaUpgradeReqDTO extends IotDeviceDownstreamAbstractReqDTO { - - /** - * 固件编号 - */ - private Long firmwareId; - /** - * 固件版本 - */ - private String version; - - /** - * 签名方式 - * - * 例如说:MD5、SHA256 - */ - private String signMethod; - /** - * 固件文件签名 - */ - private String fileSign; - /** - * 固件文件大小 - */ - private Long fileSize; - /** - * 固件文件 URL - */ - private String fileUrl; - - /** - * 自定义信息,建议使用 JSON 格式 - */ - private String information; - - public static IotDeviceOtaUpgradeReqDTO build(Map map) { - return new IotDeviceOtaUpgradeReqDTO() - .setFirmwareId(MapUtil.getLong(map, "firmwareId")).setVersion((String) map.get("version")) - .setSignMethod((String) map.get("signMethod")).setFileSign((String) map.get("fileSign")) - .setFileSize(MapUtil.getLong(map, "fileSize")).setFileUrl((String) map.get("fileUrl")) - .setInformation((String) map.get("information")); - } - - public static Map build(IotDeviceOtaUpgradeReqDTO dto) { - return MapUtil.builder() - .put("firmwareId", dto.getFirmwareId()).put("version", dto.getVersion()) - .put("signMethod", dto.getSignMethod()).put("fileSign", dto.getFileSign()) - .put("fileSize", dto.getFileSize()).put("fileUrl", dto.getFileUrl()) - .put("information", dto.getInformation()) - .build(); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDevicePropertyGetReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDevicePropertyGetReqDTO.java deleted file mode 100644 index d9ae963..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDevicePropertyGetReqDTO.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.downstream; - -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; - -import java.util.List; - -// TODO @芋艿:从 server => plugin => device 是否有必要?从阿里云 iot 来看,没有这个功能?! -// TODO @芋艿:是不是改成 read 更好?在看看阿里云的 topic 设计 -/** - * IoT 设备【属性】获取 Request DTO - * - * @author 芋道源码 - */ -@Data -public class IotDevicePropertyGetReqDTO extends IotDeviceDownstreamAbstractReqDTO { - - /** - * 属性标识数组 - */ - @NotEmpty(message = "属性标识数组不能为空") - private List identifiers; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDevicePropertySetReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDevicePropertySetReqDTO.java deleted file mode 100644 index 170fe80..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDevicePropertySetReqDTO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.downstream; - -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; - -import java.util.Map; - -/** - * IoT 设备【属性】设置 Request DTO - * - * @author 芋道源码 - */ -@Data -public class IotDevicePropertySetReqDTO extends IotDeviceDownstreamAbstractReqDTO { - - /** - * 属性参数 - */ - @NotEmpty(message = "属性参数不能为空") - private Map properties; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceServiceInvokeReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceServiceInvokeReqDTO.java deleted file mode 100644 index 0a2b3f0..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/downstream/IotDeviceServiceInvokeReqDTO.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.downstream; - -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; - -import java.util.Map; - -/** - * IoT 设备【服务】调用 Request DTO - * - * @author 芋道源码 - */ -@Data -public class IotDeviceServiceInvokeReqDTO extends IotDeviceDownstreamAbstractReqDTO { - - /** - * 服务标识 - */ - @NotEmpty(message = "服务标识不能为空") - private String identifier; - /** - * 调用参数 - */ - private Map params; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceEmqxAuthReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceEmqxAuthReqDTO.java deleted file mode 100644 index 8762aae..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceEmqxAuthReqDTO.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.upstream; - -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; - -// TODO @芋艿:要不要继承 IotDeviceUpstreamAbstractReqDTO -// TODO @芋艿:@haohao:后续其它认证的设计 -/** - * IoT 认证 Emqx 连接 Request DTO - * - * @author 芋道源码 - */ -@Data -public class IotDeviceEmqxAuthReqDTO { - - /** - * 客户端 ID - */ - @NotEmpty(message = "客户端 ID 不能为空") - private String clientId; - - /** - * 用户名 - */ - @NotEmpty(message = "用户名不能为空") - private String username; - - /** - * 密码 - */ - @NotEmpty(message = "密码不能为空") - private String password; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceEventReportReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceEventReportReqDTO.java deleted file mode 100644 index 34e6283..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceEventReportReqDTO.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.upstream; - -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; - -import java.util.Map; - -/** - * IoT 设备【事件】上报 Request DTO - * - * @author 芋道源码 - */ -@Data -public class IotDeviceEventReportReqDTO extends IotDeviceUpstreamAbstractReqDTO { - - /** - * 事件标识 - */ - @NotEmpty(message = "事件标识不能为空") - private String identifier; - /** - * 事件参数 - */ - private Map params; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceOtaProgressReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceOtaProgressReqDTO.java deleted file mode 100644 index a88a72e..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceOtaProgressReqDTO.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.upstream; - -import lombok.Data; - -// TODO @芋艿:待实现:/ota/${productKey}/${deviceName}/progress -/** - * IoT 设备【OTA】升级进度 Request DTO(上报更新固件进度) - * - * @author 芋道源码 - */ -@Data -public class IotDeviceOtaProgressReqDTO extends IotDeviceUpstreamAbstractReqDTO { - - /** - * 固件编号 - */ - private Long firmwareId; - - /** - * 升级状态 - * - * 枚举 {@link cn.iocoder.yudao.module.iot.enums.ota.IotOtaUpgradeRecordStatusEnum} - */ - private Integer status; - /** - * 升级进度,百分比 - */ - private Integer progress; - - /** - * 升级进度描述 - */ - private String description; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceOtaPullReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceOtaPullReqDTO.java deleted file mode 100644 index 6328704..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceOtaPullReqDTO.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.upstream; - -// TODO @芋艿:待实现:/ota/${productKey}/${deviceName}/pull -/** - * IoT 设备【OTA】升级下拉 Request DTO(拉取固件更新) - * - * @author 芋道源码 - */ -public class IotDeviceOtaPullReqDTO { - - /** - * 固件编号 - */ - private Long firmwareId; - - /** - * 固件版本 - */ - private String version; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceOtaReportReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceOtaReportReqDTO.java deleted file mode 100644 index 2b3b91c..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceOtaReportReqDTO.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.upstream; - -// TODO @芋艿:待实现:/ota/${productKey}/${deviceName}/report -/** - * IoT 设备【OTA】上报 Request DTO(上报固件版本) - * - * @author 芋道源码 - */ -public class IotDeviceOtaReportReqDTO { - - /** - * 固件编号 - */ - private Long firmwareId; - - /** - * 固件版本 - */ - private String version; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDevicePropertyReportReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDevicePropertyReportReqDTO.java deleted file mode 100644 index 4a276bd..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDevicePropertyReportReqDTO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.upstream; - -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; - -import java.util.Map; - -/** - * IoT 设备【属性】上报 Request DTO - * - * @author 芋道源码 - */ -@Data -public class IotDevicePropertyReportReqDTO extends IotDeviceUpstreamAbstractReqDTO { - - /** - * 属性参数 - */ - @NotEmpty(message = "属性参数不能为空") - private Map properties; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceRegisterReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceRegisterReqDTO.java deleted file mode 100644 index cab55e8..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceRegisterReqDTO.java +++ /dev/null @@ -1,12 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.upstream; - -import lombok.Data; - -/** - * IoT 设备【注册】自己 Request DTO - * - * @author 芋道源码 - */ -@Data -public class IotDeviceRegisterReqDTO extends IotDeviceUpstreamAbstractReqDTO { -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceRegisterSubReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceRegisterSubReqDTO.java deleted file mode 100644 index 0b826fb..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceRegisterSubReqDTO.java +++ /dev/null @@ -1,43 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.upstream; - -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; - -import java.util.List; - -/** - * IoT 设备【注册】子设备 Request DTO - * - * @author 芋道源码 - */ -@Data -public class IotDeviceRegisterSubReqDTO extends IotDeviceUpstreamAbstractReqDTO { - - // TODO @芋艿:看看要不要优化命名 - /** - * 子设备数组 - */ - @NotEmpty(message = "子设备不能为空") - private List params; - - /** - * 设备信息 - */ - @Data - public static class Device { - - /** - * 产品标识 - */ - @NotEmpty(message = "产品标识不能为空") - private String productKey; - - /** - * 设备名称 - */ - @NotEmpty(message = "设备名称不能为空") - private String deviceName; - - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceStateUpdateReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceStateUpdateReqDTO.java deleted file mode 100644 index 38c479a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceStateUpdateReqDTO.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.upstream; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStateEnum; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -/** - * IoT 设备【状态】更新 Request DTO - * - * @author 芋道源码 - */ -@Data -public class IotDeviceStateUpdateReqDTO extends IotDeviceUpstreamAbstractReqDTO { - - /** - * 设备状态 - */ - @NotNull(message = "设备状态不能为空") - @InEnum(IotDeviceStateEnum.class) // 只使用:在线、离线 - private Integer state; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceTopologyAddReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceTopologyAddReqDTO.java deleted file mode 100644 index 18efe7d..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceTopologyAddReqDTO.java +++ /dev/null @@ -1,44 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.upstream; - -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; - -import java.util.List; - -// TODO @芋艿:要写清楚,是来自设备网关,还是设备。 -/** - * IoT 设备【拓扑】添加 Request DTO - */ -@Data -public class IotDeviceTopologyAddReqDTO extends IotDeviceUpstreamAbstractReqDTO { - - // TODO @芋艿:看看要不要优化命名 - /** - * 子设备数组 - */ - @NotEmpty(message = "子设备不能为空") - private List params; - - /** - * 设备信息 - */ - @Data - public static class Device { - - /** - * 产品标识 - */ - @NotEmpty(message = "产品标识不能为空") - private String productKey; - - /** - * 设备名称 - */ - @NotEmpty(message = "设备名称不能为空") - private String deviceName; - - // TODO @芋艿:阿里云还有 sign 签名 - - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceUpstreamAbstractReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceUpstreamAbstractReqDTO.java deleted file mode 100644 index a0c8ce9..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotDeviceUpstreamAbstractReqDTO.java +++ /dev/null @@ -1,45 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.upstream; - -import cn.iocoder.yudao.framework.common.util.json.databind.TimestampLocalDateTimeSerializer; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * IoT 设备上行的抽象 Request DTO - * - * @author 芋道源码 - */ -@Data -public abstract class IotDeviceUpstreamAbstractReqDTO { - - /** - * 请求编号 - */ - private String requestId; - - /** - * 插件实例的进程编号 - */ - private String processId; - - /** - * 产品标识 - */ - @NotEmpty(message = "产品标识不能为空") - private String productKey; - /** - * 设备名称 - */ - @NotEmpty(message = "设备名称不能为空") - private String deviceName; - - /** - * 上报时间 - */ - @JsonSerialize(using = TimestampLocalDateTimeSerializer.class) // 解决 iot plugins 序列化 LocalDateTime 是数组,导致无法解析的问题 - private LocalDateTime reportTime; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotPluginInstanceHeartbeatReqDTO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotPluginInstanceHeartbeatReqDTO.java deleted file mode 100644 index 9125b5f..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/control/upstream/IotPluginInstanceHeartbeatReqDTO.java +++ /dev/null @@ -1,44 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device.dto.control.upstream; - -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -/** - * IoT 插件实例心跳 Request DTO - * - * @author 芋道源码 - */ -@Data -public class IotPluginInstanceHeartbeatReqDTO { - - /** - * 请求编号 - */ - @NotEmpty(message = "请求编号不能为空") - private String processId; - - /** - * 插件包标识符 - */ - @NotEmpty(message = "插件包标识符不能为空") - private String pluginKey; - - /** - * 插件实例所在 IP - */ - @NotEmpty(message = "插件实例所在 IP 不能为空") - private String hostIp; - /** - * 插件实例的进程编号 - */ - @NotNull(message = "插件实例的进程编号不能为空") - private Integer downstreamPort; - - /** - * 是否在线 - */ - @NotNull(message = "是否在线不能为空") - private Boolean online; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/package-info.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/package-info.java deleted file mode 100644 index cb946cd..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * TODO 芋艿:占位 - */ -package cn.iocoder.yudao.module.iot.api.device.dto; \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/package-info.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/package-info.java deleted file mode 100644 index 7da0c66..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * 占位 - * - * TODO 芋艿:后续删除 - */ -package cn.iocoder.yudao.module.iot.api; diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ApiConstants.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ApiConstants.java deleted file mode 100644 index 2c4147b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ApiConstants.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums; - -import cn.iocoder.yudao.framework.common.enums.RpcConstants; - -/** - * API 相关的枚举 - * - * @author 芋道源码 - */ -public class ApiConstants { - - public static final String PREFIX = RpcConstants.RPC_API_PREFIX + "/iot"; - - public static final String VERSION = "1.0.0"; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/DictTypeConstants.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/DictTypeConstants.java deleted file mode 100644 index d8f0cc6..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/DictTypeConstants.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums; - -/** - * IoT 字典类型的枚举类 - * - * @author 芋道源码 - */ -public class DictTypeConstants { - - public static final String PRODUCT_STATUS = "iot_product_status"; - public static final String PRODUCT_DEVICE_TYPE = "iot_product_device_type"; - public static final String NET_TYPE = "iot_net_type"; - public static final String PROTOCOL_TYPE = "iot_protocol_type"; - public static final String DATA_FORMAT = "iot_data_format"; - public static final String VALIDATE_TYPE = "iot_validate_type"; - - public static final String DEVICE_STATE = "iot_device_state"; - - public static final String IOT_DATA_BRIDGE_DIRECTION_ENUM = "iot_data_bridge_direction_enum"; - public static final String IOT_DATA_BRIDGE_TYPE_ENUM = "iot_data_bridge_type_enum"; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java deleted file mode 100644 index 230baca..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java +++ /dev/null @@ -1,75 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums; - -import cn.iocoder.yudao.framework.common.exception.ErrorCode; - -/** - * iot 错误码枚举类 - *

- * iot 系统,使用 1-050-000-000 段 - */ -public interface ErrorCodeConstants { - - // ========== 产品相关 1-050-001-000 ============ - 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_THING_MODEL = new ErrorCode(1_050_001_003, "产品状是发布状态,不允许操作物模型"); - - // ========== 产品物模型 1-050-002-000 ============ - 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, "设备不存在"); - ErrorCode DEVICE_NAME_EXISTS = new ErrorCode(1_050_003_001, "设备名称在同一产品下必须唯一"); - ErrorCode DEVICE_HAS_CHILDREN = new ErrorCode(1_050_003_002, "有子设备,不允许删除"); - ErrorCode DEVICE_KEY_EXISTS = new ErrorCode(1_050_003_003, "设备标识已经存在"); - ErrorCode DEVICE_GATEWAY_NOT_EXISTS = new ErrorCode(1_050_003_004, "网关设备不存在"); - ErrorCode DEVICE_NOT_GATEWAY = new ErrorCode(1_050_003_005, "设备不是网关设备"); - ErrorCode DEVICE_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_050_003_006, "导入设备数据不能为空!"); - ErrorCode DEVICE_DOWNSTREAM_FAILED = new ErrorCode(1_050_003_007, "执行失败,原因:{}"); - - // ========== 产品分类 1-050-004-000 ========== - ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_050_004_000, "产品分类不存在"); - - // ========== 设备分组 1-050-005-000 ========== - ErrorCode DEVICE_GROUP_NOT_EXISTS = new ErrorCode(1_050_005_000, "设备分组不存在"); - ErrorCode DEVICE_GROUP_DELETE_FAIL_DEVICE_EXISTS = new ErrorCode(1_050_005_001, "设备分组下存在设备,不允许删除"); - - // ========== 插件配置 1-050-006-000 ========== - ErrorCode PLUGIN_CONFIG_NOT_EXISTS = new ErrorCode(1_050_006_000, "插件配置不存在"); - ErrorCode PLUGIN_INSTALL_FAILED = new ErrorCode(1_050_006_001, "插件安装失败"); - ErrorCode PLUGIN_INSTALL_FAILED_FILE_NAME_NOT_MATCH = new ErrorCode(1_050_006_002, "插件安装失败,文件名与原插件id不匹配"); - ErrorCode PLUGIN_CONFIG_DELETE_FAILED_RUNNING = new ErrorCode(1_050_006_003, "请先停止插件"); - ErrorCode PLUGIN_STATUS_INVALID = new ErrorCode(1_050_006_004, "插件状态无效"); - ErrorCode PLUGIN_CONFIG_KEY_DUPLICATE = new ErrorCode(1_050_006_005, "插件标识已存在"); - ErrorCode PLUGIN_START_FAILED = new ErrorCode(1_050_006_006, "插件启动失败"); - ErrorCode PLUGIN_STOP_FAILED = new ErrorCode(1_050_006_007, "插件停止失败"); - - // ========== 插件实例 1-050-007-000 ========== - - // ========== 固件相关 1-050-008-000 ========== - - ErrorCode OTA_FIRMWARE_NOT_EXISTS = new ErrorCode(1_050_008_000, "固件信息不存在"); - ErrorCode OTA_FIRMWARE_PRODUCT_VERSION_DUPLICATE = new ErrorCode(1_050_008_001, "产品版本号重复"); - - ErrorCode OTA_UPGRADE_TASK_NOT_EXISTS = new ErrorCode(1_050_008_100, "升级任务不存在"); - ErrorCode OTA_UPGRADE_TASK_NAME_DUPLICATE = new ErrorCode(1_050_008_101, "升级任务名称重复"); - ErrorCode OTA_UPGRADE_TASK_DEVICE_IDS_EMPTY = new ErrorCode(1_050_008_102, "设备编号列表不能为空"); - ErrorCode OTA_UPGRADE_TASK_DEVICE_LIST_EMPTY = new ErrorCode(1_050_008_103, "设备列表不能为空"); - ErrorCode OTA_UPGRADE_TASK_CANNOT_CANCEL = new ErrorCode(1_050_008_104, "升级任务不能取消"); - - ErrorCode OTA_UPGRADE_RECORD_NOT_EXISTS = new ErrorCode(1_050_008_200, "升级记录不存在"); - ErrorCode OTA_UPGRADE_RECORD_DUPLICATE = new ErrorCode(1_050_008_201, "升级记录重复"); - ErrorCode OTA_UPGRADE_RECORD_CANNOT_RETRY = new ErrorCode(1_050_008_202, "升级记录不能重试"); - - // ========== MQTT 通信相关 1-050-009-000 ========== - ErrorCode MQTT_TOPIC_ILLEGAL = new ErrorCode(1_050_009_000, "topic illegal"); - - // ========== IoT 数据桥梁 1-050-010-000 ========== - ErrorCode DATA_BRIDGE_NOT_EXISTS = new ErrorCode(1_050_010_000, "IoT 数据桥梁不存在"); - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/device/IotDeviceMessageIdentifierEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/device/IotDeviceMessageIdentifierEnum.java deleted file mode 100644 index 6de9359..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/device/IotDeviceMessageIdentifierEnum.java +++ /dev/null @@ -1,44 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.device; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -// TODO @芋艿:需要添加对应的 DTO,以及上下行的链路,网关、网关服务、设备等 -/** - * IoT 设备消息标识符枚举 - */ -@Getter -@RequiredArgsConstructor -public enum IotDeviceMessageIdentifierEnum { - - PROPERTY_GET("get"), // 下行 TODO 芋艿:【讨论】貌似这个“上行”更合理?device 主动拉取配置。和 IotDevicePropertyGetReqDTO 一样的配置 - PROPERTY_SET("set"), // 下行 - PROPERTY_REPORT("report"), // 上行 - - STATE_ONLINE("online"), // 上行 - STATE_OFFLINE("offline"), // 上行 - - CONFIG_GET("get"), // 上行 TODO 芋艿:【讨论】暂时没有上行的场景 - CONFIG_SET("set"), // 下行 - - SERVICE_INVOKE("${identifier}"), // 下行 - SERVICE_REPLY_SUFFIX("_reply"), // 芋艿:TODO 芋艿:【讨论】上行 or 下行 - - OTA_UPGRADE("upgrade"), // 下行 - OTA_PULL("pull"), // 上行 - OTA_PROGRESS("progress"), // 上行 - OTA_REPORT("report"), // 上行 - - REGISTER_REGISTER("register"), // 上行 - REGISTER_REGISTER_SUB("register_sub"), // 上行 - REGISTER_UNREGISTER_SUB("unregister_sub"), // 下行 - - TOPOLOGY_ADD("topology_add"), // 下行; - ; - - /** - * 标志符 - */ - private final String identifier; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/device/IotDeviceMessageTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/device/IotDeviceMessageTypeEnum.java deleted file mode 100644 index 0354157..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/device/IotDeviceMessageTypeEnum.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.device; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; - -/** - * IoT 设备消息类型枚举 - */ -@Getter -@RequiredArgsConstructor -public enum IotDeviceMessageTypeEnum implements ArrayValuable { - - STATE("state"), // 设备状态 - PROPERTY("property"), // 设备属性:可参考 https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services 设备属性、事件、服务 - EVENT("event"), // 设备事件:可参考 https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services 设备属性、事件、服务 - SERVICE("service"), // 设备服务:可参考 https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services 设备属性、事件、服务 - CONFIG("config"), // 设备配置:可参考 https://help.aliyun.com/zh/iot/user-guide/remote-configuration-1 远程配置 - OTA("ota"), // 设备 OTA:可参考 https://help.aliyun.com/zh/iot/user-guide/ota-update OTA 升级 - REGISTER("register"), // 设备注册:可参考 https://help.aliyun.com/zh/iot/user-guide/register-devices 设备身份注册 - TOPOLOGY("topology"),; // 设备拓扑:可参考 https://help.aliyun.com/zh/iot/user-guide/manage-topological-relationships 设备拓扑 - - public static final String[] ARRAYS = Arrays.stream(values()).map(IotDeviceMessageTypeEnum::getType).toArray(String[]::new); - - /** - * 属性 - */ - private final String type; - - @Override - public String[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/device/IotDeviceStateEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/device/IotDeviceStateEnum.java deleted file mode 100644 index 6ce2677..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/device/IotDeviceStateEnum.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.device; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; - -/** - * IoT 设备状态枚举 - * - * @author haohao - */ -@RequiredArgsConstructor -@Getter -public enum IotDeviceStateEnum implements ArrayValuable { - - INACTIVE(0, "未激活"), - ONLINE(1, "在线"), - OFFLINE(2, "离线"); - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotDeviceStateEnum::getState).toArray(Integer[]::new); - - /** - * 状态 - */ - private final Integer state; - /** - * 状态名 - */ - private final String name; - - @Override - public Integer[] array() { - return ARRAYS; - } - - public static boolean isOnline(Integer state) { - return ONLINE.getState().equals(state); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ota/IotOtaUpgradeRecordStatusEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ota/IotOtaUpgradeRecordStatusEnum.java deleted file mode 100644 index e809a7e..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ota/IotOtaUpgradeRecordStatusEnum.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.ota; - - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; - -/** - * IoT OTA 升级记录的范围枚举 - * - * @author haohao - */ -@RequiredArgsConstructor -@Getter -public enum IotOtaUpgradeRecordStatusEnum implements ArrayValuable { - - PENDING(0), // 待推送 - PUSHED(10), // 已推送 - UPGRADING(20), // 升级中 - SUCCESS(30), // 升级成功 - FAILURE(40), // 升级失败 - CANCELED(50),; // 已取消 - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotOtaUpgradeRecordStatusEnum::getStatus).toArray(Integer[]::new); - - /** - * 范围 - */ - private final Integer status; - - @Override - public Integer[] array() { - return ARRAYS; - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ota/IotOtaUpgradeTaskScopeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ota/IotOtaUpgradeTaskScopeEnum.java deleted file mode 100644 index 6dccbb0..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ota/IotOtaUpgradeTaskScopeEnum.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.ota; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; - -/** - * IoT OTA 升级任务的范围枚举 - * - * @author haohao - */ -@RequiredArgsConstructor -@Getter -public enum IotOtaUpgradeTaskScopeEnum implements ArrayValuable { - - ALL(1), // 全部设备:只包括当前产品下的设备,不包括未来创建的设备 - SELECT(2); // 指定设备 - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotOtaUpgradeTaskScopeEnum::getScope).toArray(Integer[]::new); - - /** - * 范围 - */ - private final Integer scope; - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ota/IotOtaUpgradeTaskStatusEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ota/IotOtaUpgradeTaskStatusEnum.java deleted file mode 100644 index 78af16c..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ota/IotOtaUpgradeTaskStatusEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.ota; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; - -/** - * IoT OTA 升级任务的范围枚举 - * - * @author haohao - */ -@RequiredArgsConstructor -@Getter -public enum IotOtaUpgradeTaskStatusEnum implements ArrayValuable { - - IN_PROGRESS(10), // 进行中:升级中 - COMPLETED(20), // 已完成:已结束,全部升级完成 - INCOMPLETE(21), // 未完成:已结束,部分升级完成 - CANCELED(30),; // 已取消:一般是主动取消任务 - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotOtaUpgradeTaskStatusEnum::getStatus).toArray(Integer[]::new); - - /** - * 范围 - */ - private final Integer status; - - @Override - public Integer[] array() { - return ARRAYS; - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginDeployTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginDeployTypeEnum.java deleted file mode 100644 index b6ef4f0..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginDeployTypeEnum.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.plugin; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; - -/** - * IoT 部署方式枚举 - * - * @author haohao - */ -@RequiredArgsConstructor -@Getter -public enum IotPluginDeployTypeEnum implements ArrayValuable { - - JAR(0, "JAR 部署"), - STANDALONE(1, "独立部署"); - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotPluginDeployTypeEnum::getDeployType).toArray(Integer[]::new); - - /** - * 部署方式 - */ - private final Integer deployType; - /** - * 部署方式名 - */ - private final String name; - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginStatusEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginStatusEnum.java deleted file mode 100644 index 7e3fa65..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginStatusEnum.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.plugin; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; - -/** - * IoT 插件状态枚举 - * - * @author haohao - */ -@RequiredArgsConstructor -@Getter -public enum IotPluginStatusEnum implements ArrayValuable { - - STOPPED(0, "停止"), - RUNNING(1, "运行"); - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotPluginStatusEnum::getStatus).toArray(Integer[]::new); - - /** - * 状态 - */ - private final Integer status; - /** - * 状态名 - */ - private final String name; - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginTypeEnum.java deleted file mode 100644 index ec0b72f..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/plugin/IotPluginTypeEnum.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.plugin; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * IoT 插件类型枚举 - * - * @author haohao - */ -@AllArgsConstructor -@Getter -public enum IotPluginTypeEnum implements ArrayValuable { - - NORMAL(0, "普通插件"), - DEVICE(1, "设备插件"); - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotPluginTypeEnum::getType).toArray(Integer[]::new); - - /** - * 类型 - */ - private final Integer type; - /** - * 类型名 - */ - private final String name; - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotDataFormatEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotDataFormatEnum.java deleted file mode 100644 index 0cfe1c9..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotDataFormatEnum.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.product; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * 产品数据格式枚举类 - * - * @author ahh - * @see 阿里云 - 什么是消息解析 - */ -@AllArgsConstructor -@Getter -public enum IotDataFormatEnum implements ArrayValuable { - - JSON(0, "标准数据格式(JSON)"), - CUSTOMIZE(1, "透传/自定义"); - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotDataFormatEnum::getType).toArray(Integer[]::new); - - /** - * 类型 - */ - private final Integer type; - /** - * 描述 - */ - private final String description; - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotNetTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotNetTypeEnum.java deleted file mode 100644 index 2a54e48..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotNetTypeEnum.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.product; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * IoT 联网方式枚举类 - * - * @author ahh - */ -@AllArgsConstructor -@Getter -public enum IotNetTypeEnum implements ArrayValuable { - - WIFI(0, "Wi-Fi"), - CELLULAR(1, "Cellular"), - ETHERNET(2, "Ethernet"), - OTHER(3, "其他"); - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotNetTypeEnum::getType).toArray(Integer[]::new); - - /** - * 类型 - */ - private final Integer type; - /** - * 描述 - */ - private final String description; - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductDeviceTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductDeviceTypeEnum.java deleted file mode 100644 index 7910f1b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductDeviceTypeEnum.java +++ /dev/null @@ -1,59 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.product; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * IoT 产品的设备类型 - * - * @author ahh - */ -@AllArgsConstructor -@Getter -public enum IotProductDeviceTypeEnum implements ArrayValuable { - - DIRECT(0, "直连设备"), - GATEWAY_SUB(1, "网关子设备"), - GATEWAY(2, "网关设备"); - - /** - * 类型 - */ - private final Integer type; - - /** - * 描述 - */ - private final String description; - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotProductDeviceTypeEnum::getType).toArray(Integer[]::new); - - @Override - public Integer[] array() { - return ARRAYS; - } - - /** - * 判断是否是网关 - * - * @param type 类型 - * @return 是否是网关 - */ - public static boolean isGateway(Integer type) { - return GATEWAY.getType().equals(type); - } - - /** - * 判断是否是网关子设备 - * - * @param type 类型 - * @return 是否是网关子设备 - */ - public static boolean isGatewaySub(Integer type) { - return GATEWAY_SUB.getType().equals(type); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductStatusEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductStatusEnum.java deleted file mode 100644 index b9bbbee..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductStatusEnum.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.product; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * IoT 产品的状态枚举类 - * - * @author ahh - */ -@AllArgsConstructor -@Getter -public enum IotProductStatusEnum implements ArrayValuable { - - UNPUBLISHED(0, "开发中"), - PUBLISHED(1, "已发布"); - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotProductStatusEnum::getStatus).toArray(Integer[]::new); - - /** - * 类型 - */ - private final Integer status; - /** - * 描述 - */ - private final String description; - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProtocolTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProtocolTypeEnum.java deleted file mode 100644 index d24dea9..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProtocolTypeEnum.java +++ /dev/null @@ -1,40 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.product; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * IoT 接入网关协议枚举类 - * - * @author ahh - */ -@AllArgsConstructor -@Getter -public enum IotProtocolTypeEnum implements ArrayValuable { - - CUSTOM(0, "自定义"), - MODBUS(1, "Modbus"), - OPC_UA(2, "OPC UA"), - ZIGBEE(3, "ZigBee"), - BLE(4, "BLE"); - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotProtocolTypeEnum::getType).toArray(Integer[]::new); - - /** - * 类型 - */ - private final Integer type; - /** - * 描述 - */ - private final String description; - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotValidateTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotValidateTypeEnum.java deleted file mode 100644 index 2a15d16..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotValidateTypeEnum.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.product; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * IoT 数据校验级别枚举类 - * - * @author ahh - */ -@AllArgsConstructor -@Getter -public enum IotValidateTypeEnum implements ArrayValuable { - - WEAK(0, "弱校验"), - NONE(1, "免校验"); - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotValidateTypeEnum::getType).toArray(Integer[]::new); - - /** - * 类型 - */ - private final Integer type; - /** - * 描述 - */ - private final String description; - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotAlertConfigReceiveTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotAlertConfigReceiveTypeEnum.java deleted file mode 100644 index 3fdd532..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotAlertConfigReceiveTypeEnum.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.rule; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; - -/** - * IoT 告警配置的接收方式枚举 - * - * @author 芋道源码 - */ -@RequiredArgsConstructor -@Getter -public enum IotAlertConfigReceiveTypeEnum implements ArrayValuable { - - SMS(1), // 短信 - MAIL(2), // 邮箱 - NOTIFY(3); // 通知 - - private final Integer type; - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotAlertConfigReceiveTypeEnum::getType).toArray(Integer[]::new); - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgeDirectionEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgeDirectionEnum.java deleted file mode 100644 index a9d445f..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgeDirectionEnum.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.rule; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; - -/** - * IoT 数据桥接的方向枚举 - * - * @author 芋道源码 - */ -@RequiredArgsConstructor -@Getter -public enum IotDataBridgeDirectionEnum implements ArrayValuable { - - INPUT(1), // 输入 - OUTPUT(2); // 输出 - - private final Integer type; - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotDataBridgeDirectionEnum::getType).toArray(Integer[]::new); - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgeTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgeTypeEnum.java deleted file mode 100644 index 78fc845..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotDataBridgeTypeEnum.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.rule; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; - -/** - * IoT 数据桥接的类型枚举 - * - * @author 芋道源码 - */ -@RequiredArgsConstructor -@Getter -public enum IotDataBridgeTypeEnum implements ArrayValuable { - - HTTP(1, "HTTP"), - TCP(2, "TCP"), - WEBSOCKET(3, "WEBSOCKET"), - - MQTT(10, "MQTT"), - - DATABASE(20, "DATABASE"), - REDIS_STREAM(21, "REDIS_STREAM"), - - ROCKETMQ(30, "ROCKETMQ"), - RABBITMQ(31, "RABBITMQ"), - KAFKA(32, "KAFKA"); - - private final Integer type; - - private final String name; - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotDataBridgeTypeEnum::getType).toArray(Integer[]::new); - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneActionTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneActionTypeEnum.java deleted file mode 100644 index 2bdf7d0..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneActionTypeEnum.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.rule; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; - -/** - * IoT 规则场景的触发类型枚举 - * - * 设备触发,定时触发 - */ -@RequiredArgsConstructor -@Getter -public enum IotRuleSceneActionTypeEnum implements ArrayValuable { - - DEVICE_CONTROL(1), // 设备执行 - ALERT(2), // 告警执行 - DATA_BRIDGE(3); // 桥接执行 - - private final Integer type; - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotRuleSceneActionTypeEnum::getType).toArray(Integer[]::new); - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneTriggerConditionParameterOperatorEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneTriggerConditionParameterOperatorEnum.java deleted file mode 100644 index 5ed90cc..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneTriggerConditionParameterOperatorEnum.java +++ /dev/null @@ -1,64 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.rule; - -import cn.hutool.core.util.ArrayUtil; -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; - -/** - * IoT 场景触发条件参数的操作符枚举 - * - * @author 芋道源码 - */ -@RequiredArgsConstructor -@Getter -public enum IotRuleSceneTriggerConditionParameterOperatorEnum implements ArrayValuable { - - EQUALS("=", "#source == #value"), - NOT_EQUALS("!=", "!(#source == #value)"), - - GREATER_THAN(">", "#source > #value"), - GREATER_THAN_OR_EQUALS(">=", "#source >= #value"), - - LESS_THAN("<", "#source < #value"), - LESS_THAN_OR_EQUALS("<=", "#source <= #value"), - - IN("in", "#values.contains(#source)"), - NOT_IN("not in", "!(#values.contains(#source))"), - - BETWEEN("between", "(#source >= #values.get(0)) && (#source <= #values.get(1))"), - NOT_BETWEEN("not between", "(#source < #values.get(0)) || (#source > #values.get(1))"), - - LIKE("like", "#source.contains(#value)"), // 字符串匹配 - NOT_NULL("not null", "#source != null && #source.length() > 0"); // 非空 - - private final String operator; - private final String springExpression; - - public static final String[] ARRAYS = Arrays.stream(values()).map(IotRuleSceneTriggerConditionParameterOperatorEnum::getOperator).toArray(String[]::new); - - /** - * Spring 表达式 - 原始值 - */ - public static final String SPRING_EXPRESSION_SOURCE = "source"; - /** - * Spring 表达式 - 目标值 - */ - public static final String SPRING_EXPRESSION_VALUE = "value"; - /** - * Spring 表达式 - 目标值数组 - */ - public static final String SPRING_EXPRESSION_VALUE_List = "values"; - - public static IotRuleSceneTriggerConditionParameterOperatorEnum operatorOf(String operator) { - return ArrayUtil.firstMatch(item -> item.getOperator().equals(operator), values()); - } - - @Override - public String[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneTriggerTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneTriggerTypeEnum.java deleted file mode 100644 index a420a21..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/rule/IotRuleSceneTriggerTypeEnum.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.rule; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.Arrays; - -/** - * IoT 场景流转的触发类型枚举 - * - * @author 芋道源码 - */ -@RequiredArgsConstructor -@Getter -public enum IotRuleSceneTriggerTypeEnum implements ArrayValuable { - - DEVICE(1), // 设备触发 - TIMER(2); // 定时触发 - - private final Integer type; - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotRuleSceneTriggerTypeEnum::getType).toArray(Integer[]::new); - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotDataSpecsDataTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotDataSpecsDataTypeEnum.java deleted file mode 100644 index 5524fde..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotDataSpecsDataTypeEnum.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.thingmodel; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * IoT 数据定义的数据类型枚举类 - * - * @author 芋道源码 - */ -@AllArgsConstructor -@Getter -public enum IotDataSpecsDataTypeEnum implements ArrayValuable { - - INT("int"), - FLOAT("float"), - DOUBLE("double"), - ENUM("enum"), - BOOL("bool"), - TEXT("text"), - DATE("date"), - STRUCT("struct"), - ARRAY("array"); - - public static final String[] ARRAYS = Arrays.stream(values()).map(IotDataSpecsDataTypeEnum::getDataType).toArray(String[]::new); - - private final String dataType; - - @Override - public String[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelAccessModeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelAccessModeEnum.java deleted file mode 100644 index c0a2b32..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelAccessModeEnum.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.thingmodel; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * IoT 产品物模型属性读取类型枚举 - * - * @author ahh - */ -@AllArgsConstructor -@Getter -public enum IotThingModelAccessModeEnum implements ArrayValuable { - - READ_ONLY("r"), - READ_WRITE("rw"); - - public static final String[] ARRAYS = Arrays.stream(values()).map(IotThingModelAccessModeEnum::getMode).toArray(String[]::new); - - private final String mode; - - @Override - public String[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelParamDirectionEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelParamDirectionEnum.java deleted file mode 100644 index 4f06cef..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelParamDirectionEnum.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.thingmodel; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - - -/** - * IoT 产品物模型参数是输入参数还是输出参数枚举 - * - * @author HUIHUI - */ -@AllArgsConstructor -@Getter -public enum IotThingModelParamDirectionEnum implements ArrayValuable { - - INPUT("input"), // 输入参数 - OUTPUT("output"); // 输出参数 - - public static final String[] ARRAYS = Arrays.stream(values()).map(IotThingModelParamDirectionEnum::getDirection).toArray(String[]::new); - - private final String direction; - - @Override - public String[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelServiceCallTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelServiceCallTypeEnum.java deleted file mode 100644 index 376db6b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelServiceCallTypeEnum.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.thingmodel; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * IoT 产品物模型服务调用方式枚举 - * - * @author HUIHUI - */ -@AllArgsConstructor -@Getter -public enum IotThingModelServiceCallTypeEnum implements ArrayValuable { - - ASYNC("async"), // 异步调用 - SYNC("sync"); // 同步调用 - - public static final String[] ARRAYS = Arrays.stream(values()).map(IotThingModelServiceCallTypeEnum::getType).toArray(String[]::new); - - private final String type; - - @Override - public String[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelServiceEventTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelServiceEventTypeEnum.java deleted file mode 100644 index c7c7409..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelServiceEventTypeEnum.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.thingmodel; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * IoT 产品物模型事件类型枚举 - * - * @author HUIHUI - */ -@AllArgsConstructor -@Getter -public enum IotThingModelServiceEventTypeEnum implements ArrayValuable { - - INFO("info"), // 信息 - ALERT("alert"), // 告警 - ERROR("error"); // 故障 - - public static final String[] ARRAYS = Arrays.stream(values()).map(IotThingModelServiceEventTypeEnum::getType).toArray(String[]::new); - - private final String type; - - @Override - public String[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelTypeEnum.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelTypeEnum.java deleted file mode 100644 index e0097cf..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/thingmodel/IotThingModelTypeEnum.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.yudao.module.iot.enums.thingmodel; - -import cn.iocoder.yudao.framework.common.core.ArrayValuable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Arrays; - -/** - * IoT 产品功能(物模型)类型枚举类 - * - * @author ahh - */ -@AllArgsConstructor -@Getter -public enum IotThingModelTypeEnum implements ArrayValuable { - - PROPERTY(1, "属性"), - SERVICE(2, "服务"), - EVENT(3, "事件"); - - public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotThingModelTypeEnum::getType).toArray(Integer[]::new); - - /** - * 类型 - */ - private final Integer type; - /** - * 描述 - */ - private final String description; - - @Override - public Integer[] array() { - return ARRAYS; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/pom.xml b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/pom.xml deleted file mode 100644 index a97e951..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/pom.xml +++ /dev/null @@ -1,137 +0,0 @@ - - - - yudao-module-iot - cn.iocoder.boot - ${revision} - - 4.0.0 - jar - - yudao-module-iot-biz - - ${project.artifactId} - - 物联网 模块,主要实现 产品管理、设备管理、协议管理等功能。 - - - - - - cn.iocoder.boot - yudao-module-system - ${revision} - - - cn.iocoder.boot - yudao-module-iot-api - ${revision} - - - - cn.iocoder.boot - yudao-spring-boot-starter-biz-tenant - - - - - cn.iocoder.boot - yudao-spring-boot-starter-web - - - - cn.iocoder.boot - yudao-spring-boot-starter-security - - - - - com.taosdata.jdbc - taos-jdbcdriver - - - - cn.iocoder.boot - yudao-spring-boot-starter-mybatis - - - - cn.iocoder.boot - yudao-spring-boot-starter-redis - - - - - cn.iocoder.boot - yudao-spring-boot-starter-test - - - - - cn.iocoder.boot - yudao-spring-boot-starter-excel - - - - - org.apache.rocketmq - rocketmq-spring-boot-starter - true - - - org.springframework.kafka - spring-kafka - true - - - org.springframework.boot - spring-boot-starter-amqp - true - - - - org.pf4j - pf4j-spring - - - - - org.apache.groovy - groovy-all - 4.0.25 - pom - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/ScriptTest.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/ScriptTest.java deleted file mode 100644 index 9f54d60..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/ScriptTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package cn.iocoder.yudao.module.iot; - -import cn.hutool.script.ScriptUtil; -import javax.script.Bindings; -import javax.script.ScriptEngine; -import javax.script.ScriptException; - -/** - * TODO 芋艿:测试脚本的接入 - */ -public class ScriptTest { - - public static void main2(String[] args) { - // 创建一个 Groovy 脚本引擎 - ScriptEngine engine = ScriptUtil.createGroovyEngine(); - - // 创建绑定参数 - Bindings bindings = engine.createBindings(); - bindings.put("name", "Alice"); - bindings.put("age", 30); - - // 定义一个稍微复杂的 Groovy 脚本 - String script = "def greeting = 'Hello, ' + name + '!';\n" + - "def ageInFiveYears = age + 5;\n" + - "def message = greeting + ' In five years, you will be ' + ageInFiveYears + ' years old.';\n" + - "return message.toUpperCase();\n"; - - try { - // 执行脚本并获取结果 - Object result = engine.eval(script, bindings); - System.out.println(result); // 输出: HELLO, ALICE! IN FIVE YEARS, YOU WILL BE 35 YEARS OLD. - } catch (ScriptException e) { - e.printStackTrace(); - } - } - - public static void main(String[] args) { - // 创建一个 JavaScript 脚本引擎 - ScriptEngine jsEngine = ScriptUtil.createJsEngine(); - - // 创建绑定参数 - Bindings jsBindings = jsEngine.createBindings(); - jsBindings.put("name", "Bob"); - jsBindings.put("age", 25); - - // 定义一个简单的 JavaScript 脚本 - String jsScript = "var greeting = 'Hello, ' + name + '!';\n" + - "var ageInTenYears = age + 10;\n" + - "var message = greeting + ' In ten years, you will be ' + ageInTenYears + ' years old.';\n" + - "message.toUpperCase();\n"; - - try { - // 执行脚本并获取结果 - Object jsResult = jsEngine.eval(jsScript, jsBindings); - System.out.println(jsResult); // 输出: HELLO, BOB! IN TEN YEARS, YOU WILL BE 35 YEARS OLD. - } catch (ScriptException e) { - e.printStackTrace(); - } - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/api/device/IoTDeviceUpstreamApiImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/api/device/IoTDeviceUpstreamApiImpl.java deleted file mode 100644 index 25faa1a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/api/device/IoTDeviceUpstreamApiImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -package cn.iocoder.yudao.module.iot.api.device; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.*; -import cn.iocoder.yudao.module.iot.service.device.control.IotDeviceUpstreamService; -import cn.iocoder.yudao.module.iot.service.plugin.IotPluginInstanceService; -import jakarta.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RestController; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -/** - * * 设备数据 Upstream 上行 API 实现类 - */ -@RestController -@Validated -public class IoTDeviceUpstreamApiImpl implements IotDeviceUpstreamApi { - - @Resource - private IotDeviceUpstreamService deviceUpstreamService; - @Resource - private IotPluginInstanceService pluginInstanceService; - - // ========== 设备相关 ========== - - @Override - public CommonResult updateDeviceState(IotDeviceStateUpdateReqDTO updateReqDTO) { - deviceUpstreamService.updateDeviceState(updateReqDTO); - return success(true); - } - - @Override - public CommonResult reportDeviceProperty(IotDevicePropertyReportReqDTO reportReqDTO) { - deviceUpstreamService.reportDeviceProperty(reportReqDTO); - return success(true); - } - - @Override - public CommonResult reportDeviceEvent(IotDeviceEventReportReqDTO reportReqDTO) { - deviceUpstreamService.reportDeviceEvent(reportReqDTO); - return success(true); - } - - @Override - public CommonResult registerDevice(IotDeviceRegisterReqDTO registerReqDTO) { - deviceUpstreamService.registerDevice(registerReqDTO); - return success(true); - } - - @Override - public CommonResult registerSubDevice(IotDeviceRegisterSubReqDTO registerReqDTO) { - deviceUpstreamService.registerSubDevice(registerReqDTO); - return success(true); - } - - @Override - public CommonResult addDeviceTopology(IotDeviceTopologyAddReqDTO addReqDTO) { - deviceUpstreamService.addDeviceTopology(addReqDTO); - return success(true); - } - - @Override - public CommonResult authenticateEmqxConnection(IotDeviceEmqxAuthReqDTO authReqDTO) { - boolean result = deviceUpstreamService.authenticateEmqxConnection(authReqDTO); - return success(result); - } - - // ========== 插件相关 ========== - - @Override - public CommonResult heartbeatPluginInstance(IotPluginInstanceHeartbeatReqDTO heartbeatReqDTO) { - pluginInstanceService.heartbeatPluginInstance(heartbeatReqDTO); - return success(true); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/api/package-info.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/api/package-info.java deleted file mode 100644 index 0785218..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/api/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * 占位 - * - * TODO 芋艿:后续删除 - */ -package cn.iocoder.yudao.module.iot.api; \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.http b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.http deleted file mode 100644 index c1190ce..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.http +++ /dev/null @@ -1,75 +0,0 @@ -### 请求 /iot/device/downstream 接口(服务调用) => 成功 -POST {{baseUrl}}/iot/device/downstream -Content-Type: application/json -tenant-id: {{adminTenentId}} -Authorization: Bearer {{token}} - -{ - "id": 25, - "type": "service", - "identifier": "temperature", - "data": { - "xx": "yy" - } -} - -### 请求 /iot/device/downstream 接口(属性设置) => 成功 -POST {{baseUrl}}/iot/device/downstream -Content-Type: application/json -tenant-id: {{adminTenentId}} -Authorization: Bearer {{token}} - -{ - "id": 25, - "type": "property", - "identifier": "set", - "data": { - "xx": "yy" - } -} - -### 请求 /iot/device/downstream 接口(属性获取) => 成功 -POST {{baseUrl}}/iot/device/downstream -Content-Type: application/json -tenant-id: {{adminTenentId}} -Authorization: Bearer {{token}} - -{ - "id": 25, - "type": "property", - "identifier": "get", - "data": ["xx", "yy"] -} - -### 请求 /iot/device/downstream 接口(配置设置) => 成功 -POST {{baseUrl}}/iot/device/downstream -Content-Type: application/json -tenant-id: {{adminTenentId}} -Authorization: Bearer {{token}} - -{ - "id": 25, - "type": "config", - "identifier": "set" -} - -### 请求 /iot/device/downstream 接口(OTA 升级) => 成功 -POST {{baseUrl}}/iot/device/downstream -Content-Type: application/json -tenant-id: {{adminTenentId}} -Authorization: Bearer {{token}} - -{ - "id": 25, - "type": "ota", - "identifier": "upgrade", - "data": { - "firmwareId": 1, - "version": "1.0.0", - "signMethod": "MD5", - "fileSign": "d41d8cd98f00b204e9800998ecf8427e", - "fileSize": 1024, - "fileUrl": "http://example.com/firmware.bin", - "information": "{\"desc\":\"升级到最新版本\"}" - } -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java deleted file mode 100644 index 08fc244..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java +++ /dev/null @@ -1,188 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device; - -import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.control.IotDeviceDownstreamReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.control.IotDeviceUpstreamReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.*; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -import cn.iocoder.yudao.module.iot.service.device.control.IotDeviceDownstreamService; -import cn.iocoder.yudao.module.iot.service.device.control.IotDeviceUpstreamService; -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.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; - -@Tag(name = "管理后台 - IoT 设备") -@RestController -@RequestMapping("/iot/device") -@Validated -public class IotDeviceController { - - @Resource - private IotDeviceService deviceService; - @Resource - private IotDeviceUpstreamService deviceUpstreamService; - @Resource - private IotDeviceDownstreamService deviceDownstreamService; - - @PostMapping("/create") - @Operation(summary = "创建设备") - @PreAuthorize("@ss.hasPermission('iot:device:create')") - public CommonResult createDevice(@Valid @RequestBody IotDeviceSaveReqVO createReqVO) { - return success(deviceService.createDevice(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新设备") - @PreAuthorize("@ss.hasPermission('iot:device:update')") - public CommonResult updateDevice(@Valid @RequestBody IotDeviceSaveReqVO updateReqVO) { - deviceService.updateDevice(updateReqVO); - return success(true); - } - - // TODO @芋艿:参考阿里云:1)绑定网关;2)解绑网关 - - @PutMapping("/update-group") - @Operation(summary = "更新设备分组") - @PreAuthorize("@ss.hasPermission('iot:device:update')") - public CommonResult updateDeviceGroup(@Valid @RequestBody IotDeviceUpdateGroupReqVO updateReqVO) { - deviceService.updateDeviceGroup(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除单个设备") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('iot:device:delete')") - public CommonResult deleteDevice(@RequestParam("id") Long id) { - deviceService.deleteDevice(id); - return success(true); - } - - @DeleteMapping("/delete-list") - @Operation(summary = "删除多个设备") - @Parameter(name = "ids", description = "编号数组", required = true) - @PreAuthorize("@ss.hasPermission('iot:device:delete')") - public CommonResult deleteDeviceList(@RequestParam("ids") Collection ids) { - deviceService.deleteDeviceList(ids); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得设备") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('iot:device:query')") - public CommonResult getDevice(@RequestParam("id") Long id) { - IotDeviceDO device = deviceService.getDevice(id); - return success(BeanUtils.toBean(device, IotDeviceRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得设备分页") - @PreAuthorize("@ss.hasPermission('iot:device:query')") - public CommonResult> getDevicePage(@Valid IotDevicePageReqVO pageReqVO) { - PageResult pageResult = deviceService.getDevicePage(pageReqVO); - return success(BeanUtils.toBean(pageResult, IotDeviceRespVO.class)); - } - - @GetMapping("/export-excel") - @Operation(summary = "导出设备 Excel") - @PreAuthorize("@ss.hasPermission('iot:device:export')") - @ApiAccessLog(operateType = EXPORT) - public void exportDeviceExcel(@Valid IotDevicePageReqVO exportReqVO, - HttpServletResponse response) throws IOException { - exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - CommonResult> result = getDevicePage(exportReqVO); - // 导出 Excel - ExcelUtils.write(response, "设备.xls", "数据", IotDeviceRespVO.class, - result.getData().getList()); - } - - @GetMapping("/count") - @Operation(summary = "获得设备数量") - @Parameter(name = "productId", description = "产品编号", example = "1") - @PreAuthorize("@ss.hasPermission('iot:device:query')") - public CommonResult getDeviceCount(@RequestParam("productId") Long productId) { - return success(deviceService.getDeviceCountByProductId(productId)); - } - - @GetMapping("/simple-list") - @Operation(summary = "获取设备的精简信息列表", description = "主要用于前端的下拉选项") - @Parameter(name = "deviceType", description = "设备类型", example = "1") - public CommonResult> getSimpleDeviceList( - @RequestParam(value = "deviceType", required = false) Integer deviceType) { - List list = deviceService.getDeviceListByDeviceType(deviceType); - return success(convertList(list, device -> // 只返回 id、name 字段 - new IotDeviceRespVO().setId(device.getId()).setDeviceName(device.getDeviceName()))); - } - - @PostMapping("/import") - @Operation(summary = "导入设备") - @PreAuthorize("@ss.hasPermission('iot:device:import')") - public CommonResult importDevice( - @RequestParam("file") MultipartFile file, - @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) - throws Exception { - List list = ExcelUtils.read(file, IotDeviceImportExcelVO.class); - return success(deviceService.importDevice(list, updateSupport)); - } - - @GetMapping("/get-import-template") - @Operation(summary = "获得导入设备模板") - public void importTemplate(HttpServletResponse response) throws IOException { - // 手动创建导出 demo - List list = Arrays.asList( - IotDeviceImportExcelVO.builder().deviceName("温度传感器001").parentDeviceName("gateway110") - .productKey("1de24640dfe").groupNames("灰度分组,生产分组").build(), - IotDeviceImportExcelVO.builder().deviceName("biubiu") - .productKey("YzvHxd4r67sT4s2B").groupNames("").build()); - // 输出 - ExcelUtils.write(response, "设备导入模板.xls", "数据", IotDeviceImportExcelVO.class, list); - } - - @PostMapping("/upstream") - @Operation(summary = "设备上行", description = "可用于设备模拟") - @PreAuthorize("@ss.hasPermission('iot:device:upstream')") - public CommonResult upstreamDevice(@Valid @RequestBody IotDeviceUpstreamReqVO upstreamReqVO) { - deviceUpstreamService.upstreamDevice(upstreamReqVO); - return success(true); - } - - @PostMapping("/downstream") - @Operation(summary = "设备下行", description = "可用于设备模拟") - @PreAuthorize("@ss.hasPermission('iot:device:downstream')") - public CommonResult downstreamDevice(@Valid @RequestBody IotDeviceDownstreamReqVO downstreamReqVO) { - deviceDownstreamService.downstreamDevice(downstreamReqVO); - return success(true); - } - - // TODO @haohao:是不是默认详情接口,不返回 secret,然后这个接口,用于统一返回。然后接口名可以更通用一点。 - @GetMapping("/mqtt-connection-params") - @Operation(summary = "获取 MQTT 连接参数") - @PreAuthorize("@ss.hasPermission('iot:device:mqtt-connection-params')") - public CommonResult getMqttConnectionParams(@RequestParam("deviceId") Long deviceId) { - return success(deviceService.getMqttConnectionParams(deviceId)); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceGroupController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceGroupController.java deleted file mode 100644 index d19cf7f..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceGroupController.java +++ /dev/null @@ -1,88 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device; - -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -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.device.vo.group.IotDeviceGroupPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.group.IotDeviceGroupRespVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.group.IotDeviceGroupSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceGroupDO; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceGroupService; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -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; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; - -@Tag(name = "管理后台 - IoT 设备分组") -@RestController -@RequestMapping("/iot/device-group") -@Validated -public class IotDeviceGroupController { - - @Resource - private IotDeviceGroupService deviceGroupService; - @Resource - private IotDeviceService deviceService; - - @PostMapping("/create") - @Operation(summary = "创建设备分组") - @PreAuthorize("@ss.hasPermission('iot:device-group:create')") - public CommonResult createDeviceGroup(@Valid @RequestBody IotDeviceGroupSaveReqVO createReqVO) { - return success(deviceGroupService.createDeviceGroup(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新设备分组") - @PreAuthorize("@ss.hasPermission('iot:device-group:update')") - public CommonResult updateDeviceGroup(@Valid @RequestBody IotDeviceGroupSaveReqVO updateReqVO) { - deviceGroupService.updateDeviceGroup(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除设备分组") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('iot:device-group:delete')") - public CommonResult deleteDeviceGroup(@RequestParam("id") Long id) { - deviceGroupService.deleteDeviceGroup(id); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得设备分组") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('iot:device-group:query')") - public CommonResult getDeviceGroup(@RequestParam("id") Long id) { - IotDeviceGroupDO deviceGroup = deviceGroupService.getDeviceGroup(id); - return success(BeanUtils.toBean(deviceGroup, IotDeviceGroupRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得设备分组分页") - @PreAuthorize("@ss.hasPermission('iot:device-group:query')") - public CommonResult> getDeviceGroupPage(@Valid IotDeviceGroupPageReqVO pageReqVO) { - PageResult pageResult = deviceGroupService.getDeviceGroupPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, IotDeviceGroupRespVO.class, - group -> group.setDeviceCount(deviceService.getDeviceCountByGroupId(group.getId())))); - } - - @GetMapping("/simple-list") - @Operation(summary = "获取设备分组的精简信息列表", description = "只包含被开启的分组,主要用于前端的下拉选项") - public CommonResult> getSimpleDeviceGroupList() { - List list = deviceGroupService.getDeviceGroupListByStatus(CommonStatusEnum.ENABLE.getStatus()); - return success(convertList(list, group -> // 只返回 id、name 字段 - new IotDeviceGroupRespVO().setId(group.getId()).setName(group.getName()))); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceLogController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceLogController.java deleted file mode 100644 index 81d1bff..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceLogController.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device; - -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.device.vo.data.IotDeviceLogPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogRespVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; -import cn.iocoder.yudao.module.iot.service.device.data.IotDeviceLogService; -import io.swagger.v3.oas.annotations.Operation; -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.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - IoT 设备日志") -@RestController -@RequestMapping("/iot/device/log") -@Validated -public class IotDeviceLogController { - - @Resource - private IotDeviceLogService deviceLogService; - - @GetMapping("/page") - @Operation(summary = "获得设备日志分页") - @PreAuthorize("@ss.hasPermission('iot:device:log-query')") - public CommonResult> getDeviceLogPage(@Valid IotDeviceLogPageReqVO pageReqVO) { - PageResult pageResult = deviceLogService.getDeviceLogPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, IotDeviceLogRespVO.class)); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDevicePropertyController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDevicePropertyController.java deleted file mode 100644 index 47bf325..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDevicePropertyController.java +++ /dev/null @@ -1,95 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.date.LocalDateTimeUtil; -import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -import cn.iocoder.yudao.module.iot.service.device.data.IotDevicePropertyService; -import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Parameters; -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.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; - -@Tag(name = "管理后台 - IoT 设备属性") -@RestController -@RequestMapping("/iot/device/property") -@Validated -public class IotDevicePropertyController { - - @Resource - private IotDevicePropertyService devicePropertyService; - @Resource - private IotThingModelService thingModelService; - @Resource - private IotDeviceService deviceService; - - @GetMapping("/latest") - @Operation(summary = "获取设备属性最新属性") - @Parameters({ - @Parameter(name = "deviceId", description = "设备编号", required = true), - @Parameter(name = "identifier", description = "标识符"), - @Parameter(name = "name", description = "名称") - }) - @PreAuthorize("@ss.hasPermission('iot:device:property-query')") - public CommonResult> getLatestDeviceProperties( - @RequestParam("deviceId") Long deviceId, - @RequestParam(value = "identifier", required = false) String identifier, - @RequestParam(value = "name", required = false) String name) { - Map properties = devicePropertyService.getLatestDeviceProperties(deviceId); - - // 拼接数据 - IotDeviceDO device = deviceService.getDevice(deviceId); - Assert.notNull(device, "设备不存在"); - List thingModels = thingModelService.getThingModelListByProductId(device.getProductId()); - return success(convertList(properties.entrySet(), entry -> { - IotThingModelDO thingModel = CollUtil.findOne(thingModels, - item -> item.getIdentifier().equals(entry.getKey())); - if (thingModel == null || thingModel.getProperty() == null) { - return null; - } - if (StrUtil.isNotEmpty(identifier) && !StrUtil.contains(thingModel.getIdentifier(), identifier)) { - return null; - } - if (StrUtil.isNotEmpty(name) && !StrUtil.contains(thingModel.getName(), name)) { - return null; - } - // 构建对象 - IotDevicePropertyDO property = entry.getValue(); - return new IotDevicePropertyRespVO().setProperty(thingModel.getProperty()) - .setValue(property.getValue()).setUpdateTime(LocalDateTimeUtil.toEpochMilli(property.getUpdateTime())); - })); - } - - @GetMapping("/history-page") - @Operation(summary = "获取设备属性历史数据") - @PreAuthorize("@ss.hasPermission('iot:device:property-query')") - public CommonResult> getHistoryDevicePropertyPage( - @Valid IotDevicePropertyHistoryPageReqVO pageReqVO) { - Assert.notEmpty(pageReqVO.getIdentifier(), "标识符不能为空"); - return success(devicePropertyService.getHistoryDevicePropertyPage(pageReqVO)); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/control/IotDeviceDownstreamReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/control/IotDeviceDownstreamReqVO.java deleted file mode 100644 index eefaeff..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/control/IotDeviceDownstreamReqVO.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.control; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; -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 IotDeviceDownstreamReqVO { - - @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") - @NotNull(message = "设备编号不能为空") - private Long id; - - @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "property") - @NotEmpty(message = "消息类型不能为空") - @InEnum(IotDeviceMessageTypeEnum.class) - private String type; - - @Schema(description = "标识符", requiredMode = Schema.RequiredMode.REQUIRED, example = "report") - @NotEmpty(message = "标识符不能为空") - private String identifier; // 参见 IotDeviceMessageIdentifierEnum 枚举类 - - @Schema(description = "请求参数", requiredMode = Schema.RequiredMode.REQUIRED) - private Object data; // 例如说:服务调用的 params、属性设置的 properties - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/control/IotDeviceUpstreamReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/control/IotDeviceUpstreamReqVO.java deleted file mode 100644 index 778d75b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/control/IotDeviceUpstreamReqVO.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.control; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; -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 IotDeviceUpstreamReqVO { - - @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") - @NotNull(message = "设备编号不能为空") - private Long id; - - @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "property") - @NotEmpty(message = "消息类型不能为空") - @InEnum(IotDeviceMessageTypeEnum.class) - private String type; - - @Schema(description = "标识符", requiredMode = Schema.RequiredMode.REQUIRED, example = "report") - @NotEmpty(message = "标识符不能为空") - private String identifier; // 参见 IotDeviceMessageIdentifierEnum 枚举类 - - @Schema(description = "请求参数", requiredMode = Schema.RequiredMode.REQUIRED) - private Object data; // 例如说:属性上报的 properties、事件上报的 params - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDeviceLogPageReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDeviceLogPageReqVO.java deleted file mode 100644 index fcf3699..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDeviceLogPageReqVO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; - -@Schema(description = "管理后台 - IoT 设备日志分页查询 Request VO") -@Data -public class IotDeviceLogPageReqVO extends PageParam { - - @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "device123") - @NotEmpty(message = "设备标识不能为空") - private String deviceKey; - - @Schema(description = "消息类型", example = "property") - private String type; // 参见 IotDeviceMessageTypeEnum 枚举,精准匹配 - - @Schema(description = "标识符", example = "temperature") - private String identifier; // 参见 IotDeviceMessageIdentifierEnum 枚举,模糊匹配 - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDeviceLogRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDeviceLogRespVO.java deleted file mode 100644 index 6e6639e..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDeviceLogRespVO.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - IoT 设备日志 Response VO") -@Data -public class IotDeviceLogRespVO { - - @Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private String id; - - @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "product123") - private String productKey; - - @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "device123") - private String deviceKey; - - @Schema(description = "消息类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "property") - private String type; - - @Schema(description = "标识符", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature") - private String identifier; - - @Schema(description = "日志内容", requiredMode = Schema.RequiredMode.REQUIRED) - private String content; - - @Schema(description = "上报时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime reportTime; - - @Schema(description = "记录时间戳", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime ts; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDevicePropertyHistoryPageReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDevicePropertyHistoryPageReqVO.java deleted file mode 100644 index 0de45e4..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDevicePropertyHistoryPageReqVO.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - IoT 设备属性历史分页 Request VO") -@Data -public class IotDevicePropertyHistoryPageReqVO extends PageParam { - - @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") - @NotNull(message = "设备编号不能为空") - private Long deviceId; - - @Schema(description = "设备 Key", hidden = true) - private String deviceKey; // 非前端传递,后端自己查询设置 - - @Schema(description = "属性标识符", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "属性标识符不能为空") - private String identifier; - - @Schema(description = "时间范围", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Size(min = 2, max = 2, message = "请选择时间范围") - private LocalDateTime[] times; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDevicePropertyRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDevicePropertyRespVO.java deleted file mode 100644 index dd7a0d6..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/data/IotDevicePropertyRespVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.data; - -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Schema(description = "管理后台 - IoT 设备属性 Response VO") -@Data -public class IotDevicePropertyRespVO { - - @Schema(description = "属性定义", requiredMode = Schema.RequiredMode.REQUIRED) - private ThingModelProperty property; - - @Schema(description = "最新值", requiredMode = Schema.RequiredMode.REQUIRED) - private Object value; - - @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) - private Long updateTime; // 由于从 TDengine 查询出来的是 Long 类型,所以这里也使用 Long 类型 - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceImportExcelVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceImportExcelVO.java deleted file mode 100644 index 710e742..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceImportExcelVO.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; - -import com.alibaba.excel.annotation.ExcelProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; - -/** - * 设备 Excel 导入 VO - */ -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -@Accessors(chain = false) // 设置 chain = false,避免设备导入有问题 -public class IotDeviceImportExcelVO { - - @ExcelProperty("设备名称") - @NotEmpty(message = "设备名称不能为空") - private String deviceName; - - @ExcelProperty("父设备名称") - @Schema(description = "父设备名称", example = "网关001") - private String parentDeviceName; - - @ExcelProperty("产品标识") - @NotEmpty(message = "产品标识不能为空") - private String productKey; - - @ExcelProperty("设备分组") - private String groupNames; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceImportRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceImportRespVO.java deleted file mode 100644 index bf52b12..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceImportRespVO.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; -import lombok.Data; - -import java.util.List; -import java.util.Map; - -@Schema(description = "管理后台 - IoT 设备导入 Response VO") -@Data -@Builder -public class IotDeviceImportRespVO { - - @Schema(description = "创建成功的设备名称数组", requiredMode = Schema.RequiredMode.REQUIRED) - private List createDeviceNames; - - @Schema(description = "更新成功的设备名称数组", requiredMode = Schema.RequiredMode.REQUIRED) - private List updateDeviceNames; - - @Schema(description = "导入失败的设备集合,key为设备名称,value为失败原因", requiredMode = Schema.RequiredMode.REQUIRED) - private Map failureDeviceNames; -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceMqttConnectionParamsRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceMqttConnectionParamsRespVO.java deleted file mode 100644 index 5ce68c0..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceMqttConnectionParamsRespVO.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; - -import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; -import com.alibaba.excel.annotation.ExcelProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Schema(description = "管理后台 - IoT 设备 MQTT 连接参数 Response VO") -@Data -@ExcelIgnoreUnannotated -public class IotDeviceMqttConnectionParamsRespVO { - - @Schema(description = "MQTT 客户端 ID", example = "24602") - @ExcelProperty("MQTT 客户端 ID") - private String mqttClientId; - - @Schema(description = "MQTT 用户名", example = "芋艿") - @ExcelProperty("MQTT 用户名") - private String mqttUsername; - - @Schema(description = "MQTT 密码") - @ExcelProperty("MQTT 密码") - private String mqttPassword; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDevicePageReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDevicePageReqVO.java deleted file mode 100644 index 6862677..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDevicePageReqVO.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStateEnum; -import cn.iocoder.yudao.module.iot.enums.product.IotProductDeviceTypeEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Schema(description = "管理后台 - IoT 设备分页 Request VO") -@Data -public class IotDevicePageReqVO extends PageParam { - - @Schema(description = "设备名称", example = "王五") - private String deviceName; - - @Schema(description = "备注名称", example = "张三") - private String nickname; - - @Schema(description = "产品编号", example = "26202") - private Long productId; - - @Schema(description = "设备类型", example = "1") - @InEnum(IotProductDeviceTypeEnum.class) - private Integer deviceType; - - @Schema(description = "设备状态", example = "1") - @InEnum(IotDeviceStateEnum.class) - private Integer status; - - @Schema(description = "设备分组编号", example = "1024") - private Long groupId; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceRespVO.java deleted file mode 100644 index 8404ca9..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceRespVO.java +++ /dev/null @@ -1,93 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -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; -import java.util.Set; - -import static cn.iocoder.yudao.module.iot.enums.DictTypeConstants.DEVICE_STATE; - -@Schema(description = "管理后台 - IoT 设备 Response VO") -@Data -@ExcelIgnoreUnannotated -public class IotDeviceRespVO { - - @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "177") - private Long id; - - @Schema(description = "设备唯一标识符", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("设备唯一标识符") - private String deviceKey; - - @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") - @ExcelProperty("设备名称") - private String deviceName; - - @Schema(description = "设备备注名称", example = "张三") - @ExcelProperty("设备备注名称") - private String nickname; - - @Schema(description = "设备序列号", example = "1024") - @ExcelProperty("设备序列号") - private String serialNumber; - - @Schema(description = "设备图片", example = "我是一名码农") - @ExcelProperty("设备图片") - private String picUrl; - - @Schema(description = "设备分组编号数组", example = "1,2") - private Set groupIds; - - @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "26202") - @ExcelProperty("产品编号") - private Long productId; - - @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("产品 Key") - private String productKey; - - @Schema(description = "设备类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @ExcelProperty("设备类型") - private Integer deviceType; - - @Schema(description = "网关设备 ID", example = "16380") - private Long gatewayId; - - @Schema(description = "设备状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @ExcelProperty(value = "设备状态", converter = DictConvert.class) - @DictFormat(DEVICE_STATE) - private Integer state; - - @Schema(description = "最后上线时间") - @ExcelProperty("最后上线时间") - private LocalDateTime onlineTime; - - @Schema(description = "最后离线时间") - @ExcelProperty("最后离线时间") - private LocalDateTime offlineTime; - - @Schema(description = "设备激活时间") - @ExcelProperty("设备激活时间") - private LocalDateTime activeTime; - - @Schema(description = "设备密钥,用于设备认证") - @ExcelProperty("设备密钥") - private String deviceSecret; - - @Schema(description = "认证类型(如一机一密、动态注册)", example = "2") - @ExcelProperty("认证类型(如一机一密、动态注册)") - private String authType; - - @Schema(description = "设备配置", example = "{\"abc\": \"efg\"}") - private String config; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceSaveReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceSaveReqVO.java deleted file mode 100644 index b9ea9b9..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceSaveReqVO.java +++ /dev/null @@ -1,44 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.Size; -import lombok.Data; - -import java.util.Set; - -@Schema(description = "管理后台 - IoT 设备新增/修改 Request VO") -@Data -public class IotDeviceSaveReqVO { - - @Schema(description = "设备编号", example = "177") - private Long id; - - @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.AUTO, example = "177") - @Size(max = 50, message = "设备编号长度不能超过 50 个字符") - private String deviceKey; - - @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.AUTO, example = "王五") - private String deviceName; - - @Schema(description = "备注名称", example = "张三") - private String nickname; - - @Schema(description = "设备序列号", example = "123456") - private String serialNumber; - - @Schema(description = "设备图片", example = "https://iocoder.cn/1.png") - private String picUrl; - - @Schema(description = "设备分组编号数组", example = "1,2") - private Set groupIds; - - @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "26202") - private Long productId; - - @Schema(description = "网关设备 ID", example = "16380") - private Long gatewayId; - - @Schema(description = "设备配置", example = "{\"abc\": \"efg\"}") - private String config; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceUpdateGroupReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceUpdateGroupReqVO.java deleted file mode 100644 index bf66fbf..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceUpdateGroupReqVO.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; - -import java.util.Set; - -@Schema(description = "管理后台 - IoT 设备更新分组 Request VO") -@Data -public class IotDeviceUpdateGroupReqVO { - - @Schema(description = "设备编号列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3") - @NotEmpty(message = "设备编号列表不能为空") - private Set ids; - - @Schema(description = "分组编号列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3") - @NotEmpty(message = "分组编号列表不能为空") - private Set groupIds; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/group/IotDeviceGroupPageReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/group/IotDeviceGroupPageReqVO.java deleted file mode 100644 index 93b1a1e..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/group/IotDeviceGroupPageReqVO.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.group; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - IoT 设备分组分页 Request VO") -@Data -public class IotDeviceGroupPageReqVO extends PageParam { - - @Schema(description = "分组名字", example = "李四") - private String name; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/group/IotDeviceGroupRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/group/IotDeviceGroupRespVO.java deleted file mode 100644 index 4fd5415..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/group/IotDeviceGroupRespVO.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.group; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - IoT 设备分组 Response VO") -@Data -public class IotDeviceGroupRespVO { - - @Schema(description = "分组 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "3583") - private Long id; - - @Schema(description = "分组名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") - private String name; - - @Schema(description = "分组状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer status; - - @Schema(description = "分组描述", example = "你说的对") - private String description; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime createTime; - - @Schema(description = "设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Long deviceCount; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/group/IotDeviceGroupSaveReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/group/IotDeviceGroupSaveReqVO.java deleted file mode 100644 index 491cd93..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/group/IotDeviceGroupSaveReqVO.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.device.vo.group; - -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 IotDeviceGroupSaveReqVO { - - @Schema(description = "分组 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "3583") - private Long id; - - @Schema(description = "分组名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") - @NotEmpty(message = "分组名字不能为空") - private String name; - - @Schema(description = "分组状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "分组状态不能为空") - private Integer status; - - @Schema(description = "分组描述", example = "你说的对") - private String description; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaFirmwareController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaFirmwareController.java deleted file mode 100644 index 6cc3918..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaFirmwareController.java +++ /dev/null @@ -1,62 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.ota; - -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.ota.vo.firmware.IotOtaFirmwarePageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwareRespVO; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwareCreateReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwareUpdateReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; -import cn.iocoder.yudao.module.iot.service.ota.IotOtaFirmwareService; -import io.swagger.v3.oas.annotations.Operation; -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 static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - IoT OTA 固件") -@RestController -@RequestMapping("/iot/ota-firmware") -@Validated -public class IotOtaFirmwareController { - - @Resource - private IotOtaFirmwareService otaFirmwareService; - - @PostMapping("/create") - @Operation(summary = "创建 OTA 固件") - @PreAuthorize("@ss.hasPermission('iot:ota-firmware:create')") - public CommonResult createOtaFirmware(@Valid @RequestBody IotOtaFirmwareCreateReqVO createReqVO) { - return success(otaFirmwareService.createOtaFirmware(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新 OTA 固件") - @PreAuthorize("@ss.hasPermission('iot:ota-firmware:update')") - public CommonResult updateOtaFirmware(@Valid @RequestBody IotOtaFirmwareUpdateReqVO updateReqVO) { - otaFirmwareService.updateOtaFirmware(updateReqVO); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得 OTA 固件") - @PreAuthorize("@ss.hasPermission('iot:ota-firmware:query')") - public CommonResult getOtaFirmware(@RequestParam("id") Long id) { - IotOtaFirmwareDO otaFirmware = otaFirmwareService.getOtaFirmware(id); - return success(BeanUtils.toBean(otaFirmware, IotOtaFirmwareRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得 OTA 固件分页") - @PreAuthorize("@ss.hasPermission('iot:ota-firmware:query')") - public CommonResult> getOtaFirmwarePage(@Valid IotOtaFirmwarePageReqVO pageReqVO) { - PageResult pageResult = otaFirmwareService.getOtaFirmwarePage(pageReqVO); - return success(BeanUtils.toBean(pageResult, IotOtaFirmwareRespVO.class)); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaUpgradeRecordController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaUpgradeRecordController.java deleted file mode 100644 index f6bc526..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaUpgradeRecordController.java +++ /dev/null @@ -1,75 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.ota; - -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.ota.vo.upgrade.record.IotOtaUpgradeRecordPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.upgrade.record.IotOtaUpgradeRecordRespVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaUpgradeRecordDO; -import cn.iocoder.yudao.module.iot.service.ota.IotOtaUpgradeRecordService; -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.Map; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - IoT OTA 升级记录") -@RestController -@RequestMapping("/iot/ota-upgrade-record") -@Validated -public class IotOtaUpgradeRecordController { - - @Resource - private IotOtaUpgradeRecordService upgradeRecordService; - - @GetMapping("/get-statistics") - @Operation(summary = "固件升级设备统计") - @PreAuthorize("@ss.hasPermission('iot:ota-upgrade-record:query')") - @Parameter(name = "firmwareId", description = "固件编号", required = true, example = "1024") - public CommonResult> getOtaUpgradeRecordStatistics(@RequestParam(value = "firmwareId") Long firmwareId) { - return success(upgradeRecordService.getOtaUpgradeRecordStatistics(firmwareId)); - } - - @GetMapping("/get-count") - @Operation(summary = "获得升级记录分页 tab 数量") - @PreAuthorize("@ss.hasPermission('iot:ota-upgrade-record:query')") - public CommonResult> getOtaUpgradeRecordCount( - @Valid IotOtaUpgradeRecordPageReqVO pageReqVO) { - return success(upgradeRecordService.getOtaUpgradeRecordCount(pageReqVO)); - } - - @GetMapping("/page") - @Operation(summary = "获得升级记录分页") - @PreAuthorize("@ss.hasPermission('iot:ota-upgrade-record:query')") - public CommonResult> getUpgradeRecordPage( - @Valid IotOtaUpgradeRecordPageReqVO pageReqVO) { - PageResult pageResult = upgradeRecordService.getUpgradeRecordPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, IotOtaUpgradeRecordRespVO.class)); - } - - @GetMapping("/get") - @Operation(summary = "获得升级记录") - @PreAuthorize("@ss.hasPermission('iot:ota-upgrade-record:query')") - @Parameter(name = "id", description = "升级记录编号", required = true, example = "1024") - public CommonResult getUpgradeRecord(@RequestParam("id") Long id) { - IotOtaUpgradeRecordDO upgradeRecord = upgradeRecordService.getUpgradeRecord(id); - return success(BeanUtils.toBean(upgradeRecord, IotOtaUpgradeRecordRespVO.class)); - } - - @PutMapping("/retry") - @Operation(summary = "重试升级记录") - @PreAuthorize("@ss.hasPermission('iot:ota-upgrade-record:retry')") - @Parameter(name = "id", description = "升级记录编号", required = true, example = "1024") - public CommonResult retryUpgradeRecord(@RequestParam("id") Long id) { - upgradeRecordService.retryUpgradeRecord(id); - return success(true); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaUpgradeTaskController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaUpgradeTaskController.java deleted file mode 100644 index e248e80..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaUpgradeTaskController.java +++ /dev/null @@ -1,64 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.ota; - -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.ota.vo.upgrade.task.IotOtaUpgradeTaskPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.upgrade.task.IotOtaUpgradeTaskRespVO; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.upgrade.task.IotOtaUpgradeTaskSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaUpgradeTaskDO; -import cn.iocoder.yudao.module.iot.service.ota.IotOtaUpgradeTaskService; -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 static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - IoT OTA 升级任务") -@RestController -@RequestMapping("/iot/ota-upgrade-task") -@Validated -public class IotOtaUpgradeTaskController { - - @Resource - private IotOtaUpgradeTaskService upgradeTaskService; - - @PostMapping("/create") - @Operation(summary = "创建升级任务") - @PreAuthorize(value = "@ss.hasPermission('iot:ota-upgrade-task:create')") - public CommonResult createUpgradeTask(@Valid @RequestBody IotOtaUpgradeTaskSaveReqVO createReqVO) { - return success(upgradeTaskService.createUpgradeTask(createReqVO)); - } - - @PostMapping("/cancel") - @Operation(summary = "取消升级任务") - @Parameter(name = "id", description = "升级任务编号", required = true) - @PreAuthorize(value = "@ss.hasPermission('iot:ota-upgrade-task:cancel')") - public CommonResult cancelUpgradeTask(@RequestParam("id") Long id) { - upgradeTaskService.cancelUpgradeTask(id); - return success(true); - } - - @GetMapping("/page") - @Operation(summary = "获得升级任务分页") - @PreAuthorize(value = "@ss.hasPermission('iot:ota-upgrade-task:query')") - public CommonResult> getUpgradeTaskPage(@Valid IotOtaUpgradeTaskPageReqVO pageReqVO) { - PageResult pageResult = upgradeTaskService.getUpgradeTaskPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, IotOtaUpgradeTaskRespVO.class)); - } - - @GetMapping("/get") - @Operation(summary = "获得升级任务") - @Parameter(name = "id", description = "升级任务编号", required = true, example = "1024") - @PreAuthorize(value = "@ss.hasPermission('iot:ota-upgrade-task:query')") - public CommonResult getUpgradeTask(@RequestParam("id") Long id) { - IotOtaUpgradeTaskDO upgradeTask = upgradeTaskService.getUpgradeTask(id); - return success(BeanUtils.toBean(upgradeTask, IotOtaUpgradeTaskRespVO.class)); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwareCreateReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwareCreateReqVO.java deleted file mode 100644 index 3d8299c..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwareCreateReqVO.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -@Schema(description = "管理后台 - IoT OTA 固件创建 Request VO") -@Data -public class IotOtaFirmwareCreateReqVO { - - @Schema(description = "固件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "智能开关固件") - @NotEmpty(message = "固件名称不能为空") - private String name; - - @Schema(description = "固件描述", example = "某品牌型号固件,测试用") - private String description; - - @Schema(description = "版本号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1.0.0") - @NotEmpty(message = "版本号不能为空") - private String version; - - @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "产品编号不能为空") - private String productId; - - @Schema(description = "签名方式", example = "MD5") - // TODO @li:是不是必传哈 - private String signMethod; - - @Schema(description = "固件文件 URL", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/yudao-firmware.zip") - @NotEmpty(message = "固件文件 URL 不能为空") - private String fileUrl; - - @Schema(description = "自定义信息,建议使用 JSON 格式", example = "{\"key1\":\"value1\",\"key2\":\"value2\"}") - private String information; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwarePageReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwarePageReqVO.java deleted file mode 100644 index baa7410..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwarePageReqVO.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Data -@Schema(description = "管理后台 - IoT OTA 固件分页 Request VO") -public class IotOtaFirmwarePageReqVO extends PageParam { - - /** - * 固件名称 - */ - @Schema(description = "固件名称", example = "智能开关固件") - private String name; - - /** - * 产品标识 - */ - @Schema(description = "产品标识", example = "1024") - private String productId; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwareRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwareRespVO.java deleted file mode 100644 index 1bcc359..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwareRespVO.java +++ /dev/null @@ -1,83 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware; - -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import com.fhs.core.trans.anno.Trans; -import com.fhs.core.trans.constant.TransType; -import com.fhs.core.trans.vo.VO; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Data -@Schema(description = "管理后台 - IoT OTA 固件 Response VO") -public class IotOtaFirmwareRespVO implements VO { - - /** - * 固件编号 - */ - @Schema(description = "固件编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long id; - /** - * 固件名称 - */ - @Schema(description = "固件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "OTA固件") - private String name; - /** - * 固件描述 - */ - @Schema(description = "固件描述") - private String description; - /** - * 版本号 - */ - @Schema(description = "版本号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1.0.0") - private String version; - - /** - * 产品编号 - *

- * 关联 {@link cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO#getId()} - */ - @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @Trans(type = TransType.SIMPLE, target = IotProductDO.class, fields = {"name"}, refs = {"productName"}) - private String productId; - /** - * 产品标识 - *

- * 冗余 {@link cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO#getProductKey()} - */ - @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "iot-product-key") - private String productKey; - /** - * 产品名称 - */ - @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "OTA产品") - private String productName; - /** - * 签名方式 - *

- * 例如说:MD5、SHA256 - */ - @Schema(description = "签名方式", example = "MD5") - private String signMethod; - /** - * 固件文件签名 - */ - @Schema(description = "固件文件签名", example = "1024") - private String fileSign; - /** - * 固件文件大小 - */ - @Schema(description = "固件文件大小", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long fileSize; - /** - * 固件文件 URL - */ - @Schema(description = "固件文件 URL", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn") - private String fileUrl; - /** - * 自定义信息,建议使用 JSON 格式 - */ - @Schema(description = "自定义信息,建议使用 JSON 格式") - private String information; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwareUpdateReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwareUpdateReqVO.java deleted file mode 100644 index 2a594b2..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwareUpdateReqVO.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -@Schema(description = "管理后台 - IoT OTA 固件更新 Request VO") -@Data -public class IotOtaFirmwareUpdateReqVO { - - @Schema(description = "固件编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "固件编号不能为空") - private Long id; - - // TODO @li:name 是不是可以飞必传哈 - @Schema(description = "固件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "智能开关固件") - @NotEmpty(message = "固件名称不能为空") - private String name; - - @Schema(description = "固件描述", example = "某品牌型号固件,测试用") - private String description; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/record/IotOtaUpgradeRecordPageReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/record/IotOtaUpgradeRecordPageReqVO.java deleted file mode 100644 index cf74cbb..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/record/IotOtaUpgradeRecordPageReqVO.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.ota.vo.upgrade.record; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -@Data -@Schema(description = "管理后台 - IoT OTA 升级记录分页 Request VO") -public class IotOtaUpgradeRecordPageReqVO extends PageParam { - - // TODO @li:已经有注解,不用重复注释 - /** - * 升级任务编号字段。 - *

- * 该字段用于标识升级任务的唯一编号,不能为空。 - */ - @Schema(description = "升级任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "升级任务编号不能为空") - private Long taskId; - - /** - * 设备标识字段。 - *

- * 该字段用于标识设备的名称,通常用于区分不同的设备。 - */ - @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "摄像头A1-1") - private String deviceName; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/record/IotOtaUpgradeRecordRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/record/IotOtaUpgradeRecordRespVO.java deleted file mode 100644 index d770374..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/record/IotOtaUpgradeRecordRespVO.java +++ /dev/null @@ -1,107 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.ota.vo.upgrade.record; - -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaUpgradeTaskDO; -import com.fhs.core.trans.anno.Trans; -import com.fhs.core.trans.constant.TransType; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Data -@Schema(description = "管理后台 - IoT OTA 升级记录 Response VO") -public class IotOtaUpgradeRecordRespVO { - - /** - * 升级记录编号 - */ - @Schema(description = "升级记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long id; - /** - * 固件编号 - *

- * 关联 {@link IotOtaFirmwareDO#getId()} - */ - @Schema(description = "固件编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @Trans(type = TransType.SIMPLE, target = IotOtaFirmwareDO.class, fields = {"version"}, refs = {"firmwareVersion"}) - private Long firmwareId; - /** - * 固件版本 - */ - @Schema(description = "固件版本", requiredMode = Schema.RequiredMode.REQUIRED, example = "v1.0.0") - private String firmwareVersion; - /** - * 任务编号 - *

- * 关联 {@link IotOtaUpgradeTaskDO#getId()} - */ - @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long taskId; - /** - * 产品标识 - *

- * 关联 {@link cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO#getId()} - */ - @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "iot") - private String productKey; - /** - * 设备名称 - *

- * 关联 {@link cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO#getId()} - */ - @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "iot") - private String deviceName; - /** - * 设备编号 - *

- * 关联 {@link cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO#getId()} - */ - @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private String deviceId; - /** - * 来源的固件编号 - *

- * 关联 {@link IotDeviceDO#getFirmwareId()} - */ - @Schema(description = "来源的固件编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @Trans(type = TransType.SIMPLE, target = IotOtaFirmwareDO.class, fields = {"version"}, refs = {"fromFirmwareVersion"}) - private Long fromFirmwareId; - /** - * 来源的固件版本 - */ - @Schema(description = "来源的固件版本", requiredMode = Schema.RequiredMode.REQUIRED, example = "v1.0.0") - private String fromFirmwareVersion; - /** - * 升级状态 - *

- * 关联 {@link cn.iocoder.yudao.module.iot.enums.ota.IotOtaUpgradeRecordStatusEnum} - */ - @Schema(description = "升级状态", requiredMode = Schema.RequiredMode.REQUIRED, allowableValues = {"0", "10", "20", "30", "40", "50"}) - private Integer status; - /** - * 升级进度,百分比 - */ - @Schema(description = "升级进度,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Integer progress; - /** - * 升级进度描述 - *

- * 注意,只记录设备最后一次的升级进度描述 - * 如果想看历史记录,可以查看 {@link cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO} 设备日志 - */ - @Schema(description = "升级进度描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private String description; - /** - * 升级开始时间 - */ - @Schema(description = "升级开始时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2022-07-08 07:30:00") - private LocalDateTime startTime; - /** - * 升级结束时间 - */ - @Schema(description = "升级结束时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2022-07-08 07:30:00") - private LocalDateTime endTime; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/task/IotOtaUpgradeTaskPageReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/task/IotOtaUpgradeTaskPageReqVO.java deleted file mode 100644 index 8abdd59..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/task/IotOtaUpgradeTaskPageReqVO.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.ota.vo.upgrade.task; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -@Data -@Schema(description = "管理后台 - IoT OTA 升级任务分页 Request VO") -public class IotOtaUpgradeTaskPageReqVO extends PageParam { - - /** - * 任务名称字段,用于描述任务的名称 - */ - @Schema(description = "任务名称", example = "升级任务") - private String name; - - /** - * 固件编号字段,用于唯一标识固件,不能为空 - */ - @NotNull(message = "固件编号不能为空") - @Schema(description = "固件编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long firmwareId; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/task/IotOtaUpgradeTaskRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/task/IotOtaUpgradeTaskRespVO.java deleted file mode 100644 index 6a32522..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/task/IotOtaUpgradeTaskRespVO.java +++ /dev/null @@ -1,82 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.ota.vo.upgrade.task; - -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; -import com.fhs.core.trans.vo.VO; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; -import java.util.List; - -@Data -@Schema(description = "管理后台 - IoT OTA 升级任务 Response VO") -public class IotOtaUpgradeTaskRespVO implements VO { - - /** - * 任务编号 - */ - @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long id; - /** - * 任务名称 - */ - @Schema(description = "任务名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "升级任务") - private String name; - /** - * 任务描述 - */ - @Schema(description = "任务描述", example = "升级任务") - private String description; - /** - * 固件编号 - *

- * 关联 {@link IotOtaFirmwareDO#getId()} - */ - @Schema(description = "固件编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long firmwareId; - /** - * 任务状态 - *

- * 关联 {@link cn.iocoder.yudao.module.iot.enums.ota.IotOtaUpgradeTaskStatusEnum} - */ - @Schema(description = "任务状态", requiredMode = Schema.RequiredMode.REQUIRED, allowableValues = {"10", "20", "21", "30"}) - private Integer status; - /** - * 任务状态名称 - */ - @Schema(description = "任务状态名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "进行中") - private String statusName; - /** - * 升级范围 - *

- * 关联 {@link cn.iocoder.yudao.module.iot.enums.ota.IotOtaUpgradeTaskScopeEnum} - */ - @Schema(description = "升级范围", requiredMode = Schema.RequiredMode.REQUIRED, allowableValues = {"1", "2"}) - private Integer scope; - /** - * 设备数量 - */ - @Schema(description = "设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long deviceCount; - /** - * 选中的设备编号数组 - *

- * 关联 {@link IotDeviceDO#getId()} - */ - @Schema(description = "选中的设备编号数组", example = "1024") - private List deviceIds; - /** - * 选中的设备名字数组 - *

- * 关联 {@link IotDeviceDO#getDeviceName()} - */ - @Schema(description = "选中的设备名字数组", example = "1024") - private List deviceNames; - /** - * 创建时间 - */ - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2022-07-08 07:30:00") - private LocalDateTime createTime; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/task/IotOtaUpgradeTaskSaveReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/task/IotOtaUpgradeTaskSaveReqVO.java deleted file mode 100644 index e8cdbef..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/upgrade/task/IotOtaUpgradeTaskSaveReqVO.java +++ /dev/null @@ -1,61 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.ota.vo.upgrade.task; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; -import cn.iocoder.yudao.module.iot.enums.ota.IotOtaUpgradeTaskScopeEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -import java.util.List; - -@Data -@Schema(description = "管理后台 - IoT OTA 升级任务创建/修改 Request VO") -public class IotOtaUpgradeTaskSaveReqVO { - - // TODO @li:已经有注解,不用重复注释 - // TODO @li: @Schema 写在参数校验前面。先有定义;其他的,也检查下; - - /** - * 任务名称 - */ - @NotEmpty(message = "任务名称不能为空") - @Schema(description = "任务名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "升级任务") - private String name; - - /** - * 任务描述 - */ - @Schema(description = "任务描述", example = "升级任务") - private String description; - - /** - * 固件编号 - *

- * 关联 {@link IotOtaFirmwareDO#getId()} - */ - @NotNull(message = "固件编号不能为空") - @Schema(description = "固件编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long firmwareId; - - /** - * 升级范围 - *

- * 关联 {@link cn.iocoder.yudao.module.iot.enums.ota.IotOtaUpgradeTaskScopeEnum} - */ - @NotNull(message = "升级范围不能为空") - @InEnum(value = IotOtaUpgradeTaskScopeEnum.class) - @Schema(description = "升级范围", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer scope; - - /** - * 选中的设备编号数组 - *

- * 关联 {@link IotDeviceDO#getId()} - */ - @Schema(description = "选中的设备编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1,2,3,4]") - private List deviceIds; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/PluginConfigController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/PluginConfigController.java deleted file mode 100644 index e21b102..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/PluginConfigController.java +++ /dev/null @@ -1,90 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.plugin; - -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.plugin.vo.config.PluginConfigImportReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.config.PluginConfigPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.config.PluginConfigRespVO; -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.config.PluginConfigSaveReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.config.PluginConfigStatusReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginConfigDO; -import cn.iocoder.yudao.module.iot.service.plugin.IotPluginConfigService; -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 static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - IoT 插件配置") -@RestController -@RequestMapping("/iot/plugin-config") -@Validated -public class PluginConfigController { - - @Resource - private IotPluginConfigService pluginConfigService; - - @PostMapping("/create") - @Operation(summary = "创建插件配置") - @PreAuthorize("@ss.hasPermission('iot:plugin-config:create')") - public CommonResult createPluginConfig(@Valid @RequestBody PluginConfigSaveReqVO createReqVO) { - return success(pluginConfigService.createPluginConfig(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新插件配置") - @PreAuthorize("@ss.hasPermission('iot:plugin-config:update')") - public CommonResult updatePluginConfig(@Valid @RequestBody PluginConfigSaveReqVO updateReqVO) { - pluginConfigService.updatePluginConfig(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除插件配置") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('iot:plugin-config:delete')") - public CommonResult deletePluginConfig(@RequestParam("id") Long id) { - pluginConfigService.deletePluginConfig(id); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得插件配置") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('iot:plugin-config:query')") - public CommonResult getPluginConfig(@RequestParam("id") Long id) { - IotPluginConfigDO pluginConfig = pluginConfigService.getPluginConfig(id); - return success(BeanUtils.toBean(pluginConfig, PluginConfigRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得插件配置分页") - @PreAuthorize("@ss.hasPermission('iot:plugin-config:query')") - public CommonResult> getPluginConfigPage(@Valid PluginConfigPageReqVO pageReqVO) { - PageResult pageResult = pluginConfigService.getPluginConfigPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, PluginConfigRespVO.class)); - } - - @PostMapping("/upload-file") - @Operation(summary = "上传插件文件") - @PreAuthorize("@ss.hasPermission('iot:plugin-config:update')") - public CommonResult uploadFile(@Valid PluginConfigImportReqVO reqVO) { - pluginConfigService.uploadFile(reqVO.getId(), reqVO.getFile()); - return success(true); - } - - @PutMapping("/update-status") - @Operation(summary = "修改插件状态") - @PreAuthorize("@ss.hasPermission('iot:plugin-config:update')") - public CommonResult updatePluginConfigStatus(@Valid @RequestBody PluginConfigStatusReqVO reqVO) { - pluginConfigService.updatePluginStatus(reqVO.getId(), reqVO.getStatus()); - return success(true); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigImportReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigImportReqVO.java deleted file mode 100644 index b9b277a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigImportReqVO.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.config; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import lombok.Data; -import org.springframework.web.multipart.MultipartFile; - -@Schema(description = "管理后台 - IoT 插件上传 Request VO") -@Data -public class PluginConfigImportReqVO { - - @Schema(description = "主键 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11546") - private Long id; - - @Schema(description = "插件文件", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "插件文件不能为空") - private MultipartFile file; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigPageReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigPageReqVO.java deleted file mode 100644 index 1666d5d..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigPageReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.config; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Schema(description = "管理后台 - IoT 插件配置分页 Request VO") -@Data -public class PluginConfigPageReqVO extends PageParam { - - @Schema(description = "插件名称", example = "http") - private String name; - - @Schema(description = "状态", example = "1") - @InEnum(IotPluginStatusEnum.class) - private Integer status; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigRespVO.java deleted file mode 100644 index 2b8c4dc..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigRespVO.java +++ /dev/null @@ -1,54 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.config; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - IoT 插件配置 Response VO") -@Data -public class PluginConfigRespVO { - - @Schema(description = "主键 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "11546") - private Long id; - - @Schema(description = "插件包标识符", requiredMode = Schema.RequiredMode.REQUIRED, example = "24627") - private String pluginKey; - - @Schema(description = "插件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") - private String name; - - @Schema(description = "描述", example = "你猜") - private String description; - - @Schema(description = "部署方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") - private Integer deployType; - - @Schema(description = "插件包文件名", requiredMode = Schema.RequiredMode.REQUIRED) - private String fileName; - - @Schema(description = "插件版本", requiredMode = Schema.RequiredMode.REQUIRED) - private String version; - - @Schema(description = "插件类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") - private Integer type; - - @Schema(description = "设备插件协议类型") - private String protocol; - - @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED) - private Integer status; - - @Schema(description = "插件配置项描述信息") - private String configSchema; - - @Schema(description = "插件配置信息") - private String config; - - @Schema(description = "插件脚本") - private String script; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime createTime; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigSaveReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigSaveReqVO.java deleted file mode 100644 index e48869d..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigSaveReqVO.java +++ /dev/null @@ -1,56 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.config; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Schema(description = "管理后台 - IoT 插件配置新增/修改 Request VO") -@Data -public class PluginConfigSaveReqVO { - - // TODO @haohao:新增的字段有点多,每个都需要哇? - - // TODO @haohao:一些枚举字段,需要加枚举校验。例如说,deployType、status、type 等 - - @Schema(description = "主键编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11546") - private Long id; - - @Schema(description = "插件包标识符", requiredMode = Schema.RequiredMode.REQUIRED, example = "24627") - private String pluginKey; - - @Schema(description = "插件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") - private String name; - - @Schema(description = "描述", example = "你猜") - private String description; - - @Schema(description = "部署方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") - private Integer deployType; - - @Schema(description = "插件包文件名", requiredMode = Schema.RequiredMode.REQUIRED) - private String fileName; - - @Schema(description = "插件版本", requiredMode = Schema.RequiredMode.REQUIRED) - private String version; - - @Schema(description = "插件类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") - private Integer type; - - @Schema(description = "设备插件协议类型") - private String protocol; - - @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED) - @InEnum(IotPluginStatusEnum.class) - private Integer status; - - @Schema(description = "插件配置项描述信息") - private String configSchema; - - @Schema(description = "插件配置信息") - private String config; - - @Schema(description = "插件脚本") - private String script; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigStatusReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigStatusReqVO.java deleted file mode 100644 index eae4aa0..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/config/PluginConfigStatusReqVO.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.config; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Schema(description = "管理后台 - IoT 插件配置状态 Request VO") -@Data -public class PluginConfigStatusReqVO { - - @Schema(description = "主键编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11546") - private Long id; - - @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED) - @InEnum(IotPluginStatusEnum.class) - private Integer status; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/instance/PluginInstancePageReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/instance/PluginInstancePageReqVO.java deleted file mode 100644 index e58b888..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/instance/PluginInstancePageReqVO.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.instance; - -import lombok.*; -import io.swagger.v3.oas.annotations.media.Schema; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import org.springframework.format.annotation.DateTimeFormat; -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -// TODO @haohao:后续需要使用下 -@Schema(description = "管理后台 - IoT 插件实例分页 Request VO") -@Data -public class PluginInstancePageReqVO extends PageParam { - - @Schema(description = "插件主程序编号", example = "23738") - private String mainId; - - @Schema(description = "插件id", example = "26498") - private Long pluginId; - - @Schema(description = "插件主程序所在ip") - private String ip; - - @Schema(description = "插件主程序端口") - private Integer port; - - @Schema(description = "心跳时间,心路时间超过30秒需要剔除") - private Long heartbeatAt; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/instance/PluginInstanceRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/instance/PluginInstanceRespVO.java deleted file mode 100644 index cba59fd..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/plugin/vo/instance/PluginInstanceRespVO.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.instance; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -// TODO @haohao:后续需要使用下 -@Schema(description = "管理后台 - IoT 插件实例 Response VO") -@Data -public class PluginInstanceRespVO { - - @Schema(description = "主键编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23864") - private Long id; - - @Schema(description = "插件主程序id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23738") - private String mainId; - - @Schema(description = "插件id", requiredMode = Schema.RequiredMode.REQUIRED, example = "26498") - private Long pluginId; - - @Schema(description = "插件主程序所在ip", requiredMode = Schema.RequiredMode.REQUIRED) - private String ip; - - @Schema(description = "插件主程序端口", requiredMode = Schema.RequiredMode.REQUIRED) - private Integer port; - - @Schema(description = "心跳时间,心路时间超过30秒需要剔除", requiredMode = Schema.RequiredMode.REQUIRED) - private Long heartbeatAt; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime createTime; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductCategoryController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductCategoryController.java deleted file mode 100644 index bc1c1fb..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductCategoryController.java +++ /dev/null @@ -1,86 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.product; - -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -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.product.vo.category.IotProductCategoryPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategoryRespVO; -import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategorySaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; -import cn.iocoder.yudao.module.iot.service.product.IotProductCategoryService; -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; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; - -@Tag(name = "管理后台 - IoT 产品分类") -@RestController -@RequestMapping("/iot/product-category") -@Validated -public class IotProductCategoryController { - - @Resource - private IotProductCategoryService productCategoryService; - - @PostMapping("/create") - @Operation(summary = "创建产品分类") - @PreAuthorize("@ss.hasPermission('iot:product-category:create')") - public CommonResult createProductCategory(@Valid @RequestBody IotProductCategorySaveReqVO createReqVO) { - return success(productCategoryService.createProductCategory(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新产品分类") - @PreAuthorize("@ss.hasPermission('iot:product-category:update')") - public CommonResult updateProductCategory(@Valid @RequestBody IotProductCategorySaveReqVO updateReqVO) { - productCategoryService.updateProductCategory(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除产品分类") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('iot:product-category:delete')") - public CommonResult deleteProductCategory(@RequestParam("id") Long id) { - productCategoryService.deleteProductCategory(id); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得产品分类") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('iot:product-category:query')") - public CommonResult getProductCategory(@RequestParam("id") Long id) { - IotProductCategoryDO productCategory = productCategoryService.getProductCategory(id); - return success(BeanUtils.toBean(productCategory, IotProductCategoryRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得产品分类分页") - @PreAuthorize("@ss.hasPermission('iot:product-category:query')") - public CommonResult> getProductCategoryPage(@Valid IotProductCategoryPageReqVO pageReqVO) { - PageResult pageResult = productCategoryService.getProductCategoryPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, IotProductCategoryRespVO.class)); - } - - @GetMapping("/simple-list") - @Operation(summary = "获得所有产品分类列表") - @PreAuthorize("@ss.hasPermission('iot:product-category:query')") - public CommonResult> getSimpleProductCategoryList() { - List list = productCategoryService.getProductCategoryListByStatus( - CommonStatusEnum.ENABLE.getStatus()); - return success(convertList(list, category -> - new IotProductCategoryRespVO().setId(category.getId()).setName(category.getName()))); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductController.java deleted file mode 100644 index 2d8c856..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductController.java +++ /dev/null @@ -1,132 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.product; - -import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.MapUtils; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductRespVO; -import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.service.product.IotProductCategoryService; -import cn.iocoder.yudao.module.iot.service.product.IotProductService; -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.servlet.http.HttpServletResponse; -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.io.IOException; -import java.util.List; -import java.util.Map; - -import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; - -@Tag(name = "管理后台 - IoT 产品") -@RestController -@RequestMapping("/iot/product") -@Validated -public class IotProductController { - - @Resource - private IotProductService productService; - @Resource - private IotProductCategoryService categoryService; - - @PostMapping("/create") - @Operation(summary = "创建产品") - @PreAuthorize("@ss.hasPermission('iot:product:create')") - public CommonResult createProduct(@Valid @RequestBody IotProductSaveReqVO createReqVO) { - return success(productService.createProduct(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新产品") - @PreAuthorize("@ss.hasPermission('iot:product:update')") - public CommonResult updateProduct(@Valid @RequestBody IotProductSaveReqVO updateReqVO) { - productService.updateProduct(updateReqVO); - return success(true); - } - - @PutMapping("/update-status") - @Operation(summary = "更新产品状态") - @Parameter(name = "id", description = "编号", required = true) - @Parameter(name = "status", description = "状态", required = true) - @PreAuthorize("@ss.hasPermission('iot:product:update')") - public CommonResult updateProductStatus(@RequestParam("id") Long id, - @RequestParam("status") Integer status) { - productService.updateProductStatus(id, status); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除产品") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('iot:product:delete')") - public CommonResult deleteProduct(@RequestParam("id") Long id) { - productService.deleteProduct(id); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得产品") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('iot:product:query')") - public CommonResult getProduct(@RequestParam("id") Long id) { - IotProductDO product = productService.getProduct(id); - // 拼接数据 - IotProductCategoryDO category = categoryService.getProductCategory(product.getCategoryId()); - return success(BeanUtils.toBean(product, IotProductRespVO.class, bean -> { - if (category != null) { - bean.setCategoryName(category.getName()); - } - })); - } - - @GetMapping("/page") - @Operation(summary = "获得产品分页") - @PreAuthorize("@ss.hasPermission('iot:product:query')") - public CommonResult> getProductPage(@Valid IotProductPageReqVO pageReqVO) { - PageResult pageResult = productService.getProductPage(pageReqVO); - // 拼接数据 - Map categoryMap = categoryService.getProductCategoryMap( - convertList(pageResult.getList(), IotProductDO::getCategoryId)); - return success(BeanUtils.toBean(pageResult, IotProductRespVO.class, bean -> { - MapUtils.findAndThen(categoryMap, bean.getCategoryId(), - category -> bean.setCategoryName(category.getName())); - })); - } - - @GetMapping("/export-excel") - @Operation(summary = "导出产品 Excel") - @PreAuthorize("@ss.hasPermission('iot:product:export')") - @ApiAccessLog(operateType = EXPORT) - public void exportProductExcel(@Valid IotProductPageReqVO exportReqVO, - HttpServletResponse response) throws IOException { - exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - CommonResult> result = getProductPage(exportReqVO); - // 导出 Excel - ExcelUtils.write(response, "产品.xls", "数据", IotProductRespVO.class, - result.getData().getList()); - } - - @GetMapping("/simple-list") - @Operation(summary = "获取产品的精简信息列表", description = "主要用于前端的下拉选项") - public CommonResult> getSimpleProductList() { - List list = productService.getProductList(); - return success(convertList(list, product -> // 只返回 id、name 字段 - new IotProductRespVO().setId(product.getId()).setName(product.getName()) - .setDeviceType(product.getDeviceType()))); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/category/IotProductCategoryPageReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/category/IotProductCategoryPageReqVO.java deleted file mode 100644 index f1c12bf..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/category/IotProductCategoryPageReqVO.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.product.vo.category; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - IoT 产品分类分页 Request VO") -@Data -public class IotProductCategoryPageReqVO extends PageParam { - - @Schema(description = "分类名字", example = "王五") - private String name; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/category/IotProductCategoryRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/category/IotProductCategoryRespVO.java deleted file mode 100644 index d684b02..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/category/IotProductCategoryRespVO.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.product.vo.category; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - IoT 产品分类 Response VO") -@Data -public class IotProductCategoryRespVO { - - @Schema(description = "分类 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25284") - private Long id; - - @Schema(description = "分类名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") - private String name; - - @Schema(description = "分类排序") - private Integer sort; - - @Schema(description = "分类状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @DictFormat(DictTypeConstants.COMMON_STATUS) - private Integer status; - - @Schema(description = "分类描述", example = "随便") - private String description; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime createTime; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/category/IotProductCategorySaveReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/category/IotProductCategorySaveReqVO.java deleted file mode 100644 index a7b2fe4..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/category/IotProductCategorySaveReqVO.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.product.vo.category; - -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 IotProductCategorySaveReqVO { - - @Schema(description = "分类 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25284") - private Long id; - - @Schema(description = "分类名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") - @NotEmpty(message = "分类名字不能为空") - private String name; - - @Schema(description = "分类排序") - private Integer sort; - - @Schema(description = "分类状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "分类状态不能为空") - private Integer status; - - @Schema(description = "分类描述", example = "随便") - private String description; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductPageReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductPageReqVO.java deleted file mode 100644 index 18c69c4..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductPageReqVO.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.product.vo.product; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -@Schema(description = "管理后台 - IoT 产品分页 Request VO") -@Data -public class IotProductPageReqVO extends PageParam { - - @Schema(description = "产品名称", example = "李四") - private String name; - - @Schema(description = "产品标识") - private String productKey; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductRespVO.java deleted file mode 100644 index f674651..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductRespVO.java +++ /dev/null @@ -1,87 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.product.vo.product; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.iot.enums.DictTypeConstants; -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 IotProductRespVO { - - @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "26087") - @ExcelProperty("产品编号") - private Long id; - - @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") - @ExcelProperty("产品名称") - private String name; - - @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("产品标识") - private String productKey; - - @Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Long categoryId; - - @Schema(description = "产品分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @ExcelProperty("产品分类") - private String categoryName; - - @Schema(description = "产品图标", example = "https://iocoder.cn/1.svg") - @ExcelProperty("产品图标") - private String icon; - - @Schema(description = "产品图片", example = "https://iocoder.cn/1.png") - @ExcelProperty("产品图片") - private String picUrl; - - @Schema(description = "产品描述", example = "你猜") - @ExcelProperty("产品描述") - private String description; - - @Schema(description = "产品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @ExcelProperty(value = "产品状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.PRODUCT_STATUS) - private Integer status; - - @Schema(description = "设备类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") - @ExcelProperty(value = "设备类型", converter = DictConvert.class) - @DictFormat(DictTypeConstants.PRODUCT_DEVICE_TYPE) - private Integer deviceType; - - @Schema(description = "联网方式", example = "2") - @ExcelProperty(value = "联网方式", converter = DictConvert.class) - @DictFormat(DictTypeConstants.NET_TYPE) - private Integer netType; - - @Schema(description = "接入网关协议", example = "2") - @ExcelProperty(value = "接入网关协议", converter = DictConvert.class) - @DictFormat(DictTypeConstants.PROTOCOL_TYPE) - private Integer protocolType; - - @Schema(description = "协议编号(脚本解析 id)", requiredMode = Schema.RequiredMode.REQUIRED, example = "13177") - @ExcelProperty("协议编号(脚本解析 id)") - private Long protocolId; - - @Schema(description = "数据格式") - @ExcelProperty(value = "数据格式", converter = DictConvert.class) - @DictFormat(DictTypeConstants.DATA_FORMAT) - private Integer dataFormat; - - @Schema(description = "数据校验级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @ExcelProperty(value = "数据校验级别", converter = DictConvert.class) - @DictFormat(DictTypeConstants.VALIDATE_TYPE) - private Integer validateType; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductSaveReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductSaveReqVO.java deleted file mode 100644 index 268ab7c..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/product/IotProductSaveReqVO.java +++ /dev/null @@ -1,60 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.product.vo.product; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.enums.product.*; -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 IotProductSaveReqVO { - - @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.AUTO, example = "1") - private Long id; - - @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "温湿度") - @NotEmpty(message = "产品名称不能为空") - private String name; - - @Schema(description = "产品 Key", requiredMode = Schema.RequiredMode.AUTO, example = "12345abc") - private String productKey; - - @Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "产品分类编号不能为空") - private Long categoryId; - - @Schema(description = "产品图标", example = "https://iocoder.cn/1.svg") - private String icon; - - @Schema(description = "产品图片", example = "https://iocoder.cn/1.png") - private String picUrl; - - @Schema(description = "产品描述", example = "描述") - private String description; - - @Schema(description = "设备类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") - @InEnum(value = IotProductDeviceTypeEnum.class, message = "设备类型必须是 {value}") - @NotNull(message = "设备类型不能为空") - private Integer deviceType; - - @Schema(description = "联网方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") - @InEnum(value = IotNetTypeEnum.class, message = "联网方式必须是 {value}") - private Integer netType; - - @Schema(description = "接入网关协议", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") - @InEnum(value = IotProtocolTypeEnum.class, message = "接入网关协议必须是 {value}") - private Integer protocolType; - - @Schema(description = "数据格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") - @InEnum(value = IotDataFormatEnum.class, message = "数据格式必须是 {value}") - @NotNull(message = "数据格式不能为空") - private Integer dataFormat; - - @Schema(description = "数据校验级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") - @InEnum(value = IotValidateTypeEnum.class, message = "数据校验级别必须是 {value}") - @NotNull(message = "数据校验级别不能为空") - private Integer validateType; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/IotDataBridgeController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/IotDataBridgeController.java deleted file mode 100644 index 95e50a4..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/IotDataBridgeController.java +++ /dev/null @@ -1,72 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.rule; - -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.rule.vo.databridge.IotDataBridgePageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.IotDataBridgeRespVO; -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.IotDataBridgeSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; -import cn.iocoder.yudao.module.iot.service.rule.IotDataBridgeService; -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 static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - IoT 数据桥梁") -@RestController -@RequestMapping("/iot/data-bridge") -@Validated -public class IotDataBridgeController { - - @Resource - private IotDataBridgeService dataBridgeService; - - @PostMapping("/create") - @Operation(summary = "创建数据桥梁") - @PreAuthorize("@ss.hasPermission('iot:data-bridge:create')") - public CommonResult createDataBridge(@Valid @RequestBody IotDataBridgeSaveReqVO createReqVO) { - return success(dataBridgeService.createDataBridge(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新数据桥梁") - @PreAuthorize("@ss.hasPermission('iot:data-bridge:update')") - public CommonResult updateDataBridge(@Valid @RequestBody IotDataBridgeSaveReqVO updateReqVO) { - dataBridgeService.updateDataBridge(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除数据桥梁") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('iot:data-bridge:delete')") - public CommonResult deleteDataBridge(@RequestParam("id") Long id) { - dataBridgeService.deleteDataBridge(id); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得数据桥梁") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('iot:data-bridge:query')") - public CommonResult getDataBridge(@RequestParam("id") Long id) { - IotDataBridgeDO dataBridge = dataBridgeService.getDataBridge(id); - return success(BeanUtils.toBean(dataBridge, IotDataBridgeRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得数据桥梁分页") - @PreAuthorize("@ss.hasPermission('iot:data-bridge:query')") - public CommonResult> getDataBridgePage(@Valid IotDataBridgePageReqVO pageReqVO) { - PageResult pageResult = dataBridgeService.getDataBridgePage(pageReqVO); - return success(BeanUtils.toBean(pageResult, IotDataBridgeRespVO.class)); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/IotRuleSceneController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/IotRuleSceneController.java deleted file mode 100644 index 04e2f45..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/IotRuleSceneController.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.rule; - -import cn.iocoder.yudao.module.iot.service.rule.IotRuleSceneService; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.annotation.security.PermitAll; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@Tag(name = "管理后台 - IoT 规则场景") -@RestController -@RequestMapping("/iot/rule-scene") -@Validated -public class IotRuleSceneController { - - @Resource - private IotRuleSceneService ruleSceneService; - - @GetMapping("/test") - @PermitAll - public void test() { - ruleSceneService.test(); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgePageReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgePageReqVO.java deleted file mode 100644 index e4dc36e..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgePageReqVO.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge; - -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import cn.iocoder.yudao.framework.common.validation.InEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - IoT 数据桥梁分页 Request VO") -@Data -public class IotDataBridgePageReqVO extends PageParam { - - @Schema(description = "桥梁名称", example = "赵六") - private String name; - - @Schema(description = "桥梁状态", example = "1") - @InEnum(CommonStatusEnum.class) - private Integer status; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgeRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgeRespVO.java deleted file mode 100644 index 38e04b2..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgeRespVO.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge; - -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeAbstractConfig; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - IoT 数据桥梁 Response VO") -@Data -public class IotDataBridgeRespVO { - - @Schema(description = "桥梁编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18564") - private Long id; - - @Schema(description = "桥梁名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") - private String name; - - @Schema(description = "桥梁描述", example = "随便") - private String description; - - @Schema(description = "桥梁状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer status; - - @Schema(description = "桥梁方向", requiredMode = Schema.RequiredMode.REQUIRED) - private Integer direction; - - @Schema(description = "桥梁类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer type; - - @Schema(description = "桥梁配置") - private IotDataBridgeAbstractConfig config; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime createTime; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgeSaveReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgeSaveReqVO.java deleted file mode 100644 index 8441701..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/IotDataBridgeSaveReqVO.java +++ /dev/null @@ -1,46 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge; - -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeAbstractConfig; -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeDirectionEnum; -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum; -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 IotDataBridgeSaveReqVO { - - @Schema(description = "桥梁编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18564") - private Long id; - - @Schema(description = "桥梁名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") - @NotEmpty(message = "桥梁名称不能为空") - private String name; - - @Schema(description = "桥梁描述", example = "随便") - private String description; - - @Schema(description = "桥梁状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") - @NotNull(message = "桥梁状态不能为空") - @InEnum(CommonStatusEnum.class) - private Integer status; - - @Schema(description = "桥梁方向", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "桥梁方向不能为空") - @InEnum(IotDataBridgeDirectionEnum.class) - private Integer direction; - - @Schema(description = "桥梁类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "桥梁类型不能为空") - @InEnum(IotDataBridgeTypeEnum.class) - private Integer type; - - @Schema(description = "桥梁配置") - @NotNull(message = "桥梁配置不能为空") - private IotDataBridgeAbstractConfig config; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeAbstractConfig.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeAbstractConfig.java deleted file mode 100644 index 527e79b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeAbstractConfig.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config; - -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import lombok.Data; - -/** - * IoT IotDataBridgeConfig 抽象类 - * - * 用于表示数据桥梁配置数据的通用类型,根据具体的 "type" 字段动态映射到对应的子类 - * 提供多态支持,适用于不同类型的数据结构序列化和反序列化场景。 - * - * @author HUIHUI - */ -@Data -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true) -@JsonSubTypes({ - @JsonSubTypes.Type(value = IotDataBridgeHttpConfig.class, name = "1"), - @JsonSubTypes.Type(value = IotDataBridgeMqttConfig.class, name = "10"), - @JsonSubTypes.Type(value = IotDataBridgeRedisStreamMQConfig.class, name = "21"), - @JsonSubTypes.Type(value = IotDataBridgeRocketMQConfig.class, name = "30"), - @JsonSubTypes.Type(value = IotDataBridgeRabbitMQConfig.class, name = "31"), - @JsonSubTypes.Type(value = IotDataBridgeKafkaMQConfig.class, name = "32"), -}) -public abstract class IotDataBridgeAbstractConfig { - - /** - * 配置类型 - * - * 枚举 {@link IotDataBridgeTypeEnum#getType()} - */ - private String type; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeHttpConfig.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeHttpConfig.java deleted file mode 100644 index eca35c7..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeHttpConfig.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config; - -import lombok.Data; - -import java.util.Map; - -/** - * IoT HTTP 配置 {@link IotDataBridgeAbstractConfig} 实现类 - * - * @author HUIHUI - */ -@Data -public class IotDataBridgeHttpConfig extends IotDataBridgeAbstractConfig { - - /** - * 请求 URL - */ - private String url; - /** - * 请求方法 - */ - private String method; - /** - * 请求头 - */ - private Map headers; - /** - * 请求参数 - */ - private Map query; - /** - * 请求体 - */ - private String body; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeKafkaMQConfig.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeKafkaMQConfig.java deleted file mode 100644 index 1201214..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeKafkaMQConfig.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config; - -import lombok.Data; - -/** - * IoT Kafka 配置 {@link IotDataBridgeAbstractConfig} 实现类 - * - * @author HUIHUI - */ -@Data -public class IotDataBridgeKafkaMQConfig extends IotDataBridgeAbstractConfig { - - /** - * Kafka 服务器地址 - */ - private String bootstrapServers; - /** - * 用户名 - */ - private String username; - /** - * 密码 - */ - private String password; - /** - * 是否启用 SSL - */ - private Boolean ssl; - - /** - * 主题 - */ - private String topic; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeMqttConfig.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeMqttConfig.java deleted file mode 100644 index 448b215..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeMqttConfig.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config; - -import lombok.Data; - -/** - * IoT MQTT 配置 {@link IotDataBridgeAbstractConfig} 实现类 - * - * @author HUIHUI - */ -@Data -public class IotDataBridgeMqttConfig extends IotDataBridgeAbstractConfig { - - /** - * MQTT 服务器地址 - */ - private String url; - /** - * 用户名 - */ - private String username; - /** - * 密码 - */ - private String password; - /** - * 客户端编号 - */ - private String clientId; - /** - * 主题 - */ - private String topic; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRabbitMQConfig.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRabbitMQConfig.java deleted file mode 100644 index 2c247d1..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRabbitMQConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config; - -import lombok.Data; - -/** - * IoT RabbitMQ 配置 {@link IotDataBridgeAbstractConfig} 实现类 - * - * @author HUIHUI - */ -@Data -public class IotDataBridgeRabbitMQConfig extends IotDataBridgeAbstractConfig { - - /** - * RabbitMQ 服务器地址 - */ - private String host; - /** - * 端口 - */ - private Integer port; - /** - * 虚拟主机 - */ - private String virtualHost; - /** - * 用户名 - */ - private String username; - /** - * 密码 - */ - private String password; - - /** - * 交换机名称 - */ - private String exchange; - /** - * 路由键 - */ - private String routingKey; - /** - * 队列名称 - */ - private String queue; -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRedisStreamMQConfig.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRedisStreamMQConfig.java deleted file mode 100644 index 3c9bb33..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRedisStreamMQConfig.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config; - -import lombok.Data; - -// TODO @puhui999:MQ 可以去掉哈。stream 更精准 -/** - * IoT Redis Stream 配置 {@link IotDataBridgeAbstractConfig} 实现类 - * - * @author HUIHUI - */ -@Data -public class IotDataBridgeRedisStreamMQConfig extends IotDataBridgeAbstractConfig { - - /** - * Redis 服务器地址 - */ - private String host; - /** - * 端口 - */ - private Integer port; - /** - * 密码 - */ - private String password; - /** - * 数据库索引 - */ - private Integer database; - - /** - * 主题 - */ - private String topic; -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRocketMQConfig.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRocketMQConfig.java deleted file mode 100644 index e23e306..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/databridge/config/IotDataBridgeRocketMQConfig.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config; - -import lombok.Data; - -/** - * IoT RocketMQ 配置 {@link IotDataBridgeAbstractConfig} 实现类 - * - * @author HUIHUI - */ -@Data -public class IotDataBridgeRocketMQConfig extends IotDataBridgeAbstractConfig { - - /** - * RocketMQ 名称服务器地址 - */ - private String nameServer; - /** - * 访问密钥 - */ - private String accessKey; - /** - * 秘密钥匙 - */ - private String secretKey; - - /** - * 生产者组 - */ - private String group; - /** - * 主题 - */ - private String topic; - /** - * 标签 - */ - private String tags; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/package-info.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/package-info.java deleted file mode 100644 index f397e0a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/rule/vo/package-info.java +++ /dev/null @@ -1,2 +0,0 @@ -// TODO @芋艿:占位 -package cn.iocoder.yudao.module.iot.controller.admin.rule.vo; \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/IotStatisticsController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/IotStatisticsController.java deleted file mode 100644 index a9c1956..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/IotStatisticsController.java +++ /dev/null @@ -1,79 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.statistics; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.controller.admin.statistics.vo.IotStatisticsDeviceMessageSummaryRespVO; -import cn.iocoder.yudao.module.iot.controller.admin.statistics.vo.IotStatisticsReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.statistics.vo.IotStatisticsSummaryRespVO; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStateEnum; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -import cn.iocoder.yudao.module.iot.service.device.data.IotDeviceLogService; -import cn.iocoder.yudao.module.iot.service.product.IotProductCategoryService; -import cn.iocoder.yudao.module.iot.service.product.IotProductService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.validation.Valid; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.time.LocalDateTime; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.*; - -@Tag(name = "管理后台 - IoT 数据统计") -@RestController -@RequestMapping("/iot/statistics") -@Validated -public class IotStatisticsController { - - @Resource - private IotDeviceService deviceService; - @Resource - private IotProductCategoryService productCategoryService; - @Resource - private IotProductService productService; - @Resource - private IotDeviceLogService deviceLogService; - - @GetMapping("/get-summary") - @Operation(summary = "获取 IoT 数据统计") - public CommonResult getIotStatisticsSummary(){ - IotStatisticsSummaryRespVO respVO = new IotStatisticsSummaryRespVO(); - // 1.1 获取总数 - respVO.setProductCategoryCount(productCategoryService.getProductCategoryCount(null)); - respVO.setProductCount(productService.getProductCount(null)); - respVO.setDeviceCount(deviceService.getDeviceCount(null)); - respVO.setDeviceMessageCount(deviceLogService.getDeviceLogCount(null)); - // 1.2 获取今日新增数量 - // TODO @super:使用 LocalDateTimeUtils.getToday() - LocalDateTime todayStart = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0); - respVO.setProductCategoryTodayCount(productCategoryService.getProductCategoryCount(todayStart)); - respVO.setProductTodayCount(productService.getProductCount(todayStart)); - respVO.setDeviceTodayCount(deviceService.getDeviceCount(todayStart)); - respVO.setDeviceMessageTodayCount(deviceLogService.getDeviceLogCount(todayStart)); - - // 2. 获取各个品类下设备数量统计 - respVO.setProductCategoryDeviceCounts(productCategoryService.getProductCategoryDeviceCountMap()); - - // 3. 获取设备状态数量统计 - Map deviceCountMap = deviceService.getDeviceCountMapByState(); - respVO.setDeviceOnlineCount(deviceCountMap.getOrDefault(IotDeviceStateEnum.ONLINE.getState(), 0L)); - respVO.setDeviceOfflineCount(deviceCountMap.getOrDefault(IotDeviceStateEnum.OFFLINE.getState(), 0L)); - respVO.setDeviceInactiveCount(deviceCountMap.getOrDefault(IotDeviceStateEnum.INACTIVE.getState(), 0L)); - return success(respVO); - } - - // TODO @super:要不干掉 IotStatisticsReqVO 参数,直接使用 @RequestParam 接收,简单一些。 - @GetMapping("/get-log-summary") - @Operation(summary = "获取 IoT 设备上下行消息数据统计") - public CommonResult getIotStatisticsDeviceMessageSummary( - @Valid IotStatisticsReqVO reqVO) { - return success(new IotStatisticsDeviceMessageSummaryRespVO() - .setDownstreamCounts(deviceLogService.getDeviceLogUpCountByHour(null, reqVO.getStartTime(), reqVO.getEndTime())) - .setDownstreamCounts((deviceLogService.getDeviceLogDownCountByHour(null, reqVO.getStartTime(), reqVO.getEndTime())))); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsDeviceMessageSummaryRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsDeviceMessageSummaryRespVO.java deleted file mode 100644 index 15d2abc..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsDeviceMessageSummaryRespVO.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.statistics.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.util.List; -import java.util.Map; - -@Schema(description = "管理后台 - IoT 设备上下行消息数量统计 Response VO") -@Data -public class IotStatisticsDeviceMessageSummaryRespVO { - - @Schema(description = "每小时上行数据数量统计") - private List> upstreamCounts; - - @Schema(description = "每小时下行数据数量统计") - private List> downstreamCounts; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsReqVO.java deleted file mode 100644 index 741f77f..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsReqVO.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.statistics.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -@Schema(description = "管理后台 - IoT 统计 Request VO") -@Data -public class IotStatisticsReqVO { - - // TODO @super:前端传递的时候,还是通过 startTime 和 endTime 传递。后端转成 Long - - @Schema(description = "查询起始时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1658486600000") - @NotNull(message = "查询起始时间不能为空") - private Long startTime; - - @Schema(description = "查询结束时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "1758486600000") - @NotNull(message = "查询结束时间不能为空") - private Long endTime; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsSummaryRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsSummaryRespVO.java deleted file mode 100644 index 21745c4..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/statistics/vo/IotStatisticsSummaryRespVO.java +++ /dev/null @@ -1,51 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.statistics.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.util.Map; - -/** - * 管理后台 - IoT 统计 Response VO - */ -@Schema(description = "管理后台 - IoT 统计 Response VO") -@Data -public class IotStatisticsSummaryRespVO { - - @Schema(description = "品类数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Long productCategoryCount; - - @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") - private Long productCount; - - @Schema(description = "设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") - private Long deviceCount; - - @Schema(description = "上报数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") - private Long deviceMessageCount; - - @Schema(description = "今日新增品类数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Long productCategoryTodayCount; - - @Schema(description = "今日新增产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20") - private Long productTodayCount; - - @Schema(description = "今日新增设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") - private Long deviceTodayCount; - - @Schema(description = "今日新增上报数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") - private Long deviceMessageTodayCount; - - @Schema(description = "在线数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "80") - private Long deviceOnlineCount; - - @Schema(description = "离线数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15") - private Long deviceOfflineCount; - - @Schema(description = "待激活设备数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") - private Long deviceInactiveCount; - - @Schema(description = "按品类统计的设备数量") - private Map productCategoryDeviceCounts; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.http b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.http deleted file mode 100644 index 1e1f721..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.http +++ /dev/null @@ -1,181 +0,0 @@ -### 请求 /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": "百分比" - } - } -} - -### 请求 /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": "开关", - "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 颜色", - "accessMode": "rw", - "required": true, - "dataType": "array", - "dataSpecs": { - "dataType": "array", - "size": 10, - "childDataType": "struct", - "dataSpecsList": [ - { - "identifier": "switch", - "name": "开关", - "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": "百分比" - } - } - ] - } - } -} - -### 请求 /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": "开关", - "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=67 -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/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.java deleted file mode 100644 index 382940f..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.java +++ /dev/null @@ -1,93 +0,0 @@ -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.IotThingModelListReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelRespVO; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; -import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; -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/thing-model") -@Validated -public class IotThingModelController { - - @Resource - private IotThingModelService thingModelService; - - @PostMapping("/create") - @Operation(summary = "创建产品物模型") - @PreAuthorize("@ss.hasPermission('iot:thing-model:create')") - public CommonResult createThingModel(@Valid @RequestBody IotThingModelSaveReqVO createReqVO) { - return success(thingModelService.createThingModel(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新产品物模型") - @PreAuthorize("@ss.hasPermission('iot:thing-model:update')") - public CommonResult updateThingModel(@Valid @RequestBody IotThingModelSaveReqVO updateReqVO) { - thingModelService.updateThingModel(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除产品物模型") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('iot:thing-model:delete')") - public CommonResult deleteThingModel(@RequestParam("id") Long id) { - thingModelService.deleteThingModel(id); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得产品物模型") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('iot:thing-model:query')") - public CommonResult getThingModel(@RequestParam("id") Long id) { - IotThingModelDO thingModel = thingModelService.getThingModel(id); - return success(BeanUtils.toBean(thingModel, IotThingModelRespVO.class)); - } - - @GetMapping("/list-by-product-id") - @Operation(summary = "获得产品物模型") - @Parameter(name = "productId", description = "产品ID", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('iot:thing-model:query')") - public CommonResult> getThingModelListByProductId(@RequestParam("productId") Long productId) { - List list = thingModelService.getThingModelListByProductId(productId); - return success(BeanUtils.toBean(list, IotThingModelRespVO.class)); - } - - // TODO @puhui @super:getThingModelListByProductId 和 getThingModelListByProductId 可以融合么? - @GetMapping("/list") - @Operation(summary = "获得产品物模型列表") - @PreAuthorize("@ss.hasPermission('iot:thing-model:query')") - public CommonResult> getThingModelListByProductId(@Valid IotThingModelListReqVO reqVO) { - List list = thingModelService.getThingModelList(reqVO); - return success(BeanUtils.toBean(list, IotThingModelRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得产品物模型分页") - @PreAuthorize("@ss.hasPermission('iot:thing-model:query')") - public CommonResult> getThingModelPage(@Valid IotThingModelPageReqVO pageReqVO) { - PageResult pageResult = thingModelService.getProductThingModelPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, IotThingModelRespVO.class)); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelEvent.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelEvent.java deleted file mode 100644 index 06cc438..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelEvent.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelServiceEventTypeEnum; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.Pattern; -import lombok.Data; - -import java.util.List; - -/** - * IoT 物模型中的事件 - * - * @author HUIHUI - */ -@Data -public class ThingModelEvent { - - /** - * 事件标识符 - */ - @NotEmpty(message = "事件标识符不能为空") - @Pattern(regexp = "^[a-zA-Z][a-zA-Z0-9_]{0,31}$", message = "事件标识符只能由字母、数字和下划线组成,必须以字母开头,长度不超过 32 个字符") - private String identifier; - /** - * 事件名称 - */ - @NotEmpty(message = "事件名称不能为空") - private String name; - /** - * 是否是标准品类的必选事件 - */ - private Boolean required; - /** - * 事件类型 - * - * 枚举 {@link IotThingModelServiceEventTypeEnum} - */ - @NotEmpty(message = "事件类型不能为空") - @InEnum(IotThingModelServiceEventTypeEnum.class) - private String type; - /** - * 事件的输出参数 - * - * 输出参数定义事件调用后返回的结果或反馈信息,用于确认操作结果或提供额外的信息。 - */ - @Valid - private List outputParams; - /** - * 标识设备需要执行的具体操作 - */ - private String method; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelParam.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelParam.java deleted file mode 100644 index 2afad89..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelParam.java +++ /dev/null @@ -1,63 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDataSpecs; -import cn.iocoder.yudao.module.iot.enums.thingmodel.IotDataSpecsDataTypeEnum; -import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelParamDirectionEnum; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.Pattern; -import lombok.Data; - -import java.util.List; - -/** - * IoT 产品物模型中的参数 - * - * @author HUIHUI - */ -@Data -public class ThingModelParam { - - /** - * 参数标识符 - */ - @NotEmpty(message = "参数标识符不能为空") - @Pattern(regexp = "^[a-zA-Z][a-zA-Z0-9_]{0,31}$", message = "参数标识符只能由字母、数字和下划线组成,必须以字母开头,长度不超过 32 个字符") - private String identifier; - /** - * 参数名称 - */ - @NotEmpty(message = "参数名称不能为空") - private String name; - /** - * 用于区分输入或输出参数 - * - * 枚举 {@link IotThingModelParamDirectionEnum} - */ - @NotEmpty(message = "参数方向不能为空") - @InEnum(IotThingModelParamDirectionEnum.class) - private String direction; - /** - * 参数的序号。从 0 开始排序,且不能重复。 - * - * TODO 考虑要不要序号,感觉是要的, 先留一手看看 - */ - private Integer paraOrder; - /** - * 参数值的数据类型,与 dataSpecs 的 dataType 保持一致 - * - * 枚举 {@link IotDataSpecsDataTypeEnum} - */ - @NotEmpty(message = "数据类型不能为空") - @InEnum(IotDataSpecsDataTypeEnum.class) - 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/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelProperty.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelProperty.java deleted file mode 100644 index 4b9a05a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelProperty.java +++ /dev/null @@ -1,63 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDataSpecs; -import cn.iocoder.yudao.module.iot.enums.thingmodel.IotDataSpecsDataTypeEnum; -import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelAccessModeEnum; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.Pattern; -import lombok.Data; - -import java.util.List; - -/** - * IoT 物模型中的属性 - * - * dataSpecs 和 dataSpecsList 之中必须传入且只能传入一个 - * - * @author HUIHUI - */ -@Data -public class ThingModelProperty { - - /** - * 属性标识符 - */ - @NotEmpty(message = "属性标识符不能为空") - @Pattern(regexp = "^[a-zA-Z][a-zA-Z0-9_]{0,31}$", message = "属性标识符只能由字母、数字和下划线组成,必须以字母开头,长度不超过 32 个字符") - private String identifier; - /** - * 属性名称 - */ - @NotEmpty(message = "属性名称不能为空") - private String name; - /** - * 云端可以对该属性进行的操作类型 - * - * 枚举 {@link IotThingModelAccessModeEnum} - */ - @NotEmpty(message = "操作类型不能为空") - @InEnum(IotThingModelAccessModeEnum.class) - private String accessMode; - /** - * 是否是标准品类的必选服务 - */ - private Boolean required; - /** - * 参数值的数据类型,与 dataSpecs 的 dataType 保持一致 - * - * 枚举 {@link IotDataSpecsDataTypeEnum} - */ - @NotEmpty(message = "数据类型不能为空") - @InEnum(IotDataSpecsDataTypeEnum.class) - 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/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelService.java deleted file mode 100644 index c98acd8..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/ThingModelService.java +++ /dev/null @@ -1,62 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelServiceCallTypeEnum; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.Pattern; -import lombok.Data; - -import java.util.List; - -/** - * IoT 物模型中的服务 - * - * @author HUIHUI - */ -@Data -public class ThingModelService { - - /** - * 服务标识符 - */ - @NotEmpty(message = "服务标识符不能为空") - @Pattern(regexp = "^[a-zA-Z][a-zA-Z0-9_]{0,31}$", message = "服务标识符只能由字母、数字和下划线组成,必须以字母开头,长度不超过 32 个字符") - private String identifier; - /** - * 服务名称 - */ - @NotEmpty(message = "服务名称不能为空") - private String name; - /** - * 是否是标准品类的必选服务 - */ - private Boolean required; - /** - * 调用类型 - * - * 枚举 {@link IotThingModelServiceCallTypeEnum} - */ - @NotEmpty(message = "调用类型不能为空") - @InEnum(IotThingModelServiceCallTypeEnum.class) - private String callType; - /** - * 服务的输入参数 - * - * 输入参数定义服务调用时所需提供的信息,用于控制设备行为或执行特定任务 - */ - @Valid - private List inputParams; - /** - * 服务的输出参数 - * - * 输出参数定义服务调用后返回的结果或反馈信息,用于确认操作结果或提供额外的信息。 - */ - @Valid - private List outputParams; - /** - * 标识设备需要执行的具体操作 - */ - private String method; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArrayDataSpecs.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArrayDataSpecs.java deleted file mode 100644 index 50011aa..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelArrayDataSpecs.java +++ /dev/null @@ -1,34 +0,0 @@ -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; - -/** - * IoT 物模型数据类型为数组的 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/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelBoolOrEnumDataSpecs.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelBoolOrEnumDataSpecs.java deleted file mode 100644 index 925bc67..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelBoolOrEnumDataSpecs.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * IoT 物模型数据类型为布尔型或枚举型的 DataSpec 定义 - * - * 数据类型,取值为 bool 或 enum。 - * - * @author HUIHUI - */ -@Data -@EqualsAndHashCode(callSuper = true) -@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段,从而避免重复 -public class ThingModelBoolOrEnumDataSpecs extends ThingModelDataSpecs { - - // TODO @puhui999:要不写下参数校验?这样,注释可以简洁一点 - /** - * 枚举项的名称。 - * 可包含中文、大小写英文字母、数字、下划线(_)和短划线(-) - * 必须以中文、英文字母或数字开头,长度不超过 20 个字符 - */ - private String name; - /** - * 枚举值。 - */ - private Integer value; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDataSpecs.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDataSpecs.java deleted file mode 100644 index d9fc12d..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDataSpecs.java +++ /dev/null @@ -1,35 +0,0 @@ -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; - -/** - * IoT 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/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDateOrTextDataSpecs.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDateOrTextDataSpecs.java deleted file mode 100644 index 62500bc..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelDateOrTextDataSpecs.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * IoT 物模型数据类型为时间型或文本型的 DataSpec 定义 - * - * 数据类型,取值为 date 或 text。 - * - * @author HUIHUI - */ -@Data -@EqualsAndHashCode(callSuper = true) -@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段,从而避免重复 -public class ThingModelDateOrTextDataSpecs extends ThingModelDataSpecs { - - /** - * 数据长度,单位为字节。取值不能超过 2048。 - * 当 dataType 为 text 时,需传入该参数。 - */ - private Integer length; - /** - * 默认值,可选参数,用于存储默认值。 - */ - private String defaultValue; - -} - diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelNumericDataSpec.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelNumericDataSpec.java deleted file mode 100644 index 8d0827c..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelNumericDataSpec.java +++ /dev/null @@ -1,51 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * IoT 物模型数据类型为数值的 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/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelStructDataSpecs.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelStructDataSpecs.java deleted file mode 100644 index 6d483ee..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/model/dataType/ThingModelStructDataSpecs.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType; - -import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelAccessModeEnum; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -/** - * IoT 物模型数据类型为 struct 的 DataSpec 定义 - * - * @author HUIHUI - */ -@Data -@EqualsAndHashCode(callSuper = true) -@JsonIgnoreProperties({"dataType"}) // 忽略子类中的 dataType 字段,从而避免重复 -public class ThingModelStructDataSpecs extends ThingModelDataSpecs { - - /** - * 属性标识符 - */ - private String identifier; - /** - * 属性名称 - */ - private String name; - /** - * 云端可以对该属性进行的操作类型 - * - * 枚举 {@link IotThingModelAccessModeEnum} - */ - private String accessMode; - /** - * 是否是标准品类的必选服务 - */ - 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/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelListReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelListReqVO.java deleted file mode 100644 index 5b92256..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelListReqVO.java +++ /dev/null @@ -1,27 +0,0 @@ -package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo; - -import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -@Schema(description = "管理后台 - IoT 产品物模型 List Request VO") -@Data -public class IotThingModelListReqVO { - - @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "产品编号不能为空") - private Long productId; - - @Schema(description = "功能标识", example = "temperature") - private String identifier; - - @Schema(description = "功能名称", example = "温度") - private String name; - - @Schema(description = "功能类型", example = "1") - @InEnum(IotThingModelTypeEnum.class) - private Integer type; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelPageReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelPageReqVO.java deleted file mode 100644 index 8064b10..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelPageReqVO.java +++ /dev/null @@ -1,28 +0,0 @@ -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.IotThingModelTypeEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -@Schema(description = "管理后台 - IoT 产品物模型分页 Request VO") -@Data -public class IotThingModelPageReqVO extends PageParam { - - @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "产品编号不能为空") - private Long productId; - - @Schema(description = "功能标识", example = "temperature") - private String identifier; - - @Schema(description = "功能名称", example = "温度") - private String name; - - @Schema(description = "功能类型", example = "1") - @InEnum(IotThingModelTypeEnum.class) - private Integer type; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelRespVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelRespVO.java deleted file mode 100644 index 15a5b9f..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelRespVO.java +++ /dev/null @@ -1,54 +0,0 @@ -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 IotThingModelRespVO { - - @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21816") - @ExcelProperty("产品ID") - private Long id; - - @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long productId; - - @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature_sensor") - @ExcelProperty("产品标识") - private String productKey; - - @Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature") - private String identifier; - - @Schema(description = "功能名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "温度") - private String name; - - @Schema(description = "功能描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "测量当前环境温度") - private String description; - - @Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - 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/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelSaveReqVO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelSaveReqVO.java deleted file mode 100644 index 1e8564d..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelSaveReqVO.java +++ /dev/null @@ -1,57 +0,0 @@ -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.IotThingModelTypeEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -@Schema(description = "管理后台 - IoT 产品物模型新增/修改 Request VO") -@Data -public class IotThingModelSaveReqVO { - - @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, example = "temperature_001") - @NotEmpty(message = "产品标识不能为空") - private String productKey; - - @Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temp_monitor") - @NotEmpty(message = "功能标识不能为空") - private String identifier; - - @Schema(description = "功能名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "温度监测器") - @NotEmpty(message = "功能名称不能为空") - private String name; - - @Schema(description = "功能描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "用于监测环境温度的传感器") - private String description; - - @Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "功能类型不能为空") - @InEnum(IotThingModelTypeEnum.class) - private Integer type; - - @Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED) - @Valid - private ThingModelProperty property; - - @Schema(description = "服务", requiredMode = Schema.RequiredMode.REQUIRED) - @Valid - private ThingModelService service; - - @Schema(description = "事件", requiredMode = Schema.RequiredMode.REQUIRED) - @Valid - private ThingModelEvent event; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/IotThinkModelFunctionController.http b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/IotThinkModelFunctionController.http deleted file mode 100644 index 84446b0..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/IotThinkModelFunctionController.http +++ /dev/null @@ -1,112 +0,0 @@ -### 请求 /iot/think-model-function/create 接口 => 成功 -POST {{baseUrl}}/iot/think-model-function/create -Content-Type: application/json -tenant-id: {{adminTenantId}} -Authorization: Bearer {{token}} - -{ - "productId": 1001, - "productKey": "smart-sensor-001", - "identifier": "Temperature", - "name": "温度", - "description": "当前温度值", - "type": 1, - "property": { - "identifier": "Temperature", - "name": "温度", - "accessMode": "r", - "required": true, - "dataType": { - "type": "float", - "specs": { - "min": -10.0, - "max": 100.0, - "step": 0.1, - "unit": "℃" - } - }, - "description": "当前温度值" - } -} - -### 请求 /iot/think-model-function/create 接口 => 成功 -POST {{baseUrl}}/iot/think-model-function/create -Content-Type: application/json -tenant-id: {{adminTenantId}} -Authorization: Bearer {{token}} - -{ - "productId": 1001, - "productKey": "smart-sensor-001", - "identifier": "Humidity", - "name": "湿度", - "description": "当前湿度值", - "type": 1, - "property": { - "identifier": "Humidity", - "name": "湿度", - "accessMode": "r", - "required": true, - "dataType": { - "type": "float", - "specs": { - "min": 0.0, - "max": 100.0, - "step": 0.1, - "unit": "%" - } - }, - "description": "当前湿度值" - } -} - - - - -### 请求 /iot/think-model-function/update 接口 => 成功 -PUT {{baseUrl}}/iot/think-model-function/update -Content-Type: application/json -tenant-id: {{adminTenantId}} -Authorization: Bearer {{token}} - -{ - "id": 11, - "productId": 1001, - "productKey": "smart-sensor-001", - "identifier": "Temperature", - "name": "温度", - "description": "当前温度值", - "type": 1, - "property": { - "identifier": "Temperature", - "name": "温度", - "accessMode": "r", - "required": true, - "dataType": { - "type": "float", - "specs": { - "min": -111.0, - "max": 222.0, - "step": 0.1, - "unit": "℃" - } - }, - "description": "当前温度值" - } -} - -### 请求 /iot/think-model-function/delete 接口 => 成功 -DELETE {{baseUrl}}/iot/think-model-function/delete?id=7 -tenant-id: {{adminTenantId}} -Authorization: Bearer {{token}} - -### 请求 /iot/think-model-function/get 接口 => 成功 -GET {{baseUrl}}/iot/think-model-function/get?id=10 -tenant-id: {{adminTenantId}} -Authorization: Bearer {{token}} - - -### 请求 /iot/think-model-function/list-by-product-id 接口 => 成功 -GET {{baseUrl}}/iot/think-model-function/list-by-product-id?productId=1001 -tenant-id: {{adminTenantId}} -Authorization: Bearer {{token}} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/package-info.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/package-info.java deleted file mode 100644 index 5d2990e..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * 提供 RESTful API 给前端: - * 1. admin 包:提供给管理后台 yudao-ui-admin 前端项目 - * 2. app 包:提供给用户 APP yudao-ui-app 前端项目,它的 Controller 和 VO 都要添加 App 前缀,用于和管理后台进行区分 - */ -package cn.iocoder.yudao.module.iot.controller; diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/package-info.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/package-info.java deleted file mode 100644 index 18d7ad2..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * 提供 POJO 类的实体转换 - * - * 目前使用 MapStruct 框架 - */ -package cn.iocoder.yudao.module.iot.convert; \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thingmodel/IotThingModelConvert.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thingmodel/IotThingModelConvert.java deleted file mode 100644 index 9577b18..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/convert/thingmodel/IotThingModelConvert.java +++ /dev/null @@ -1,50 +0,0 @@ -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.IotThingModelSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; -import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.Named; -import org.mapstruct.factory.Mappers; - -import java.util.Objects; - -@Mapper -public interface IotThingModelConvert { - - IotThingModelConvert INSTANCE = Mappers.getMapper(IotThingModelConvert.class); - - @Mapping(target = "property", expression = "java(convertToProperty(bean))") - @Mapping(target = "event", expression = "java(convertToEvent(bean))") - @Mapping(target = "service", expression = "java(convertToService(bean))") - IotThingModelDO convert(IotThingModelSaveReqVO bean); - - @Named("convertToProperty") - default ThingModelProperty convertToProperty(IotThingModelSaveReqVO bean) { - if (Objects.equals(bean.getType(), IotThingModelTypeEnum.PROPERTY.getType())) { - return bean.getProperty(); - } - return null; - } - - @Named("convertToEvent") - default ThingModelEvent convertToEvent(IotThingModelSaveReqVO bean) { - if (Objects.equals(bean.getType(), IotThingModelTypeEnum.EVENT.getType())) { - return bean.getEvent(); - } - return null; - } - - @Named("convertToService") - default ThingModelService convertToService(IotThingModelSaveReqVO bean) { - if (Objects.equals(bean.getType(), IotThingModelTypeEnum.SERVICE.getType())) { - return bean.getService(); - } - return null; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceDO.java deleted file mode 100644 index 9633d2f..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceDO.java +++ /dev/null @@ -1,173 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.device; - -import cn.iocoder.yudao.framework.mybatis.core.type.LongSetTypeHandler; -import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStateEnum; -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 lombok.*; - -import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.util.Set; - -/** - * IoT 设备 DO - * - * @author haohao - */ -@TableName(value = "iot_device", autoResultMap = true) -@KeySequence("iot_device_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotDeviceDO extends TenantBaseDO { - - /** - * 设备 ID,主键,自增 - */ - @TableId - private Long id; - /** - * 设备唯一标识符,全局唯一,用于识别设备 - * - * 类似阿里云 QueryDeviceInfo 的 IotInstanceId - */ - private String deviceKey; - /** - * 设备名称,在产品内唯一,用于标识设备 - */ - private String deviceName; - /** - * 设备备注名称 - */ - private String nickname; - /** - * 设备序列号 - */ - private String serialNumber; - /** - * 设备图片 - */ - private String picUrl; - /** - * 设备分组编号集合 - * - * 关联 {@link IotDeviceGroupDO#getId()} - */ - @TableField(typeHandler = LongSetTypeHandler.class) - private Set groupIds; - - /** - * 产品编号 - *

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

- * 冗余 {@link IotProductDO#getProductKey()} - */ - private String productKey; - /** - * 设备类型 - *

- * 冗余 {@link IotProductDO#getDeviceType()} - */ - private Integer deviceType; - /** - * 网关设备编号 - *

- * 子设备需要关联的网关设备 ID - *

- * 关联 {@link IotDeviceDO#getId()} - */ - private Long gatewayId; - - /** - * 设备状态 - *

- * 枚举 {@link IotDeviceStateEnum} - */ - private Integer state; - /** - * 最后上线时间 - */ - private LocalDateTime onlineTime; - /** - * 最后离线时间 - */ - private LocalDateTime offlineTime; - /** - * 设备激活时间 - */ - private LocalDateTime activeTime; - - /** - * 设备的 IP 地址 - */ - private String ip; - /** - * 固件编号 - * - * 关联 {@link IotOtaFirmwareDO#getId()} - */ - private String firmwareId; - - // TODO @芋艿:【待定 003】:要不要增加 username?目前 tl 有,阿里云之类的没有 - /** - * 设备密钥,用于设备认证,需安全存储 - */ - private String deviceSecret; - /** - * MQTT 客户端 ID - */ - private String mqttClientId; - /** - * MQTT 用户名 - */ - private String mqttUsername; - /** - * MQTT 密码 - */ - private String mqttPassword; - /** - * 认证类型(如一机一密、动态注册) - */ - // TODO @haohao:是不是要枚举哈 - private String authType; - - // TODO @芋艿:【待定 002】:1)设备维护的时候,设置位置?类似 tl?;2)设备上传的时候,设置位置,类似 it? - /** - * 设备位置的纬度 - */ - private BigDecimal latitude; - /** - * 设备位置的经度 - */ - private BigDecimal longitude; - /** - * 地区编码 - *

- * 关联 Area 的 id - */ - private Integer areaId; - /** - * 设备详细地址 - */ - private String address; - - /** - * 设备配置 - * - * JSON 格式,可下发给 device 进行自定义配置 - */ - private String config; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceGroupDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceGroupDO.java deleted file mode 100644 index 7865a44..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceGroupDO.java +++ /dev/null @@ -1,42 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.device; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -/** - * IoT 设备分组 DO - * - * @author 芋道源码 - */ -@TableName("iot_device_group") -@KeySequence("iot_device_group_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotDeviceGroupDO extends BaseDO { - - /** - * 分组 ID - */ - @TableId - private Long id; - /** - * 分组名字 - */ - private String name; - /** - * 分组状态 - * - * 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum} - */ - private Integer status; - /** - * 分组描述 - */ - private String description; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceLogDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceLogDO.java deleted file mode 100644 index 55cfb19..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceLogDO.java +++ /dev/null @@ -1,95 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.device; - -import cn.hutool.core.util.IdUtil; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * IoT 设备日志数据 DO - * - * 目前使用 TDengine 存储 - * - * @author alwayssuper - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotDeviceLogDO { - - /** - * 日志编号 - * - * 通过 {@link IdUtil#fastSimpleUUID()} 生成 - */ - private String id; - - /** - * 请求编号 - * - * 对应 {@link IotDeviceMessage#getRequestId()} 字段 - */ - private String requestId; - - /** - * 产品标识 - *

- * 关联 {@link IotProductDO#getProductKey()} - */ - private String productKey; - /** - * 设备名称 - * - * 关联 {@link IotDeviceDO#getDeviceName()} - */ - private String deviceName; - /** - * 设备标识 - *

- * 关联 {@link IotDeviceDO#getDeviceKey()}} - */ - private String deviceKey; // 非存储字段,用于 TDengine 的 TAG - - /** - * 日志类型 - * - * 枚举 {@link IotDeviceMessageTypeEnum} - */ - private String type; - /** - * 标识符 - * - * 枚举 {@link IotDeviceMessageIdentifierEnum} - */ - private String identifier; - - /** - * 数据内容 - * - * 存储具体的消息数据内容,通常是 JSON 格式 - */ - private String content; - /** - * 响应码 - * - * 目前只有 server 下行消息给 device 设备时,才会有响应码 - */ - private Integer code; - - /** - * 上报时间戳 - */ - private Long reportTime; - - /** - * 时序时间 - */ - private Long ts; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDevicePropertyDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDevicePropertyDO.java deleted file mode 100644 index afb3288..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDevicePropertyDO.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.device; - -import cn.iocoder.yudao.module.iot.dal.redis.device.DevicePropertyRedisDAO; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.time.LocalDateTime; - -/** - * IoT 设备属性项 Redis DO - * - * @see cn.iocoder.yudao.module.iot.dal.redis.RedisKeyConstants#DEVICE_PROPERTY - * @see DevicePropertyRedisDAO - * - * @author haohao - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotDevicePropertyDO { - - /** - * 属性值(最新) - */ - private Object value; - - /** - * 更新时间 - */ - private LocalDateTime updateTime; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ota/IotOtaFirmwareDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ota/IotOtaFirmwareDO.java deleted file mode 100644 index fa56f69..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ota/IotOtaFirmwareDO.java +++ /dev/null @@ -1,80 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.ota; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -/** - * IoT OTA 固件 DO - * - * @see https://help.aliyun.com/zh/iot/user-guide/ota-upgrade-overview - * - * @author 芋道源码 - */ -@TableName(value = "iot_ota_firmware", autoResultMap = true) -@KeySequence("iot_ota_firmware_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotOtaFirmwareDO extends BaseDO { - - /** - * 固件编号 - */ - @TableField - private Long id; - /** - * 固件名称 - */ - private String name; - /** - * 固件版本 - */ - private String description; - /** - * 版本号 - */ - private String version; - - /** - * 产品编号 - * - * 关联 {@link cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO#getId()} - */ - // TODO @li:帮我改成 Long 哈,写错了 - private String productId; - /** - * 产品标识 - * - * 冗余 {@link cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO#getProductKey()} - */ - private String productKey; - - /** - * 签名方式 - * - * 例如说:MD5、SHA256 - */ - private String signMethod; - /** - * 固件文件签名 - */ - private String fileSign; - /** - * 固件文件大小 - */ - private Long fileSize; - /** - * 固件文件 URL - */ - private String fileUrl; - - /** - * 自定义信息,建议使用 JSON 格式 - */ - private String information; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ota/IotOtaUpgradeRecordDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ota/IotOtaUpgradeRecordDO.java deleted file mode 100644 index ff4f0e7..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ota/IotOtaUpgradeRecordDO.java +++ /dev/null @@ -1,92 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.ota; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -import java.time.LocalDateTime; - -/** - * IoT OTA 升级记录 DO - * - * @author 芋道源码 - */ -@TableName(value = "iot_ota_upgrade_record", autoResultMap = true) -@KeySequence("iot_ota_upgrade_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotOtaUpgradeRecordDO extends BaseDO { - - @TableId - private Long id; - - /** - * 固件编号 - * - * 关联 {@link IotOtaFirmwareDO#getId()} - */ - private Long firmwareId; - /** - * 任务编号 - * - * 关联 {@link IotOtaUpgradeTaskDO#getId()} - */ - private Long taskId; - - /** - * 产品标识 - * - * 关联 {@link cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO#getId()} - */ - private String productKey; - /** - * 设备名称 - * - * 关联 {@link cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO#getId()} - */ - private String deviceName; - /** - * 设备编号 - * - * 关联 {@link cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO#getId()} - */ - private String deviceId; - /** - * 来源的固件编号 - * - * 关联 {@link IotDeviceDO#getFirmwareId()} - */ - private Long fromFirmwareId; - - /** - * 升级状态 - * - * 关联 {@link cn.iocoder.yudao.module.iot.enums.ota.IotOtaUpgradeRecordStatusEnum} - */ - private Integer status; - /** - * 升级进度,百分比 - */ - private Integer progress; - /** - * 升级进度描述 - * - * 注意,只记录设备最后一次的升级进度描述 - * 如果想看历史记录,可以查看 {@link cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO} 设备日志 - */ - private String description; - /** - * 升级开始时间 - */ - private LocalDateTime startTime; - /** - * 升级结束时间 - */ - private LocalDateTime endTime; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ota/IotOtaUpgradeTaskDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ota/IotOtaUpgradeTaskDO.java deleted file mode 100644 index 221bdc5..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/ota/IotOtaUpgradeTaskDO.java +++ /dev/null @@ -1,72 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.ota; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; -import lombok.*; - -import java.util.List; - -/** - * IoT OTA 升级任务 DO - * - * @author 芋道源码 - */ -@TableName(value = "iot_ota_upgrade_task", autoResultMap = true) -@KeySequence("iot_ota_upgrade_task_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotOtaUpgradeTaskDO extends BaseDO { - - /** - * 任务编号 - */ - @TableField - private Long id; - /** - * 任务名称 - */ - private String name; - /** - * 任务描述 - */ - private String description; - - /** - * 固件编号 - *

- * 关联 {@link IotOtaFirmwareDO#getId()} - */ - private Long firmwareId; - - /** - * 任务状态 - *

- * 关联 {@link cn.iocoder.yudao.module.iot.enums.ota.IotOtaUpgradeTaskStatusEnum} - */ - private Integer status; - - /** - * 升级范围 - *

- * 关联 {@link cn.iocoder.yudao.module.iot.enums.ota.IotOtaUpgradeTaskScopeEnum} - */ - private Integer scope; - /** - * 设备数量 - */ - private Long deviceCount; - /** - * 选中的设备编号数组 - *

- * 关联 {@link IotDeviceDO#getId()} - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private List deviceIds; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugin/IotPluginConfigDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugin/IotPluginConfigDO.java deleted file mode 100644 index cb247fc..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugin/IotPluginConfigDO.java +++ /dev/null @@ -1,93 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.plugin; - -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; -import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginDeployTypeEnum; -import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginTypeEnum; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -/** - * IoT 插件配置 DO - * - * @author 芋道源码 - */ -@TableName("iot_plugin_config") -@KeySequence("iot_plugin_config_seq") -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotPluginConfigDO extends TenantBaseDO { - - /** - * 主键 ID - */ - @TableId - private Long id; - /** - * 插件包标识符 - */ - private String pluginKey; - /** - * 插件名称 - */ - private String name; - /** - * 插件描述 - */ - private String description; - /** - * 部署方式 - *

- * 枚举 {@link IotPluginDeployTypeEnum} - */ - private Integer deployType; - // TODO @芋艿:如果是外置的插件,fileName 和 version 的选择~ - /** - * 插件包文件名 - */ - private String fileName; - /** - * 插件版本 - */ - private String version; - // TODO @芋艿:type 字典的定义 - /** - * 插件类型 - *

- * 枚举 {@link IotPluginTypeEnum} - */ - private Integer type; - /** - * 设备插件协议类型 - */ - // TODO @芋艿:枚举字段 - private String protocol; - // TODO @haohao:这个字段,是不是直接用 CommonStatus,开启、禁用;然后插件实例那,online 是否在线 - /** - * 状态 - *

- * 枚举 {@link CommonStatusEnum} - */ - private Integer status; - - // TODO @芋艿:configSchema、config 示例字段 - /** - * 插件配置项描述信息 - */ - private String configSchema; - /** - * 插件配置信息 - */ - private String config; - - // TODO @芋艿:script 后续的使用 - /** - * 插件脚本 - */ - private String script; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugin/IotPluginInstanceDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugin/IotPluginInstanceDO.java deleted file mode 100644 index 34abe89..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/plugin/IotPluginInstanceDO.java +++ /dev/null @@ -1,70 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.plugin; - -import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -import java.time.LocalDateTime; - -/** - * IoT 插件实例 DO - * - * @author 芋道源码 - */ -@TableName("iot_plugin_instance") -@KeySequence("iot_plugin_instance_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotPluginInstanceDO extends TenantBaseDO { - - /** - * 主键 - */ - @TableId - private Long id; - /** - * 插件编号 - *

- * 关联 {@link IotPluginConfigDO#getId()} - */ - private Long pluginId; - /** - * 插件进程编号 - * - * 一般格式是:hostIp@processId@${uuid} - */ - private String processId; - - /** - * 插件实例所在 IP - */ - private String hostIp; - /** - * 设备下行端口 - */ - private Integer downstreamPort; - - /** - * 是否在线 - */ - private Boolean online; - /** - * 在线时间 - */ - private LocalDateTime onlineTime; - /** - * 离线时间 - */ - private LocalDateTime offlineTime; - /** - * 心跳时间 - * - * 目的:心路时间超过一定时间后,会被进行下线处理 - */ - private LocalDateTime heartbeatTime; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/product/IotProductCategoryDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/product/IotProductCategoryDO.java deleted file mode 100644 index 174342a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/product/IotProductCategoryDO.java +++ /dev/null @@ -1,46 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.product; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -/** - * IoT 产品分类 DO - * - * @author 芋道源码 - */ -@TableName("iot_product_category") -@KeySequence("iot_product_category_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotProductCategoryDO extends BaseDO { - - /** - * 分类 ID - */ - @TableId - private Long id; - /** - * 分类名字 - */ - private String name; - /** - * 分类排序 - */ - private Integer sort; - /** - * 分类状态 - * - * 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum} - */ - private Integer status; - /** - * 分类描述 - */ - private String description; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/product/IotProductDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/product/IotProductDO.java deleted file mode 100644 index 3caebbc..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/product/IotProductDO.java +++ /dev/null @@ -1,98 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.product; - -import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -/** - * IoT 产品 DO - * - * @author ahh - */ -@TableName("iot_product") -@KeySequence("iot_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotProductDO extends TenantBaseDO { - - /** - * 产品 ID - */ - @TableId - private Long id; - /** - * 产品名称 - */ - private String name; - /** - * 产品标识 - */ - private String productKey; - /** - * 产品分类编号 - *

- * 关联 {@link IotProductCategoryDO#getId()} - */ - private Long categoryId; - /** - * 产品图标 - */ - private String icon; - /** - * 产品图片 - */ - private String picUrl; - /** - * 产品描述 - */ - private String description; - - /** - * 产品状态 - *

- * 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum} - */ - private Integer status; - /** - * 设备类型 - *

- * 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotProductDeviceTypeEnum} - */ - private Integer deviceType; - /** - * 联网方式 - *

- * 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotNetTypeEnum} - */ - private Integer netType; - - /** - * 接入网关协议 - *

- * 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotProtocolTypeEnum} - */ - private Integer protocolType; - /** - * 协议编号 - *

- * TODO 外键:后续加 - */ - private Long protocolId; - /** - * 数据格式 - *

- * 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotDataFormatEnum} - */ - private Integer dataFormat; - /** - * 数据校验级别 - *

- * 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotValidateTypeEnum} - */ - private Integer validateType; - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotAlertConfig.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotAlertConfig.java deleted file mode 100644 index c6a2390..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotAlertConfig.java +++ /dev/null @@ -1,77 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.rule; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.module.iot.enums.rule.IotAlertConfigReceiveTypeEnum; -import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; -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.*; - -import java.util.List; - -/** - * IoT 告警配置 DO - * - * @author 芋道源码 - */ -@TableName("iot_alert_config") -@KeySequence("iot_alert_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotAlertConfig extends BaseDO { - - /** - * 配置编号 - */ - @TableId - private Long id; - /** - * 配置名称 - */ - private String name; - /** - * 配置描述 - */ - private String description; - /** - * 配置状态 - * - * TODO 数据字典 - */ - private Integer level; - /** - * 配置状态 - * - * 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum} - */ - private Integer status; - - /** - * 关联的规则场景编号数组 - * - * 关联 {@link IotRuleSceneDO#getId()} - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private List ruleSceneIds; - - /** - * 接收的用户编号数组 - * - * 关联 {@link AdminUserRespDTO#getId()} - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private List receiveUserIds; - /** - * 接收的类型数组 - * - * 枚举 {@link IotAlertConfigReceiveTypeEnum} - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private List receiveTypes; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotAlertRecordDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotAlertRecordDO.java deleted file mode 100644 index 8401110..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotAlertRecordDO.java +++ /dev/null @@ -1,77 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.rule; - -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; -import lombok.*; - -/** - * IoT 告警记录 DO - * - * @author 芋道源码 - */ -@TableName("iot_alert_record") -@KeySequence("iot_alert_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotAlertRecordDO extends BaseDO { - - /** - * 记录编号 - */ - @TableField - private Long id; - /** - * 告警名称 - * - * 冗余 {@link IotAlertConfig#getName()} - */ - private Long configId; - /** - * 告警名称 - * - * 冗余 {@link IotAlertConfig#getName()} - */ - private String name; - - /** - * 产品标识 - * - * 关联 {@link IotProductDO#getProductKey()} ()} - */ - private String productKey; - /** - * 设备名称 - * - * 冗余 {@link IotDeviceDO#getDeviceName()} - */ - private String deviceName; - - // TODO @芋艿:有没更好的方式 - /** - * 触发的设备消息 - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private IotDeviceMessage deviceMessage; - - // TODO @芋艿:换成枚举,枚举对应 ApiErrorLogProcessStatusEnum - /** - * 处理状态 - * - * true - 已处理 - * false - 未处理 - */ - private Boolean processStatus; - /** - * 处理结果(备注) - */ - private String processRemark; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotDataBridgeDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotDataBridgeDO.java deleted file mode 100644 index fed4298..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotDataBridgeDO.java +++ /dev/null @@ -1,67 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.rule; - -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeAbstractConfig; -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeDirectionEnum; -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum; -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.*; - -/** - * IoT 数据桥梁 DO - * - * @author 芋道源码 - */ -@TableName(value = "iot_data_bridge", autoResultMap = true) -@KeySequence("iot_data_bridge_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotDataBridgeDO extends BaseDO { - - /** - * 桥梁编号 - */ - @TableId - private Long id; - /** - * 桥梁名称 - */ - private String name; - /** - * 桥梁描述 - */ - private String description; - /** - * 桥梁状态 - * - * 枚举 {@link CommonStatusEnum} - */ - private Integer status; - /** - * 桥梁方向 - * - * 枚举 {@link IotDataBridgeDirectionEnum} - */ - private Integer direction; - - /** - * 桥梁类型 - * - * 枚举 {@link IotDataBridgeTypeEnum} - */ - private Integer type; - - /** - * 桥梁配置 - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private IotDataBridgeAbstractConfig config; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotRuleSceneDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotRuleSceneDO.java deleted file mode 100644 index f50101a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotRuleSceneDO.java +++ /dev/null @@ -1,243 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.dataobject.rule; - -import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerConditionParameterOperatorEnum; -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum; -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.*; - -import java.util.List; -import java.util.Map; - -/** - * IoT 规则场景(场景联动) DO - * - * @author 芋道源码 - */ -@TableName("iot_rule_scene") -@KeySequence("iot_rule_scene_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotRuleSceneDO extends TenantBaseDO { - - /** - * 场景编号 - */ - @TableId - private Long id; - /** - * 场景名称 - */ - private String name; - /** - * 场景描述 - */ - private String description; - /** - * 场景状态 - * - * 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum} - */ - private Integer status; - - /** - * 触发器数组 - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private List triggers; - - /** - * 执行器数组 - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private List actions; - - /** - * 触发器配置 - */ - @Data - public static class TriggerConfig { - - /** - * 触发类型 - * - * 枚举 {@link IotRuleSceneTriggerTypeEnum} - */ - private Integer type; - - /** - * 产品标识 - * - * 关联 {@link IotProductDO#getProductKey()} - */ - private String productKey; - /** - * 设备名称数组 - * - * 关联 {@link IotDeviceDO#getDeviceName()} - */ - private List deviceNames; - - /** - * 触发条件数组 - * - * 必填:当 {@link #type} 为 {@link IotRuleSceneTriggerTypeEnum#DEVICE} 时 - * 条件与条件之间,是“或”的关系 - */ - private List conditions; - - /** - * CRON 表达式 - * - * 必填:当 {@link #type} 为 {@link IotRuleSceneTriggerTypeEnum#TIMER} 时 - */ - private String cronExpression; - - } - - /** - * 触发条件 - */ - @Data - public static class TriggerCondition { - - /** - * 消息类型 - * - * 枚举 {@link IotDeviceMessageTypeEnum} - */ - private String type; - /** - * 消息标识符 - * - * 枚举 {@link IotDeviceMessageIdentifierEnum} - */ - private String identifier; - - /** - * 参数数组 - * - * 参数与参数之间,是“或”的关系 - */ - private List parameters; - - } - - /** - * 触发条件参数 - */ - @Data - public static class TriggerConditionParameter { - - /** - * 标识符(属性、事件、服务) - * - * 关联 {@link IotThingModelDO#getIdentifier()} - */ - private String identifier; - - /** - * 操作符 - * - * 枚举 {@link IotRuleSceneTriggerConditionParameterOperatorEnum} - */ - private String operator; - - /** - * 比较值 - * - * 如果有多个值,则使用 "," 分隔,类似 "1,2,3"。 - * 例如说,{@link IotRuleSceneTriggerConditionParameterOperatorEnum#IN}、{@link IotRuleSceneTriggerConditionParameterOperatorEnum#BETWEEN} - */ - private String value; - - } - - /** - * 执行器配置 - */ - @Data - public static class ActionConfig { - - /** - * 执行类型 - * - * 枚举 {@link IotRuleSceneActionTypeEnum} - */ - private Integer type; - - /** - * 设备控制 - * - * 必填:当 {@link #type} 为 {@link IotRuleSceneActionTypeEnum#DEVICE_CONTROL} 时 - */ - private ActionDeviceControl deviceControl; - - /** - * 数据桥接编号 - * - * 必填:当 {@link #type} 为 {@link IotRuleSceneActionTypeEnum#DATA_BRIDGE} 时 - * 关联:{@link IotDataBridgeDO#getId()} - */ - private Long dataBridgeId; - - } - - /** - * 执行设备控制 - */ - @Data - public static class ActionDeviceControl { - - /** - * 产品标识 - * - * 关联 {@link IotProductDO#getProductKey()} - */ - private String productKey; - /** - * 设备名称数组 - * - * 关联 {@link IotDeviceDO#getDeviceName()} - */ - private List deviceNames; - - /** - * 消息类型 - * - * 枚举 {@link IotDeviceMessageTypeEnum#PROPERTY}、{@link IotDeviceMessageTypeEnum#SERVICE} - */ - private String type; - /** - * 消息标识符 - * - * 枚举 {@link IotDeviceMessageIdentifierEnum} - * - * 1. 属性设置:对应 {@link IotDeviceMessageIdentifierEnum#PROPERTY_SET} - * 2. 服务调用:对应 {@link IotDeviceMessageIdentifierEnum#SERVICE_INVOKE} - */ - private String identifier; - - /** - * 具体数据 - * - * 1. 属性设置:在 {@link #type} 是 {@link IotDeviceMessageTypeEnum#PROPERTY} 时,对应 properties - * 2. 服务调用:在 {@link #type} 是 {@link IotDeviceMessageTypeEnum#SERVICE} 时,对应 params - */ - private Map data; - - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thingmodel/IotThingModelDO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thingmodel/IotThingModelDO.java deleted file mode 100644 index e3b4a6d..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/thingmodel/IotThingModelDO.java +++ /dev/null @@ -1,91 +0,0 @@ -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.IotThingModelTypeEnum; -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 IotThingModelDO} 是“一对多”的关系,它的每个属性、事件、服务都对应一条记录 - * - * @author 芋道源码 - */ -@TableName(value = "iot_thing_model", autoResultMap = true) -@KeySequence("iot_thing_model_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class IotThingModelDO 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 IotThingModelTypeEnum} - */ - 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/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceGroupMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceGroupMapper.java deleted file mode 100644 index 1f80ae4..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceGroupMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.device; - -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.device.vo.group.IotDeviceGroupPageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceGroupDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -/** - * IoT 设备分组 Mapper - * - * @author 芋道源码 - */ -@Mapper -public interface IotDeviceGroupMapper extends BaseMapperX { - - default PageResult selectPage(IotDeviceGroupPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(IotDeviceGroupDO::getName, reqVO.getName()) - .betweenIfPresent(IotDeviceGroupDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(IotDeviceGroupDO::getId)); - } - - default List selectListByStatus(Integer status) { - return selectList(IotDeviceGroupDO::getStatus, status); - } - - default IotDeviceGroupDO selectByName(String name) { - return selectOne(IotDeviceGroupDO::getName, name); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java deleted file mode 100644 index babbf29..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java +++ /dev/null @@ -1,96 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.device; - -import cn.hutool.core.util.ObjectUtil; -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.device.vo.device.IotDevicePageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import org.apache.ibatis.annotations.Mapper; - -import javax.annotation.Nullable; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; - -/** - * IoT 设备 Mapper - * - * @author 芋道源码 - */ -@Mapper -public interface IotDeviceMapper extends BaseMapperX { - - default PageResult selectPage(IotDevicePageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(IotDeviceDO::getDeviceName, reqVO.getDeviceName()) - .eqIfPresent(IotDeviceDO::getProductId, reqVO.getProductId()) - .eqIfPresent(IotDeviceDO::getDeviceType, reqVO.getDeviceType()) - .likeIfPresent(IotDeviceDO::getNickname, reqVO.getNickname()) - .eqIfPresent(IotDeviceDO::getState, reqVO.getStatus()) - .apply(ObjectUtil.isNotNull(reqVO.getGroupId()), "FIND_IN_SET(" + reqVO.getGroupId() + ",group_ids) > 0") - .orderByDesc(IotDeviceDO::getId)); - } - - default IotDeviceDO selectByDeviceName(String deviceName) { - return selectOne(IotDeviceDO::getDeviceName, deviceName); - } - - default IotDeviceDO selectByProductKeyAndDeviceName(String productKey, String deviceName) { - return selectOne(IotDeviceDO::getProductKey, productKey, - IotDeviceDO::getDeviceName, deviceName); - } - - default long selectCountByGatewayId(Long id) { - return selectCount(IotDeviceDO::getGatewayId, id); - } - - default Long selectCountByProductId(Long productId) { - return selectCount(IotDeviceDO::getProductId, productId); - } - - default IotDeviceDO selectByDeviceKey(String deviceKey) { - return selectOne(new LambdaQueryWrapper() - .apply("LOWER(device_key) = {0}", deviceKey.toLowerCase())); - } - - default List selectListByDeviceType(Integer deviceType) { - return selectList(IotDeviceDO::getDeviceType, deviceType); - } - - default List selectListByState(Integer state) { - return selectList(IotDeviceDO::getState, state); - } - - default List selectListByProductId(Long productId) { - return selectList(IotDeviceDO::getProductId, productId); - } - - default Long selectCountByGroupId(Long groupId) { - return selectCount(new LambdaQueryWrapperX() - .apply("FIND_IN_SET(" + groupId + ",group_ids) > 0")); - } - - default Long selectCountByCreateTime(@Nullable LocalDateTime createTime) { - return selectCount(new LambdaQueryWrapperX() - .geIfPresent(IotDeviceDO::getCreateTime, createTime)); - } - - /** - * 查询指定产品下各状态的设备数量 - * - * @return 设备数量统计列表 - */ - // TODO @super:通过 mybatis-plus 来写哈,然后返回 Map 貌似就行了?! - List> selectDeviceCountMapByProductId(); - - // TODO @super:通过 mybatis-plus 来写哈,然后返回 Map 貌似就行了?! - /** - * 查询各个状态下的设备数量 - * - * @return 设备数量统计列表 - */ - List> selectDeviceCountGroupByState(); - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaFirmwareMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaFirmwareMapper.java deleted file mode 100644 index 7adf793..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaFirmwareMapper.java +++ /dev/null @@ -1,41 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.ota; - -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.ota.vo.firmware.IotOtaFirmwarePageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -// TODO @li:参考 IotOtaUpgradeRecordMapper 的写法 -@Mapper -public interface IotOtaFirmwareMapper extends BaseMapperX { - - /** - * 根据产品ID和固件版本号查询固件信息列表。 - * - * @param productId 产品ID,用于筛选固件信息。 - * @param version 固件版本号,用于筛选固件信息。 - * @return 返回符合条件的固件信息列表。 - */ - default List selectByProductIdAndVersion(String productId, String version) { - return selectList(IotOtaFirmwareDO::getProductId, productId, - IotOtaFirmwareDO::getVersion, version); - } - - /** - * 分页查询固件信息,支持根据名称和产品ID进行筛选,并按创建时间降序排列。 - * - * @param pageReqVO 分页查询请求对象,包含分页参数和筛选条件。 - * @return 返回分页查询结果,包含符合条件的固件信息列表。 - */ - default PageResult selectPage(IotOtaFirmwarePageReqVO pageReqVO) { - return selectPage(pageReqVO, new LambdaQueryWrapperX() - .likeIfPresent(IotOtaFirmwareDO::getName, pageReqVO.getName()) - .eqIfPresent(IotOtaFirmwareDO::getProductId, pageReqVO.getProductId()) - .orderByDesc(IotOtaFirmwareDO::getCreateTime)); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaUpgradeRecordMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaUpgradeRecordMapper.java deleted file mode 100644 index 5e5d820..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaUpgradeRecordMapper.java +++ /dev/null @@ -1,159 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.ota; - -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.ota.vo.upgrade.record.IotOtaUpgradeRecordPageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaUpgradeRecordDO; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; - -import java.util.List; -import java.util.Map; - -@Mapper -public interface IotOtaUpgradeRecordMapper extends BaseMapperX { - - // TODO @li:selectByFirmwareIdAndTaskIdAndDeviceId;让方法自解释 - /** - * 根据条件查询单个OTA升级记录 - * - * @param firmwareId 固件ID,可选参数,用于筛选固件ID匹配的记录 - * @param taskId 任务ID,可选参数,用于筛选任务ID匹配的记录 - * @param deviceId 设备ID,可选参数,用于筛选设备ID匹配的记录 - * @return 返回符合条件的单个OTA升级记录,如果不存在则返回null - */ - default IotOtaUpgradeRecordDO selectByConditions(Long firmwareId, Long taskId, String deviceId) { - // 使用LambdaQueryWrapperX构建查询条件,根据传入的参数动态添加查询条件 - return selectOne(new LambdaQueryWrapperX() - .eqIfPresent(IotOtaUpgradeRecordDO::getFirmwareId, firmwareId) - .eqIfPresent(IotOtaUpgradeRecordDO::getTaskId, taskId) - .eqIfPresent(IotOtaUpgradeRecordDO::getDeviceId, deviceId)); - } - - // TODO @li:这个是不是 groupby status 就 ok 拉? - /** - * 根据任务ID和设备名称查询OTA升级记录的状态统计信息。 - * 该函数通过SQL查询统计不同状态(0到5)的记录数量,并返回一个包含统计结果的Map列表。 - * - * @param taskId 任务ID,用于筛选特定任务的OTA升级记录。 - * @param deviceName 设备名称,支持模糊查询,用于筛选特定设备的OTA升级记录。 - * @return 返回一个Map列表,每个Map包含不同状态(0到5)的记录数量。 - */ - @Select("select count(case when status = 0 then 1 else 0) as `0` " + - "count(case when status = 1 then 1 else 0) as `1` " + - "count(case when status = 2 then 1 else 0) as `2` " + - "count(case when status = 3 then 1 else 0) as `3` " + - "count(case when status = 4 then 1 else 0) as `4` " + - "count(case when status = 5 then 1 else 0) as `5` " + - "from iot_ota_upgrade_record " + - "where task_id = #{taskId} " + - "and device_name like concat('%', #{deviceName}, '%') " + - "and status = #{status}") - List> selectOtaUpgradeRecordCount(@Param("taskId") Long taskId, - @Param("deviceName") String deviceName); - - /** - * 根据固件ID查询OTA升级记录的状态统计信息。 - * 该函数通过SQL查询统计不同状态(0到5)的记录数量,并返回一个包含统计结果的Map列表。 - * - * @param firmwareId 固件ID,用于筛选特定固件的OTA升级记录。 - * @return 返回一个Map列表,每个Map包含不同状态(0到5)的记录数量。 - */ - @Select("select count(case when status = 0 then 1 else 0) as `0` " + - "count(case when status = 1 then 1 else 0) as `1` " + - "count(case when status = 2 then 1 else 0) as `2` " + - "count(case when status = 3 then 1 else 0) as `3` " + - "count(case when status = 4 then 1 else 0) as `4` " + - "count(case when status = 5 then 1 else 0) as `5` " + - "from iot_ota_upgrade_record " + - "where firmware_id = #{firmwareId}") - List> selectOtaUpgradeRecordStatistics(Long firmwareId); - - // TODO @li:这里的注释,可以去掉哈 - /** - * 根据分页查询条件获取 OTA升级记录的分页结果 - * - * @param pageReqVO 分页查询请求参数,包含设备名称、任务ID等查询条件 - * @return 返回分页查询结果,包含符合条件的 OTA升级记录列表 - */ - // TODO @li:selectPage 就 ok 拉。 - default PageResult selectUpgradeRecordPage(IotOtaUpgradeRecordPageReqVO pageReqVO) { - // TODO @li:这里的注释,可以去掉哈;然后下面的“如果”。。。也没必要注释 - // 使用LambdaQueryWrapperX构建查询条件,并根据请求参数动态添加查询条件 - return selectPage(pageReqVO, new LambdaQueryWrapperX() - .likeIfPresent(IotOtaUpgradeRecordDO::getDeviceName, pageReqVO.getDeviceName()) // 如果设备名称存在,则添加模糊查询条件 - .eqIfPresent(IotOtaUpgradeRecordDO::getTaskId, pageReqVO.getTaskId())); // 如果任务ID存在,则添加等值查询条件 - } - - // TODO @li:这里的注释,可以去掉哈 - /** - * 根据任务ID和状态更新升级记录的状态 - *

- * 该函数用于将符合指定任务ID和状态的升级记录的状态更新为新的状态。 - * - * @param setStatus 要设置的新状态值,类型为Integer - * @param taskId 要更新的升级记录对应的任务ID,类型为Long - * @param whereStatus 用于筛选升级记录的当前状态值,类型为Integer - */ - // TODO @li:改成 updateByTaskIdAndStatus(taskId, status, IotOtaUpgradeRecordDO) 更通用一些。 - default void updateUpgradeRecordStatusByTaskIdAndStatus(Integer setStatus, Long taskId, Integer whereStatus) { - // 使用LambdaUpdateWrapper构建更新条件,将指定状态的记录更新为指定状态 - update(new LambdaUpdateWrapper() - .set(IotOtaUpgradeRecordDO::getStatus, setStatus) - .eq(IotOtaUpgradeRecordDO::getTaskId, taskId) - .eq(IotOtaUpgradeRecordDO::getStatus, whereStatus) - ); - } - - // TODO @li:参考上面的建议,调整下这个方法 - /** - * 根据状态查询符合条件的升级记录列表 - *

- * 该函数使用LambdaQueryWrapperX构建查询条件,查询指定状态的升级记录。 - * - * @param state 升级记录的状态,用于筛选符合条件的记录 - * @return 返回符合指定状态的升级记录列表,类型为List - */ - default List selectUpgradeRecordListByState(Integer state) { - // 使用LambdaQueryWrapperX构建查询条件,根据状态查询符合条件的升级记录 - return selectList(new LambdaQueryWrapperX() - .eq(IotOtaUpgradeRecordDO::getStatus, state)); - } - - // TODO @li:参考上面的建议,调整下这个方法 - /** - * 更新升级记录状态 - *

- * 该函数用于批量更新指定ID列表中的升级记录状态。通过传入的ID列表和状态值,使用LambdaUpdateWrapper构建更新条件, - * 并执行更新操作。 - * - * @param ids 需要更新的升级记录ID列表,类型为List。传入的ID列表中的记录将被更新。 - * @param status 要更新的状态值,类型为Integer。该值将被设置到符合条件的升级记录中。 - */ - default void updateUpgradeRecordStatus(List ids, Integer status) { - // 使用LambdaUpdateWrapper构建更新条件,设置状态字段,并根据ID列表进行筛选 - update(new LambdaUpdateWrapper() - .set(IotOtaUpgradeRecordDO::getStatus, status) - .in(IotOtaUpgradeRecordDO::getId, ids) - ); - } - - // TODO @li:参考上面的建议,调整下这个方法 - /** - * 根据任务ID查询升级记录列表 - *

- * 该函数通过任务ID查询符合条件的升级记录,并返回查询结果列表。 - * - * @param taskId 任务ID,用于筛选升级记录 - * @return 返回符合条件的升级记录列表,若未找到则返回空列表 - */ - default List selectUpgradeRecordListByTaskId(Long taskId) { - // 使用LambdaQueryWrapperX构建查询条件,根据任务ID查询符合条件的升级记录 - return selectList(new LambdaQueryWrapperX() - .eq(IotOtaUpgradeRecordDO::getTaskId, taskId)); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaUpgradeTaskMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaUpgradeTaskMapper.java deleted file mode 100644 index d955b13..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaUpgradeTaskMapper.java +++ /dev/null @@ -1,57 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.ota; - -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.ota.vo.upgrade.task.IotOtaUpgradeTaskPageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaUpgradeTaskDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -/** - * OTA 升级任务Mapper - * - * @author Shelly - */ -@Mapper -public interface IotOtaUpgradeTaskMapper extends BaseMapperX { - - /** - * 根据固件ID和任务名称查询升级任务列表。 - * - * @param firmwareId 固件ID,用于筛选升级任务 - * @param name 任务名称,用于筛选升级任务 - * @return 符合条件的升级任务列表 - */ - default List selectByFirmwareIdAndName(Long firmwareId, String name) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(IotOtaUpgradeTaskDO::getFirmwareId, firmwareId) - .eqIfPresent(IotOtaUpgradeTaskDO::getName, name)); - } - - /** - * 分页查询升级任务列表,支持根据固件ID和任务名称进行筛选。 - * - * @param pageReqVO 分页查询请求对象,包含分页参数和筛选条件 - * @return 分页结果,包含符合条件的升级任务列表 - */ - default PageResult selectUpgradeTaskPage(IotOtaUpgradeTaskPageReqVO pageReqVO) { - return selectPage(pageReqVO, new LambdaQueryWrapperX() - .eqIfPresent(IotOtaUpgradeTaskDO::getFirmwareId, pageReqVO.getFirmwareId()) - .likeIfPresent(IotOtaUpgradeTaskDO::getName, pageReqVO.getName())); - } - - /** - * 根据任务状态查询升级任务列表 - *

- * 该函数通过传入的任务状态,查询数据库中符合条件的升级任务列表。 - * - * @param status 任务状态,用于筛选升级任务的状态值 - * @return 返回符合条件的升级任务列表,列表中的每个元素为 IotOtaUpgradeTaskDO 对象 - */ - default List selectUpgradeTaskByState(Integer status) { - return selectList(IotOtaUpgradeTaskDO::getStatus, status); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/plugin/IotPluginConfigMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/plugin/IotPluginConfigMapper.java deleted file mode 100644 index 0e2163a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/plugin/IotPluginConfigMapper.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.plugin; - -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.plugin.vo.config.PluginConfigPageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginConfigDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -@Mapper -public interface IotPluginConfigMapper extends BaseMapperX { - - default PageResult selectPage(PluginConfigPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(IotPluginConfigDO::getName, reqVO.getName()) - .eqIfPresent(IotPluginConfigDO::getStatus, reqVO.getStatus()) - .orderByDesc(IotPluginConfigDO::getId)); - } - - default List selectListByStatusAndDeployType(Integer status, Integer deployType) { - return selectList(new LambdaQueryWrapperX() - .eq(IotPluginConfigDO::getStatus, status) - .eq(IotPluginConfigDO::getDeployType, deployType) - .orderByAsc(IotPluginConfigDO::getId)); - } - - default IotPluginConfigDO selectByPluginKey(String pluginKey) { - return selectOne(IotPluginConfigDO::getPluginKey, pluginKey); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/plugin/IotPluginInstanceMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/plugin/IotPluginInstanceMapper.java deleted file mode 100644 index 93ffe87..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/plugin/IotPluginInstanceMapper.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.plugin; - -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginInstanceDO; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import org.apache.ibatis.annotations.Mapper; - -import java.time.LocalDateTime; -import java.util.List; - -// TODO @li:参考 IotOtaUpgradeRecordMapper 的写法 -@Mapper -public interface IotPluginInstanceMapper extends BaseMapperX { - - default IotPluginInstanceDO selectByProcessId(String processId) { - return selectOne(IotPluginInstanceDO::getProcessId, processId); - } - - default List selectListByHeartbeatTimeLt(LocalDateTime heartbeatTime) { - return selectList(new LambdaQueryWrapper() - .lt(IotPluginInstanceDO::getHeartbeatTime, heartbeatTime)); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductCategoryMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductCategoryMapper.java deleted file mode 100644 index dc9367b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductCategoryMapper.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.product; - -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.product.vo.category.IotProductCategoryPageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; -import org.apache.ibatis.annotations.Mapper; - -import javax.annotation.Nullable; -import java.time.LocalDateTime; -import java.util.List; - -/** - * IoT 产品分类 Mapper - * - * @author 芋道源码 - */ -@Mapper -public interface IotProductCategoryMapper extends BaseMapperX { - - default PageResult selectPage(IotProductCategoryPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(IotProductCategoryDO::getName, reqVO.getName()) - .betweenIfPresent(IotProductCategoryDO::getCreateTime, reqVO.getCreateTime()) - .orderByAsc(IotProductCategoryDO::getSort)); - } - - default List selectListByStatus(Integer status) { - return selectList(IotProductCategoryDO::getStatus, status); - } - - default Long selectCountByCreateTime(@Nullable LocalDateTime createTime) { - return selectCount(new LambdaQueryWrapperX() - .geIfPresent(IotProductCategoryDO::getCreateTime, createTime)); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductMapper.java deleted file mode 100644 index 5ba4a81..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductMapper.java +++ /dev/null @@ -1,41 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.product; - -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.product.vo.product.IotProductPageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import org.apache.ibatis.annotations.Mapper; - -import javax.annotation.Nullable; -import java.time.LocalDateTime; -import java.util.List; - -/** - * IoT 产品 Mapper - * - * @author ahh - */ -@Mapper -public interface IotProductMapper extends BaseMapperX { - - default PageResult selectPage(IotProductPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(IotProductDO::getName, reqVO.getName()) - .likeIfPresent(IotProductDO::getProductKey, reqVO.getProductKey()) - .orderByDesc(IotProductDO::getId)); - } - - default IotProductDO selectByProductKey(String productKey) { - return selectOne(new LambdaQueryWrapper() - .apply("LOWER(product_key) = {0}", productKey.toLowerCase())); - } - - default Long selectCountByCreateTime(@Nullable LocalDateTime createTime) { - return selectCount(new LambdaQueryWrapperX() - .geIfPresent(IotProductDO::getCreateTime, createTime)); - } - - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/rule/IotDataBridgeMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/rule/IotDataBridgeMapper.java deleted file mode 100644 index 3035791..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/rule/IotDataBridgeMapper.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.rule; - -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.rule.vo.databridge.IotDataBridgePageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; -import org.apache.ibatis.annotations.Mapper; - -/** - * IoT 数据桥梁 Mapper - * - * @author HUIHUI - */ -@Mapper -public interface IotDataBridgeMapper extends BaseMapperX { - - default PageResult selectPage(IotDataBridgePageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(IotDataBridgeDO::getName, reqVO.getName()) - .eqIfPresent(IotDataBridgeDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(IotDataBridgeDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(IotDataBridgeDO::getId)); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/rule/IotRuleSceneMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/rule/IotRuleSceneMapper.java deleted file mode 100644 index e5e069a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/rule/IotRuleSceneMapper.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.mysql.rule; - -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; -import org.apache.ibatis.annotations.Mapper; - -@Mapper -public interface IotRuleSceneMapper extends BaseMapperX { - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thingmodel/IotThingModelMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thingmodel/IotThingModelMapper.java deleted file mode 100644 index 082386b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thingmodel/IotThingModelMapper.java +++ /dev/null @@ -1,88 +0,0 @@ -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.IotThingModelListReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; -import org.apache.ibatis.annotations.Mapper; - -import java.time.LocalDateTime; -import java.util.List; - -/** - * IoT 产品物模型 Mapper - * - * @author 芋道源码 - */ -@Mapper -public interface IotThingModelMapper extends BaseMapperX { - - default PageResult selectPage(IotThingModelPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(IotThingModelDO::getIdentifier, reqVO.getIdentifier()) - .likeIfPresent(IotThingModelDO::getName, reqVO.getName()) - .eqIfPresent(IotThingModelDO::getType, reqVO.getType()) - .eqIfPresent(IotThingModelDO::getProductId, reqVO.getProductId()) - // TODO @芋艿:看看要不要加枚举 - .notIn(IotThingModelDO::getIdentifier, "get", "set", "post") - .orderByDesc(IotThingModelDO::getId)); - } - - default List selectList(IotThingModelListReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .eqIfPresent(IotThingModelDO::getIdentifier, reqVO.getIdentifier()) - .likeIfPresent(IotThingModelDO::getName, reqVO.getName()) - .eqIfPresent(IotThingModelDO::getType, reqVO.getType()) - .eqIfPresent(IotThingModelDO::getProductId, reqVO.getProductId()) - // TODO @芋艿:看看要不要加枚举 - .notIn(IotThingModelDO::getIdentifier, "get", "set", "post") - .orderByDesc(IotThingModelDO::getId)); - } - - default IotThingModelDO selectByProductIdAndIdentifier(Long productId, String identifier) { - return selectOne(IotThingModelDO::getProductId, productId, - IotThingModelDO::getIdentifier, identifier); - } - - default List selectListByProductId(Long productId) { - return selectList(IotThingModelDO::getProductId, productId); - } - - default List selectListByProductKey(String productKey) { - return selectList(IotThingModelDO::getProductKey, productKey); - } - - default List selectListByProductIdAndType(Long productId, Integer type) { - return selectList(IotThingModelDO::getProductId, productId, - IotThingModelDO::getType, type); - } - - default List selectListByProductIdAndIdentifiersAndTypes(Long productId, - List identifiers, - List types) { - return selectList(new LambdaQueryWrapperX() - .eq(IotThingModelDO::getProductId, productId) - .in(IotThingModelDO::getIdentifier, identifiers) - .in(IotThingModelDO::getType, types)); - } - - default IotThingModelDO selectByProductIdAndName(Long productId, String name) { - return selectOne(IotThingModelDO::getProductId, productId, - IotThingModelDO::getName, name); - } - - // TODO @super:用不到,删除下; - /** - * 统计物模型数量 - * - * @param createTime 创建时间,如果为空,则统计所有物模型数量 - * @return 物模型数量 - */ - default Long selectCountByCreateTime(LocalDateTime createTime) { - return selectCount(new LambdaQueryWrapperX() - .geIfPresent(IotThingModelDO::getCreateTime, createTime)); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/RedisKeyConstants.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/RedisKeyConstants.java deleted file mode 100644 index d09dac7..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/RedisKeyConstants.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.redis; - -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginInstanceDO; - -/** - * IoT Redis Key 枚举类 - * - * @author 芋道源码 - */ -public interface RedisKeyConstants { - - /** - * 设备属性的数据缓存,采用 HASH 结构 - *

- * KEY 格式:device_property:{deviceKey} - * HASH KEY:identifier 属性标识 - * VALUE 数据类型:String(JSON) {@link IotDevicePropertyDO} - */ - String DEVICE_PROPERTY = "iot:device_property:%s"; - - /** - * 设备的最后上报时间,采用 ZSET 结构 - * - * KEY 格式:{deviceKey} - * SCORE:上报时间 - */ - String DEVICE_REPORT_TIMES = "iot:device_report_times"; - - /** - * 设备信息的数据缓存,使用 Spring Cache 操作(忽略租户) - * - * KEY 格式:device_${productKey}_${deviceKey} - * VALUE 数据类型:String(JSON) - */ - String DEVICE = "iot:device"; - - /** - * 物模型的数据缓存,使用 Spring Cache 操作(忽略租户) - * - * KEY 格式:thing_model_${productKey} - * VALUE 数据类型:String 数组(JSON),即 {@link cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO} 列表 - */ - String THING_MODEL_LIST = "iot:thing_model_list"; - - /** - * 设备插件的插件进程编号的映射,采用 HASH 结构 - * - * KEY 格式:device_plugin_instance_process_ids - * HASH KEY:${deviceKey} - * VALUE:插件进程编号,对应 {@link IotPluginInstanceDO#getProcessId()} 字段 - */ - String DEVICE_PLUGIN_INSTANCE_PROCESS_IDS = "iot:device_plugin_instance_process_ids"; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/device/DevicePropertyRedisDAO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/device/DevicePropertyRedisDAO.java deleted file mode 100644 index 0f1196a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/device/DevicePropertyRedisDAO.java +++ /dev/null @@ -1,50 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.redis.device; - -import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; -import jakarta.annotation.Resource; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.stereotype.Repository; - -import java.util.Collections; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; -import static cn.iocoder.yudao.module.iot.dal.redis.RedisKeyConstants.DEVICE_PROPERTY; - -/** - * {@link IotDevicePropertyDO} 的 Redis DAO - */ -@Repository -public class DevicePropertyRedisDAO { - - @Resource - private StringRedisTemplate stringRedisTemplate; - - public Map get(String deviceKey) { - String redisKey = formatKey(deviceKey); - Map entries = stringRedisTemplate.opsForHash().entries(redisKey); - if (CollUtil.isEmpty(entries)) { - return Collections.emptyMap(); - } - return convertMap(entries.entrySet(), - entry -> (String) entry.getKey(), - entry -> JsonUtils.parseObject((String) entry.getValue(), IotDevicePropertyDO.class)); - } - - public void putAll(String deviceKey, Map properties) { - if (CollUtil.isEmpty(properties)) { - return; - } - String redisKey = formatKey(deviceKey); - stringRedisTemplate.opsForHash().putAll(redisKey, convertMap(properties.entrySet(), - Map.Entry::getKey, - entry -> JsonUtils.toJsonString(entry.getValue()))); - } - - private static String formatKey(String deviceKey) { - return String.format(DEVICE_PROPERTY, deviceKey); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/device/DeviceReportTimeRedisDAO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/device/DeviceReportTimeRedisDAO.java deleted file mode 100644 index d84af75..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/device/DeviceReportTimeRedisDAO.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.redis.device; - -import cn.hutool.core.date.LocalDateTimeUtil; -import cn.iocoder.yudao.module.iot.dal.redis.RedisKeyConstants; -import jakarta.annotation.Resource; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.stereotype.Repository; - -import java.time.LocalDateTime; -import java.util.Set; - -/** - * 设备的最后上报时间的 Redis DAO - * - * @author 芋道源码 - */ -@Repository -public class DeviceReportTimeRedisDAO { - - @Resource - private StringRedisTemplate stringRedisTemplate; - - public void update(String deviceKey, LocalDateTime reportTime) { - stringRedisTemplate.opsForZSet().add(RedisKeyConstants.DEVICE_REPORT_TIMES, deviceKey, - LocalDateTimeUtil.toEpochMilli(reportTime)); - } - - public Set range(LocalDateTime maxReportTime) { - return stringRedisTemplate.opsForZSet().rangeByScore(RedisKeyConstants.DEVICE_REPORT_TIMES, 0, - LocalDateTimeUtil.toEpochMilli(maxReportTime)); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/plugin/DevicePluginProcessIdRedisDAO.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/plugin/DevicePluginProcessIdRedisDAO.java deleted file mode 100644 index 32559d7..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/redis/plugin/DevicePluginProcessIdRedisDAO.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.redis.plugin; - -import cn.iocoder.yudao.module.iot.dal.redis.RedisKeyConstants; -import jakarta.annotation.Resource; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.stereotype.Repository; - -/** - * 设备插件的插件进程编号的缓存的 Redis DAO - */ -@Repository -public class DevicePluginProcessIdRedisDAO { - - @Resource - private StringRedisTemplate stringRedisTemplate; - - public void put(String deviceKey, String processId) { - stringRedisTemplate.opsForHash().put(RedisKeyConstants.DEVICE_PLUGIN_INSTANCE_PROCESS_IDS, deviceKey, processId); - } - - public String get(String deviceKey) { - return (String) stringRedisTemplate.opsForHash().get(RedisKeyConstants.DEVICE_PLUGIN_INSTANCE_PROCESS_IDS, deviceKey); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogMapper.java deleted file mode 100644 index 96741e6..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogMapper.java +++ /dev/null @@ -1,76 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.tdengine; - -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogPageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; -import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS; -import com.baomidou.mybatisplus.annotation.InterceptorIgnore; -import com.baomidou.mybatisplus.core.metadata.IPage; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; - -import java.util.List; -import java.util.Map; - -/** - * 设备日志 {@link IotDeviceLogDO} Mapper 接口 - */ -@Mapper -@TDengineDS -@InterceptorIgnore(tenantLine = "true") // 避免 SQL 解析,因为 JSqlParser 对 TDengine 的 SQL 解析会报错 -public interface IotDeviceLogMapper { - - /** - * 创建设备日志超级表 - */ - void createDeviceLogSTable(); - - /** - * 查询设备日志表是否存在 - * - * @return 存在则返回表名;不存在则返回 null - */ - String showDeviceLogSTable(); - - /** - * 插入设备日志数据 - * - * 如果子表不存在,会自动创建子表 - * - * @param log 设备日志数据 - */ - void insert(IotDeviceLogDO log); - - /** - * 获得设备日志分页 - * - * @param reqVO 分页查询条件 - * @return 设备日志列表 - */ - IPage selectPage(IPage page, - @Param("reqVO") IotDeviceLogPageReqVO reqVO); - - /** - * 统计设备日志数量 - * - * @param createTime 创建时间,如果为空,则统计所有日志数量 - * @return 日志数量 - */ - Long selectCountByCreateTime(@Param("createTime") Long createTime); - - // TODO @super:1)上行、下行,不写在 mapper 里,而是通过参数传递,这样,selectDeviceLogUpCountByHour、selectDeviceLogDownCountByHour 可以合并; - // TODO @super:2)不能只基于 identifier 来计算,而是要 type + identifier 成对 - /** - * 查询每个小时设备上行消息数量 - */ - List> selectDeviceLogUpCountByHour(@Param("deviceKey") String deviceKey, - @Param("startTime") Long startTime, - @Param("endTime") Long endTime); - - /** - * 查询每个小时设备下行消息数量 - */ - List> selectDeviceLogDownCountByHour(@Param("deviceKey") String deviceKey, - @Param("startTime") Long startTime, - @Param("endTime") Long endTime); - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDevicePropertyMapper.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDevicePropertyMapper.java deleted file mode 100644 index 37a72e4..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDevicePropertyMapper.java +++ /dev/null @@ -1,90 +0,0 @@ -package cn.iocoder.yudao.module.iot.dal.tdengine; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.framework.tdengine.core.TDengineTableField; -import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS; -import com.baomidou.mybatisplus.annotation.InterceptorIgnore; -import com.baomidou.mybatisplus.core.metadata.IPage; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -@Mapper -@TDengineDS -@InterceptorIgnore(tenantLine = "true") // 避免 SQL 解析,因为 JSqlParser 对 TDengine 的 SQL 解析会报错 -public interface IotDevicePropertyMapper { - - List getProductPropertySTableFieldList(@Param("productKey") String productKey); - - void createProductPropertySTable(@Param("productKey") String productKey, - @Param("fields") List fields); - - @SuppressWarnings("SimplifyStreamApiCallChains") // 保持 JDK8 兼容性 - default void alterProductPropertySTable(String productKey, - List oldFields, - List newFields) { - oldFields.removeIf(field -> StrUtil.equalsAny(field.getField(), - TDengineTableField.FIELD_TS, "report_time", "device_key")); - List addFields = newFields.stream().filter( // 新增的字段 - newField -> oldFields.stream().noneMatch(oldField -> oldField.getField().equals(newField.getField()))) - .collect(Collectors.toList()); - List dropFields = oldFields.stream().filter( // 删除的字段 - oldField -> newFields.stream().noneMatch(n -> n.getField().equals(oldField.getField()))) - .collect(Collectors.toList()); - List modifyTypeFields = new ArrayList<>(); // 变更类型的字段 - List modifyLengthFields = new ArrayList<>(); // 变更长度的字段 - newFields.forEach(newField -> { - TDengineTableField oldField = CollUtil.findOne(oldFields, field -> field.getField().equals(newField.getField())); - if (oldField == null) { - return; - } - if (ObjectUtil.notEqual(oldField.getType(), newField.getType())) { - modifyTypeFields.add(newField); - return; - } - if (newField.getLength() != null) { - if (newField.getLength() > oldField.getLength()) { - modifyLengthFields.add(newField); - } else if (newField.getLength() < oldField.getLength()) { - // 特殊:TDengine 长度修改时,只允许变长,所以此时认为是修改类型 - modifyTypeFields.add(newField); - } - } - }); - - // 执行 - addFields.forEach(field -> alterProductPropertySTableAddField(productKey, field)); - dropFields.forEach(field -> alterProductPropertySTableDropField(productKey, field)); - modifyLengthFields.forEach(field -> alterProductPropertySTableModifyField(productKey, field)); - modifyTypeFields.forEach(field -> { - alterProductPropertySTableDropField(productKey, field); - alterProductPropertySTableAddField(productKey, field); - }); - } - - void alterProductPropertySTableAddField(@Param("productKey") String productKey, - @Param("field") TDengineTableField field); - - void alterProductPropertySTableModifyField(@Param("productKey") String productKey, - @Param("field") TDengineTableField field); - - void alterProductPropertySTableDropField(@Param("productKey") String productKey, - @Param("field") TDengineTableField field); - - void insert(@Param("device") IotDeviceDO device, - @Param("properties") Map properties, - @Param("reportTime") Long reportTime); - - IPage selectPageByHistory(IPage page, - @Param("reqVO") IotDevicePropertyHistoryPageReqVO reqVO); - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/job/config/IotJobConfiguration.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/job/config/IotJobConfiguration.java deleted file mode 100644 index 7cd6f09..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/job/config/IotJobConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.iot.framework.job.config; - -import cn.iocoder.yudao.module.iot.framework.job.core.IotSchedulerManager; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.sql.DataSource; - -/** - * IoT 模块的 Job 自动配置类 - * - * @author 芋道源码 - */ -@Configuration -public class IotJobConfiguration { - - @Bean(initMethod = "start", destroyMethod = "stop") - public IotSchedulerManager iotSchedulerManager(DataSource dataSource, - ApplicationContext applicationContext) { - return new IotSchedulerManager(dataSource, applicationContext); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/job/core/IotSchedulerManager.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/job/core/IotSchedulerManager.java deleted file mode 100644 index 015b9ec..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/job/core/IotSchedulerManager.java +++ /dev/null @@ -1,186 +0,0 @@ -package cn.iocoder.yudao.module.iot.framework.job.core; - -import lombok.extern.slf4j.Slf4j; -import org.quartz.*; -import org.springframework.context.ApplicationContext; -import org.springframework.scheduling.quartz.SchedulerFactoryBean; -import org.springframework.scheduling.quartz.SpringBeanJobFactory; - -import javax.sql.DataSource; -import java.util.Map; -import java.util.Properties; - -/** - * IoT 模块的 Scheduler 管理类,基于 Quartz 实现 - * - * 疑问:为什么 IoT 模块不复用全局的 SchedulerManager 呢? - * 回复:yudao-cloud 项目,使用的是 XXL-Job 作为调度中心,无法动态添加任务。 - * - * @author 芋道源码 - */ -@Slf4j -public class IotSchedulerManager { - - private static final String SCHEDULER_NAME = "iotScheduler"; - - private final SchedulerFactoryBean schedulerFactoryBean; - - private Scheduler scheduler; - - public IotSchedulerManager(DataSource dataSource, - ApplicationContext applicationContext) { - // 1. 参考 SchedulerFactoryBean 类 - SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); - SpringBeanJobFactory jobFactory = new SpringBeanJobFactory(); - jobFactory.setApplicationContext(applicationContext); - schedulerFactoryBean.setJobFactory(jobFactory); - schedulerFactoryBean.setAutoStartup(true); - schedulerFactoryBean.setSchedulerName(SCHEDULER_NAME); - schedulerFactoryBean.setDataSource(dataSource); - schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(true); - Properties properties = new Properties(); - schedulerFactoryBean.setQuartzProperties(properties); - // 2. 参考 application-local.yaml 配置文件 - // 2.1 Scheduler 相关配置 - properties.put("org.quartz.scheduler.instanceName", SCHEDULER_NAME); - properties.put("org.quartz.scheduler.instanceId", "AUTO"); - // 2.2 JobStore 相关配置 - properties.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore"); - properties.put("org.quartz.jobStore.isClustered", "true"); - properties.put("org.quartz.jobStore.clusterCheckinInterval", "15000"); - properties.put("org.quartz.jobStore.misfireThreshold", "60000"); - // 2.3 线程池相关配置 - properties.put("org.quartz.threadPool.threadCount", "25"); - properties.put("org.quartz.threadPool.threadPriority", "5"); - properties.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); - this.schedulerFactoryBean = schedulerFactoryBean; - } - - public void start() throws Exception { - log.info("[start][Scheduler 初始化开始]"); - // 初始化 - schedulerFactoryBean.afterPropertiesSet(); - schedulerFactoryBean.start(); - // 获得 Scheduler 对象 - this.scheduler = schedulerFactoryBean.getScheduler(); - log.info("[start][Scheduler 初始化完成]"); - } - - public void stop() { - log.info("[stop][Scheduler 关闭开始]"); - schedulerFactoryBean.stop(); - this.scheduler = null; - log.info("[stop][Scheduler 关闭完成]"); - } - - // ========== 参考 SchedulerManager 实现 ========== - - /** - * 添加或更新 Job 到 Quartz 中 - * - * @param jobClass 任务处理器的类 - * @param jobName 任务名 - * @param cronExpression CRON 表达式 - * @param jobDataMap 任务数据 - * @throws SchedulerException 添加异常 - */ - public void addOrUpdateJob(Class jobClass, String jobName, - String cronExpression, Map jobDataMap) - throws SchedulerException { - if (scheduler.checkExists(new JobKey(jobName))) { - this.updateJob(jobName, cronExpression); - } else { - this.addJob(jobClass, jobName, cronExpression, jobDataMap); - } - } - - /** - * 添加 Job 到 Quartz 中 - * - * @param jobClass 任务处理器的类 - * @param jobName 任务名 - * @param cronExpression CRON 表达式 - * @param jobDataMap 任务数据 - * @throws SchedulerException 添加异常 - */ - public void addJob(Class jobClass, String jobName, - String cronExpression, Map jobDataMap) - throws SchedulerException { - // 创建 JobDetail 对象 - JobDetail jobDetail = JobBuilder.newJob(jobClass) - .usingJobData(new JobDataMap(jobDataMap)) - .withIdentity(jobName).build(); - // 创建 Trigger 对象 - Trigger trigger = this.buildTrigger(jobName, cronExpression); - // 新增 Job 调度 - scheduler.scheduleJob(jobDetail, trigger); - } - - /** - * 更新 Job 到 Quartz - * - * @param jobName 任务名 - * @param cronExpression CRON 表达式 - * @throws SchedulerException 更新异常 - */ - public void updateJob(String jobName, String cronExpression) - throws SchedulerException { - // 创建新 Trigger 对象 - Trigger newTrigger = this.buildTrigger(jobName, cronExpression); - // 修改调度 - scheduler.rescheduleJob(new TriggerKey(jobName), newTrigger); - } - - /** - * 删除 Quartz 中的 Job - * - * @param jobName 任务名 - * @throws SchedulerException 删除异常 - */ - public void deleteJob(String jobName) throws SchedulerException { - // 暂停 Trigger 对象 - scheduler.pauseTrigger(new TriggerKey(jobName)); - // 取消并删除 Job 调度 - scheduler.unscheduleJob(new TriggerKey(jobName)); - scheduler.deleteJob(new JobKey(jobName)); - } - - /** - * 暂停 Quartz 中的 Job - * - * @param jobName 任务名 - * @throws SchedulerException 暂停异常 - */ - public void pauseJob(String jobName) throws SchedulerException { - scheduler.pauseJob(new JobKey(jobName)); - } - - /** - * 启动 Quartz 中的 Job - * - * @param jobName 任务名 - * @throws SchedulerException 启动异常 - */ - public void resumeJob(String jobName) throws SchedulerException { - scheduler.resumeJob(new JobKey(jobName)); - scheduler.resumeTrigger(new TriggerKey(jobName)); - } - - /** - * 立即触发一次 Quartz 中的 Job - * - * @param jobName 任务名 - * @throws SchedulerException 触发异常 - */ - public void triggerJob(String jobName) throws SchedulerException { - scheduler.triggerJob(new JobKey(jobName)); - } - - private Trigger buildTrigger(String jobName, String cronExpression) { - return TriggerBuilder.newTrigger() - .withIdentity(jobName) - .withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)) - .build(); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/package-info.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/package-info.java deleted file mode 100644 index 234cad8..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * 属于 iot 模块的 framework 封装 - * - * @author ahh - */ -package cn.iocoder.yudao.module.iot.framework; diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/config/IotPluginConfiguration.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/config/IotPluginConfiguration.java deleted file mode 100644 index 0a2812a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/config/IotPluginConfiguration.java +++ /dev/null @@ -1,46 +0,0 @@ -package cn.iocoder.yudao.module.iot.framework.plugin.config; - -import cn.iocoder.yudao.module.iot.framework.plugin.core.IotPluginStartRunner; -import cn.iocoder.yudao.module.iot.framework.plugin.core.IotPluginStateListener; -import cn.iocoder.yudao.module.iot.service.plugin.IotPluginConfigService; -import lombok.extern.slf4j.Slf4j; -import org.pf4j.spring.SpringPluginManager; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.nio.file.Paths; - -/** - * IoT 插件配置类 - * - * @author haohao - */ -@Configuration -@Slf4j -public class IotPluginConfiguration { - - @Bean - public IotPluginStartRunner pluginStartRunner(SpringPluginManager pluginManager, - IotPluginConfigService pluginConfigService) { - return new IotPluginStartRunner(pluginManager, pluginConfigService); - } - - // TODO @芋艿:需要 review 下 - @Bean - public SpringPluginManager pluginManager(@Value("${pf4j.pluginsDir:pluginsDir}") String pluginsDir) { - log.info("[init][实例化 SpringPluginManager]"); - SpringPluginManager springPluginManager = new SpringPluginManager(Paths.get(pluginsDir)) { - - @Override - public void startPlugins() { - // 禁用插件启动,避免插件启动时,启动所有插件 - log.info("[init][禁用默认启动所有插件]"); - } - - }; - springPluginManager.addPluginStateListener(new IotPluginStateListener()); - return springPluginManager; - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/core/IotPluginStartRunner.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/core/IotPluginStartRunner.java deleted file mode 100644 index 64d2585..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/core/IotPluginStartRunner.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.iocoder.yudao.module.iot.framework.plugin.core; - -import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; -import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginConfigDO; -import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginDeployTypeEnum; -import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum; -import cn.iocoder.yudao.module.iot.service.plugin.IotPluginConfigService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.pf4j.spring.SpringPluginManager; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; - -import java.util.List; - -/** - * IoT 插件启动 Runner - * - * 用于 Spring Boot 启动时,启动 {@link IotPluginDeployTypeEnum#JAR} 部署类型的插件 - */ -@RequiredArgsConstructor -@Slf4j -public class IotPluginStartRunner implements ApplicationRunner { - - private final SpringPluginManager springPluginManager; - - private final IotPluginConfigService pluginConfigService; - - @Override - public void run(ApplicationArguments args) { - List pluginConfigList = TenantUtils.executeIgnore( - () -> pluginConfigService.getPluginConfigListByStatusAndDeployType( - IotPluginStatusEnum.RUNNING.getStatus(), IotPluginDeployTypeEnum.JAR.getDeployType())); - if (CollUtil.isEmpty(pluginConfigList)) { - log.info("[run][没有需要启动的插件]"); - return; - } - - // 遍历插件列表,逐个启动 - pluginConfigList.forEach(pluginConfig -> { - try { - log.info("[run][插件({}) 启动开始]", pluginConfig.getPluginKey()); - springPluginManager.startPlugin(pluginConfig.getPluginKey()); - log.info("[run][插件({}) 启动完成]", pluginConfig.getPluginKey()); - } catch (Exception e) { - log.error("[run][插件({}) 启动异常]", pluginConfig.getPluginKey(), e); - } - }); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/core/IotPluginStateListener.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/core/IotPluginStateListener.java deleted file mode 100644 index bbc73c6..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/core/IotPluginStateListener.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.module.iot.framework.plugin.core; - -import lombok.extern.slf4j.Slf4j; -import org.pf4j.PluginStateEvent; -import org.pf4j.PluginStateListener; - -/** - * IoT 插件状态监听器,用于 log 插件的状态变化 - * - * @author haohao - */ -@Slf4j -public class IotPluginStateListener implements PluginStateListener { - - @Override - public void pluginStateChanged(PluginStateEvent event) { - log.info("[pluginStateChanged][插件({}) 状态变化,从 {} 变为 {}]", event.getPlugin().getPluginId(), - event.getOldState().toString(), event.getPluginState().toString()); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/security/config/SecurityConfiguration.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/security/config/SecurityConfiguration.java deleted file mode 100644 index 9cf00cc..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/security/config/SecurityConfiguration.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.yudao.module.iot.framework.security.config; - -import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer; -import cn.iocoder.yudao.module.iot.enums.ApiConstants; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer; - -/** - * IoT 模块的 Security 配置 - */ -@Configuration(proxyBeanMethods = false, value = "iotSecurityConfiguration") -public class SecurityConfiguration { - - @Bean("iotAuthorizeRequestsCustomizer") - public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() { - return new AuthorizeRequestsCustomizer() { - - @Override - public void customize(AuthorizeHttpRequestsConfigurer.AuthorizationManagerRequestMatcherRegistry registry) { - // RPC 服务的安全配置 - registry.requestMatchers(ApiConstants.PREFIX + "/**").permitAll(); - } - - }; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/security/core/package-info.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/security/core/package-info.java deleted file mode 100644 index c714d10..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/security/core/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * 占位 - */ -package cn.iocoder.yudao.module.iot.framework.security.core; diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/config/TDengineTableInitRunner.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/config/TDengineTableInitRunner.java deleted file mode 100644 index 3517e1e..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/config/TDengineTableInitRunner.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.module.iot.framework.tdengine.config; - -import cn.iocoder.yudao.module.iot.service.device.data.IotDeviceLogService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.stereotype.Component; - -/** - * TDengine 表初始化的 Configuration - * - * @author alwayssuper - */ -@Component -@RequiredArgsConstructor -@Slf4j -public class TDengineTableInitRunner implements ApplicationRunner { - - private final IotDeviceLogService deviceLogService; - - @Override - public void run(ApplicationArguments args) { - try { - // 初始化设备日志表 - deviceLogService.defineDeviceLog(); - } catch (Exception ex) { - // 初始化失败时打印错误日志并退出系统 - log.error("[run][TDengine初始化设备日志表结构失败,系统无法正常运行,即将退出]", ex); - System.exit(1); - } - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/core/TDengineTableField.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/core/TDengineTableField.java deleted file mode 100644 index e3bbdd2..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/core/TDengineTableField.java +++ /dev/null @@ -1,58 +0,0 @@ -package cn.iocoder.yudao.module.iot.framework.tdengine.core; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * TDEngine 表字段 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class TDengineTableField { - - /** - * 字段名 - TDengine 默认 ts 字段,默认会被 TDengine 创建 - */ - public static final String FIELD_TS = "ts"; - - public static final String TYPE_TINYINT = "TINYINT"; - public static final String TYPE_INT = "INT"; - public static final String TYPE_FLOAT = "FLOAT"; - public static final String TYPE_DOUBLE = "DOUBLE"; - public static final String TYPE_BOOL = "BOOL"; - public static final String TYPE_NCHAR = "NCHAR"; - public static final String TYPE_TIMESTAMP = "TIMESTAMP"; - - /** - * 注释 - TAG 字段 - */ - public static final String NOTE_TAG = "TAG"; - - /** - * 字段名 - */ - private String field; - - /** - * 字段类型 - */ - private String type; - - /** - * 字段长度 - */ - private Integer length; - - /** - * 注释 - */ - private String note; - - public TDengineTableField(String field, String type) { - this.field = field; - this.type = type; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/core/annotation/TDengineDS.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/core/annotation/TDengineDS.java deleted file mode 100644 index e3960d0..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/core/annotation/TDengineDS.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation; - -import com.baomidou.dynamic.datasource.annotation.DS; - -import java.lang.annotation.*; - -/** - * TDEngine 数据源 - * - * @author 芋道源码 - */ -@Target({ElementType.TYPE, ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@DS("tdengine") -public @interface TDengineDS { -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/package-info.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/package-info.java deleted file mode 100644 index f92428f..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * iot 模块的 tdengine 拓展封装 - */ -package cn.iocoder.yudao.module.iot.framework.tdengine; \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/web/config/IotWebConfiguration.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/web/config/IotWebConfiguration.java deleted file mode 100644 index 6b3cc6a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/web/config/IotWebConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.iot.framework.web.config; - -import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration; -import org.springdoc.core.models.GroupedOpenApi; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * iot 模块的 web 组件的 Configuration - * - * @author ahh - */ -@Configuration(proxyBeanMethods = false) -public class IotWebConfiguration { - - /** - * iot 模块的 API 分组 - */ - @Bean - public GroupedOpenApi iotGroupedOpenApi() { - return YudaoSwaggerAutoConfiguration.buildGroupedOpenApi("iot"); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/web/package-info.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/web/package-info.java deleted file mode 100644 index aafcca2..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/web/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * iot 模块的 web 拓展封装 - */ -package cn.iocoder.yudao.module.iot.framework.web; diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/device/IotDeviceOfflineCheckJob.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/device/IotDeviceOfflineCheckJob.java deleted file mode 100644 index 4e9e9ec..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/device/IotDeviceOfflineCheckJob.java +++ /dev/null @@ -1,75 +0,0 @@ -package cn.iocoder.yudao.module.iot.job.device; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.IdUtil; -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; -import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotDeviceStateUpdateReqDTO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStateEnum; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -import cn.iocoder.yudao.module.iot.service.device.data.IotDevicePropertyService; -import cn.iocoder.yudao.module.iot.service.device.control.IotDeviceUpstreamService; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Component; - -import java.time.Duration; -import java.time.LocalDateTime; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -/** - * IoT 设备离线检查 Job - * - * 检测逻辑:设备最后一条 {@link cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage} 消息超过一定时间,则认为设备离线 - * - * @author 芋道源码 - */ -@Component -public class IotDeviceOfflineCheckJob implements JobHandler { - - /** - * 设备离线超时时间 - * - * TODO 芋艿:暂定 10 分钟,后续看看要不要基于设备或者全局有配置文件 - */ - public static final Duration OFFLINE_TIMEOUT = Duration.ofMinutes(10); - - @Resource - private IotDeviceService deviceService; - @Resource - private IotDevicePropertyService devicePropertyService; - @Resource - private IotDeviceUpstreamService deviceUpstreamService; - - @Override - @TenantJob - public String execute(String param) { - // 1.1 获得在线设备列表 - List devices = deviceService.getDeviceListByState(IotDeviceStateEnum.ONLINE.getState()); - if (CollUtil.isEmpty(devices)) { - return JsonUtils.toJsonString(Collections.emptyList()); - } - // 1.2 获取超时的 deviceKey 集合 - Set timeoutDeviceKeys = devicePropertyService.getDeviceKeysByReportTime( - LocalDateTime.now().minus(OFFLINE_TIMEOUT)); - - // 2. 下线设备 - List offlineDeviceKeys = CollUtil.newArrayList(); - for (IotDeviceDO device : devices) { - if (!timeoutDeviceKeys.contains(device.getDeviceKey())) { - continue; - } - offlineDeviceKeys.add(device.getDeviceKey()); - // 为什么不直接更新状态呢?因为通过 IotDeviceMessage 可以经过一系列的处理,例如说记录日志等等 - deviceUpstreamService.updateDeviceState(((IotDeviceStateUpdateReqDTO) - new IotDeviceStateUpdateReqDTO().setRequestId(IdUtil.fastSimpleUUID()).setReportTime(LocalDateTime.now()) - .setProductKey(device.getProductKey()).setDeviceName(device.getDeviceName())) - .setState((IotDeviceStateEnum.OFFLINE.getState()))); - } - return JsonUtils.toJsonString(offlineDeviceKeys); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/plugin/IotPluginInstancesJob.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/plugin/IotPluginInstancesJob.java deleted file mode 100644 index ff93dc8..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/plugin/IotPluginInstancesJob.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.yudao.module.iot.job.plugin; - -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; -import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; -import cn.iocoder.yudao.module.iot.service.plugin.IotPluginInstanceService; -import org.springframework.stereotype.Component; - -import jakarta.annotation.Resource; -import java.time.Duration; -import java.time.LocalDateTime; - -/** - * IoT 插件实例离线检查 Job - * - * @author 芋道源码 - */ -@Component -public class IotPluginInstancesJob implements JobHandler { - - /** - * 插件离线超时时间 - * - * TODO 芋艿:暂定 10 分钟,后续看要不要做配置 - */ - public static final Duration OFFLINE_TIMEOUT = Duration.ofMinutes(10); - - @Resource - private IotPluginInstanceService pluginInstanceService; - - @Override - @TenantJob - public String execute(String param) { - int count = pluginInstanceService.offlineTimeoutPluginInstance( - LocalDateTime.now().minus(OFFLINE_TIMEOUT)); - return StrUtil.format("离线超时插件实例数量为: {}", count); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/rule/IotRuleSceneJob.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/rule/IotRuleSceneJob.java deleted file mode 100644 index 594f9ef..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/rule/IotRuleSceneJob.java +++ /dev/null @@ -1,58 +0,0 @@ -package cn.iocoder.yudao.module.iot.job.rule; - -import cn.hutool.core.map.MapUtil; -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum; -import cn.iocoder.yudao.module.iot.service.rule.IotRuleSceneService; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.quartz.JobExecutionContext; -import org.springframework.scheduling.quartz.QuartzJobBean; - -import java.util.Map; - -/** - * IoT 规则场景 Job,用于执行 {@link IotRuleSceneTriggerTypeEnum#TIMER} 类型的规则场景 - * - * @author 芋道源码 - */ -@Slf4j -public class IotRuleSceneJob extends QuartzJobBean { - - /** - * JobData Key - 规则场景编号 - */ - public static final String JOB_DATA_KEY_RULE_SCENE_ID = "ruleSceneId"; - - @Resource - private IotRuleSceneService ruleSceneService; - - @Override - protected void executeInternal(JobExecutionContext context) { - // 获得规则场景编号 - Long ruleSceneId = context.getMergedJobDataMap().getLong(JOB_DATA_KEY_RULE_SCENE_ID); - - // 执行规则场景 - ruleSceneService.executeRuleSceneByTimer(ruleSceneId); - } - - /** - * 创建 JobData Map - * - * @param ruleSceneId 规则场景编号 - * @return JobData Map - */ - public static Map buildJobDataMap(Long ruleSceneId) { - return MapUtil.of(JOB_DATA_KEY_RULE_SCENE_ID, ruleSceneId); - } - - /** - * 创建 Job 名字 - * - * @param ruleSceneId 规则场景编号 - * @return Job 名字 - */ - public static String buildJobName(Long ruleSceneId) { - return String.format("%s_%d", IotRuleSceneJob.class.getSimpleName(), ruleSceneId); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/device/IotDeviceLogMessageConsumer.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/device/IotDeviceLogMessageConsumer.java deleted file mode 100644 index 2972677..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/device/IotDeviceLogMessageConsumer.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.mq.consumer.device; - -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import cn.iocoder.yudao.module.iot.service.device.data.IotDeviceLogService; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; - -/** - * 针对 {@link IotDeviceMessage} 的消费者,记录设备日志 - * - * @author 芋道源码 - */ -@Component -@Slf4j -public class IotDeviceLogMessageConsumer { - - @Resource - private IotDeviceLogService deviceLogService; - - @EventListener - @Async - public void onMessage(IotDeviceMessage message) { - log.info("[onMessage][消息内容({})]", message); - deviceLogService.createDeviceLog(message); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/device/IotDeviceOnlineMessageConsumer.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/device/IotDeviceOnlineMessageConsumer.java deleted file mode 100644 index f0e49bd..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/device/IotDeviceOnlineMessageConsumer.java +++ /dev/null @@ -1,85 +0,0 @@ -package cn.iocoder.yudao.module.iot.mq.consumer.device; - -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotDeviceStateUpdateReqDTO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStateEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -import cn.iocoder.yudao.module.iot.service.device.control.IotDeviceUpstreamService; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; - -import java.time.LocalDateTime; -import java.util.Objects; - -/** - * 针对 {@link IotDeviceMessage} 的消费者,将离线的设备,自动标记为上线 - * - * 注意:只有设备上行消息,才会触发该逻辑 - * - * @author 芋道源码 - */ -@Component -@Slf4j -public class IotDeviceOnlineMessageConsumer { - - @Resource - private IotDeviceService deviceService; - - @Resource - private IotDeviceUpstreamService deviceUpstreamService; - - @EventListener - @Async - public void onMessage(IotDeviceMessage message) { - // 1.1 只处理上行消息。因为,只有设备上行的消息,才会触发设备上线的逻辑 - if (!isUpstreamMessage(message)) { - return; - } - // 1.2 如果设备已在线,则不做处理 - log.info("[onMessage][消息内容({})]", message); - IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceNameFromCache( - message.getProductKey(), message.getDeviceName()); - if (device == null) { - log.error("[onMessage][消息({}) 对应的设备部存在]", message); - return; - } - if (IotDeviceStateEnum.isOnline(device.getState())) { - return; - } - - // 2. 标记设备为在线 - // 为什么不直接更新状态呢?因为通过 IotDeviceMessage 可以经过一系列的处理,例如说记录日志等等 - deviceUpstreamService.updateDeviceState(((IotDeviceStateUpdateReqDTO) - new IotDeviceStateUpdateReqDTO().setRequestId(IdUtil.fastSimpleUUID()).setReportTime(LocalDateTime.now()) - .setProductKey(device.getProductKey()).setDeviceName(device.getDeviceName())) - .setState((IotDeviceStateEnum.ONLINE.getState()))); - } - - private boolean isUpstreamMessage(IotDeviceMessage message) { - // 设备属性 - if (Objects.equals(message.getType(), IotDeviceMessageTypeEnum.PROPERTY.getType()) - && Objects.equals(message.getIdentifier(), IotDeviceMessageIdentifierEnum.PROPERTY_REPORT.getIdentifier())) { - return true; - } - // 设备事件 - if (Objects.equals(message.getType(), IotDeviceMessageTypeEnum.EVENT.getType())) { - return true; - } - // 设备服务 - // noinspection RedundantIfStatement - if (Objects.equals(message.getType(), IotDeviceMessageTypeEnum.SERVICE.getType()) - && !StrUtil.endWith(message.getIdentifier(), IotDeviceMessageIdentifierEnum.SERVICE_REPLY_SUFFIX.getIdentifier())) { - return true; - } - return false; - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/device/IotDevicePropertyMessageConsumer.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/device/IotDevicePropertyMessageConsumer.java deleted file mode 100644 index bf9cc53..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/device/IotDevicePropertyMessageConsumer.java +++ /dev/null @@ -1,40 +0,0 @@ -package cn.iocoder.yudao.module.iot.mq.consumer.device; - -import cn.hutool.core.util.ObjectUtil; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import cn.iocoder.yudao.module.iot.service.device.data.IotDevicePropertyService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; - -import jakarta.annotation.Resource; - -/** - * 针对 {@link IotDeviceMessage} 的消费者,记录设备属性 - * - * @author alwayssuper - */ -@Component -@Slf4j -public class IotDevicePropertyMessageConsumer { - - @Resource - private IotDevicePropertyService deviceDataService; - - @EventListener - @Async - public void onMessage(IotDeviceMessage message) { - if (ObjectUtil.notEqual(message.getType(), IotDeviceMessageTypeEnum.PROPERTY.getType()) - || ObjectUtil.notEqual(message.getIdentifier(), IotDeviceMessageIdentifierEnum.PROPERTY_REPORT.getIdentifier())) { - return; - } - log.info("[onMessage][消息内容({})]", message); - - // 保存设备属性 - deviceDataService.saveDeviceProperty(message); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/rule/IotRuleSceneMessageHandler.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/rule/IotRuleSceneMessageHandler.java deleted file mode 100644 index e6ea3e2..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/rule/IotRuleSceneMessageHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.yudao.module.iot.mq.consumer.rule; - -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import cn.iocoder.yudao.module.iot.service.rule.IotRuleSceneService; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; - -/** - * 针对 {@link IotDeviceMessage} 的消费者,处理规则场景 - * - * @author 芋道源码 - */ -@Component -@Slf4j -public class IotRuleSceneMessageHandler { - - @Resource - private IotRuleSceneService ruleSceneService; - - @EventListener - @Async - public void onMessage(IotDeviceMessage message) { - log.info("[onMessage][消息内容({})]", message); - ruleSceneService.executeRuleSceneByDevice(message); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/message/IotDeviceMessage.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/message/IotDeviceMessage.java deleted file mode 100644 index 0e8309a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/message/IotDeviceMessage.java +++ /dev/null @@ -1,76 +0,0 @@ -package cn.iocoder.yudao.module.iot.mq.message; - -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.time.LocalDateTime; - -// TODO @芋艿:参考阿里云的物模型,优化 IoT 上下行消息的设计,尽量保持一致(渐进式,不要一口气)! -/** - * IoT 设备消息 - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -public class IotDeviceMessage { - - /** - * 请求编号 - */ - private String requestId; - - /** - * 设备信息 - */ - private String productKey; - /** - * 设备名称 - */ - private String deviceName; - /** - * 设备标识 - */ - private String deviceKey; - - /** - * 消息类型 - * - * 枚举 {@link IotDeviceMessageTypeEnum} - */ - private String type; - /** - * 标识符 - * - * 枚举 {@link IotDeviceMessageIdentifierEnum} - */ - private String identifier; - - /** - * 请求参数 - * - * 例如说:属性上报的 properties、事件上报的 params - */ - private Object data; - /** - * 响应码 - * - * 目前只有 server 下行消息给 device 设备时,才会有响应码 - */ - private Integer code; - - /** - * 上报时间 - */ - private LocalDateTime reportTime; - - /** - * 租户编号 - */ - private Long tenantId; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/device/IotDeviceProducer.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/device/IotDeviceProducer.java deleted file mode 100644 index 11d5d96..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/device/IotDeviceProducer.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.iot.mq.producer.device; - -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Component; - -/** - * IoT 设备相关消息的 Producer - * - * @author alwayssuper - * @since 2024/12/17 16:35 - */ -@Slf4j -@Component -public class IotDeviceProducer { - - @Resource - private ApplicationContext applicationContext; - - /** - * 发送 {@link IotDeviceMessage} 消息 - * - * @param thingModelMessage 物模型消息 - */ - public void sendDeviceMessage(IotDeviceMessage thingModelMessage) { - applicationContext.publishEvent(thingModelMessage); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/package-info.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/package-info.java deleted file mode 100644 index 37d0ba0..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * TODO 芋艿:临时占位 - */ -package cn.iocoder.yudao.module.iot.mq.producer; \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceGroupService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceGroupService.java deleted file mode 100644 index 5d074ad..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceGroupService.java +++ /dev/null @@ -1,97 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.ListUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.group.IotDeviceGroupPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.group.IotDeviceGroupSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceGroupDO; -import jakarta.validation.Valid; - -import java.util.Collection; -import java.util.List; - -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; - -/** - * IoT 设备分组 Service 接口 - * - * @author 芋道源码 - */ -public interface IotDeviceGroupService { - - /** - * 创建设备分组 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createDeviceGroup(@Valid IotDeviceGroupSaveReqVO createReqVO); - - /** - * 更新设备分组 - * - * @param updateReqVO 更新信息 - */ - void updateDeviceGroup(@Valid IotDeviceGroupSaveReqVO updateReqVO); - - /** - * 删除设备分组 - * - * @param id 编号 - */ - void deleteDeviceGroup(Long id); - - /** - * 校验设备分组是否存在 - * - * @param ids 设备分组 ID 数组 - */ - default List validateDeviceGroupExists(Collection ids) { - if (CollUtil.isEmpty(ids)) { - return ListUtil.empty(); - } - return convertList(ids, this::validateDeviceGroupExists); - } - - /** - * 校验设备分组是否存在 - * - * @param id 设备分组 ID - * @return 设备分组 - */ - IotDeviceGroupDO validateDeviceGroupExists(Long id); - - /** - * 获得设备分组 - * - * @param id 编号 - * @return 设备分组 - */ - IotDeviceGroupDO getDeviceGroup(Long id); - - /** - * 获得设备分组 - * - * @param name 名称 - * @return 设备分组 - */ - IotDeviceGroupDO getDeviceGroupByName(String name); - - /** - * 获得设备分组分页 - * - * @param pageReqVO 分页查询 - * @return 设备分组分页 - */ - PageResult getDeviceGroupPage(IotDeviceGroupPageReqVO pageReqVO); - - /** - * 获得设备分组列表 - * - * @param status 状态 - * @return 设备分组列表 - */ - List getDeviceGroupListByStatus(Integer status); - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceGroupServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceGroupServiceImpl.java deleted file mode 100644 index 06e5cb1..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceGroupServiceImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device; - -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.device.vo.group.IotDeviceGroupPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.group.IotDeviceGroupSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceGroupDO; -import cn.iocoder.yudao.module.iot.dal.mysql.device.IotDeviceGroupMapper; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.util.List; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_GROUP_DELETE_FAIL_DEVICE_EXISTS; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_GROUP_NOT_EXISTS; - -/** - * IoT 设备分组 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Validated -public class IotDeviceGroupServiceImpl implements IotDeviceGroupService { - - @Resource - private IotDeviceGroupMapper deviceGroupMapper; - - @Resource - private IotDeviceService deviceService; - - @Override - public Long createDeviceGroup(IotDeviceGroupSaveReqVO createReqVO) { - // 插入 - IotDeviceGroupDO deviceGroup = BeanUtils.toBean(createReqVO, IotDeviceGroupDO.class); - deviceGroupMapper.insert(deviceGroup); - // 返回 - return deviceGroup.getId(); - } - - @Override - public void updateDeviceGroup(IotDeviceGroupSaveReqVO updateReqVO) { - // 校验存在 - validateDeviceGroupExists(updateReqVO.getId()); - // 更新 - IotDeviceGroupDO updateObj = BeanUtils.toBean(updateReqVO, IotDeviceGroupDO.class); - deviceGroupMapper.updateById(updateObj); - } - - @Override - public void deleteDeviceGroup(Long id) { - // 1.1 校验存在 - validateDeviceGroupExists(id); - // 1.2 校验是否存在设备 - if (deviceService.getDeviceCountByGroupId(id) > 0) { - throw exception(DEVICE_GROUP_DELETE_FAIL_DEVICE_EXISTS); - } - - // 删除 - deviceGroupMapper.deleteById(id); - } - - @Override - public IotDeviceGroupDO validateDeviceGroupExists(Long id) { - IotDeviceGroupDO group = deviceGroupMapper.selectById(id); - if (group == null) { - throw exception(DEVICE_GROUP_NOT_EXISTS); - } - return group; - } - - @Override - public IotDeviceGroupDO getDeviceGroup(Long id) { - return deviceGroupMapper.selectById(id); - } - - @Override - public IotDeviceGroupDO getDeviceGroupByName(String name) { - return deviceGroupMapper.selectByName(name); - } - - @Override - public PageResult getDeviceGroupPage(IotDeviceGroupPageReqVO pageReqVO) { - return deviceGroupMapper.selectPage(pageReqVO); - } - - @Override - public List getDeviceGroupListByStatus(Integer status) { - return deviceGroupMapper.selectListByStatus(status); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java deleted file mode 100644 index 1dda3f3..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java +++ /dev/null @@ -1,222 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.*; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStateEnum; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; - -import javax.annotation.Nullable; -import java.time.LocalDateTime; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -/** - * IoT 设备 Service 接口 - * - * @author 芋道源码 - */ -public interface IotDeviceService { - - /** - * 【管理员】创建设备 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createDevice(@Valid IotDeviceSaveReqVO createReqVO); - - /** - * 【设备注册】创建设备 - * - * @param productKey 产品标识 - * @param deviceName 设备名称 - * @param gatewayId 网关设备 ID - * @return 设备 - */ - IotDeviceDO createDevice(@NotEmpty(message = "产品标识不能为空") String productKey, - @NotEmpty(message = "设备名称不能为空") String deviceName, - Long gatewayId); - - /** - * 更新设备 - * - * @param updateReqVO 更新信息 - */ - void updateDevice(@Valid IotDeviceSaveReqVO updateReqVO); - - // TODO @芋艿:先这么实现。未来看情况,要不要自己实现 - - /** - * 更新设备的所属网关 - * - * @param id 编号 - * @param gatewayId 网关设备 ID - */ - default void updateDeviceGateway(Long id, Long gatewayId) { - updateDevice(new IotDeviceSaveReqVO().setId(id).setGatewayId(gatewayId)); - } - - /** - * 更新设备状态 - * - * @param id 编号 - * @param state 状态 - */ - void updateDeviceState(Long id, Integer state); - - /** - * 更新设备分组 - * - * @param updateReqVO 更新信息 - */ - void updateDeviceGroup(@Valid IotDeviceUpdateGroupReqVO updateReqVO); - - /** - * 删除单个设备 - * - * @param id 编号 - */ - void deleteDevice(Long id); - - /** - * 删除多个设备 - * - * @param ids 编号数组 - */ - void deleteDeviceList(Collection ids); - - /** - * 校验设备是否存在 - * - * @param id 设备 ID - * @return 设备对象 - */ - IotDeviceDO validateDeviceExists(Long id); - - /** - * 获得设备 - * - * @param id 编号 - * @return IoT 设备 - */ - IotDeviceDO getDevice(Long id); - - /** - * 根据设备 key 获得设备 - * - * @param deviceKey 编号 - * @return IoT 设备 - */ - IotDeviceDO getDeviceByDeviceKey(String deviceKey); - - /** - * 获得设备分页 - * - * @param pageReqVO 分页查询 - * @return IoT 设备分页 - */ - PageResult getDevicePage(IotDevicePageReqVO pageReqVO); - - /** - * 基于设备类型,获得设备列表 - * - * @param deviceType 设备类型 - * @return 设备列表 - */ - List getDeviceListByDeviceType(@Nullable Integer deviceType); - - /** - * 获得状态,获得设备列表 - * - * @param state 状态 - * @return 设备列表 - */ - List getDeviceListByState(Integer state); - - /** - * 根据产品ID获取设备列表 - * - * @param productId 产品ID,用于查询特定产品的设备列表 - * @return 返回与指定产品ID关联的设备列表,列表中的每个元素为IotDeviceDO对象 - */ - List getDeviceListByProductId(Long productId); - - /** - * 根据设备ID列表获取设备信息列表 - * - * @param deviceIdList 设备ID列表,包含需要查询的设备ID - * @return 返回与设备ID列表对应的设备信息列表,列表中的每个元素为IotDeviceDO对象 - */ - List getDeviceListByIdList(List deviceIdList); - - /** - * 基于产品编号,获得设备数量 - * - * @param productId 产品编号 - * @return 设备数量 - */ - Long getDeviceCountByProductId(Long productId); - - /** - * 获得设备数量 - * - * @param groupId 分组编号 - * @return 设备数量 - */ - Long getDeviceCountByGroupId(Long groupId); - - /** - * 【缓存】根据产品 key 和设备名称,获得设备信息 - *

- * 注意:该方法会忽略租户信息,所以调用时,需要确认会不会有跨租户访问的风险!!! - * - * @param productKey 产品 key - * @param deviceName 设备名称 - * @return 设备信息 - */ - IotDeviceDO getDeviceByProductKeyAndDeviceNameFromCache(String productKey, String deviceName); - - /** - * 导入设备 - * - * @param importDevices 导入设备列表 - * @param updateSupport 是否支持更新 - * @return 导入结果 - */ - IotDeviceImportRespVO importDevice(List importDevices, boolean updateSupport); - - /** - * 获得设备数量 - * - * @param createTime 创建时间,如果为空,则统计所有设备数量 - * @return 设备数量 - */ - Long getDeviceCount(@Nullable LocalDateTime createTime); - - /** - * 获取 MQTT 连接参数 - * - * @param deviceId 设备 ID - * @return MQTT 连接参数 - */ - IotDeviceMqttConnectionParamsRespVO getMqttConnectionParams(Long deviceId); - - /** - * 获得各个产品下的设备数量 Map - * - * @return key: 产品编号, value: 设备数量 - */ - Map getDeviceCountMapByProductId(); - - /** - * 获得各个状态下的设备数量 Map - * - * @return key: 设备状态枚举 {@link IotDeviceStateEnum} - * value: 设备数量 - */ - Map getDeviceCountMapByState(); - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java deleted file mode 100644 index bfba04c..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java +++ /dev/null @@ -1,454 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.RandomUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.spring.SpringUtil; -import cn.iocoder.yudao.framework.common.exception.ServiceException; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; -import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; -import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.*; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceGroupDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.dal.mysql.device.IotDeviceMapper; -import cn.iocoder.yudao.module.iot.dal.redis.RedisKeyConstants; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStateEnum; -import cn.iocoder.yudao.module.iot.enums.product.IotProductDeviceTypeEnum; -import cn.iocoder.yudao.module.iot.service.product.IotProductService; -import cn.iocoder.yudao.module.iot.util.MqttSignUtils; -import cn.iocoder.yudao.module.iot.util.MqttSignUtils.MqttSignResult; -import jakarta.annotation.Resource; -import jakarta.validation.ConstraintViolationException; -import lombok.extern.slf4j.Slf4j; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; - -import javax.annotation.Nullable; -import java.time.LocalDateTime; -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.convertList; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*; - -/** - * IoT 设备 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Validated -@Slf4j -public class IotDeviceServiceImpl implements IotDeviceService { - - @Resource - private IotDeviceMapper deviceMapper; - - @Resource - private IotProductService productService; - @Resource - @Lazy // 延迟加载,解决循环依赖 - private IotDeviceGroupService deviceGroupService; - - @Override - public Long createDevice(IotDeviceSaveReqVO createReqVO) { - // 1.1 校验产品是否存在 - IotProductDO product = productService.getProduct(createReqVO.getProductId()); - if (product == null) { - throw exception(PRODUCT_NOT_EXISTS); - } - // 1.2 统一校验 - validateCreateDeviceParam(product.getProductKey(), createReqVO.getDeviceName(), createReqVO.getDeviceKey(), - createReqVO.getGatewayId(), product); - // 1.3 校验分组存在 - deviceGroupService.validateDeviceGroupExists(createReqVO.getGroupIds()); - - // 2. 插入到数据库 - IotDeviceDO device = BeanUtils.toBean(createReqVO, IotDeviceDO.class); - initDevice(device, product); - deviceMapper.insert(device); - return device.getId(); - } - - @Override - public IotDeviceDO createDevice(String productKey, String deviceName, Long gatewayId) { - String deviceKey = generateDeviceKey(); - // 1.1 校验产品是否存在 - IotProductDO product = TenantUtils.executeIgnore(() -> productService.getProductByProductKey(productKey)); - if (product == null) { - throw exception(PRODUCT_NOT_EXISTS); - } - return TenantUtils.execute(product.getTenantId(), () -> { - // 1.2 校验设备名称在同一产品下是否唯一 - validateCreateDeviceParam(productKey, deviceName, deviceKey, gatewayId, product); - - // 2. 插入到数据库 - IotDeviceDO device = new IotDeviceDO().setDeviceName(deviceName).setDeviceKey(deviceKey) - .setGatewayId(gatewayId); - initDevice(device, product); - deviceMapper.insert(device); - return device; - }); - } - - private void validateCreateDeviceParam(String productKey, String deviceName, String deviceKey, - Long gatewayId, IotProductDO product) { - TenantUtils.executeIgnore(() -> { - // 校验设备名称在同一产品下是否唯一 - if (deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName) != null) { - throw exception(DEVICE_NAME_EXISTS); - } - // 校验设备标识是否唯一 - if (deviceMapper.selectByDeviceKey(deviceKey) != null) { - throw exception(DEVICE_KEY_EXISTS); - } - }); - - // 校验父设备是否为合法网关 - if (IotProductDeviceTypeEnum.isGatewaySub(product.getDeviceType()) - && gatewayId != null) { - validateGatewayDeviceExists(gatewayId); - } - } - - private void initDevice(IotDeviceDO device, IotProductDO product) { - device.setProductId(product.getId()).setProductKey(product.getProductKey()) - .setDeviceType(product.getDeviceType()); - // 生成密钥 - device.setDeviceSecret(generateDeviceSecret()); - // 设置设备状态为未激活 - device.setState(IotDeviceStateEnum.INACTIVE.getState()); - } - - @Override - public void updateDevice(IotDeviceSaveReqVO updateReqVO) { - updateReqVO.setDeviceKey(null).setDeviceName(null).setProductId(null); // 不允许更新 - // 1.1 校验存在 - IotDeviceDO device = validateDeviceExists(updateReqVO.getId()); - // 1.2 校验父设备是否为合法网关 - if (IotProductDeviceTypeEnum.isGatewaySub(device.getDeviceType()) - && updateReqVO.getGatewayId() != null) { - validateGatewayDeviceExists(updateReqVO.getGatewayId()); - } - // 1.3 校验分组存在 - deviceGroupService.validateDeviceGroupExists(updateReqVO.getGroupIds()); - - // 2. 更新到数据库 - IotDeviceDO updateObj = BeanUtils.toBean(updateReqVO, IotDeviceDO.class); - deviceMapper.updateById(updateObj); - - // 3. 清空对应缓存 - deleteDeviceCache(device); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateDeviceGroup(IotDeviceUpdateGroupReqVO updateReqVO) { - // 1.1 校验设备存在 - List devices = deviceMapper.selectByIds(updateReqVO.getIds()); - if (CollUtil.isEmpty(devices)) { - return; - } - // 1.2 校验分组存在 - deviceGroupService.validateDeviceGroupExists(updateReqVO.getGroupIds()); - - // 3. 更新设备分组 - deviceMapper.updateBatch(convertList(devices, device -> new IotDeviceDO() - .setId(device.getId()).setGroupIds(updateReqVO.getGroupIds()))); - - // 4. 清空对应缓存 - deleteDeviceCache(devices); - } - - @Override - public void deleteDevice(Long id) { - // 1.1 校验存在 - IotDeviceDO device = validateDeviceExists(id); - // 1.2 如果是网关设备,检查是否有子设备 - if (device.getGatewayId() != null && deviceMapper.selectCountByGatewayId(id) > 0) { - throw exception(DEVICE_HAS_CHILDREN); - } - - // 2. 删除设备 - deviceMapper.deleteById(id); - - // 3. 清空对应缓存 - deleteDeviceCache(device); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteDeviceList(Collection ids) { - // 1.1 校验存在 - if (CollUtil.isEmpty(ids)) { - return; - } - List devices = deviceMapper.selectByIds(ids); - if (CollUtil.isEmpty(devices)) { - return; - } - // 1.2 校验网关设备是否存在 - for (IotDeviceDO device : devices) { - if (device.getGatewayId() != null && deviceMapper.selectCountByGatewayId(device.getId()) > 0) { - throw exception(DEVICE_HAS_CHILDREN); - } - } - - // 2. 删除设备 - deviceMapper.deleteByIds(ids); - - // 3. 清空对应缓存 - deleteDeviceCache(devices); - } - - @Override - public IotDeviceDO validateDeviceExists(Long id) { - IotDeviceDO device = deviceMapper.selectById(id); - if (device == null) { - throw exception(DEVICE_NOT_EXISTS); - } - return device; - } - - /** - * 校验网关设备是否存在 - * - * @param id 设备 ID - */ - private void validateGatewayDeviceExists(Long id) { - IotDeviceDO device = deviceMapper.selectById(id); - if (device == null) { - throw exception(DEVICE_GATEWAY_NOT_EXISTS); - } - if (!IotProductDeviceTypeEnum.isGateway(device.getDeviceType())) { - throw exception(DEVICE_NOT_GATEWAY); - } - } - - @Override - public IotDeviceDO getDevice(Long id) { - return deviceMapper.selectById(id); - } - - @Override - public IotDeviceDO getDeviceByDeviceKey(String deviceKey) { - return deviceMapper.selectByDeviceKey(deviceKey); - } - - @Override - public PageResult getDevicePage(IotDevicePageReqVO pageReqVO) { - return deviceMapper.selectPage(pageReqVO); - } - - @Override - public List getDeviceListByDeviceType(@Nullable Integer deviceType) { - return deviceMapper.selectListByDeviceType(deviceType); - } - - @Override - public List getDeviceListByState(Integer state) { - return deviceMapper.selectListByState(state); - } - - @Override - public List getDeviceListByProductId(Long productId) { - return deviceMapper.selectListByProductId(productId); - } - - @Override - public List getDeviceListByIdList(List deviceIdList) { - return deviceMapper.selectByIds(deviceIdList); - } - - @Override - public void updateDeviceState(Long id, Integer state) { - // 1. 校验存在 - IotDeviceDO device = validateDeviceExists(id); - - // 2. 更新状态和时间 - IotDeviceDO updateObj = new IotDeviceDO().setId(id).setState(state); - if (device.getOnlineTime() == null - && Objects.equals(state, IotDeviceStateEnum.ONLINE.getState())) { - updateObj.setActiveTime(LocalDateTime.now()); - } - if (Objects.equals(state, IotDeviceStateEnum.ONLINE.getState())) { - updateObj.setOnlineTime(LocalDateTime.now()); - } else if (Objects.equals(state, IotDeviceStateEnum.OFFLINE.getState())) { - updateObj.setOfflineTime(LocalDateTime.now()); - } - deviceMapper.updateById(updateObj); - - // 3. 清空对应缓存 - deleteDeviceCache(device); - } - - @Override - public Long getDeviceCountByProductId(Long productId) { - return deviceMapper.selectCountByProductId(productId); - } - - @Override - public Long getDeviceCountByGroupId(Long groupId) { - return deviceMapper.selectCountByGroupId(groupId); - } - - @Override - @Cacheable(value = RedisKeyConstants.DEVICE, key = "#productKey + '_' + #deviceName", unless = "#result == null") - @TenantIgnore // 忽略租户信息,跨租户 productKey + deviceName 是唯一的 - public IotDeviceDO getDeviceByProductKeyAndDeviceNameFromCache(String productKey, String deviceName) { - return deviceMapper.selectByProductKeyAndDeviceName(productKey, deviceName); - } - - /** - * 生成 deviceKey - * - * @return 生成的 deviceKey - */ - private String generateDeviceKey() { - return RandomUtil.randomString(16); - } - - /** - * 生成 deviceSecret - * - * @return 生成的 deviceSecret - */ - private String generateDeviceSecret() { - return IdUtil.fastSimpleUUID(); - } - - @Override - @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入 - public IotDeviceImportRespVO importDevice(List importDevices, boolean updateSupport) { - // 1. 参数校验 - if (CollUtil.isEmpty(importDevices)) { - throw exception(DEVICE_IMPORT_LIST_IS_EMPTY); - } - - // 2. 遍历,逐个创建 or 更新 - IotDeviceImportRespVO respVO = IotDeviceImportRespVO.builder().createDeviceNames(new ArrayList<>()) - .updateDeviceNames(new ArrayList<>()).failureDeviceNames(new LinkedHashMap<>()).build(); - importDevices.forEach(importDevice -> { - try { - // 2.1.1 校验字段是否符合要求 - try { - ValidationUtils.validate(importDevice); - } catch (ConstraintViolationException ex) { - respVO.getFailureDeviceNames().put(importDevice.getDeviceName(), ex.getMessage()); - return; - } - // 2.1.2 校验产品是否存在 - IotProductDO product = productService.validateProductExists(importDevice.getProductKey()); - // 2.1.3 校验父设备是否存在 - Long gatewayId = null; - if (StrUtil.isNotEmpty(importDevice.getParentDeviceName())) { - IotDeviceDO gatewayDevice = deviceMapper.selectByDeviceName(importDevice.getParentDeviceName()); - if (gatewayDevice == null) { - throw exception(DEVICE_GATEWAY_NOT_EXISTS); - } - if (!IotProductDeviceTypeEnum.isGateway(gatewayDevice.getDeviceType())) { - throw exception(DEVICE_NOT_GATEWAY); - } - gatewayId = gatewayDevice.getId(); - } - // 2.1.4 校验设备分组是否存在 - Set groupIds = new HashSet<>(); - if (StrUtil.isNotEmpty(importDevice.getGroupNames())) { - String[] groupNames = importDevice.getGroupNames().split(","); - for (String groupName : groupNames) { - IotDeviceGroupDO group = deviceGroupService.getDeviceGroupByName(groupName); - if (group == null) { - throw exception(DEVICE_GROUP_NOT_EXISTS); - } - groupIds.add(group.getId()); - } - } - - // 2.2.1 判断如果不存在,在进行插入 - IotDeviceDO existDevice = deviceMapper.selectByDeviceName(importDevice.getDeviceName()); - if (existDevice == null) { - createDevice(new IotDeviceSaveReqVO() - .setDeviceName(importDevice.getDeviceName()).setDeviceKey(generateDeviceKey()) - .setProductId(product.getId()).setGatewayId(gatewayId).setGroupIds(groupIds)); - respVO.getCreateDeviceNames().add(importDevice.getDeviceName()); - return; - } - // 2.2.2 如果存在,判断是否允许更新 - if (updateSupport) { - throw exception(DEVICE_KEY_EXISTS); - } - updateDevice(new IotDeviceSaveReqVO().setId(existDevice.getId()) - .setGatewayId(gatewayId).setGroupIds(groupIds)); - respVO.getUpdateDeviceNames().add(importDevice.getDeviceName()); - } catch (ServiceException ex) { - respVO.getFailureDeviceNames().put(importDevice.getDeviceName(), ex.getMessage()); - } - }); - return respVO; - } - - @Override - public IotDeviceMqttConnectionParamsRespVO getMqttConnectionParams(Long deviceId) { - IotDeviceDO device = validateDeviceExists(deviceId); - MqttSignResult mqttSignResult = MqttSignUtils.calculate(device.getProductKey(), device.getDeviceName(), - device.getDeviceSecret()); - return new IotDeviceMqttConnectionParamsRespVO() - .setMqttClientId(mqttSignResult.getClientId()) - .setMqttUsername(mqttSignResult.getUsername()) - .setMqttPassword(mqttSignResult.getPassword()); - } - - private void deleteDeviceCache(IotDeviceDO device) { - // 保证 Spring AOP 触发 - getSelf().deleteDeviceCache0(device); - } - - private void deleteDeviceCache(List devices) { - devices.forEach(this::deleteDeviceCache); - } - - @CacheEvict(value = RedisKeyConstants.DEVICE, key = "#device.productKey + '_' + #device.deviceName") - public void deleteDeviceCache0(IotDeviceDO device) { - } - - private IotDeviceServiceImpl getSelf() { - return SpringUtil.getBean(getClass()); - } - - @Override - public Long getDeviceCount(LocalDateTime createTime) { - return deviceMapper.selectCountByCreateTime(createTime); - } - - // TODO @super:简化 - @Override - public Map getDeviceCountMapByProductId() { - // 查询结果转换成Map - List> list = deviceMapper.selectDeviceCountMapByProductId(); - return list.stream().collect(Collectors.toMap( - map -> Long.valueOf(map.get("key").toString()), - map -> Integer.valueOf(map.get("value").toString()) - )); - } - - @Override - public Map getDeviceCountMapByState() { - // 查询结果转换成Map - List> list = deviceMapper.selectDeviceCountGroupByState(); - return list.stream().collect(Collectors.toMap( - map -> Integer.valueOf(map.get("key").toString()), - map -> Long.valueOf(map.get("value").toString()) - )); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceDownstreamService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceDownstreamService.java deleted file mode 100644 index f09604d..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceDownstreamService.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device.control; - -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.control.IotDeviceDownstreamReqVO; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import jakarta.validation.Valid; - -/** - * IoT 设备下行 Service 接口 - * - * 目的:服务端 -> 插件 -> 设备 - * - * @author 芋道源码 - */ -public interface IotDeviceDownstreamService { - - /** - * 设备下行,可用于设备模拟 - * - * @param downstreamReqVO 设备下行请求 VO - * @return 下发消息 - */ - IotDeviceMessage downstreamDevice(@Valid IotDeviceDownstreamReqVO downstreamReqVO); - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceDownstreamServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceDownstreamServiceImpl.java deleted file mode 100644 index 3aab53d..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceDownstreamServiceImpl.java +++ /dev/null @@ -1,354 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device.control; - -import cn.hutool.core.exceptions.ExceptionUtil; -import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.IdUtil; -import cn.iocoder.yudao.framework.common.exception.ServiceException; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.*; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.control.IotDeviceDownstreamReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginInstanceDO; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import cn.iocoder.yudao.module.iot.mq.producer.device.IotDeviceProducer; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -import cn.iocoder.yudao.module.iot.service.plugin.IotPluginInstanceService; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.client.RestTemplate; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_DOWNSTREAM_FAILED; - -/** - * IoT 设备下行 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Validated -@Slf4j -public class IotDeviceDownstreamServiceImpl implements IotDeviceDownstreamService { - - @Resource - private IotDeviceService deviceService; - @Resource - private IotPluginInstanceService pluginInstanceService; - - @Resource - private RestTemplate restTemplate; - - @Resource - private IotDeviceProducer deviceProducer; - - @Override - public IotDeviceMessage downstreamDevice(IotDeviceDownstreamReqVO downstreamReqVO) { - // 校验设备是否存在 - IotDeviceDO device = deviceService.validateDeviceExists(downstreamReqVO.getId()); - // TODO @芋艿:离线设备,不允许推送 - // TODO 芋艿:父设备的处理 - IotDeviceDO parentDevice = null; - - // 服务调用 - if (Objects.equals(downstreamReqVO.getType(), IotDeviceMessageTypeEnum.SERVICE.getType())) { - return invokeDeviceService(downstreamReqVO, device, parentDevice); - } - // 属性相关 - if (Objects.equals(downstreamReqVO.getType(), IotDeviceMessageTypeEnum.PROPERTY.getType())) { - // 属性设置 - if (Objects.equals(downstreamReqVO.getIdentifier(), - IotDeviceMessageIdentifierEnum.PROPERTY_SET.getIdentifier())) { - return setDeviceProperty(downstreamReqVO, device, parentDevice); - } - // 属性设置 - if (Objects.equals(downstreamReqVO.getIdentifier(), - IotDeviceMessageIdentifierEnum.PROPERTY_GET.getIdentifier())) { - return getDeviceProperty(downstreamReqVO, device, parentDevice); - } - } - // 配置下发 - if (Objects.equals(downstreamReqVO.getType(), IotDeviceMessageTypeEnum.CONFIG.getType()) - && Objects.equals(downstreamReqVO.getIdentifier(), - IotDeviceMessageIdentifierEnum.CONFIG_SET.getIdentifier())) { - return setDeviceConfig(downstreamReqVO, device, parentDevice); - } - // OTA 升级 - if (Objects.equals(downstreamReqVO.getType(), IotDeviceMessageTypeEnum.OTA.getType())) { - return otaUpgrade(downstreamReqVO, device, parentDevice); - } - // TODO @芋艿:取消设备的网关的时,要不要下发 REGISTER_UNREGISTER_SUB ? - throw new IllegalArgumentException("不支持的下行消息类型:" + downstreamReqVO); - } - - /** - * 调用设备服务 - * - * @param downstreamReqVO 下行请求 - * @param device 设备 - * @param parentDevice 父设备 - * @return 下发消息 - */ - @SuppressWarnings("unchecked") - private IotDeviceMessage invokeDeviceService(IotDeviceDownstreamReqVO downstreamReqVO, - IotDeviceDO device, IotDeviceDO parentDevice) { - // 1. 参数校验 - if (!(downstreamReqVO.getData() instanceof Map)) { - throw new ServiceException(BAD_REQUEST.getCode(), "data 不是 Map 类型"); - } - // TODO @super:【可优化】过滤掉不合法的服务 - - // 2. 发送请求 - String url = String.format("sys/%s/%s/thing/service/%s", - getProductKey(device, parentDevice), getDeviceName(device, parentDevice), - downstreamReqVO.getIdentifier()); - IotDeviceServiceInvokeReqDTO reqDTO = new IotDeviceServiceInvokeReqDTO() - .setParams((Map) downstreamReqVO.getData()); - CommonResult result = requestPlugin(url, reqDTO, device); - - // 3. 发送设备消息 - IotDeviceMessage message = new IotDeviceMessage().setRequestId(reqDTO.getRequestId()) - .setType(IotDeviceMessageTypeEnum.SERVICE.getType()).setIdentifier(reqDTO.getIdentifier()) - .setData(reqDTO.getParams()); - sendDeviceMessage(message, device, result.getCode()); - - // 4. 如果不成功,抛出异常,提示用户 - if (result.isError()) { - log.error("[invokeDeviceService][设备({})服务调用失败,请求参数:({}),响应结果:({})]", - device.getDeviceKey(), reqDTO, result); - throw exception(DEVICE_DOWNSTREAM_FAILED, result.getMsg()); - } - return message; - } - - /** - * 设置设备属性 - * - * @param downstreamReqVO 下行请求 - * @param device 设备 - * @param parentDevice 父设备 - * @return 下发消息 - */ - @SuppressWarnings("unchecked") - private IotDeviceMessage setDeviceProperty(IotDeviceDownstreamReqVO downstreamReqVO, - IotDeviceDO device, IotDeviceDO parentDevice) { - // 1. 参数校验 - if (!(downstreamReqVO.getData() instanceof Map)) { - throw new ServiceException(BAD_REQUEST.getCode(), "data 不是 Map 类型"); - } - // TODO @super:【可优化】过滤掉不合法的属性 - - // 2. 发送请求 - String url = String.format("sys/%s/%s/thing/service/property/set", - getProductKey(device, parentDevice), getDeviceName(device, parentDevice)); - IotDevicePropertySetReqDTO reqDTO = new IotDevicePropertySetReqDTO() - .setProperties((Map) downstreamReqVO.getData()); - CommonResult result = requestPlugin(url, reqDTO, device); - - // 3. 发送设备消息 - IotDeviceMessage message = new IotDeviceMessage().setRequestId(reqDTO.getRequestId()) - .setType(IotDeviceMessageTypeEnum.PROPERTY.getType()) - .setIdentifier(IotDeviceMessageIdentifierEnum.PROPERTY_SET.getIdentifier()) - .setData(reqDTO.getProperties()); - sendDeviceMessage(message, device, result.getCode()); - - // 4. 如果不成功,抛出异常,提示用户 - if (result.isError()) { - log.error("[setDeviceProperty][设备({})属性设置失败,请求参数:({}),响应结果:({})]", - device.getDeviceKey(), reqDTO, result); - throw exception(DEVICE_DOWNSTREAM_FAILED, result.getMsg()); - } - return message; - } - - /** - * 获取设备属性 - * - * @param downstreamReqVO 下行请求 - * @param device 设备 - * @param parentDevice 父设备 - * @return 下发消息 - */ - @SuppressWarnings("unchecked") - private IotDeviceMessage getDeviceProperty(IotDeviceDownstreamReqVO downstreamReqVO, - IotDeviceDO device, IotDeviceDO parentDevice) { - // 1. 参数校验 - if (!(downstreamReqVO.getData() instanceof List)) { - throw new ServiceException(BAD_REQUEST.getCode(), "data 不是 List 类型"); - } - // TODO @super:【可优化】过滤掉不合法的属性 - - // 2. 发送请求 - String url = String.format("sys/%s/%s/thing/service/property/get", - getProductKey(device, parentDevice), getDeviceName(device, parentDevice)); - IotDevicePropertyGetReqDTO reqDTO = new IotDevicePropertyGetReqDTO() - .setIdentifiers((List) downstreamReqVO.getData()); - CommonResult result = requestPlugin(url, reqDTO, device); - - // 3. 发送设备消息 - IotDeviceMessage message = new IotDeviceMessage().setRequestId(reqDTO.getRequestId()) - .setType(IotDeviceMessageTypeEnum.PROPERTY.getType()) - .setIdentifier(IotDeviceMessageIdentifierEnum.PROPERTY_SET.getIdentifier()) - .setData(reqDTO.getIdentifiers()); - sendDeviceMessage(message, device, result.getCode()); - - // 4. 如果不成功,抛出异常,提示用户 - if (result.isError()) { - log.error("[getDeviceProperty][设备({})属性获取失败,请求参数:({}),响应结果:({})]", - device.getDeviceKey(), reqDTO, result); - throw exception(DEVICE_DOWNSTREAM_FAILED, result.getMsg()); - } - return message; - } - - /** - * 设置设备配置 - * - * @param downstreamReqVO 下行请求 - * @param device 设备 - * @param parentDevice 父设备 - * @return 下发消息 - */ - @SuppressWarnings({ "unchecked", "unused" }) - private IotDeviceMessage setDeviceConfig(IotDeviceDownstreamReqVO downstreamReqVO, - IotDeviceDO device, IotDeviceDO parentDevice) { - // 1. 参数转换,无需校验 - Map config = JsonUtils.parseObject(device.getConfig(), Map.class); - - // 2. 发送请求 - String url = String.format("sys/%s/%s/thing/service/config/set", - getProductKey(device, parentDevice), getDeviceName(device, parentDevice)); - IotDeviceConfigSetReqDTO reqDTO = new IotDeviceConfigSetReqDTO() - .setConfig(config); - CommonResult result = requestPlugin(url, reqDTO, device); - - // 3. 发送设备消息 - IotDeviceMessage message = new IotDeviceMessage().setRequestId(reqDTO.getRequestId()) - .setType(IotDeviceMessageTypeEnum.CONFIG.getType()) - .setIdentifier(IotDeviceMessageIdentifierEnum.CONFIG_SET.getIdentifier()) - .setData(reqDTO.getConfig()); - sendDeviceMessage(message, device, result.getCode()); - - // 4. 如果不成功,抛出异常,提示用户 - if (result.isError()) { - log.error("[setDeviceConfig][设备({})配置下发失败,请求参数:({}),响应结果:({})]", - device.getDeviceKey(), reqDTO, result); - throw exception(DEVICE_DOWNSTREAM_FAILED, result.getMsg()); - } - return message; - } - - /** - * 设备 OTA 升级 - * - * @param downstreamReqVO 下行请求 - * @param device 设备 - * @param parentDevice 父设备 - * @return 下发消息 - */ - private IotDeviceMessage otaUpgrade(IotDeviceDownstreamReqVO downstreamReqVO, - IotDeviceDO device, IotDeviceDO parentDevice) { - // 1. 参数校验 - if (!(downstreamReqVO.getData() instanceof Map data)) { - throw new ServiceException(BAD_REQUEST.getCode(), "data 不是 Map 类型"); - } - - // 2. 发送请求 - String url = String.format("ota/%s/%s/upgrade", - getProductKey(device, parentDevice), getDeviceName(device, parentDevice)); - IotDeviceOtaUpgradeReqDTO reqDTO = IotDeviceOtaUpgradeReqDTO.build(data); - CommonResult result = requestPlugin(url, reqDTO, device); - - // 3. 发送设备消息 - IotDeviceMessage message = new IotDeviceMessage().setRequestId(reqDTO.getRequestId()) - .setType(IotDeviceMessageTypeEnum.OTA.getType()) - .setIdentifier(IotDeviceMessageIdentifierEnum.OTA_UPGRADE.getIdentifier()) - .setData(downstreamReqVO.getData()); - sendDeviceMessage(message, device, result.getCode()); - - // 4. 如果不成功,抛出异常,提示用户 - if (result.isError()) { - log.error("[otaUpgrade][设备({}) OTA 升级失败,请求参数:({}),响应结果:({})]", - device.getDeviceKey(), reqDTO, result); - throw exception(DEVICE_DOWNSTREAM_FAILED, result.getMsg()); - } - return message; - } - - /** - * 请求插件 - * - * @param url URL - * @param reqDTO 请求参数,只需要设置子类的参数! - * @param device 设备 - * @return 响应结果 - */ - @SuppressWarnings({ "unchecked", "HttpUrlsUsage" }) - private CommonResult requestPlugin(String url, IotDeviceDownstreamAbstractReqDTO reqDTO, - IotDeviceDO device) { - // 获得设备对应的插件实例 - IotPluginInstanceDO pluginInstance = pluginInstanceService.getPluginInstanceByDeviceKey(device.getDeviceKey()); - if (pluginInstance == null) { - throw exception(DEVICE_DOWNSTREAM_FAILED, "设备找不到对应的插件实例"); - } - - // 补充通用参数 - reqDTO.setRequestId(IdUtil.fastSimpleUUID()); - - // 执行请求 - ResponseEntity> responseEntity; - try { - responseEntity = restTemplate.postForEntity( - String.format("http://%s:%d/%s", pluginInstance.getHostIp(), pluginInstance.getDownstreamPort(), - url), - reqDTO, (Class>) (Class) CommonResult.class); - Assert.isTrue(responseEntity.getStatusCode().is2xxSuccessful(), - "HTTP 状态码不是 2xx,而是" + responseEntity.getStatusCode()); - Assert.notNull(responseEntity.getBody(), "响应结果不能为空"); - } catch (Exception ex) { - log.error("[requestPlugin][设备({}) url({}) 下行消息失败,请求参数({})]", device.getDeviceKey(), url, reqDTO, ex); - throw exception(DEVICE_DOWNSTREAM_FAILED, ExceptionUtil.getMessage(ex)); - } - return responseEntity.getBody(); - } - - private void sendDeviceMessage(IotDeviceMessage message, IotDeviceDO device, Integer code) { - // 1. 完善消息 - message.setProductKey(device.getProductKey()).setDeviceName(device.getDeviceName()) - .setDeviceKey(device.getDeviceKey()) - .setTenantId(device.getTenantId()); - Assert.notNull(message.getRequestId(), "requestId 不能为空"); - if (message.getReportTime() == null) { - message.setReportTime(LocalDateTime.now()); - } - message.setCode(code); - - // 2. 发送消息 - try { - deviceProducer.sendDeviceMessage(message); - log.info("[sendDeviceMessage][message({}) 发送消息成功]", message); - } catch (Exception e) { - log.error("[sendDeviceMessage][message({}) 发送消息失败]", message, e); - } - } - - private String getDeviceName(IotDeviceDO device, IotDeviceDO parentDevice) { - return parentDevice != null ? parentDevice.getDeviceName() : device.getDeviceName(); - } - - private String getProductKey(IotDeviceDO device, IotDeviceDO parentDevice) { - return parentDevice != null ? parentDevice.getProductKey() : device.getProductKey(); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceUpstreamService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceUpstreamService.java deleted file mode 100644 index dba529d..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceUpstreamService.java +++ /dev/null @@ -1,72 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device.control; - -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.*; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.control.IotDeviceUpstreamReqVO; -import jakarta.validation.Valid; - -/** - * IoT 设备上行 Service 接口 - * - * 目的:设备 -> 插件 -> 服务端 - * - * @author 芋道源码 - */ -public interface IotDeviceUpstreamService { - - /** - * 设备上行,可用于设备模拟 - * - * @param simulatorReqVO 设备上行请求 VO - */ - void upstreamDevice(@Valid IotDeviceUpstreamReqVO simulatorReqVO); - - /** - * 更新设备状态 - * - * @param updateReqDTO 更新设备状态 DTO - */ - void updateDeviceState(IotDeviceStateUpdateReqDTO updateReqDTO); - - /** - * 上报设备属性数据 - * - * @param reportReqDTO 上报设备属性数据 DTO - */ - void reportDeviceProperty(IotDevicePropertyReportReqDTO reportReqDTO); - - /** - * 上报设备事件数据 - * - * @param reportReqDTO 设备事件 - */ - void reportDeviceEvent(IotDeviceEventReportReqDTO reportReqDTO); - - /** - * 注册设备 - * - * @param registerReqDTO 注册设备 DTO - */ - void registerDevice(IotDeviceRegisterReqDTO registerReqDTO); - - /** - * 注册子设备 - * - * @param registerReqDTO 注册子设备 DTO - */ - void registerSubDevice(IotDeviceRegisterSubReqDTO registerReqDTO); - - /** - * 添加设备拓扑 - * - * @param addReqDTO 添加设备拓扑 DTO - */ - void addDeviceTopology(IotDeviceTopologyAddReqDTO addReqDTO); - - /** - * Emqx 连接认证 - * - * @param authReqDTO Emqx 连接认证 DTO - */ - boolean authenticateEmqxConnection(IotDeviceEmqxAuthReqDTO authReqDTO); - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceUpstreamServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceUpstreamServiceImpl.java deleted file mode 100644 index 6c80e75..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/control/IotDeviceUpstreamServiceImpl.java +++ /dev/null @@ -1,344 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device.control; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ObjUtil; -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; -import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.*; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.control.IotDeviceUpstreamReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStateEnum; -import cn.iocoder.yudao.module.iot.enums.product.IotProductDeviceTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import cn.iocoder.yudao.module.iot.mq.producer.device.IotDeviceProducer; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -import cn.iocoder.yudao.module.iot.service.device.data.IotDevicePropertyService; -import cn.iocoder.yudao.module.iot.service.plugin.IotPluginInstanceService; -import cn.iocoder.yudao.module.iot.util.MqttSignUtils; -import cn.iocoder.yudao.module.iot.util.MqttSignUtils.MqttSignResult; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.time.LocalDateTime; -import java.util.Map; -import java.util.Objects; - -/** - * IoT 设备上行 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Validated -@Slf4j -public class IotDeviceUpstreamServiceImpl implements IotDeviceUpstreamService { - - @Resource - private IotDeviceService deviceService; - @Resource - private IotDevicePropertyService devicePropertyService; - @Resource - private IotPluginInstanceService pluginInstanceService; - - @Resource - private IotDeviceProducer deviceProducer; - - @Override - @SuppressWarnings("unchecked") - public void upstreamDevice(IotDeviceUpstreamReqVO simulatorReqVO) { - // 1. 校验存在 - IotDeviceDO device = deviceService.validateDeviceExists(simulatorReqVO.getId()); - - // 2.1 情况一:属性上报 - String requestId = IdUtil.fastSimpleUUID(); - if (Objects.equals(simulatorReqVO.getType(), IotDeviceMessageTypeEnum.PROPERTY.getType())) { - reportDeviceProperty(((IotDevicePropertyReportReqDTO) new IotDevicePropertyReportReqDTO() - .setRequestId(requestId).setReportTime(LocalDateTime.now()) - .setProductKey(device.getProductKey()).setDeviceName(device.getDeviceName())) - .setProperties((Map) simulatorReqVO.getData())); - return; - } - // 2.2 情况二:事件上报 - if (Objects.equals(simulatorReqVO.getType(), IotDeviceMessageTypeEnum.EVENT.getType())) { - reportDeviceEvent(((IotDeviceEventReportReqDTO) new IotDeviceEventReportReqDTO().setRequestId(requestId) - .setReportTime(LocalDateTime.now()) - .setProductKey(device.getProductKey()).setDeviceName(device.getDeviceName())) - .setIdentifier(simulatorReqVO.getIdentifier()) - .setParams((Map) simulatorReqVO.getData())); - return; - } - // 2.3 情况三:状态变更 - if (Objects.equals(simulatorReqVO.getType(), IotDeviceMessageTypeEnum.STATE.getType())) { - updateDeviceState(((IotDeviceStateUpdateReqDTO) new IotDeviceStateUpdateReqDTO() - .setRequestId(IdUtil.fastSimpleUUID()).setReportTime(LocalDateTime.now()) - .setProductKey(device.getProductKey()).setDeviceName(device.getDeviceName())) - .setState((Integer) simulatorReqVO.getData())); - return; - } - throw new IllegalArgumentException("未知的类型:" + simulatorReqVO.getType()); - } - - @Override - public void updateDeviceState(IotDeviceStateUpdateReqDTO updateReqDTO) { - Assert.isTrue(ObjectUtils.equalsAny(updateReqDTO.getState(), - IotDeviceStateEnum.ONLINE.getState(), IotDeviceStateEnum.OFFLINE.getState()), - "状态不合法"); - // 1.1 获得设备 - log.info("[updateDeviceState][更新设备状态: {}]", updateReqDTO); - IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceNameFromCache( - updateReqDTO.getProductKey(), updateReqDTO.getDeviceName()); - if (device == null) { - log.error("[updateDeviceState][设备({}/{}) 不存在]", - updateReqDTO.getProductKey(), updateReqDTO.getDeviceName()); - return; - } - TenantUtils.execute(device.getTenantId(), () -> { - // 1.2 记录设备的最后时间 - updateDeviceLastTime(device, updateReqDTO); - // 1.3 当前状态一致,不处理 - if (Objects.equals(device.getState(), updateReqDTO.getState())) { - return; - } - - // 2. 更新设备状态 - deviceService.updateDeviceState(device.getId(), updateReqDTO.getState()); - - // 3. TODO 芋艿:子设备的关联 - - // 4. 发送设备消息 - IotDeviceMessage message = BeanUtils.toBean(updateReqDTO, IotDeviceMessage.class) - .setType(IotDeviceMessageTypeEnum.STATE.getType()) - .setIdentifier(ObjUtil.equals(updateReqDTO.getState(), IotDeviceStateEnum.ONLINE.getState()) - ? IotDeviceMessageIdentifierEnum.STATE_ONLINE.getIdentifier() - : IotDeviceMessageIdentifierEnum.STATE_OFFLINE.getIdentifier()); - sendDeviceMessage(message, device); - }); - } - - @Override - public void reportDeviceProperty(IotDevicePropertyReportReqDTO reportReqDTO) { - // 1.1 获得设备 - log.info("[reportDeviceProperty][上报设备属性: {}]", reportReqDTO); - IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceNameFromCache( - reportReqDTO.getProductKey(), reportReqDTO.getDeviceName()); - if (device == null) { - log.error("[reportDeviceProperty][设备({}/{})不存在]", - reportReqDTO.getProductKey(), reportReqDTO.getDeviceName()); - return; - } - // 1.2 记录设备的最后时间 - updateDeviceLastTime(device, reportReqDTO); - - // 2. 发送设备消息 - IotDeviceMessage message = BeanUtils.toBean(reportReqDTO, IotDeviceMessage.class) - .setType(IotDeviceMessageTypeEnum.PROPERTY.getType()) - .setIdentifier(IotDeviceMessageIdentifierEnum.PROPERTY_REPORT.getIdentifier()) - .setData(reportReqDTO.getProperties()); - sendDeviceMessage(message, device); - } - - @Override - public void reportDeviceEvent(IotDeviceEventReportReqDTO reportReqDTO) { - // 1.1 获得设备 - log.info("[reportDeviceEvent][上报设备事件: {}]", reportReqDTO); - IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceNameFromCache( - reportReqDTO.getProductKey(), reportReqDTO.getDeviceName()); - if (device == null) { - log.error("[reportDeviceEvent][设备({}/{})不存在]", - reportReqDTO.getProductKey(), reportReqDTO.getDeviceName()); - return; - } - // 1.2 记录设备的最后时间 - updateDeviceLastTime(device, reportReqDTO); - - // 2. 发送设备消息 - IotDeviceMessage message = BeanUtils.toBean(reportReqDTO, IotDeviceMessage.class) - .setType(IotDeviceMessageTypeEnum.EVENT.getType()) - .setIdentifier(reportReqDTO.getIdentifier()) - .setData(reportReqDTO.getParams()); - sendDeviceMessage(message, device); - } - - @Override - public void registerDevice(IotDeviceRegisterReqDTO registerReqDTO) { - log.info("[registerDevice][注册设备: {}]", registerReqDTO); - registerDevice0(registerReqDTO.getProductKey(), registerReqDTO.getDeviceName(), null, registerReqDTO); - } - - private void registerDevice0(String productKey, String deviceName, Long gatewayId, - IotDeviceUpstreamAbstractReqDTO registerReqDTO) { - // 1.1 注册设备 - IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceNameFromCache(productKey, deviceName); - boolean registerNew = device == null; - if (device == null) { - device = deviceService.createDevice(productKey, deviceName, gatewayId); - log.info("[registerDevice0][消息({}) 设备({}/{}) 成功注册]", registerReqDTO, productKey, device); - } else if (gatewayId != null && ObjUtil.notEqual(device.getGatewayId(), gatewayId)) { - Long deviceId = device.getId(); - TenantUtils.execute(device.getTenantId(), - () -> deviceService.updateDeviceGateway(deviceId, gatewayId)); - log.info("[registerDevice0][消息({}) 设备({}/{}) 更新网关设备编号({})]", - registerReqDTO, productKey, device, gatewayId); - } - // 1.2 记录设备的最后时间 - updateDeviceLastTime(device, registerReqDTO); - - // 2. 发送设备消息 - if (registerNew) { - IotDeviceMessage message = BeanUtils.toBean(registerReqDTO, IotDeviceMessage.class) - .setType(IotDeviceMessageTypeEnum.REGISTER.getType()) - .setIdentifier(IotDeviceMessageIdentifierEnum.REGISTER_REGISTER.getIdentifier()); - sendDeviceMessage(message, device); - } - } - - @Override - public void registerSubDevice(IotDeviceRegisterSubReqDTO registerReqDTO) { - // 1.1 注册子设备 - log.info("[registerSubDevice][注册子设备: {}]", registerReqDTO); - IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceNameFromCache( - registerReqDTO.getProductKey(), registerReqDTO.getDeviceName()); - if (device == null) { - log.error("[registerSubDevice][设备({}/{}) 不存在]", - registerReqDTO.getProductKey(), registerReqDTO.getDeviceName()); - return; - } - if (!IotProductDeviceTypeEnum.isGateway(device.getDeviceType())) { - log.error("[registerSubDevice][设备({}/{}) 不是网关设备({}),无法进行注册]", - registerReqDTO.getProductKey(), registerReqDTO.getDeviceName(), device); - return; - } - // 1.2 记录设备的最后时间 - updateDeviceLastTime(device, registerReqDTO); - - // 2. 处理子设备 - if (CollUtil.isNotEmpty(registerReqDTO.getParams())) { - registerReqDTO.getParams().forEach(subDevice -> registerDevice0( - subDevice.getProductKey(), subDevice.getDeviceName(), device.getId(), registerReqDTO)); - // TODO @芋艿:后续要处理,每个设备是否成功 - } - - // 3. 发送设备消息 - IotDeviceMessage message = BeanUtils.toBean(registerReqDTO, IotDeviceMessage.class) - .setType(IotDeviceMessageTypeEnum.REGISTER.getType()) - .setIdentifier(IotDeviceMessageIdentifierEnum.REGISTER_REGISTER_SUB.getIdentifier()) - .setData(registerReqDTO.getParams()); - sendDeviceMessage(message, device); - } - - @Override - public void addDeviceTopology(IotDeviceTopologyAddReqDTO addReqDTO) { - // 1.1 获得设备 - log.info("[addDeviceTopology][添加设备拓扑: {}]", addReqDTO); - IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceNameFromCache( - addReqDTO.getProductKey(), addReqDTO.getDeviceName()); - if (device == null) { - log.error("[addDeviceTopology][设备({}/{}) 不存在]", - addReqDTO.getProductKey(), addReqDTO.getDeviceName()); - return; - } - if (!IotProductDeviceTypeEnum.isGateway(device.getDeviceType())) { - log.error("[addDeviceTopology][设备({}/{}) 不是网关设备({}),无法进行拓扑添加]", - addReqDTO.getProductKey(), addReqDTO.getDeviceName(), device); - return; - } - // 1.2 记录设备的最后时间 - updateDeviceLastTime(device, addReqDTO); - - // 2. 处理拓扑 - if (CollUtil.isNotEmpty(addReqDTO.getParams())) { - TenantUtils.execute(device.getTenantId(), () -> { - addReqDTO.getParams().forEach(subDevice -> { - IotDeviceDO subDeviceDO = deviceService.getDeviceByProductKeyAndDeviceNameFromCache( - subDevice.getProductKey(), subDevice.getDeviceName()); - // TODO @芋艿:后续要处理,每个设备是否成功 - if (subDeviceDO == null) { - log.error("[addDeviceTopology][子设备({}/{}) 不存在]", - subDevice.getProductKey(), subDevice.getDeviceName()); - return; - } - deviceService.updateDeviceGateway(subDeviceDO.getId(), device.getId()); - log.info("[addDeviceTopology][子设备({}/{}) 添加到网关设备({}) 成功]", - subDevice.getProductKey(), subDevice.getDeviceName(), device); - }); - }); - } - - // 3. 发送设备消息 - IotDeviceMessage message = BeanUtils.toBean(addReqDTO, IotDeviceMessage.class) - .setType(IotDeviceMessageTypeEnum.TOPOLOGY.getType()) - .setIdentifier(IotDeviceMessageIdentifierEnum.TOPOLOGY_ADD.getIdentifier()) - .setData(addReqDTO.getParams()); - sendDeviceMessage(message, device); - } - - // TODO @芋艿:后续需要考虑,http 的认证 - @Override - public boolean authenticateEmqxConnection(IotDeviceEmqxAuthReqDTO authReqDTO) { - log.info("[authenticateEmqxConnection][认证 Emqx 连接: {}]", authReqDTO); - // 1.1 校验设备是否存在。username 格式:${DeviceName}&${ProductKey} - String[] usernameParts = authReqDTO.getUsername().split("&"); - if (usernameParts.length != 2) { - log.error("[authenticateEmqxConnection][认证失败,username 格式不正确]"); - return false; - } - String deviceName = usernameParts[0]; - String productKey = usernameParts[1]; - // 1.2 获得设备 - IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceNameFromCache(productKey, deviceName); - if (device == null) { - log.error("[authenticateEmqxConnection][设备({}/{}) 不存在]", productKey, deviceName); - return false; - } - // TODO @haohao:需要记录,记录设备的最后时间 - - // 2. 校验密码 - String deviceSecret = device.getDeviceSecret(); - String clientId = authReqDTO.getClientId(); - MqttSignResult sign = MqttSignUtils.calculate(productKey, deviceName, deviceSecret, clientId); - // TODO 建议,先失败,return false; - if (StrUtil.equals(sign.getPassword(), authReqDTO.getPassword())) { - log.info("[authenticateEmqxConnection][认证成功]"); - return true; - } - log.error("[authenticateEmqxConnection][认证失败,密码不正确]"); - return false; - } - - private void updateDeviceLastTime(IotDeviceDO device, IotDeviceUpstreamAbstractReqDTO reqDTO) { - // 1. 【异步】记录设备与插件实例的映射 - pluginInstanceService.updateDevicePluginInstanceProcessIdAsync(device.getDeviceKey(), reqDTO.getProcessId()); - - // 2. 【异步】更新设备的最后时间 - devicePropertyService.updateDeviceReportTimeAsync(device.getDeviceKey(), LocalDateTime.now()); - } - - private void sendDeviceMessage(IotDeviceMessage message, IotDeviceDO device) { - // 1. 完善消息 - message.setDeviceKey(device.getDeviceKey()) - .setTenantId(device.getTenantId()); - if (StrUtil.isEmpty(message.getRequestId())) { - message.setRequestId(IdUtil.fastSimpleUUID()); - } - if (message.getReportTime() == null) { - message.setReportTime(LocalDateTime.now()); - } - - // 2. 发送消息 - try { - deviceProducer.sendDeviceMessage(message); - log.info("[sendDeviceMessage][message({}) 发送消息成功]", message); - } catch (Exception e) { - log.error("[sendDeviceMessage][message({}) 发送消息失败]", message, e); - } - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogService.java deleted file mode 100644 index b797329..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogService.java +++ /dev/null @@ -1,75 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device.data; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogPageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; - -import javax.annotation.Nullable; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; - -/** - * IoT 设备日志数据 Service 接口 - * - * @author alwayssuper - */ -public interface IotDeviceLogService { - - /** - * 初始化 TDengine 超级表 - * - * 系统启动时,会自动初始化一次 - */ - void defineDeviceLog(); - - /** - * 插入设备日志 - * - * @param message 设备数据 - */ - void createDeviceLog(IotDeviceMessage message); - - /** - * 获得设备日志分页 - * - * @param pageReqVO 分页查询 - * @return 设备日志分页 - */ - PageResult getDeviceLogPage(IotDeviceLogPageReqVO pageReqVO); - - /** - * 获得设备日志数量 - * - * @param createTime 创建时间,如果为空,则统计所有日志数量 - * @return 日志数量 - */ - Long getDeviceLogCount(@Nullable LocalDateTime createTime); - - // TODO @super:deviceKey 是不是用不上哈? - /** - * 获得每个小时设备上行消息数量统计 - * - * @param deviceKey 设备标识 - * @param startTime 开始时间 - * @param endTime 结束时间 - * @return key: 时间戳, value: 消息数量 - */ - List> getDeviceLogUpCountByHour(@Nullable String deviceKey, - @Nullable Long startTime, - @Nullable Long endTime); - - /** - * 获得每个小时设备下行消息数量统计 - * - * @param deviceKey 设备标识 - * @param startTime 开始时间 - * @param endTime 结束时间 - * @return key: 时间戳, value: 消息数量 - */ - List> getDeviceLogDownCountByHour(@Nullable String deviceKey, - @Nullable Long startTime, - @Nullable Long endTime); - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogServiceImpl.java deleted file mode 100644 index 2ed2312..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDeviceLogServiceImpl.java +++ /dev/null @@ -1,112 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device.data; - -import cn.hutool.core.date.LocalDateTimeUtil; -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDeviceLogPageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; -import cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogMapper; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.sql.Timestamp; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * IoT 设备日志数据 Service 实现类 - * - * @author alwayssuper - */ -@Service -@Slf4j -@Validated -public class IotDeviceLogServiceImpl implements IotDeviceLogService { - - @Resource - private IotDeviceLogMapper deviceLogMapper; - - @Override - public void defineDeviceLog() { - if (StrUtil.isNotEmpty(deviceLogMapper.showDeviceLogSTable())) { - log.info("[defineDeviceLog][设备日志超级表已存在,创建跳过]"); - return; - } - - log.info("[defineDeviceLog][设备日志超级表不存在,创建开始...]"); - deviceLogMapper.createDeviceLogSTable(); - log.info("[defineDeviceLog][设备日志超级表不存在,创建成功]"); - } - - @Override - public void createDeviceLog(IotDeviceMessage message) { - IotDeviceLogDO log = BeanUtils.toBean(message, IotDeviceLogDO.class) - .setId(IdUtil.fastSimpleUUID()) - .setContent(JsonUtils.toJsonString(message.getData())); - deviceLogMapper.insert(log); - } - - @Override - public PageResult getDeviceLogPage(IotDeviceLogPageReqVO pageReqVO) { - try { - IPage page = deviceLogMapper.selectPage( - new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()), pageReqVO); - return new PageResult<>(page.getRecords(), page.getTotal()); - } catch (Exception exception) { - if (exception.getMessage().contains("Table does not exist")) { - return PageResult.empty(); - } - throw exception; - } - } - - @Override - public Long getDeviceLogCount(LocalDateTime createTime) { - return deviceLogMapper.selectCountByCreateTime(createTime != null ? LocalDateTimeUtil.toEpochMilli(createTime) : null); - } - - // TODO @super:加一个参数,Boolean upstream:true 上行,false 下行,null 不过滤 - @Override - public List> getDeviceLogUpCountByHour(String deviceKey, Long startTime, Long endTime) { - // TODO @super:不能只基于数据库统计。因为有一些小时,可能出现没数据的情况,导致前端展示的图是不全的。可以参考 CrmStatisticsCustomerService 来实现 - List> list = deviceLogMapper.selectDeviceLogUpCountByHour(deviceKey, startTime, endTime); - return list.stream() - .map(map -> { - // 从Timestamp获取时间戳 - Timestamp timestamp = (Timestamp) map.get("time"); - Long timeMillis = timestamp.getTime(); - // 消息数量转换 - Integer count = ((Number) map.get("data")).intValue(); - return MapUtil.of(timeMillis, count); - }) - .collect(Collectors.toList()); - } - - // TODO @super:getDeviceLogDownCountByHour 融合到 getDeviceLogUpCountByHour - @Override - public List> getDeviceLogDownCountByHour(String deviceKey, Long startTime, Long endTime) { - List> list = deviceLogMapper.selectDeviceLogDownCountByHour(deviceKey, startTime, endTime); - return list.stream() - .map(map -> { - // 从Timestamp获取时间戳 - Timestamp timestamp = (Timestamp) map.get("time"); - Long timeMillis = timestamp.getTime(); - // 消息数量转换 - Integer count = ((Number) map.get("data")).intValue(); - return MapUtil.of(timeMillis, count); - }) - .collect(Collectors.toList()); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDevicePropertyService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDevicePropertyService.java deleted file mode 100644 index 2f06268..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDevicePropertyService.java +++ /dev/null @@ -1,71 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device.data; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import jakarta.validation.Valid; - -import java.time.LocalDateTime; -import java.util.Map; -import java.util.Set; - -/** - * IoT 设备【属性】数据 Service 接口 - * - * @author 芋道源码 - */ -public interface IotDevicePropertyService { - - // ========== 设备属性相关操作 ========== - - /** - * 定义设备属性数据的结构 - * - * @param productId 产品编号 - */ - void defineDevicePropertyData(Long productId); - - /** - * 保存设备数据 - * - * @param message 设备消息 - */ - void saveDeviceProperty(IotDeviceMessage message); - - /** - * 获得设备属性最新数据 - * - * @param deviceId 设备编号 - * @return 设备属性最新数据 - */ - Map getLatestDeviceProperties(Long deviceId); - - /** - * 获得设备属性历史数据 - * - * @param pageReqVO 分页请求 - * @return 设备属性历史数据 - */ - PageResult getHistoryDevicePropertyPage(@Valid IotDevicePropertyHistoryPageReqVO pageReqVO); - - // ========== 设备时间相关操作 ========== - - /** - * 获得最后上报时间小于指定时间的设备标识 - * - * @param maxReportTime 最大上报时间 - * @return 设备标识列表 - */ - Set getDeviceKeysByReportTime(LocalDateTime maxReportTime); - - /** - * 异步更新设备上报时间 - * - * @param deviceKey 设备标识 - * @param reportTime 上报时间 - */ - void updateDeviceReportTimeAsync(String deviceKey, LocalDateTime reportTime); - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDevicePropertyServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDevicePropertyServiceImpl.java deleted file mode 100644 index 77dde64..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/data/IotDevicePropertyServiceImpl.java +++ /dev/null @@ -1,200 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.device.data; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.date.LocalDateTimeUtil; -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyHistoryPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDateOrTextDataSpecs; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDevicePropertyDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; -import cn.iocoder.yudao.module.iot.dal.redis.device.DevicePropertyRedisDAO; -import cn.iocoder.yudao.module.iot.dal.redis.device.DeviceReportTimeRedisDAO; -import cn.iocoder.yudao.module.iot.dal.tdengine.IotDevicePropertyMapper; -import cn.iocoder.yudao.module.iot.enums.thingmodel.IotDataSpecsDataTypeEnum; -import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum; -import cn.iocoder.yudao.module.iot.framework.tdengine.core.TDengineTableField; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -import cn.iocoder.yudao.module.iot.service.product.IotProductService; -import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Service; - -import java.time.LocalDateTime; -import java.util.*; - -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; - -/** - * IoT 设备【属性】数据 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Slf4j -public class IotDevicePropertyServiceImpl implements IotDevicePropertyService { - - /** - * 物模型的数据类型,与 TDengine 数据类型的映射关系 - */ - private static final Map TYPE_MAPPING = MapUtil.builder() - .put(IotDataSpecsDataTypeEnum.INT.getDataType(), TDengineTableField.TYPE_INT) - .put(IotDataSpecsDataTypeEnum.FLOAT.getDataType(), TDengineTableField.TYPE_FLOAT) - .put(IotDataSpecsDataTypeEnum.DOUBLE.getDataType(), TDengineTableField.TYPE_DOUBLE) - .put(IotDataSpecsDataTypeEnum.ENUM.getDataType(), TDengineTableField.TYPE_TINYINT) // TODO 芋艿:为什么要映射为 TINYINT 的说明? - .put(IotDataSpecsDataTypeEnum.BOOL.getDataType(), TDengineTableField.TYPE_TINYINT) // TODO 芋艿:为什么要映射为 TINYINT 的说明? - .put(IotDataSpecsDataTypeEnum.TEXT.getDataType(), TDengineTableField.TYPE_NCHAR) - .put(IotDataSpecsDataTypeEnum.DATE.getDataType(), TDengineTableField.TYPE_TIMESTAMP) - .put(IotDataSpecsDataTypeEnum.STRUCT.getDataType(), TDengineTableField.TYPE_NCHAR) // TODO 芋艿:怎么映射!!!! - .put(IotDataSpecsDataTypeEnum.ARRAY.getDataType(), TDengineTableField.TYPE_NCHAR) // TODO 芋艿:怎么映射!!!! - .build(); - - @Resource - private IotDeviceService deviceService; - @Resource - private IotThingModelService thingModelService; - @Resource - private IotProductService productService; - - @Resource - private DevicePropertyRedisDAO deviceDataRedisDAO; - @Resource - private DeviceReportTimeRedisDAO deviceReportTimeRedisDAO; - - @Resource - private IotDevicePropertyMapper devicePropertyMapper; - - // ========== 设备属性相关操作 ========== - - @Override - public void defineDevicePropertyData(Long productId) { - // 1.1 查询产品和物模型 - IotProductDO product = productService.validateProductExists(productId); - List thingModels = filterList(thingModelService.getThingModelListByProductId(productId), - thingModel -> IotThingModelTypeEnum.PROPERTY.getType().equals(thingModel.getType())); - // 1.2 解析 DB 里的字段 - List oldFields = new ArrayList<>(); - try { - oldFields.addAll(devicePropertyMapper.getProductPropertySTableFieldList(product.getProductKey())); - } catch (Exception e) { - if (!e.getMessage().contains("Table does not exist")) { - throw e; - } - } - - // 2.1 情况一:如果是新增的时候,需要创建表 - List newFields = buildTableFieldList(thingModels); - if (CollUtil.isEmpty(oldFields)) { - if (CollUtil.isEmpty(newFields)) { - log.info("[defineDevicePropertyData][productId({}) 没有需要定义的属性]", productId); - return; - } - devicePropertyMapper.createProductPropertySTable(product.getProductKey(), newFields); - return; - } - // 2.2 情况二:如果是修改的时候,需要更新表 - devicePropertyMapper.alterProductPropertySTable(product.getProductKey(), oldFields, newFields); - } - - private List buildTableFieldList(List thingModels) { - return convertList(thingModels, thingModel -> { - TDengineTableField field = new TDengineTableField( - StrUtil.toUnderlineCase(thingModel.getIdentifier()), // TDengine 字段默认都是小写 - TYPE_MAPPING.get(thingModel.getProperty().getDataType())); - if (thingModel.getProperty().getDataType().equals(IotDataSpecsDataTypeEnum.TEXT.getDataType())) { - field.setLength(((ThingModelDateOrTextDataSpecs) thingModel.getProperty().getDataSpecs()).getLength()); - } - return field; - }); - } - - @Override - @TenantIgnore - public void saveDeviceProperty(IotDeviceMessage message) { - if (!(message.getData() instanceof Map)) { - log.error("[saveDeviceProperty][消息内容({}) 的 data 类型不正确]", message); - return; - } - // 1. 获得设备信息 - IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceNameFromCache(message.getProductKey(), message.getDeviceName()); - if (device == null) { - log.error("[saveDeviceProperty][消息({}) 对应的设备不存在]", message); - return; - } - - // 2. 根据物模型,拼接合法的属性 - // TODO @芋艿:【待定 004】赋能后,属性到底以 thingModel 为准(ik),还是 db 的表结构为准(tl)? - List thingModels = thingModelService.getThingModelListByProductKeyFromCache(device.getProductKey()); - Map properties = new HashMap<>(); - ((Map) message.getData()).forEach((key, value) -> { - if (CollUtil.findOne(thingModels, thingModel -> thingModel.getIdentifier().equals(key)) == null) { - log.error("[saveDeviceProperty][消息({}) 的属性({}) 不存在]", message, key); - return; - } - properties.put((String) key, value); - }); - if (CollUtil.isEmpty(properties)) { - log.error("[saveDeviceProperty][消息({}) 没有合法的属性]", message); - return; - } - - // 3.1 保存设备属性【数据】 - devicePropertyMapper.insert(device, properties, - LocalDateTimeUtil.toEpochMilli(message.getReportTime())); - - // 3.2 保存设备属性【日志】 - deviceDataRedisDAO.putAll(message.getDeviceKey(), convertMap(properties.entrySet(), Map.Entry::getKey, - entry -> IotDevicePropertyDO.builder().value(entry.getValue()).updateTime(message.getReportTime()).build())); - } - - @Override - public Map getLatestDeviceProperties(Long deviceId) { - // 获取设备信息 - IotDeviceDO device = deviceService.validateDeviceExists(deviceId); - - // 获得设备属性 - return deviceDataRedisDAO.get(device.getDeviceKey()); - } - - @Override - public PageResult getHistoryDevicePropertyPage(IotDevicePropertyHistoryPageReqVO pageReqVO) { - // 获取设备信息 - IotDeviceDO device = deviceService.validateDeviceExists(pageReqVO.getDeviceId()); - pageReqVO.setDeviceKey(device.getDeviceKey()); - - try { - IPage page = devicePropertyMapper.selectPageByHistory( - new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize()), pageReqVO); - return new PageResult<>(page.getRecords(), page.getTotal()); - } catch (Exception exception) { - if (exception.getMessage().contains("Table does not exist")) { - return PageResult.empty(); - } - throw exception; - } - } - - // ========== 设备时间相关操作 ========== - - @Override - public Set getDeviceKeysByReportTime(LocalDateTime maxReportTime) { - return deviceReportTimeRedisDAO.range(maxReportTime); - } - - @Override - @Async - public void updateDeviceReportTimeAsync(String deviceKey, LocalDateTime reportTime) { - deviceReportTimeRedisDAO.update(deviceKey, reportTime); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaFirmwareService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaFirmwareService.java deleted file mode 100644 index 99e3b38..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaFirmwareService.java +++ /dev/null @@ -1,59 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.ota; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwareCreateReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwarePageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwareUpdateReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; -import jakarta.validation.Valid; - -// TODO @li:注释写的有点冗余,可以看看别的模块哈。= = AI 生成的注释,有的时候太啰嗦了,需要处理下的哈 -/** - * OTA 固件管理 Service - * - * @author Shelly Chan - */ -public interface IotOtaFirmwareService { - - /** - * 创建 OTA 固件 - * - * @param saveReqVO OTA固件保存请求对象,包含固件的相关信息 - * @return 返回新创建的固件的ID - */ - Long createOtaFirmware(@Valid IotOtaFirmwareCreateReqVO saveReqVO); - - /** - * 更新 OTA 固件信息 - * - * @param updateReqVO OTA固件保存请求对象,包含需要更新的固件信息 - */ - void updateOtaFirmware(@Valid IotOtaFirmwareUpdateReqVO updateReqVO); - - /** - * 根据 ID 获取 OTA 固件信息 - * - * @param id OTA固件的唯一标识符 - * @return 返回OTA固件的详细信息对象 - */ - IotOtaFirmwareDO getOtaFirmware(Long id); - - /** - * 分页查询 OTA 固件信息 - * - * @param pageReqVO 包含分页查询条件的请求对象 - * @return 返回分页查询结果,包含固件信息列表和分页信息 - */ - PageResult getOtaFirmwarePage(@Valid IotOtaFirmwarePageReqVO pageReqVO); - - /** - * 验证物联网 OTA 固件是否存在 - * - * @param id 固件的唯一标识符 - * 该方法用于检查系统中是否存在与给定ID关联的物联网OTA固件信息 - * 主要目的是在进行固件更新操作前,确保目标固件已经存在并可以被访问 - * 如果固件不存在,该方法可能抛出异常或返回错误信息,具体行为未定义 - */ - IotOtaFirmwareDO validateFirmwareExists(Long id); - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaFirmwareServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaFirmwareServiceImpl.java deleted file mode 100644 index 7c0ddba..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaFirmwareServiceImpl.java +++ /dev/null @@ -1,104 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.ota; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.convert.Convert; -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.ota.vo.firmware.IotOtaFirmwareCreateReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwarePageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwareUpdateReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.dal.mysql.ota.IotOtaFirmwareMapper; -import cn.iocoder.yudao.module.iot.service.product.IotProductService; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.util.List; -import java.util.Objects; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.OTA_FIRMWARE_NOT_EXISTS; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.OTA_FIRMWARE_PRODUCT_VERSION_DUPLICATE; - -@Slf4j -@Service -@Validated -public class IotOtaFirmwareServiceImpl implements IotOtaFirmwareService { - - @Resource - private IotOtaFirmwareMapper otaFirmwareMapper; - @Lazy - @Resource - private IotProductService productService; - - @Override - public Long createOtaFirmware(IotOtaFirmwareCreateReqVO saveReqVO) { - // 1. 校验固件产品 + 版本号不能重复 - validateProductAndVersionDuplicate(saveReqVO.getProductId(), saveReqVO.getVersion()); - - // 2.1.转化数据格式,准备存储到数据库中 - IotOtaFirmwareDO firmware = BeanUtils.toBean(saveReqVO, IotOtaFirmwareDO.class); - // 2.2.查询ProductKey - // TODO @li:productService.getProduct(Convert.toLong(firmware.getProductId())) 放到 1. 后面,先做参考校验。逻辑两段:1)先参数校验;2)构建对象 + 存储 - IotProductDO product = productService.getProduct(Convert.toLong(firmware.getProductId())); - firmware.setProductKey(Objects.requireNonNull(product).getProductKey()); - // TODO @芋艿: 附件、附件签名等属性的计算 - otaFirmwareMapper.insert(firmware); - return firmware.getId(); - } - - @Override - public void updateOtaFirmware(IotOtaFirmwareUpdateReqVO updateReqVO) { - // 1. 校验存在 - validateFirmwareExists(updateReqVO.getId()); - - // 2. 更新数据 - IotOtaFirmwareDO updateObj = BeanUtils.toBean(updateReqVO, IotOtaFirmwareDO.class); - otaFirmwareMapper.updateById(updateObj); - } - - @Override - public IotOtaFirmwareDO getOtaFirmware(Long id) { - return otaFirmwareMapper.selectById(id); - } - - @Override - public PageResult getOtaFirmwarePage(IotOtaFirmwarePageReqVO pageReqVO) { - return otaFirmwareMapper.selectPage(pageReqVO); - } - - @Override - public IotOtaFirmwareDO validateFirmwareExists(Long id) { - IotOtaFirmwareDO firmware = otaFirmwareMapper.selectById(id); - if (firmware == null) { - throw exception(OTA_FIRMWARE_NOT_EXISTS); - } - return firmware; - } - - // TODO @li:注释有点冗余 - /** - * 验证产品和版本号是否重复 - *

- * 该方法用于确保在系统中不存在具有相同产品ID和版本号的固件条目 - * 它通过调用otaFirmwareMapper的selectByProductIdAndVersion方法来查询数据库中是否存在匹配的产品ID和版本号的固件信息 - * 如果查询结果非空且不为null,则抛出异常,提示固件信息已存在,从而避免数据重复 - * - * @param productId 产品ID,用于数据库查询 - * @param version 版本号,用于数据库查询 - * @throws cn.iocoder.yudao.framework.common.exception.ServiceException,则抛出异常,提示固件信息已存在 - */ - private void validateProductAndVersionDuplicate(String productId, String version) { - // 查询数据库中是否存在具有相同产品ID和版本号的固件信息 - List list = otaFirmwareMapper.selectByProductIdAndVersion(productId, version); - // 如果查询结果非空且不为null,则抛出异常,提示固件信息已存在 - if (CollUtil.isNotEmpty(list)) { - throw exception(OTA_FIRMWARE_PRODUCT_VERSION_DUPLICATE); - } - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeRecordService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeRecordService.java deleted file mode 100644 index cbf900a..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeRecordService.java +++ /dev/null @@ -1,104 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.ota; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.upgrade.record.IotOtaUpgradeRecordPageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaUpgradeRecordDO; -import jakarta.validation.Valid; - -import java.util.List; -import java.util.Map; - -// TODO @li:注释写的有点冗余,可以看看别的模块哈。= = AI 生成的注释,有的时候太啰嗦了,需要处理下的哈 -/** - * IotOtaUpgradeRecordService 接口定义了与物联网设备OTA升级记录相关的操作。 - * 该接口提供了创建、更新、查询、统计和重试升级记录的功能。 - */ -public interface IotOtaUpgradeRecordService { - - /** - * 批量创建 OTA 升级记录 - * 该函数用于为指定的设备列表、固件ID和升级任务ID创建OTA升级记录。 - * - * @param deviceIds 设备ID列表,表示需要升级的设备集合。 - * @param firmwareId 固件ID,表示要升级到的固件版本。 - * @param upgradeTaskId 升级任务ID,表示此次升级任务的唯一标识。 - */ - void createOtaUpgradeRecordBatch(List deviceIds, Long firmwareId, Long upgradeTaskId); - - /** - * 获取 OTA 升级记录的数量统计 - * - * @return 返回一个 Map,其中键为状态码,值为对应状态的升级记录数量 - */ - Map getOtaUpgradeRecordCount(@Valid IotOtaUpgradeRecordPageReqVO pageReqVO); - - /** - * 获取 OTA 升级记录的统计信息。 - * - * @return 返回一个 Map,其中键为状态码,值为对应状态的升级记录统计信息 - */ - Map getOtaUpgradeRecordStatistics(Long firmwareId); - - /** - * 重试指定的 OTA 升级记录 - * - * @param id 需要重试的升级记录的ID。 - */ - void retryUpgradeRecord(Long id); - - /** - * 获取指定 ID 的 OTA 升级记录的详细信息。 - * - * @param id 需要查询的升级记录的ID。 - * @return 返回包含升级记录详细信息的响应对象。 - */ - IotOtaUpgradeRecordDO getUpgradeRecord(Long id); - - /** - * 分页查询 OTA 升级记录。 - * - * @param pageReqVO 包含分页查询条件的请求对象,必须经过验证。 - * @return 返回包含分页查询结果的响应对象。 - */ - PageResult getUpgradeRecordPage(@Valid IotOtaUpgradeRecordPageReqVO pageReqVO); - - /** - * 根据任务 ID 取消升级记录 - *

- * 该函数用于根据给定的任务ID,取消与该任务相关的升级记录。通常用于在任务执行失败或用户手动取消时, - * 清理或标记相关的升级记录为取消状态。 - * - * @param taskId 要取消升级记录的任务ID。该ID唯一标识一个任务,通常由任务管理系统生成。 - */ - void cancelUpgradeRecordByTaskId(Long taskId); - - // TODO @li:不要的方法,可以删除下哈。 - /** - * 根据升级状态获取升级记录列表 - * - * @param state 升级状态,用于筛选符合条件的升级记录 - * @return 返回符合指定状态的升级记录列表,列表中的元素为 {@link IotOtaUpgradeRecordDO} 对象 - */ - List getUpgradeRecordListByState(Integer state); - - /** - * 更新升级记录的状态。 - *

- * 该函数用于批量更新指定升级记录的状态。通过传入的ID列表和状态值,将对应的升级记录的状态更新为指定的值。 - * - * @param ids 需要更新状态的升级记录的ID列表。列表中的每个元素代表一个升级记录的ID。 - * @param status 要更新的状态值。该值应为有效的状态标识符,通常为整数类型。 - */ - void updateUpgradeRecordStatus(List ids, Integer status); - - /** - * 根据任务ID获取升级记录列表 - *

- * 该函数通过给定的任务ID,查询并返回与该任务相关的所有升级记录。 - * - * @param taskId 任务ID,用于指定需要查询的任务 - * @return 返回一个包含升级记录的列表,列表中的每个元素为IotOtaUpgradeRecordDO对象 - */ - List getUpgradeRecordListByTaskId(Long taskId); - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeRecordServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeRecordServiceImpl.java deleted file mode 100644 index 02ef39c..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeRecordServiceImpl.java +++ /dev/null @@ -1,229 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.ota; - -import cn.hutool.core.convert.Convert; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.upgrade.record.IotOtaUpgradeRecordPageReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaUpgradeRecordDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaUpgradeTaskDO; -import cn.iocoder.yudao.module.iot.dal.mysql.ota.IotOtaUpgradeRecordMapper; -import cn.iocoder.yudao.module.iot.enums.ota.IotOtaUpgradeRecordStatusEnum; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; - -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*; - -// TODO @li:@Service、@Validated、@Slf4j,先用关键注解;2)类注释,简单写 -@Slf4j -@Service -@Validated -public class IotOtaUpgradeRecordServiceImpl implements IotOtaUpgradeRecordService { - - @Resource - private IotOtaUpgradeRecordMapper upgradeRecordMapper; - // TODO @li:1)@Resource 写在 @Lazy 之前,先用关键注解;2)有必要的情况下,在写 @Lazy 注解。 - @Lazy - @Resource - private IotDeviceService deviceService; - @Lazy - @Resource - private IotOtaFirmwareService firmwareService; - @Lazy - @Resource - private IotOtaUpgradeTaskService upgradeTaskService; - - @Override - public void createOtaUpgradeRecordBatch(List deviceIds, Long firmwareId, Long upgradeTaskId) { - // 1. 校验升级记录信息是否存在,并且已经取消的任务可以重新开始 - // TODO @li:批量查询。。 - deviceIds.forEach(deviceId -> validateUpgradeRecordDuplicate(firmwareId, upgradeTaskId, String.valueOf(deviceId))); - - // 2.初始化OTA升级记录列表信息 - IotOtaUpgradeTaskDO upgradeTask = upgradeTaskService.getUpgradeTask(upgradeTaskId); - IotOtaFirmwareDO firmware = firmwareService.getOtaFirmware(firmwareId); - List deviceList = deviceService.getDeviceListByIdList(deviceIds); - List upgradeRecordList = deviceList.stream().map(device -> { - IotOtaUpgradeRecordDO upgradeRecord = new IotOtaUpgradeRecordDO(); - upgradeRecord.setFirmwareId(firmware.getId()); - upgradeRecord.setTaskId(upgradeTask.getId()); - upgradeRecord.setProductKey(device.getProductKey()); - upgradeRecord.setDeviceName(device.getDeviceName()); - upgradeRecord.setDeviceId(Convert.toStr(device.getId())); - upgradeRecord.setFromFirmwareId(Convert.toLong(device.getFirmwareId())); - upgradeRecord.setStatus(IotOtaUpgradeRecordStatusEnum.PENDING.getStatus()); - upgradeRecord.setProgress(0); - return upgradeRecord; - }).toList(); - // 3.保存数据 - upgradeRecordMapper.insertBatch(upgradeRecordList); - // TODO @芋艿:在这里需要处理推送升级任务的逻辑 - - } - - // TODO @li:1)方法注释,简单写;2)父类写了注释,子类就不用写了。。。 - /** - * 获取OTA升级记录的数量统计。 - * 该方法根据传入的查询条件,统计不同状态的OTA升级记录数量,并返回一个包含各状态数量的映射。 - * - * @param pageReqVO 包含查询条件的请求对象,主要包括任务ID和设备名称等信息。 - * @return 返回一个Map,其中键为状态常量,值为对应状态的记录数量。 - */ - @Override - @Transactional - public Map getOtaUpgradeRecordCount(IotOtaUpgradeRecordPageReqVO pageReqVO) { - // 分别查询不同状态的OTA升级记录数量 - List> upgradeRecordCountList = upgradeRecordMapper.selectOtaUpgradeRecordCount( - pageReqVO.getTaskId(), pageReqVO.getDeviceName()); - Map upgradeRecordCountMap = ObjectUtils.defaultIfNull(upgradeRecordCountList.get(0)); - Objects.requireNonNull(upgradeRecordCountMap); - return upgradeRecordCountMap.entrySet().stream().collect(Collectors.toMap( - entry -> Convert.toInt(entry.getKey()), - entry -> Convert.toLong(entry.getValue()))); - } - - // TODO @li:1)方法注释,简单写;2)父类写了注释,子类就不用写了。。。 - /** - * 获取指定固件ID的OTA升级记录统计信息。 - * 该方法通过查询数据库,统计不同状态的OTA升级记录数量,并返回一个包含各状态数量的映射。 - * - * @param firmwareId 固件ID,用于指定需要统计的固件升级记录。 - * @return 返回一个Map,其中键为升级记录状态(如PENDING、PUSHED等),值为对应状态的记录数量。 - */ - @Override - @Transactional - public Map getOtaUpgradeRecordStatistics(Long firmwareId) { - // 查询并统计不同状态的OTA升级记录数量 - List> upgradeRecordStatisticsList = upgradeRecordMapper.selectOtaUpgradeRecordStatistics(firmwareId); - Map upgradeRecordStatisticsMap = ObjectUtils.defaultIfNull(upgradeRecordStatisticsList.get(0)); - Objects.requireNonNull(upgradeRecordStatisticsMap); - return upgradeRecordStatisticsMap.entrySet().stream().collect(Collectors.toMap( - entry -> Convert.toInt(entry.getKey()), - entry -> Convert.toLong(entry.getValue()))); - } - - @Override - public void retryUpgradeRecord(Long id) { - // 1.1.校验升级记录信息是否存在 - IotOtaUpgradeRecordDO upgradeRecord = validateUpgradeRecordExists(id); - // 1.2.校验升级记录是否可以重新升级 - validateUpgradeRecordCanRetry(upgradeRecord); - - // 2. 将一些数据重置,这样定时任务轮询就可以重启任务 - // TODO @li:更新的时候,wherestatus; - upgradeRecordMapper.updateById(new IotOtaUpgradeRecordDO() - .setId(upgradeRecord.getId()).setProgress(0) - .setStatus(IotOtaUpgradeRecordStatusEnum.PENDING.getStatus())); - } - - @Override - public IotOtaUpgradeRecordDO getUpgradeRecord(Long id) { - return upgradeRecordMapper.selectById(id); - } - - @Override - public PageResult getUpgradeRecordPage(IotOtaUpgradeRecordPageReqVO pageReqVO) { - return upgradeRecordMapper.selectUpgradeRecordPage(pageReqVO); - } - - @Override - public void cancelUpgradeRecordByTaskId(Long taskId) { - // 暂定只有待推送的升级记录可以取消 TODO @芋艿:可以看看阿里云,哪些可以取消 - upgradeRecordMapper.updateUpgradeRecordStatusByTaskIdAndStatus( - IotOtaUpgradeRecordStatusEnum.CANCELED.getStatus(), taskId, - IotOtaUpgradeRecordStatusEnum.PENDING.getStatus()); - } - - @Override - public List getUpgradeRecordListByState(Integer state) { - return upgradeRecordMapper.selectUpgradeRecordListByState(state); - } - - @Override - public void updateUpgradeRecordStatus(List ids, Integer status) { - upgradeRecordMapper.updateUpgradeRecordStatus(ids, status); - } - - @Override - public List getUpgradeRecordListByTaskId(Long taskId) { - return upgradeRecordMapper.selectUpgradeRecordListByTaskId(taskId); - } - - /** - * 验证指定的升级记录是否存在。 - *

- * 该函数通过给定的ID查询升级记录,如果查询结果为空,则抛出异常,表示升级记录不存在。 - * - * @param id 升级记录的唯一标识符,类型为Long。 - * @throws cn.iocoder.yudao.framework.common.exception.ServiceException,则抛出异常,异常类型为OTA_UPGRADE_RECORD_NOT_EXISTS。 - */ - private IotOtaUpgradeRecordDO validateUpgradeRecordExists(Long id) { - // 根据ID查询升级记录 - IotOtaUpgradeRecordDO upgradeRecord = upgradeRecordMapper.selectById(id); - // 如果查询结果为空,抛出异常 - if (upgradeRecord == null) { - throw exception(OTA_UPGRADE_RECORD_NOT_EXISTS); - } - return upgradeRecord; - } - - // TODO @li:注释有点冗余 - /** - * 校验固件升级记录是否重复。 - *

- * 该函数用于检查给定的固件ID、任务ID和设备ID是否已经存在未取消的升级记录。 - * 如果存在未取消的记录,则抛出异常,提示升级记录重复。 - * - * @param firmwareId 固件ID,用于标识特定的固件版本 - * @param taskId 任务ID,用于标识特定的升级任务 - * @param deviceId 设备ID,用于标识特定的设备 - */ - private void validateUpgradeRecordDuplicate(Long firmwareId, Long taskId, String deviceId) { - // 根据条件查询升级记录 - IotOtaUpgradeRecordDO upgradeRecord = upgradeRecordMapper.selectByConditions(firmwareId, taskId, deviceId); - // 如果查询到升级记录且状态不是已取消,则抛出异常 - // TODO @li:if return,减少括号层级; - // TODO @li:ObjUtil.notEquals,尽量不用 !取否逻辑; - if (upgradeRecord != null) { - if (!IotOtaUpgradeRecordStatusEnum.CANCELED.getStatus().equals(upgradeRecord.getStatus())) { - // TODO @li:提示的时候,需要把 deviceName 给提示出来,不然用户不知道哪个重复啦。 - throw exception(OTA_UPGRADE_RECORD_DUPLICATE); - } - } - } - - // TODO @li:注释有点冗余 - /** - * 验证升级记录是否可以重试。 - *

- * 该方法用于检查给定的升级记录是否处于允许重试的状态。如果升级记录的状态为 - * PENDING、PUSHED 或 UPGRADING,则抛出异常,表示不允许重试。 - * - * @param upgradeRecord 需要验证的升级记录对象,类型为 IotOtaUpgradeRecordDO - * @throws cn.iocoder.yudao.framework.common.exception.ServiceException,则抛出 OTA_UPGRADE_RECORD_CANNOT_RETRY 异常 - */ - // TODO @li:这种一次性的方法(不复用的),其实一步一定要抽成小方法; - private void validateUpgradeRecordCanRetry(IotOtaUpgradeRecordDO upgradeRecord) { - // 检查升级记录的状态是否为 PENDING、PUSHED 或 UPGRADING - if (ObjectUtils.equalsAny(upgradeRecord.getStatus(), - IotOtaUpgradeRecordStatusEnum.PENDING.getStatus(), - IotOtaUpgradeRecordStatusEnum.PUSHED.getStatus(), - IotOtaUpgradeRecordStatusEnum.UPGRADING.getStatus())) { - // 如果升级记录处于上述状态之一,则抛出异常,表示不允许重试 - throw exception(OTA_UPGRADE_RECORD_CANNOT_RETRY); - } - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeTaskService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeTaskService.java deleted file mode 100644 index a2a810b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeTaskService.java +++ /dev/null @@ -1,68 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.ota; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.upgrade.task.IotOtaUpgradeTaskPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.upgrade.task.IotOtaUpgradeTaskSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaUpgradeTaskDO; -import jakarta.validation.Valid; - -import java.util.List; - -/** - * IoT OTA升级任务 Service 接口 - * - * @author Shelly Chan - */ -public interface IotOtaUpgradeTaskService { - - /** - * 创建OTA升级任务 - * - * @param createReqVO OTA升级任务的创建请求对象,包含创建任务所需的信息 - * @return 创建成功的OTA升级任务的ID - */ - Long createUpgradeTask(@Valid IotOtaUpgradeTaskSaveReqVO createReqVO); - - /** - * 取消OTA升级任务 - * - * @param id 要取消的OTA升级任务的ID - */ - void cancelUpgradeTask(Long id); - - /** - * 根据ID获取OTA升级任务的详细信息 - * - * @param id OTA升级任务的ID - * @return OTA升级任务的详细信息对象 - */ - IotOtaUpgradeTaskDO getUpgradeTask(Long id); - - /** - * 分页查询OTA升级任务 - * - * @param pageReqVO OTA升级任务的分页查询请求对象,包含查询条件和分页信息 - * @return 分页查询结果,包含OTA升级任务列表和总记录数 - */ - PageResult getUpgradeTaskPage(@Valid IotOtaUpgradeTaskPageReqVO pageReqVO); - - /** - * 根据任务状态获取升级任务列表 - * - * @param state 任务状态,用于筛选符合条件的升级任务 - * @return 返回符合指定状态的升级任务列表,列表中的元素为 IotOtaUpgradeTaskDO 对象 - */ - List getUpgradeTaskByState(Integer state); - - /** - * 更新升级任务的状态。 - *

- * 该函数用于根据任务ID更新指定升级任务的状态。通常用于在任务执行过程中 - * 更新任务的状态,例如从“进行中”变为“已完成”或“失败”。 - * - * @param id 升级任务的唯一标识符,类型为Long。不能为null。 - * @param status 要更新的任务状态,类型为Integer。通常表示任务的状态码,如0表示未开始,1表示进行中,2表示已完成等。 - */ - void updateUpgradeTaskStatus(Long id, Integer status); - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeTaskServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeTaskServiceImpl.java deleted file mode 100644 index cee3ba5..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaUpgradeTaskServiceImpl.java +++ /dev/null @@ -1,207 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.ota; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.convert.Convert; -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.ota.vo.upgrade.task.IotOtaUpgradeTaskPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.upgrade.task.IotOtaUpgradeTaskSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaUpgradeTaskDO; -import cn.iocoder.yudao.module.iot.dal.mysql.ota.IotOtaUpgradeTaskMapper; -import cn.iocoder.yudao.module.iot.enums.ota.IotOtaUpgradeTaskScopeEnum; -import cn.iocoder.yudao.module.iot.enums.ota.IotOtaUpgradeTaskStatusEnum; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; - -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*; - -// TODO @li:完善注释、注解顺序 -@Slf4j -@Service -@Validated -public class IotOtaUpgradeTaskServiceImpl implements IotOtaUpgradeTaskService { - - @Resource - private IotOtaUpgradeTaskMapper upgradeTaskMapper; - - @Resource - @Lazy - private IotDeviceService deviceService; - @Resource - @Lazy - private IotOtaFirmwareService firmwareService; - @Resource - @Lazy - private IotOtaUpgradeRecordService upgradeRecordService; - - @Override - @Transactional(rollbackFor = Exception.class) - public Long createUpgradeTask(IotOtaUpgradeTaskSaveReqVO createReqVO) { - // 1.1 校验同一固件的升级任务名称不重复 - validateFirmwareTaskDuplicate(createReqVO.getFirmwareId(), createReqVO.getName()); - // 1.2 校验固件信息是否存在 - IotOtaFirmwareDO firmware = firmwareService.validateFirmwareExists(createReqVO.getFirmwareId()); - // 1.3 补全设备范围信息,并且校验是否又设备可以升级,如果没有设备可以升级,则报错 - validateScopeAndDevice(createReqVO.getScope(), createReqVO.getDeviceIds(), firmware.getProductId()); - - // 2. 保存 OTA 升级任务信息到数据库 - IotOtaUpgradeTaskDO upgradeTask = initOtaUpgradeTask(createReqVO, firmware.getProductId()); - upgradeTaskMapper.insert(upgradeTask); - - // 3. 生成设备升级记录信息并存储,等待定时任务轮询 - upgradeRecordService.createOtaUpgradeRecordBatch(upgradeTask.getDeviceIds(), firmware.getId(), upgradeTask.getId()); - return upgradeTask.getId(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void cancelUpgradeTask(Long id) { - // 1.1 校验升级任务是否存在 - IotOtaUpgradeTaskDO upgradeTask = validateUpgradeTaskExists(id); - // 1.2 校验升级任务是否可以取消 - // TODO @li:ObjUtil notequals - if (!Objects.equals(upgradeTask.getStatus(), IotOtaUpgradeTaskStatusEnum.IN_PROGRESS.getStatus())) { - throw exception(OTA_UPGRADE_TASK_CANNOT_CANCEL); - } - - // 2. 更新 OTA 升级任务状态为已取消 - upgradeTaskMapper.updateById(IotOtaUpgradeTaskDO.builder() - .id(id).status(IotOtaUpgradeTaskStatusEnum.CANCELED.getStatus()) - .build()); - - // 3. 更新 OTA 升级记录状态为已取消 - upgradeRecordService.cancelUpgradeRecordByTaskId(id); - } - - @Override - public IotOtaUpgradeTaskDO getUpgradeTask(Long id) { - return upgradeTaskMapper.selectById(id); - } - - @Override - public PageResult getUpgradeTaskPage(IotOtaUpgradeTaskPageReqVO pageReqVO) { - return upgradeTaskMapper.selectUpgradeTaskPage(pageReqVO); - } - - @Override - public List getUpgradeTaskByState(Integer state) { - return upgradeTaskMapper.selectUpgradeTaskByState(state); - } - - @Override - public void updateUpgradeTaskStatus(Long id, Integer status) { - upgradeTaskMapper.updateById(IotOtaUpgradeTaskDO.builder().id(id).status(status).build()); - } - - // TODO @li:注释有点冗余 - /** - * 校验固件升级任务是否重复 - *

- * 该方法用于检查给定固件ID和任务名称组合是否已存在于数据库中,如果存在则抛出异常, - * 表示任务名称对于该固件而言是重复的此检查确保用户不能创建具有相同名称的任务, - * 从而避免数据重复和混淆 - * - * @param firmwareId 固件的唯一标识符,用于区分不同的固件 - * @param taskName 升级任务的名称,用于与固件ID一起检查重复性 - * @throws cn.iocoder.yudao.framework.common.exception.ServerException 则抛出预定义的异常 - */ - private void validateFirmwareTaskDuplicate(Long firmwareId, String taskName) { - // 查询数据库中是否有相同固件ID和任务名称的升级任务存在 - List upgradeTaskList = upgradeTaskMapper.selectByFirmwareIdAndName(firmwareId, taskName); - // 如果查询结果不为空,说明存在重复的任务名称,抛出异常 - if (CollUtil.isNotEmpty(upgradeTaskList)) { - throw exception(OTA_UPGRADE_TASK_NAME_DUPLICATE); - } - } - - // TODO @li:注释有点冗余 - /** - * 验证升级任务的范围和设备列表的有效性。 - *

- * 根据升级任务的范围(scope),验证设备列表(deviceIds)或产品ID(productId)是否有效。 - * 如果范围是“选择设备”(SELECT),则必须提供设备列表;如果范围是“所有设备”(ALL),则必须根据产品ID获取设备列表,并确保列表不为空。 - * - * @param scope 升级任务的范围,参考 IotOtaUpgradeTaskScopeEnum 枚举值 - * @param deviceIds 设备ID列表,当范围为“选择设备”时,该列表不能为空 - * @param productId 产品ID,当范围为“所有设备”时,用于获取设备列表 - * @throws cn.iocoder.yudao.framework.common.exception.ServiceException,抛出相应的异常 - */ - private void validateScopeAndDevice(Integer scope, List deviceIds, String productId) { - // TODO @li:if return - // 验证范围为“选择设备”时,设备列表不能为空 - if (Objects.equals(scope, IotOtaUpgradeTaskScopeEnum.SELECT.getScope())) { - if (CollUtil.isEmpty(deviceIds)) { - throw exception(OTA_UPGRADE_TASK_DEVICE_IDS_EMPTY); - } - } else if (Objects.equals(scope, IotOtaUpgradeTaskScopeEnum.ALL.getScope())) { - // 验证范围为“所有设备”时,根据产品ID获取的设备列表不能为空 - List deviceList = deviceService.getDeviceListByProductId(Convert.toLong(productId)); - if (CollUtil.isEmpty(deviceList)) { - throw exception(OTA_UPGRADE_TASK_DEVICE_LIST_EMPTY); - } - } - } - - // TODO @li:注释有点冗余 - /** - * 验证升级任务是否存在 - *

- * 通过查询数据库来验证给定ID的升级任务是否存在此方法主要用于确保后续操作所针对的升级任务是有效的 - * - * @param id 升级任务的唯一标识符如果为null或数据库中不存在对应的记录,则认为任务不存在 - * @throws cn.iocoder.yudao.framework.common.exception.ServiceException 如果升级任务不存在,则抛出异常提示任务不存在 - */ - private IotOtaUpgradeTaskDO validateUpgradeTaskExists(Long id) { - // 查询数据库中是否有相同固件ID和任务名称的升级任务存在 - IotOtaUpgradeTaskDO upgradeTask = upgradeTaskMapper.selectById(id); - // 如果查询结果不为空,说明存在重复的任务名称,抛出异常 - if (Objects.isNull(upgradeTask)) { - throw exception(OTA_UPGRADE_TASK_NOT_EXISTS); - } - return upgradeTask; - } - - // TODO @li:注释有点冗余 - /** - * 初始化升级任务 - *

- * 根据请求参数创建升级任务对象,并根据选择的范围初始化设备数量 - * 如果选择特定设备进行升级,则设备数量为所选设备的总数 - * 如果选择全部设备进行升级,则设备数量为该固件对应产品下的所有设备总数 - * - * @param createReqVO 升级任务保存请求对象,包含创建升级任务所需的信息 - * @return 返回初始化后的升级任务对象 - */ - // TODO @li:一次性的方法,不用特别抽小方法 - private IotOtaUpgradeTaskDO initOtaUpgradeTask(IotOtaUpgradeTaskSaveReqVO createReqVO, String productId) { - // 将请求参数转换为升级任务对象 - IotOtaUpgradeTaskDO upgradeTask = BeanUtils.toBean(createReqVO, IotOtaUpgradeTaskDO.class); - // 初始化的时候,设置设备数量和状态 - upgradeTask.setDeviceCount(Convert.toLong(CollUtil.size(createReqVO.getDeviceIds()))) - .setStatus(IotOtaUpgradeTaskStatusEnum.IN_PROGRESS.getStatus()); - // 如果选择全选,则需要查询设备数量 - if (Objects.equals(createReqVO.getScope(), IotOtaUpgradeTaskScopeEnum.ALL.getScope())) { - // 根据产品ID查询设备数量 - List deviceList = deviceService.getDeviceListByProductId(Convert.toLong(productId)); - // 设置升级任务的设备数量 - upgradeTask.setDeviceCount((long) deviceList.size()); - upgradeTask.setDeviceIds( - deviceList.stream().map(IotDeviceDO::getId).collect(Collectors.toList())); - } - // 返回初始化后的升级任务对象 - return upgradeTask; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginConfigService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginConfigService.java deleted file mode 100644 index 8b6610f..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginConfigService.java +++ /dev/null @@ -1,100 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.plugin; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.config.PluginConfigPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.config.PluginConfigSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginConfigDO; -import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginDeployTypeEnum; -import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotEmpty; -import org.springframework.web.multipart.MultipartFile; - -import java.util.List; - -/** - * IoT 插件配置 Service 接口 - * - * @author haohao - */ -public interface IotPluginConfigService { - - /** - * 创建插件配置 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createPluginConfig(@Valid PluginConfigSaveReqVO createReqVO); - - /** - * 更新插件配置 - * - * @param updateReqVO 更新信息 - */ - void updatePluginConfig(@Valid PluginConfigSaveReqVO updateReqVO); - - /** - * 删除插件配置 - * - * @param id 编号 - */ - void deletePluginConfig(Long id); - - /** - * 获得插件配置 - * - * @param id 编号 - * @return 插件配置 - */ - IotPluginConfigDO getPluginConfig(Long id); - - /** - * 获得插件配置分页 - * - * @param pageReqVO 分页查询 - * @return 插件配置分页 - */ - PageResult getPluginConfigPage(PluginConfigPageReqVO pageReqVO); - - /** - * 上传插件的 JAR 包 - * - * @param id 插件id - * @param file 文件 - */ - void uploadFile(Long id, MultipartFile file); - - /** - * 更新插件的状态 - * - * @param id 插件id - * @param status 状态 {@link IotPluginStatusEnum} - */ - void updatePluginStatus(Long id, Integer status); - - /** - * 获得插件配置列表 - * - * @return 插件配置列表 - */ - List getPluginConfigList(); - - /** - * 根据状态和部署类型获得插件配置列表 - * - * @param status 状态 {@link IotPluginStatusEnum} - * @param deployType 部署类型 {@link IotPluginDeployTypeEnum} - * @return 插件配置列表 - */ - List getPluginConfigListByStatusAndDeployType(Integer status, Integer deployType); - - /** - * 根据插件包标识符获取插件配置 - * - * @param pluginKey 插件包标识符 - * @return 插件配置 - */ - IotPluginConfigDO getPluginConfigByPluginKey(@NotEmpty(message = "插件包标识符不能为空") String pluginKey); - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginConfigServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginConfigServiceImpl.java deleted file mode 100644 index 18376bc..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginConfigServiceImpl.java +++ /dev/null @@ -1,188 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.plugin; - -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.plugin.vo.config.PluginConfigPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.plugin.vo.config.PluginConfigSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginConfigDO; -import cn.iocoder.yudao.module.iot.dal.mysql.plugin.IotPluginConfigMapper; -import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.pf4j.PluginWrapper; -import org.pf4j.spring.SpringPluginManager; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.multipart.MultipartFile; - -import java.util.List; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*; -/** - * IoT 插件配置 Service 实现类 - * - * @author haohao - */ -@Service -@Validated -@Slf4j -public class IotPluginConfigServiceImpl implements IotPluginConfigService { - - @Resource - private IotPluginConfigMapper pluginConfigMapper; - - @Resource - private IotPluginInstanceService pluginInstanceService; - - @Resource - private SpringPluginManager springPluginManager; - - @Override - public Long createPluginConfig(PluginConfigSaveReqVO createReqVO) { - // 1. 校验插件标识唯一性:确保没有其他配置使用相同的 pluginKey(新建时 id 为 null) - validatePluginKeyUnique(null, createReqVO.getPluginKey()); - IotPluginConfigDO pluginConfig = BeanUtils.toBean(createReqVO, IotPluginConfigDO.class); - // 2. 插入插件配置到数据库 - pluginConfigMapper.insert(pluginConfig); - return pluginConfig.getId(); - } - - @Override - public void updatePluginConfig(PluginConfigSaveReqVO updateReqVO) { - // 1. 校验插件配置是否存在:根据传入 ID 判断记录是否存在 - validatePluginConfigExists(updateReqVO.getId()); - // 2. 校验插件标识唯一性:确保更新后的 pluginKey 没有被其他记录占用 - validatePluginKeyUnique(updateReqVO.getId(), updateReqVO.getPluginKey()); - // 3. 将更新请求对象转换为插件配置数据对象 - IotPluginConfigDO updateObj = BeanUtils.toBean(updateReqVO, IotPluginConfigDO.class); - pluginConfigMapper.updateById(updateObj); - } - - /** - * 校验插件标识唯一性 - * - * @param id 当前插件配置的 ID(如果为 null 则说明为新建操作) - * @param pluginKey 待校验的插件标识 - */ - private void validatePluginKeyUnique(Long id, String pluginKey) { - // 1. 根据 pluginKey 从数据库中查询已有的插件配置 - IotPluginConfigDO pluginConfig = pluginConfigMapper.selectByPluginKey(pluginKey); - // 2. 如果查询到记录且记录的 ID 与当前 ID 不相同,则认为存在重复,抛出异常 - if (pluginConfig != null && !pluginConfig.getId().equals(id)) { - throw exception(PLUGIN_CONFIG_KEY_DUPLICATE); - } - } - - @Override - public void deletePluginConfig(Long id) { - // 1. 校验存在 - IotPluginConfigDO pluginConfigDO = validatePluginConfigExists(id); - // 2. 未开启状态,才允许删除 - if (IotPluginStatusEnum.RUNNING.getStatus().equals(pluginConfigDO.getStatus())) { - throw exception(PLUGIN_CONFIG_DELETE_FAILED_RUNNING); - } - - // 3. 卸载插件 - pluginInstanceService.stopAndUnloadPlugin(pluginConfigDO.getPluginKey()); - // 4. 删除插件文件 - pluginInstanceService.deletePluginFile(pluginConfigDO); - - // 5. 删除插件配置 - pluginConfigMapper.deleteById(id); - } - - /** - * 校验插件配置是否存在 - * - * @param id 插件配置编号 - * @return 插件配置 - */ - private IotPluginConfigDO validatePluginConfigExists(Long id) { - IotPluginConfigDO pluginConfig = pluginConfigMapper.selectById(id); - if (pluginConfig == null) { - throw exception(PLUGIN_CONFIG_NOT_EXISTS); - } - return pluginConfig; - } - - @Override - public IotPluginConfigDO getPluginConfig(Long id) { - return pluginConfigMapper.selectById(id); - } - - @Override - public PageResult getPluginConfigPage(PluginConfigPageReqVO pageReqVO) { - return pluginConfigMapper.selectPage(pageReqVO); - } - - @Override - public void uploadFile(Long id, MultipartFile file) { - // 1. 校验插件配置是否存在 - IotPluginConfigDO pluginConfigDO = validatePluginConfigExists(id); - - // 2.1 停止并卸载旧的插件 - pluginInstanceService.stopAndUnloadPlugin(pluginConfigDO.getPluginKey()); - // 2.2 上传新的插件文件,更新插件启用状态文件 - String pluginKeyNew = pluginInstanceService.uploadAndLoadNewPlugin(file); - - // 3. 校验 file 相关参数,是否完整 - validatePluginConfigFile(pluginKeyNew); - - // 4. 更新插件配置 - IotPluginConfigDO updatedPluginConfig = new IotPluginConfigDO() - .setId(pluginConfigDO.getId()) - .setPluginKey(pluginKeyNew) - .setStatus(IotPluginStatusEnum.STOPPED.getStatus()) // TODO @haohao:这个状态,是不是非 stop 哈? - .setFileName(file.getOriginalFilename()) - .setScript("") // TODO @haohao:这个设置为 "" 会不会覆盖数据里的哈?应该从插件里读取?未来? - .setConfigSchema(springPluginManager.getPlugin(pluginKeyNew).getDescriptor().getPluginDescription()) - .setVersion(springPluginManager.getPlugin(pluginKeyNew).getDescriptor().getVersion()) - .setDescription(springPluginManager.getPlugin(pluginKeyNew).getDescriptor().getPluginDescription()); - pluginConfigMapper.updateById(updatedPluginConfig); - } - - /** - * 校验 file 相关参数 - * - * @param pluginKeyNew 插件标识符 - */ - private void validatePluginConfigFile(String pluginKeyNew) { - // TODO @haohao:校验 file 相关参数,是否完整,类似:version 之类是不是可以解析到 - PluginWrapper plugin = springPluginManager.getPlugin(pluginKeyNew); - if (plugin == null) { - throw exception(PLUGIN_INSTALL_FAILED); - } - if (plugin.getDescriptor().getVersion() == null) { - throw exception(PLUGIN_INSTALL_FAILED); - } - } - - @Override - public void updatePluginStatus(Long id, Integer status) { - // 1. 校验插件配置是否存在 - IotPluginConfigDO pluginConfigDo = validatePluginConfigExists(id); - - // 2. 更新插件状态 - pluginInstanceService.updatePluginStatus(pluginConfigDo, status); - - // 3. 更新数据库中的插件状态 - pluginConfigMapper.updateById(new IotPluginConfigDO().setId(id).setStatus(status)); - } - - @Override - public List getPluginConfigList() { - return pluginConfigMapper.selectList(); - } - - @Override - public List getPluginConfigListByStatusAndDeployType(Integer status, Integer deployType) { - return pluginConfigMapper.selectListByStatusAndDeployType(status, deployType); - } - - @Override - public IotPluginConfigDO getPluginConfigByPluginKey(String pluginKey) { - return pluginConfigMapper.selectByPluginKey(pluginKey); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginInstanceService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginInstanceService.java deleted file mode 100644 index 56e1bf0..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginInstanceService.java +++ /dev/null @@ -1,79 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.plugin; - -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotPluginInstanceHeartbeatReqDTO; -import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginConfigDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginInstanceDO; -import org.springframework.web.multipart.MultipartFile; - -import java.time.LocalDateTime; - -/** - * IoT 插件实例 Service 接口 - * - * @author 芋道源码 - */ -public interface IotPluginInstanceService { - - /** - * 心跳插件实例 - * - * @param heartbeatReqDTO 心跳插件实例 DTO - */ - void heartbeatPluginInstance(IotPluginInstanceHeartbeatReqDTO heartbeatReqDTO); - - /** - * 离线超时插件实例 - * - * @param maxHeartbeatTime 最大心跳时间 - */ - int offlineTimeoutPluginInstance(LocalDateTime maxHeartbeatTime); - - /** - * 停止并卸载插件 - * - * @param pluginKey 插件标识符 - */ - void stopAndUnloadPlugin(String pluginKey); - - /** - * 删除插件文件 - * - * @param pluginConfigDO 插件配置 - */ - void deletePluginFile(IotPluginConfigDO pluginConfigDO); - - /** - * 上传并加载新的插件文件 - * - * @param file 插件文件 - * @return 插件标识符 - */ - String uploadAndLoadNewPlugin(MultipartFile file); - - /** - * 更新插件状态 - * - * @param pluginConfigDO 插件配置 - * @param status 新状态 - */ - void updatePluginStatus(IotPluginConfigDO pluginConfigDO, Integer status); - - // ========== 设备与插件的映射操作 ========== - - /** - * 更新设备对应的插件实例的进程编号 - * - * @param deviceKey 设备 Key - * @param processId 进程编号 - */ - void updateDevicePluginInstanceProcessIdAsync(String deviceKey, String processId); - - /** - * 获得设备对应的插件实例 - * - * @param deviceKey 设备 Key - * @return 插件实例 - */ - IotPluginInstanceDO getPluginInstanceByDeviceKey(String deviceKey); - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginInstanceServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginInstanceServiceImpl.java deleted file mode 100644 index 3c15ff7..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/IotPluginInstanceServiceImpl.java +++ /dev/null @@ -1,231 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.plugin; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotPluginInstanceHeartbeatReqDTO; -import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginConfigDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.plugin.IotPluginInstanceDO; -import cn.iocoder.yudao.module.iot.dal.mysql.plugin.IotPluginInstanceMapper; -import cn.iocoder.yudao.module.iot.dal.redis.plugin.DevicePluginProcessIdRedisDAO; -import cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants; -import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.pf4j.PluginState; -import org.pf4j.PluginWrapper; -import org.pf4j.spring.SpringPluginManager; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.multipart.MultipartFile; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.time.LocalDateTime; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; - -/** - * IoT 插件实例 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Validated -@Slf4j -public class IotPluginInstanceServiceImpl implements IotPluginInstanceService { - - @Resource - @Lazy // 延迟加载,避免循环依赖 - private IotPluginConfigService pluginConfigService; - - @Resource - private IotPluginInstanceMapper pluginInstanceMapper; - - @Resource - private DevicePluginProcessIdRedisDAO devicePluginProcessIdRedisDAO; - - @Resource - private SpringPluginManager pluginManager; - - @Value("${pf4j.pluginsDir}") - private String pluginsDir; - - @Override - public void heartbeatPluginInstance(IotPluginInstanceHeartbeatReqDTO heartbeatReqDTO) { - // 情况一:已存在,则进行更新 - IotPluginInstanceDO instance = TenantUtils.executeIgnore( - () -> pluginInstanceMapper.selectByProcessId(heartbeatReqDTO.getProcessId())); - if (instance != null) { - IotPluginInstanceDO.IotPluginInstanceDOBuilder updateObj = IotPluginInstanceDO.builder().id(instance.getId()) - .hostIp(heartbeatReqDTO.getHostIp()).downstreamPort(heartbeatReqDTO.getDownstreamPort()) - .online(heartbeatReqDTO.getOnline()).heartbeatTime(LocalDateTime.now()); - if (Boolean.TRUE.equals(heartbeatReqDTO.getOnline())) { - if (Boolean.FALSE.equals(instance.getOnline())) { // 当前处于离线时,才需要更新上线时间 - updateObj.onlineTime(LocalDateTime.now()); - } - } else { - updateObj.offlineTime(LocalDateTime.now()); - } - TenantUtils.execute(instance.getTenantId(), - () -> pluginInstanceMapper.updateById(updateObj.build())); - return; - } - - // 情况二:不存在,则创建 - IotPluginConfigDO info = TenantUtils.executeIgnore( - () -> pluginConfigService.getPluginConfigByPluginKey(heartbeatReqDTO.getPluginKey())); - if (info == null) { - log.error("[heartbeatPluginInstance][心跳({}) 对应的插件不存在]", heartbeatReqDTO); - return; - } - IotPluginInstanceDO.IotPluginInstanceDOBuilder insertObj = IotPluginInstanceDO.builder() - .pluginId(info.getId()).processId(heartbeatReqDTO.getProcessId()) - .hostIp(heartbeatReqDTO.getHostIp()).downstreamPort(heartbeatReqDTO.getDownstreamPort()) - .online(heartbeatReqDTO.getOnline()).heartbeatTime(LocalDateTime.now()); - if (Boolean.TRUE.equals(heartbeatReqDTO.getOnline())) { - insertObj.onlineTime(LocalDateTime.now()); - } else { - insertObj.offlineTime(LocalDateTime.now()); - } - TenantUtils.execute(info.getTenantId(), - () -> pluginInstanceMapper.insert(insertObj.build())); - } - - @Override - public int offlineTimeoutPluginInstance(LocalDateTime maxHeartbeatTime) { - List list = pluginInstanceMapper.selectListByHeartbeatTimeLt(maxHeartbeatTime); - if (CollUtil.isEmpty(list)) { - return 0; - } - - // 更新插件实例为离线 - int count = 0; - for (IotPluginInstanceDO instance : list) { - pluginInstanceMapper.updateById(IotPluginInstanceDO.builder().id(instance.getId()) - .online(false).offlineTime(LocalDateTime.now()).build()); - count++; - } - return count; - } - - @Override - public void stopAndUnloadPlugin(String pluginKey) { - PluginWrapper plugin = pluginManager.getPlugin(pluginKey); - if (plugin == null) { - log.warn("插件不存在或已卸载: {}", pluginKey); - return; - } - if (plugin.getPluginState().equals(PluginState.STARTED)) { - pluginManager.stopPlugin(pluginKey); // 停止插件 - log.info("已停止插件: {}", pluginKey); - } - pluginManager.unloadPlugin(pluginKey); // 卸载插件 - log.info("已卸载插件: {}", pluginKey); - } - - @Override - public void deletePluginFile(IotPluginConfigDO pluginConfigDO) { - File file = new File(pluginsDir, pluginConfigDO.getFileName()); - if (!file.exists()) { - return; - } - try { - TimeUnit.SECONDS.sleep(1); // 等待 1 秒,避免插件未卸载完毕 - if (!file.delete()) { - log.error("[deletePluginFile][删除插件文件({}) 失败]", pluginConfigDO.getFileName()); - } - } catch (InterruptedException e) { - log.error("[deletePluginFile][删除插件文件({}) 失败]", pluginConfigDO.getFileName(), e); - } - } - - @Override - public String uploadAndLoadNewPlugin(MultipartFile file) { - String pluginKeyNew; - // TODO @haohao:多节点,是不是要上传 s3 之类的存储器;然后定时去加载 - Path pluginsPath = Paths.get(pluginsDir); - try { - FileUtil.mkdir(pluginsPath.toFile()); // 创建插件目录 - String filename = file.getOriginalFilename(); - if (filename != null) { - Path jarPath = pluginsPath.resolve(filename); - Files.copy(file.getInputStream(), jarPath, StandardCopyOption.REPLACE_EXISTING); // 保存上传的 JAR 文件 - pluginKeyNew = pluginManager.loadPlugin(jarPath.toAbsolutePath()); // 加载插件 - log.info("已加载插件: {}", pluginKeyNew); - } else { - throw exception(ErrorCodeConstants.PLUGIN_INSTALL_FAILED); - } - } catch (IOException e) { - log.error("[uploadAndLoadNewPlugin][上传插件文件失败]", e); - throw exception(ErrorCodeConstants.PLUGIN_INSTALL_FAILED, e); - } catch (Exception e) { - log.error("[uploadAndLoadNewPlugin][加载插件失败]", e); - throw exception(ErrorCodeConstants.PLUGIN_INSTALL_FAILED, e); - } - return pluginKeyNew; - } - - @Override - public void updatePluginStatus(IotPluginConfigDO pluginConfigDO, Integer status) { - String pluginKey = pluginConfigDO.getPluginKey(); - PluginWrapper plugin = pluginManager.getPlugin(pluginKey); - - if (plugin == null) { - // 插件不存在且状态为停止,抛出异常 - if (IotPluginStatusEnum.STOPPED.getStatus().equals(pluginConfigDO.getStatus())) { - throw exception(ErrorCodeConstants.PLUGIN_STATUS_INVALID); - } - return; - } - - // 启动插件 - if (status.equals(IotPluginStatusEnum.RUNNING.getStatus()) - && plugin.getPluginState() != PluginState.STARTED) { - try { - pluginManager.startPlugin(pluginKey); - } catch (Exception e) { - log.error("[updatePluginStatus][启动插件({}) 失败]", pluginKey, e); - throw exception(ErrorCodeConstants.PLUGIN_START_FAILED, e); - } - log.info("已启动插件: {}", pluginKey); - } - // 停止插件 - else if (status.equals(IotPluginStatusEnum.STOPPED.getStatus()) - && plugin.getPluginState() == PluginState.STARTED) { - try { - pluginManager.stopPlugin(pluginKey); - } catch (Exception e) { - log.error("[updatePluginStatus][停止插件({}) 失败]", pluginKey, e); - throw exception(ErrorCodeConstants.PLUGIN_STOP_FAILED, e); - } - log.info("已停止插件: {}", pluginKey); - } - } - - // ========== 设备与插件的映射操作 ========== - - @Override - public void updateDevicePluginInstanceProcessIdAsync(String deviceKey, String processId) { - devicePluginProcessIdRedisDAO.put(deviceKey, processId); - } - - @Override - public IotPluginInstanceDO getPluginInstanceByDeviceKey(String deviceKey) { - String processId = devicePluginProcessIdRedisDAO.get(deviceKey); - if (StrUtil.isEmpty(processId)) { - return null; - } - return pluginInstanceMapper.selectByProcessId(processId); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryService.java deleted file mode 100644 index 8cc6405..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryService.java +++ /dev/null @@ -1,103 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.product; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategoryPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategorySaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; -import jakarta.validation.Valid; - -import javax.annotation.Nullable; -import java.time.LocalDateTime; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; - -/** - * IoT 产品分类 Service 接口 - * - * @author 芋道源码 - */ -public interface IotProductCategoryService { - - /** - * 创建产品分类 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createProductCategory(@Valid IotProductCategorySaveReqVO createReqVO); - - /** - * 更新产品分类 - * - * @param updateReqVO 更新信息 - */ - void updateProductCategory(@Valid IotProductCategorySaveReqVO updateReqVO); - - /** - * 删除产品分类 - * - * @param id 编号 - */ - void deleteProductCategory(Long id); - - /** - * 获得产品分类 - * - * @param id 编号 - * @return 产品分类 - */ - IotProductCategoryDO getProductCategory(Long id); - - /** - * 获得产品分类列表 - * - * @param ids 编号 - * @return 产品分类列表 - */ - List getProductCategoryList(Collection ids); - - /** - * 获得产品分类 Map - * - * @param ids 编号 - * @return 产品分类 Map - */ - default Map getProductCategoryMap(Collection ids) { - return convertMap(getProductCategoryList(ids), IotProductCategoryDO::getId); - } - - /** - * 获得产品分类分页 - * - * @param pageReqVO 分页查询 - * @return 产品分类分页 - */ - PageResult getProductCategoryPage(IotProductCategoryPageReqVO pageReqVO); - - /** - * 获得产品分类列表,根据状态 - * - * @param status 状态 - * @return 产品分类列表 - */ - List getProductCategoryListByStatus(Integer status); - - /** - * 获得产品分类数量 - * - * @param createTime 创建时间,如果为空,则统计所有分类数量 - * @return 产品分类数量 - */ - Long getProductCategoryCount(@Nullable LocalDateTime createTime); - - /** - * 获得各个品类下设备数量统计,其中 key 是产品分类名 - * - * @return 品类设备统计列表 - */ - Map getProductCategoryDeviceCountMap(); - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java deleted file mode 100644 index 9eb401c..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java +++ /dev/null @@ -1,123 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.product; - -import cn.hutool.core.collection.CollUtil; -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.product.vo.category.IotProductCategoryPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProductCategorySaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.dal.mysql.product.IotProductCategoryMapper; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.time.LocalDateTime; -import java.util.*; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_CATEGORY_NOT_EXISTS; - -/** - * IoT 产品分类 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Validated -public class IotProductCategoryServiceImpl implements IotProductCategoryService { - - @Resource - private IotProductCategoryMapper iotProductCategoryMapper; - - @Resource - private IotProductService productService; - - @Resource - private IotDeviceService deviceService; - - public Long createProductCategory(IotProductCategorySaveReqVO createReqVO) { - // 插入 - IotProductCategoryDO productCategory = BeanUtils.toBean(createReqVO, IotProductCategoryDO.class); - iotProductCategoryMapper.insert(productCategory); - // 返回 - return productCategory.getId(); - } - - @Override - public void updateProductCategory(IotProductCategorySaveReqVO updateReqVO) { - // 校验存在 - validateProductCategoryExists(updateReqVO.getId()); - // 更新 - IotProductCategoryDO updateObj = BeanUtils.toBean(updateReqVO, IotProductCategoryDO.class); - iotProductCategoryMapper.updateById(updateObj); - } - - @Override - public void deleteProductCategory(Long id) { - // 校验存在 - validateProductCategoryExists(id); - // 删除 - iotProductCategoryMapper.deleteById(id); - } - - private void validateProductCategoryExists(Long id) { - if (iotProductCategoryMapper.selectById(id) == null) { - throw exception(PRODUCT_CATEGORY_NOT_EXISTS); - } - } - - @Override - public IotProductCategoryDO getProductCategory(Long id) { - return iotProductCategoryMapper.selectById(id); - } - - @Override - public List getProductCategoryList(Collection ids) { - if (CollUtil.isEmpty(ids)) { - return CollUtil.newArrayList(); - } - return iotProductCategoryMapper.selectByIds(ids); - } - - @Override - public PageResult getProductCategoryPage(IotProductCategoryPageReqVO pageReqVO) { - return iotProductCategoryMapper.selectPage(pageReqVO); - } - - @Override - public List getProductCategoryListByStatus(Integer status) { - return iotProductCategoryMapper.selectListByStatus(status); - } - - @Override - public Long getProductCategoryCount(LocalDateTime createTime) { - return iotProductCategoryMapper.selectCountByCreateTime(createTime); - } - - @Override - public Map getProductCategoryDeviceCountMap() { - // 1. 获取所有数据 - List categoryList = iotProductCategoryMapper.selectList(); - List productList = productService.getProductList(); - // TODO @super:不要 list 查询,返回内存,而是查询一个 Map - Map deviceCountMapByProductId = deviceService.getDeviceCountMapByProductId(); - - // 2. 统计每个分类下的设备数量 - Map categoryDeviceCountMap = new HashMap<>(); - for (IotProductCategoryDO category : categoryList) { - categoryDeviceCountMap.put(category.getName(), 0); - // TODO @super:CollectionUtils.getSumValue(),看看能不能简化下 - // 2.2 找到该分类下的所有产品,累加设备数量 - for (IotProductDO product : productList) { - if (Objects.equals(product.getCategoryId(), category.getId())) { - Integer deviceCount = deviceCountMapByProductId.getOrDefault(product.getId(), 0); - categoryDeviceCountMap.merge(category.getName(), deviceCount, Integer::sum); - } - } - } - return categoryDeviceCountMap; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductService.java deleted file mode 100644 index 8497d73..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductService.java +++ /dev/null @@ -1,106 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.product; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import jakarta.validation.Valid; - -import javax.annotation.Nullable; -import java.time.LocalDateTime; -import java.util.List; - -/** - * IoT 产品 Service 接口 - * - * @author ahh - */ -public interface IotProductService { - - /** - * 创建产品 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createProduct(@Valid IotProductSaveReqVO createReqVO); - - /** - * 更新产品 - * - * @param updateReqVO 更新信息 - */ - void updateProduct(@Valid IotProductSaveReqVO updateReqVO); - - /** - * 删除产品 - * - * @param id 编号 - */ - void deleteProduct(Long id); - - /** - * 获得产品 - * - * @param id 编号 - * @return 产品 - */ - IotProductDO getProduct(Long id); - - /** - * 根据产品 key 获得产品 - * - * @param productKey 产品 key - * @return 产品 - */ - IotProductDO getProductByProductKey(String productKey); - - /** - * 校验产品存在 - * - * @param id 编号 - * @return 产品 - */ - IotProductDO validateProductExists(Long id); - - /** - * 校验产品存在 - * - * @param productKey 产品 key - * @return 产品 - */ - IotProductDO validateProductExists(String productKey); - - /** - * 获得产品分页 - * - * @param pageReqVO 分页查询 - * @return 产品分页 - */ - PageResult getProductPage(IotProductPageReqVO pageReqVO); - - /** - * 更新产品状态 - * - * @param id 编号 - * @param status 状态 - */ - void updateProductStatus(Long id, Integer status); - - /** - * 获得所有产品 - * - * @return 产品列表 - */ - List getProductList(); - - /** - * 获得产品数量 - * - * @param createTime 创建时间,如果为空,则统计所有产品数量 - * @return 产品数量 - */ - Long getProductCount(@Nullable LocalDateTime createTime); - - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java deleted file mode 100644 index 4a7263c..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java +++ /dev/null @@ -1,147 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.product; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; -import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.product.vo.product.IotProductSaveReqVO; -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.device.data.IotDevicePropertyService; -import com.baomidou.dynamic.datasource.annotation.DSTransactional; -import jakarta.annotation.Resource; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Objects; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*; - -/** - * IoT 产品 Service 实现类 - * - * @author ahh - */ -@Service -@Validated -public class IotProductServiceImpl implements IotProductService { - - @Resource - private IotProductMapper productMapper; - - @Resource - @Lazy // 延迟加载,解决循环依赖 - private IotDevicePropertyService devicePropertyDataService; - - @Override - public Long createProduct(IotProductSaveReqVO createReqVO) { - // 1. 校验 ProductKey - TenantUtils.executeIgnore(() -> { - // 为什么忽略租户?避免多个租户之间,productKey 重复,导致 TDengine 设备属性表重复 - if (productMapper.selectByProductKey(createReqVO.getProductKey()) != null) { - throw exception(PRODUCT_KEY_EXISTS); - } - }); - - // 2. 插入 - IotProductDO product = BeanUtils.toBean(createReqVO, IotProductDO.class) - .setStatus(IotProductStatusEnum.UNPUBLISHED.getStatus()); - productMapper.insert(product); - return product.getId(); - } - - @Override - public void updateProduct(IotProductSaveReqVO updateReqVO) { - updateReqVO.setProductKey(null); // 不更新产品标识 - // 1.1 校验存在 - IotProductDO iotProductDO = validateProductExists(updateReqVO.getId()); - // 1.2 发布状态不可更新 - validateProductStatus(iotProductDO); - // 2. 更新 - IotProductDO updateObj = BeanUtils.toBean(updateReqVO, IotProductDO.class); - productMapper.updateById(updateObj); - } - - @Override - public void deleteProduct(Long id) { - // 1.1 校验存在 - IotProductDO iotProductDO = validateProductExists(id); - // 1.2 发布状态不可删除 - validateProductStatus(iotProductDO); - // 2. 删除 - productMapper.deleteById(id); - } - - @Override - public IotProductDO validateProductExists(Long id) { - IotProductDO product = productMapper.selectById(id); - if (product == null) { - throw exception(PRODUCT_NOT_EXISTS); - } - return product; - } - - @Override - public IotProductDO validateProductExists(String productKey) { - IotProductDO product = productMapper.selectByProductKey(productKey); - if (product == null) { - throw exception(PRODUCT_NOT_EXISTS); - } - return product; - } - - private void validateProductStatus(IotProductDO product) { - if (Objects.equals(product.getStatus(), IotProductStatusEnum.PUBLISHED.getStatus())) { - throw exception(PRODUCT_STATUS_NOT_DELETE); - } - } - - @Override - public IotProductDO getProduct(Long id) { - return productMapper.selectById(id); - } - - @Override - public IotProductDO getProductByProductKey(String productKey) { - return productMapper.selectByProductKey(productKey); - } - - @Override - public PageResult getProductPage(IotProductPageReqVO pageReqVO) { - return productMapper.selectPage(pageReqVO); - } - - @Override - @DSTransactional(rollbackFor = Exception.class) - public void updateProductStatus(Long id, Integer status) { - // 1. 校验存在 - validateProductExists(id); - - // 2. 更新为发布状态,需要创建产品超级表数据模型 - // TODO @芋艿:【待定 001】1)是否需要操作后,在 redis 进行缓存,实现一个“快照”的情况,类似 tl; - if (Objects.equals(status, IotProductStatusEnum.PUBLISHED.getStatus())) { - devicePropertyDataService.defineDevicePropertyData(id); - } - - // 3. 更新 - IotProductDO updateObj = IotProductDO.builder().id(id).status(status).build(); - productMapper.updateById(updateObj); - } - - @Override - public List getProductList() { - return productMapper.selectList(); - } - - @Override - public Long getProductCount(LocalDateTime createTime) { - return productMapper.selectCountByCreateTime(createTime); - } - - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotDataBridgeService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotDataBridgeService.java deleted file mode 100644 index 1806937..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotDataBridgeService.java +++ /dev/null @@ -1,54 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.IotDataBridgePageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.IotDataBridgeSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; -import jakarta.validation.Valid; - -/** - * IoT 数据桥梁 Service 接口 - * - * @author HUIHUI - */ -public interface IotDataBridgeService { - - /** - * 创建数据桥梁 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createDataBridge(@Valid IotDataBridgeSaveReqVO createReqVO); - - /** - * 更新数据桥梁 - * - * @param updateReqVO 更新信息 - */ - void updateDataBridge(@Valid IotDataBridgeSaveReqVO updateReqVO); - - /** - * 删除数据桥梁 - * - * @param id 编号 - */ - void deleteDataBridge(Long id); - - /** - * 获得数据桥梁 - * - * @param id 编号 - * @return 数据桥梁 - */ - IotDataBridgeDO getDataBridge(Long id); - - /** - * 获得数据桥梁分页 - * - * @param pageReqVO 分页查询 - * @return 数据桥梁分页 - */ - PageResult getDataBridgePage(IotDataBridgePageReqVO pageReqVO); - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotDataBridgeServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotDataBridgeServiceImpl.java deleted file mode 100644 index 9e439fc..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotDataBridgeServiceImpl.java +++ /dev/null @@ -1,70 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule; - -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.rule.vo.databridge.IotDataBridgePageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.IotDataBridgeSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; -import cn.iocoder.yudao.module.iot.dal.mysql.rule.IotDataBridgeMapper; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DATA_BRIDGE_NOT_EXISTS; - -/** - * IoT 数据桥梁 Service 实现类 - * - * @author HUIHUI - */ -@Service -@Validated -public class IotDataBridgeServiceImpl implements IotDataBridgeService { - - @Resource - private IotDataBridgeMapper dataBridgeMapper; - - @Override - public Long createDataBridge(IotDataBridgeSaveReqVO createReqVO) { - // 插入 - IotDataBridgeDO dataBridge = BeanUtils.toBean(createReqVO, IotDataBridgeDO.class); - dataBridgeMapper.insert(dataBridge); - // 返回 - return dataBridge.getId(); - } - - @Override - public void updateDataBridge(IotDataBridgeSaveReqVO updateReqVO) { - // 校验存在 - validateDataBridgeExists(updateReqVO.getId()); - // 更新 - IotDataBridgeDO updateObj = BeanUtils.toBean(updateReqVO, IotDataBridgeDO.class); - dataBridgeMapper.updateById(updateObj); - } - - @Override - public void deleteDataBridge(Long id) { - // 校验存在 - validateDataBridgeExists(id); - // 删除 - dataBridgeMapper.deleteById(id); - } - - private void validateDataBridgeExists(Long id) { - if (dataBridgeMapper.selectById(id) == null) { - throw exception(DATA_BRIDGE_NOT_EXISTS); - } - } - - @Override - public IotDataBridgeDO getDataBridge(Long id) { - return dataBridgeMapper.selectById(id); - } - - @Override - public PageResult getDataBridgePage(IotDataBridgePageReqVO pageReqVO) { - return dataBridgeMapper.selectPage(pageReqVO); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotRuleSceneService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotRuleSceneService.java deleted file mode 100644 index 6927b11..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotRuleSceneService.java +++ /dev/null @@ -1,44 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule; - -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; - -import java.util.List; - -/** - * IoT 规则场景 Service 接口 - * - * @author 芋道源码 - */ -public interface IotRuleSceneService { - - /** - * 【缓存】获得指定设备的场景列表 - * - * @param productKey 产品 Key - * @param deviceName 设备名称 - * @return 场景列表 - */ - List getRuleSceneListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName); - - /** - * 基于 {@link IotRuleSceneTriggerTypeEnum#DEVICE} 场景,执行规则场景 - * - * @param message 消息 - */ - void executeRuleSceneByDevice(IotDeviceMessage message); - - /** - * 基于 {@link IotRuleSceneTriggerTypeEnum#TIMER} 场景,执行规则场景 - * - * @param id 场景编号 - */ - void executeRuleSceneByTimer(Long id); - - /** - * TODO 芋艿:测试方法,需要删除 - */ - void test(); - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotRuleSceneServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotRuleSceneServiceImpl.java deleted file mode 100644 index 2219d4b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/IotRuleSceneServiceImpl.java +++ /dev/null @@ -1,438 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.ListUtil; -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.text.CharPool; -import cn.hutool.core.util.NumberUtil; -import cn.hutool.core.util.ObjUtil; -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.util.number.NumberUtils; -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; -import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils; -import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; -import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; -import cn.iocoder.yudao.module.iot.dal.mysql.rule.IotRuleSceneMapper; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageIdentifierEnum; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceMessageTypeEnum; -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerConditionParameterOperatorEnum; -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneTriggerTypeEnum; -import cn.iocoder.yudao.module.iot.framework.job.core.IotSchedulerManager; -import cn.iocoder.yudao.module.iot.job.rule.IotRuleSceneJob; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import cn.iocoder.yudao.module.iot.service.rule.action.IotRuleSceneAction; -import jakarta.annotation.Resource; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; -import org.quartz.JobKey; -import org.quartz.Scheduler; -import org.quartz.SchedulerException; -import org.quartz.TriggerKey; -import org.quartz.impl.StdSchedulerFactory; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; - -/** - * IoT 规则场景 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Validated -@Slf4j -public class IotRuleSceneServiceImpl implements IotRuleSceneService { - - @Resource - private IotRuleSceneMapper ruleSceneMapper; - - @Resource - private List ruleSceneActions; - - @Resource(name = "iotSchedulerManager") - private IotSchedulerManager schedulerManager; - - // TODO 芋艿,缓存待实现 - @Override - @TenantIgnore // 忽略租户隔离:因为 IotRuleSceneMessageHandler 调用时,一般未传递租户,所以需要忽略 - public List getRuleSceneListByProductKeyAndDeviceNameFromCache(String productKey, String deviceName) { - if (true) { - IotRuleSceneDO ruleScene01 = new IotRuleSceneDO(); - ruleScene01.setTriggers(CollUtil.newArrayList()); - IotRuleSceneDO.TriggerConfig trigger01 = new IotRuleSceneDO.TriggerConfig(); - trigger01.setType(IotRuleSceneTriggerTypeEnum.DEVICE.getType()); - trigger01.setConditions(CollUtil.newArrayList()); - // 属性 - IotRuleSceneDO.TriggerCondition condition01 = new IotRuleSceneDO.TriggerCondition(); - condition01.setType(IotDeviceMessageTypeEnum.PROPERTY.getType()); - condition01.setIdentifier(IotDeviceMessageIdentifierEnum.PROPERTY_REPORT.getIdentifier()); - condition01.setParameters(CollUtil.newArrayList()); -// IotRuleSceneDO.TriggerConditionParameter parameter010 = new IotRuleSceneDO.TriggerConditionParameter(); -// parameter010.setIdentifier("width"); -// parameter010.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.getOperator()); -// parameter010.setValue("abc"); -// condition01.getParameters().add(parameter010); - IotRuleSceneDO.TriggerConditionParameter parameter011 = new IotRuleSceneDO.TriggerConditionParameter(); - parameter011.setIdentifier("width"); - parameter011.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.getOperator()); - parameter011.setValue("1"); - condition01.getParameters().add(parameter011); - IotRuleSceneDO.TriggerConditionParameter parameter012 = new IotRuleSceneDO.TriggerConditionParameter(); - parameter012.setIdentifier("width"); - parameter012.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_EQUALS.getOperator()); - parameter012.setValue("2"); - condition01.getParameters().add(parameter012); - IotRuleSceneDO.TriggerConditionParameter parameter013 = new IotRuleSceneDO.TriggerConditionParameter(); - parameter013.setIdentifier("width"); - parameter013.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.GREATER_THAN.getOperator()); - parameter013.setValue("0"); - condition01.getParameters().add(parameter013); - IotRuleSceneDO.TriggerConditionParameter parameter014 = new IotRuleSceneDO.TriggerConditionParameter(); - parameter014.setIdentifier("width"); - parameter014.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.GREATER_THAN_OR_EQUALS.getOperator()); - parameter014.setValue("0"); - condition01.getParameters().add(parameter014); - IotRuleSceneDO.TriggerConditionParameter parameter015 = new IotRuleSceneDO.TriggerConditionParameter(); - parameter015.setIdentifier("width"); - parameter015.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.LESS_THAN.getOperator()); - parameter015.setValue("2"); - condition01.getParameters().add(parameter015); - IotRuleSceneDO.TriggerConditionParameter parameter016 = new IotRuleSceneDO.TriggerConditionParameter(); - parameter016.setIdentifier("width"); - parameter016.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.LESS_THAN_OR_EQUALS.getOperator()); - parameter016.setValue("2"); - condition01.getParameters().add(parameter016); - IotRuleSceneDO.TriggerConditionParameter parameter017 = new IotRuleSceneDO.TriggerConditionParameter(); - parameter017.setIdentifier("width"); - parameter017.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.IN.getOperator()); - parameter017.setValue("1,2,3"); - condition01.getParameters().add(parameter017); - IotRuleSceneDO.TriggerConditionParameter parameter018 = new IotRuleSceneDO.TriggerConditionParameter(); - parameter018.setIdentifier("width"); - parameter018.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_IN.getOperator()); - parameter018.setValue("0,2,3"); - condition01.getParameters().add(parameter018); - IotRuleSceneDO.TriggerConditionParameter parameter019 = new IotRuleSceneDO.TriggerConditionParameter(); - parameter019.setIdentifier("width"); - parameter019.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.BETWEEN.getOperator()); - parameter019.setValue("1,3"); - condition01.getParameters().add(parameter019); - IotRuleSceneDO.TriggerConditionParameter parameter020 = new IotRuleSceneDO.TriggerConditionParameter(); - parameter020.setIdentifier("width"); - parameter020.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_BETWEEN.getOperator()); - parameter020.setValue("2,3"); - condition01.getParameters().add(parameter020); - trigger01.getConditions().add(condition01); - // 状态 - IotRuleSceneDO.TriggerCondition condition02 = new IotRuleSceneDO.TriggerCondition(); - condition02.setType(IotDeviceMessageTypeEnum.STATE.getType()); - condition02.setIdentifier(IotDeviceMessageIdentifierEnum.STATE_ONLINE.getIdentifier()); - condition02.setParameters(CollUtil.newArrayList()); - trigger01.getConditions().add(condition02); - // 事件 - IotRuleSceneDO.TriggerCondition condition03 = new IotRuleSceneDO.TriggerCondition(); - condition03.setType(IotDeviceMessageTypeEnum.EVENT.getType()); - condition03.setIdentifier("xxx"); - condition03.setParameters(CollUtil.newArrayList()); - IotRuleSceneDO.TriggerConditionParameter parameter030 = new IotRuleSceneDO.TriggerConditionParameter(); - parameter030.setIdentifier("width"); - parameter030.setOperator(IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.getOperator()); - parameter030.setValue("1"); - trigger01.getConditions().add(condition03); - ruleScene01.getTriggers().add(trigger01); - // 动作 - ruleScene01.setActions(CollUtil.newArrayList()); - // 设备控制 - IotRuleSceneDO.ActionConfig action01 = new IotRuleSceneDO.ActionConfig(); - action01.setType(IotRuleSceneActionTypeEnum.DEVICE_CONTROL.getType()); - IotRuleSceneDO.ActionDeviceControl actionDeviceControl01 = new IotRuleSceneDO.ActionDeviceControl(); - actionDeviceControl01.setProductKey("4aymZgOTOOCrDKRT"); - actionDeviceControl01.setDeviceNames(ListUtil.of("small")); - actionDeviceControl01.setType(IotDeviceMessageTypeEnum.PROPERTY.getType()); - actionDeviceControl01.setIdentifier(IotDeviceMessageIdentifierEnum.PROPERTY_SET.getIdentifier()); - actionDeviceControl01.setData(MapUtil.builder() - .put("power", 1) - .put("color", "red") - .build()); - action01.setDeviceControl(actionDeviceControl01); -// ruleScene01.getActions().add(action01); // TODO 芋艿:先不测试了 - // 数据桥接(http) - IotRuleSceneDO.ActionConfig action02 = new IotRuleSceneDO.ActionConfig(); - action02.setType(IotRuleSceneActionTypeEnum.DATA_BRIDGE.getType()); - action02.setDataBridgeId(1L); - ruleScene01.getActions().add(action02); - return ListUtil.toList(ruleScene01); - } - - List list = ruleSceneMapper.selectList(); - // TODO @芋艿:需要考虑开启状态 - return filterList(list, ruleScene -> { - for (IotRuleSceneDO.TriggerConfig trigger : ruleScene.getTriggers()) { - if (ObjUtil.notEqual(trigger.getProductKey(), productKey)) { - continue; - } - if (CollUtil.isEmpty(trigger.getDeviceNames()) // 无设备名称限制 - || trigger.getDeviceNames().contains(deviceName)) { // 包含设备名称 - return true; - } - } - return false; - }); - } - - @Override - public void executeRuleSceneByDevice(IotDeviceMessage message) { - TenantUtils.execute(message.getTenantId(), () -> { - // 1. 获得设备匹配的规则场景 - List ruleScenes = getMatchedRuleSceneListByMessage(message); - if (CollUtil.isEmpty(ruleScenes)) { - return; - } - - // 2. 执行规则场景 - executeRuleSceneAction(message, ruleScenes); - }); - } - - @Override - public void executeRuleSceneByTimer(Long id) { - // 1.1 获得规则场景 -// IotRuleSceneDO scene = TenantUtils.executeIgnore(() -> ruleSceneMapper.selectById(id)); - // TODO @芋艿:这里,临时测试,后续删除。 - IotRuleSceneDO scene = new IotRuleSceneDO().setStatus(CommonStatusEnum.ENABLE.getStatus()); - if (true) { - scene.setTenantId(1L); - IotRuleSceneDO.TriggerConfig triggerConfig = new IotRuleSceneDO.TriggerConfig(); - triggerConfig.setType(IotRuleSceneTriggerTypeEnum.TIMER.getType()); - scene.setTriggers(ListUtil.toList(triggerConfig)); - // 动作 - IotRuleSceneDO.ActionConfig action01 = new IotRuleSceneDO.ActionConfig(); - action01.setType(IotRuleSceneActionTypeEnum.DEVICE_CONTROL.getType()); - IotRuleSceneDO.ActionDeviceControl actionDeviceControl01 = new IotRuleSceneDO.ActionDeviceControl(); - actionDeviceControl01.setProductKey("4aymZgOTOOCrDKRT"); - actionDeviceControl01.setDeviceNames(ListUtil.of("small")); - actionDeviceControl01.setType(IotDeviceMessageTypeEnum.PROPERTY.getType()); - actionDeviceControl01.setIdentifier(IotDeviceMessageIdentifierEnum.PROPERTY_SET.getIdentifier()); - actionDeviceControl01.setData(MapUtil.builder() - .put("power", 1) - .put("color", "red") - .build()); - action01.setDeviceControl(actionDeviceControl01); - scene.setActions(ListUtil.toList(action01)); - } - if (scene == null) { - log.error("[executeRuleSceneByTimer][规则场景({}) 不存在]", id); - return; - } - if (CommonStatusEnum.isDisable(scene.getStatus())) { - log.info("[executeRuleSceneByTimer][规则场景({}) 已被禁用]", id); - return; - } - // 1.2 判断是否有定时触发器,避免脏数据 - IotRuleSceneDO.TriggerConfig config = CollUtil.findOne(scene.getTriggers(), - trigger -> ObjUtil.equals(trigger.getType(), IotRuleSceneTriggerTypeEnum.TIMER.getType())); - if (config == null) { - log.error("[executeRuleSceneByTimer][规则场景({}) 不存在定时触发器]", scene); - return; - } - - // 2. 执行规则场景 - TenantUtils.execute(scene.getTenantId(), - () -> executeRuleSceneAction(null, ListUtil.toList(scene))); - } - - /** - * 基于消息,获得匹配的规则场景列表 - * - * @param message 设备消息 - * @return 规则场景列表 - */ - private List getMatchedRuleSceneListByMessage(IotDeviceMessage message) { - // 1. 匹配设备 - // TODO @芋艿:可能需要 getSelf(); 缓存 - List ruleScenes = getRuleSceneListByProductKeyAndDeviceNameFromCache( - message.getProductKey(), message.getDeviceName()); - if (CollUtil.isEmpty(ruleScenes)) { - return ruleScenes; - } - - // 2. 匹配 trigger 触发器的条件 - return filterList(ruleScenes, ruleScene -> { - for (IotRuleSceneDO.TriggerConfig trigger : ruleScene.getTriggers()) { - // 2.1 非设备触发,不匹配 - if (ObjUtil.notEqual(trigger.getType(), IotRuleSceneTriggerTypeEnum.DEVICE.getType())) { - return false; - } - // TODO 芋艿:产品、设备的匹配,要不要这里在做一次???貌似和 1. 部分重复了 - // 2.2 条件为空,说明没有匹配的条件,因此不匹配 - if (CollUtil.isEmpty(trigger.getConditions())) { - return false; - } - // 2.3 多个条件,只需要满足一个即可 - IotRuleSceneDO.TriggerCondition matchedCondition = CollUtil.findOne(trigger.getConditions(), condition -> { - if (ObjUtil.notEqual(message.getType(), condition.getType()) - || ObjUtil.notEqual(message.getIdentifier(), condition.getIdentifier())) { - return false; - } - // 多个条件参数,必须全部满足。所以,下面的逻辑就是找到一个不满足的条件参数 - IotRuleSceneDO.TriggerConditionParameter notMatchedParameter = CollUtil.findOne(condition.getParameters(), - parameter -> !isTriggerConditionParameterMatched(message, parameter, ruleScene, trigger)); - return notMatchedParameter == null; - }); - if (matchedCondition == null) { - return false; - } - log.info("[getMatchedRuleSceneList][消息({}) 匹配到规则场景编号({}) 的触发器({})]", message, ruleScene.getId(), trigger); - return true; - } - return false; - }); - } - - // TODO @芋艿:【可优化】可以考虑增加下单测,边界太多了。 - /** - * 判断触发器的条件参数是否匹配 - * - * @param message 设备消息 - * @param parameter 触发器条件参数 - * @param ruleScene 规则场景(用于日志,无其它作用) - * @param trigger 触发器(用于日志,无其它作用) - * @return 是否匹配 - */ - @SuppressWarnings({"unchecked", "DataFlowIssue"}) - private boolean isTriggerConditionParameterMatched(IotDeviceMessage message, IotRuleSceneDO.TriggerConditionParameter parameter, - IotRuleSceneDO ruleScene, IotRuleSceneDO.TriggerConfig trigger) { - // 1.1 校验操作符是否合法 - IotRuleSceneTriggerConditionParameterOperatorEnum operator = - IotRuleSceneTriggerConditionParameterOperatorEnum.operatorOf(parameter.getOperator()); - if (operator == null) { - log.error("[isTriggerConditionParameterMatched][规则场景编号({}) 的触发器({}) 存在错误的操作符({})]", - ruleScene.getId(), trigger, parameter.getOperator()); - return false; - } - // 1.2 校验消息是否包含对应的值 - String messageValue = MapUtil.getStr((Map) message.getData(), parameter.getIdentifier()); - if (messageValue == null) { - return false; - } - - // 2.1 构建 Spring 表达式的变量 - Map springExpressionVariables = new HashMap<>(); - try { - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_SOURCE, messageValue); - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE, parameter.getValue()); - List parameterValues = StrUtil.splitTrim(parameter.getValue(), CharPool.COMMA); - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE_List, parameterValues); - // 特殊:解决数字的比较。因为 Spring 是基于它的 compareTo 方法,对数字的比较存在问题! - if (ObjectUtils.equalsAny(operator, IotRuleSceneTriggerConditionParameterOperatorEnum.BETWEEN, - IotRuleSceneTriggerConditionParameterOperatorEnum.NOT_BETWEEN, - IotRuleSceneTriggerConditionParameterOperatorEnum.GREATER_THAN, - IotRuleSceneTriggerConditionParameterOperatorEnum.GREATER_THAN_OR_EQUALS, - IotRuleSceneTriggerConditionParameterOperatorEnum.LESS_THAN, - IotRuleSceneTriggerConditionParameterOperatorEnum.LESS_THAN_OR_EQUALS) - && NumberUtil.isNumber(messageValue) - && NumberUtils.isAllNumber(parameterValues)) { - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_SOURCE, - NumberUtil.parseDouble(messageValue)); - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE, - NumberUtil.parseDouble(parameter.getValue())); - springExpressionVariables.put(IotRuleSceneTriggerConditionParameterOperatorEnum.SPRING_EXPRESSION_VALUE_List, - convertList(parameterValues, NumberUtil::parseDouble)); - } - // 2.2 计算 Spring 表达式 - return (Boolean) SpringExpressionUtils.parseExpression(operator.getSpringExpression(), springExpressionVariables); - } catch (Exception e) { - log.error("[isTriggerConditionParameterMatched][消息({}) 规则场景编号({}) 的触发器({}) 的匹配表达式({}/{}) 计算异常]", - message, ruleScene.getId(), trigger, operator, springExpressionVariables, e); - return false; - } - } - - /** - * 执行规则场景的动作 - * - * @param message 设备消息 - * @param ruleScenes 规则场景列表 - */ - private void executeRuleSceneAction(IotDeviceMessage message, List ruleScenes) { - // 1. 遍历规则场景 - ruleScenes.forEach(ruleScene -> { - // 2. 遍历规则场景的动作 - ruleScene.getActions().forEach(actionConfig -> { - // 3.1 获取对应的动作 Action 数组 - List actions = filterList(ruleSceneActions, - action -> action.getType().getType().equals(actionConfig.getType())); - if (CollUtil.isEmpty(actions)) { - return; - } - // 3.2 执行动作 - actions.forEach(action -> { - try { - action.execute(message, actionConfig); - log.info("[executeRuleSceneAction][消息({}) 规则场景编号({}) 的执行动作({}) 成功]", - message, ruleScene.getId(), actionConfig); - } catch (Exception e) { - log.error("[executeRuleSceneAction][消息({}) 规则场景编号({}) 的执行动作({}) 执行异常]", - message, ruleScene.getId(), actionConfig, e); - } - }); - }); - }); - } - - @Override - @SneakyThrows - public void test() { - // TODO @芋艿:测试思路代码,记得删除!!! - // 1. Job 类:IotRuleSceneJob DONE - // 2. 参数:id DONE - // 3. jobHandlerName:IotRuleSceneJob + id DONE - - // 新增:addJob - // 修改:不存在 addJob、存在 updateJob - // 有 + 禁用:1)存在、停止;2)不存在:不处理;TODO 测试:直接暂停,是否可以???(结论:可以)pauseJob - // 有 + 开启:1)存在,更新;2)不存在,新增;结论:使用 save(addOrUpdateJob) - // 无 + 禁用、开启:1)存在,删除;TODO 测试:直接删除???(结论:可以)deleteJob - - // - if (false) { - Long id = 1L; - Map jobDataMap = IotRuleSceneJob.buildJobDataMap(id); - schedulerManager.addOrUpdateJob(IotRuleSceneJob.class, - IotRuleSceneJob.buildJobName(id), - "0/10 * * * * ?", - jobDataMap); - } - if (false) { - Long id = 1L; - schedulerManager.pauseJob(IotRuleSceneJob.buildJobName(id)); - } - if (true) { - Long id = 1L; - schedulerManager.deleteJob(IotRuleSceneJob.buildJobName(id)); - } - } - - public static void main2(String[] args) throws SchedulerException { -// System.out.println(QuartzJobBean.class); - Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); - scheduler.start(); - - String jobHandlerName = "123"; - // 暂停 Trigger 对象 - scheduler.pauseTrigger(new TriggerKey(jobHandlerName)); - // 取消并删除 Job 调度 - scheduler.unscheduleJob(new TriggerKey(jobHandlerName)); - scheduler.deleteJob(new JobKey(jobHandlerName)); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneAction.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneAction.java deleted file mode 100644 index c7b921c..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneAction.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule.action; - -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; - -import javax.annotation.Nullable; - -/** - * IoT 规则场景的场景执行器接口 - * - * @author 芋道源码 - */ -public interface IotRuleSceneAction { - - // TODO @芋艿:groovy 或者 javascript 实现数据的转换;可以考虑基于 hutool 的 ScriptUtil 做 - /** - * 执行场景 - * - * @param message 消息,允许空 - * 1. 空的情况:定时触发 - * 2. 非空的情况:设备触发 - * @param config 配置 - */ - void execute(@Nullable IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) throws Exception; - - /** - * 获得类型 - * - * @return 类型 - */ - IotRuleSceneActionTypeEnum getType(); - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneAlertAction.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneAlertAction.java deleted file mode 100644 index eadc173..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneAlertAction.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule.action; - -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import org.springframework.stereotype.Component; - -import javax.annotation.Nullable; - -/** - * IoT 告警的 {@link IotRuleSceneAction} 实现类 - * - * @author 芋道源码 - */ -@Component -public class IotRuleSceneAlertAction implements IotRuleSceneAction { - - @Override - public void execute(@Nullable IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) { - // TODO @芋艿:待实现 - } - - @Override - public IotRuleSceneActionTypeEnum getType() { - return IotRuleSceneActionTypeEnum.ALERT; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneDataBridgeAction.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneDataBridgeAction.java deleted file mode 100644 index b38e181..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneDataBridgeAction.java +++ /dev/null @@ -1,60 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule.action; - -import cn.hutool.core.lang.Assert; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import cn.iocoder.yudao.module.iot.service.rule.IotDataBridgeService; -import cn.iocoder.yudao.module.iot.service.rule.action.databridge.IotDataBridgeExecute; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - * IoT 数据桥梁的 {@link IotRuleSceneAction} 实现类 - * - * @author 芋道源码 - */ -@Component -@Slf4j -public class IotRuleSceneDataBridgeAction implements IotRuleSceneAction { - - @Resource - private IotDataBridgeService dataBridgeService; - @Resource - private List> dataBridgeExecutes; - - @Override - public void execute(IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) throws Exception { - // 1.1 如果消息为空,直接返回 - if (message == null) { - return; - } - // 1.2 获得数据桥梁 - Assert.notNull(config.getDataBridgeId(), "数据桥梁编号不能为空"); - IotDataBridgeDO dataBridge = dataBridgeService.getDataBridge(config.getDataBridgeId()); - if (dataBridge == null || dataBridge.getConfig() == null) { - log.error("[execute][message({}) config({}) 对应的数据桥梁不存在]", message, config); - return; - } - if (CommonStatusEnum.isDisable(dataBridge.getStatus())) { - log.info("[execute][message({}) config({}) 对应的数据桥梁({}) 状态为禁用]", message, config, dataBridge); - return; - } - - // 2. 执行数据桥接操作 - for (IotDataBridgeExecute execute : dataBridgeExecutes) { - execute.execute(message, dataBridge); - } - } - - @Override - public IotRuleSceneActionTypeEnum getType() { - return IotRuleSceneActionTypeEnum.DATA_BRIDGE; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneDeviceControlAction.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneDeviceControlAction.java deleted file mode 100644 index d8fd76b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/IotRuleSceneDeviceControlAction.java +++ /dev/null @@ -1,56 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule.action; - -import cn.hutool.core.lang.Assert; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.control.IotDeviceDownstreamReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotRuleSceneDO; -import cn.iocoder.yudao.module.iot.enums.rule.IotRuleSceneActionTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; -import cn.iocoder.yudao.module.iot.service.device.control.IotDeviceDownstreamService; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -/** - * IoT 设备控制的 {@link IotRuleSceneAction} 实现类 - * - * @author 芋道源码 - */ -@Component -@Slf4j -public class IotRuleSceneDeviceControlAction implements IotRuleSceneAction { - - @Resource - private IotDeviceDownstreamService deviceDownstreamService; - @Resource - private IotDeviceService deviceService; - - @Override - public void execute(IotDeviceMessage message, IotRuleSceneDO.ActionConfig config) { - IotRuleSceneDO.ActionDeviceControl control = config.getDeviceControl(); - Assert.notNull(control, "设备控制配置不能为空"); - // 遍历每个设备,下发消息 - control.getDeviceNames().forEach(deviceName -> { - IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceNameFromCache(control.getProductKey(), deviceName); - if (device == null) { - log.error("[execute][message({}) config({}) 对应的设备不存在]", message, config); - return; - } - try { - IotDeviceMessage downstreamMessage = deviceDownstreamService.downstreamDevice(new IotDeviceDownstreamReqVO() - .setId(device.getId()).setType(control.getType()).setIdentifier(control.getIdentifier()) - .setData(control.getData())); - log.info("[execute][message({}) config({}) 下发消息({})成功]", message, config, downstreamMessage); - } catch (Exception e) { - log.error("[execute][message({}) config({}) 下发消息失败]", message, config, e); - } - }); - } - - @Override - public IotRuleSceneActionTypeEnum getType() { - return IotRuleSceneActionTypeEnum.DEVICE_CONTROL; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/AbstractCacheableDataBridgeExecute.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/AbstractCacheableDataBridgeExecute.java deleted file mode 100644 index e7f84dd..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/AbstractCacheableDataBridgeExecute.java +++ /dev/null @@ -1,114 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule.action.databridge; - -import cn.hutool.core.util.ObjUtil; -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.common.cache.RemovalListener; -import lombok.extern.slf4j.Slf4j; - -import java.time.Duration; - -// TODO @芋艿:数据库 -// TODO @芋艿:mqtt -// TODO @芋艿:tcp -// TODO @芋艿:websocket - -/** - * 带缓存功能的数据桥梁执行器抽象类 - * - * 该类提供了一个通用的缓存机制,用于管理各类数据桥接的生产者(Producer)实例。 - * - * 主要特点: - * - 基于Guava Cache实现高效的生产者实例缓存管理 - * - 自动处理生产者的生命周期(创建、获取、关闭) - * - 支持30分钟未访问自动过期清理机制 - * - 异常处理与日志记录,便于问题排查 - * - * 子类需要实现: - * - initProducer(Config) - 初始化特定类型的生产者实例 - * - closeProducer(Producer) - 关闭生产者实例并释放资源 - * - * @param 配置信息类型,用于初始化生产者 - * @param 生产者类型,负责将数据发送到目标系统 - * @author HUIHUI - */ -@Slf4j -public abstract class AbstractCacheableDataBridgeExecute implements IotDataBridgeExecute { - - /** - * Producer 缓存 - */ - private final LoadingCache PRODUCER_CACHE = CacheBuilder.newBuilder() - .expireAfterAccess(Duration.ofMinutes(30)) // 30 分钟未访问就提前过期 - .removalListener((RemovalListener) notification -> { - Producer producer = notification.getValue(); - if (producer == null) { - return; - } - - try { - closeProducer(producer); - log.info("[PRODUCER_CACHE][配置({}) 对应的 producer 已关闭]", notification.getKey()); - } catch (Exception e) { - log.error("[PRODUCER_CACHE][配置({}) 对应的 producer 关闭失败]", notification.getKey(), e); - } - }) - .build(new CacheLoader() { - - @Override - public Producer load(Config config) throws Exception { - try { - Producer producer = initProducer(config); - log.info("[PRODUCER_CACHE][配置({}) 对应的 producer 已创建并启动]", config); - return producer; - } catch (Exception e) { - log.error("[PRODUCER_CACHE][配置({}) 对应的 producer 创建启动失败]", config, e); - throw e; // 抛出异常,触发缓存加载失败机制 - } - } - - }); - - /** - * 获取生产者 - * - * @param config 配置信息 - * @return 生产者对象 - */ - protected Producer getProducer(Config config) throws Exception { - return PRODUCER_CACHE.get(config); - } - - /** - * 初始化生产者 - * - * @param config 配置信息 - * @return 生产者对象 - * @throws Exception 如果初始化失败 - */ - protected abstract Producer initProducer(Config config) throws Exception; - - /** - * 关闭生产者 - * - * @param producer 生产者对象 - */ - protected abstract void closeProducer(Producer producer) throws Exception; - - @Override - @SuppressWarnings({"unchecked"}) - public void execute(IotDeviceMessage message, IotDataBridgeDO dataBridge) { - if (ObjUtil.notEqual(message.getType(), getType())) { - return; - } - try { - execute0(message, (Config) dataBridge.getConfig()); - } catch (Exception e) { - log.error("[execute][桥梁配置 config({}) 对应的 message({}) 发送异常]", dataBridge.getConfig(), message, e); - } - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotDataBridgeExecute.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotDataBridgeExecute.java deleted file mode 100644 index ce3d0f1..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotDataBridgeExecute.java +++ /dev/null @@ -1,46 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule.action.databridge; - -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; - - -/** - * IoT 数据桥梁的执行器 execute 接口 - * - * @author HUIHUI - */ -public interface IotDataBridgeExecute { - - /** - * 获取数据桥梁类型 - * - * @return 数据桥梁类型 - */ - Integer getType(); - - /** - * 执行数据桥梁操作 - * - * @param message 设备消息 - * @param dataBridge 数据桥梁 - */ - @SuppressWarnings({"unchecked"}) - default void execute(IotDeviceMessage message, IotDataBridgeDO dataBridge) throws Exception { - // 1.1 校验数据桥梁类型 - if (!getType().equals(dataBridge.getType())) { - return; - } - - // 1.2 执行对应的数据桥梁发送消息 - execute0(message, (Config) dataBridge.getConfig()); - } - - /** - * 【真正】执行数据桥梁操作 - * - * @param message 设备消息 - * @param config 桥梁配置 - */ - void execute0(IotDeviceMessage message, Config config) throws Exception; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotHttpDataBridgeExecute.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotHttpDataBridgeExecute.java deleted file mode 100644 index 22b72e0..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotHttpDataBridgeExecute.java +++ /dev/null @@ -1,89 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule.action.databridge; - -import cn.hutool.core.collection.CollUtil; -import cn.iocoder.yudao.framework.common.util.http.HttpUtils; -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeHttpConfig; -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.*; -import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriComponentsBuilder; - -import java.util.HashMap; -import java.util.Map; - -import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; - -/** - * Http 的 {@link IotDataBridgeExecute} 实现类 - * - * @author HUIHUI - */ -@Component -@Slf4j -public class IotHttpDataBridgeExecute implements IotDataBridgeExecute { - - @Resource - private RestTemplate restTemplate; - - @Override - public Integer getType() { - return IotDataBridgeTypeEnum.HTTP.getType(); - } - - @Override - @SuppressWarnings({"unchecked", "deprecation"}) - public void execute0(IotDeviceMessage message, IotDataBridgeHttpConfig config) { - String url = null; - HttpMethod method = HttpMethod.valueOf(config.getMethod().toUpperCase()); - HttpEntity requestEntity = null; - ResponseEntity responseEntity = null; - try { - // 1.1 构建 Header - HttpHeaders headers = new HttpHeaders(); - if (CollUtil.isNotEmpty(config.getHeaders())) { - config.getHeaders().putAll(config.getHeaders()); - } - headers.add(HEADER_TENANT_ID, message.getTenantId().toString()); - // 1.2 构建 URL - UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(config.getUrl()); - if (CollUtil.isNotEmpty(config.getQuery())) { - config.getQuery().forEach(uriBuilder::queryParam); - } - // 1.3 构建请求体 - if (method == HttpMethod.GET) { - uriBuilder.queryParam("message", HttpUtils.encodeUtf8(JsonUtils.toJsonString(message))); - url = uriBuilder.build().toUriString(); - requestEntity = new HttpEntity<>(headers); - } else { - url = uriBuilder.build().toUriString(); - Map requestBody = JsonUtils.parseObject(config.getBody(), Map.class); - if (requestBody == null) { - requestBody = new HashMap<>(); - } - requestBody.put("message", message); - headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE); - requestEntity = new HttpEntity<>(JsonUtils.toJsonString(requestBody), headers); - } - - // 2.1 发送请求 - responseEntity = restTemplate.exchange(url, method, requestEntity, String.class); - // 2.2 记录日志 - if (responseEntity.getStatusCode().is2xxSuccessful()) { - log.info("[executeHttp][message({}) config({}) url({}) method({}) requestEntity({}) 请求成功({})]", - message, config, url, method, requestEntity, responseEntity); - } else { - log.error("[executeHttp][message({}) config({}) url({}) method({}) requestEntity({}) 请求失败({})]", - message, config, url, method, requestEntity, responseEntity); - } - } catch (Exception e) { - log.error("[executeHttp][message({}) config({}) url({}) method({}) requestEntity({}) 请求异常({})]", - message, config, url, method, requestEntity, responseEntity, e); - } - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotKafkaMQDataBridgeExecute.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotKafkaMQDataBridgeExecute.java deleted file mode 100644 index 5674c7d..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotKafkaMQDataBridgeExecute.java +++ /dev/null @@ -1,78 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule.action.databridge; - -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeKafkaMQConfig; -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import lombok.extern.slf4j.Slf4j; -import org.apache.kafka.clients.producer.ProducerConfig; -import org.apache.kafka.common.serialization.StringSerializer; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.kafka.core.DefaultKafkaProducerFactory; -import org.springframework.kafka.core.KafkaTemplate; -import org.springframework.stereotype.Component; - -import java.time.Duration; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -/** - * Kafka 的 {@link IotDataBridgeExecute} 实现类 - * - * @author HUIHUI - */ -@ConditionalOnClass(name = "org.springframework.kafka.core.KafkaTemplate") -@Component -@Slf4j -public class IotKafkaMQDataBridgeExecute extends - AbstractCacheableDataBridgeExecute> { - - private static final Duration SEND_TIMEOUT = Duration.ofMillis(10000); // 10 秒超时时间 - - @Override - public Integer getType() { - return IotDataBridgeTypeEnum.KAFKA.getType(); - } - - @Override - public void execute0(IotDeviceMessage message, IotDataBridgeKafkaMQConfig config) throws Exception { - // 1. 获取或创建 KafkaTemplate - KafkaTemplate kafkaTemplate = getProducer(config); - - // 2. 发送消息并等待结果 - kafkaTemplate.send(config.getTopic(), message.toString()) - .get(SEND_TIMEOUT.getSeconds(), TimeUnit.SECONDS); // 添加超时等待 - log.info("[execute0][message({}) 发送成功]", message); - } - - @Override - protected KafkaTemplate initProducer(IotDataBridgeKafkaMQConfig config) { - // 1.1 构建生产者配置 - Map props = new HashMap<>(); - props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, config.getBootstrapServers()); - props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); - props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class); - // 1.2 如果配置了认证信息 - if (config.getUsername() != null && config.getPassword() != null) { - props.put("security.protocol", "SASL_PLAINTEXT"); - props.put("sasl.mechanism", "PLAIN"); - props.put("sasl.jaas.config", - "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"" - + config.getUsername() + "\" password=\"" + config.getPassword() + "\";"); - } - // 1.3 如果启用 SSL - if (Boolean.TRUE.equals(config.getSsl())) { - props.put("security.protocol", "SSL"); - } - - // 2. 创建 KafkaTemplate - DefaultKafkaProducerFactory producerFactory = new DefaultKafkaProducerFactory<>(props); - return new KafkaTemplate<>(producerFactory); - } - - @Override - protected void closeProducer(KafkaTemplate producer) { - producer.destroy(); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRabbitMQDataBridgeExecute.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRabbitMQDataBridgeExecute.java deleted file mode 100644 index efe08b1..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRabbitMQDataBridgeExecute.java +++ /dev/null @@ -1,77 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule.action.databridge; - -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeRabbitMQConfig; -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import com.rabbitmq.client.Channel; -import com.rabbitmq.client.Connection; -import com.rabbitmq.client.ConnectionFactory; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.stereotype.Component; - -import java.nio.charset.StandardCharsets; - -/** - * RabbitMQ 的 {@link IotDataBridgeExecute} 实现类 - * - * @author HUIHUI - */ -@ConditionalOnClass(name = "com.rabbitmq.client.Channel") -@Component -@Slf4j -public class IotRabbitMQDataBridgeExecute extends - AbstractCacheableDataBridgeExecute { - - - @Override - public Integer getType() { - return IotDataBridgeTypeEnum.RABBITMQ.getType(); - } - - @Override - public void execute0(IotDeviceMessage message, IotDataBridgeRabbitMQConfig config) throws Exception { - // 1. 获取或创建 Channel - Channel channel = getProducer(config); - - // 2.1 声明交换机、队列和绑定关系 - channel.exchangeDeclare(config.getExchange(), "direct", true); - channel.queueDeclare(config.getQueue(), true, false, false, null); - channel.queueBind(config.getQueue(), config.getExchange(), config.getRoutingKey()); - - // 2.2 发送消息 - channel.basicPublish(config.getExchange(), config.getRoutingKey(), null, - message.toString().getBytes(StandardCharsets.UTF_8)); - log.info("[executeRabbitMQ][message({}) config({}) 发送成功]", message, config); - } - - @Override - @SuppressWarnings("resource") - protected Channel initProducer(IotDataBridgeRabbitMQConfig config) throws Exception { - // 1. 创建连接工厂 - ConnectionFactory factory = new ConnectionFactory(); - factory.setHost(config.getHost()); - factory.setPort(config.getPort()); - factory.setVirtualHost(config.getVirtualHost()); - factory.setUsername(config.getUsername()); - factory.setPassword(config.getPassword()); - - // 2. 创建连接 - Connection connection = factory.newConnection(); - - // 3. 创建信道 - return connection.createChannel(); - } - - @Override - protected void closeProducer(Channel channel) throws Exception { - if (channel.isOpen()) { - channel.close(); - } - Connection connection = channel.getConnection(); - if (connection.isOpen()) { - connection.close(); - } - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRedisStreamMQDataBridgeExecute.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRedisStreamMQDataBridgeExecute.java deleted file mode 100644 index 2aac766..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRedisStreamMQDataBridgeExecute.java +++ /dev/null @@ -1,96 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule.action.databridge; - -import cn.hutool.core.util.ReflectUtil; -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeRedisStreamMQConfig; -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import lombok.extern.slf4j.Slf4j; -import org.redisson.Redisson; -import org.redisson.api.RedissonClient; -import org.redisson.config.Config; -import org.redisson.config.SingleServerConfig; -import org.redisson.spring.data.connection.RedissonConnectionFactory; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.connection.stream.ObjectRecord; -import org.springframework.data.redis.connection.stream.StreamRecords; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.serializer.RedisSerializer; -import org.springframework.stereotype.Component; - -/** - * Redis Stream MQ 的 {@link IotDataBridgeExecute} 实现类 - * - * @author HUIHUI - */ -@Component -@Slf4j -public class IotRedisStreamMQDataBridgeExecute extends - AbstractCacheableDataBridgeExecute> { - - @Override - public Integer getType() { - return IotDataBridgeTypeEnum.REDIS_STREAM.getType(); - } - - @Override - public void execute0(IotDeviceMessage message, IotDataBridgeRedisStreamMQConfig config) throws Exception { - // 1. 获取 RedisTemplate - RedisTemplate redisTemplate = getProducer(config); - - // 2. 创建并发送 Stream 记录 - ObjectRecord record = StreamRecords.newRecord() - .ofObject(message).withStreamKey(config.getTopic()); - String recordId = String.valueOf(redisTemplate.opsForStream().add(record)); - log.info("[executeRedisStream][消息发送成功] messageId: {}, config: {}", recordId, config); - } - - @Override - protected RedisTemplate initProducer(IotDataBridgeRedisStreamMQConfig config) { - // 1.1 创建 Redisson 配置 - Config redissonConfig = new Config(); - SingleServerConfig serverConfig = redissonConfig.useSingleServer() - .setAddress("redis://" + config.getHost() + ":" + config.getPort()) - .setDatabase(config.getDatabase()); - // 1.2 设置密码(如果有) - if (StrUtil.isNotBlank(config.getPassword())) { - serverConfig.setPassword(config.getPassword()); - } - - // TODO @huihui:看看能不能简化一些。按道理说,不用这么多的哈。 - // 2.1 创建 RedissonClient - RedissonClient redisson = Redisson.create(redissonConfig); - // 2.2 创建并配置 RedisTemplate - RedisTemplate template = new RedisTemplate<>(); - // 设置 RedisConnection 工厂。😈 它就是实现多种 Java Redis 客户端接入的秘密工厂。感兴趣的胖友,可以自己去撸下。 - template.setConnectionFactory(new RedissonConnectionFactory(redisson)); - // 使用 String 序列化方式,序列化 KEY 。 - template.setKeySerializer(RedisSerializer.string()); - template.setHashKeySerializer(RedisSerializer.string()); - // 使用 JSON 序列化方式(库是 Jackson ),序列化 VALUE 。 - template.setValueSerializer(buildRedisSerializer()); - template.setHashValueSerializer(buildRedisSerializer()); - template.afterPropertiesSet();// 初始化 - return template; - } - - @Override - protected void closeProducer(RedisTemplate producer) throws Exception { - RedisConnectionFactory factory = producer.getConnectionFactory(); - if (factory != null) { - ((RedissonConnectionFactory) factory).destroy(); - } - } - - // TODO @huihui:看看能不能简化一些。按道理说,不用这么多的哈。 - public static RedisSerializer buildRedisSerializer() { - RedisSerializer json = RedisSerializer.json(); - // 解决 LocalDateTime 的序列化 - ObjectMapper objectMapper = (ObjectMapper) ReflectUtil.getFieldValue(json, "mapper"); - objectMapper.registerModules(new JavaTimeModule()); - return json; - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRocketMQDataBridgeExecute.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRocketMQDataBridgeExecute.java deleted file mode 100644 index d3ac772..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRocketMQDataBridgeExecute.java +++ /dev/null @@ -1,65 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule.action.databridge; - -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeRocketMQConfig; -import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import lombok.extern.slf4j.Slf4j; -import org.apache.rocketmq.client.producer.DefaultMQProducer; -import org.apache.rocketmq.client.producer.SendResult; -import org.apache.rocketmq.client.producer.SendStatus; -import org.apache.rocketmq.common.message.Message; -import org.apache.rocketmq.remoting.common.RemotingHelper; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.stereotype.Component; - -/** - * RocketMQ 的 {@link IotDataBridgeExecute} 实现类 - * - * @author HUIHUI - */ -@ConditionalOnClass(name = "org.apache.rocketmq.client.producer.DefaultMQProducer") -@Component -@Slf4j -public class IotRocketMQDataBridgeExecute extends - AbstractCacheableDataBridgeExecute { - - @Override - public Integer getType() { - return IotDataBridgeTypeEnum.ROCKETMQ.getType(); - } - - @Override - public void execute0(IotDeviceMessage message, IotDataBridgeRocketMQConfig config) throws Exception { - // 1. 获取或创建 Producer - DefaultMQProducer producer = getProducer(config); - - // 2.1 创建消息对象,指定Topic、Tag和消息体 - Message msg = new Message( - config.getTopic(), - config.getTags(), - message.toString().getBytes(RemotingHelper.DEFAULT_CHARSET) - ); - // 2.2 发送同步消息并处理结果 - SendResult sendResult = producer.send(msg); - // 2.3 处理发送结果 - if (SendStatus.SEND_OK.equals(sendResult.getSendStatus())) { - log.info("[executeRocketMQ][message({}) config({}) 发送成功,结果({})]", message, config, sendResult); - } else { - log.error("[executeRocketMQ][message({}) config({}) 发送失败,结果({})]", message, config, sendResult); - } - } - - @Override - protected DefaultMQProducer initProducer(IotDataBridgeRocketMQConfig config) throws Exception { - DefaultMQProducer producer = new DefaultMQProducer(config.getGroup()); - producer.setNamesrvAddr(config.getNameServer()); - producer.start(); - return producer; - } - - @Override - protected void closeProducer(DefaultMQProducer producer) { - producer.shutdown(); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelService.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelService.java deleted file mode 100644 index 8834772..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelService.java +++ /dev/null @@ -1,93 +0,0 @@ -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.IotThingModelListReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; -import jakarta.validation.Valid; - -import java.time.LocalDateTime; -import java.util.List; - -/** - * IoT 产品物模型 Service 接口 - * - * @author 芋道源码 - */ -public interface IotThingModelService { - - /** - * 创建产品物模型 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createThingModel(@Valid IotThingModelSaveReqVO createReqVO); - - /** - * 更新产品物模型 - * - * @param updateReqVO 更新信息 - */ - void updateThingModel(@Valid IotThingModelSaveReqVO updateReqVO); - - /** - * 删除产品物模型 - * - * @param id 编号 - */ - void deleteThingModel(Long id); - - /** - * 获得产品物模型 - * - * @param id 编号 - * @return 产品物模型 - */ - IotThingModelDO getThingModel(Long id); - - /** - * 获得产品物模型列表 - * - * @param productId 产品编号 - * @return 产品物模型列表 - */ - List getThingModelListByProductId(Long productId); - - /** - * 【缓存】获得产品物模型列表 - * - * 注意:该方法会忽略租户信息,所以调用时,需要确认会不会有跨租户访问的风险!!! - * - * @param productKey 产品标识 - * @return 产品物模型列表 - */ - List getThingModelListByProductKeyFromCache(String productKey); - - /** - * 获得产品物模型分页 - * - * @param pageReqVO 分页查询 - * @return 产品物模型分页 - */ - PageResult getProductThingModelPage(IotThingModelPageReqVO pageReqVO); - - /** - * 获得产品物模型列表 - * - * @param reqVO 列表查询 - * @return 产品物模型列表 - */ - List getThingModelList(IotThingModelListReqVO reqVO); - - // TODO @super:用不到,删除下哈。 - /** - * 获得物模型数量 - * - * @param createTime 创建时间,如果为空,则统计所有物模型数量 - * @return 物模型数量 - */ - Long getThingModelCount(LocalDateTime createTime); - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelServiceImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelServiceImpl.java deleted file mode 100644 index 9487ff2..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelServiceImpl.java +++ /dev/null @@ -1,373 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.thingmodel; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.spring.SpringUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelParam; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelListReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; -import cn.iocoder.yudao.module.iot.convert.thingmodel.IotThingModelConvert; -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; -import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; -import cn.iocoder.yudao.module.iot.dal.mysql.thingmodel.IotThingModelMapper; -import cn.iocoder.yudao.module.iot.dal.redis.RedisKeyConstants; -import cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum; -import cn.iocoder.yudao.module.iot.enums.thingmodel.*; -import cn.iocoder.yudao.module.iot.service.product.IotProductService; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; - -import java.time.LocalDateTime; -import java.util.*; - -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*; - -/** - * IoT 产品物模型 Service 实现类 - * - * @author 芋道源码 - */ -@Service -@Validated -@Slf4j -public class IotThingModelServiceImpl implements IotThingModelService { - - @Resource - private IotThingModelMapper thingModelMapper; - - @Resource - private IotProductService productService; - - @Override - @Transactional(rollbackFor = Exception.class) - public Long createThingModel(IotThingModelSaveReqVO createReqVO) { - // 1.1 校验功能标识符在同一产品下是否唯一 - validateIdentifierUnique(null, createReqVO.getProductId(), createReqVO.getIdentifier()); - // 1.2 功能名称在同一产品下是否唯一 - validateNameUnique(createReqVO.getProductId(), createReqVO.getName()); - // 1.3 校验产品状态,发布状态下,不允许新增功能 - validateProductStatus(createReqVO.getProductId()); - - // 2. 插入数据库 - IotThingModelDO thingModel = IotThingModelConvert.INSTANCE.convert(createReqVO); - thingModelMapper.insert(thingModel); - - // 3. 如果创建的是属性,需要更新默认的事件和服务 - if (Objects.equals(createReqVO.getType(), IotThingModelTypeEnum.PROPERTY.getType())) { - createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey()); - } - - // 4. 删除缓存 - deleteThingModelListCache(createReqVO.getProductKey()); - return thingModel.getId(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateThingModel(IotThingModelSaveReqVO updateReqVO) { - // 1.1 校验功能是否存在 - validateProductThingModelMapperExists(updateReqVO.getId()); - // 1.2 校验功能标识符是否唯一 - validateIdentifierUnique(updateReqVO.getId(), updateReqVO.getProductId(), updateReqVO.getIdentifier()); - // 1.3 校验产品状态,发布状态下,不允许操作功能 - validateProductStatus(updateReqVO.getProductId()); - - // 2. 更新数据库 - IotThingModelDO thingModel = IotThingModelConvert.INSTANCE.convert(updateReqVO); - thingModelMapper.updateById(thingModel); - - // 3. 如果更新的是属性,需要更新默认的事件和服务 - if (Objects.equals(updateReqVO.getType(), IotThingModelTypeEnum.PROPERTY.getType())) { - createDefaultEventsAndServices(updateReqVO.getProductId(), updateReqVO.getProductKey()); - } - - // 4. 删除缓存 - deleteThingModelListCache(updateReqVO.getProductKey()); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteThingModel(Long id) { - // 1.1 校验功能是否存在 - IotThingModelDO thingModel = thingModelMapper.selectById(id); - if (thingModel == null) { - throw exception(THING_MODEL_NOT_EXISTS); - } - // 1.2 校验产品状态,发布状态下,不允许操作功能 - validateProductStatus(thingModel.getProductId()); - - // 2. 删除功能 - thingModelMapper.deleteById(id); - - // 3. 如果删除的是属性,需要更新默认的事件和服务 - if (Objects.equals(thingModel.getType(), IotThingModelTypeEnum.PROPERTY.getType())) { - createDefaultEventsAndServices(thingModel.getProductId(), thingModel.getProductKey()); - } - - // 4. 删除缓存 - deleteThingModelListCache(thingModel.getProductKey()); - } - - @Override - public IotThingModelDO getThingModel(Long id) { - return thingModelMapper.selectById(id); - } - - @Override - public List getThingModelListByProductId(Long productId) { - return thingModelMapper.selectListByProductId(productId); - } - - @Override - @Cacheable(value = RedisKeyConstants.THING_MODEL_LIST, key = "#productKey") - @TenantIgnore // 忽略租户信息,跨租户 productKey 是唯一的 - public List getThingModelListByProductKeyFromCache(String productKey) { - return thingModelMapper.selectListByProductKey(productKey); - } - - @Override - public PageResult getProductThingModelPage(IotThingModelPageReqVO pageReqVO) { - return thingModelMapper.selectPage(pageReqVO); - } - - @Override - public List getThingModelList(IotThingModelListReqVO reqVO) { - return thingModelMapper.selectList(reqVO); - } - - /** - * 校验功能是否存在 - * - * @param id 功能编号 - */ - private void validateProductThingModelMapperExists(Long id) { - if (thingModelMapper.selectById(id) == null) { - throw exception(THING_MODEL_NOT_EXISTS); - } - } - - private void validateIdentifierUnique(Long id, Long productId, String identifier) { - // 1.0 情况一:创建时校验 - if (id == null) { - // 1.1 系统保留字段,不能用于标识符定义 - if (StrUtil.equalsAny(identifier, "set", "get", "post", "property", "event", "time", "value")) { - throw exception(THING_MODEL_IDENTIFIER_INVALID); - } - - // 1.2 校验唯一 - IotThingModelDO thingModel = thingModelMapper.selectByProductIdAndIdentifier(productId, identifier); - if (thingModel != null) { - throw exception(THING_MODEL_IDENTIFIER_EXISTS); - } - return; - } - - // 2.0 情况二:更新时校验 - IotThingModelDO thingModel = thingModelMapper.selectByProductIdAndIdentifier(productId, identifier); - if (thingModel != null && ObjectUtil.notEqual(thingModel.getId(), id)) { - throw exception(THING_MODEL_IDENTIFIER_EXISTS); - } - } - - private void validateProductStatus(Long createReqVO) { - IotProductDO product = productService.validateProductExists(createReqVO); - if (Objects.equals(product.getStatus(), IotProductStatusEnum.PUBLISHED.getStatus())) { - throw exception(PRODUCT_STATUS_NOT_ALLOW_THING_MODEL); - } - } - - private void validateNameUnique(Long productId, String name) { - IotThingModelDO thingModel = thingModelMapper.selectByProductIdAndName(productId, name); - if (thingModel != null) { - throw exception(THING_MODEL_NAME_EXISTS); - } - } - - /** - * 创建默认的事件和服务 - * - * @param productId 产品编号 - * @param productKey 产品标识 - */ - public void createDefaultEventsAndServices(Long productId, String productKey) { - // 1. 获取当前属性列表 - List properties = thingModelMapper - .selectListByProductIdAndType(productId, IotThingModelTypeEnum.PROPERTY.getType()); - - // 2. 生成新的事件和服务列表 - List newThingModels = new ArrayList<>(); - // 2.1 生成属性上报事件 - ThingModelEvent propertyPostEvent = generatePropertyPostEvent(properties); - if (propertyPostEvent != null) { - newThingModels.add(buildEventThingModel(productId, productKey, propertyPostEvent, "属性上报事件")); - } - // 2.2 生成属性设置服务 - ThingModelService propertySetService = generatePropertySetService(properties); - if (propertySetService != null) { - newThingModels.add(buildServiceThingModel(productId, productKey, propertySetService, "属性设置服务")); - } - // 2.3 生成属性获取服务 - ThingModelService propertyGetService = generatePropertyGetService(properties); - if (propertyGetService != null) { - newThingModels.add(buildServiceThingModel(productId, productKey, propertyGetService, "属性获取服务")); - } - - // 3.1 获取数据库中的默认的旧事件和服务列表 - List oldThingModels = thingModelMapper.selectListByProductIdAndIdentifiersAndTypes( - productId, - Arrays.asList("post", "set", "get"), - Arrays.asList(IotThingModelTypeEnum.EVENT.getType(), IotThingModelTypeEnum.SERVICE.getType()) - ); - // 3.2 创建默认的事件和服务 - createDefaultEventsAndServices(oldThingModels, newThingModels); - } - - /** - * 创建默认的事件和服务 - */ - private void createDefaultEventsAndServices(List oldThingModels, - List newThingModels) { - // 使用 diffList 方法比较新旧列表 - List> diffResult = diffList(oldThingModels, newThingModels, - (oldVal, newVal) -> { - // 继续使用 identifier 和 type 进行比较:这样可以准确地匹配对应的功能对象。 - boolean same = Objects.equals(oldVal.getIdentifier(), newVal.getIdentifier()) - && Objects.equals(oldVal.getType(), newVal.getType()); - if (same) { - newVal.setId(oldVal.getId()); // 设置编号 - } - return same; - }); - // 批量添加、修改、删除 - if (CollUtil.isNotEmpty(diffResult.get(0))) { - thingModelMapper.insertBatch(diffResult.get(0)); - } - if (CollUtil.isNotEmpty(diffResult.get(1))) { - thingModelMapper.updateBatch(diffResult.get(1)); - } - if (CollUtil.isNotEmpty(diffResult.get(2))) { - thingModelMapper.deleteByIds(convertSet(diffResult.get(2), IotThingModelDO::getId)); - } - } - - /** - * 构建事件功能对象 - */ - private IotThingModelDO buildEventThingModel(Long productId, String productKey, - ThingModelEvent event, String description) { - return new IotThingModelDO().setProductId(productId).setProductKey(productKey) - .setIdentifier(event.getIdentifier()).setName(event.getName()).setDescription(description) - .setType(IotThingModelTypeEnum.EVENT.getType()).setEvent(event); - } - - /** - * 构建服务功能对象 - */ - private IotThingModelDO buildServiceThingModel(Long productId, String productKey, - ThingModelService service, String description) { - return new IotThingModelDO().setProductId(productId).setProductKey(productKey) - .setIdentifier(service.getIdentifier()).setName(service.getName()).setDescription(description) - .setType(IotThingModelTypeEnum.SERVICE.getType()).setService(service); - } - - // TODO @haohao:是不是不用生成这个?目前属性上报,是个批量接口 - - /** - * 生成属性上报事件 - */ - private ThingModelEvent generatePropertyPostEvent(List thingModels) { - // 没有属性则不生成 - if (CollUtil.isEmpty(thingModels)) { - return null; - } - - // 生成属性上报事件 - return new ThingModelEvent().setIdentifier("post").setName("属性上报").setMethod("thing.event.property.post") - .setType(IotThingModelServiceEventTypeEnum.INFO.getType()) - .setOutputParams(buildInputOutputParam(thingModels, IotThingModelParamDirectionEnum.OUTPUT)); - } - - // TODO @haohao:是不是不用生成这个?目前属性上报,是个批量接口 - - /** - * 生成属性设置服务 - */ - private ThingModelService generatePropertySetService(List thingModels) { - // 1.1 过滤出所有可写属性 - thingModels = filterList(thingModels, thingModel -> - IotThingModelAccessModeEnum.READ_WRITE.getMode().equals(thingModel.getProperty().getAccessMode())); - // 1.2 没有可写属性则不生成 - if (CollUtil.isEmpty(thingModels)) { - return null; - } - - // 2. 生成属性设置服务 - return new ThingModelService().setIdentifier("set").setName("属性设置").setMethod("thing.service.property.set") - .setCallType(IotThingModelServiceCallTypeEnum.ASYNC.getType()) - .setInputParams(buildInputOutputParam(thingModels, IotThingModelParamDirectionEnum.INPUT)) - .setOutputParams(Collections.emptyList()); // 属性设置服务一般不需要输出参数 - } - - /** - * 生成属性获取服务 - */ - private ThingModelService generatePropertyGetService(List thingModels) { - // 1.1 没有属性则不生成 - if (CollUtil.isEmpty(thingModels)) { - return null; - } - - // 1.2 生成属性获取服务 - return new ThingModelService().setIdentifier("get").setName("属性获取").setMethod("thing.service.property.get") - .setCallType(IotThingModelServiceCallTypeEnum.ASYNC.getType()) - .setInputParams(buildInputOutputParam(thingModels, IotThingModelParamDirectionEnum.INPUT)) - .setOutputParams(buildInputOutputParam(thingModels, IotThingModelParamDirectionEnum.OUTPUT)); - } - - /** - * 构建输入/输出参数列表 - * - * @param thingModels 属性列表 - * @return 输入/输出参数列表 - */ - private List buildInputOutputParam(List thingModels, - IotThingModelParamDirectionEnum direction) { - return convertList(thingModels, thingModel -> - BeanUtils.toBean(thingModel.getProperty(), ThingModelParam.class).setParaOrder(0) // TODO @puhui999: 先搞个默认值看看怎么个事 - .setDirection(direction.getDirection())); - } - - private void deleteThingModelListCache(String productKey) { - // 保证 Spring AOP 触发 - getSelf().deleteThingModelListCache0(productKey); - } - - @CacheEvict(value = RedisKeyConstants.THING_MODEL_LIST, key = "#productKey") - public void deleteThingModelListCache0(String productKey) { - } - - private IotThingModelServiceImpl getSelf() { - return SpringUtil.getBean(getClass()); - } - - // TODO @super:用不到,删除下; - @Override - public Long getThingModelCount(LocalDateTime createTime) { - return thingModelMapper.selectCountByCreateTime(createTime); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/util/MqttSignUtils.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/util/MqttSignUtils.java deleted file mode 100644 index 01a6dba..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/util/MqttSignUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -package cn.iocoder.yudao.module.iot.util; - -import cn.hutool.crypto.digest.HMac; -import cn.hutool.crypto.digest.HmacAlgorithm; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.nio.charset.StandardCharsets; - -/** - * MQTT 签名工具类 - * - * 提供静态方法来计算 MQTT 连接参数 - */ -public class MqttSignUtils { - - /** - * 计算 MQTT 连接参数 - * - * @param productKey 产品密钥 - * @param deviceName 设备名称 - * @param deviceSecret 设备密钥 - * @return 包含 clientId, username, password 的结果对象 - */ - public static MqttSignResult calculate(String productKey, String deviceName, String deviceSecret) { - return calculate(productKey, deviceName, deviceSecret, productKey + "." + deviceName); - } - - /** - * 计算 MQTT 连接参数 - * - * @param productKey 产品密钥 - * @param deviceName 设备名称 - * @param deviceSecret 设备密钥 - * @param clientId 客户端 ID - * @return 包含 clientId, username, password 的结果对象 - */ - public static MqttSignResult calculate(String productKey, String deviceName, String deviceSecret, String clientId) { - String username = deviceName + "&" + productKey; - // 构建签名内容 - StringBuilder signContentBuilder = new StringBuilder() - .append("clientId").append(clientId) - .append("deviceName").append(deviceName) - .append("deviceSecret").append(deviceSecret) - .append("productKey").append(productKey); - - // 使用 HMac 计算签名 - byte[] key = deviceSecret.getBytes(StandardCharsets.UTF_8); - String signContent = signContentBuilder.toString(); - HMac mac = new HMac(HmacAlgorithm.HmacSHA256, key); - String password = mac.digestHex(signContent); - - return new MqttSignResult(clientId, username, password); - } - - /** - * MQTT 签名结果类 - */ - @Getter - @AllArgsConstructor - public static class MqttSignResult { - - private final String clientId; - private final String username; - private final String password; - - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogMapper.xml b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogMapper.xml deleted file mode 100644 index 932a9a8..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogMapper.xml +++ /dev/null @@ -1,122 +0,0 @@ - - - - - - CREATE STABLE IF NOT EXISTS device_log ( - ts TIMESTAMP, - id NCHAR(50), - product_key NCHAR(50), - device_name NCHAR(50), - type NCHAR(50), - identifier NCHAR(255), - content NCHAR(1024), - code INT, - report_time TIMESTAMP - ) TAGS ( - device_key NCHAR(50) - ) - - - - - - INSERT INTO device_log_${deviceKey} (ts, id, product_key, device_name, type, identifier, content, code, report_time) - USING device_log - TAGS ('${deviceKey}') - VALUES ( - NOW, - #{id}, - #{productKey}, - #{deviceName}, - #{type}, - #{identifier}, - #{content}, - #{code}, - #{reportTime} - ) - - - - - - - - - - - \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceMapper.xml b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceMapper.xml deleted file mode 100644 index 8404729..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceMapper.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml deleted file mode 100644 index bdc40e8..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - CREATE STABLE product_property_${productKey} ( - ts TIMESTAMP, - report_time TIMESTAMP, - - ${field.field} ${field.type} - - (${field.length}) - - - ) - TAGS ( - device_key NCHAR(50) - ) - - - - ALTER STABLE product_property_${productKey} - ADD COLUMN ${field.field} ${field.type} - - (${field.length}) - - - - - ALTER STABLE product_property_${productKey} - MODIFY COLUMN ${field.field} ${field.type} - - (${field.length}) - - - - - ALTER STABLE product_property_${productKey} - DROP COLUMN ${field.field} - - - - INSERT INTO device_property_${device.deviceKey} - USING product_property_${device.productKey} - TAGS ('${device.deviceKey}') - (ts, report_time, - - ${@cn.hutool.core.util.StrUtil@toUnderlineCase(key)} - - ) - VALUES - (NOW, #{reportTime}, - - #{value} - - ) - - - - - - - \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotDataBridgeExecuteTest.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotDataBridgeExecuteTest.java deleted file mode 100644 index 38586af..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotDataBridgeExecuteTest.java +++ /dev/null @@ -1,154 +0,0 @@ -package cn.iocoder.yudao.module.iot.service.rule.action.databridge; - -import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; -import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.*; -import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO; -import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; - -import java.time.LocalDateTime; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; - -/** - * {@link IotDataBridgeExecute} 实现类的测试 - * - * @author HUIHUI - */ -@Disabled // 默认禁用,需要手动启用测试 -@Slf4j -public class IotDataBridgeExecuteTest extends BaseMockitoUnitTest { - - private IotDeviceMessage message; - - @Mock - private RestTemplate restTemplate; - - @InjectMocks - private IotHttpDataBridgeExecute httpDataBridgeExecute; - - @BeforeEach - public void setUp() { - // 创建共享的测试消息 - message = IotDeviceMessage.builder().requestId("TEST-001").reportTime(LocalDateTime.now()).tenantId(1L) - .productKey("testProduct").deviceName("testDevice").deviceKey("testDeviceKey") - .type("property").identifier("temperature").data("{\"value\": 60}") - .build(); - - // 配置 RestTemplate mock 返回成功响应 - // TODO @puhui999:这个应该放到 testHttpDataBridge 里 - when(restTemplate.exchange(anyString(), any(HttpMethod.class), any(), any(Class.class))) - .thenReturn(new ResponseEntity<>("Success", HttpStatus.OK)); - } - - @Test - public void testKafkaMQDataBridge() { - // 1. 创建执行器实例 - IotKafkaMQDataBridgeExecute action = new IotKafkaMQDataBridgeExecute(); - - // 2. 创建配置 - // TODO @puhui999:可以改成链式哈。 - IotDataBridgeKafkaMQConfig config = new IotDataBridgeKafkaMQConfig(); - config.setBootstrapServers("127.0.0.1:9092"); - config.setTopic("test-topic"); - config.setSsl(false); - config.setUsername(null); - config.setPassword(null); - - // 3. 执行两次测试,验证缓存 - log.info("[testKafkaMQDataBridge][第一次执行,应该会创建新的 producer]"); - action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config)); - - log.info("[testKafkaMQDataBridge][第二次执行,应该会复用缓存的 producer]"); - action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config)); - } - - @Test - public void testRabbitMQDataBridge() { - // 1. 创建执行器实例 - IotRabbitMQDataBridgeExecute action = new IotRabbitMQDataBridgeExecute(); - - // 2. 创建配置 - IotDataBridgeRabbitMQConfig config = new IotDataBridgeRabbitMQConfig(); - config.setHost("localhost"); - config.setPort(5672); - config.setVirtualHost("/"); - config.setUsername("admin"); - config.setPassword("123456"); - config.setExchange("test-exchange"); - config.setRoutingKey("test-key"); - config.setQueue("test-queue"); - - // 3. 执行两次测试,验证缓存 - log.info("[testRabbitMQDataBridge][第一次执行,应该会创建新的 producer]"); - action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config)); - - log.info("[testRabbitMQDataBridge][第二次执行,应该会复用缓存的 producer]"); - action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config)); - } - - @Test - public void testRedisStreamMQDataBridge() { - // 1. 创建执行器实例 - IotRedisStreamMQDataBridgeExecute action = new IotRedisStreamMQDataBridgeExecute(); - - // 2. 创建配置 - IotDataBridgeRedisStreamMQConfig config = new IotDataBridgeRedisStreamMQConfig(); - config.setHost("127.0.0.1"); - config.setPort(6379); - config.setDatabase(0); - config.setPassword("123456"); - config.setTopic("test-stream"); - - // 3. 执行两次测试,验证缓存 - log.info("[testRedisStreamMQDataBridge][第一次执行,应该会创建新的 producer]"); - action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config)); - - log.info("[testRedisStreamMQDataBridge][第二次执行,应该会复用缓存的 producer]"); - action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config)); - } - - @Test - public void testRocketMQDataBridge() { - // 1. 创建执行器实例 - IotRocketMQDataBridgeExecute action = new IotRocketMQDataBridgeExecute(); - - // 2. 创建配置 - IotDataBridgeRocketMQConfig config = new IotDataBridgeRocketMQConfig(); - config.setNameServer("127.0.0.1:9876"); - config.setGroup("test-group"); - config.setTopic("test-topic"); - config.setTags("test-tag"); - - // 3. 执行两次测试,验证缓存 - log.info("[testRocketMQDataBridge][第一次执行,应该会创建新的 producer]"); - action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config)); - - log.info("[testRocketMQDataBridge][第二次执行,应该会复用缓存的 producer]"); - action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config)); - } - - @Test - public void testHttpDataBridge() throws Exception { - // 创建配置 - IotDataBridgeHttpConfig config = new IotDataBridgeHttpConfig(); - config.setUrl("https://doc.iocoder.cn/"); - config.setMethod(HttpMethod.GET.name()); - - // 执行测试 - log.info("[testHttpDataBridge][执行HTTP数据桥接测试]"); - httpDataBridgeExecute.execute(message, new IotDataBridgeDO().setType(httpDataBridgeExecute.getType()).setConfig(config)); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/pom.xml b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/pom.xml deleted file mode 100644 index d332925..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/pom.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - yudao-module-iot - cn.iocoder.boot - ${revision} - - - yudao-module-iot-plugin-common - yudao-module-iot-plugin-http - yudao-module-iot-plugin-mqtt - yudao-module-iot-plugin-emqx - - - 4.0.0 - - yudao-module-iot-plugins - pom - - ${project.artifactId} - - 物联网 插件 模块 - - - \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/pom.xml b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/pom.xml deleted file mode 100644 index 1e5a69b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - yudao-module-iot-plugins - cn.iocoder.boot - ${revision} - - 4.0.0 - yudao-module-iot-plugin-common - jar - - ${project.artifactId} - - - 物联网 插件 模块 - 通用功能 - - - - - org.springframework.boot - spring-boot-starter - - - - cn.iocoder.boot - yudao-module-iot-api - ${revision} - - - - - org.springframework - spring-web - - - - - io.vertx - vertx-web - - - - - org.springframework.boot - spring-boot-starter-validation - true - - - - diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/config/IotPluginCommonAutoConfiguration.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/config/IotPluginCommonAutoConfiguration.java deleted file mode 100644 index ba7d56f..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/config/IotPluginCommonAutoConfiguration.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.common.config; - -import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi; -import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler; -import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamServer; -import cn.iocoder.yudao.module.iot.plugin.common.heartbeat.IotPluginInstanceHeartbeatJob; -import cn.iocoder.yudao.module.iot.plugin.common.upstream.IotDeviceUpstreamClient; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.web.client.RestTemplate; - -/** - * IoT 插件的通用自动配置类 - * - * @author haohao - */ -@AutoConfiguration -@EnableConfigurationProperties(IotPluginCommonProperties.class) -@EnableScheduling // 开启定时任务,因为 IotPluginInstanceHeartbeatJob 是一个定时任务 -public class IotPluginCommonAutoConfiguration { - - @Bean - public RestTemplate restTemplate(IotPluginCommonProperties properties) { - return new RestTemplateBuilder() - .connectTimeout(properties.getUpstreamConnectTimeout()) - .readTimeout(properties.getUpstreamReadTimeout()) - .build(); - } - - @Bean - public IotDeviceUpstreamApi deviceUpstreamApi(IotPluginCommonProperties properties, - RestTemplate restTemplate) { - return new IotDeviceUpstreamClient(properties, restTemplate); - } - - @Bean(initMethod = "start", destroyMethod = "stop") - public IotDeviceDownstreamServer deviceDownstreamServer(IotPluginCommonProperties properties, - IotDeviceDownstreamHandler deviceDownstreamHandler) { - return new IotDeviceDownstreamServer(properties, deviceDownstreamHandler); - } - - @Bean(initMethod = "init", destroyMethod = "stop") - public IotPluginInstanceHeartbeatJob pluginInstanceHeartbeatJob(IotDeviceUpstreamApi deviceDataApi, - IotDeviceDownstreamServer deviceDownstreamServer, - IotPluginCommonProperties commonProperties) { - return new IotPluginInstanceHeartbeatJob(deviceDataApi, deviceDownstreamServer, commonProperties); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/config/IotPluginCommonProperties.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/config/IotPluginCommonProperties.java deleted file mode 100644 index 03d42c2..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/config/IotPluginCommonProperties.java +++ /dev/null @@ -1,59 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.common.config; - -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.validation.annotation.Validated; - -import java.time.Duration; - -/** - * IoT 插件的通用配置类 - * - * @author haohao - */ -@ConfigurationProperties(prefix = "yudao.iot.plugin.common") -@Validated -@Data -public class IotPluginCommonProperties { - - /** - * 上行连接超时的默认值 - */ - public static final Duration UPSTREAM_CONNECT_TIMEOUT_DEFAULT = Duration.ofSeconds(30); - /** - * 上行读取超时的默认值 - */ - public static final Duration UPSTREAM_READ_TIMEOUT_DEFAULT = Duration.ofSeconds(30); - - /** - * 下行端口 - 随机 - */ - public static final Integer DOWNSTREAM_PORT_RANDOM = 0; - - /** - * 上行 URL - */ - @NotEmpty(message = "上行 URL 不能为空") - private String upstreamUrl; - /** - * 上行连接超时 - */ - private Duration upstreamConnectTimeout = UPSTREAM_CONNECT_TIMEOUT_DEFAULT; - /** - * 上行读取超时 - */ - private Duration upstreamReadTimeout = UPSTREAM_READ_TIMEOUT_DEFAULT; - - /** - * 下行端口 - */ - private Integer downstreamPort = DOWNSTREAM_PORT_RANDOM; - - /** - * 插件包标识符 - */ - @NotEmpty(message = "插件包标识符不能为空") - private String pluginKey; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/IotDeviceDownstreamHandler.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/IotDeviceDownstreamHandler.java deleted file mode 100644 index 38aba3d..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/IotDeviceDownstreamHandler.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.common.downstream; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.*; - -/** - * IoT 设备下行处理器 - * - * 目的:每个 plugin 需要实现,用于处理 server 下行的指令(请求),从而实现从 server => plugin => device 的下行流程 - * - * @author 芋道源码 - */ -public interface IotDeviceDownstreamHandler { - - /** - * 调用设备服务 - * - * @param invokeReqDTO 调用设备服务的请求 - * @return 是否成功 - */ - CommonResult invokeDeviceService(IotDeviceServiceInvokeReqDTO invokeReqDTO); - - /** - * 获取设备属性 - * - * @param getReqDTO 获取设备属性的请求 - * @return 是否成功 - */ - CommonResult getDeviceProperty(IotDevicePropertyGetReqDTO getReqDTO); - - /** - * 设置设备属性 - * - * @param setReqDTO 设置设备属性的请求 - * @return 是否成功 - */ - CommonResult setDeviceProperty(IotDevicePropertySetReqDTO setReqDTO); - - /** - * 设置设备配置 - * - * @param setReqDTO 设置设备配置的请求 - * @return 是否成功 - */ - CommonResult setDeviceConfig(IotDeviceConfigSetReqDTO setReqDTO); - - /** - * 升级设备 OTA - * - * @param upgradeReqDTO 升级设备 OTA 的请求 - * @return 是否成功 - */ - CommonResult upgradeDeviceOta(IotDeviceOtaUpgradeReqDTO upgradeReqDTO); - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/IotDeviceDownstreamServer.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/IotDeviceDownstreamServer.java deleted file mode 100644 index 719fdb5..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/IotDeviceDownstreamServer.java +++ /dev/null @@ -1,94 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.common.downstream; - -import cn.iocoder.yudao.module.iot.plugin.common.config.IotPluginCommonProperties; -import cn.iocoder.yudao.module.iot.plugin.common.downstream.router.*; -import io.vertx.core.Vertx; -import io.vertx.core.http.HttpServer; -import io.vertx.ext.web.Router; -import io.vertx.ext.web.handler.BodyHandler; -import lombok.extern.slf4j.Slf4j; - -/** - * IoT 设备下行服务端,接收来自 server 服务器的请求,转发给 device 设备 - * - * @author 芋道源码 - */ -@Slf4j -public class IotDeviceDownstreamServer { - - private final Vertx vertx; - private final HttpServer server; - private final IotPluginCommonProperties properties; - - public IotDeviceDownstreamServer(IotPluginCommonProperties properties, - IotDeviceDownstreamHandler deviceDownstreamHandler) { - this.properties = properties; - // 创建 Vertx 实例 - this.vertx = Vertx.vertx(); - // 创建 Router 实例 - Router router = Router.router(vertx); - router.route().handler(BodyHandler.create()); // 处理 Body - router.post(IotDeviceServiceInvokeVertxHandler.PATH) - .handler(new IotDeviceServiceInvokeVertxHandler(deviceDownstreamHandler)); - router.post(IotDevicePropertySetVertxHandler.PATH) - .handler(new IotDevicePropertySetVertxHandler(deviceDownstreamHandler)); - router.post(IotDevicePropertyGetVertxHandler.PATH) - .handler(new IotDevicePropertyGetVertxHandler(deviceDownstreamHandler)); - router.post(IotDeviceConfigSetVertxHandler.PATH) - .handler(new IotDeviceConfigSetVertxHandler(deviceDownstreamHandler)); - router.post(IotDeviceOtaUpgradeVertxHandler.PATH) - .handler(new IotDeviceOtaUpgradeVertxHandler(deviceDownstreamHandler)); - // 创建 HttpServer 实例 - this.server = vertx.createHttpServer().requestHandler(router); - } - - /** - * 启动 HTTP 服务器 - */ - public void start() { - log.info("[start][开始启动]"); - server.listen(properties.getDownstreamPort()) - .toCompletionStage() - .toCompletableFuture() - .join(); - log.info("[start][启动完成,端口({})]", this.server.actualPort()); - } - - /** - * 停止所有 - */ - public void stop() { - log.info("[stop][开始关闭]"); - try { - // 关闭 HTTP 服务器 - if (server != null) { - server.close() - .toCompletionStage() - .toCompletableFuture() - .join(); - } - - // 关闭 Vertx 实例 - if (vertx != null) { - vertx.close() - .toCompletionStage() - .toCompletableFuture() - .join(); - } - log.info("[stop][关闭完成]"); - } catch (Exception e) { - log.error("[stop][关闭异常]", e); - throw new RuntimeException(e); - } - } - - /** - * 获得端口 - * - * @return 端口 - */ - public int getPort() { - return this.server.actualPort(); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDeviceConfigSetVertxHandler.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDeviceConfigSetVertxHandler.java deleted file mode 100644 index 1693f12..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDeviceConfigSetVertxHandler.java +++ /dev/null @@ -1,73 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.common.downstream.router; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDeviceConfigSetReqDTO; -import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler; -import cn.iocoder.yudao.module.iot.plugin.common.pojo.IotStandardResponse; -import cn.iocoder.yudao.module.iot.plugin.common.util.IotPluginCommonUtils; -import io.vertx.core.Handler; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.RoutingContext; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR; - -/** - * IoT 设备配置设置 Vertx Handler - * - * 芋道源码 - */ -@Slf4j -@RequiredArgsConstructor -public class IotDeviceConfigSetVertxHandler implements Handler { - - // TODO @haohao:是不是可以把 PATH、Method 所有的,抽到一个枚举类里?因为 topic、path、method 相当于不同的几个表达? - public static final String PATH = "/sys/:productKey/:deviceName/thing/service/config/set"; - public static final String METHOD = "thing.service.config.set"; - - private final IotDeviceDownstreamHandler deviceDownstreamHandler; - - @Override - @SuppressWarnings("unchecked") - public void handle(RoutingContext routingContext) { - // 1. 解析参数 - IotDeviceConfigSetReqDTO reqDTO; - try { - String productKey = routingContext.pathParam("productKey"); - String deviceName = routingContext.pathParam("deviceName"); - JsonObject body = routingContext.body().asJsonObject(); - String requestId = body.getString("requestId"); - Map config = (Map) body.getMap().get("config"); - reqDTO = ((IotDeviceConfigSetReqDTO) new IotDeviceConfigSetReqDTO() - .setRequestId(requestId).setProductKey(productKey).setDeviceName(deviceName)) - .setConfig(config); - } catch (Exception e) { - log.error("[handle][路径参数({}) 解析参数失败]", routingContext.pathParams(), e); - IotStandardResponse errorResponse = IotStandardResponse.error( - null, METHOD, BAD_REQUEST.getCode(), BAD_REQUEST.getMsg()); - IotPluginCommonUtils.writeJsonResponse(routingContext, errorResponse); - return; - } - - // 2. 调用处理器 - try { - CommonResult result = deviceDownstreamHandler.setDeviceConfig(reqDTO); - - // 3. 响应结果 - IotStandardResponse response = result.isSuccess() ? - IotStandardResponse.success(reqDTO.getRequestId(), METHOD, result.getData()) - : IotStandardResponse.error(reqDTO.getRequestId(), METHOD, result.getCode(), result.getMsg()); - IotPluginCommonUtils.writeJsonResponse(routingContext, response); - } catch (Exception e) { - log.error("[handle][请求参数({}) 配置设置异常]", reqDTO, e); - IotStandardResponse errorResponse = IotStandardResponse.error( - reqDTO.getRequestId(), METHOD, INTERNAL_SERVER_ERROR.getCode(), INTERNAL_SERVER_ERROR.getMsg()); - IotPluginCommonUtils.writeJsonResponse(routingContext, errorResponse); - } - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDeviceOtaUpgradeVertxHandler.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDeviceOtaUpgradeVertxHandler.java deleted file mode 100644 index b417229..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDeviceOtaUpgradeVertxHandler.java +++ /dev/null @@ -1,78 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.common.downstream.router; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDeviceOtaUpgradeReqDTO; -import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler; -import cn.iocoder.yudao.module.iot.plugin.common.pojo.IotStandardResponse; -import cn.iocoder.yudao.module.iot.plugin.common.util.IotPluginCommonUtils; -import io.vertx.core.Handler; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.RoutingContext; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR; - -/** - * IoT 设备 OTA 升级 Vertx Handler - *

- * 芋道源码 - */ -@Slf4j -@RequiredArgsConstructor -public class IotDeviceOtaUpgradeVertxHandler implements Handler { - - public static final String PATH = "/ota/:productKey/:deviceName/upgrade"; - public static final String METHOD = "ota.device.upgrade"; - - private final IotDeviceDownstreamHandler deviceDownstreamHandler; - - @Override - public void handle(RoutingContext routingContext) { - // 1. 解析参数 - IotDeviceOtaUpgradeReqDTO reqDTO; - try { - String productKey = routingContext.pathParam("productKey"); - String deviceName = routingContext.pathParam("deviceName"); - JsonObject body = routingContext.body().asJsonObject(); - String requestId = body.getString("requestId"); - Long firmwareId = body.getLong("firmwareId"); - String version = body.getString("version"); - String signMethod = body.getString("signMethod"); - String fileSign = body.getString("fileSign"); - Long fileSize = body.getLong("fileSize"); - String fileUrl = body.getString("fileUrl"); - String information = body.getString("information"); - reqDTO = ((IotDeviceOtaUpgradeReqDTO) new IotDeviceOtaUpgradeReqDTO() - .setRequestId(requestId).setProductKey(productKey).setDeviceName(deviceName)) - .setFirmwareId(firmwareId).setVersion(version) - .setSignMethod(signMethod).setFileSign(fileSign).setFileSize(fileSize).setFileUrl(fileUrl) - .setInformation(information); - } catch (Exception e) { - log.error("[handle][路径参数({}) 解析参数失败]", routingContext.pathParams(), e); - IotStandardResponse errorResponse = IotStandardResponse.error( - null, METHOD, BAD_REQUEST.getCode(), BAD_REQUEST.getMsg()); - IotPluginCommonUtils.writeJsonResponse(routingContext, errorResponse); - return; - } - - // 2. 调用处理器 - try { - CommonResult result = deviceDownstreamHandler.upgradeDeviceOta(reqDTO); - - // 3. 响应结果 - // TODO @haohao:可以考虑 IotStandardResponse.of(requestId, method, CommonResult) - IotStandardResponse response = result.isSuccess() ? - IotStandardResponse.success(reqDTO.getRequestId(), METHOD, result.getData()) - :IotStandardResponse.error(reqDTO.getRequestId(), METHOD, result.getCode(), result.getMsg()); - IotPluginCommonUtils.writeJsonResponse(routingContext, response); - } catch (Exception e) { - log.error("[handle][请求参数({}) OTA 升级异常]", reqDTO, e); - // TODO @haohao:可以考虑 IotStandardResponse.of(requestId, method, ErrorCode) - IotStandardResponse errorResponse = IotStandardResponse.error( - reqDTO.getRequestId(), METHOD, INTERNAL_SERVER_ERROR.getCode(), INTERNAL_SERVER_ERROR.getMsg()); - IotPluginCommonUtils.writeJsonResponse(routingContext, errorResponse); - } - } -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDevicePropertyGetVertxHandler.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDevicePropertyGetVertxHandler.java deleted file mode 100644 index 3cb4bc9..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDevicePropertyGetVertxHandler.java +++ /dev/null @@ -1,75 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.common.downstream.router; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDevicePropertyGetReqDTO; -import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler; -import cn.iocoder.yudao.module.iot.plugin.common.pojo.IotStandardResponse; -import cn.iocoder.yudao.module.iot.plugin.common.util.IotPluginCommonUtils; -import io.vertx.core.Handler; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.RoutingContext; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.util.List; - -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR; - -/** - * IoT 设备服务获取 Vertx Handler - * - * 芋道源码 - */ -@Slf4j -@RequiredArgsConstructor -public class IotDevicePropertyGetVertxHandler implements Handler { - - public static final String PATH = "/sys/:productKey/:deviceName/thing/service/property/get"; - public static final String METHOD = "thing.service.property.get"; - - private final IotDeviceDownstreamHandler deviceDownstreamHandler; - - @Override - @SuppressWarnings("unchecked") - public void handle(RoutingContext routingContext) { - // 1. 解析参数 - IotDevicePropertyGetReqDTO reqDTO; - try { - String productKey = routingContext.pathParam("productKey"); - String deviceName = routingContext.pathParam("deviceName"); - JsonObject body = routingContext.body().asJsonObject(); - String requestId = body.getString("requestId"); - List identifiers = (List) body.getMap().get("identifiers"); - reqDTO = ((IotDevicePropertyGetReqDTO) new IotDevicePropertyGetReqDTO() - .setRequestId(requestId).setProductKey(productKey).setDeviceName(deviceName)) - .setIdentifiers(identifiers); - } catch (Exception e) { - log.error("[handle][路径参数({}) 解析参数失败]", routingContext.pathParams(), e); - IotStandardResponse errorResponse = IotStandardResponse.error( - null, METHOD, BAD_REQUEST.getCode(), BAD_REQUEST.getMsg()); - IotPluginCommonUtils.writeJsonResponse(routingContext, errorResponse); - return; - } - - // 2. 调用处理器 - try { - CommonResult result = deviceDownstreamHandler.getDeviceProperty(reqDTO); - - // 3. 响应结果 - IotStandardResponse response; - if (result.isSuccess()) { - response = IotStandardResponse.success(reqDTO.getRequestId(), METHOD, result.getData()); - } else { - response = IotStandardResponse.error(reqDTO.getRequestId(), METHOD, result.getCode(), result.getMsg()); - } - IotPluginCommonUtils.writeJsonResponse(routingContext, response); - } catch (Exception e) { - log.error("[handle][请求参数({}) 属性获取异常]", reqDTO, e); - IotStandardResponse errorResponse = IotStandardResponse.error( - reqDTO.getRequestId(), METHOD, INTERNAL_SERVER_ERROR.getCode(), INTERNAL_SERVER_ERROR.getMsg()); - IotPluginCommonUtils.writeJsonResponse(routingContext, errorResponse); - } - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDevicePropertySetVertxHandler.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDevicePropertySetVertxHandler.java deleted file mode 100644 index 251be1e..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDevicePropertySetVertxHandler.java +++ /dev/null @@ -1,75 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.common.downstream.router; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDevicePropertySetReqDTO; -import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler; -import cn.iocoder.yudao.module.iot.plugin.common.pojo.IotStandardResponse; -import cn.iocoder.yudao.module.iot.plugin.common.util.IotPluginCommonUtils; -import io.vertx.core.Handler; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.RoutingContext; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR; - -/** - * IoT 设置设备属性 Vertx Handler - * - * 芋道源码 - */ -@Slf4j -@RequiredArgsConstructor -public class IotDevicePropertySetVertxHandler implements Handler { - - public static final String PATH = "/sys/:productKey/:deviceName/thing/service/property/set"; - public static final String METHOD = "thing.service.property.set"; - - private final IotDeviceDownstreamHandler deviceDownstreamHandler; - - @Override - @SuppressWarnings("unchecked") - public void handle(RoutingContext routingContext) { - // 1. 解析参数 - IotDevicePropertySetReqDTO reqDTO; - try { - String productKey = routingContext.pathParam("productKey"); - String deviceName = routingContext.pathParam("deviceName"); - JsonObject body = routingContext.body().asJsonObject(); - String requestId = body.getString("requestId"); - Map properties = (Map) body.getMap().get("properties"); - reqDTO = ((IotDevicePropertySetReqDTO) new IotDevicePropertySetReqDTO() - .setRequestId(requestId).setProductKey(productKey).setDeviceName(deviceName)) - .setProperties(properties); - } catch (Exception e) { - log.error("[handle][路径参数({}) 解析参数失败]", routingContext.pathParams(), e); - IotStandardResponse errorResponse = IotStandardResponse.error( - null, METHOD, BAD_REQUEST.getCode(), BAD_REQUEST.getMsg()); - IotPluginCommonUtils.writeJsonResponse(routingContext, errorResponse); - return; - } - - // 2. 调用处理器 - try { - CommonResult result = deviceDownstreamHandler.setDeviceProperty(reqDTO); - - // 3. 响应结果 - IotStandardResponse response; - if (result.isSuccess()) { - response = IotStandardResponse.success(reqDTO.getRequestId(), METHOD, result.getData()); - } else { - response = IotStandardResponse.error(reqDTO.getRequestId(), METHOD, result.getCode(), result.getMsg()); - } - IotPluginCommonUtils.writeJsonResponse(routingContext, response); - } catch (Exception e) { - log.error("[handle][请求参数({}) 属性设置异常]", reqDTO, e); - IotStandardResponse errorResponse = IotStandardResponse.error( - reqDTO.getRequestId(), METHOD, INTERNAL_SERVER_ERROR.getCode(), INTERNAL_SERVER_ERROR.getMsg()); - IotPluginCommonUtils.writeJsonResponse(routingContext, errorResponse); - } - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDeviceServiceInvokeVertxHandler.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDeviceServiceInvokeVertxHandler.java deleted file mode 100644 index 534823f..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/downstream/router/IotDeviceServiceInvokeVertxHandler.java +++ /dev/null @@ -1,80 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.common.downstream.router; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDeviceServiceInvokeReqDTO; -import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler; -import cn.iocoder.yudao.module.iot.plugin.common.pojo.IotStandardResponse; -import cn.iocoder.yudao.module.iot.plugin.common.util.IotPluginCommonUtils; -import io.vertx.core.Handler; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.RoutingContext; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR; - -/** - * IoT 设备服务调用 Vertx Handler - * - * 芋道源码 - */ -@Slf4j -@RequiredArgsConstructor -public class IotDeviceServiceInvokeVertxHandler implements Handler { - - public static final String PATH = "/sys/:productKey/:deviceName/thing/service/:identifier"; - public static final String METHOD_PREFIX = "thing.service."; - public static final String METHOD_SUFFIX = ""; - - private final IotDeviceDownstreamHandler deviceDownstreamHandler; - - @Override - @SuppressWarnings("unchecked") - public void handle(RoutingContext routingContext) { - // 1. 解析参数 - IotDeviceServiceInvokeReqDTO reqDTO; - try { - String productKey = routingContext.pathParam("productKey"); - String deviceName = routingContext.pathParam("deviceName"); - String identifier = routingContext.pathParam("identifier"); - JsonObject body = routingContext.body().asJsonObject(); - String requestId = body.getString("requestId"); - Map params = (Map) body.getMap().get("params"); - reqDTO = ((IotDeviceServiceInvokeReqDTO) new IotDeviceServiceInvokeReqDTO() - .setRequestId(requestId).setProductKey(productKey).setDeviceName(deviceName)) - .setIdentifier(identifier).setParams(params); - } catch (Exception e) { - log.error("[handle][路径参数({}) 解析参数失败]", routingContext.pathParams(), e); - String method = METHOD_PREFIX + routingContext.pathParam("identifier") + METHOD_SUFFIX; - IotStandardResponse errorResponse = IotStandardResponse.error( - null, method, BAD_REQUEST.getCode(), BAD_REQUEST.getMsg()); - IotPluginCommonUtils.writeJsonResponse(routingContext, errorResponse); - return; - } - - // 2. 调用处理器 - try { - CommonResult result = deviceDownstreamHandler.invokeDeviceService(reqDTO); - - // 3. 响应结果 - String method = METHOD_PREFIX + reqDTO.getIdentifier() + METHOD_SUFFIX; - IotStandardResponse response; - if (result.isSuccess()) { - response = IotStandardResponse.success(reqDTO.getRequestId(), method, result.getData()); - } else { - response = IotStandardResponse.error(reqDTO.getRequestId(), method, result.getCode(), result.getMsg()); - } - IotPluginCommonUtils.writeJsonResponse(routingContext, response); - } catch (Exception e) { - log.error("[handle][请求参数({}) 服务调用异常]", reqDTO, e); - String method = METHOD_PREFIX + reqDTO.getIdentifier() + METHOD_SUFFIX; - IotStandardResponse errorResponse = IotStandardResponse.error( - reqDTO.getRequestId(), method, INTERNAL_SERVER_ERROR.getCode(), INTERNAL_SERVER_ERROR.getMsg()); - IotPluginCommonUtils.writeJsonResponse(routingContext, errorResponse); - } - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/heartbeat/IotPluginInstanceHeartbeatJob.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/heartbeat/IotPluginInstanceHeartbeatJob.java deleted file mode 100644 index f272468..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/heartbeat/IotPluginInstanceHeartbeatJob.java +++ /dev/null @@ -1,52 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.common.heartbeat; - -import cn.hutool.system.SystemUtil; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotPluginInstanceHeartbeatReqDTO; -import cn.iocoder.yudao.module.iot.plugin.common.config.IotPluginCommonProperties; -import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamServer; -import cn.iocoder.yudao.module.iot.plugin.common.util.IotPluginCommonUtils; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Scheduled; - -import java.util.concurrent.TimeUnit; - -/** - * IoT 插件实例心跳 Job - * - * 用于定时发送心跳给服务端 - */ -@RequiredArgsConstructor -@Slf4j -public class IotPluginInstanceHeartbeatJob { - - private final IotDeviceUpstreamApi deviceUpstreamApi; - private final IotDeviceDownstreamServer deviceDownstreamServer; - private final IotPluginCommonProperties commonProperties; - - public void init() { - CommonResult result = deviceUpstreamApi.heartbeatPluginInstance(buildPluginInstanceHeartbeatReqDTO(true)); - log.info("[init][上线结果:{})]", result); - } - - public void stop() { - CommonResult result = deviceUpstreamApi.heartbeatPluginInstance(buildPluginInstanceHeartbeatReqDTO(false)); - log.info("[stop][下线结果:{})]", result); - } - - @Scheduled(initialDelay = 3, fixedRate = 3, timeUnit = TimeUnit.MINUTES) // 3 分钟执行一次 - public void execute() { - CommonResult result = deviceUpstreamApi.heartbeatPluginInstance(buildPluginInstanceHeartbeatReqDTO(true)); - log.info("[execute][心跳结果:{})]", result); - } - - private IotPluginInstanceHeartbeatReqDTO buildPluginInstanceHeartbeatReqDTO(Boolean online) { - return new IotPluginInstanceHeartbeatReqDTO() - .setPluginKey(commonProperties.getPluginKey()).setProcessId(IotPluginCommonUtils.getProcessId()) - .setHostIp(SystemUtil.getHostInfo().getAddress()).setDownstreamPort(deviceDownstreamServer.getPort()) - .setOnline(online); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/package-info.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/package-info.java deleted file mode 100644 index 83b5bb5..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/package-info.java +++ /dev/null @@ -1,2 +0,0 @@ -// TODO @芋艿:注释 -package cn.iocoder.yudao.module.iot.plugin.common; \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/pojo/IotStandardResponse.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/pojo/IotStandardResponse.java deleted file mode 100644 index 131eb1b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/pojo/IotStandardResponse.java +++ /dev/null @@ -1,94 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.common.pojo; - -import lombok.Data; - -// TODO @芋艿:1)后续考虑,要不要叫 IoT 网关之类的 Response;2)包名 pojo -/** - * IoT 标准协议响应实体类 - *

- * 用于统一 MQTT 和 HTTP 的响应格式 - * - * @author haohao - */ -@Data -public class IotStandardResponse { - - /** - * 消息ID - */ - private String id; - - /** - * 状态码 - */ - private Integer code; - - /** - * 响应数据 - */ - private Object data; - - /** - * 响应消息 - */ - private String message; - - /** - * 方法名 - */ - private String method; - - /** - * 协议版本 - */ - private String version; - - /** - * 创建成功响应 - * - * @param id 消息ID - * @param method 方法名 - * @return 成功响应 - */ - public static IotStandardResponse success(String id, String method) { - return success(id, method, null); - } - - /** - * 创建成功响应 - * - * @param id 消息ID - * @param method 方法名 - * @param data 响应数据 - * @return 成功响应 - */ - public static IotStandardResponse success(String id, String method, Object data) { - return new IotStandardResponse() - .setId(id) - .setCode(200) - .setData(data) - .setMessage("success") - .setMethod(method) - .setVersion("1.0"); - } - - /** - * 创建错误响应 - * - * @param id 消息ID - * @param method 方法名 - * @param code 错误码 - * @param message 错误消息 - * @return 错误响应 - */ - public static IotStandardResponse error(String id, String method, Integer code, String message) { - return new IotStandardResponse() - .setId(id) - .setCode(code) - .setData(null) - .setMessage(message) - .setMethod(method) - .setVersion("1.0"); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/upstream/IotDeviceUpstreamClient.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/upstream/IotDeviceUpstreamClient.java deleted file mode 100644 index 1bf4d67..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/upstream/IotDeviceUpstreamClient.java +++ /dev/null @@ -1,91 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.common.upstream; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.*; -import cn.iocoder.yudao.module.iot.plugin.common.config.IotPluginCommonProperties; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.client.RestTemplate; - -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR; - -/** - * 设备数据 Upstream 上行客户端 - * - * 通过 HTTP 调用远程的 IotDeviceUpstreamApi 接口 - * - * @author haohao - */ -@RequiredArgsConstructor -@Slf4j -public class IotDeviceUpstreamClient implements IotDeviceUpstreamApi { - - public static final String URL_PREFIX = "/rpc-api/iot/device/upstream"; - - private final IotPluginCommonProperties properties; - - private final RestTemplate restTemplate; - - @Override - public CommonResult updateDeviceState(IotDeviceStateUpdateReqDTO updateReqDTO) { - String url = properties.getUpstreamUrl() + URL_PREFIX + "/update-state"; - return doPost(url, updateReqDTO); - } - - @Override - public CommonResult reportDeviceEvent(IotDeviceEventReportReqDTO reportReqDTO) { - String url = properties.getUpstreamUrl() + URL_PREFIX + "/report-event"; - return doPost(url, reportReqDTO); - } - - // TODO @芋艿:待实现 - @Override - public CommonResult registerDevice(IotDeviceRegisterReqDTO registerReqDTO) { - return null; - } - - // TODO @芋艿:待实现 - @Override - public CommonResult registerSubDevice(IotDeviceRegisterSubReqDTO registerReqDTO) { - return null; - } - - // TODO @芋艿:待实现 - @Override - public CommonResult addDeviceTopology(IotDeviceTopologyAddReqDTO addReqDTO) { - return null; - } - - @Override - public CommonResult authenticateEmqxConnection(IotDeviceEmqxAuthReqDTO authReqDTO) { - String url = properties.getUpstreamUrl() + URL_PREFIX + "/authenticate-emqx-connection"; - return doPost(url, authReqDTO); - } - - @Override - public CommonResult reportDeviceProperty(IotDevicePropertyReportReqDTO reportReqDTO) { - String url = properties.getUpstreamUrl() + URL_PREFIX + "/report-property"; - return doPost(url, reportReqDTO); - } - - @Override - public CommonResult heartbeatPluginInstance(IotPluginInstanceHeartbeatReqDTO heartbeatReqDTO) { - String url = properties.getUpstreamUrl() + URL_PREFIX + "/heartbeat-plugin-instance"; - return doPost(url, heartbeatReqDTO); - } - - @SuppressWarnings("unchecked") - private CommonResult doPost(String url, T requestBody) { - try { - CommonResult result = restTemplate.postForObject(url, requestBody, - (Class>) (Class) CommonResult.class); - log.info("[doPost][url({}) requestBody({}) result({})]", url, requestBody, result); - return result; - } catch (Exception e) { - log.error("[doPost][url({}) requestBody({}) 发生异常]", url, requestBody, e); - return CommonResult.error(INTERNAL_SERVER_ERROR); - } - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/util/IotPluginCommonUtils.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/util/IotPluginCommonUtils.java deleted file mode 100644 index 34c6c0f..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/util/IotPluginCommonUtils.java +++ /dev/null @@ -1,76 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.common.util; - -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.system.SystemUtil; -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import cn.iocoder.yudao.module.iot.plugin.common.pojo.IotStandardResponse; -import io.vertx.core.http.HttpHeaders; -import io.vertx.ext.web.RoutingContext; -import org.springframework.http.MediaType; - -/** - * IoT 插件的通用工具类 - * - * @author 芋道源码 - */ -public class IotPluginCommonUtils { - - /** - * 流程实例的进程编号 - */ - private static String processId; - - public static String getProcessId() { - if (StrUtil.isEmpty(processId)) { - initProcessId(); - } - return processId; - } - - private synchronized static void initProcessId() { - processId = String.format("%s@%d@%s", // IP@PID@${uuid} - SystemUtil.getHostInfo().getAddress(), SystemUtil.getCurrentPID(), IdUtil.fastSimpleUUID()); - } - - /** - * 将对象转换为JSON字符串后写入HTTP响应 - * - * @param routingContext 路由上下文 - * @param data 数据对象 - */ - @SuppressWarnings("deprecation") - public static void writeJsonResponse(RoutingContext routingContext, Object data) { - routingContext.response() - .setStatusCode(200) - .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE) - .end(JsonUtils.toJsonString(data)); - } - - /** - * 生成标准JSON格式的响应并写入HTTP响应(基于IotStandardResponse) - *

- * 推荐使用此方法,统一MQTT和HTTP的响应格式。使用方式: - * - *

-     * // 成功响应
-     * IotStandardResponse response = IotStandardResponse.success(requestId, method, data);
-     * IotPluginCommonUtils.writeJsonResponse(routingContext, response);
-     *
-     * // 错误响应
-     * IotStandardResponse errorResponse = IotStandardResponse.error(requestId, method, code, message);
-     * IotPluginCommonUtils.writeJsonResponse(routingContext, errorResponse);
-     * 
- * - * @param routingContext 路由上下文 - * @param response IotStandardResponse响应对象 - */ - @SuppressWarnings("deprecation") - public static void writeJsonResponse(RoutingContext routingContext, IotStandardResponse response) { - routingContext.response() - .setStatusCode(200) - .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE) - .end(JsonUtils.toJsonString(response)); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index eae9ad8..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -cn.iocoder.yudao.module.iot.plugin.common.config.IotPluginCommonAutoConfiguration \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/plugin.properties b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/plugin.properties deleted file mode 100644 index 565e81e..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/plugin.properties +++ /dev/null @@ -1,6 +0,0 @@ -plugin.id=yudao-module-iot-plugin-emqx -plugin.class=cn.iocoder.yudao.module.iot.plugin.emqx.config.IotEmqxPlugin -plugin.version=1.0.0 -plugin.provider=yudao -plugin.dependencies= -plugin.description=yudao-module-iot-plugin-emqx-1.0.0 diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/pom.xml b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/pom.xml deleted file mode 100644 index 8620eca..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/pom.xml +++ /dev/null @@ -1,169 +0,0 @@ - - - - yudao-module-iot-plugins - cn.iocoder.boot - ${revision} - - 4.0.0 - jar - - yudao-module-iot-plugin-emqx - 1.0.0 - - ${project.artifactId} - - - 物联网 插件模块 - emqx 插件 - - - - - emqx-plugin - cn.iocoder.yudao.module.iot.plugin.emqx.config.IotEmqxPlugin - ${project.version} - yudao - ${project.artifactId}-${project.version} - - - - - - - - org.apache.maven.plugins - maven-antrun-plugin - 1.6 - - - unzip jar file - package - - - - - - - run - - - - - - - maven-assembly-plugin - 2.3 - - - - src/main/assembly/assembly.xml - - - false - - - - make-assembly - package - - attached - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - - - ${plugin.id} - ${plugin.class} - ${plugin.version} - ${plugin.provider} - ${plugin.description} - ${plugin.dependencies} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring.boot.version} - - - - repackage - - - -standalone - - - - - - - - - - - cn.iocoder.boot - yudao-module-iot-plugin-common - ${revision} - - - - - org.springframework.boot - spring-boot-starter-web - - - - - io.vertx - vertx-web - - - io.vertx - vertx-mqtt - - - \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/assembly/assembly.xml b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/assembly/assembly.xml deleted file mode 100644 index daec9e4..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/assembly/assembly.xml +++ /dev/null @@ -1,31 +0,0 @@ - - plugin - - zip - - false - - - false - runtime - lib - - *:jar:* - - - - - - - target/plugin-classes - classes - - - diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/IotEmqxPluginApplication.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/IotEmqxPluginApplication.java deleted file mode 100644 index 1780384..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/IotEmqxPluginApplication.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.emqx; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.WebApplicationType; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * IoT Emqx 插件的独立运行入口 - */ -@Slf4j -@SpringBootApplication -public class IotEmqxPluginApplication { - - public static void main(String[] args) { - SpringApplication application = new SpringApplication(IotEmqxPluginApplication.class); - application.setWebApplicationType(WebApplicationType.NONE); - application.run(args); - log.info("[main][独立模式启动完成]"); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/config/IotEmqxPlugin.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/config/IotEmqxPlugin.java deleted file mode 100644 index b877d1b..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/config/IotEmqxPlugin.java +++ /dev/null @@ -1,64 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.emqx.config; - -import cn.hutool.extra.spring.SpringUtil; -import lombok.extern.slf4j.Slf4j; -import org.pf4j.PluginWrapper; -import org.pf4j.spring.SpringPlugin; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.Statement; - -/** - * EMQX 插件实现类 - * - * 基于 PF4J 插件框架,实现 EMQX 消息中间件的集成:负责插件的生命周期管理,包括启动、停止和应用上下文的创建 - * - * @author haohao - */ -@Slf4j -public class IotEmqxPlugin extends SpringPlugin { - - public IotEmqxPlugin(PluginWrapper wrapper) { - super(wrapper); - } - - @Override - public void start() { - log.info("[EmqxPlugin][EmqxPlugin 插件启动开始...]"); - try { - log.info("[EmqxPlugin][EmqxPlugin 插件启动成功...]"); - } catch (Exception e) { - log.error("[EmqxPlugin][EmqxPlugin 插件开启动异常...]", e); - } - } - - @Override - public void stop() { - log.info("[EmqxPlugin][EmqxPlugin 插件停止开始...]"); - try { - log.info("[EmqxPlugin][EmqxPlugin 插件停止成功...]"); - } catch (Exception e) { - log.error("[EmqxPlugin][EmqxPlugin 插件停止异常...]", e); - } - } - - @Override - protected ApplicationContext createApplicationContext() { - // 创建插件自己的 ApplicationContext - AnnotationConfigApplicationContext pluginContext = new AnnotationConfigApplicationContext(); - // 设置父容器为主应用的 ApplicationContext (确保主应用中提供的类可用) - pluginContext.setParent(SpringUtil.getApplicationContext()); - // 继续使用插件自己的 ClassLoader 以加载插件内部的类 - pluginContext.setClassLoader(getWrapper().getPluginClassLoader()); - // 扫描当前插件的自动配置包 - // TODO @芋艿:是不是要配置下包 - pluginContext.scan("cn.iocoder.yudao.module.iot.plugin.emqx.config"); - pluginContext.refresh(); - return pluginContext; - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/config/IotPluginEmqxAutoConfiguration.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/config/IotPluginEmqxAutoConfiguration.java deleted file mode 100644 index e1d1150..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/config/IotPluginEmqxAutoConfiguration.java +++ /dev/null @@ -1,54 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.emqx.config; - -import cn.hutool.core.util.IdUtil; -import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi; -import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler; -import cn.iocoder.yudao.module.iot.plugin.emqx.downstream.IotDeviceDownstreamHandlerImpl; -import cn.iocoder.yudao.module.iot.plugin.emqx.upstream.IotDeviceUpstreamServer; -import io.vertx.core.Vertx; -import io.vertx.mqtt.MqttClient; -import io.vertx.mqtt.MqttClientOptions; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * IoT 插件 EMQX 的专用自动配置类 - * - * @author haohao - */ -@Slf4j -@Configuration -@EnableConfigurationProperties(IotPluginEmqxProperties.class) -public class IotPluginEmqxAutoConfiguration { - - @Bean - public Vertx vertx() { - return Vertx.vertx(); - } - - @Bean - public MqttClient mqttClient(Vertx vertx, IotPluginEmqxProperties emqxProperties) { - MqttClientOptions options = new MqttClientOptions() - .setClientId("yudao-iot-downstream-" + IdUtil.fastSimpleUUID()) - .setUsername(emqxProperties.getMqttUsername()) - .setPassword(emqxProperties.getMqttPassword()) - .setSsl(emqxProperties.getMqttSsl()); - return MqttClient.create(vertx, options); - } - - @Bean(initMethod = "start", destroyMethod = "stop") - public IotDeviceUpstreamServer deviceUpstreamServer(IotDeviceUpstreamApi deviceUpstreamApi, - IotPluginEmqxProperties emqxProperties, - Vertx vertx, - MqttClient mqttClient) { - return new IotDeviceUpstreamServer(emqxProperties, deviceUpstreamApi, vertx, mqttClient); - } - - @Bean - public IotDeviceDownstreamHandler deviceDownstreamHandler(MqttClient mqttClient) { - return new IotDeviceDownstreamHandlerImpl(mqttClient); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/config/IotPluginEmqxProperties.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/config/IotPluginEmqxProperties.java deleted file mode 100644 index 219fe03..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/config/IotPluginEmqxProperties.java +++ /dev/null @@ -1,50 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.emqx.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.validation.annotation.Validated; - -/** - * 物联网插件 - EMQX 配置 - * - * @author 芋道源码 - */ -@ConfigurationProperties(prefix = "yudao.iot.plugin.emqx") -@Validated -@Data -public class IotPluginEmqxProperties { - - // TODO @haohao:参数校验,加下,啊哈 - - /** - * 服务主机 - */ - private String mqttHost; - /** - * 服务端口 - */ - private Integer mqttPort; - /** - * 服务用户名 - */ - private String mqttUsername; - /** - * 服务密码 - */ - private String mqttPassword; - /** - * 是否启用 SSL - */ - private Boolean mqttSsl; - - /** - * 订阅的主题列表 - */ - private String[] mqttTopics; - - /** - * 认证端口 - */ - private Integer authPort; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/downstream/IotDeviceDownstreamHandlerImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/downstream/IotDeviceDownstreamHandlerImpl.java deleted file mode 100644 index f5c1922..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/downstream/IotDeviceDownstreamHandlerImpl.java +++ /dev/null @@ -1,176 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.emqx.downstream; - -import cn.hutool.core.util.IdUtil; -import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.*; -import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler; -import io.netty.handler.codec.mqtt.MqttQoS; -import io.vertx.core.buffer.Buffer; -import io.vertx.mqtt.MqttClient; -import lombok.extern.slf4j.Slf4j; - -import java.util.Map; - -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.MQTT_TOPIC_ILLEGAL; - -/** - * EMQX 插件的 {@link IotDeviceDownstreamHandler} 实现类 - * - * @author 芋道源码 - */ -@Slf4j -public class IotDeviceDownstreamHandlerImpl implements IotDeviceDownstreamHandler { - - private static final String SYS_TOPIC_PREFIX = "/sys/"; - - // TODO @haohao:是不是可以类似 IotDeviceConfigSetVertxHandler 的建议,抽到统一的枚举类 - // TODO @haohao:讨论,感觉 mqtt 和 http,可以做个相对统一的格式哈。;回复 都使用 Alink 格式,方便后续扩展。 - // 设备服务调用 标准 JSON - // 请求Topic:/sys/${productKey}/${deviceName}/thing/service/${tsl.service.identifier} - // 响应Topic:/sys/${productKey}/${deviceName}/thing/service/${tsl.service.identifier}_reply - private static final String SERVICE_TOPIC_PREFIX = "/thing/service/"; - - // 设置设备属性 标准 JSON - // 请求Topic:/sys/${productKey}/${deviceName}/thing/service/property/set - // 响应Topic:/sys/${productKey}/${deviceName}/thing/service/property/set_reply - private static final String PROPERTY_SET_TOPIC = "/thing/service/property/set"; - - private final MqttClient mqttClient; - - /** - * 构造函数 - * - * @param mqttClient MQTT客户端 - */ - public IotDeviceDownstreamHandlerImpl(MqttClient mqttClient) { - this.mqttClient = mqttClient; - } - - @Override - public CommonResult invokeDeviceService(IotDeviceServiceInvokeReqDTO reqDTO) { - log.info("[invokeService][开始调用设备服务][reqDTO: {}]", JSONUtil.toJsonStr(reqDTO)); - - // 验证参数 - if (reqDTO.getProductKey() == null || reqDTO.getDeviceName() == null || reqDTO.getIdentifier() == null) { - log.error("[invokeService][参数不完整][reqDTO: {}]", JSONUtil.toJsonStr(reqDTO)); - return CommonResult.error(MQTT_TOPIC_ILLEGAL.getCode(), MQTT_TOPIC_ILLEGAL.getMsg()); - } - - try { - // 构建请求主题 - String topic = buildServiceTopic(reqDTO.getProductKey(), reqDTO.getDeviceName(), reqDTO.getIdentifier()); - // 构建请求消息 - String requestId = reqDTO.getRequestId() != null ? reqDTO.getRequestId() : generateRequestId(); - JSONObject request = buildServiceRequest(requestId, reqDTO.getIdentifier(), reqDTO.getParams()); - // 发送消息 - publishMessage(topic, request); - - log.info("[invokeService][调用设备服务成功][requestId: {}][topic: {}]", requestId, topic); - return CommonResult.success(true); - } catch (Exception e) { - log.error("[invokeService][调用设备服务异常][reqDTO: {}]", JSONUtil.toJsonStr(reqDTO), e); - return CommonResult.error(MQTT_TOPIC_ILLEGAL.getCode(), MQTT_TOPIC_ILLEGAL.getMsg()); - } - } - - @Override - public CommonResult getDeviceProperty(IotDevicePropertyGetReqDTO getReqDTO) { - return CommonResult.success(true); - } - - @Override - public CommonResult setDeviceProperty(IotDevicePropertySetReqDTO reqDTO) { - // 验证参数 - log.info("[setProperty][开始设置设备属性][reqDTO: {}]", JSONUtil.toJsonStr(reqDTO)); - if (reqDTO.getProductKey() == null || reqDTO.getDeviceName() == null) { - log.error("[setProperty][参数不完整][reqDTO: {}]", JSONUtil.toJsonStr(reqDTO)); - return CommonResult.error(MQTT_TOPIC_ILLEGAL.getCode(), MQTT_TOPIC_ILLEGAL.getMsg()); - } - - try { - // 构建请求主题 - String topic = buildPropertySetTopic(reqDTO.getProductKey(), reqDTO.getDeviceName()); - // 构建请求消息 - String requestId = reqDTO.getRequestId() != null ? reqDTO.getRequestId() : generateRequestId(); - JSONObject request = buildPropertySetRequest(requestId, reqDTO.getProperties()); - // 发送消息 - publishMessage(topic, request); - - log.info("[setProperty][设置设备属性成功][requestId: {}][topic: {}]", requestId, topic); - return CommonResult.success(true); - } catch (Exception e) { - log.error("[setProperty][设置设备属性异常][reqDTO: {}]", JSONUtil.toJsonStr(reqDTO), e); - return CommonResult.error(MQTT_TOPIC_ILLEGAL.getCode(), MQTT_TOPIC_ILLEGAL.getMsg()); - } - } - - @Override - public CommonResult setDeviceConfig(IotDeviceConfigSetReqDTO setReqDTO) { - return CommonResult.success(true); - } - - @Override - public CommonResult upgradeDeviceOta(IotDeviceOtaUpgradeReqDTO upgradeReqDTO) { - return CommonResult.success(true); - } - - /** - * 构建服务调用主题 - */ - private String buildServiceTopic(String productKey, String deviceName, String serviceIdentifier) { - return SYS_TOPIC_PREFIX + productKey + "/" + deviceName + SERVICE_TOPIC_PREFIX + serviceIdentifier; - } - - /** - * 构建属性设置主题 - */ - private String buildPropertySetTopic(String productKey, String deviceName) { - return SYS_TOPIC_PREFIX + productKey + "/" + deviceName + PROPERTY_SET_TOPIC; - } - - // TODO @haohao:这个,后面搞个对象,会不会好点哈? - /** - * 构建服务调用请求 - */ - private JSONObject buildServiceRequest(String requestId, String serviceIdentifier, Map params) { - return new JSONObject() - .set("id", requestId) - .set("version", "1.0") - .set("method", "thing.service." + serviceIdentifier) - .set("params", params != null ? params : new JSONObject()); - } - - /** - * 构建属性设置请求 - */ - private JSONObject buildPropertySetRequest(String requestId, Map properties) { - return new JSONObject() - .set("id", requestId) - .set("version", "1.0") - .set("method", "thing.service.property.set") - .set("params", properties); - } - - /** - * 发布 MQTT 消息 - */ - private void publishMessage(String topic, JSONObject payload) { - mqttClient.publish( - topic, - Buffer.buffer(payload.toString()), - MqttQoS.AT_LEAST_ONCE, - false, - false); - log.info("[publishMessage][发送消息成功][topic: {}][payload: {}]", topic, payload); - } - - /** - * 生成请求 ID - */ - private String generateRequestId() { - return IdUtil.fastSimpleUUID(); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/IotDeviceUpstreamServer.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/IotDeviceUpstreamServer.java deleted file mode 100644 index 00792eb..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/IotDeviceUpstreamServer.java +++ /dev/null @@ -1,236 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.emqx.upstream; - -import cn.hutool.core.util.ArrayUtil; -import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi; -import cn.iocoder.yudao.module.iot.plugin.emqx.config.IotPluginEmqxProperties; -import cn.iocoder.yudao.module.iot.plugin.emqx.upstream.router.IotDeviceAuthVertxHandler; -import cn.iocoder.yudao.module.iot.plugin.emqx.upstream.router.IotDeviceMqttMessageHandler; -import cn.iocoder.yudao.module.iot.plugin.emqx.upstream.router.IotDeviceWebhookVertxHandler; -import io.netty.handler.codec.mqtt.MqttQoS; -import io.vertx.core.Future; -import io.vertx.core.Vertx; -import io.vertx.core.http.HttpServer; -import io.vertx.ext.web.Router; -import io.vertx.ext.web.handler.BodyHandler; -import io.vertx.mqtt.MqttClient; -import lombok.extern.slf4j.Slf4j; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; - -/** - * IoT 设备下行服务端,接收来自 device 设备的请求,转发给 server 服务器 - *

- * 协议:HTTP、MQTT - * - * @author haohao - */ -@Slf4j -public class IotDeviceUpstreamServer { - - /** - * 重连延迟时间(毫秒) - */ - private static final int RECONNECT_DELAY_MS = 5000; - /** - * 连接超时时间(毫秒) - */ - private static final int CONNECTION_TIMEOUT_MS = 10000; - /** - * 默认 QoS 级别 - */ - private static final MqttQoS DEFAULT_QOS = MqttQoS.AT_LEAST_ONCE; - - private final Vertx vertx; - private final HttpServer server; - private final MqttClient client; - private final IotPluginEmqxProperties emqxProperties; - private final IotDeviceMqttMessageHandler mqttMessageHandler; - - /** - * 服务运行状态标志 - */ - private volatile boolean isRunning = false; - - public IotDeviceUpstreamServer(IotPluginEmqxProperties emqxProperties, - IotDeviceUpstreamApi deviceUpstreamApi, - Vertx vertx, - MqttClient client) { - this.vertx = vertx; - this.emqxProperties = emqxProperties; - this.client = client; - - // 创建 Router 实例 - Router router = Router.router(vertx); - router.route().handler(BodyHandler.create()); // 处理 Body - router.post(IotDeviceAuthVertxHandler.PATH) - // TODO @haohao:疑问,mqtt 的认证,需要通过 http 呀? - // 回复:MQTT 认证不必须通过 HTTP 进行,但 HTTP 认证是 EMQX 等 MQTT 服务器支持的一种灵活的认证方式 - .handler(new IotDeviceAuthVertxHandler(deviceUpstreamApi)); - // 添加 Webhook 处理器,用于处理设备连接和断开连接事件 - router.post(IotDeviceWebhookVertxHandler.PATH) - .handler(new IotDeviceWebhookVertxHandler(deviceUpstreamApi)); - // 创建 HttpServer 实例 - this.server = vertx.createHttpServer().requestHandler(router); - this.mqttMessageHandler = new IotDeviceMqttMessageHandler(deviceUpstreamApi, client); - } - - /** - * 启动 HTTP 服务器、MQTT 客户端 - */ - public void start() { - if (isRunning) { - log.warn("[start][服务已经在运行中,请勿重复启动]"); - return; - } - log.info("[start][开始启动服务]"); - - // TODO @haohao:建议先启动 MQTT Broker,再启动 HTTP Server。类似 jdbc 先连接了,在启动 tomcat 的味道 - // 1. 启动 HTTP 服务器 - CompletableFuture httpFuture = server.listen(emqxProperties.getAuthPort()) - .toCompletionStage() - .toCompletableFuture() - .thenAccept(v -> log.info("[start][HTTP 服务器启动完成,端口: {}]", server.actualPort())); - - // 2. 连接 MQTT Broker - CompletableFuture mqttFuture = connectMqtt() - .toCompletionStage() - .toCompletableFuture() - .thenAccept(v -> { - // 2.1 添加 MQTT 断开重连监听器 - client.closeHandler(closeEvent -> { - log.warn("[closeHandler][MQTT 连接已断开,准备重连]"); - reconnectWithDelay(); - }); - // 2.2 设置 MQTT 消息处理器 - setupMessageHandler(); - }); - - // 3. 等待所有服务启动完成 - CompletableFuture.allOf(httpFuture, mqttFuture) - .orTimeout(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS) // TODO @芋艿:JDK8 不兼容 - .whenComplete((result, error) -> { - if (error != null) { - log.error("[start][服务启动失败]", error); - } else { - isRunning = true; - log.info("[start][所有服务启动完成]"); - } - }); - } - - /** - * 设置 MQTT 消息处理器 - */ - private void setupMessageHandler() { - client.publishHandler(mqttMessageHandler::handle); - log.debug("[setupMessageHandler][MQTT 消息处理器设置完成]"); - } - - /** - * 重连 MQTT 客户端 - */ - private void reconnectWithDelay() { - if (!isRunning) { - log.info("[reconnectWithDelay][服务已停止,不再尝试重连]"); - return; - } - - vertx.setTimer(RECONNECT_DELAY_MS, id -> { - log.info("[reconnectWithDelay][开始重新连接 MQTT]"); - connectMqtt(); - }); - } - - /** - * 连接 MQTT Broker 并订阅主题 - * - * @return 连接结果的Future - */ - private Future connectMqtt() { - return client.connect(emqxProperties.getMqttPort(), emqxProperties.getMqttHost()) - .compose(connAck -> { - log.info("[connectMqtt][MQTT客户端连接成功]"); - return subscribeToTopics(); - }) - .recover(error -> { - log.error("[connectMqtt][连接MQTT Broker失败:]", error); - reconnectWithDelay(); - return Future.failedFuture(error); - }); - } - - /** - * 订阅设备上行消息主题 - * - * @return 订阅结果的 Future - */ - private Future subscribeToTopics() { - String[] topics = emqxProperties.getMqttTopics(); - if (ArrayUtil.isEmpty(topics)) { - log.warn("[subscribeToTopics][未配置MQTT主题,跳过订阅]"); - return Future.succeededFuture(); - } - log.info("[subscribeToTopics][开始订阅设备上行消息主题]"); - - Future compositeFuture = Future.succeededFuture(); - for (String topic : topics) { - String trimmedTopic = topic.trim(); - if (trimmedTopic.isEmpty()) { - continue; - } - compositeFuture = compositeFuture.compose(v -> client.subscribe(trimmedTopic, DEFAULT_QOS.value()) - .map(ack -> { - log.info("[subscribeToTopics][成功订阅主题: {}]", trimmedTopic); - return null; - }) - .recover(error -> { - log.error("[subscribeToTopics][订阅主题失败: {}]", trimmedTopic, error); - return Future.succeededFuture(); // 继续订阅其他主题 - })); - } - return compositeFuture; - } - - /** - * 停止所有服务 - */ - public void stop() { - if (!isRunning) { - log.warn("[stop][服务未运行,无需停止]"); - return; - } - log.info("[stop][开始关闭服务]"); - isRunning = false; - - try { - // 关闭 HTTP 服务器 - if (server != null) { - server.close() - .toCompletionStage() - .toCompletableFuture() - .join(); - } - - // 关闭 MQTT 客户端 - if (client != null) { - client.disconnect() - .toCompletionStage() - .toCompletableFuture() - .join(); - } - - // 关闭 Vertx 实例 - if (vertx!= null) { - vertx.close() - .toCompletionStage() - .toCompletableFuture() - .join(); - } - log.info("[stop][关闭完成]"); - } catch (Exception e) { - log.error("[stop][关闭服务异常]", e); - throw new RuntimeException("关闭 IoT 设备上行服务失败", e); - } - } -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/router/IotDeviceAuthVertxHandler.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/router/IotDeviceAuthVertxHandler.java deleted file mode 100644 index e9206d5..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/router/IotDeviceAuthVertxHandler.java +++ /dev/null @@ -1,64 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.emqx.upstream.router; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotDeviceEmqxAuthReqDTO; -import cn.iocoder.yudao.module.iot.plugin.common.util.IotPluginCommonUtils; -import io.vertx.core.Handler; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.RoutingContext; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.util.Collections; - -/** - * IoT EMQX 连接认证的 Vert.x Handler - * - * 参考:EMQX HTTP - * - * 注意:该处理器需要返回特定格式:{"result": "allow"} 或 {"result": "deny"}, - * 以符合 EMQX 认证插件的要求,因此不使用 IotStandardResponse 实体类 - * - * @author haohao - */ -@RequiredArgsConstructor -@Slf4j -public class IotDeviceAuthVertxHandler implements Handler { - - public static final String PATH = "/mqtt/auth"; - - private final IotDeviceUpstreamApi deviceUpstreamApi; - - @Override - public void handle(RoutingContext routingContext) { - try { - // 构建认证请求 DTO - JsonObject json = routingContext.body().asJsonObject(); - String clientId = json.getString("clientid"); - String username = json.getString("username"); - String password = json.getString("password"); - IotDeviceEmqxAuthReqDTO authReqDTO = new IotDeviceEmqxAuthReqDTO() - .setClientId(clientId) - .setUsername(username) - .setPassword(password); - - // 调用认证 API - CommonResult authResult = deviceUpstreamApi.authenticateEmqxConnection(authReqDTO); - if (authResult.getCode() != 0 || !authResult.getData()) { - // 注意:这里必须返回 {"result": "deny"} 格式,以符合 EMQX 认证插件的要求 - IotPluginCommonUtils.writeJsonResponse(routingContext, Collections.singletonMap("result", "deny")); - return; - } - - // 响应结果 - // 注意:这里必须返回 {"result": "allow"} 格式,以符合 EMQX 认证插件的要求 - IotPluginCommonUtils.writeJsonResponse(routingContext, Collections.singletonMap("result", "allow")); - } catch (Exception e) { - log.error("[handle][EMQX 认证异常]", e); - // 注意:这里必须返回 {"result": "deny"} 格式,以符合 EMQX 认证插件的要求 - IotPluginCommonUtils.writeJsonResponse(routingContext, Collections.singletonMap("result", "deny")); - } - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/router/IotDeviceMqttMessageHandler.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/router/IotDeviceMqttMessageHandler.java deleted file mode 100644 index 00fa1b9..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/router/IotDeviceMqttMessageHandler.java +++ /dev/null @@ -1,296 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.emqx.upstream.router; - -import cn.hutool.core.util.StrUtil; -import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotDeviceEventReportReqDTO; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotDevicePropertyReportReqDTO; -import cn.iocoder.yudao.module.iot.plugin.common.pojo.IotStandardResponse; -import cn.iocoder.yudao.module.iot.plugin.common.util.IotPluginCommonUtils; -import io.netty.handler.codec.mqtt.MqttQoS; -import io.vertx.core.buffer.Buffer; -import io.vertx.mqtt.MqttClient; -import io.vertx.mqtt.messages.MqttPublishMessage; -import lombok.extern.slf4j.Slf4j; - -import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -/** - * IoT 设备 MQTT 消息处理器 - * - * 参考:设备属性、事件、服务 - */ -@Slf4j -public class IotDeviceMqttMessageHandler { - - // TODO @haohao:讨论,感觉 mqtt 和 http,可以做个相对统一的格式哈;回复 都使用 Alink 格式,方便后续扩展。 - // 设备上报属性 标准 JSON - // 请求 Topic:/sys/${productKey}/${deviceName}/thing/event/property/post - // 响应 Topic:/sys/${productKey}/${deviceName}/thing/event/property/post_reply - - // 设备上报事件 标准 JSON - // 请求 Topic:/sys/${productKey}/${deviceName}/thing/event/${tsl.event.identifier}/post - // 响应 Topic:/sys/${productKey}/${deviceName}/thing/event/${tsl.event.identifier}/post_reply - - private static final String SYS_TOPIC_PREFIX = "/sys/"; - private static final String PROPERTY_POST_TOPIC = "/thing/event/property/post"; - private static final String EVENT_POST_TOPIC_PREFIX = "/thing/event/"; - private static final String EVENT_POST_TOPIC_SUFFIX = "/post"; - private static final String REPLY_SUFFIX = "_reply"; - private static final String PROPERTY_METHOD = "thing.event.property.post"; - private static final String EVENT_METHOD_PREFIX = "thing.event."; - private static final String EVENT_METHOD_SUFFIX = ".post"; - - private final IotDeviceUpstreamApi deviceUpstreamApi; - private final MqttClient mqttClient; - - public IotDeviceMqttMessageHandler(IotDeviceUpstreamApi deviceUpstreamApi, MqttClient mqttClient) { - this.deviceUpstreamApi = deviceUpstreamApi; - this.mqttClient = mqttClient; - } - - /** - * 处理MQTT消息 - * - * @param message MQTT发布消息 - */ - public void handle(MqttPublishMessage message) { - String topic = message.topicName(); - String payload = message.payload().toString(); - log.info("[messageHandler][接收到消息][topic: {}][payload: {}]", topic, payload); - - try { - if (StrUtil.isEmpty(payload)) { - log.warn("[messageHandler][消息内容为空][topic: {}]", topic); - return; - } - handleMessage(topic, payload); - } catch (Exception e) { - log.error("[messageHandler][处理消息失败][topic: {}][payload: {}]", topic, payload, e); - } - } - - /** - * 根据主题类型处理消息 - * - * @param topic 主题 - * @param payload 消息内容 - */ - private void handleMessage(String topic, String payload) { - // 校验前缀 - if (!topic.startsWith(SYS_TOPIC_PREFIX)) { - log.warn("[handleMessage][未知的消息类型][topic: {}]", topic); - return; - } - - // 处理设备属性上报消息 - if (topic.endsWith(PROPERTY_POST_TOPIC)) { - log.info("[handleMessage][接收到设备属性上报][topic: {}]", topic); - handlePropertyPost(topic, payload); - return; - } - - // 处理设备事件上报消息 - if (topic.contains(EVENT_POST_TOPIC_PREFIX) && topic.endsWith(EVENT_POST_TOPIC_SUFFIX)) { - log.info("[handleMessage][接收到设备事件上报][topic: {}]", topic); - handleEventPost(topic, payload); - return; - } - - // 未知消息类型 - log.warn("[handleMessage][未知的消息类型][topic: {}]", topic); - } - - /** - * 处理设备属性上报消息 - * - * @param topic 主题 - * @param payload 消息内容 - */ - private void handlePropertyPost(String topic, String payload) { - try { - // 解析消息内容 - JSONObject jsonObject = JSONUtil.parseObj(payload); - String[] topicParts = parseTopic(topic); - if (topicParts == null) { - return; - } - - // 构建设备属性上报请求对象 - IotDevicePropertyReportReqDTO reportReqDTO = buildPropertyReportDTO(jsonObject, topicParts); - - // 调用上游 API 处理设备上报数据 - deviceUpstreamApi.reportDeviceProperty(reportReqDTO); - log.info("[handlePropertyPost][处理设备属性上报成功][topic: {}]", topic); - - // 发送响应消息 - sendResponse(topic, jsonObject, PROPERTY_METHOD, null); - } catch (Exception e) { - log.error("[handlePropertyPost][处理设备属性上报失败][topic: {}][payload: {}]", topic, payload, e); - } - } - - /** - * 处理设备事件上报消息 - * - * @param topic 主题 - * @param payload 消息内容 - */ - private void handleEventPost(String topic, String payload) { - try { - // 解析消息内容 - JSONObject jsonObject = JSONUtil.parseObj(payload); - String[] topicParts = parseTopic(topic); - if (topicParts == null) { - return; - } - - // 构建设备事件上报请求对象 - IotDeviceEventReportReqDTO reportReqDTO = buildEventReportDTO(jsonObject, topicParts); - - // 调用上游 API 处理设备上报数据 - deviceUpstreamApi.reportDeviceEvent(reportReqDTO); - log.info("[handleEventPost][处理设备事件上报成功][topic: {}]", topic); - - // 从 topic 中获取事件标识符 - String eventIdentifier = getEventIdentifier(topicParts, topic); - if (eventIdentifier == null) { - return; - } - - // 发送响应消息 - String method = EVENT_METHOD_PREFIX + eventIdentifier + EVENT_METHOD_SUFFIX; - sendResponse(topic, jsonObject, method, null); - } catch (Exception e) { - log.error("[handleEventPost][处理设备事件上报失败][topic: {}][payload: {}]", topic, payload, e); - } - } - - /** - * 解析主题,获取主题各部分 - * - * @param topic 主题 - * @return 主题各部分数组,如果解析失败返回null - */ - private String[] parseTopic(String topic) { - String[] topicParts = topic.split("/"); - if (topicParts.length < 7) { - log.warn("[parseTopic][主题格式不正确][topic: {}]", topic); - return null; - } - return topicParts; - } - - /** - * 从主题部分中获取事件标识符 - * - * @param topicParts 主题各部分 - * @param topic 原始主题,用于日志 - * @return 事件标识符,如果获取失败返回null - */ - private String getEventIdentifier(String[] topicParts, String topic) { - try { - return topicParts[6]; - } catch (ArrayIndexOutOfBoundsException e) { - log.warn("[getEventIdentifier][无法从主题中获取事件标识符][topic: {}][topicParts: {}]", - topic, Arrays.toString(topicParts)); - return null; - } - } - - /** - * 发送响应消息 - * - * @param topic 原始主题 - * @param jsonObject 原始消息JSON对象 - * @param method 响应方法 - * @param customData 自定义数据,可为 null - */ - private void sendResponse(String topic, JSONObject jsonObject, String method, Object customData) { - String replyTopic = topic + REPLY_SUFFIX; - - // 响应结果 - IotStandardResponse response = IotStandardResponse.success( - jsonObject.getStr("id"), method, customData); - try { - mqttClient.publish(replyTopic, Buffer.buffer(JsonUtils.toJsonString(response)), - MqttQoS.AT_LEAST_ONCE, false, false); - log.info("[sendResponse][发送响应消息成功][topic: {}]", replyTopic); - } catch (Exception e) { - log.error("[sendResponse][发送响应消息失败][topic: {}][response: {}]", replyTopic, response, e); - } - } - - /** - * 构建设备属性上报请求对象 - * - * @param jsonObject 消息内容 - * @param topicParts 主题部分 - * @return 设备属性上报请求对象 - */ - private IotDevicePropertyReportReqDTO buildPropertyReportDTO(JSONObject jsonObject, String[] topicParts) { - IotDevicePropertyReportReqDTO reportReqDTO = new IotDevicePropertyReportReqDTO(); - reportReqDTO.setRequestId(jsonObject.getStr("id")); - reportReqDTO.setProcessId(IotPluginCommonUtils.getProcessId()); - reportReqDTO.setReportTime(LocalDateTime.now()); - reportReqDTO.setProductKey(topicParts[2]); - reportReqDTO.setDeviceName(topicParts[3]); - - // 只使用标准JSON格式处理属性数据 - JSONObject params = jsonObject.getJSONObject("params"); - if (params == null) { - log.warn("[buildPropertyReportDTO][消息格式不正确,缺少params字段][jsonObject: {}]", jsonObject); - params = new JSONObject(); - } - - // 将标准格式的params转换为平台需要的properties格式 - Map properties = new HashMap<>(); - for (Map.Entry entry : params.entrySet()) { - String key = entry.getKey(); - Object valueObj = entry.getValue(); - - // 如果是复杂结构(包含value和time) - if (valueObj instanceof JSONObject valueJson) { - properties.put(key, valueJson.getOrDefault("value", valueObj)); - } else { - properties.put(key, valueObj); - } - } - reportReqDTO.setProperties(properties); - - return reportReqDTO; - } - - /** - * 构建设备事件上报请求对象 - * - * @param jsonObject 消息内容 - * @param topicParts 主题部分 - * @return 设备事件上报请求对象 - */ - private IotDeviceEventReportReqDTO buildEventReportDTO(JSONObject jsonObject, String[] topicParts) { - IotDeviceEventReportReqDTO reportReqDTO = new IotDeviceEventReportReqDTO(); - reportReqDTO.setRequestId(jsonObject.getStr("id")); - reportReqDTO.setProcessId(IotPluginCommonUtils.getProcessId()); - reportReqDTO.setReportTime(LocalDateTime.now()); - reportReqDTO.setProductKey(topicParts[2]); - reportReqDTO.setDeviceName(topicParts[3]); - reportReqDTO.setIdentifier(topicParts[6]); - - // 只使用标准JSON格式处理事件参数 - JSONObject params = jsonObject.getJSONObject("params"); - if (params == null) { - log.warn("[buildEventReportDTO][消息格式不正确,缺少params字段][jsonObject: {}]", jsonObject); - params = new JSONObject(); - } - reportReqDTO.setParams(params); - - return reportReqDTO; - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/router/IotDeviceWebhookVertxHandler.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/router/IotDeviceWebhookVertxHandler.java deleted file mode 100644 index 21b49e0..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/router/IotDeviceWebhookVertxHandler.java +++ /dev/null @@ -1,152 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.emqx.upstream.router; - -import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotDeviceStateUpdateReqDTO; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStateEnum; -import cn.iocoder.yudao.module.iot.plugin.common.util.IotPluginCommonUtils; -import io.vertx.core.Handler; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.RoutingContext; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.time.LocalDateTime; -import java.util.Collections; - -/** - * IoT EMQX Webhook 事件处理的 Vert.x Handler - * - * 参考:EMQX Webhook - * - * 注意:该处理器需要返回特定格式:{"result": "success"} 或 {"result": "error"}, - * 以符合 EMQX Webhook 插件的要求,因此不使用 IotStandardResponse 实体类。 - * - * @author haohao - */ -@RequiredArgsConstructor -@Slf4j -public class IotDeviceWebhookVertxHandler implements Handler { - - public static final String PATH = "/mqtt/webhook"; - - private final IotDeviceUpstreamApi deviceUpstreamApi; - - @Override - public void handle(RoutingContext routingContext) { - try { - // 解析请求体 - JsonObject json = routingContext.body().asJsonObject(); - String event = json.getString("event"); - String clientId = json.getString("clientid"); - String username = json.getString("username"); - - // 处理不同的事件类型 - switch (event) { - case "client.connected": - handleClientConnected(clientId, username); - break; - case "client.disconnected": - handleClientDisconnected(clientId, username); - break; - default: - log.info("[handle][未处理的 Webhook 事件] event={}, clientId={}, username={}", event, clientId, username); - break; - } - - // 返回成功响应 - // 注意:这里必须返回 {"result": "success"} 格式,以符合 EMQX Webhook 插件的要求 - IotPluginCommonUtils.writeJsonResponse(routingContext, Collections.singletonMap("result", "success")); - } catch (Exception e) { - log.error("[handle][处理 Webhook 事件异常]", e); - // 注意:这里必须返回 {"result": "error"} 格式,以符合 EMQX Webhook 插件的要求 - IotPluginCommonUtils.writeJsonResponse(routingContext, Collections.singletonMap("result", "error")); - } - } - - /** - * 处理客户端连接事件 - * - * @param clientId 客户端ID - * @param username 用户名 - */ - private void handleClientConnected(String clientId, String username) { - // 解析产品标识和设备名称 - if (StrUtil.isEmpty(username) || "undefined".equals(username)) { - log.warn("[handleClientConnected][客户端连接事件,但用户名为空] clientId={}", clientId); - return; - } - String[] parts = parseUsername(username); - if (parts == null) { - return; - } - - // 更新设备状态为在线 - IotDeviceStateUpdateReqDTO updateReqDTO = new IotDeviceStateUpdateReqDTO(); - updateReqDTO.setProductKey(parts[1]); - updateReqDTO.setDeviceName(parts[0]); - updateReqDTO.setState(IotDeviceStateEnum.ONLINE.getState()); - updateReqDTO.setProcessId(IotPluginCommonUtils.getProcessId()); - updateReqDTO.setReportTime(LocalDateTime.now()); - CommonResult result = deviceUpstreamApi.updateDeviceState(updateReqDTO); - if (result.getCode() != 0 || !result.getData()) { - log.error("[handleClientConnected][更新设备状态为在线失败] clientId={}, username={}, code={}, msg={}", - clientId, username, result.getCode(), result.getMsg()); - } else { - log.info("[handleClientConnected][更新设备状态为在线成功] clientId={}, username={}", clientId, username); - } - } - - /** - * 处理客户端断开连接事件 - * - * @param clientId 客户端ID - * @param username 用户名 - */ - private void handleClientDisconnected(String clientId, String username) { - // 解析产品标识和设备名称 - if (StrUtil.isEmpty(username) || "undefined".equals(username)) { - log.warn("[handleClientDisconnected][客户端断开连接事件,但用户名为空] clientId={}", clientId); - return; - } - String[] parts = parseUsername(username); - if (parts == null) { - return; - } - - // 更新设备状态为离线 - IotDeviceStateUpdateReqDTO offlineReqDTO = new IotDeviceStateUpdateReqDTO(); - offlineReqDTO.setProductKey(parts[1]); - offlineReqDTO.setDeviceName(parts[0]); - offlineReqDTO.setState(IotDeviceStateEnum.OFFLINE.getState()); - offlineReqDTO.setProcessId(IotPluginCommonUtils.getProcessId()); - offlineReqDTO.setReportTime(LocalDateTime.now()); - CommonResult offlineResult = deviceUpstreamApi.updateDeviceState(offlineReqDTO); - if (offlineResult.getCode() != 0 || !offlineResult.getData()) { - log.error("[handleClientDisconnected][更新设备状态为离线失败] clientId={}, username={}, code={}, msg={}", - clientId, username, offlineResult.getCode(), offlineResult.getMsg()); - } else { - log.info("[handleClientDisconnected][更新设备状态为离线成功] clientId={}, username={}", clientId, username); - } - } - - /** - * 解析用户名,格式为 deviceName&productKey - * - * @param username 用户名 - * @return 解析结果,[0] 为 deviceName,[1] 为 productKey,解析失败返回 null - */ - private String[] parseUsername(String username) { - if (StrUtil.isEmpty(username)) { - return null; - } - String[] parts = username.split("&"); - if (parts.length != 2) { - log.warn("[parseUsername][用户名格式({})不正确,无法解析产品标识和设备名称]", username); - return null; - } - return parts; - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/resources/application.yml b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/resources/application.yml deleted file mode 100644 index c00621c..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/resources/application.yml +++ /dev/null @@ -1,20 +0,0 @@ -spring: - application: - name: yudao-module-iot-plugin-emqx - -yudao: - iot: - plugin: - common: - upstream-url: http://127.0.0.1:48080 - downstream-port: 8100 - plugin-key: yudao-module-iot-plugin-emqx - emqx: - mqtt-host: 127.0.0.1 - mqtt-port: 1883 - mqtt-ssl: false - mqtt-username: yudao - mqtt-password: 123456 - mqtt-topics: - - "/sys/#" - auth-port: 8101 diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/plugin.properties b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/plugin.properties deleted file mode 100644 index 647d551..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/plugin.properties +++ /dev/null @@ -1,6 +0,0 @@ -plugin.id=yudao-module-iot-plugin-http -plugin.class=cn.iocoder.yudao.module.iot.plugin.http.config.IotHttpVertxPlugin -plugin.version=1.0.0 -plugin.provider=yudao -plugin.dependencies= -plugin.description=yudao-module-iot-plugin-http-1.0.0 \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/pom.xml b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/pom.xml deleted file mode 100644 index 88a413c..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/pom.xml +++ /dev/null @@ -1,165 +0,0 @@ - - - - yudao-module-iot-plugins - cn.iocoder.boot - ${revision} - - 4.0.0 - jar - - yudao-module-iot-plugin-http - 1.0.0 - - ${project.artifactId} - - - 物联网 插件模块 - http 插件 - - - - - ${project.artifactId} - cn.iocoder.yudao.module.iot.plugin.http.config.IotHttpVertxPlugin - ${project.version} - yudao - ${project.artifactId}-${project.version} - - - - - - - - org.apache.maven.plugins - maven-antrun-plugin - 1.6 - - - unzip jar file - package - - - - - - - run - - - - - - - maven-assembly-plugin - 2.3 - - - - src/main/assembly/assembly.xml - - - false - - - - make-assembly - package - - attached - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - - - ${plugin.id} - ${plugin.class} - ${plugin.version} - ${plugin.provider} - ${plugin.description} - ${plugin.dependencies} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring.boot.version} - - - - repackage - - - -standalone - - - - - - - - - - - cn.iocoder.boot - yudao-module-iot-plugin-common - ${revision} - - - - - org.springframework.boot - spring-boot-starter-web - - - - - io.vertx - vertx-web - - - \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/assembly/assembly.xml b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/assembly/assembly.xml deleted file mode 100644 index 9b79e61..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/assembly/assembly.xml +++ /dev/null @@ -1,24 +0,0 @@ - - plugin - - zip - - false - - - false - runtime - lib - - *:jar:* - - - - - - - target/plugin-classes - classes - - - diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/IotHttpPluginApplication.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/IotHttpPluginApplication.java deleted file mode 100644 index a88b34e..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/IotHttpPluginApplication.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.http; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.WebApplicationType; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * 独立运行入口 - */ -@Slf4j -@SpringBootApplication -public class IotHttpPluginApplication { - - public static void main(String[] args) { - SpringApplication application = new SpringApplication(IotHttpPluginApplication.class); - application.setWebApplicationType(WebApplicationType.NONE); - application.run(args); - log.info("[main][独立模式启动完成]"); - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotHttpVertxPlugin.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotHttpVertxPlugin.java deleted file mode 100644 index f704c18..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotHttpVertxPlugin.java +++ /dev/null @@ -1,60 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.http.config; - -import cn.hutool.core.lang.Assert; -import cn.hutool.extra.spring.SpringUtil; -import lombok.extern.slf4j.Slf4j; -import org.pf4j.PluginWrapper; -import org.pf4j.spring.SpringPlugin; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; - -// TODO @芋艿:完善注释 -/** - * 负责插件的启动和停止,与 Vert.x 的生命周期管理 - */ -@Slf4j -public class IotHttpVertxPlugin extends SpringPlugin { - - public IotHttpVertxPlugin(PluginWrapper wrapper) { - super(wrapper); - } - - @Override - public void start() { - log.info("[HttpVertxPlugin][HttpVertxPlugin 插件启动开始...]"); - try { - ApplicationContext pluginContext = getApplicationContext(); - Assert.notNull(pluginContext, "pluginContext 不能为空"); - log.info("[HttpVertxPlugin][HttpVertxPlugin 插件启动成功...]"); - } catch (Exception e) { - log.error("[HttpVertxPlugin][HttpVertxPlugin 插件开启动异常...]", e); - } - } - - @Override - public void stop() { - log.info("[HttpVertxPlugin][HttpVertxPlugin 插件停止开始...]"); - try { - log.info("[HttpVertxPlugin][HttpVertxPlugin 插件停止成功...]"); - } catch (Exception e) { - log.error("[HttpVertxPlugin][HttpVertxPlugin 插件停止异常...]", e); - } - } - - // TODO @芋艿:思考下,未来要不要。。。 - @Override - protected ApplicationContext createApplicationContext() { - // 创建插件自己的 ApplicationContext - AnnotationConfigApplicationContext pluginContext = new AnnotationConfigApplicationContext(); - // 设置父容器为主应用的 ApplicationContext (确保主应用中提供的类可用) - pluginContext.setParent(SpringUtil.getApplicationContext()); - // 继续使用插件自己的 ClassLoader 以加载插件内部的类 - pluginContext.setClassLoader(getWrapper().getPluginClassLoader()); - // 扫描当前插件的自动配置包 - // TODO @芋艿:后续看看,怎么配置类包 - pluginContext.scan("cn.iocoder.yudao.module.iot.plugin.http.config"); - pluginContext.refresh(); - return pluginContext; - } - -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotPluginHttpAutoConfiguration.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotPluginHttpAutoConfiguration.java deleted file mode 100644 index 63e55f5..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotPluginHttpAutoConfiguration.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.http.config; - -import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi; -import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler; -import cn.iocoder.yudao.module.iot.plugin.http.downstream.IotDeviceDownstreamHandlerImpl; -import cn.iocoder.yudao.module.iot.plugin.http.upstream.IotDeviceUpstreamServer; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * IoT 插件 HTTP 的专用自动配置类 - * - * @author haohao - */ -@Configuration -@EnableConfigurationProperties(IotPluginHttpProperties.class) -public class IotPluginHttpAutoConfiguration { - - @Bean(initMethod = "start", destroyMethod = "stop") - public IotDeviceUpstreamServer deviceUpstreamServer(IotDeviceUpstreamApi deviceUpstreamApi, - IotPluginHttpProperties properties) { - return new IotDeviceUpstreamServer(properties, deviceUpstreamApi); - } - - @Bean - public IotDeviceDownstreamHandler deviceDownstreamHandler() { - return new IotDeviceDownstreamHandlerImpl(); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotPluginHttpProperties.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotPluginHttpProperties.java deleted file mode 100644 index 49dca81..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/IotPluginHttpProperties.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.http.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.validation.annotation.Validated; - -@ConfigurationProperties(prefix = "yudao.iot.plugin.http") -@Validated -@Data -public class IotPluginHttpProperties { - - /** - * HTTP 服务端口 - */ - private Integer serverPort; - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/downstream/IotDeviceDownstreamHandlerImpl.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/downstream/IotDeviceDownstreamHandlerImpl.java deleted file mode 100644 index 869fe72..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/downstream/IotDeviceDownstreamHandlerImpl.java +++ /dev/null @@ -1,44 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.http.downstream; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.*; -import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler; - -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.NOT_IMPLEMENTED; - -/** - * HTTP 插件的 {@link IotDeviceDownstreamHandler} 实现类 - * - * 但是:由于设备通过 HTTP 短链接接入,导致其实无法下行指导给 device 设备,所以基本都是直接返回失败!!! - * 类似 MQTT、WebSocket、TCP 插件,是可以实现下行指令的。 - * - * @author 芋道源码 - */ -public class IotDeviceDownstreamHandlerImpl implements IotDeviceDownstreamHandler { - - @Override - public CommonResult invokeDeviceService(IotDeviceServiceInvokeReqDTO invokeReqDTO) { - return CommonResult.error(NOT_IMPLEMENTED.getCode(), "HTTP 不支持调用设备服务"); - } - - @Override - public CommonResult getDeviceProperty(IotDevicePropertyGetReqDTO getReqDTO) { - return CommonResult.error(NOT_IMPLEMENTED.getCode(), "HTTP 不支持获取设备属性"); - } - - @Override - public CommonResult setDeviceProperty(IotDevicePropertySetReqDTO setReqDTO) { - return CommonResult.error(NOT_IMPLEMENTED.getCode(), "HTTP 不支持设置设备属性"); - } - - @Override - public CommonResult setDeviceConfig(IotDeviceConfigSetReqDTO setReqDTO) { - return CommonResult.error(NOT_IMPLEMENTED.getCode(), "HTTP 不支持设置设备属性"); - } - - @Override - public CommonResult upgradeDeviceOta(IotDeviceOtaUpgradeReqDTO upgradeReqDTO) { - return CommonResult.error(NOT_IMPLEMENTED.getCode(), "HTTP 不支持设置设备属性"); - } - -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/upstream/IotDeviceUpstreamServer.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/upstream/IotDeviceUpstreamServer.java deleted file mode 100644 index 67129a4..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/upstream/IotDeviceUpstreamServer.java +++ /dev/null @@ -1,83 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.http.upstream; - -import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi; -import cn.iocoder.yudao.module.iot.plugin.http.config.IotPluginHttpProperties; -import cn.iocoder.yudao.module.iot.plugin.http.upstream.router.IotDeviceUpstreamVertxHandler; -import io.vertx.core.Vertx; -import io.vertx.core.http.HttpServer; -import io.vertx.ext.web.Router; -import io.vertx.ext.web.handler.BodyHandler; -import lombok.extern.slf4j.Slf4j; - -/** - * IoT 设备下行服务端,接收来自 device 设备的请求,转发给 server 服务器 - * - * 协议:HTTP - * - * @author haohao - */ -@Slf4j -public class IotDeviceUpstreamServer { - - private final Vertx vertx; - private final HttpServer server; - private final IotPluginHttpProperties properties; - - public IotDeviceUpstreamServer(IotPluginHttpProperties properties, - IotDeviceUpstreamApi deviceUpstreamApi) { - this.properties = properties; - // 创建 Vertx 实例 - this.vertx = Vertx.vertx(); - // 创建 Router 实例 - Router router = Router.router(vertx); - router.route().handler(BodyHandler.create()); // 处理 Body - - // 使用统一的 Handler 处理所有上行请求 - IotDeviceUpstreamVertxHandler upstreamHandler = new IotDeviceUpstreamVertxHandler(deviceUpstreamApi); - router.post(IotDeviceUpstreamVertxHandler.PROPERTY_PATH).handler(upstreamHandler); - router.post(IotDeviceUpstreamVertxHandler.EVENT_PATH).handler(upstreamHandler); - - // 创建 HttpServer 实例 - this.server = vertx.createHttpServer().requestHandler(router); - } - - /** - * 启动 HTTP 服务器 - */ - public void start() { - log.info("[start][开始启动]"); - server.listen(properties.getServerPort()) - .toCompletionStage() - .toCompletableFuture() - .join(); - log.info("[start][启动完成,端口({})]", this.server.actualPort()); - } - - /** - * 停止所有 - */ - public void stop() { - log.info("[stop][开始关闭]"); - try { - // 关闭 HTTP 服务器 - if (server != null) { - server.close() - .toCompletionStage() - .toCompletableFuture() - .join(); - } - - // 关闭 Vertx 实例 - if (vertx != null) { - vertx.close() - .toCompletionStage() - .toCompletableFuture() - .join(); - } - log.info("[stop][关闭完成]"); - } catch (Exception e) { - log.error("[stop][关闭异常]", e); - throw new RuntimeException(e); - } - } -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/upstream/router/IotDeviceUpstreamVertxHandler.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/upstream/router/IotDeviceUpstreamVertxHandler.java deleted file mode 100644 index 79d465e..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/upstream/router/IotDeviceUpstreamVertxHandler.java +++ /dev/null @@ -1,188 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin.http.upstream.router; - -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ObjUtil; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.iot.api.device.IotDeviceUpstreamApi; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotDeviceEventReportReqDTO; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotDevicePropertyReportReqDTO; -import cn.iocoder.yudao.module.iot.api.device.dto.control.upstream.IotDeviceStateUpdateReqDTO; -import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStateEnum; -import cn.iocoder.yudao.module.iot.plugin.common.pojo.IotStandardResponse; -import cn.iocoder.yudao.module.iot.plugin.common.util.IotPluginCommonUtils; -import io.vertx.core.Handler; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.RoutingContext; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.time.LocalDateTime; -import java.util.HashMap; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; -import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR; - -/** - * IoT 设备上行统一处理的 Vert.x Handler - *

- * 统一处理设备属性上报和事件上报的请求 - * - * @author haohao - */ -@RequiredArgsConstructor -@Slf4j -public class IotDeviceUpstreamVertxHandler implements Handler { - - // TODO @haohao:要不要类似 IotDeviceConfigSetVertxHandler 写的,把这些 PATH、METHOD 之类的抽走 - /** - * 属性上报路径 - */ - public static final String PROPERTY_PATH = "/sys/:productKey/:deviceName/thing/event/property/post"; - /** - * 事件上报路径 - */ - public static final String EVENT_PATH = "/sys/:productKey/:deviceName/thing/event/:identifier/post"; - - private static final String PROPERTY_METHOD = "thing.event.property.post"; - private static final String EVENT_METHOD_PREFIX = "thing.event."; - private static final String EVENT_METHOD_SUFFIX = ".post"; - - private final IotDeviceUpstreamApi deviceUpstreamApi; - - // TODO @haohao:要不要分成多个 Handler?每个只解决一个问题哈。 - @Override - public void handle(RoutingContext routingContext) { - String path = routingContext.request().path(); - String requestId = IdUtil.fastSimpleUUID(); - - try { - // 1. 解析通用参数 - String productKey = routingContext.pathParam("productKey"); - String deviceName = routingContext.pathParam("deviceName"); - JsonObject body = routingContext.body().asJsonObject(); - requestId = ObjUtil.defaultIfBlank(body.getString("id"), requestId); - - // 2. 根据路径模式处理不同类型的请求 - CommonResult result; - String method; - if (path.matches(".*/thing/event/property/post")) { - // 处理属性上报 - IotDevicePropertyReportReqDTO reportReqDTO = parsePropertyReportRequest(productKey, deviceName, requestId, body); - - // 设备上线 - updateDeviceState(reportReqDTO.getProductKey(), reportReqDTO.getDeviceName()); - - // 属性上报 - result = deviceUpstreamApi.reportDeviceProperty(reportReqDTO); - method = PROPERTY_METHOD; - } else if (path.matches(".*/thing/event/.+/post")) { - // 处理事件上报 - String identifier = routingContext.pathParam("identifier"); - IotDeviceEventReportReqDTO reportReqDTO = parseEventReportRequest(productKey, deviceName, identifier, requestId, body); - - // 设备上线 - updateDeviceState(reportReqDTO.getProductKey(), reportReqDTO.getDeviceName()); - - // 事件上报 - result = deviceUpstreamApi.reportDeviceEvent(reportReqDTO); - method = EVENT_METHOD_PREFIX + identifier + EVENT_METHOD_SUFFIX; - } else { - // 不支持的请求路径 - IotStandardResponse errorResponse = IotStandardResponse.error(requestId, "unknown", BAD_REQUEST.getCode(), "不支持的请求路径"); - IotPluginCommonUtils.writeJsonResponse(routingContext, errorResponse); - return; - } - - // 3. 返回标准响应 - IotStandardResponse response; - if (result.isSuccess()) { - response = IotStandardResponse.success(requestId, method, result.getData()); - } else { - response = IotStandardResponse.error(requestId, method, result.getCode(), result.getMsg()); - } - IotPluginCommonUtils.writeJsonResponse(routingContext, response); - } catch (Exception e) { - log.error("[handle][处理上行请求异常] path={}", path, e); - String method = path.contains("/property/") ? PROPERTY_METHOD - : EVENT_METHOD_PREFIX + (routingContext.pathParams().containsKey("identifier") - ? routingContext.pathParam("identifier") - : "unknown") + EVENT_METHOD_SUFFIX; - IotStandardResponse errorResponse = IotStandardResponse.error(requestId, method, INTERNAL_SERVER_ERROR.getCode(), INTERNAL_SERVER_ERROR.getMsg()); - IotPluginCommonUtils.writeJsonResponse(routingContext, errorResponse); - } - } - - /** - * 更新设备状态 - * - * @param productKey 产品 Key - * @param deviceName 设备名称 - */ - private void updateDeviceState(String productKey, String deviceName) { - deviceUpstreamApi.updateDeviceState(((IotDeviceStateUpdateReqDTO) new IotDeviceStateUpdateReqDTO() - .setRequestId(IdUtil.fastSimpleUUID()).setProcessId(IotPluginCommonUtils.getProcessId()).setReportTime(LocalDateTime.now()) - .setProductKey(productKey).setDeviceName(deviceName)).setState(IotDeviceStateEnum.ONLINE.getState())); - } - - /** - * 解析属性上报请求 - * - * @param productKey 产品 Key - * @param deviceName 设备名称 - * @param requestId 请求 ID - * @param body 请求体 - * @return 属性上报请求 DTO - */ - @SuppressWarnings("unchecked") - private IotDevicePropertyReportReqDTO parsePropertyReportRequest(String productKey, String deviceName, String requestId, JsonObject body) { - // 按照标准 JSON 格式处理属性数据 - Map properties = new HashMap<>(); - Map params = body.getJsonObject("params") != null ? body.getJsonObject("params").getMap() : null; - if (params != null) { - // 将标准格式的 params 转换为平台需要的 properties 格式 - for (Map.Entry entry : params.entrySet()) { - String key = entry.getKey(); - Object valueObj = entry.getValue(); - // 如果是复杂结构(包含 value 和 time) - if (valueObj instanceof Map) { - Map valueMap = (Map) valueObj; - properties.put(key, valueMap.getOrDefault("value", valueObj)); - } else { - properties.put(key, valueObj); - } - } - } - - // 构建属性上报请求 DTO - return ((IotDevicePropertyReportReqDTO) new IotDevicePropertyReportReqDTO().setRequestId(requestId) - .setProcessId(IotPluginCommonUtils.getProcessId()).setReportTime(LocalDateTime.now()) - .setProductKey(productKey).setDeviceName(deviceName)).setProperties(properties); - } - - /** - * 解析事件上报请求 - * - * @param productKey 产品K ey - * @param deviceName 设备名称 - * @param identifier 事件标识符 - * @param requestId 请求 ID - * @param body 请求体 - * @return 事件上报请求 DTO - */ - private IotDeviceEventReportReqDTO parseEventReportRequest(String productKey, String deviceName, String identifier, String requestId, JsonObject body) { - // 按照标准 JSON 格式处理事件参数 - Map params; - if (body.containsKey("params")) { - params = body.getJsonObject("params").getMap(); - } else { - // 兼容旧格式 - params = new HashMap<>(); - } - - // 构建事件上报请求 DTO - return ((IotDeviceEventReportReqDTO) new IotDeviceEventReportReqDTO().setRequestId(requestId) - .setProcessId(IotPluginCommonUtils.getProcessId()).setReportTime(LocalDateTime.now()) - .setProductKey(productKey).setDeviceName(deviceName)).setIdentifier(identifier).setParams(params); - } -} \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/resources/application.yml b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/resources/application.yml deleted file mode 100644 index f195628..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/resources/application.yml +++ /dev/null @@ -1,13 +0,0 @@ -spring: - application: - name: yudao-module-iot-plugin-http - -yudao: - iot: - plugin: - common: - upstream-url: http://127.0.0.1:48080 - downstream-port: 8093 - plugin-key: yudao-module-iot-plugin-http - http: - server-port: 8092 diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/plugin.properties b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/plugin.properties deleted file mode 100644 index 939e0f6..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/plugin.properties +++ /dev/null @@ -1,7 +0,0 @@ -plugin.id=mqtt-plugin -plugin.description=Vert.x MQTT plugin -plugin.class=cn.iocoder.yudao.module.iot.plugin.MqttPlugin -plugin.version=1.0.0 -plugin.requires= -plugin.provider=ahh -plugin.license=Apache-2.0 diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/pom.xml b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/pom.xml deleted file mode 100644 index f1fba50..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/pom.xml +++ /dev/null @@ -1,156 +0,0 @@ - - - - yudao-module-iot-plugins - cn.iocoder.boot - ${revision} - - 4.0.0 - jar - - yudao-module-iot-plugin-mqtt - - ${project.artifactId} - - - 物联网 插件模块 - mqtt 插件 - - - - - mqtt-plugin - cn.iocoder.yudao.module.iot.plugin.MqttPlugin - 0.0.1 - ahh - mqtt-plugin-0.0.1 - - - - - - - - - org.apache.maven.plugins - maven-antrun-plugin - 1.6 - - - unzip jar file - package - - - - - - - run - - - - - - - maven-assembly-plugin - 2.3 - - - - src/main/assembly/assembly.xml - - - false - - - - make-assembly - package - - attached - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - - - ${plugin.id} - ${plugin.class} - ${plugin.version} - ${plugin.provider} - ${plugin.description} - ${plugin.dependencies} - - - - - - - maven-deploy-plugin - - true - - - - - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.pf4j - pf4j-spring - provided - - - - cn.iocoder.boot - yudao-module-iot-api - ${revision} - - - org.projectlombok - lombok - ${lombok.version} - provided - - - - io.vertx - vertx-mqtt - 4.5.11 - - - \ No newline at end of file diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/src/main/assembly/assembly.xml b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/src/main/assembly/assembly.xml deleted file mode 100644 index daec9e4..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/src/main/assembly/assembly.xml +++ /dev/null @@ -1,31 +0,0 @@ - - plugin - - zip - - false - - - false - runtime - lib - - *:jar:* - - - - - - - target/plugin-classes - classes - - - diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/src/main/java/cn/iocoder/yudao/module/iot/plugin/MqttPlugin.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/src/main/java/cn/iocoder/yudao/module/iot/plugin/MqttPlugin.java deleted file mode 100644 index 7883fa8..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/src/main/java/cn/iocoder/yudao/module/iot/plugin/MqttPlugin.java +++ /dev/null @@ -1,37 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin; - -import lombok.extern.slf4j.Slf4j; -import org.pf4j.Plugin; -import org.pf4j.PluginWrapper; - -// TODO @芋艿:暂未实现 -@Slf4j -public class MqttPlugin extends Plugin { - - private MqttServerExtension mqttServerExtension; - - public MqttPlugin(PluginWrapper wrapper) { - super(wrapper); - } - - @Override - public void start() { - log.info("MQTT Plugin started."); - mqttServerExtension = new MqttServerExtension(); - mqttServerExtension.startMqttServer(); - } - - @Override - public void stop() { - log.info("MQTT Plugin stopped."); - if (mqttServerExtension != null) { - mqttServerExtension.stopMqttServer().onComplete(ar -> { - if (ar.succeeded()) { - log.info("Stopped MQTT Server successfully"); - } else { - log.error("Failed to stop MQTT Server: {}", ar.cause().getMessage()); - } - }); - } - } -} diff --git a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/src/main/java/cn/iocoder/yudao/module/iot/plugin/MqttServerExtension.java b/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/src/main/java/cn/iocoder/yudao/module/iot/plugin/MqttServerExtension.java deleted file mode 100644 index dd0c5da..0000000 --- a/cc-admin-master/yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-mqtt/src/main/java/cn/iocoder/yudao/module/iot/plugin/MqttServerExtension.java +++ /dev/null @@ -1,232 +0,0 @@ -package cn.iocoder.yudao.module.iot.plugin; - -import io.netty.handler.codec.mqtt.MqttProperties; -import io.netty.handler.codec.mqtt.MqttQoS; -import io.vertx.core.Future; -import io.vertx.core.Vertx; -import io.vertx.core.buffer.Buffer; -import io.vertx.mqtt.MqttEndpoint; -import io.vertx.mqtt.MqttServer; -import io.vertx.mqtt.MqttServerOptions; -import io.vertx.mqtt.MqttTopicSubscription; -import io.vertx.mqtt.messages.MqttDisconnectMessage; -import io.vertx.mqtt.messages.MqttPublishMessage; -import io.vertx.mqtt.messages.MqttSubscribeMessage; -import io.vertx.mqtt.messages.MqttUnsubscribeMessage; -import io.vertx.mqtt.messages.codes.MqttSubAckReasonCode; -import lombok.extern.slf4j.Slf4j; -import org.pf4j.Extension; - -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -// TODO @芋艿:暂未实现 -/** - * 根据官方示例,整合常见 MQTT 功能到 PF4J 的 Extension 类中 - */ -@Slf4j -@Extension -public class MqttServerExtension { - - private Vertx vertx; - private MqttServer mqttServer; - - /** - * 启动 MQTT 服务端 - * 可根据需要决定是否启用 SSL/TLS、WebSocket、多实例部署等 - */ - public void startMqttServer() { - // 初始化 Vert.x - vertx = Vertx.vertx(); - - // ========== 如果需要 SSL/TLS,请参考下面注释,启用注释并替换端口、证书路径等 ========== - // MqttServerOptions options = new MqttServerOptions() - // .setPort(8883) - // .setKeyCertOptions(new PemKeyCertOptions() - // .setKeyPath("./src/test/resources/tls/server-key.pem") - // .setCertPath("./src/test/resources/tls/server-cert.pem")) - // .setSsl(true); - - // ========== 如果需要 WebSocket,请设置 setUseWebSocket(true) ========== - // options.setUseWebSocket(true); - - // ========== 默认不启用 SSL 的示例 ========== - MqttServerOptions options = new MqttServerOptions() - .setPort(1883) - .setHost("0.0.0.0") - .setUseWebSocket(false); // 如果需要 WebSocket,请改为 true - - mqttServer = MqttServer.create(vertx, options); - - // 指定 endpointHandler,处理客户端连接等 - mqttServer.endpointHandler(endpoint -> { - handleClientConnect(endpoint); - handleDisconnect(endpoint); - handleSubscribe(endpoint); - handleUnsubscribe(endpoint); - handlePublish(endpoint); - handlePing(endpoint); - }); - - // 启动监听 - mqttServer.listen(ar -> { - if (ar.succeeded()) { - log.info("MQTT server is listening on port {}", mqttServer.actualPort()); - } else { - log.error("Error on starting the server", ar.cause()); - } - }); - } - - /** - * 优雅关闭 MQTT 服务端 - */ - public Future stopMqttServer() { - if (mqttServer != null) { - return mqttServer.close().onComplete(ar -> { - if (ar.succeeded()) { - log.info("MQTT server closed."); - if (vertx != null) { - vertx.close(); - log.info("Vert.x instance closed."); - } - } else { - log.error("Failed to close MQTT server: {}", ar.cause().getMessage()); - } - }); - } - return Future.succeededFuture(); - } - - // ==================== 以下为官方示例中常见事件的处理封装 ==================== - - /** - * 处理客户端连接 (CONNECT) - */ - private void handleClientConnect(MqttEndpoint endpoint) { - // 打印 CONNECT 的主要信息 - log.info("MQTT client [{}] request to connect, clean session = {}", - endpoint.clientIdentifier(), endpoint.isCleanSession()); - - if (endpoint.auth() != null) { - log.info("[username = {}, password = {}]", endpoint.auth().getUsername(), endpoint.auth().getPassword()); - } - log.info("[properties = {}]", endpoint.connectProperties()); - - if (endpoint.will() != null) { - log.info("[will topic = {}, msg = {}, QoS = {}, isRetain = {}]", - endpoint.will().getWillTopic(), - new String(endpoint.will().getWillMessageBytes()), - endpoint.will().getWillQos(), - endpoint.will().isWillRetain()); - } - - log.info("[keep alive timeout = {}]", endpoint.keepAliveTimeSeconds()); - - // 接受远程客户端的连接 - endpoint.accept(false); - } - - /** - * 处理客户端主动断开 (DISCONNECT) - */ - private void handleDisconnect(MqttEndpoint endpoint) { - endpoint.disconnectMessageHandler((MqttDisconnectMessage disconnectMessage) -> { - log.info("Received disconnect from client [{}], reason code = {}", - endpoint.clientIdentifier(), disconnectMessage.code()); - }); - } - - /** - * 处理客户端订阅 (SUBSCRIBE) - */ - private void handleSubscribe(MqttEndpoint endpoint) { - endpoint.subscribeHandler((MqttSubscribeMessage subscribe) -> { - List reasonCodes = new ArrayList<>(); - for (MqttTopicSubscription s : subscribe.topicSubscriptions()) { - log.info("Subscription for {} with QoS {}", s.topicName(), s.qualityOfService()); - // 将客户端请求的 QoS 转换为返回给客户端的 reason code(可能是错误码或实际 granted QoS) - reasonCodes.add(MqttSubAckReasonCode.qosGranted(s.qualityOfService())); - } - // 回复 SUBACK,MQTT 5.0 时可指定 reasonCodes、properties - endpoint.subscribeAcknowledge(subscribe.messageId(), reasonCodes, MqttProperties.NO_PROPERTIES); - }); - } - - /** - * 处理客户端取消订阅 (UNSUBSCRIBE) - */ - private void handleUnsubscribe(MqttEndpoint endpoint) { - endpoint.unsubscribeHandler((MqttUnsubscribeMessage unsubscribe) -> { - for (String topic : unsubscribe.topics()) { - log.info("Unsubscription for {}", topic); - } - // 回复 UNSUBACK,MQTT 5.0 时可指定 reasonCodes、properties - endpoint.unsubscribeAcknowledge(unsubscribe.messageId()); - }); - } - - /** - * 处理客户端发布的消息 (PUBLISH) - */ - private void handlePublish(MqttEndpoint endpoint) { - // 接收 PUBLISH 消息 - endpoint.publishHandler((MqttPublishMessage message) -> { - String payload = message.payload().toString(Charset.defaultCharset()); - log.info("Received message [{}] on topic [{}] with QoS [{}]", - payload, message.topicName(), message.qosLevel()); - - // 根据不同 QoS,回复客户端 - if (message.qosLevel() == MqttQoS.AT_LEAST_ONCE) { - endpoint.publishAcknowledge(message.messageId()); - } else if (message.qosLevel() == MqttQoS.EXACTLY_ONCE) { - endpoint.publishReceived(message.messageId()); - } - }); - - // 如果 QoS = 2,需要处理 PUBREL - endpoint.publishReleaseHandler(messageId -> { - endpoint.publishComplete(messageId); - }); - } - - /** - * 处理客户端 PINGREQ - */ - private void handlePing(MqttEndpoint endpoint) { - endpoint.pingHandler(v -> { - // 这里仅做日志, PINGRESP 已自动发送 - log.info("Ping received from client [{}]", endpoint.clientIdentifier()); - }); - } - - // ==================== 如果需要服务端向客户端发布消息,可用以下示例 ==================== - - /** - * 服务端主动向已连接的某个 endpoint 发布消息的示例 - * 如果使用 MQTT 5.0,可以传递更多消息属性 - */ - public void publishToClient(MqttEndpoint endpoint, String topic, String content) { - endpoint.publish(topic, - Buffer.buffer(content), - MqttQoS.AT_LEAST_ONCE, // QoS 自行选择 - false, - false); - - // 处理 QoS 1 和 QoS 2 的 ACK - endpoint.publishAcknowledgeHandler(messageId -> { - log.info("Received PUBACK from client [{}] for messageId = {}", endpoint.clientIdentifier(), messageId); - }).publishReceivedHandler(messageId -> { - endpoint.publishRelease(messageId); - }).publishCompletionHandler(messageId -> { - log.info("Received PUBCOMP from client [{}] for messageId = {}", endpoint.clientIdentifier(), messageId); - }); - } - - // ==================== 如果需要多实例部署,用于多核扩展,可参考以下思路 ==================== - // 例如,在宿主应用或插件中循环启动多个 MqttServerExtension 实例,或使用 Vert.x 的 deployVerticle: - // DeploymentOptions options = new DeploymentOptions().setInstances(10); - // vertx.deployVerticle(() -> new MyMqttVerticle(), options); - -} diff --git a/cc-admin-master/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java b/cc-admin-master/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java index 60a9e99..3f314d2 100644 --- a/cc-admin-master/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java +++ b/cc-admin-master/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java @@ -270,10 +270,6 @@ public class AdminAuthServiceImpl implements AdminAuthService { // 2. 校验用户名是否已存在 Long userId = userService.registerUser(registerReqVO); - // 分配角色 - if (1 == registerReqVO.getType()){ - permissionService.assignUserRole(userId, singleton(164L)); - } // 3. 创建 Token 令牌,记录登录日志 return createTokenAfterLoginSuccess(userId, registerReqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME); diff --git a/cc-admin-master/yudao-server/pom.xml b/cc-admin-master/yudao-server/pom.xml index a8cf05e..1bf2069 100644 --- a/cc-admin-master/yudao-server/pom.xml +++ b/cc-admin-master/yudao-server/pom.xml @@ -50,6 +50,12 @@ yudao-module-bpm ${revision} + + + cn.iocoder.boot + yudao-module-hand-mqtt + ${revision} +