优化商品类型里面的重复判断逻辑,增加上级目录的条件

This commit is contained in:
jishenghua
2025-10-28 17:21:58 +08:00
parent 390c2d34e1
commit 13a9ec92dd
4 changed files with 12 additions and 4 deletions

View File

@@ -97,10 +97,12 @@ public class MaterialCategoryController extends BaseController {
@GetMapping(value = "/checkIsNameExist")
@ApiOperation(value = "检查名称是否存在")
public String checkIsNameExist(@RequestParam Long id, @RequestParam(value ="name", required = false) String name,
public String checkIsNameExist(@RequestParam Long id,
@RequestParam(value ="name", required = false) String name,
@RequestParam(value ="parentId", required = false) Long parentId,
HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
int exist = materialCategoryService.checkIsNameExist(id, name);
int exist = materialCategoryService.checkIsNameExist(id, name, parentId);
if(exist > 0) {
objectMap.put("status", true);
} else {

View File

@@ -204,9 +204,13 @@ public class MaterialCategoryService {
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
public int checkIsNameExist(Long id, String name, Long parentId)throws Exception {
MaterialCategoryExample example = new MaterialCategoryExample();
example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
if(parentId!=null) {
example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andParentIdEqualTo(parentId).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
} else {
example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
}
List<MaterialCategory> list=null;
try{
list= materialCategoryMapper.selectByExample(example);