|
|
|
@ -49,7 +49,9 @@ public class ClassicCategoryApplicationServiceImpl implements ClassicCategoryApp |
|
|
|
Map<Long, List<ClassicPaperSetDTO>> paperSetMap = Boolean.TRUE.equals(withPaperSet) ? new HashMap<>() : null; |
|
|
|
for (ClassicPaperSetEntity set : allPaperSets) { |
|
|
|
Long catId = set.getClassicCategoryId(); |
|
|
|
if (catId == null) continue; |
|
|
|
if (catId == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
countMap.merge(catId, 1, Integer::sum); |
|
|
|
if (paperSetMap != null) { |
|
|
|
//按分类ID分组套题组
|
|
|
|
@ -163,6 +165,46 @@ public class ClassicCategoryApplicationServiceImpl implements ClassicCategoryApp |
|
|
|
return Result.success(entity.toDTO(ClassicCategoryDTO::new)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<ClassicCategoryDTO> rename(Long id, String name) throws Exception { |
|
|
|
// 1. 参数校验
|
|
|
|
if (id == null) { |
|
|
|
throw new BusinessErrorException("分类ID不能为空"); |
|
|
|
} |
|
|
|
if (StrUtil.isBlank(name)) { |
|
|
|
throw new BusinessErrorException("分类名称不能为空"); |
|
|
|
} |
|
|
|
if (StrUtil.length(name) > 50) { |
|
|
|
throw new BusinessErrorException("分类名称过长"); |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 分类存在性校验
|
|
|
|
ClassicCategoryEntity entity = classicCategoryBaseService.getById(id); |
|
|
|
if (entity == null) { |
|
|
|
throw new BusinessErrorException("分类不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 名称未变更则直接返回
|
|
|
|
if (StrUtil.equals(entity.getName(), name)) { |
|
|
|
return Result.success(entity.toDTO(ClassicCategoryDTO::new)); |
|
|
|
} |
|
|
|
|
|
|
|
// 4. 同父级下重名校验
|
|
|
|
LambdaQueryWrapper<ClassicCategoryEntity> duplicateQuery = new LambdaQueryWrapper<ClassicCategoryEntity>() |
|
|
|
.eq(ClassicCategoryEntity::getName, name) |
|
|
|
.eq(ClassicCategoryEntity::getParentId, entity.getParentId()) |
|
|
|
.ne(ClassicCategoryEntity::getId, id); |
|
|
|
if (classicCategoryBaseService.count(duplicateQuery) > 0) { |
|
|
|
throw new BusinessErrorException("同级下已存在同名分类"); |
|
|
|
} |
|
|
|
|
|
|
|
// 5. 只更新 name 字段,避免覆盖其他字段
|
|
|
|
entity.setName(name); |
|
|
|
classicCategoryBaseService.updateById(entity); |
|
|
|
|
|
|
|
return Result.success(entity.toDTO(ClassicCategoryDTO::new)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<String> delete(Long id) throws Exception { |
|
|
|
ClassicCategoryEntity category = classicCategoryBaseService.getById(id); |
|
|
|
|