|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|