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