Commit 416486bf47e5513af6adcc8eb62f2f5a360d660d
Merge remote-tracking branch 'origin/master-jdk17' into master-jdk17
Showing
6 changed files
with
45 additions
and
3 deletions
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/app/file/AppFileController.java
| ... | ... | @@ -35,7 +35,6 @@ public class AppFileController { |
| 35 | 35 | @Operation(summary = "上传文件") |
| 36 | 36 | @Parameter(name = "file", description = "文件附件", required = true, |
| 37 | 37 | schema = @Schema(type = "string", format = "binary")) |
| 38 | - @PermitAll | |
| 39 | 38 | public CommonResult<String> uploadFile(@Valid AppFileUploadReqVO uploadReqVO) throws Exception { |
| 40 | 39 | MultipartFile file = uploadReqVO.getFile(); |
| 41 | 40 | byte[] content = IoUtil.readBytes(file.getInputStream()); |
| ... | ... | @@ -57,7 +56,6 @@ public class AppFileController { |
| 57 | 56 | |
| 58 | 57 | @PostMapping("/create") |
| 59 | 58 | @Operation(summary = "创建文件", description = "模式二:前端上传文件:配合 presigned-url 接口,记录上传了上传的文件") |
| 60 | - @PermitAll | |
| 61 | 59 | public CommonResult<Long> createFile(@Valid @RequestBody FileCreateReqVO createReqVO) { |
| 62 | 60 | return success(fileService.createFile(createReqVO)); |
| 63 | 61 | } | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/ota/IotOtaFirmwareController.java
| ... | ... | @@ -12,6 +12,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO; |
| 12 | 12 | import cn.iocoder.yudao.module.iot.service.ota.IotOtaFirmwareService; |
| 13 | 13 | import cn.iocoder.yudao.module.iot.service.product.IotProductService; |
| 14 | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 15 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 15 | 16 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 16 | 17 | import jakarta.annotation.Resource; |
| 17 | 18 | import jakarta.validation.Valid; |
| ... | ... | @@ -47,6 +48,15 @@ public class IotOtaFirmwareController { |
| 47 | 48 | return success(true); |
| 48 | 49 | } |
| 49 | 50 | |
| 51 | + @DeleteMapping("/delete") | |
| 52 | + @Operation(summary = "删除 OTA 固件") | |
| 53 | + @Parameter(name = "id", description = "固件编号", required = true, example = "1024") | |
| 54 | + @PreAuthorize("@ss.hasPermission('iot:ota-firmware:delete')") | |
| 55 | + public CommonResult<Boolean> deleteOtaFirmware(@RequestParam("id") Long id) { | |
| 56 | + otaFirmwareService.deleteOtaFirmware(id); | |
| 57 | + return success(true); | |
| 58 | + } | |
| 59 | + | |
| 50 | 60 | @GetMapping("/get") |
| 51 | 61 | @Operation(summary = "获得 OTA 固件") |
| 52 | 62 | @PreAuthorize("@ss.hasPermission('iot:ota-firmware:query')") | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/ota/IotOtaTaskMapper.java
| ... | ... | @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 6 | 6 | import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.task.IotOtaTaskPageReqVO; |
| 7 | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaTaskDO; |
| 8 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
| 8 | 9 | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| 9 | 10 | import org.apache.ibatis.annotations.Mapper; |
| 10 | 11 | |
| ... | ... | @@ -16,6 +17,12 @@ public interface IotOtaTaskMapper extends BaseMapperX<IotOtaTaskDO> { |
| 16 | 17 | IotOtaTaskDO::getName, name); |
| 17 | 18 | } |
| 18 | 19 | |
| 20 | + default Long selectCountByFirmwareIdAndStatus(Long firmwareId, Integer status) { | |
| 21 | + return selectCount(new LambdaQueryWrapper<IotOtaTaskDO>() | |
| 22 | + .eq(IotOtaTaskDO::getFirmwareId, firmwareId) | |
| 23 | + .eq(IotOtaTaskDO::getStatus, status)); | |
| 24 | + } | |
| 25 | + | |
| 19 | 26 | default PageResult<IotOtaTaskDO> selectPage(IotOtaTaskPageReqVO pageReqVO) { |
| 20 | 27 | return selectPage(pageReqVO, new LambdaQueryWrapperX<IotOtaTaskDO>() |
| 21 | 28 | .eqIfPresent(IotOtaTaskDO::getFirmwareId, pageReqVO.getFirmwareId()) | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java
| ... | ... | @@ -66,6 +66,8 @@ public interface ErrorCodeConstants { |
| 66 | 66 | |
| 67 | 67 | ErrorCode OTA_FIRMWARE_NOT_EXISTS = new ErrorCode(1_050_008_000, "固件信息不存在"); |
| 68 | 68 | ErrorCode OTA_FIRMWARE_PRODUCT_VERSION_DUPLICATE = new ErrorCode(1_050_008_001, "产品版本号重复"); |
| 69 | + ErrorCode OTA_FIRMWARE_DELETE_FAIL_TASK_IN_PROGRESS = new ErrorCode(1_050_008_002, | |
| 70 | + "删除 OTA 固件失败,原因:存在进行中的升级任务"); | |
| 69 | 71 | |
| 70 | 72 | // ========== OTA 升级任务相关 1-050-008-100 ========== |
| 71 | 73 | |
| ... | ... | @@ -105,4 +107,4 @@ public interface ErrorCodeConstants { |
| 105 | 107 | // ========== IoT 告警记录 1-050-014-000 ========== |
| 106 | 108 | ErrorCode ALERT_RECORD_NOT_EXISTS = new ErrorCode(1_050_014_000, "IoT 告警记录不存在"); |
| 107 | 109 | |
| 108 | -} | |
| 109 | 110 | \ No newline at end of file |
| 111 | +} | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaFirmwareService.java
| ... | ... | @@ -36,6 +36,13 @@ public interface IotOtaFirmwareService { |
| 36 | 36 | void updateOtaFirmware(@Valid IotOtaFirmwareUpdateReqVO updateReqVO); |
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | + * 删除 OTA 固件信息 | |
| 40 | + * | |
| 41 | + * @param id 固件编号 | |
| 42 | + */ | |
| 43 | + void deleteOtaFirmware(Long id); | |
| 44 | + | |
| 45 | + /** | |
| 39 | 46 | * 获取 OTA 固件信息 |
| 40 | 47 | * |
| 41 | 48 | * @param id 固件编号 | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/ota/IotOtaFirmwareServiceImpl.java
| ... | ... | @@ -10,6 +10,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwa |
| 10 | 10 | import cn.iocoder.yudao.module.iot.controller.admin.ota.vo.firmware.IotOtaFirmwareUpdateReqVO; |
| 11 | 11 | import cn.iocoder.yudao.module.iot.dal.dataobject.ota.IotOtaFirmwareDO; |
| 12 | 12 | import cn.iocoder.yudao.module.iot.dal.mysql.ota.IotOtaFirmwareMapper; |
| 13 | +import cn.iocoder.yudao.module.iot.dal.mysql.ota.IotOtaTaskMapper; | |
| 14 | +import cn.iocoder.yudao.module.iot.enums.ota.IotOtaTaskStatusEnum; | |
| 13 | 15 | import cn.iocoder.yudao.module.iot.service.product.IotProductService; |
| 14 | 16 | import jakarta.annotation.Resource; |
| 15 | 17 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -23,6 +25,7 @@ import java.util.Collections; |
| 23 | 25 | import java.util.List; |
| 24 | 26 | |
| 25 | 27 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 28 | +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.OTA_FIRMWARE_DELETE_FAIL_TASK_IN_PROGRESS; | |
| 26 | 29 | import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.OTA_FIRMWARE_NOT_EXISTS; |
| 27 | 30 | import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.OTA_FIRMWARE_PRODUCT_VERSION_DUPLICATE; |
| 28 | 31 | |
| ... | ... | @@ -38,6 +41,8 @@ public class IotOtaFirmwareServiceImpl implements IotOtaFirmwareService { |
| 38 | 41 | |
| 39 | 42 | @Resource |
| 40 | 43 | private IotOtaFirmwareMapper otaFirmwareMapper; |
| 44 | + @Resource | |
| 45 | + private IotOtaTaskMapper otaTaskMapper; | |
| 41 | 46 | @Lazy |
| 42 | 47 | @Resource |
| 43 | 48 | private IotProductService productService; |
| ... | ... | @@ -75,6 +80,19 @@ public class IotOtaFirmwareServiceImpl implements IotOtaFirmwareService { |
| 75 | 80 | } |
| 76 | 81 | |
| 77 | 82 | @Override |
| 83 | + public void deleteOtaFirmware(Long id) { | |
| 84 | + // 1.1 校验存在 | |
| 85 | + validateFirmwareExists(id); | |
| 86 | + // 1.2 校验是否有进行中的升级任务 | |
| 87 | + if (otaTaskMapper.selectCountByFirmwareIdAndStatus(id, IotOtaTaskStatusEnum.IN_PROGRESS.getStatus()) > 0) { | |
| 88 | + throw exception(OTA_FIRMWARE_DELETE_FAIL_TASK_IN_PROGRESS); | |
| 89 | + } | |
| 90 | + | |
| 91 | + // 2. 删除 | |
| 92 | + otaFirmwareMapper.deleteById(id); | |
| 93 | + } | |
| 94 | + | |
| 95 | + @Override | |
| 78 | 96 | public IotOtaFirmwareDO getOtaFirmware(Long id) { |
| 79 | 97 | return otaFirmwareMapper.selectById(id); |
| 80 | 98 | } | ... | ... |