优化商品类型里面的重复判断逻辑,增加上级目录的条件
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user