mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-25 00:15:06 +08:00
修改:更新产品状态
This commit is contained in:
@ -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<Boolean> 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)
|
||||
|
@ -51,4 +51,11 @@ public interface ProductService {
|
||||
*/
|
||||
PageResult<ProductDO> getProductPage(ProductPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 更新产品状态
|
||||
*
|
||||
* @param id 编号
|
||||
* @param status 状态
|
||||
*/
|
||||
void updateProductStatus(Long id, Integer status);
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user