Browse Source

逻辑修改

master
luoweijian 2 months ago
parent
commit
483a047d36
  1. 22
      src/main/java/com/project/classicpaper/application/impl/ClassicPaperSetApplicationServiceImpl.java
  2. 18
      src/main/java/com/project/classicpaper/domain/service/impl/SavePaperSetDomainServiceImpl.java

22
src/main/java/com/project/classicpaper/application/impl/ClassicPaperSetApplicationServiceImpl.java

@ -152,6 +152,28 @@ public class ClassicPaperSetApplicationServiceImpl implements ClassicPaperSetApp
computeScoreRatio(paperSet, setDTO);
if (paperId == null) {
// 填充版本精简信息(不返回具体题目)
List<ClassicPaperEntity> papers = classicPaperBaseService.list(
new LambdaQueryWrapper<ClassicPaperEntity>()
.select(ClassicPaperEntity::getId, ClassicPaperEntity::getName,
ClassicPaperEntity::getSetIndex, ClassicPaperEntity::getStatus)
.eq(ClassicPaperEntity::getSetId, setId)
.orderByAsc(ClassicPaperEntity::getSetIndex)
);
if (!papers.isEmpty()) {
List<ClassicPaperDTO> versions = papers.stream()
.map(p -> {
ClassicPaperDTO v = new ClassicPaperDTO();
v.setId(p.getId());
v.setName(p.getName());
v.setSetIndex(p.getSetIndex());
v.setStatus(p.getStatus());
v.setStatusText(ClassicPaperStatusEnum.findByValue(p.getStatus()));
return v;
})
.toList();
setDTO.setVersions(versions);
}
return Result.success(setDTO);
}

18
src/main/java/com/project/classicpaper/domain/service/impl/SavePaperSetDomainServiceImpl.java

@ -1,5 +1,6 @@
package com.project.classicpaper.domain.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -9,7 +10,6 @@ import com.project.classicpaper.domain.dto.ClassicPaperSetDTO;
import com.project.classicpaper.domain.entity.ClassicPaperEntity;
import com.project.classicpaper.domain.entity.ClassicPaperQuestionEntity;
import com.project.classicpaper.domain.entity.ClassicPaperSetEntity;
import com.project.classicpaper.domain.enums.ClassicPaperStatusEnum;
import com.project.classicpaper.domain.service.ClassicPaperBaseService;
import com.project.classicpaper.domain.service.ClassicPaperQuestionBaseService;
import com.project.classicpaper.domain.service.ClassicPaperSetBaseService;
@ -52,7 +52,21 @@ public class SavePaperSetDomainServiceImpl implements SavePaperSetDomainService
throw new BusinessErrorException("套题组不存在");
}
// 2. 更新分值比例
// 2. 更新名称(如果传了且不同)
if (StrUtil.isNotBlank(request.getName()) && !request.getName().equals(paperSet.getName())) {
// 同一分类下名称不能重复(排除自身)
long nameCount = classicPaperSetBaseService.count(
new LambdaQueryWrapper<ClassicPaperSetEntity>()
.eq(ClassicPaperSetEntity::getClassicCategoryId, paperSet.getClassicCategoryId())
.eq(ClassicPaperSetEntity::getName, request.getName())
.ne(ClassicPaperSetEntity::getId, setId));
if (nameCount > 0) {
throw new BusinessErrorException("同一分类下套题名称已存在");
}
paperSet.setName(request.getName());
}
// 3. 更新分值比例
String scoreRatio = buildScoreRatioFromFields(request);
if (scoreRatio != null) {
paperSet.setScoreRatio(scoreRatio);

Loading…
Cancel
Save