fix: 删除商品改为硬删除,删除分类需检查是否有商品
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Agent
2026-03-31 15:57:22 +00:00
parent 5d9774aaaf
commit e39643fdb7

View File

@@ -68,16 +68,16 @@ public class ProductServiceImpl implements ProductService {
/** /**
* 删除分类 * 删除分类
* 需要先处理关联的产品(硬删除已软删除的产品) * 检查是否有商品使用该分类,存在则不允许删除
*/ */
@Override @Override
public void deleteCategory(String id) { public void deleteCategory(String id) {
// 先将关联该分类的产品的 category_id 置空(处理软删除的产品) // 检查是否有商品使用该分类
Product product = new Product(); Long count = productMapper.selectCount(new LambdaQueryWrapper<Product>()
product.setCategoryId(null);
productMapper.update(product, new LambdaQueryWrapper<Product>()
.eq(Product::getCategoryId, id)); .eq(Product::getCategoryId, id));
// 再删除分类 if (count > 0) {
throw new RuntimeException("该分类下有商品,无法删除");
}
categoryMapper.deleteById(id); categoryMapper.deleteById(id);
} }
@@ -137,14 +137,11 @@ public class ProductServiceImpl implements ProductService {
} }
/** /**
* 删除商品(软删) * 删除商品(硬删除)
*/ */
@Override @Override
public void deleteProduct(String id) { public void deleteProduct(String id) {
Product product = new Product(); productMapper.deleteById(id);
product.setProductId(id);
product.setStatus(0);
productMapper.updateById(product);
} }
/** /**