分类名修改重复问题校验
This commit is contained in:
parent
080d91d65d
commit
f173fe4285
@ -79,7 +79,7 @@ public class CategoryController {
|
|||||||
@RequiresPermissions("admin:category:update")
|
@RequiresPermissions("admin:category:update")
|
||||||
@ApiOperation("分类修改")
|
@ApiOperation("分类修改")
|
||||||
public R update(@RequestBody CategoryEntity category){
|
public R update(@RequestBody CategoryEntity category){
|
||||||
categoryService.updateById(category);
|
categoryService.updateCategory(category);
|
||||||
|
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
@ -33,5 +33,7 @@ public interface CategoryService extends IService<CategoryEntity> {
|
|||||||
void saveCategory(CategoryEntity category);
|
void saveCategory(CategoryEntity category);
|
||||||
|
|
||||||
void deleteByIdList(List<Integer> list);
|
void deleteByIdList(List<Integer> list);
|
||||||
|
|
||||||
|
void updateCategory(CategoryEntity category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +58,10 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void saveCategory(CategoryEntity category) {
|
public void saveCategory(CategoryEntity category) {
|
||||||
Integer count = this.lambdaQuery().eq(CategoryEntity::getCateName, category.getCateName()).count();
|
Integer count = this.lambdaQuery()
|
||||||
if (count != 0) {
|
.eq(CategoryEntity::getCateName, category.getCateName())
|
||||||
|
.count();
|
||||||
|
if (count > 0) {
|
||||||
throw new LinfengException("分类名不能重复");
|
throw new LinfengException("分类名不能重复");
|
||||||
}
|
}
|
||||||
this.save(category);
|
this.save(category);
|
||||||
@ -83,4 +85,16 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
|
|||||||
this.removeByIds(list);
|
this.removeByIds(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateCategory(CategoryEntity category) {
|
||||||
|
Integer count = this.lambdaQuery()
|
||||||
|
.eq(CategoryEntity::getCateName, category.getCateName())
|
||||||
|
.count();
|
||||||
|
if (count > 1) {
|
||||||
|
throw new LinfengException("分类名不能重复");
|
||||||
|
}
|
||||||
|
this.updateById(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user