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