fix: 删除分类时先置空关联产品的category_id
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,9 +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();
|
||||||
|
product.setCategoryId(null);
|
||||||
|
productMapper.update(product, new LambdaQueryWrapper<Product>()
|
||||||
|
.eq(Product::getCategoryId, id));
|
||||||
|
// 再删除分类
|
||||||
categoryMapper.deleteById(id);
|
categoryMapper.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user