Commit 6a35ca729006c8c4be8001d60376cb989be9fa2c
1 parent
5a456a95
【代码评审】IoT:产品、设备、物模型的代码
Showing
10 changed files
with
25 additions
and
38 deletions
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductFunctionTypeEnum.java
| ... | ... | @@ -7,7 +7,7 @@ import lombok.Getter; |
| 7 | 7 | import java.util.Arrays; |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | - * IOT 产品功能类型枚举类 | |
| 10 | + * IOT 产品功能(物模型)类型枚举类 | |
| 11 | 11 | * |
| 12 | 12 | * @author ahh |
| 13 | 13 | */ |
| ... | ... | @@ -15,17 +15,8 @@ import java.util.Arrays; |
| 15 | 15 | @Getter |
| 16 | 16 | public enum IotProductFunctionTypeEnum implements IntArrayValuable { |
| 17 | 17 | |
| 18 | - /** | |
| 19 | - * 属性 | |
| 20 | - */ | |
| 21 | 18 | PROPERTY(1, "属性"), |
| 22 | - /** | |
| 23 | - * 服务 | |
| 24 | - */ | |
| 25 | 19 | SERVICE(2, "服务"), |
| 26 | - /** | |
| 27 | - * 事件 | |
| 28 | - */ | |
| 29 | 20 | EVENT(3, "事件"); |
| 30 | 21 | |
| 31 | 22 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProductFunctionTypeEnum::getType).toArray(); | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java
| ... | ... | @@ -83,7 +83,7 @@ public class IotDeviceController { |
| 83 | 83 | @Parameter(name = "productId", description = "产品编号", example = "1") |
| 84 | 84 | @PreAuthorize("@ss.hasPermission('iot:device:query')") |
| 85 | 85 | public CommonResult<Long> getDeviceCount(@RequestParam("productId") Long productId) { |
| 86 | - return success(deviceService.getDeviceCount(productId)); | |
| 86 | + return success(deviceService.getDeviceCountByProductId(productId)); | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | } |
| 90 | 90 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductController.java
| ... | ... | @@ -83,11 +83,12 @@ public class IotProductController { |
| 83 | 83 | return success(BeanUtils.toBean(pageResult, IotProductRespVO.class)); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | + // TODO @haohao:改成 simple-list 哈 | |
| 86 | 87 | @GetMapping("/list-all-simple") |
| 87 | 88 | @Operation(summary = "获得所有产品列表") |
| 88 | 89 | @PreAuthorize("@ss.hasPermission('iot:product:query')") |
| 89 | 90 | public CommonResult<List<IotProductSimpleRespVO>> listAllSimpleProducts() { |
| 90 | - List<IotProductDO> list = productService.listAllProducts(); | |
| 91 | + List<IotProductDO> list = productService.getProductList(); | |
| 91 | 92 | return success(BeanUtils.toBean(list, IotProductSimpleRespVO.class)); |
| 92 | 93 | } |
| 93 | 94 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thinkmodelfunction/IotThinkModelFunctionController.java
| ... | ... | @@ -32,14 +32,14 @@ public class IotThinkModelFunctionController { |
| 32 | 32 | private IotThinkModelFunctionService thinkModelFunctionService; |
| 33 | 33 | |
| 34 | 34 | @PostMapping("/create") |
| 35 | - @Operation(summary = "创建IoT 产品物模型") | |
| 35 | + @Operation(summary = "创建产品物模型") | |
| 36 | 36 | @PreAuthorize("@ss.hasPermission('iot:think-model-function:create')") |
| 37 | 37 | public CommonResult<Long> createThinkModelFunction(@Valid @RequestBody IotThinkModelFunctionSaveReqVO createReqVO) { |
| 38 | 38 | return success(thinkModelFunctionService.createThinkModelFunction(createReqVO)); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | @PutMapping("/update") |
| 42 | - @Operation(summary = "更新IoT 产品物模型") | |
| 42 | + @Operation(summary = "更新产品物模型") | |
| 43 | 43 | @PreAuthorize("@ss.hasPermission('iot:think-model-function:update')") |
| 44 | 44 | public CommonResult<Boolean> updateThinkModelFunction(@Valid @RequestBody IotThinkModelFunctionSaveReqVO updateReqVO) { |
| 45 | 45 | thinkModelFunctionService.updateThinkModelFunction(updateReqVO); |
| ... | ... | @@ -47,7 +47,7 @@ public class IotThinkModelFunctionController { |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | @DeleteMapping("/delete") |
| 50 | - @Operation(summary = "删除IoT 产品物模型") | |
| 50 | + @Operation(summary = "删除产品物模型") | |
| 51 | 51 | @Parameter(name = "id", description = "编号", required = true) |
| 52 | 52 | @PreAuthorize("@ss.hasPermission('iot:think-model-function:delete')") |
| 53 | 53 | public CommonResult<Boolean> deleteThinkModelFunction(@RequestParam("id") Long id) { |
| ... | ... | @@ -56,30 +56,29 @@ public class IotThinkModelFunctionController { |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | @GetMapping("/get") |
| 59 | - @Operation(summary = "获得IoT 产品物模型") | |
| 59 | + @Operation(summary = "获得产品物模型") | |
| 60 | 60 | @Parameter(name = "id", description = "编号", required = true) |
| 61 | 61 | @PreAuthorize("@ss.hasPermission('iot:think-model-function:query')") |
| 62 | 62 | public CommonResult<IotThinkModelFunctionRespVO> getThinkModelFunction(@RequestParam("id") Long id) { |
| 63 | - IotThinkModelFunctionDO thinkModelFunction = thinkModelFunctionService.getThinkModelFunction(id); | |
| 64 | - IotThinkModelFunctionRespVO respVO = IotThinkModelFunctionConvert.INSTANCE.convert(thinkModelFunction); | |
| 65 | - return success(respVO); | |
| 63 | + IotThinkModelFunctionDO function = thinkModelFunctionService.getThinkModelFunction(id); | |
| 64 | + return success(IotThinkModelFunctionConvert.INSTANCE.convert(function)); | |
| 66 | 65 | } |
| 67 | 66 | |
| 68 | 67 | @GetMapping("/list-by-product-id") |
| 69 | - @Operation(summary = "获得IoT 产品物模型") | |
| 68 | + @Operation(summary = "获得产品物模型") | |
| 70 | 69 | @Parameter(name = "productId", description = "产品ID", required = true, example = "1024") |
| 71 | 70 | @PreAuthorize("@ss.hasPermission('iot:think-model-function:query')") |
| 72 | 71 | public CommonResult<List<IotThinkModelFunctionRespVO>> getThinkModelFunctionListByProductId(@RequestParam("productId") Long productId) { |
| 73 | - List<IotThinkModelFunctionDO> thinkModelFunctionListByProductId = thinkModelFunctionService.getThinkModelFunctionListByProductId(productId); | |
| 74 | - List<IotThinkModelFunctionRespVO> respVO = IotThinkModelFunctionConvert.INSTANCE.convertList(thinkModelFunctionListByProductId); | |
| 75 | - return success(respVO); | |
| 72 | + List<IotThinkModelFunctionDO> list = thinkModelFunctionService.getThinkModelFunctionListByProductId(productId); | |
| 73 | + return success(IotThinkModelFunctionConvert.INSTANCE.convertList(list)); | |
| 76 | 74 | } |
| 77 | 75 | |
| 78 | 76 | @GetMapping("/page") |
| 79 | - @Operation(summary = "获得IoT 产品物模型分页") | |
| 77 | + @Operation(summary = "获得产品物模型分页") | |
| 80 | 78 | @PreAuthorize("@ss.hasPermission('iot:think-model-function:query')") |
| 81 | 79 | public CommonResult<PageResult<IotThinkModelFunctionRespVO>> getThinkModelFunctionPage(@Valid IotThinkModelFunctionPageReqVO pageReqVO) { |
| 82 | 80 | PageResult<IotThinkModelFunctionDO> pageResult = thinkModelFunctionService.getThinkModelFunctionPage(pageReqVO); |
| 83 | 81 | return success(BeanUtils.toBean(pageResult, IotThinkModelFunctionRespVO.class)); |
| 84 | 82 | } |
| 83 | + | |
| 85 | 84 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/thinkmodelfunction/IotThinkModelFunctionMapper.java
| ... | ... | @@ -27,7 +27,6 @@ public interface IotThinkModelFunctionMapper extends BaseMapperX<IotThinkModelFu |
| 27 | 27 | .orderByDesc(IotThinkModelFunctionDO::getId)); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - | |
| 31 | 30 | default IotThinkModelFunctionDO selectByProductIdAndIdentifier(Long productId, String identifier) { |
| 32 | 31 | return selectOne(IotThinkModelFunctionDO::getProductId, productId, |
| 33 | 32 | IotThinkModelFunctionDO::getIdentifier, identifier); |
| ... | ... | @@ -55,4 +54,5 @@ public interface IotThinkModelFunctionMapper extends BaseMapperX<IotThinkModelFu |
| 55 | 54 | return selectOne(IotThinkModelFunctionDO::getProductId, productId, |
| 56 | 55 | IotThinkModelFunctionDO::getName, name); |
| 57 | 56 | } |
| 57 | + | |
| 58 | 58 | } |
| 59 | 59 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/DeviceServiceImpl.java
| ... | ... | @@ -158,17 +158,12 @@ public class DeviceServiceImpl implements IotDeviceService { |
| 158 | 158 | @Override |
| 159 | 159 | @Transactional(rollbackFor = Exception.class) |
| 160 | 160 | public void updateDevice(IotDeviceSaveReqVO updateReqVO) { |
| 161 | - // 校验存在 | |
| 161 | + // 1. 校验存在 | |
| 162 | 162 | validateDeviceExists(updateReqVO.getId()); |
| 163 | 163 | |
| 164 | - // 设备名称 和 产品 ID 不能修改 | |
| 165 | - updateReqVO.setDeviceName(null); | |
| 166 | - updateReqVO.setProductId(null); | |
| 167 | - | |
| 168 | - // 更新 DO 对象 | |
| 169 | - IotDeviceDO updateObj = BeanUtils.toBean(updateReqVO, IotDeviceDO.class); | |
| 170 | - | |
| 171 | - // 更新到数据库 | |
| 164 | + // 2. 更新到数据库 | |
| 165 | + IotDeviceDO updateObj = BeanUtils.toBean(updateReqVO, IotDeviceDO.class) | |
| 166 | + .setDeviceName(null).setProductId(null); // 设备名称 和 产品 ID 不能修改 | |
| 172 | 167 | deviceMapper.updateById(updateObj); |
| 173 | 168 | } |
| 174 | 169 | |
| ... | ... | @@ -225,7 +220,7 @@ public class DeviceServiceImpl implements IotDeviceService { |
| 225 | 220 | } |
| 226 | 221 | |
| 227 | 222 | @Override |
| 228 | - public Long getDeviceCount(Long productId) { | |
| 223 | + public Long getDeviceCountByProductId(Long productId) { | |
| 229 | 224 | return deviceMapper.selectCountByProductId(productId); |
| 230 | 225 | } |
| 231 | 226 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductService.java
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java
| ... | ... | @@ -115,7 +115,7 @@ public class IotProductServiceImpl implements IotProductService { |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | @Override |
| 118 | - public List<IotProductDO> listAllProducts() { | |
| 118 | + public List<IotProductDO> getProductList() { | |
| 119 | 119 | return productMapper.selectList(); |
| 120 | 120 | } |
| 121 | 121 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodelfunction/IotThinkModelFunctionService.java