Commit 39ba4e72da281a90715baab359a8995627747f7a
1 parent
b02e396a
【功能新增】IoT:设备管理界面增加设备分组功能
Showing
4 changed files
with
66 additions
and
14 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java
| ... | ... | @@ -6,10 +6,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 8 | 8 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 9 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDevicePageReqVO; | |
| 10 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceRespVO; | |
| 11 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceSaveReqVO; | |
| 12 | -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceStatusUpdateReqVO; | |
| 9 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.*; | |
| 13 | 10 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 14 | 11 | import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; |
| 15 | 12 | import io.swagger.v3.oas.annotations.Operation; |
| ... | ... | @@ -62,6 +59,14 @@ public class IotDeviceController { |
| 62 | 59 | return success(true); |
| 63 | 60 | } |
| 64 | 61 | |
| 62 | + @PutMapping("/update-group") | |
| 63 | + @Operation(summary = "更新设备分组") | |
| 64 | + @PreAuthorize("@ss.hasPermission('iot:device:update')") | |
| 65 | + public CommonResult<Boolean> updateDeviceGroup(@Valid @RequestBody IotDeviceUpdateGroupReqVO updateReqVO) { | |
| 66 | + deviceService.updateDeviceGroup(updateReqVO); | |
| 67 | + return success(true); | |
| 68 | + } | |
| 69 | + | |
| 65 | 70 | @DeleteMapping("/delete") |
| 66 | 71 | @Operation(summary = "删除单个设备") |
| 67 | 72 | @Parameter(name = "id", description = "编号", required = true) |
| ... | ... | @@ -102,7 +107,7 @@ public class IotDeviceController { |
| 102 | 107 | @PreAuthorize("@ss.hasPermission('iot:device:export')") |
| 103 | 108 | @ApiAccessLog(operateType = EXPORT) |
| 104 | 109 | public void exportDeviceExcel(@Valid IotDevicePageReqVO exportReqVO, |
| 105 | - HttpServletResponse response) throws IOException { | |
| 110 | + HttpServletResponse response) throws IOException { | |
| 106 | 111 | exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| 107 | 112 | CommonResult<PageResult<IotDeviceRespVO>> result = getDevicePage(exportReqVO); |
| 108 | 113 | // 导出 Excel |
| ... | ... | @@ -125,7 +130,7 @@ public class IotDeviceController { |
| 125 | 130 | @RequestParam(value = "deviceType", required = false) Integer deviceType) { |
| 126 | 131 | List<IotDeviceDO> list = deviceService.getDeviceList(deviceType); |
| 127 | 132 | return success(convertList(list, device -> // 只返回 id、name 字段 |
| 128 | - new IotDeviceRespVO().setId(device.getId()).setDeviceName(device.getDeviceName()))); | |
| 133 | + new IotDeviceRespVO().setId(device.getId()).setDeviceName(device.getDeviceName()))); | |
| 129 | 134 | } |
| 130 | 135 | |
| 131 | 136 | } |
| 132 | 137 | \ 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/device/IotDeviceUpdateGroupReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.controller.admin.device.vo.device; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotEmpty; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +import java.util.Set; | |
| 8 | + | |
| 9 | +@Schema(description = "管理后台 - IoT 设备更新分组 Request VO") | |
| 10 | +@Data | |
| 11 | +public class IotDeviceUpdateGroupReqVO { | |
| 12 | + | |
| 13 | + @Schema(description = "设备编号列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3") | |
| 14 | + @NotEmpty(message = "设备编号列表不能为空") | |
| 15 | + private Set<Long> ids; | |
| 16 | + | |
| 17 | + @Schema(description = "分组编号列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3") | |
| 18 | + @NotEmpty(message = "分组编号列表不能为空") | |
| 19 | + private Set<Long> groupIds; | |
| 20 | + | |
| 21 | +} | |
| 0 | 22 | \ No newline at end of file | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java
| ... | ... | @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDevicePageReqVO; |
| 5 | 5 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceSaveReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceStatusUpdateReqVO; |
| 7 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceUpdateGroupReqVO; | |
| 7 | 8 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 8 | 9 | import jakarta.validation.Valid; |
| 9 | 10 | |
| ... | ... | @@ -34,6 +35,20 @@ public interface IotDeviceService { |
| 34 | 35 | void updateDevice(@Valid IotDeviceSaveReqVO updateReqVO); |
| 35 | 36 | |
| 36 | 37 | /** |
| 38 | + * 更新设备状态 | |
| 39 | + * | |
| 40 | + * @param updateReqVO 更新信息 | |
| 41 | + */ | |
| 42 | + void updateDeviceStatus(IotDeviceStatusUpdateReqVO updateReqVO); | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * 更新设备分组 | |
| 46 | + * | |
| 47 | + * @param updateReqVO 更新信息 | |
| 48 | + */ | |
| 49 | + void updateDeviceGroup(@Valid IotDeviceUpdateGroupReqVO updateReqVO); | |
| 50 | + | |
| 51 | + /** | |
| 37 | 52 | * 删除单个设备 |
| 38 | 53 | * |
| 39 | 54 | * @param id 编号 |
| ... | ... | @@ -72,13 +87,6 @@ public interface IotDeviceService { |
| 72 | 87 | List<IotDeviceDO> getDeviceList(@Nullable Integer deviceType); |
| 73 | 88 | |
| 74 | 89 | /** |
| 75 | - * 更新设备状态 | |
| 76 | - * | |
| 77 | - * @param updateReqVO 更新信息 | |
| 78 | - */ | |
| 79 | - void updateDeviceStatus(IotDeviceStatusUpdateReqVO updateReqVO); | |
| 80 | - | |
| 81 | - /** | |
| 82 | 90 | * 获得设备数量 |
| 83 | 91 | * |
| 84 | 92 | * @param productId 产品编号 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java
| ... | ... | @@ -9,6 +9,7 @@ import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; |
| 9 | 9 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDevicePageReqVO; |
| 10 | 10 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceSaveReqVO; |
| 11 | 11 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceStatusUpdateReqVO; |
| 12 | +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceUpdateGroupReqVO; | |
| 12 | 13 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 13 | 14 | import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; |
| 14 | 15 | import cn.iocoder.yudao.module.iot.dal.mysql.device.IotDeviceMapper; |
| ... | ... | @@ -29,6 +30,7 @@ import java.util.List; |
| 29 | 30 | import java.util.Objects; |
| 30 | 31 | |
| 31 | 32 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 33 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 32 | 34 | import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*; |
| 33 | 35 | |
| 34 | 36 | /** |
| ... | ... | @@ -67,7 +69,7 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 67 | 69 | } |
| 68 | 70 | // 1.4 校验父设备是否为合法网关 |
| 69 | 71 | if (IotProductDeviceTypeEnum.isGateway(product.getDeviceType()) |
| 70 | - && createReqVO.getGatewayId() != null) { | |
| 72 | + && createReqVO.getGatewayId() != null) { | |
| 71 | 73 | validateGatewayDeviceExists(createReqVO.getGatewayId()); |
| 72 | 74 | } |
| 73 | 75 | // 1.5 校验分组存在 |
| ... | ... | @@ -108,6 +110,22 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 108 | 110 | } |
| 109 | 111 | |
| 110 | 112 | @Override |
| 113 | + @Transactional(rollbackFor = Exception.class) | |
| 114 | + public void updateDeviceGroup(IotDeviceUpdateGroupReqVO updateReqVO) { | |
| 115 | + // 1.1 校验设备存在 | |
| 116 | + List<IotDeviceDO> devices = deviceMapper.selectBatchIds(updateReqVO.getIds()); | |
| 117 | + if (CollUtil.isEmpty(devices)) { | |
| 118 | + return; | |
| 119 | + } | |
| 120 | + // 1.2 校验分组存在 | |
| 121 | + deviceGroupService.validateDeviceGroupExists(updateReqVO.getGroupIds()); | |
| 122 | + | |
| 123 | + // 3. 更新设备分组 | |
| 124 | + deviceMapper.updateBatch(convertList(devices, device -> new IotDeviceDO() | |
| 125 | + .setId(device.getId()).setGroupIds(updateReqVO.getGroupIds()))); | |
| 126 | + } | |
| 127 | + | |
| 128 | + @Override | |
| 111 | 129 | public void deleteDevice(Long id) { |
| 112 | 130 | // 1.1 校验存在 |
| 113 | 131 | IotDeviceDO device = validateDeviceExists(id); | ... | ... |