Exam->PaperComposition;UserExam->PaperUser

This commit is contained in:
joylink_zhangsai 2022-12-06 10:50:52 +08:00
parent 50d028d92a
commit 38868f2ea7

View File

@ -2,15 +2,38 @@ package club.joylink.rtss.controller.paper;
import club.joylink.rtss.constants.RoleEnum;
import club.joylink.rtss.controller.advice.Role;
import club.joylink.rtss.dao.ExamDefinitionDAO;
import club.joylink.rtss.dao.ExamDefinitionRulesDAO;
import club.joylink.rtss.dao.OrgDAO;
import club.joylink.rtss.dao.UserExamMapper;
import club.joylink.rtss.dao.org.OrgProjectDao;
import club.joylink.rtss.dao.paper.PaperUserDAO;
import club.joylink.rtss.entity.ExamDefinitionExample;
import club.joylink.rtss.entity.UserExam;
import club.joylink.rtss.entity.UserExamExample;
import club.joylink.rtss.entity.org.OrgProject;
import club.joylink.rtss.entity.paper.PaperUser;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.IMapService;
import club.joylink.rtss.services.paper.PaperCompositionService;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.map.MapVO;
import club.joylink.rtss.vo.paper.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* 试卷蓝图业务接口
@ -27,6 +50,7 @@ public class PaperCompositionController {
/**
* 数据管理查询
*
* @param req
* @return
*/
@ -35,9 +59,11 @@ public class PaperCompositionController {
public PageVO<PaperCompositionWithRuleVo> findPaperCompositionForPage(@RequestBody FindPaperCompositionPageReqVo req) {
return this.compositionService.findPaperCompositionByPage(req);
}
/**
* 创建试卷蓝图包括规则定义
* 参数 tags 只支持单个
*
* @param orgId 组织id
*/
@PostMapping("/{orgId}")
@ -99,6 +125,7 @@ public class PaperCompositionController {
public List<PaperCompositionWithRuleVo> findPaperCompositionByList(@RequestBody FindPaperCompositionPageReqVo req) {
return this.compositionService.findPaperCompositionList(req);
}
/**
* 根据试卷蓝图名称简介分页查找某个组织的试卷蓝图
*/
@ -123,6 +150,95 @@ public class PaperCompositionController {
*/
@GetMapping("/{pcId}")
public PaperCompositionWithRuleVo findPaperComposition(@PathVariable("pcId") Long pcId, @RequestAttribute AccountVO user) {
return this.compositionService.findPaperComposition(pcId,user);
return this.compositionService.findPaperComposition(pcId, user);
}
@Autowired
ExamDefinitionDAO examDefinitionDAO;
@Autowired
ExamDefinitionRulesDAO examDefinitionRulesDAO;
@Autowired
IMapService iMapService;
@Autowired
OrgDAO orgDAO;
@Autowired
OrgProjectDao orgProjectDao;
@Autowired
UserExamMapper userExamMapper;
@Autowired
private PaperUserDAO paperUserDAO;
/**
* 旧数据处理接口用完删除
*/
@Transactional
@PostMapping("/oldData/handle")
public List<String> oldDataHandle(@RequestAttribute AccountVO user) {
List<String> msg = new ArrayList<>();
//所有在线地图
Map<Long, MapVO> onlineMaps = iMapService.listOnline().stream().collect(Collectors.toMap(MapVO::getId, Function.identity()));
//所有项目-组织对应关系
Map<String, Long> projectCode_orgId_map = orgProjectDao.selectByExample(null).stream().collect(Collectors.toMap(OrgProject::getProjectCode, OrgProject::getOrgId));
//转化试卷并记录试卷id变化
ExamDefinitionExample examDefinitionExample = new ExamDefinitionExample();
examDefinitionExample.createCriteria().andStatusEqualTo("1");
Map<Long, Long> old_newExamIdMap = new HashMap<>();
examDefinitionDAO.selectByExample(examDefinitionExample).stream()
.filter(exam -> {
if (exam.getOrgId() != null) {
return true;
}
MapVO map = onlineMaps.get(exam.getMapId());
if (map == null) {
msg.add(String.format("[id:%s]的试卷对应的地图[id:%s]不存在或已下架", exam.getId(), exam.getMapId()));
return false;
}
String projectCode = map.getProjectCode();
if (!StringUtils.hasText(projectCode)) {
exam.setOrgId(projectCode_orgId_map.get("DEFAULT"));
} else {
exam.setOrgId(projectCode_orgId_map.get(projectCode));
}
return true;
}).forEach(exam -> {
PaperCompositionWithRuleVo paperCompositionWithRuleVo = new PaperCompositionWithRuleVo();
paperCompositionWithRuleVo.setMapId(exam.getMapId());
paperCompositionWithRuleVo.setName(exam.getName());
paperCompositionWithRuleVo.setProfile(exam.getRemarks());
paperCompositionWithRuleVo.setOrgId(exam.getOrgId());
paperCompositionWithRuleVo.setStartTime(exam.getStartTime());
paperCompositionWithRuleVo.setEndTime(exam.getEndTime());
paperCompositionWithRuleVo.setValidDuration(exam.getDuration() / 60);
paperCompositionWithRuleVo.setPassScore(exam.getPassingPoint());
paperCompositionWithRuleVo.setFullScore(exam.getFullPoint());
paperCompositionWithRuleVo.setCreatorId(exam.getCreatorId());
paperCompositionWithRuleVo.setCreateTime(exam.getCreateTime());
paperCompositionWithRuleVo.setUpdateTime(null);
paperCompositionWithRuleVo.setState(PaperCompositionState.Locked);
CreatePaperCompositionRspVo paperComposition = createPaperCompositionWithRuleForOrg(exam.getOrgId(), paperCompositionWithRuleVo, user);
old_newExamIdMap.put(exam.getId(), paperComposition.getId());
});
//查询试卷记录
ArrayList<Long> oldExamIds = new ArrayList<>(old_newExamIdMap.keySet());
UserExamExample userExamExample = new UserExamExample();
userExamExample.createCriteria().andExamIdIn(oldExamIds);
List<UserExam> userExams = userExamMapper.selectByExample(userExamExample);
//转化试卷记录
LocalDateTime now = LocalDateTime.now();
for (UserExam userExam : userExams) {
PaperUser paperUser = new PaperUser();
paperUser.setUserId(userExam.getUserId());
Long newExamId = old_newExamIdMap.get(userExam.getExamId());
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(newExamId);
paperUser.setPcId(newExamId);
paperUser.setScore(userExam.getScore().intValue());
paperUser.setStartTime(userExam.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
if (userExam.getEndTime() != null) {
paperUser.setEndTime(userExam.getEndTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
}
paperUser.setCreateTime(now);
paperUserDAO.insert(paperUser);
}
return msg;
}
}