mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 12:18:42 +08:00 
			
		
		
		
	【代码评审】IoT:产品、设备、物模型的代码
This commit is contained in:
		@@ -7,7 +7,7 @@ import lombok.Getter;
 | 
				
			|||||||
import java.util.Arrays;
 | 
					import java.util.Arrays;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * IOT 产品功能类型枚举类
 | 
					 * IOT 产品功能(物模型)类型枚举类
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author ahh
 | 
					 * @author ahh
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
@@ -15,17 +15,8 @@ import java.util.Arrays;
 | 
				
			|||||||
@Getter
 | 
					@Getter
 | 
				
			||||||
public enum IotProductFunctionTypeEnum implements IntArrayValuable {
 | 
					public enum IotProductFunctionTypeEnum implements IntArrayValuable {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * 属性
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    PROPERTY(1, "属性"),
 | 
					    PROPERTY(1, "属性"),
 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * 服务
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    SERVICE(2, "服务"),
 | 
					    SERVICE(2, "服务"),
 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * 事件
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    EVENT(3, "事件");
 | 
					    EVENT(3, "事件");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProductFunctionTypeEnum::getType).toArray();
 | 
					    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProductFunctionTypeEnum::getType).toArray();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -83,7 +83,7 @@ public class IotDeviceController {
 | 
				
			|||||||
    @Parameter(name = "productId", description = "产品编号", example = "1")
 | 
					    @Parameter(name = "productId", description = "产品编号", example = "1")
 | 
				
			||||||
    @PreAuthorize("@ss.hasPermission('iot:device:query')")
 | 
					    @PreAuthorize("@ss.hasPermission('iot:device:query')")
 | 
				
			||||||
    public CommonResult<Long> getDeviceCount(@RequestParam("productId") Long productId) {
 | 
					    public CommonResult<Long> getDeviceCount(@RequestParam("productId") Long productId) {
 | 
				
			||||||
        return success(deviceService.getDeviceCount(productId));
 | 
					        return success(deviceService.getDeviceCountByProductId(productId));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -83,11 +83,12 @@ public class IotProductController {
 | 
				
			|||||||
        return success(BeanUtils.toBean(pageResult, IotProductRespVO.class));
 | 
					        return success(BeanUtils.toBean(pageResult, IotProductRespVO.class));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // TODO @haohao:改成 simple-list 哈
 | 
				
			||||||
    @GetMapping("/list-all-simple")
 | 
					    @GetMapping("/list-all-simple")
 | 
				
			||||||
    @Operation(summary = "获得所有产品列表")
 | 
					    @Operation(summary = "获得所有产品列表")
 | 
				
			||||||
    @PreAuthorize("@ss.hasPermission('iot:product:query')")
 | 
					    @PreAuthorize("@ss.hasPermission('iot:product:query')")
 | 
				
			||||||
    public CommonResult<List<IotProductSimpleRespVO>> listAllSimpleProducts() {
 | 
					    public CommonResult<List<IotProductSimpleRespVO>> listAllSimpleProducts() {
 | 
				
			||||||
        List<IotProductDO> list = productService.listAllProducts();
 | 
					        List<IotProductDO> list = productService.getProductList();
 | 
				
			||||||
        return success(BeanUtils.toBean(list, IotProductSimpleRespVO.class));
 | 
					        return success(BeanUtils.toBean(list, IotProductSimpleRespVO.class));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,14 +32,14 @@ public class IotThinkModelFunctionController {
 | 
				
			|||||||
    private IotThinkModelFunctionService thinkModelFunctionService;
 | 
					    private IotThinkModelFunctionService thinkModelFunctionService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @PostMapping("/create")
 | 
					    @PostMapping("/create")
 | 
				
			||||||
    @Operation(summary = "创建IoT 产品物模型")
 | 
					    @Operation(summary = "创建产品物模型")
 | 
				
			||||||
    @PreAuthorize("@ss.hasPermission('iot:think-model-function:create')")
 | 
					    @PreAuthorize("@ss.hasPermission('iot:think-model-function:create')")
 | 
				
			||||||
    public CommonResult<Long> createThinkModelFunction(@Valid @RequestBody IotThinkModelFunctionSaveReqVO createReqVO) {
 | 
					    public CommonResult<Long> createThinkModelFunction(@Valid @RequestBody IotThinkModelFunctionSaveReqVO createReqVO) {
 | 
				
			||||||
        return success(thinkModelFunctionService.createThinkModelFunction(createReqVO));
 | 
					        return success(thinkModelFunctionService.createThinkModelFunction(createReqVO));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @PutMapping("/update")
 | 
					    @PutMapping("/update")
 | 
				
			||||||
    @Operation(summary = "更新IoT 产品物模型")
 | 
					    @Operation(summary = "更新产品物模型")
 | 
				
			||||||
    @PreAuthorize("@ss.hasPermission('iot:think-model-function:update')")
 | 
					    @PreAuthorize("@ss.hasPermission('iot:think-model-function:update')")
 | 
				
			||||||
    public CommonResult<Boolean> updateThinkModelFunction(@Valid @RequestBody IotThinkModelFunctionSaveReqVO updateReqVO) {
 | 
					    public CommonResult<Boolean> updateThinkModelFunction(@Valid @RequestBody IotThinkModelFunctionSaveReqVO updateReqVO) {
 | 
				
			||||||
        thinkModelFunctionService.updateThinkModelFunction(updateReqVO);
 | 
					        thinkModelFunctionService.updateThinkModelFunction(updateReqVO);
 | 
				
			||||||
@@ -47,7 +47,7 @@ public class IotThinkModelFunctionController {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @DeleteMapping("/delete")
 | 
					    @DeleteMapping("/delete")
 | 
				
			||||||
    @Operation(summary = "删除IoT 产品物模型")
 | 
					    @Operation(summary = "删除产品物模型")
 | 
				
			||||||
    @Parameter(name = "id", description = "编号", required = true)
 | 
					    @Parameter(name = "id", description = "编号", required = true)
 | 
				
			||||||
    @PreAuthorize("@ss.hasPermission('iot:think-model-function:delete')")
 | 
					    @PreAuthorize("@ss.hasPermission('iot:think-model-function:delete')")
 | 
				
			||||||
    public CommonResult<Boolean> deleteThinkModelFunction(@RequestParam("id") Long id) {
 | 
					    public CommonResult<Boolean> deleteThinkModelFunction(@RequestParam("id") Long id) {
 | 
				
			||||||
@@ -56,30 +56,29 @@ public class IotThinkModelFunctionController {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @GetMapping("/get")
 | 
					    @GetMapping("/get")
 | 
				
			||||||
    @Operation(summary = "获得IoT 产品物模型")
 | 
					    @Operation(summary = "获得产品物模型")
 | 
				
			||||||
    @Parameter(name = "id", description = "编号", required = true)
 | 
					    @Parameter(name = "id", description = "编号", required = true)
 | 
				
			||||||
    @PreAuthorize("@ss.hasPermission('iot:think-model-function:query')")
 | 
					    @PreAuthorize("@ss.hasPermission('iot:think-model-function:query')")
 | 
				
			||||||
    public CommonResult<IotThinkModelFunctionRespVO> getThinkModelFunction(@RequestParam("id") Long id) {
 | 
					    public CommonResult<IotThinkModelFunctionRespVO> getThinkModelFunction(@RequestParam("id") Long id) {
 | 
				
			||||||
        IotThinkModelFunctionDO thinkModelFunction = thinkModelFunctionService.getThinkModelFunction(id);
 | 
					        IotThinkModelFunctionDO function = thinkModelFunctionService.getThinkModelFunction(id);
 | 
				
			||||||
        IotThinkModelFunctionRespVO respVO = IotThinkModelFunctionConvert.INSTANCE.convert(thinkModelFunction);
 | 
					        return success(IotThinkModelFunctionConvert.INSTANCE.convert(function));
 | 
				
			||||||
        return success(respVO);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @GetMapping("/list-by-product-id")
 | 
					    @GetMapping("/list-by-product-id")
 | 
				
			||||||
    @Operation(summary = "获得IoT 产品物模型")
 | 
					    @Operation(summary = "获得产品物模型")
 | 
				
			||||||
    @Parameter(name = "productId", description = "产品ID", required = true, example = "1024")
 | 
					    @Parameter(name = "productId", description = "产品ID", required = true, example = "1024")
 | 
				
			||||||
    @PreAuthorize("@ss.hasPermission('iot:think-model-function:query')")
 | 
					    @PreAuthorize("@ss.hasPermission('iot:think-model-function:query')")
 | 
				
			||||||
    public CommonResult<List<IotThinkModelFunctionRespVO>> getThinkModelFunctionListByProductId(@RequestParam("productId") Long productId) {
 | 
					    public CommonResult<List<IotThinkModelFunctionRespVO>> getThinkModelFunctionListByProductId(@RequestParam("productId") Long productId) {
 | 
				
			||||||
        List<IotThinkModelFunctionDO> thinkModelFunctionListByProductId = thinkModelFunctionService.getThinkModelFunctionListByProductId(productId);
 | 
					        List<IotThinkModelFunctionDO> list = thinkModelFunctionService.getThinkModelFunctionListByProductId(productId);
 | 
				
			||||||
        List<IotThinkModelFunctionRespVO> respVO = IotThinkModelFunctionConvert.INSTANCE.convertList(thinkModelFunctionListByProductId);
 | 
					        return success(IotThinkModelFunctionConvert.INSTANCE.convertList(list));
 | 
				
			||||||
        return success(respVO);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @GetMapping("/page")
 | 
					    @GetMapping("/page")
 | 
				
			||||||
    @Operation(summary = "获得IoT 产品物模型分页")
 | 
					    @Operation(summary = "获得产品物模型分页")
 | 
				
			||||||
    @PreAuthorize("@ss.hasPermission('iot:think-model-function:query')")
 | 
					    @PreAuthorize("@ss.hasPermission('iot:think-model-function:query')")
 | 
				
			||||||
    public CommonResult<PageResult<IotThinkModelFunctionRespVO>> getThinkModelFunctionPage(@Valid IotThinkModelFunctionPageReqVO pageReqVO) {
 | 
					    public CommonResult<PageResult<IotThinkModelFunctionRespVO>> getThinkModelFunctionPage(@Valid IotThinkModelFunctionPageReqVO pageReqVO) {
 | 
				
			||||||
        PageResult<IotThinkModelFunctionDO> pageResult = thinkModelFunctionService.getThinkModelFunctionPage(pageReqVO);
 | 
					        PageResult<IotThinkModelFunctionDO> pageResult = thinkModelFunctionService.getThinkModelFunctionPage(pageReqVO);
 | 
				
			||||||
        return success(BeanUtils.toBean(pageResult, IotThinkModelFunctionRespVO.class));
 | 
					        return success(BeanUtils.toBean(pageResult, IotThinkModelFunctionRespVO.class));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,7 +27,6 @@ public interface IotThinkModelFunctionMapper extends BaseMapperX<IotThinkModelFu
 | 
				
			|||||||
                .orderByDesc(IotThinkModelFunctionDO::getId));
 | 
					                .orderByDesc(IotThinkModelFunctionDO::getId));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    default IotThinkModelFunctionDO selectByProductIdAndIdentifier(Long productId, String identifier) {
 | 
					    default IotThinkModelFunctionDO selectByProductIdAndIdentifier(Long productId, String identifier) {
 | 
				
			||||||
        return selectOne(IotThinkModelFunctionDO::getProductId, productId,
 | 
					        return selectOne(IotThinkModelFunctionDO::getProductId, productId,
 | 
				
			||||||
                IotThinkModelFunctionDO::getIdentifier, identifier);
 | 
					                IotThinkModelFunctionDO::getIdentifier, identifier);
 | 
				
			||||||
@@ -55,4 +54,5 @@ public interface IotThinkModelFunctionMapper extends BaseMapperX<IotThinkModelFu
 | 
				
			|||||||
        return selectOne(IotThinkModelFunctionDO::getProductId, productId,
 | 
					        return selectOne(IotThinkModelFunctionDO::getProductId, productId,
 | 
				
			||||||
                IotThinkModelFunctionDO::getName, name);
 | 
					                IotThinkModelFunctionDO::getName, name);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -158,17 +158,12 @@ public class DeviceServiceImpl implements IotDeviceService {
 | 
				
			|||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    @Transactional(rollbackFor = Exception.class)
 | 
					    @Transactional(rollbackFor = Exception.class)
 | 
				
			||||||
    public void updateDevice(IotDeviceSaveReqVO updateReqVO) {
 | 
					    public void updateDevice(IotDeviceSaveReqVO updateReqVO) {
 | 
				
			||||||
        // 校验存在
 | 
					        // 1. 校验存在
 | 
				
			||||||
        validateDeviceExists(updateReqVO.getId());
 | 
					        validateDeviceExists(updateReqVO.getId());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // 设备名称 和 产品 ID 不能修改
 | 
					        // 2. 更新到数据库
 | 
				
			||||||
        updateReqVO.setDeviceName(null);
 | 
					        IotDeviceDO updateObj = BeanUtils.toBean(updateReqVO, IotDeviceDO.class)
 | 
				
			||||||
        updateReqVO.setProductId(null);
 | 
					                .setDeviceName(null).setProductId(null); // 设备名称 和 产品 ID 不能修改
 | 
				
			||||||
 | 
					 | 
				
			||||||
        // 更新 DO 对象
 | 
					 | 
				
			||||||
        IotDeviceDO updateObj = BeanUtils.toBean(updateReqVO, IotDeviceDO.class);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // 更新到数据库
 | 
					 | 
				
			||||||
        deviceMapper.updateById(updateObj);
 | 
					        deviceMapper.updateById(updateObj);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -225,7 +220,7 @@ public class DeviceServiceImpl implements IotDeviceService {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public Long getDeviceCount(Long productId) {
 | 
					    public Long getDeviceCountByProductId(Long productId) {
 | 
				
			||||||
        return deviceMapper.selectCountByProductId(productId);
 | 
					        return deviceMapper.selectCountByProductId(productId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -63,5 +63,5 @@ public interface IotDeviceService {
 | 
				
			|||||||
     * @param productId 产品编号
 | 
					     * @param productId 产品编号
 | 
				
			||||||
     * @return 设备数量
 | 
					     * @return 设备数量
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    Long getDeviceCount(Long productId);
 | 
					    Long getDeviceCountByProductId(Long productId);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -66,6 +66,6 @@ public interface IotProductService {
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return 产品列表
 | 
					     * @return 产品列表
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    List<IotProductDO> listAllProducts();
 | 
					    List<IotProductDO> getProductList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -115,7 +115,7 @@ public class IotProductServiceImpl implements IotProductService {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public List<IotProductDO> listAllProducts() {
 | 
					    public List<IotProductDO> getProductList() {
 | 
				
			||||||
        return productMapper.selectList();
 | 
					        return productMapper.selectList();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,4 +61,5 @@ public interface IotThinkModelFunctionService {
 | 
				
			|||||||
     * @return 产品物模型分页
 | 
					     * @return 产品物模型分页
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    PageResult<IotThinkModelFunctionDO> getThinkModelFunctionPage(IotThinkModelFunctionPageReqVO pageReqVO);
 | 
					    PageResult<IotThinkModelFunctionDO> getThinkModelFunctionPage(IotThinkModelFunctionPageReqVO pageReqVO);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user