|
@@ -3,13 +3,19 @@ package com.fjhx.classif.service.impl;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.base.BaseEntity;
|
|
|
import com.fjhx.classif.entity.Classif;
|
|
|
+import com.fjhx.classif.enums.ClassifTypeEnum;
|
|
|
import com.fjhx.classif.mapper.ClassifMapper;
|
|
|
import com.fjhx.classif.service.ClassifService;
|
|
|
import com.fjhx.classif.vo.ClassifVo;
|
|
|
+import com.fjhx.material.entity.Material;
|
|
|
+import com.fjhx.material.service.MaterialService;
|
|
|
+import com.fjhx.product.entity.Product;
|
|
|
+import com.fjhx.product.service.ProductService;
|
|
|
import com.fjhx.utils.Assert;
|
|
|
import com.fjhx.utils.TreeUtil;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
@@ -27,6 +33,12 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class ClassifServiceImpl extends ServiceImpl<ClassifMapper, Classif> implements ClassifService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProductService productService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MaterialService materialService;
|
|
|
+
|
|
|
@Override
|
|
|
public void add(ClassifVo classifVo) {
|
|
|
|
|
@@ -55,13 +67,23 @@ public class ClassifServiceImpl extends ServiceImpl<ClassifMapper, Classif> impl
|
|
|
|
|
|
@Override
|
|
|
public void delete(ClassifVo classifVo) {
|
|
|
-
|
|
|
Long id = classifVo.getId();
|
|
|
+ Integer type = classifVo.getType();
|
|
|
|
|
|
- Integer count = lambdaQuery().eq(Classif::getParentId, id).count();
|
|
|
- Assert.eqZero(count, "存在子级分类,不能删除");
|
|
|
+ Assert.notEmpty(id, "分类id不能为空");
|
|
|
+ Assert.notEmpty(type, "分类类型不能为空");
|
|
|
+
|
|
|
+ Integer childrenCount = lambdaQuery().eq(Classif::getParentId, id).count();
|
|
|
+ Assert.eqZero(childrenCount, "该分类下存在子级分类,无法删除");
|
|
|
+
|
|
|
+ if (type.equals(ClassifTypeEnum.PRODUCT_TYPE.getCode())) {
|
|
|
+ Integer relationCount = productService.lambdaQuery().eq(Product::getClassifId, id).count();
|
|
|
+ Assert.eqZero(relationCount, "该分类下存在产品,无法删除");
|
|
|
+ } else {
|
|
|
+ Integer relationCount = materialService.lambdaQuery().eq(Material::getClassifId, id).count();
|
|
|
+ Assert.eqZero(relationCount, "该分类下存在物料,无法删除");
|
|
|
+ }
|
|
|
|
|
|
- // TODO 分类下有数据,不允许删除
|
|
|
removeById(classifVo.getId());
|
|
|
}
|
|
|
|