分类名修改重复问题校验

This commit is contained in:
linfeng 2023-07-24 10:14:41 +08:00
parent 080d91d65d
commit f173fe4285
3 changed files with 19 additions and 3 deletions

View File

@ -79,7 +79,7 @@ public class CategoryController {
@RequiresPermissions("admin:category:update")
@ApiOperation("分类修改")
public R update(@RequestBody CategoryEntity category){
categoryService.updateById(category);
categoryService.updateCategory(category);
return R.ok();
}

View File

@ -33,5 +33,7 @@ public interface CategoryService extends IService<CategoryEntity> {
void saveCategory(CategoryEntity category);
void deleteByIdList(List<Integer> list);
void updateCategory(CategoryEntity category);
}

View File

@ -58,8 +58,10 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
@Override
@Transactional(rollbackFor = Exception.class)
public void saveCategory(CategoryEntity category) {
Integer count = this.lambdaQuery().eq(CategoryEntity::getCateName, category.getCateName()).count();
if (count != 0) {
Integer count = this.lambdaQuery()
.eq(CategoryEntity::getCateName, category.getCateName())
.count();
if (count > 0) {
throw new LinfengException("分类名不能重复");
}
this.save(category);
@ -83,4 +85,16 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity
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);
}
}