diff --git a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java index 6a21de7cb..3fd09ce8e 100644 --- a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java +++ b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java @@ -12,4 +12,5 @@ public interface ErrorCodeConstants { // ========== 产品相关 1-050-001-000 ============ ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_050_001_000, "产品不存在"); ErrorCode PRODUCT_IDENTIFICATION_EXISTS = new ErrorCode(1_050_001_001, "产品标识已经存在"); + ErrorCode PRODUCT_STATUS_NOT_DELETE = new ErrorCode(1_050_001_002, "产品状是发布状态,不允许删除"); } diff --git a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductStatusEnum.java b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductStatusEnum.java index 38316371b..b10cee46f 100644 --- a/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductStatusEnum.java +++ b/yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductStatusEnum.java @@ -6,13 +6,13 @@ import lombok.Getter; /** * IOT 产品状态枚举类 - * 产品状态, 0: 未发布, 1: 已发布 + * 产品状态, 0: 开发中, 1: 已发布 */ @AllArgsConstructor @Getter public enum IotProductStatusEnum implements IntArrayValuable { - UNPUBLISHED(0, "未发布"), + UNPUBLISHED(0, "开发中"), PUBLISHED(1, "已发布"); /** diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/ProductController.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/ProductController.java index 9acce0234..f6d7e494d 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/ProductController.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/ProductController.java @@ -51,6 +51,17 @@ public class ProductController { return success(true); } + @PutMapping("/update-status") + @Operation(summary = "更新产品状态") + @Parameter(name = "id", description = "编号", required = true) + @Parameter(name = "status", description = "状态", required = true) + @PreAuthorize("@ss.hasPermission('iot:product:update')") + public CommonResult updateProductStatus(@RequestParam("id") Long id, + @RequestParam("status") Integer status) { + productService.updateProductStatus(id, status); + return success(true); + } + @DeleteMapping("/delete") @Operation(summary = "删除产品") @Parameter(name = "id", description = "编号", required = true) diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/ProductService.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/ProductService.java index 049ba26ce..cc1ffce81 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/ProductService.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/ProductService.java @@ -51,4 +51,11 @@ public interface ProductService { */ PageResult getProductPage(ProductPageReqVO pageReqVO); + /** + * 更新产品状态 + * + * @param id 编号 + * @param status 状态 + */ + void updateProductStatus(Long id, Integer status); } \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/ProductServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/ProductServiceImpl.java index b2ca76213..b692faa71 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/ProductServiceImpl.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/ProductServiceImpl.java @@ -6,14 +6,17 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.ProductPageReqVO; import cn.iocoder.yudao.module.iot.controller.admin.product.vo.ProductSaveReqVO; import cn.iocoder.yudao.module.iot.dal.dataobject.product.ProductDO; import cn.iocoder.yudao.module.iot.dal.mysql.product.ProductMapper; +import cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; +import java.util.Objects; import java.util.UUID; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_NOT_EXISTS; +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_STATUS_NOT_DELETE; /** * IOT 产品 Service 实现类 @@ -62,6 +65,8 @@ public class ProductServiceImpl implements ProductService { public void deleteProduct(Long id) { // 校验存在 validateProductExists(id); + // 发布状态不可删除 + validateProductStatus(id); // 删除 productMapper.deleteById(id); } @@ -72,6 +77,13 @@ public class ProductServiceImpl implements ProductService { } } + private void validateProductStatus(Long id) { + ProductDO product = productMapper.selectById(id); + if (Objects.equals(product.getStatus(), IotProductStatusEnum.PUBLISHED.getType())) { + throw exception(PRODUCT_STATUS_NOT_DELETE); + } + } + @Override public ProductDO getProduct(Long id) { return productMapper.selectById(id); @@ -82,4 +94,13 @@ public class ProductServiceImpl implements ProductService { return productMapper.selectPage(pageReqVO); } + @Override + public void updateProductStatus(Long id, Integer status) { + // 校验存在 + validateProductExists(id); + // 更新 + ProductDO updateObj = ProductDO.builder().id(id).status(status).build(); + productMapper.updateById(updateObj); + } + } \ No newline at end of file