fix: 删除商品改为硬删除,删除分类需检查是否有商品
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -68,16 +68,16 @@ public class ProductServiceImpl implements ProductService {
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
* 需要先处理关联的产品(硬删除已软删除的产品)
|
||||
* 检查是否有商品使用该分类,存在则不允许删除
|
||||
*/
|
||||
@Override
|
||||
public void deleteCategory(String id) {
|
||||
// 先将关联该分类的产品的 category_id 置空(处理软删除的产品)
|
||||
Product product = new Product();
|
||||
product.setCategoryId(null);
|
||||
productMapper.update(product, new LambdaQueryWrapper<Product>()
|
||||
// 检查是否有商品使用该分类
|
||||
Long count = productMapper.selectCount(new LambdaQueryWrapper<Product>()
|
||||
.eq(Product::getCategoryId, id));
|
||||
// 再删除分类
|
||||
if (count > 0) {
|
||||
throw new RuntimeException("该分类下有商品,无法删除");
|
||||
}
|
||||
categoryMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@@ -137,14 +137,11 @@ public class ProductServiceImpl implements ProductService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品(软删)
|
||||
* 删除商品(硬删除)
|
||||
*/
|
||||
@Override
|
||||
public void deleteProduct(String id) {
|
||||
Product product = new Product();
|
||||
product.setProductId(id);
|
||||
product.setStatus(0);
|
||||
productMapper.updateById(product);
|
||||
productMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user