|
|
|
@ -1,19 +1,35 @@
|
|
|
|
|
package com.tz.platform.competitiion.api.biz;
|
|
|
|
|
|
|
|
|
|
import com.tz.platform.common.core.base.Result;
|
|
|
|
|
import com.tz.platform.common.core.bo.GroupCat;
|
|
|
|
|
import com.tz.platform.common.core.bo.SubQuestionVO;
|
|
|
|
|
import com.tz.platform.common.core.tools.BeanUtils;
|
|
|
|
|
import com.tz.platform.common.core.tools.DateUtil;
|
|
|
|
|
import com.tz.platform.competitiion.api.dto.ExamDTO;
|
|
|
|
|
import com.tz.platform.competitiion.api.dto.SubmitResultDTO;
|
|
|
|
|
import com.tz.platform.competitiion.api.vo.SubmitQuestionVO;
|
|
|
|
|
import com.tz.platform.competitiion.api.vo.SubmitVo;
|
|
|
|
|
import com.tz.platform.entity.CompetitionGroup;
|
|
|
|
|
import com.tz.platform.entity.CompetitionMember;
|
|
|
|
|
import com.tz.platform.entity.CompetitionTask;
|
|
|
|
|
import com.tz.platform.entity.ExamPaper;
|
|
|
|
|
import com.tz.platform.feign.exam.IFeignExam;
|
|
|
|
|
import com.tz.platform.feign.exam.qo.CacheQuetionQO;
|
|
|
|
|
import com.tz.platform.feign.exam.qo.QuestionQO;
|
|
|
|
|
import com.tz.platform.feign.exam.qo.CacheQuestionQO;
|
|
|
|
|
import com.tz.platform.feign.exam.vo.QuestionVo;
|
|
|
|
|
import com.tz.platform.feign.user.IFeignUser;
|
|
|
|
|
import com.tz.platform.feign.user.vo.UserVo;
|
|
|
|
|
import com.tz.platform.repository.CompetitionGroupDao;
|
|
|
|
|
import com.tz.platform.repository.CompetitionMemberDao;
|
|
|
|
|
import com.tz.platform.repository.CompetitionTaskDao;
|
|
|
|
|
import com.tz.platform.repository.ExamPaperDao;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
|
public class CompetitionExamBiz {
|
|
|
|
@ -27,19 +43,37 @@ public class CompetitionExamBiz {
|
|
|
|
|
@Autowired
|
|
|
|
|
private CompetitionGroupDao groupDao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CompetitionMemberDao competitionMemberDao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ExamPaperDao examPaperDao;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IFeignExam feignExam;
|
|
|
|
|
|
|
|
|
|
public List<QuestionVo> getExamQuestion(Long compId,Integer stageId,Long userId){
|
|
|
|
|
|
|
|
|
|
UserVo currentUser = feignUser.getByUserNo(userId);
|
|
|
|
|
CompetitionTask task = competitionTaskDao.getByCompetitionIdAndStageId(compId,stageId);
|
|
|
|
|
|
|
|
|
|
List<CompetitionGroup> groupList = groupDao.findByCompetitionId(compId);
|
|
|
|
|
//学生层次限制
|
|
|
|
|
List<CompetitionGroup> limitList = groupList.stream().filter(g->g.getLimitType() == 1).collect(Collectors.toList());
|
|
|
|
|
List<Long> ids = new ArrayList<>();
|
|
|
|
|
task.getQuestionList().forEach(taskQuestion -> {
|
|
|
|
|
if(taskQuestion.getGroupId().equals(0)){
|
|
|
|
|
ids.addAll(taskQuestion.getQuestionIds());
|
|
|
|
|
}else{
|
|
|
|
|
//不同学生层次不同案例题
|
|
|
|
|
CompetitionGroup group = limitList.stream().filter(g->g.getId() .equals(taskQuestion.getGroupId())).findFirst().orElse(null);
|
|
|
|
|
if(group!=null) {
|
|
|
|
|
GroupCat groupCat = group.getCatList().stream().filter(groupCat1 -> groupCat1.getId().equals(currentUser.getLevelId())).findFirst().orElse(null);
|
|
|
|
|
if (groupCat != null) {
|
|
|
|
|
ids.addAll(taskQuestion.getQuestionIds());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
CacheQuetionQO qo = new CacheQuetionQO();
|
|
|
|
|
CacheQuestionQO qo = new CacheQuestionQO();
|
|
|
|
|
qo.setIds(ids);
|
|
|
|
|
List<QuestionVo> questionVos = feignExam.listQusetion(qo);
|
|
|
|
|
return questionVos;
|
|
|
|
@ -48,7 +82,117 @@ public class CompetitionExamBiz {
|
|
|
|
|
private List<QuestionVo> getQList(List<QuestionVo> qList,Long userId){
|
|
|
|
|
UserVo userVo = feignUser.getByUserNo(userId);
|
|
|
|
|
System.out.println(userVo.getLevelId());
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
public Result<ExamDTO> startExam(Long compId, Integer stageId, Long userNo){
|
|
|
|
|
CompetitionMember member = competitionMemberDao.getByCompetitionIdAndStageIdAndUserId(compId,stageId,userNo);
|
|
|
|
|
if(member == null){
|
|
|
|
|
return Result.error("未报名该大赛或赛段");
|
|
|
|
|
}
|
|
|
|
|
if(member.getExamStartTime()!=null){
|
|
|
|
|
ExamDTO dto = new ExamDTO();
|
|
|
|
|
dto.setStartTime(member.getExamStartTime());
|
|
|
|
|
dto.setEndTime(DateUtil.addHours(member.getExamStartTime(),1));
|
|
|
|
|
return Result.success(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Date examStartTime = new Date();
|
|
|
|
|
Date examEndTime = DateUtil.addHours(examStartTime,1);
|
|
|
|
|
int affect = competitionMemberDao.updateExamStartTime(userNo,stageId,compId,examStartTime);
|
|
|
|
|
if(affect>0){
|
|
|
|
|
ExamDTO dto = new ExamDTO();
|
|
|
|
|
dto.setStartTime(examStartTime);
|
|
|
|
|
dto.setEndTime(examEndTime);
|
|
|
|
|
return Result.success(dto);
|
|
|
|
|
}
|
|
|
|
|
return Result.error("failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
public Result<SubmitResultDTO> submit(SubmitVo vo){
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
CompetitionMember member = competitionMemberDao.getByCompetitionIdAndStageIdAndUserId(vo.getCompId(),vo.getStageId(),vo.getUserNo());
|
|
|
|
|
if(member.getExamScore()!=null){
|
|
|
|
|
SubmitResultDTO dto = new SubmitResultDTO();
|
|
|
|
|
dto.setScore(member.getExamScore());
|
|
|
|
|
return Result.success(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Long costTime =now.getTime() - member.getExamStartTime().getTime();
|
|
|
|
|
if(costTime >3600000){
|
|
|
|
|
return Result.error("考试超时");
|
|
|
|
|
}
|
|
|
|
|
CompetitionTask task = competitionTaskDao.getByCompetitionIdAndStageId(vo.getCompId(),vo.getStageId());
|
|
|
|
|
if(task.getExamEndTime().getTime()<now.getTime()){
|
|
|
|
|
return Result.error("考试超时");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SubmitResultDTO dto = new SubmitResultDTO();
|
|
|
|
|
List<QuestionVo> questionVoList = getExamQuestion(vo.getCompId(),vo.getStageId(),vo.getUserNo());
|
|
|
|
|
Long score = computeScore(questionVoList,vo.getQList());
|
|
|
|
|
competitionMemberDao.updateScore(vo.getUserNo(),vo.getStageId(),vo.getCompId(),score);
|
|
|
|
|
competitionMemberDao.updateExamEndTimeAndCostTime(vo.getUserNo(),vo.getStageId(),vo.getCompId(),now,costTime);
|
|
|
|
|
ExamPaper paper = BeanUtils.copyProperties(vo,ExamPaper.class);
|
|
|
|
|
paper.setId(paper.getCompId()+"_"+paper.getStageId()+"_"+paper.getUserNo());
|
|
|
|
|
examPaperDao.save(paper);
|
|
|
|
|
dto.setScore(score);
|
|
|
|
|
return Result.success(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//计算得分
|
|
|
|
|
private Long computeScore(List<QuestionVo> questionVoList, List<SubmitQuestionVO> submitQuestionVOS){
|
|
|
|
|
Long totalScore = 0L;
|
|
|
|
|
for(int j = 0;j< submitQuestionVOS.size();j++)
|
|
|
|
|
{
|
|
|
|
|
SubmitQuestionVO submitQuestionVO = submitQuestionVOS.get(j);
|
|
|
|
|
QuestionVo q = questionVoList.stream().filter(questionVo -> questionVo.getId().equals(submitQuestionVO.getId())).findFirst().orElse(null);
|
|
|
|
|
if(q == null) { continue; }
|
|
|
|
|
if(q.getType() == 0){
|
|
|
|
|
//普通题
|
|
|
|
|
if(checkCorrect(q.getAnswerId(),submitQuestionVO.getIds())){
|
|
|
|
|
totalScore += q.getScore();
|
|
|
|
|
}
|
|
|
|
|
// if(q.getAnswerId().size() == submitQuestionVO.getIds().size()){
|
|
|
|
|
// boolean crorrect = true;
|
|
|
|
|
// for(int i = 0 ;i <submitQuestionVO.getIds().size();i++){
|
|
|
|
|
// if(q.getAnswerId().indexOf(submitQuestionVO.getIds().get(i))<0){
|
|
|
|
|
// crorrect = false;
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// if(crorrect){
|
|
|
|
|
// totalScore+= q.getScore();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
}else{
|
|
|
|
|
//案例题
|
|
|
|
|
SubQuestionVO subQuestionVO = q.getChildren().stream().filter(subQuestionVO1 -> subQuestionVO1.getId().intValue() == submitQuestionVO.getSubId()).findFirst().orElse(null);
|
|
|
|
|
if(subQuestionVO == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(checkCorrect(subQuestionVO.getAnswerId(),submitQuestionVO.getIds())){
|
|
|
|
|
totalScore += subQuestionVO.getScore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return totalScore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean checkCorrect(List<Integer> answerId,List<Integer> checkList){
|
|
|
|
|
if(checkList ==null&&checkList.size() == 0) {return false;}
|
|
|
|
|
if(answerId.size() == checkList.size()){
|
|
|
|
|
boolean correct = true;
|
|
|
|
|
for(int i = 0 ;i <checkList.size();i++){
|
|
|
|
|
if(answerId.indexOf(checkList.get(i))<0){
|
|
|
|
|
correct = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return correct;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|