Commit c7b1cc9a436084ee78d416276f2fc351673a69c1
1 parent
037ab39a
修改:更新产品状态
Showing
5 changed files
with
42 additions
and
2 deletions
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 { | @@ -12,4 +12,5 @@ public interface ErrorCodeConstants { | ||
| 12 | // ========== 产品相关 1-050-001-000 ============ | 12 | // ========== 产品相关 1-050-001-000 ============ |
| 13 | ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_050_001_000, "产品不存在"); | 13 | ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_050_001_000, "产品不存在"); |
| 14 | ErrorCode PRODUCT_IDENTIFICATION_EXISTS = new ErrorCode(1_050_001_001, "产品标识已经存在"); | 14 | ErrorCode PRODUCT_IDENTIFICATION_EXISTS = new ErrorCode(1_050_001_001, "产品标识已经存在"); |
| 15 | + ErrorCode PRODUCT_STATUS_NOT_DELETE = new ErrorCode(1_050_001_002, "产品状是发布状态,不允许删除"); | ||
| 15 | } | 16 | } |
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; | @@ -6,13 +6,13 @@ import lombok.Getter; | ||
| 6 | 6 | ||
| 7 | /** | 7 | /** |
| 8 | * IOT 产品状态枚举类 | 8 | * IOT 产品状态枚举类 |
| 9 | - * 产品状态, 0: 未发布, 1: 已发布 | 9 | + * 产品状态, 0: 开发中, 1: 已发布 |
| 10 | */ | 10 | */ |
| 11 | @AllArgsConstructor | 11 | @AllArgsConstructor |
| 12 | @Getter | 12 | @Getter |
| 13 | public enum IotProductStatusEnum implements IntArrayValuable { | 13 | public enum IotProductStatusEnum implements IntArrayValuable { |
| 14 | 14 | ||
| 15 | - UNPUBLISHED(0, "未发布"), | 15 | + UNPUBLISHED(0, "开发中"), |
| 16 | PUBLISHED(1, "已发布"); | 16 | PUBLISHED(1, "已发布"); |
| 17 | 17 | ||
| 18 | /** | 18 | /** |
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 { | @@ -51,6 +51,17 @@ public class ProductController { | ||
| 51 | return success(true); | 51 | return success(true); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | + @PutMapping("/update-status") | ||
| 55 | + @Operation(summary = "更新产品状态") | ||
| 56 | + @Parameter(name = "id", description = "编号", required = true) | ||
| 57 | + @Parameter(name = "status", description = "状态", required = true) | ||
| 58 | + @PreAuthorize("@ss.hasPermission('iot:product:update')") | ||
| 59 | + public CommonResult<Boolean> updateProductStatus(@RequestParam("id") Long id, | ||
| 60 | + @RequestParam("status") Integer status) { | ||
| 61 | + productService.updateProductStatus(id, status); | ||
| 62 | + return success(true); | ||
| 63 | + } | ||
| 64 | + | ||
| 54 | @DeleteMapping("/delete") | 65 | @DeleteMapping("/delete") |
| 55 | @Operation(summary = "删除产品") | 66 | @Operation(summary = "删除产品") |
| 56 | @Parameter(name = "id", description = "编号", required = true) | 67 | @Parameter(name = "id", description = "编号", required = true) |
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 { | @@ -51,4 +51,11 @@ public interface ProductService { | ||
| 51 | */ | 51 | */ |
| 52 | PageResult<ProductDO> getProductPage(ProductPageReqVO pageReqVO); | 52 | PageResult<ProductDO> getProductPage(ProductPageReqVO pageReqVO); |
| 53 | 53 | ||
| 54 | + /** | ||
| 55 | + * 更新产品状态 | ||
| 56 | + * | ||
| 57 | + * @param id 编号 | ||
| 58 | + * @param status 状态 | ||
| 59 | + */ | ||
| 60 | + void updateProductStatus(Long id, Integer status); | ||
| 54 | } | 61 | } |
| 55 | \ No newline at end of file | 62 | \ No newline at end of file |
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; | @@ -6,14 +6,17 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.ProductPageReqVO; | ||
| 6 | import cn.iocoder.yudao.module.iot.controller.admin.product.vo.ProductSaveReqVO; | 6 | import cn.iocoder.yudao.module.iot.controller.admin.product.vo.ProductSaveReqVO; |
| 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.product.ProductDO; | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.product.ProductDO; |
| 8 | import cn.iocoder.yudao.module.iot.dal.mysql.product.ProductMapper; | 8 | import cn.iocoder.yudao.module.iot.dal.mysql.product.ProductMapper; |
| 9 | +import cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum; | ||
| 9 | import jakarta.annotation.Resource; | 10 | import jakarta.annotation.Resource; |
| 10 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 11 | import org.springframework.validation.annotation.Validated; | 12 | import org.springframework.validation.annotation.Validated; |
| 12 | 13 | ||
| 14 | +import java.util.Objects; | ||
| 13 | import java.util.UUID; | 15 | import java.util.UUID; |
| 14 | 16 | ||
| 15 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 17 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 16 | import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_NOT_EXISTS; | 18 | import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_NOT_EXISTS; |
| 19 | +import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_STATUS_NOT_DELETE; | ||
| 17 | 20 | ||
| 18 | /** | 21 | /** |
| 19 | * IOT 产品 Service 实现类 | 22 | * IOT 产品 Service 实现类 |
| @@ -62,6 +65,8 @@ public class ProductServiceImpl implements ProductService { | @@ -62,6 +65,8 @@ public class ProductServiceImpl implements ProductService { | ||
| 62 | public void deleteProduct(Long id) { | 65 | public void deleteProduct(Long id) { |
| 63 | // 校验存在 | 66 | // 校验存在 |
| 64 | validateProductExists(id); | 67 | validateProductExists(id); |
| 68 | + // 发布状态不可删除 | ||
| 69 | + validateProductStatus(id); | ||
| 65 | // 删除 | 70 | // 删除 |
| 66 | productMapper.deleteById(id); | 71 | productMapper.deleteById(id); |
| 67 | } | 72 | } |
| @@ -72,6 +77,13 @@ public class ProductServiceImpl implements ProductService { | @@ -72,6 +77,13 @@ public class ProductServiceImpl implements ProductService { | ||
| 72 | } | 77 | } |
| 73 | } | 78 | } |
| 74 | 79 | ||
| 80 | + private void validateProductStatus(Long id) { | ||
| 81 | + ProductDO product = productMapper.selectById(id); | ||
| 82 | + if (Objects.equals(product.getStatus(), IotProductStatusEnum.PUBLISHED.getType())) { | ||
| 83 | + throw exception(PRODUCT_STATUS_NOT_DELETE); | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + | ||
| 75 | @Override | 87 | @Override |
| 76 | public ProductDO getProduct(Long id) { | 88 | public ProductDO getProduct(Long id) { |
| 77 | return productMapper.selectById(id); | 89 | return productMapper.selectById(id); |
| @@ -82,4 +94,13 @@ public class ProductServiceImpl implements ProductService { | @@ -82,4 +94,13 @@ public class ProductServiceImpl implements ProductService { | ||
| 82 | return productMapper.selectPage(pageReqVO); | 94 | return productMapper.selectPage(pageReqVO); |
| 83 | } | 95 | } |
| 84 | 96 | ||
| 97 | + @Override | ||
| 98 | + public void updateProductStatus(Long id, Integer status) { | ||
| 99 | + // 校验存在 | ||
| 100 | + validateProductExists(id); | ||
| 101 | + // 更新 | ||
| 102 | + ProductDO updateObj = ProductDO.builder().id(id).status(status).build(); | ||
| 103 | + productMapper.updateById(updateObj); | ||
| 104 | + } | ||
| 105 | + | ||
| 85 | } | 106 | } |
| 86 | \ No newline at end of file | 107 | \ No newline at end of file |