Commit e5ce1952795ab19302afbc1dca0473d0eabf630b
1 parent
ecf6a4a8
feat:【IoT 物联网】增加 OTA 相关的数据读取
Showing
15 changed files
with
167 additions
and
44 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java
| ... | ... | @@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| 11 | 11 | import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; |
| 12 | 12 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | 13 | import io.swagger.v3.oas.annotations.Parameter; |
| 14 | +import io.swagger.v3.oas.annotations.Parameters; | |
| 14 | 15 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 15 | 16 | import jakarta.annotation.Resource; |
| 16 | 17 | import jakarta.servlet.http.HttpServletResponse; |
| ... | ... | @@ -121,10 +122,14 @@ public class IotDeviceController { |
| 121 | 122 | |
| 122 | 123 | @GetMapping("/simple-list") |
| 123 | 124 | @Operation(summary = "获取设备的精简信息列表", description = "主要用于前端的下拉选项") |
| 124 | - @Parameter(name = "deviceType", description = "设备类型", example = "1") | |
| 125 | + @Parameters({ | |
| 126 | + @Parameter(name = "deviceType", description = "设备类型", example = "1"), | |
| 127 | + @Parameter(name = "productId", description = "产品编号", example = "1024") | |
| 128 | + }) | |
| 125 | 129 | public CommonResult<List<IotDeviceRespVO>> getDeviceSimpleList( |
| 126 | - @RequestParam(value = "deviceType", required = false) Integer deviceType) { | |
| 127 | - List<IotDeviceDO> list = deviceService.getDeviceListByDeviceType(deviceType); | |
| 130 | + @RequestParam(value = "deviceType", required = false) Integer deviceType, | |
| 131 | + @RequestParam(value = "productId", required = false) Long productId) { | |
| 132 | + List<IotDeviceDO> list = deviceService.getDeviceListByCondition(deviceType, productId); | |
| 128 | 133 | return success(convertList(list, device -> // 只返回 id、name、productId 字段 |
| 129 | 134 | new IotDeviceRespVO().setId(device.getId()).setDeviceName(device.getDeviceName()) |
| 130 | 135 | .setProductId(device.getProductId()))); | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaFirmwareController.java
| ... | ... | @@ -3,12 +3,14 @@ package cn.iocoder.yudao.module.iot.controller.admin.ota; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | +import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwareCreateReqVO; | |
| 6 | 7 | import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwarePageReqVO; |
| 7 | 8 | import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwareRespVO; |
| 8 | -import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwareCreateReqVO; | |
| 9 | 9 | import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwareUpdateReqVO; |
| 10 | 10 | import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; |
| 11 | +import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; | |
| 11 | 12 | import cn.iocoder.yudao.module.iot.service.ota.IotOtaFirmwareService; |
| 13 | +import cn.iocoder.yudao.module.iot.service.product.IotProductService; | |
| 12 | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | 15 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 14 | 16 | import jakarta.annotation.Resource; |
| ... | ... | @@ -27,6 +29,8 @@ public class IotOtaFirmwareController { |
| 27 | 29 | |
| 28 | 30 | @Resource |
| 29 | 31 | private IotOtaFirmwareService otaFirmwareService; |
| 32 | + @Resource | |
| 33 | + private IotProductService productService; | |
| 30 | 34 | |
| 31 | 35 | @PostMapping("/create") |
| 32 | 36 | @Operation(summary = "创建 OTA 固件") |
| ... | ... | @@ -47,8 +51,16 @@ public class IotOtaFirmwareController { |
| 47 | 51 | @Operation(summary = "获得 OTA 固件") |
| 48 | 52 | @PreAuthorize("@ss.hasPermission('iot:ota-firmware:query')") |
| 49 | 53 | public CommonResult<IotOtaFirmwareRespVO> getOtaFirmware(@RequestParam("id") Long id) { |
| 50 | - IotOtaFirmwareDO otaFirmware = otaFirmwareService.getOtaFirmware(id); | |
| 51 | - return success(BeanUtils.toBean(otaFirmware, IotOtaFirmwareRespVO.class)); | |
| 54 | + IotOtaFirmwareDO firmware = otaFirmwareService.getOtaFirmware(id); | |
| 55 | + if (firmware == null) { | |
| 56 | + return success(null); | |
| 57 | + } | |
| 58 | + return success(BeanUtils.toBean(firmware, IotOtaFirmwareRespVO.class, o -> { | |
| 59 | + IotProductDO product = productService.getProduct(firmware.getProductId()); | |
| 60 | + if (product != null) { | |
| 61 | + o.setProductName(product.getName()); | |
| 62 | + } | |
| 63 | + })); | |
| 52 | 64 | } |
| 53 | 65 | |
| 54 | 66 | @GetMapping("/page") | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaTaskRecordController.java
| ... | ... | @@ -2,10 +2,15 @@ package cn.iocoder.yudao.module.iot.controller.admin.ota; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | |
| 5 | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | 7 | import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.task.record.IotOtaTaskRecordPageReqVO; |
| 7 | 8 | import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.task.record.IotOtaTaskRecordRespVO; |
| 9 | +import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; | |
| 10 | +import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; | |
| 8 | 11 | import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaTaskRecordDO; |
| 12 | +import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; | |
| 13 | +import cn.iocoder.yudao.module.iot.service.ota.IotOtaFirmwareService; | |
| 9 | 14 | import cn.iocoder.yudao.module.iot.service.ota.IotOtaTaskRecordService; |
| 10 | 15 | import io.swagger.v3.oas.annotations.Operation; |
| 11 | 16 | import io.swagger.v3.oas.annotations.Parameter; |
| ... | ... | @@ -13,6 +18,7 @@ import io.swagger.v3.oas.annotations.Parameters; |
| 13 | 18 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 14 | 19 | import jakarta.annotation.Resource; |
| 15 | 20 | import jakarta.validation.Valid; |
| 21 | +import org.dromara.hutool.core.collection.CollUtil; | |
| 16 | 22 | import org.springframework.security.access.prepost.PreAuthorize; |
| 17 | 23 | import org.springframework.validation.annotation.Validated; |
| 18 | 24 | import org.springframework.web.bind.annotation.GetMapping; |
| ... | ... | @@ -23,6 +29,7 @@ import org.springframework.web.bind.annotation.RestController; |
| 23 | 29 | import java.util.Map; |
| 24 | 30 | |
| 25 | 31 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 32 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 26 | 33 | |
| 27 | 34 | @Tag(name = "管理后台 - IoT OTA 升级任务记录") |
| 28 | 35 | @RestController |
| ... | ... | @@ -32,18 +39,22 @@ public class IotOtaTaskRecordController { |
| 32 | 39 | |
| 33 | 40 | @Resource |
| 34 | 41 | private IotOtaTaskRecordService otaTaskRecordService; |
| 42 | + @Resource | |
| 43 | + private IotDeviceService deviceService; | |
| 44 | + @Resource | |
| 45 | + private IotOtaFirmwareService otaFirmwareService; | |
| 35 | 46 | |
| 36 | - @GetMapping("/get-status-count") | |
| 47 | + @GetMapping("/get-status-statistics") | |
| 37 | 48 | @Operation(summary = "获得 OTA 升级记录状态统计") |
| 38 | 49 | @Parameters({ |
| 39 | 50 | @Parameter(name = "firmwareId", description = "固件编号", example = "1024"), |
| 40 | 51 | @Parameter(name = "taskId", description = "升级任务编号", example = "2048") |
| 41 | 52 | }) |
| 42 | 53 | @PreAuthorize("@ss.hasPermission('iot:ota-task-record:query')") |
| 43 | - public CommonResult<Map<Integer, Long>> getOtaTaskRecordStatusCountMap( | |
| 54 | + public CommonResult<Map<Integer, Long>> getOtaTaskRecordStatusStatistics( | |
| 44 | 55 | @RequestParam(value = "firmwareId", required = false) Long firmwareId, |
| 45 | 56 | @RequestParam(value = "taskId", required = false) Long taskId) { |
| 46 | - return success(otaTaskRecordService.getOtaTaskRecordStatusCountMap(firmwareId, taskId)); | |
| 57 | + return success(otaTaskRecordService.getOtaTaskRecordStatusStatistics(firmwareId, taskId)); | |
| 47 | 58 | } |
| 48 | 59 | |
| 49 | 60 | @GetMapping("/page") |
| ... | ... | @@ -52,7 +63,22 @@ public class IotOtaTaskRecordController { |
| 52 | 63 | public CommonResult<PageResult<IotOtaTaskRecordRespVO>> getOtaTaskRecordPage( |
| 53 | 64 | @Valid IotOtaTaskRecordPageReqVO pageReqVO) { |
| 54 | 65 | PageResult<IotOtaTaskRecordDO> pageResult = otaTaskRecordService.getOtaTaskRecordPage(pageReqVO); |
| 55 | - return success(BeanUtils.toBean(pageResult, IotOtaTaskRecordRespVO.class)); | |
| 66 | + if (CollUtil.isEmpty(pageResult.getList())) { | |
| 67 | + return success(PageResult.empty()); | |
| 68 | + } | |
| 69 | + | |
| 70 | + // 批量查询固件信息 | |
| 71 | + Map<Long, IotOtaFirmwareDO> firmwareMap = otaFirmwareService.getOtaFirmwareMap( | |
| 72 | + convertSet(pageResult.getList(), IotOtaTaskRecordDO::getFromFirmwareId)); | |
| 73 | + Map<Long, IotDeviceDO> deviceMap = deviceService.getDeviceMap( | |
| 74 | + convertSet(pageResult.getList(), IotOtaTaskRecordDO::getDeviceId)); | |
| 75 | + // 转换为响应 VO | |
| 76 | + return success(BeanUtils.toBean(pageResult, IotOtaTaskRecordRespVO.class, (vo) -> { | |
| 77 | + MapUtils.findAndThen(firmwareMap, vo.getFromFirmwareId(), firmware -> | |
| 78 | + vo.setFromFirmwareVersion(firmware.getVersion())); | |
| 79 | + MapUtils.findAndThen(deviceMap, vo.getDeviceId(), device -> | |
| 80 | + vo.setDeviceName(device.getDeviceName())); | |
| 81 | + })); | |
| 56 | 82 | } |
| 57 | 83 | |
| 58 | 84 | @GetMapping("/get") | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/firmware/IotOtaFirmwareRespVO.java
| ... | ... | @@ -25,6 +25,9 @@ public class IotOtaFirmwareRespVO implements VO { |
| 25 | 25 | @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 26 | 26 | private Long productId; |
| 27 | 27 | |
| 28 | + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "智能设备") | |
| 29 | + private String productName; | |
| 30 | + | |
| 28 | 31 | @Schema(description = "固件文件 URL", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/firmware.bin") |
| 29 | 32 | private String fileUrl; |
| 30 | 33 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/task/record/IotOtaTaskRecordPageReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.controller.admin.ota.vo.task.record; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | +import cn.iocoder.yudao.module.iot.enums.ota.IotOtaTaskRecordStatusEnum; | |
| 4 | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 7 | import lombok.Data; |
| 6 | 8 | |
| ... | ... | @@ -11,7 +13,8 @@ public class IotOtaTaskRecordPageReqVO extends PageParam { |
| 11 | 13 | @Schema(description = "升级任务编号", example = "1024") |
| 12 | 14 | private Long taskId; |
| 13 | 15 | |
| 14 | - @Schema(description = "设备标识", example = "摄像头A1-1") | |
| 15 | - private String deviceName; | |
| 16 | + @Schema(description = "升级记录状态", example = "5") | |
| 17 | + @InEnum(IotOtaTaskRecordStatusEnum.class) | |
| 18 | + private Integer status; | |
| 16 | 19 | |
| 17 | 20 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/vo/task/record/IotOtaTaskRecordRespVO.java
| ... | ... | @@ -3,40 +3,46 @@ package cn.iocoder.yudao.module.iot.controller.admin.ota.vo.task.record; |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | 5 | |
| 6 | -@Schema(description = "管理后台 - IoT OTA 升级记录 Response VO") | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | + | |
| 8 | +@Schema(description = "管理后台 - IoT OTA 升级任务记录 Response VO") | |
| 7 | 9 | @Data |
| 8 | 10 | public class IotOtaTaskRecordRespVO { |
| 9 | 11 | |
| 10 | - // TODO @芋艿:梳理字段 | |
| 11 | - | |
| 12 | - @Schema(description = "升级记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 12 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 13 | 13 | private Long id; |
| 14 | 14 | |
| 15 | 15 | @Schema(description = "固件编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 16 | 16 | private Long firmwareId; |
| 17 | 17 | |
| 18 | - @Schema(description = "固件版本", requiredMode = Schema.RequiredMode.REQUIRED, example = "v1.0.0") | |
| 19 | - private String firmwareVersion; | |
| 20 | - | |
| 21 | - @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 18 | + @Schema(description = "任务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") | |
| 22 | 19 | private Long taskId; |
| 23 | 20 | |
| 24 | 21 | @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 25 | - private String deviceId; | |
| 22 | + private Long deviceId; | |
| 26 | 23 | |
| 27 | - @Schema(description = "来源的固件编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 24 | + @Schema(description = "设备名称", example = "智能开关") | |
| 25 | + private String deviceName; | |
| 26 | + | |
| 27 | + @Schema(description = "来源的固件编号", example = "1023") | |
| 28 | 28 | private Long fromFirmwareId; |
| 29 | 29 | |
| 30 | - @Schema(description = "来源的固件版本", requiredMode = Schema.RequiredMode.REQUIRED, example = "v1.0.0") | |
| 30 | + @Schema(description = "来源固件版本", example = "1.0.0") | |
| 31 | 31 | private String fromFirmwareVersion; |
| 32 | 32 | |
| 33 | - @Schema(description = "升级状态", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 33 | + @Schema(description = "升级状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 34 | 34 | private Integer status; |
| 35 | 35 | |
| 36 | - @Schema(description = "升级进度,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") | |
| 36 | + @Schema(description = "升级进度,百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "50") | |
| 37 | 37 | private Integer progress; |
| 38 | 38 | |
| 39 | - @Schema(description = "升级进度描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") | |
| 39 | + @Schema(description = "升级进度描述", example = "正在下载固件...") | |
| 40 | 40 | private String description; |
| 41 | 41 | |
| 42 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 43 | + private LocalDateTime createTime; | |
| 44 | + | |
| 45 | + @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 46 | + private LocalDateTime updateTime; | |
| 47 | + | |
| 42 | 48 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/IotDeviceMapper.java
| ... | ... | @@ -52,9 +52,11 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> { |
| 52 | 52 | return selectCount(IotDeviceDO::getProductId, productId); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - default List<IotDeviceDO> selectListByDeviceType(@Nullable Integer deviceType) { | |
| 55 | + default List<IotDeviceDO> selectListByCondition(@Nullable Integer deviceType, | |
| 56 | + @Nullable Long productId) { | |
| 56 | 57 | return selectList(new LambdaQueryWrapperX<IotDeviceDO>() |
| 57 | - .geIfPresent(IotDeviceDO::getDeviceType, deviceType)); | |
| 58 | + .eqIfPresent(IotDeviceDO::getDeviceType, deviceType) | |
| 59 | + .eqIfPresent(IotDeviceDO::getProductId, productId)); | |
| 58 | 60 | } |
| 59 | 61 | |
| 60 | 62 | default List<IotDeviceDO> selectListByState(Integer state) { | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaTaskRecordMapper.java
| ... | ... | @@ -23,7 +23,8 @@ public interface IotOtaTaskRecordMapper extends BaseMapperX<IotOtaTaskRecordDO> |
| 23 | 23 | |
| 24 | 24 | default PageResult<IotOtaTaskRecordDO> selectPage(IotOtaTaskRecordPageReqVO pageReqVO) { |
| 25 | 25 | return selectPage(pageReqVO, new LambdaQueryWrapperX<IotOtaTaskRecordDO>() |
| 26 | - .eqIfPresent(IotOtaTaskRecordDO::getTaskId, pageReqVO.getTaskId())); | |
| 26 | + .eqIfPresent(IotOtaTaskRecordDO::getTaskId, pageReqVO.getTaskId()) | |
| 27 | + .eqIfPresent(IotOtaTaskRecordDO::getStatus, pageReqVO.getStatus())); | |
| 27 | 28 | } |
| 28 | 29 | |
| 29 | 30 | default void updateByTaskIdAndStatus(Long taskId, Integer fromStatus, IotOtaTaskRecordDO updateRecord) { | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/enums/DictTypeConstants.java
| ... | ... | @@ -18,5 +18,6 @@ public class DictTypeConstants { |
| 18 | 18 | |
| 19 | 19 | public static final String OTA_TASK_DEVICE_SCOPE = "iot_ota_task_device_scope"; |
| 20 | 20 | public static final String OTA_TASK_STATUS = "iot_ota_task_status"; |
| 21 | + public static final String OTA_TASK_RECORD_STATUS = "iot_ota_task_record_status"; | |
| 21 | 22 | |
| 22 | 23 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceService.java
| ... | ... | @@ -13,6 +13,8 @@ import java.util.Collection; |
| 13 | 13 | import java.util.List; |
| 14 | 14 | import java.util.Map; |
| 15 | 15 | |
| 16 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 17 | + | |
| 16 | 18 | /** |
| 17 | 19 | * IoT 设备 Service 接口 |
| 18 | 20 | * |
| ... | ... | @@ -138,12 +140,14 @@ public interface IotDeviceService { |
| 138 | 140 | PageResult<IotDeviceDO> getDevicePage(IotDevicePageReqVO pageReqVO); |
| 139 | 141 | |
| 140 | 142 | /** |
| 141 | - * 基于设备类型,获得设备列表 | |
| 143 | + * 根据条件,获得设备列表 | |
| 142 | 144 | * |
| 143 | 145 | * @param deviceType 设备类型 |
| 146 | + * @param productId 产品编号 | |
| 144 | 147 | * @return 设备列表 |
| 145 | 148 | */ |
| 146 | - List<IotDeviceDO> getDeviceListByDeviceType(@Nullable Integer deviceType); | |
| 149 | + List<IotDeviceDO> getDeviceListByCondition(@Nullable Integer deviceType, | |
| 150 | + @Nullable Long productId); | |
| 147 | 151 | |
| 148 | 152 | /** |
| 149 | 153 | * 获得状态,获得设备列表 |
| ... | ... | @@ -241,4 +245,22 @@ public interface IotDeviceService { |
| 241 | 245 | */ |
| 242 | 246 | List<IotDeviceDO> validateDeviceListExists(Collection<Long> ids); |
| 243 | 247 | |
| 248 | + /** | |
| 249 | + * 获得设备列表 | |
| 250 | + * | |
| 251 | + * @param ids 设备编号数组 | |
| 252 | + * @return 设备列表 | |
| 253 | + */ | |
| 254 | + List<IotDeviceDO> getDeviceList(Collection<Long> ids); | |
| 255 | + | |
| 256 | + /** | |
| 257 | + * 获得设备 Map | |
| 258 | + * | |
| 259 | + * @param ids 设备编号数组 | |
| 260 | + * @return 设备 Map | |
| 261 | + */ | |
| 262 | + default Map<Long, IotDeviceDO> getDeviceMap(Collection<Long> ids) { | |
| 263 | + return convertMap(getDeviceList(ids), IotDeviceDO::getId); | |
| 264 | + } | |
| 265 | + | |
| 244 | 266 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceServiceImpl.java
| ... | ... | @@ -264,8 +264,8 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | @Override |
| 267 | - public List<IotDeviceDO> getDeviceListByDeviceType(@Nullable Integer deviceType) { | |
| 268 | - return deviceMapper.selectListByDeviceType(deviceType); | |
| 267 | + public List<IotDeviceDO> getDeviceListByCondition(@Nullable Integer deviceType, @Nullable Long productId) { | |
| 268 | + return deviceMapper.selectListByCondition(deviceType, productId); | |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | @Override |
| ... | ... | @@ -470,16 +470,21 @@ public class IotDeviceServiceImpl implements IotDeviceService { |
| 470 | 470 | |
| 471 | 471 | @Override |
| 472 | 472 | public List<IotDeviceDO> validateDeviceListExists(Collection<Long> ids) { |
| 473 | - if (CollUtil.isEmpty(ids)) { | |
| 474 | - return Collections.emptyList(); | |
| 475 | - } | |
| 476 | - List<IotDeviceDO> devices = deviceMapper.selectByIds(ids); | |
| 473 | + List<IotDeviceDO> devices = getDeviceList(ids); | |
| 477 | 474 | if (devices.size() != ids.size()) { |
| 478 | 475 | throw exception(DEVICE_NOT_EXISTS); |
| 479 | 476 | } |
| 480 | 477 | return devices; |
| 481 | 478 | } |
| 482 | 479 | |
| 480 | + @Override | |
| 481 | + public List<IotDeviceDO> getDeviceList(Collection<Long> ids) { | |
| 482 | + if (CollUtil.isEmpty(ids)) { | |
| 483 | + return Collections.emptyList(); | |
| 484 | + } | |
| 485 | + return deviceMapper.selectByIds(ids); | |
| 486 | + } | |
| 487 | + | |
| 483 | 488 | private IotDeviceServiceImpl getSelf() { |
| 484 | 489 | return SpringUtil.getBean(getClass()); |
| 485 | 490 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaFirmwareService.java
| ... | ... | @@ -7,6 +7,12 @@ import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwa |
| 7 | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; |
| 8 | 8 | import jakarta.validation.Valid; |
| 9 | 9 | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 11 | + | |
| 12 | +import java.util.Collection; | |
| 13 | +import java.util.List; | |
| 14 | +import java.util.Map; | |
| 15 | + | |
| 10 | 16 | /** |
| 11 | 17 | * OTA 固件管理 Service 接口 |
| 12 | 18 | * |
| ... | ... | @@ -30,14 +36,32 @@ public interface IotOtaFirmwareService { |
| 30 | 36 | void updateOtaFirmware(@Valid IotOtaFirmwareUpdateReqVO updateReqVO); |
| 31 | 37 | |
| 32 | 38 | /** |
| 33 | - * 根据 ID 获取 OTA 固件信息 | |
| 39 | + * 获取 OTA 固件信息 | |
| 34 | 40 | * |
| 35 | - * @param id OTA 固件编号 | |
| 41 | + * @param id 固件编号 | |
| 36 | 42 | * @return 固件信息 |
| 37 | 43 | */ |
| 38 | 44 | IotOtaFirmwareDO getOtaFirmware(Long id); |
| 39 | 45 | |
| 40 | 46 | /** |
| 47 | + * 获取 OTA 固件信息列表 | |
| 48 | + * | |
| 49 | + * @param ids 固件编号集合 | |
| 50 | + * @return 固件信息列表 | |
| 51 | + */ | |
| 52 | + List<IotOtaFirmwareDO> getOtaFirmwareList(Collection<Long> ids); | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * 获取 OTA 固件信息 Map | |
| 56 | + * | |
| 57 | + * @param ids 固件编号集合 | |
| 58 | + * @return 固件信息 Map | |
| 59 | + */ | |
| 60 | + default Map<Long, IotOtaFirmwareDO> getOtaFirmwareMap(Collection<Long> ids) { | |
| 61 | + return convertMap(getOtaFirmwareList(ids), IotOtaFirmwareDO::getId); | |
| 62 | + } | |
| 63 | + | |
| 64 | + /** | |
| 41 | 65 | * 分页查询 OTA 固件信息 |
| 42 | 66 | * |
| 43 | 67 | * @param pageReqVO 分页查询条件 |
| ... | ... | @@ -46,10 +70,10 @@ public interface IotOtaFirmwareService { |
| 46 | 70 | PageResult<IotOtaFirmwareDO> getOtaFirmwarePage(@Valid IotOtaFirmwarePageReqVO pageReqVO); |
| 47 | 71 | |
| 48 | 72 | /** |
| 49 | - * 验证物联网 OTA 固件是否存在 | |
| 73 | + * 验证 OTA 固件是否存在 | |
| 50 | 74 | * |
| 51 | - * @param id 物联网 OTA 固件编号 | |
| 52 | - * @return OTA 固件 | |
| 75 | + * @param id 固件编号 | |
| 76 | + * @return 固件信息 | |
| 53 | 77 | */ |
| 54 | 78 | IotOtaFirmwareDO validateFirmwareExists(Long id); |
| 55 | 79 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaFirmwareServiceImpl.java
| ... | ... | @@ -18,8 +18,13 @@ import org.springframework.stereotype.Service; |
| 18 | 18 | import org.springframework.validation.annotation.Validated; |
| 19 | 19 | |
| 20 | 20 | import java.io.ByteArrayInputStream; |
| 21 | +import java.util.Collection; | |
| 22 | +import java.util.Collections; | |
| 23 | +import java.util.List; | |
| 24 | +import java.util.Map; | |
| 21 | 25 | |
| 22 | 26 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 27 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 23 | 28 | import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.OTA_FIRMWARE_NOT_EXISTS; |
| 24 | 29 | import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.OTA_FIRMWARE_PRODUCT_VERSION_DUPLICATE; |
| 25 | 30 | |
| ... | ... | @@ -77,6 +82,14 @@ public class IotOtaFirmwareServiceImpl implements IotOtaFirmwareService { |
| 77 | 82 | } |
| 78 | 83 | |
| 79 | 84 | @Override |
| 85 | + public List<IotOtaFirmwareDO> getOtaFirmwareList(Collection<Long> ids) { | |
| 86 | + if (ids == null || ids.isEmpty()) { | |
| 87 | + return Collections.emptyList(); | |
| 88 | + } | |
| 89 | + return otaFirmwareMapper.selectByIds(ids); | |
| 90 | + } | |
| 91 | + | |
| 92 | + @Override | |
| 80 | 93 | public PageResult<IotOtaFirmwareDO> getOtaFirmwarePage(IotOtaFirmwarePageReqVO pageReqVO) { |
| 81 | 94 | return otaFirmwareMapper.selectPage(pageReqVO); |
| 82 | 95 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaTaskRecordService.java
| ... | ... | @@ -31,7 +31,7 @@ public interface IotOtaTaskRecordService { |
| 31 | 31 | * @param taskId 任务编号 |
| 32 | 32 | * @return 状态统计 Map,key 为状态码,value 为对应状态的升级记录数量 |
| 33 | 33 | */ |
| 34 | - Map<Integer, Long> getOtaTaskRecordStatusCountMap(Long firmwareId, Long taskId); | |
| 34 | + Map<Integer, Long> getOtaTaskRecordStatusStatistics(Long firmwareId, Long taskId); | |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * 获取 OTA 升级记录 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaTaskRecordServiceImpl.java
| ... | ... | @@ -42,7 +42,7 @@ public class IotOtaTaskRecordServiceImpl implements IotOtaTaskRecordService { |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | @Override |
| 45 | - public Map<Integer, Long> getOtaTaskRecordStatusCountMap(Long firmwareId, Long taskId) { | |
| 45 | + public Map<Integer, Long> getOtaTaskRecordStatusStatistics(Long firmwareId, Long taskId) { | |
| 46 | 46 | // 按照 status 枚举,初始化 countMap 为 0 |
| 47 | 47 | Map<Integer, Long> countMap = convertMap(Arrays.asList(IotOtaTaskRecordStatusEnum.values()), |
| 48 | 48 | IotOtaTaskRecordStatusEnum::getStatus, iotOtaTaskRecordStatusEnum -> 0L); | ... | ... |