|
@@ -1,5 +1,6 @@
|
|
|
package com.fjhx.classify.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.base.BaseEntity;
|
|
|
import com.fjhx.classify.mapper.ClassifyMapper;
|
|
@@ -14,7 +15,6 @@ 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;
|
|
|
|
|
@@ -45,9 +45,13 @@ public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, Classify> i
|
|
|
String type = condition.get("type");
|
|
|
Assert.notEmpty(type, "分类类型不能为空");
|
|
|
|
|
|
+ // 分类名称
|
|
|
+ String name = condition.get("name");
|
|
|
+
|
|
|
List<Classify> list = lambdaQuery()
|
|
|
- .eq(Classify::getType, type)
|
|
|
.select(Classify::getId, Classify::getName, Classify::getParentId)
|
|
|
+ .eq(Classify::getType, type)
|
|
|
+ .like(ObjectUtil.isNotEmpty(name), Classify::getName, name)
|
|
|
.list();
|
|
|
|
|
|
// 构建树形
|
|
@@ -77,14 +81,17 @@ public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, Classify> i
|
|
|
(ObjectUtil.isEmpty(parentIdSet) ? "" : parentIdSet + ",") + parentId);
|
|
|
}
|
|
|
|
|
|
+ peerNameOnly(classifyVo.getParentId(), classifyVo.getName(), null);
|
|
|
save(classifyVo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void edit(ClassifyVo classifyVo) {
|
|
|
Assert.notEmpty(classifyVo.getId(), "分类Id不能为空");
|
|
|
- classifyVo.setParentId(null);
|
|
|
- classifyVo.setParentIdSet(null);
|
|
|
+ Assert.notEmpty(classifyVo.getParentId(), "父分类id不能为空");
|
|
|
+ Assert.notEmpty(classifyVo.getName(), "分类名称不能为空");
|
|
|
+
|
|
|
+ peerNameOnly(classifyVo.getParentId(), classifyVo.getName(), classifyVo.getId());
|
|
|
updateById(classifyVo);
|
|
|
}
|
|
|
|
|
@@ -126,4 +133,20 @@ public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, Classify> i
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保证同级名称不重复
|
|
|
+ */
|
|
|
+ private void peerNameOnly(Long parentId, String classifyName, Long excludeId) {
|
|
|
+
|
|
|
+ Integer count = lambdaQuery()
|
|
|
+ .eq(BaseEntity::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Classify::getParentId, parentId)
|
|
|
+ .eq(Classify::getName, classifyName)
|
|
|
+ .ne(ObjectUtil.isNotEmpty(excludeId), BaseEntity::getId, excludeId)
|
|
|
+ .count();
|
|
|
+
|
|
|
+ Assert.eqZero(count, "存在相同分类名称");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|