Commit 4f59ebf4626d6e54936ad995a9d9eeb295cf009d
Merge branch 'feature/iot' of https://gitee.com/alwayssuper/ruoyi-vue-pro into origin/feature/iot
Showing
14 changed files
with
311 additions
and
19 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceDataController.java
| @@ -3,19 +3,21 @@ package cn.iocoder.yudao.module.iot.controller.admin.device; | @@ -3,19 +3,21 @@ package cn.iocoder.yudao.module.iot.controller.admin.device; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceSaveReqVO; | ||
| 6 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO; | 7 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO; |
| 7 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataRespVO; | 8 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataRespVO; |
| 9 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO; | ||
| 8 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO; | 10 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO; |
| 9 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotTimeDataRespVO; | 11 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotTimeDataRespVO; |
| 12 | +import cn.iocoder.yudao.module.iot.service.device.IotDeviceLogDataService; | ||
| 10 | import cn.iocoder.yudao.module.iot.service.device.IotDevicePropertyDataService; | 13 | import cn.iocoder.yudao.module.iot.service.device.IotDevicePropertyDataService; |
| 11 | import io.swagger.v3.oas.annotations.Operation; | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 12 | import io.swagger.v3.oas.annotations.tags.Tag; | 15 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 13 | import jakarta.annotation.Resource; | 16 | import jakarta.annotation.Resource; |
| 14 | import jakarta.validation.Valid; | 17 | import jakarta.validation.Valid; |
| 18 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 15 | import org.springframework.validation.annotation.Validated; | 19 | import org.springframework.validation.annotation.Validated; |
| 16 | -import org.springframework.web.bind.annotation.GetMapping; | ||
| 17 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 18 | -import org.springframework.web.bind.annotation.RestController; | 20 | +import org.springframework.web.bind.annotation.*; |
| 19 | 21 | ||
| 20 | import java.util.List; | 22 | import java.util.List; |
| 21 | import java.util.Map; | 23 | import java.util.Map; |
| @@ -31,6 +33,9 @@ public class IotDeviceDataController { | @@ -31,6 +33,9 @@ public class IotDeviceDataController { | ||
| 31 | @Resource | 33 | @Resource |
| 32 | private IotDevicePropertyDataService deviceDataService; | 34 | private IotDevicePropertyDataService deviceDataService; |
| 33 | 35 | ||
| 36 | + @Resource | ||
| 37 | + private IotDeviceLogDataService iotDeviceLogDataService; | ||
| 38 | + | ||
| 34 | // TODO @浩浩:这里的 /latest-list,包括方法名。 | 39 | // TODO @浩浩:这里的 /latest-list,包括方法名。 |
| 35 | @GetMapping("/latest") | 40 | @GetMapping("/latest") |
| 36 | @Operation(summary = "获取设备属性最新数据") | 41 | @Operation(summary = "获取设备属性最新数据") |
| @@ -47,4 +52,12 @@ public class IotDeviceDataController { | @@ -47,4 +52,12 @@ public class IotDeviceDataController { | ||
| 47 | return success(BeanUtils.toBean(list, IotTimeDataRespVO.class)); | 52 | return success(BeanUtils.toBean(list, IotTimeDataRespVO.class)); |
| 48 | } | 53 | } |
| 49 | 54 | ||
| 55 | + @PostMapping("/simulator") | ||
| 56 | + @Operation(summary = "模拟设备") | ||
| 57 | + public CommonResult<Boolean> simulatorDevice(@Valid @RequestBody IotDeviceDataSimulatorSaveReqVO simulatorReqVO) { | ||
| 58 | + //TODO:先生成一下日志 后续完善模拟设备代码逻辑 | ||
| 59 | + iotDeviceLogDataService.createDeviceLog(simulatorReqVO); | ||
| 60 | + return success(true); | ||
| 61 | + } | ||
| 62 | + | ||
| 50 | } | 63 | } |
| 51 | \ No newline at end of file | 64 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/deviceData/IotDeviceDataSimulatorSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import jakarta.validation.constraints.NotEmpty; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +import java.time.LocalDateTime; | ||
| 9 | + | ||
| 10 | +@Schema(description = "管理后台 - IoT 模拟设备数据 Request VO") | ||
| 11 | +@Data | ||
| 12 | +public class IotDeviceDataSimulatorSaveReqVO { | ||
| 13 | + | ||
| 14 | + @Schema(description = "消息ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "msg123") | ||
| 15 | + private String id; | ||
| 16 | + | ||
| 17 | + @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "product123") | ||
| 18 | + @NotEmpty(message = "产品ID不能为空") | ||
| 19 | + private String productKey; | ||
| 20 | + | ||
| 21 | + @Schema(description = "设备ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "device123") | ||
| 22 | + @NotEmpty(message = "设备ID不能为空") | ||
| 23 | + private String deviceKey; | ||
| 24 | + | ||
| 25 | + @Schema(description = "消息/日志类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "property") | ||
| 26 | + @NotEmpty(message = "消息类型不能为空") | ||
| 27 | + private String type; | ||
| 28 | + | ||
| 29 | + @Schema(description = "标识符", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature") | ||
| 30 | + @NotEmpty(message = "标识符不能为空") | ||
| 31 | + private String subType; | ||
| 32 | + | ||
| 33 | + @Schema(description = "数据内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "{\"value\": 25.6}") | ||
| 34 | + @NotEmpty(message = "数据内容不能为空") | ||
| 35 | + private String content; | ||
| 36 | + | ||
| 37 | + @Schema(description = "上报时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 38 | + private LocalDateTime reportTime; | ||
| 39 | + | ||
| 40 | +} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.java
| @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.iot.controller.admin.thingmodel; | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.iot.controller.admin.thingmodel; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelListReqVO; | ||
| 6 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; | 7 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; |
| 7 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelRespVO; | 8 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelRespVO; |
| 8 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; | 9 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; |
| @@ -73,6 +74,14 @@ public class IotThingModelController { | @@ -73,6 +74,14 @@ public class IotThingModelController { | ||
| 73 | return success(IotThingModelConvert.INSTANCE.convertList(list)); | 74 | return success(IotThingModelConvert.INSTANCE.convertList(list)); |
| 74 | } | 75 | } |
| 75 | 76 | ||
| 77 | + @GetMapping("/list") | ||
| 78 | + @Operation(summary = "获得产品物模型列表") | ||
| 79 | + @PreAuthorize("@ss.hasPermission('iot:thing-model:query')") | ||
| 80 | + public CommonResult<List<IotThingModelRespVO>> getThingModelListByProductId(@Valid IotThingModelListReqVO reqVO) { | ||
| 81 | + List<IotThingModelDO> list = thingModelService.getThingModelList(reqVO); | ||
| 82 | + return success(IotThingModelConvert.INSTANCE.convertList(list)); | ||
| 83 | + } | ||
| 84 | + | ||
| 76 | @GetMapping("/page") | 85 | @GetMapping("/page") |
| 77 | @Operation(summary = "获得产品物模型分页") | 86 | @Operation(summary = "获得产品物模型分页") |
| 78 | @PreAuthorize("@ss.hasPermission('iot:thing-model:query')") | 87 | @PreAuthorize("@ss.hasPermission('iot:thing-model:query')") |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelListReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 4 | +import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum; | ||
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 6 | +import jakarta.validation.constraints.NotNull; | ||
| 7 | +import lombok.Data; | ||
| 8 | + | ||
| 9 | + | ||
| 10 | + | ||
| 11 | +@Schema(description = "管理后台 - IoT 产品物模型List Request VO") | ||
| 12 | +@Data | ||
| 13 | +public class IotThingModelListReqVO { | ||
| 14 | + @Schema(description = "功能标识") | ||
| 15 | + private String identifier; | ||
| 16 | + | ||
| 17 | + @Schema(description = "功能名称", example = "张三") | ||
| 18 | + private String name; | ||
| 19 | + | ||
| 20 | + @Schema(description = "功能类型", example = "1") | ||
| 21 | + @InEnum(IotThingModelTypeEnum.class) | ||
| 22 | + private Integer type; | ||
| 23 | + | ||
| 24 | + @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 25 | + @NotNull(message = "产品ID不能为空") | ||
| 26 | + private Long productId; | ||
| 27 | +} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceLogDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.dal.dataobject.device; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.date.DateTime; | ||
| 4 | +import lombok.AllArgsConstructor; | ||
| 5 | +import lombok.Builder; | ||
| 6 | +import lombok.Data; | ||
| 7 | +import lombok.NoArgsConstructor; | ||
| 8 | + | ||
| 9 | +import java.time.LocalDateTime; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * IoT 设备日志数据 DO | ||
| 13 | + * | ||
| 14 | + * @author alwayssuper | ||
| 15 | + */ | ||
| 16 | +@Data | ||
| 17 | +@Builder | ||
| 18 | +@NoArgsConstructor | ||
| 19 | +@AllArgsConstructor | ||
| 20 | +public class IotDeviceLogDO { | ||
| 21 | + /** | ||
| 22 | + * 消息ID | ||
| 23 | + */ | ||
| 24 | + private String id; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 产品ID | ||
| 28 | + */ | ||
| 29 | + private String productKey; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 设备ID | ||
| 33 | + */ | ||
| 34 | + private String deviceKey; | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 消息/日志类型 | ||
| 38 | + */ | ||
| 39 | + private String type; | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * 标识符:用于标识具体的属性、事件或服务 | ||
| 43 | + */ | ||
| 44 | + private String subType; | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 数据内容:存储具体的消息数据内容,通常是JSON格式 | ||
| 48 | + */ | ||
| 49 | + private String content; | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * 上报时间戳 | ||
| 53 | + */ | ||
| 54 | + private DateTime reportTime; | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 时序时间 | ||
| 58 | + */ | ||
| 59 | + private DateTime ts; | ||
| 60 | + | ||
| 61 | + | ||
| 62 | +} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thingmodel/IotThingModelMapper.java
| @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.iot.dal.mysql.thingmodel; | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.iot.dal.mysql.thingmodel; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelListReqVO; | ||
| 6 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; | 7 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; |
| 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; | 8 | import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; |
| 8 | import org.apache.ibatis.annotations.Mapper; | 9 | import org.apache.ibatis.annotations.Mapper; |
| @@ -28,6 +29,17 @@ public interface IotThingModelMapper extends BaseMapperX<IotThingModelDO> { | @@ -28,6 +29,17 @@ public interface IotThingModelMapper extends BaseMapperX<IotThingModelDO> { | ||
| 28 | .orderByDesc(IotThingModelDO::getId)); | 29 | .orderByDesc(IotThingModelDO::getId)); |
| 29 | } | 30 | } |
| 30 | 31 | ||
| 32 | + default List<IotThingModelDO> selectList(IotThingModelListReqVO reqVO) { | ||
| 33 | + return selectList(new LambdaQueryWrapperX<IotThingModelDO>() | ||
| 34 | + .eqIfPresent(IotThingModelDO::getIdentifier, reqVO.getIdentifier()) | ||
| 35 | + .likeIfPresent(IotThingModelDO::getName, reqVO.getName()) | ||
| 36 | + .eqIfPresent(IotThingModelDO::getType, reqVO.getType()) | ||
| 37 | + .eqIfPresent(IotThingModelDO::getProductId, reqVO.getProductId()) | ||
| 38 | + // TODO @芋艿:看看要不要加枚举 | ||
| 39 | + .notIn(IotThingModelDO::getIdentifier, "get", "set", "post") | ||
| 40 | + .orderByDesc(IotThingModelDO::getId)); | ||
| 41 | + } | ||
| 42 | + | ||
| 31 | default IotThingModelDO selectByProductIdAndIdentifier(Long productId, String identifier) { | 43 | default IotThingModelDO selectByProductIdAndIdentifier(Long productId, String identifier) { |
| 32 | return selectOne(IotThingModelDO::getProductId, productId, | 44 | return selectOne(IotThingModelDO::getProductId, productId, |
| 33 | IotThingModelDO::getIdentifier, identifier); | 45 | IotThingModelDO::getIdentifier, identifier); |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdThingModelMessageMapper.java
| @@ -13,6 +13,7 @@ import org.apache.ibatis.annotations.Param; | @@ -13,6 +13,7 @@ import org.apache.ibatis.annotations.Param; | ||
| 13 | * 处理 TD 中物模型消息日志的操作 | 13 | * 处理 TD 中物模型消息日志的操作 |
| 14 | */ | 14 | */ |
| 15 | @Mapper | 15 | @Mapper |
| 16 | +@Deprecated | ||
| 16 | @TDengineDS | 17 | @TDengineDS |
| 17 | @InterceptorIgnore(tenantLine = "true") // 避免 SQL 解析,因为 JSqlParser 对 TDengine 的 SQL 解析会报错 | 18 | @InterceptorIgnore(tenantLine = "true") // 避免 SQL 解析,因为 JSqlParser 对 TDengine 的 SQL 解析会报错 |
| 18 | public interface TdThingModelMessageMapper { | 19 | public interface TdThingModelMessageMapper { |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/config/TDengineTableInitConfiguration.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.framework.tdengine.config; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.iot.service.device.IotDeviceLogDataService; | ||
| 4 | +import lombok.RequiredArgsConstructor; | ||
| 5 | +import lombok.extern.slf4j.Slf4j; | ||
| 6 | +import org.springframework.boot.ApplicationArguments; | ||
| 7 | +import org.springframework.boot.ApplicationRunner; | ||
| 8 | +import org.springframework.context.annotation.Configuration; | ||
| 9 | +import org.springframework.core.annotation.Order; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * TDengine 表初始化的 Configuration | ||
| 13 | + * | ||
| 14 | + * @author alwayssuper | ||
| 15 | + */ | ||
| 16 | +@Slf4j | ||
| 17 | +@RequiredArgsConstructor | ||
| 18 | +@Configuration | ||
| 19 | +@Order(Integer.MAX_VALUE) // 保证在最后执行 | ||
| 20 | +public class TDengineTableInitConfiguration implements ApplicationRunner { | ||
| 21 | + | ||
| 22 | + private final IotDeviceLogDataService deviceLogService; | ||
| 23 | + | ||
| 24 | + @Override | ||
| 25 | + public void run(ApplicationArguments args) { | ||
| 26 | + try { | ||
| 27 | + // 初始化设备日志表 | ||
| 28 | + deviceLogService.initTDengineSTable(); | ||
| 29 | + log.info("初始化 设备日志表 TDengine 表结构成功"); | ||
| 30 | + } catch (Exception ex) { | ||
| 31 | + if (ex.getMessage().contains("Table already exists")) { | ||
| 32 | + log.info("TDengine 设备日志超级表已存在,跳过创建"); | ||
| 33 | + return; | ||
| 34 | + }else{ | ||
| 35 | + log.error("初始化 设备日志表 TDengine 表结构失败", ex); | ||
| 36 | + } | ||
| 37 | + throw ex; | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | +} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.service.device; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.date.DateTime; | ||
| 4 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 5 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; | ||
| 7 | +import cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogDataMapper; | ||
| 8 | +import jakarta.annotation.Resource; | ||
| 9 | +import lombok.extern.slf4j.Slf4j; | ||
| 10 | +import org.springframework.stereotype.Service; | ||
| 11 | +import org.springframework.validation.annotation.Validated; | ||
| 12 | + | ||
| 13 | +import java.time.LocalDateTime; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * IoT 设备日志数据 Service 实现了 | ||
| 17 | + * | ||
| 18 | + * @author alwayssuper | ||
| 19 | + */ | ||
| 20 | +@Service | ||
| 21 | +@Slf4j | ||
| 22 | +public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ | ||
| 23 | + | ||
| 24 | + @Resource | ||
| 25 | + private IotDeviceLogDataMapper iotDeviceLogDataMapper; | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + public void initTDengineSTable() { | ||
| 30 | + try { | ||
| 31 | + // 创建设备日志超级表 | ||
| 32 | + iotDeviceLogDataMapper.createDeviceLogSTable(); | ||
| 33 | + log.info("创建设备日志超级表成功"); | ||
| 34 | + } catch (Exception ex) { | ||
| 35 | + throw ex; | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + @Override | ||
| 40 | + public void createDeviceLog(IotDeviceDataSimulatorSaveReqVO simulatorReqVO) { | ||
| 41 | + IotDeviceLogDO iotDeviceLogDO = BeanUtils.toBean(simulatorReqVO, IotDeviceLogDO.class); | ||
| 42 | + iotDeviceLogDO.setTs(DateTime.now()); | ||
| 43 | + iotDeviceLogDataMapper.insert(iotDeviceLogDO); | ||
| 44 | + } | ||
| 45 | +} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDevicePropertyDataServiceImpl.java
| @@ -85,8 +85,6 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe | @@ -85,8 +85,6 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe | ||
| 85 | @Resource | 85 | @Resource |
| 86 | private IotDevicePropertyDataMapper devicePropertyDataMapper; | 86 | private IotDevicePropertyDataMapper devicePropertyDataMapper; |
| 87 | 87 | ||
| 88 | - @Resource | ||
| 89 | - private TdThingModelMessageMapper tdThingModelMessageMapper; | ||
| 90 | 88 | ||
| 91 | @Override | 89 | @Override |
| 92 | public void defineDevicePropertyData(Long productId) { | 90 | public void defineDevicePropertyData(Long productId) { |
| @@ -114,8 +112,6 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe | @@ -114,8 +112,6 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe | ||
| 114 | newFields.add(0, new TDengineTableField(TDengineTableField.FIELD_TS, TDengineTableField.TYPE_TIMESTAMP)); | 112 | newFields.add(0, new TDengineTableField(TDengineTableField.FIELD_TS, TDengineTableField.TYPE_TIMESTAMP)); |
| 115 | // 2.1.1 创建产品超级表 | 113 | // 2.1.1 创建产品超级表 |
| 116 | devicePropertyDataMapper.createProductPropertySTable(product.getProductKey(), newFields); | 114 | devicePropertyDataMapper.createProductPropertySTable(product.getProductKey(), newFields); |
| 117 | - // 2.1.2 创建物模型日志超级表 | ||
| 118 | - tdThingModelMessageMapper.createSuperTable(product.getProductKey()); | ||
| 119 | return; | 115 | return; |
| 120 | } | 116 | } |
| 121 | // 2.2 情况二:如果是修改的时候,需要更新表 | 117 | // 2.2 情况二:如果是修改的时候,需要更新表 |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java
| @@ -78,8 +78,6 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ | @@ -78,8 +78,6 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ | ||
| 78 | createDeviceTable(device.getDeviceType(), device.getProductKey(), device.getDeviceName(), device.getDeviceKey()); | 78 | createDeviceTable(device.getDeviceType(), device.getProductKey(), device.getDeviceName(), device.getDeviceKey()); |
| 79 | iotDeviceService.updateDeviceStatus(new IotDeviceStatusUpdateReqVO() | 79 | iotDeviceService.updateDeviceStatus(new IotDeviceStatusUpdateReqVO() |
| 80 | .setId(device.getId()).setStatus(IotDeviceStatusEnum.ONLINE.getStatus())); | 80 | .setId(device.getId()).setStatus(IotDeviceStatusEnum.ONLINE.getStatus())); |
| 81 | - // 1.2 创建物模型日志设备表 | ||
| 82 | - tdThingModelMessageMapper.createTableWithTag(device.getProductKey(), device.getDeviceKey()); | ||
| 83 | } | 81 | } |
| 84 | 82 | ||
| 85 | // 2. 获取设备属性并进行物模型校验,过滤非物模型属性 | 83 | // 2. 获取设备属性并进行物模型校验,过滤非物模型属性 |
| @@ -231,16 +229,7 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ | @@ -231,16 +229,7 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ | ||
| 231 | .setTags(tagsFieldValues)); | 229 | .setTags(tagsFieldValues)); |
| 232 | } | 230 | } |
| 233 | 231 | ||
| 234 | - /** | ||
| 235 | - * 创建物模型日志设备数据表 | ||
| 236 | - * | ||
| 237 | - * @param productKey 产品 Key | ||
| 238 | - * @param deviceKey 设备 Key | ||
| 239 | - * | ||
| 240 | - */ | ||
| 241 | - private void createThingModelMessageDeviceTable(String productKey, String deviceKey){ | ||
| 242 | - tdThingModelMessageMapper.createTableWithTag(productKey, deviceKey); | ||
| 243 | - } | 232 | + |
| 244 | 233 | ||
| 245 | /** | 234 | /** |
| 246 | * 获取数据库名称 | 235 | * 获取数据库名称 |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelService.java
| 1 | package cn.iocoder.yudao.module.iot.service.thingmodel; | 1 | package cn.iocoder.yudao.module.iot.service.thingmodel; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelListReqVO; | ||
| 4 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; | 5 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; |
| 5 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; | 6 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; |
| 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO; |
| @@ -69,4 +70,11 @@ public interface IotThingModelService { | @@ -69,4 +70,11 @@ public interface IotThingModelService { | ||
| 69 | */ | 70 | */ |
| 70 | List<IotThingModelDO> getProductThingModelListByProductKey(String productKey); | 71 | List<IotThingModelDO> getProductThingModelListByProductKey(String productKey); |
| 71 | 72 | ||
| 73 | + /** | ||
| 74 | + * 获得产品物模型列表 | ||
| 75 | + * | ||
| 76 | + * @param reqVO 列表查询 | ||
| 77 | + * @return 产品物模型列表 | ||
| 78 | + */ | ||
| 79 | + List<IotThingModelDO> getThingModelList(IotThingModelListReqVO reqVO); | ||
| 72 | } | 80 | } |
| 73 | \ No newline at end of file | 81 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thingmodel/IotThingModelServiceImpl.java
| @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 7 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent; | 7 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelEvent; |
| 8 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelParam; | 8 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelParam; |
| 9 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService; | 9 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService; |
| 10 | +import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelListReqVO; | ||
| 10 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; | 11 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelPageReqVO; |
| 11 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; | 12 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.vo.IotThingModelSaveReqVO; |
| 12 | import cn.iocoder.yudao.module.iot.convert.thingmodel.IotThingModelConvert; | 13 | import cn.iocoder.yudao.module.iot.convert.thingmodel.IotThingModelConvert; |
| @@ -134,6 +135,11 @@ public class IotThingModelServiceImpl implements IotThingModelService { | @@ -134,6 +135,11 @@ public class IotThingModelServiceImpl implements IotThingModelService { | ||
| 134 | return thingModelMapper.selectListByProductKey(productKey); | 135 | return thingModelMapper.selectListByProductKey(productKey); |
| 135 | } | 136 | } |
| 136 | 137 | ||
| 138 | + @Override | ||
| 139 | + public List<IotThingModelDO> getThingModelList(IotThingModelListReqVO reqVO) { | ||
| 140 | + return thingModelMapper.selectList(reqVO); | ||
| 141 | + } | ||
| 142 | + | ||
| 137 | /** | 143 | /** |
| 138 | * 校验功能是否存在 | 144 | * 校验功能是否存在 |
| 139 | * | 145 | * |
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogDataMapper.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!DOCTYPE mapper | ||
| 3 | + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 4 | + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 5 | +<mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogDataMapper"> | ||
| 6 | + | ||
| 7 | + <!-- 创建设备日志超级表 初始化只创建一次--> | ||
| 8 | + <update id="createDeviceLogSTable"> | ||
| 9 | + CREATE STABLE device_log( | ||
| 10 | + ts TIMESTAMP, | ||
| 11 | + id NCHAR(50), | ||
| 12 | + product_key NCHAR(50), | ||
| 13 | + type NCHAR(50), | ||
| 14 | + subType NCHAR(50), | ||
| 15 | + content NCHAR(1024), | ||
| 16 | + report_time TIMESTAMP | ||
| 17 | + )TAGS ( | ||
| 18 | + device_key NCHAR(50) | ||
| 19 | + ) | ||
| 20 | + </update> | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + <!-- 创建设备日志子表 讨论:TDengine 在子表不存在的情况下 可在数据插入时 自动建表 要不要去掉创建子表的逻辑 由第一次插入数据时自动创建--> | ||
| 24 | + <update id="createDeviceLogTable"> | ||
| 25 | + CREATE TABLE device_log_${deviceKey} USING device_log TAGS('${deviceKey}') | ||
| 26 | + </update> | ||
| 27 | + | ||
| 28 | + <!-- 插入设备日志数据 在子表不存在的情况下 可在数据插入时 自动建表 --> | ||
| 29 | + <insert id="insert"> | ||
| 30 | + INSERT INTO device_log_${log.deviceKey} (ts, id, product_key, type, subType, content, report_time) | ||
| 31 | + USING device_log | ||
| 32 | + TAGS ('${log.deviceKey}') | ||
| 33 | + VALUES ( | ||
| 34 | + #{log.ts}, | ||
| 35 | + #{log.id}, | ||
| 36 | + #{log.productKey}, | ||
| 37 | + #{log.type}, | ||
| 38 | + #{log.subType}, | ||
| 39 | + #{log.content}, | ||
| 40 | + #{log.reportTime} | ||
| 41 | + ) | ||
| 42 | + </insert> | ||
| 43 | + | ||
| 44 | +</mapper> | ||
| 0 | \ No newline at end of file | 45 | \ No newline at end of file |