大赛管理功能
This commit is contained in:
parent
636f049bfe
commit
6c1bb1d77f
|
@ -10,6 +10,7 @@ import club.joylink.rtss.vo.race.RacePaper.RacePaperDetailVO;
|
|||
import club.joylink.rtss.vo.race.RacePaper.RacePaperModuleVO;
|
||||
import club.joylink.rtss.vo.race.RacePaper.RacePaperVO;
|
||||
import club.joylink.rtss.vo.race.RacePaperQueryVO;
|
||||
import club.joylink.rtss.vo.race.RaceTask.RacePaperModuleTask;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -77,7 +78,7 @@ public class RacePaperController {
|
|||
}
|
||||
|
||||
@GetMapping("/{paperId}/module/{moduleId}/task")
|
||||
public void paperModuleTask(@PathVariable("paperId") Long id, @PathVariable("moduleId") Integer moduleId) {
|
||||
|
||||
public RacePaperModuleTask paperModuleTask(@PathVariable("paperId") Long id, @PathVariable("moduleId") Integer moduleId) {
|
||||
return this.racePaperService.paperModuleTask(id, moduleId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import club.joylink.rtss.dao.MyBatisBaseDao;
|
|||
import club.joylink.rtss.entity.racetr.RacetrTask;
|
||||
import club.joylink.rtss.entity.racetr.RacetrTaskExample;
|
||||
import club.joylink.rtss.vo.race.RaceTaskDetailDTO;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
@ -27,4 +28,6 @@ public interface RacetrTaskDAO extends MyBatisBaseDao<RacetrTask, Long, RacetrTa
|
|||
+ " and A.id = #{id}"
|
||||
+ "</script>")
|
||||
RaceTaskDetailDTO details(@Param("id") Long id);
|
||||
|
||||
List<RaceTaskDetailDTO> recursiveFindTask(@Param("taskIds") List<Long> taskIds);
|
||||
}
|
|
@ -15,14 +15,21 @@ import club.joylink.rtss.vo.race.RacePaper.RacePaperVO;
|
|||
import club.joylink.rtss.vo.race.RacePaperPageVO;
|
||||
import club.joylink.rtss.vo.race.RacePaperQueryVO;
|
||||
import club.joylink.rtss.vo.race.RaceSeasonOuterClass.RaceSeason.Group;
|
||||
import club.joylink.rtss.vo.race.RaceTask.RacePaperModuleTask;
|
||||
import club.joylink.rtss.vo.race.RaceTask.RacePaperModuleTask.PaperModuleGroup;
|
||||
import club.joylink.rtss.vo.race.RaceTask.RaceTaskChildVO;
|
||||
import club.joylink.rtss.vo.race.RaceTaskDetailDTO;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -35,6 +42,8 @@ public class RacePaperService {
|
|||
|
||||
@Autowired
|
||||
private RacetrPaperDAO paperDAO;
|
||||
@Autowired
|
||||
private RaceTaskService taskService;
|
||||
|
||||
private RacetrPaper findId(Long id) {
|
||||
RacetrPaper rp = this.paperDAO.selectByPrimaryKey(id);
|
||||
|
@ -52,7 +61,6 @@ public class RacePaperService {
|
|||
rp.setUpdateTime(now);
|
||||
rp.setCreatorId(user.getId());
|
||||
rp.setUpdaterId(user.getId());
|
||||
// rp.setSupportCopy(createVO.getSupportCopy());
|
||||
this.paperDAO.insertSelective(rp);
|
||||
}
|
||||
|
||||
|
@ -63,7 +71,6 @@ public class RacePaperService {
|
|||
rp.setSeasonId(updateVO.getSeasonId());
|
||||
rp.setUpdateTime(LocalDateTime.now());
|
||||
rp.setUpdaterId(user.getId());
|
||||
// rp.setSupportCopy(updateVO.getSupportCopy());
|
||||
this.paperDAO.updateByPrimaryKey(rp);
|
||||
|
||||
}
|
||||
|
@ -90,7 +97,6 @@ public class RacePaperService {
|
|||
builder.setModifyInfo(modifyInfoVO);
|
||||
builder.setSeasonId(rp.getSeasonId());
|
||||
builder.setSeasonName(Objects.isNull(rp.getSeasonName()) ? "" : rp.getSeasonName());
|
||||
// builder.setSupportCopy(!Objects.isNull(rp.getSupportCopy()) && rp.getSupportCopy());
|
||||
builder.setGroup(Group.Unknown);
|
||||
if (Objects.nonNull(rp.getGroup())) {
|
||||
builder.setGroup(Group.valueOf(rp.getGroup()));
|
||||
|
@ -162,11 +168,9 @@ public class RacePaperService {
|
|||
|
||||
public void copy(Long id, AccountVO user) {
|
||||
RacetrPaper paper = this.findId(id);
|
||||
// BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(paper.getSupportCopy(), "此试卷不支持拷贝");
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
paper.setId(null);
|
||||
paper.setName(String.format("%s_copy", paper.getName()));
|
||||
// paper.setSupportCopy(!Objects.isNull(paper.getSupportCopy()) && paper.getSupportCopy());
|
||||
paper.setCreatorId(user.getId());
|
||||
paper.setUpdaterId(user.getId());
|
||||
paper.setCreateTime(now);
|
||||
|
@ -174,15 +178,89 @@ public class RacePaperService {
|
|||
this.paperDAO.insert(paper);
|
||||
}
|
||||
|
||||
public void paperModuleTask(Long paperId, Integer moduleId) {
|
||||
public RacePaperModuleTask paperModuleTask(Long paperId, Integer moduleId) {
|
||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(moduleId), "请选择对应的模型");
|
||||
RacePaperDetailVO detailVO = this.detail(paperId);
|
||||
RacePaperModuleVO moduleVO = detailVO.getModuleVo();
|
||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(CollectionUtils.isEmpty(moduleVO.getModulesList()), "此试卷没有模块数据");
|
||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(!CollectionUtils.isEmpty(moduleVO.getModulesList()), "此试卷没有模块数据");
|
||||
PaperModule pm = moduleVO.getModulesList().stream().filter(d -> d.getCustomModuleId() == moduleId).findFirst().orElse(null);
|
||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(pm), "没有找到对应的模块");
|
||||
for (RacePaperModuleVO.Group moduleGroup : pm.getGroupList()) {
|
||||
|
||||
List<Long> allGroupTaskIds = this.collectAllTaskIds(pm.getGroupList());
|
||||
Map<Long, List<RaceTaskDetailDTO>> taskMapList = this.taskService.recursiveFindTask(allGroupTaskIds);
|
||||
RacePaperModuleTask.Builder modultTask = RacePaperModuleTask.newBuilder();
|
||||
modultTask.setCustomModuleId(pm.getCustomModuleId());
|
||||
List<PaperModuleGroup> convertGroupList = this.convert(pm.getGroupList(), taskMapList);
|
||||
modultTask.addAllModuleGroup(convertGroupList);
|
||||
return modultTask.build();
|
||||
}
|
||||
|
||||
private List<PaperModuleGroup> convert(List<RacePaperModuleVO.Group> groupList, Map<Long, List<RaceTaskDetailDTO>> allTaskMapList) {
|
||||
List<PaperModuleGroup> groups = new ArrayList<>();
|
||||
for (RacePaperModuleVO.Group group : groupList) {
|
||||
PaperModuleGroup.Builder groupBuilder = PaperModuleGroup.newBuilder();
|
||||
groupBuilder.setGroupName(group.getName());
|
||||
for (Long taskId : group.getTaskIdsList()) {
|
||||
RaceTaskChildVO taskVO = this.findTask(taskId, allTaskMapList);
|
||||
groupBuilder.addTreeData(taskVO);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(group.getGroupList())) {
|
||||
List<PaperModuleGroup> childGroup = this.convert(group.getGroupList(), allTaskMapList);
|
||||
groupBuilder.addAllModuleGroup(childGroup);
|
||||
}
|
||||
groups.add(groupBuilder.build());
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
private RaceTaskChildVO findTask(Long taskId, Map<Long, List<RaceTaskDetailDTO>> allTaskMapList) {
|
||||
List<RaceTaskDetailDTO> dtoList = allTaskMapList.get(RaceTaskService.TASK_ROOT_ID);
|
||||
RaceTaskDetailDTO taskDto = dtoList.stream().filter(d -> Objects.equals(d.getId(), taskId)).findFirst().orElse(null);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(taskDto), String.format("对应的任务没有找到[%s]", taskDto));
|
||||
RaceTaskChildVO.Builder vo = this.convertVO(taskDto);
|
||||
this.childTask(vo, allTaskMapList);
|
||||
return vo.build();
|
||||
}
|
||||
|
||||
private void childTask(RaceTaskChildVO.Builder vob, Map<Long, List<RaceTaskDetailDTO>> allTaskMapList) {
|
||||
List<RaceTaskDetailDTO> childDto = allTaskMapList.get(vob.getId());
|
||||
if (!CollectionUtils.isEmpty(childDto)) {
|
||||
for (RaceTaskDetailDTO ch : childDto) {
|
||||
RaceTaskChildVO.Builder chvo = this.convertVO(ch);
|
||||
vob.addChildren(chvo);
|
||||
this.childTask(chvo, allTaskMapList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private RaceTaskChildVO.Builder convertVO(RaceTaskDetailDTO dto) {
|
||||
RaceTaskChildVO.Builder cb = RaceTaskChildVO.newBuilder();
|
||||
cb.setId(dto.getId());
|
||||
cb.setName(dto.getName());
|
||||
cb.setDesc(dto.getDesc());
|
||||
cb.setContent(dto.getContent());
|
||||
cb.setStandards(dto.getStandards());
|
||||
|
||||
return cb;
|
||||
}
|
||||
|
||||
|
||||
private List<Long> collectAllTaskIds(List<RacePaperModuleVO.Group> groupList) {
|
||||
List<Long> allTaskIds = Lists.newArrayList();
|
||||
for (RacePaperModuleVO.Group group : groupList) {
|
||||
this.collectTaskIds(group, allTaskIds);
|
||||
}
|
||||
return allTaskIds.stream().distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void collectTaskIds(RacePaperModuleVO.Group group, List<Long> collectorList) {
|
||||
collectorList.addAll(group.getTaskIdsList());
|
||||
if (!CollectionUtils.isEmpty(group.getGroupList())) {
|
||||
for (RacePaperModuleVO.Group group1 : group.getGroupList()) {
|
||||
this.collectTaskIds(group1, collectorList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public class RaceTaskService {
|
|||
@Autowired
|
||||
private RacetrTaskDAO raceTaskDAO;
|
||||
|
||||
private final static Long TASK_ROOT_ID = 0L;
|
||||
protected final static Long TASK_ROOT_ID = 0L;
|
||||
|
||||
private RacetrTask findById(Long id) {
|
||||
RacetrTask task = this.raceTaskDAO.selectByPrimaryKey(id);
|
||||
|
@ -179,4 +179,10 @@ public class RaceTaskService {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Long, List<RaceTaskDetailDTO>> recursiveFindTask(List<Long> taskIds) {
|
||||
List<RaceTaskDetailDTO> taskDtoList = this.raceTaskDAO.recursiveFindTask(taskIds);
|
||||
Map<Long, List<RaceTaskDetailDTO>> dtoMapList = taskDtoList.stream().collect(Collectors.groupingBy(RaceTaskDetailDTO::getParentId));
|
||||
return dtoMapList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -322,4 +322,14 @@
|
|||
update_time = #{updateTime,jdbcType=TIMESTAMP}
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</update>
|
||||
<select id="recursiveFindTask" parameterType="arraylist" resultType="club.joylink.rtss.vo.race.RaceTaskDetailDTO">
|
||||
WITH RECURSIVE task as
|
||||
(select id,name,`desc`,content,standards,scene_id,score_rule_id, 0 as parent_id from racetr_task where id in
|
||||
<foreach collection="taskIds" item="d" separator="," open="(" close=")">
|
||||
#{d}
|
||||
</foreach>
|
||||
UNION all
|
||||
select A.id,A.name,A.desc,A.content,A.standards,A.score_rule_id,A.score_rule_id,A.parent_id from racetr_task A, task B where A.parent_id = B.id)
|
||||
select * from task
|
||||
</select>
|
||||
</mapper>
|
|
@ -8,6 +8,7 @@ import club.joylink.rtss.vo.race.RacePaper.RacePaperCreateVO;
|
|||
import club.joylink.rtss.vo.race.RacePaper.RacePaperVO;
|
||||
import club.joylink.rtss.vo.race.RacePaperQueryVO;
|
||||
import club.joylink.rtss.vo.race.RaceSeasonOuterClass.RaceSeason.Group;
|
||||
import club.joylink.rtss.vo.race.RaceTask.RacePaperModuleTask;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
@ -43,4 +44,9 @@ public class PaperServiceTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paperModuleTaskTest() {
|
||||
RacePaperModuleTask moduleTask = this.paperService.paperModuleTask(13L, 2);
|
||||
System.out.println(JsonUtils.writeValueAsString(moduleTask));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue