|
|
@ -51,28 +51,28 @@ public class CompetitionExamBiz {
|
|
|
|
private IFeignExam feignExam;
|
|
|
|
private IFeignExam feignExam;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RedisTemplate<String,Object> template;
|
|
|
|
private RedisTemplate<String, Object> template;
|
|
|
|
|
|
|
|
|
|
|
|
public List<QuestionVo> getExamQuestion(Long compId,Integer stageId,Long userId,Integer type ){
|
|
|
|
public List<QuestionVo> getExamQuestion(Long compId, Integer stageId, Long userId, Integer type) {
|
|
|
|
UserVo currentUser = feignUser.getByUserNo(userId);
|
|
|
|
UserVo currentUser = feignUser.getByUserNo(userId);
|
|
|
|
String key = "questionList_"+compId+"_"+stageId+"_"+currentUser.getLevelId();
|
|
|
|
String key = "questionList_" + compId + "_" + stageId + "_" + currentUser.getLevelId();
|
|
|
|
Object questListObj = template.opsForValue().get(key);
|
|
|
|
Object questListObj = template.opsForValue().get(key);
|
|
|
|
List<QuestionVo> questionVos = null;
|
|
|
|
List<QuestionVo> questionVos = null;
|
|
|
|
if(questListObj!=null){
|
|
|
|
if (questListObj != null) {
|
|
|
|
questionVos = ( List<QuestionVo>) questListObj;
|
|
|
|
questionVos = (List<QuestionVo>) questListObj;
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
CompetitionTask task = competitionTaskDao.getByCompetitionIdAndStageId(compId,stageId);
|
|
|
|
CompetitionTask task = competitionTaskDao.getByCompetitionIdAndStageId(compId, stageId);
|
|
|
|
List<CompetitionGroup> groupList = groupDao.findByCompetitionId(compId);
|
|
|
|
List<CompetitionGroup> groupList = groupDao.findByCompetitionId(compId);
|
|
|
|
//学生层次限制
|
|
|
|
//学生层次限制
|
|
|
|
List<CompetitionGroup> limitList = groupList.stream().filter(g->g.getLimitType() == 1).collect(Collectors.toList());
|
|
|
|
List<CompetitionGroup> limitList = groupList.stream().filter(g -> g.getLimitType() == 1).collect(Collectors.toList());
|
|
|
|
List<Long> ids = new ArrayList<>();
|
|
|
|
List<Long> ids = new ArrayList<>();
|
|
|
|
task.getQuestionList().forEach(taskQuestion -> {
|
|
|
|
task.getQuestionList().forEach(taskQuestion -> {
|
|
|
|
if(taskQuestion.getGroupId().equals(0)){
|
|
|
|
if (taskQuestion.getGroupId().equals(0)) {
|
|
|
|
ids.addAll(taskQuestion.getQuestionIds());
|
|
|
|
ids.addAll(taskQuestion.getQuestionIds());
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
//不同学生层次不同案例题
|
|
|
|
//不同学生层次不同案例题
|
|
|
|
CompetitionGroup group = limitList.stream().filter(g->g.getId() .equals(taskQuestion.getGroupId())).findFirst().orElse(null);
|
|
|
|
CompetitionGroup group = limitList.stream().filter(g -> g.getId().equals(taskQuestion.getGroupId())).findFirst().orElse(null);
|
|
|
|
if(group!=null) {
|
|
|
|
if (group != null) {
|
|
|
|
GroupCat groupCat = group.getCatList().stream().filter(groupCat1 -> groupCat1.getId().equals(currentUser.getLevelId())).findFirst().orElse(null);
|
|
|
|
GroupCat groupCat = group.getCatList().stream().filter(groupCat1 -> groupCat1.getId().equals(currentUser.getLevelId())).findFirst().orElse(null);
|
|
|
|
if (groupCat != null) {
|
|
|
|
if (groupCat != null) {
|
|
|
|
ids.addAll(taskQuestion.getQuestionIds());
|
|
|
|
ids.addAll(taskQuestion.getQuestionIds());
|
|
|
@ -84,12 +84,12 @@ public class CompetitionExamBiz {
|
|
|
|
qo.setIds(ids);
|
|
|
|
qo.setIds(ids);
|
|
|
|
questionVos = feignExam.listQusetion(qo);
|
|
|
|
questionVos = feignExam.listQusetion(qo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(type == 0){
|
|
|
|
if (type == 0) {
|
|
|
|
questionVos.forEach(questionVo -> {
|
|
|
|
questionVos.forEach(questionVo -> {
|
|
|
|
if(questionVo.getType() == 0){
|
|
|
|
if (questionVo.getType() == 0) {
|
|
|
|
questionVo.setAnswerId(new ArrayList<>());
|
|
|
|
questionVo.setAnswerId(new ArrayList<>());
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
questionVo.getChildren().forEach(child->{
|
|
|
|
questionVo.getChildren().forEach(child -> {
|
|
|
|
child.setAnswerId(new ArrayList<>());
|
|
|
|
child.setAnswerId(new ArrayList<>());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -99,34 +99,34 @@ public class CompetitionExamBiz {
|
|
|
|
return questionVos;
|
|
|
|
return questionVos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<QuestionVo> getQList(List<QuestionVo> qList,Long userId){
|
|
|
|
private List<QuestionVo> getQList(List<QuestionVo> qList, Long userId) {
|
|
|
|
UserVo userVo = feignUser.getByUserNo(userId);
|
|
|
|
UserVo userVo = feignUser.getByUserNo(userId);
|
|
|
|
System.out.println(userVo.getLevelId());
|
|
|
|
System.out.println(userVo.getLevelId());
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public Result<ExamDTO> startExam(Long compId, Integer stageId, Long userNo){
|
|
|
|
public Result<ExamDTO> startExam(Long compId, Integer stageId, Long userNo) {
|
|
|
|
CompetitionMember member = competitionMemberDao.getByCompetitionIdAndStageIdAndUserId(compId,stageId,userNo);
|
|
|
|
CompetitionMember member = competitionMemberDao.getByCompetitionIdAndStageIdAndUserId(compId, stageId, userNo);
|
|
|
|
CompetitionTask task = competitionTaskDao.getByCompetitionIdAndStageId(compId,stageId);
|
|
|
|
CompetitionTask task = competitionTaskDao.getByCompetitionIdAndStageId(compId, stageId);
|
|
|
|
if(member == null){
|
|
|
|
if (member == null) {
|
|
|
|
return Result.error("未报名该大赛或赛段");
|
|
|
|
return Result.error("未报名该大赛或赛段");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(task.getExamDuration() == null){
|
|
|
|
if (task.getExamDuration() == null) {
|
|
|
|
return Result.error("试卷设置错误");
|
|
|
|
return Result.error("试卷设置错误");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(member.getExamStartTime()!=null){
|
|
|
|
if (member.getExamStartTime() != null) {
|
|
|
|
ExamDTO dto = new ExamDTO();
|
|
|
|
ExamDTO dto = new ExamDTO();
|
|
|
|
dto.setStartTime(member.getExamStartTime());
|
|
|
|
dto.setStartTime(member.getExamStartTime());
|
|
|
|
dto.setEndTime(DateUtil.addHours(member.getExamStartTime(),task.getExamDuration()));
|
|
|
|
dto.setEndTime(DateUtil.addHours(member.getExamStartTime(), task.getExamDuration()));
|
|
|
|
return Result.success(dto);
|
|
|
|
return Result.success(dto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Date examStartTime = new Date();
|
|
|
|
Date examStartTime = new Date();
|
|
|
|
Date examEndTime = DateUtil.addHours(examStartTime,task.getExamDuration());
|
|
|
|
Date examEndTime = DateUtil.addHours(examStartTime, task.getExamDuration());
|
|
|
|
int affect = competitionMemberDao.updateExamStartTime(userNo,stageId,compId,examStartTime);
|
|
|
|
int affect = competitionMemberDao.updateExamStartTime(userNo, stageId, compId, examStartTime);
|
|
|
|
if(affect>0){
|
|
|
|
if (affect > 0) {
|
|
|
|
ExamDTO dto = new ExamDTO();
|
|
|
|
ExamDTO dto = new ExamDTO();
|
|
|
|
dto.setStartTime(examStartTime);
|
|
|
|
dto.setStartTime(examStartTime);
|
|
|
|
dto.setEndTime(examEndTime);
|
|
|
|
dto.setEndTime(examEndTime);
|
|
|
@ -136,56 +136,64 @@ public class CompetitionExamBiz {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public Result<SubmitResultDTO> submit(SubmitVo vo){
|
|
|
|
public Result<SubmitResultDTO> submit(SubmitVo vo) {
|
|
|
|
Date now = new Date();
|
|
|
|
Date now = new Date();
|
|
|
|
CompetitionMember member = competitionMemberDao.getByCompetitionIdAndStageIdAndUserId(vo.getCompId(),vo.getStageId(),vo.getUserNo());
|
|
|
|
CompetitionMember member = competitionMemberDao.getByCompetitionIdAndStageIdAndUserId(vo.getCompId(), vo.getStageId(), vo.getUserNo());
|
|
|
|
if(member.getExamScore()!=null){
|
|
|
|
if (member.getExamScore() != null) {
|
|
|
|
SubmitResultDTO dto = new SubmitResultDTO();
|
|
|
|
SubmitResultDTO dto = new SubmitResultDTO();
|
|
|
|
dto.setScore(member.getExamScore());
|
|
|
|
dto.setScore(member.getExamScore());
|
|
|
|
return Result.success(dto);
|
|
|
|
return Result.success(dto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CompetitionTask task = competitionTaskDao.getByCompetitionIdAndStageId(vo.getCompId(),vo.getStageId());
|
|
|
|
CompetitionTask task = competitionTaskDao.getByCompetitionIdAndStageId(vo.getCompId(), vo.getStageId());
|
|
|
|
Long costTime =now.getTime() - member.getExamStartTime().getTime();
|
|
|
|
Long costTime = now.getTime() - member.getExamStartTime().getTime();
|
|
|
|
if(costTime >3600000*task.getExamDuration()){
|
|
|
|
if (costTime > 3600000L * task.getExamDuration()) {
|
|
|
|
return Result.error("考试超时");
|
|
|
|
return Result.error("考试超时");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(task.getExamEndTime().getTime()<now.getTime()){
|
|
|
|
if (task.getExamEndTime().getTime() < now.getTime()) {
|
|
|
|
return Result.error("考试超时");
|
|
|
|
return Result.error("考试超时");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SubmitResultDTO dto = new SubmitResultDTO();
|
|
|
|
SubmitResultDTO dto = new SubmitResultDTO();
|
|
|
|
List<QuestionVo> questionVoList = getExamQuestion(vo.getCompId(),vo.getStageId(),vo.getUserNo(),1);
|
|
|
|
List<QuestionVo> questionVoList = getExamQuestion(vo.getCompId(), vo.getStageId(), vo.getUserNo(), 1);
|
|
|
|
Double score = computeScore(questionVoList,vo.getQList());
|
|
|
|
Double score = computeScore(questionVoList, vo.getQList());
|
|
|
|
competitionMemberDao.updateScore(vo.getUserNo(),vo.getStageId(),vo.getCompId(),score);
|
|
|
|
competitionMemberDao.updateScore(vo.getUserNo(), vo.getStageId(), vo.getCompId(), score);
|
|
|
|
competitionMemberDao.updateExamEndTimeAndCostTime(vo.getUserNo(),vo.getStageId(),vo.getCompId(),now,costTime);
|
|
|
|
competitionMemberDao.updateExamEndTimeAndCostTime(vo.getUserNo(), vo.getStageId(), vo.getCompId(), now, costTime);
|
|
|
|
ExamPaper paper = BeanUtils.copyProperties(vo,ExamPaper.class);
|
|
|
|
ExamPaper paper = BeanUtils.copyProperties(vo, ExamPaper.class);
|
|
|
|
paper.setId(paper.getCompId()+"_"+paper.getStageId()+"_"+paper.getUserNo());
|
|
|
|
paper.setId(paper.getCompId() + "_" + paper.getStageId() + "_" + paper.getUserNo());
|
|
|
|
examPaperDao.save(paper);
|
|
|
|
examPaperDao.save(paper);
|
|
|
|
dto.setScore(score);
|
|
|
|
dto.setScore(score);
|
|
|
|
return Result.success(dto);
|
|
|
|
return Result.success(dto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//计算得分
|
|
|
|
//计算得分
|
|
|
|
private Double computeScore(List<QuestionVo> questionVoList, List<SubmitQuestionVO> submitQuestionVOS){
|
|
|
|
private Double computeScore(List<QuestionVo> questionVoList, List<SubmitQuestionVO> submitQuestionVOS) {
|
|
|
|
Double totalScore = 0D;
|
|
|
|
Double totalScore = 0D;
|
|
|
|
for(int j = 0;j< submitQuestionVOS.size();j++)
|
|
|
|
for (int j = 0; j < submitQuestionVOS.size(); j++) {
|
|
|
|
{
|
|
|
|
SubmitQuestionVO submitQuestionVO = submitQuestionVOS.get(j);
|
|
|
|
SubmitQuestionVO submitQuestionVO = submitQuestionVOS.get(j);
|
|
|
|
|
|
|
|
QuestionVo q = questionVoList.stream().filter(questionVo -> questionVo.getId().equals(submitQuestionVO.getId())).findFirst().orElse(null);
|
|
|
|
QuestionVo q = questionVoList.stream().filter(questionVo -> questionVo.getId().equals(submitQuestionVO.getId())).findFirst().orElse(null);
|
|
|
|
if(q == null) { continue; }
|
|
|
|
if (q == null) {
|
|
|
|
if(q.getType() == 0){
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (q.getType() == 0) {
|
|
|
|
//普通题
|
|
|
|
//普通题
|
|
|
|
if(checkCorrect(q.getAnswerId(),submitQuestionVO.getIds())){
|
|
|
|
if (checkCorrect(q.getAnswerId(), submitQuestionVO.getIds())) {
|
|
|
|
totalScore += q.getScore();
|
|
|
|
totalScore += q.getScore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
//填空题直接对比
|
|
|
|
|
|
|
|
if (q.getQuestionType() == 4) {
|
|
|
|
|
|
|
|
String title = q.getAnswerList().get(0).getTitle();
|
|
|
|
|
|
|
|
if (title.equals(submitQuestionVO.getGapFillingAnswer())) {
|
|
|
|
|
|
|
|
totalScore += q.getScore();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//案例题
|
|
|
|
//案例题
|
|
|
|
SubQuestionVO subQuestionVO = q.getChildren().stream().filter(subQuestionVO1 -> subQuestionVO1.getId().intValue() == submitQuestionVO.getSubId()).findFirst().orElse(null);
|
|
|
|
SubQuestionVO subQuestionVO = q.getChildren().stream().filter(subQuestionVO1 -> subQuestionVO1.getId().intValue() == submitQuestionVO.getSubId()).findFirst().orElse(null);
|
|
|
|
if(subQuestionVO == null) {
|
|
|
|
if (subQuestionVO == null) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(checkCorrect(subQuestionVO.getAnswerId(),submitQuestionVO.getIds())){
|
|
|
|
if (checkCorrect(subQuestionVO.getAnswerId(), submitQuestionVO.getIds())) {
|
|
|
|
totalScore += subQuestionVO.getScore();
|
|
|
|
totalScore += subQuestionVO.getScore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -193,18 +201,20 @@ public class CompetitionExamBiz {
|
|
|
|
return totalScore;
|
|
|
|
return totalScore;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean checkCorrect(List<Integer> answerId,List<Integer> checkList){
|
|
|
|
private boolean checkCorrect(List<Integer> answerId, List<Integer> checkList) {
|
|
|
|
if(checkList ==null||checkList.size() == 0) {return false;}
|
|
|
|
if (checkList == null || checkList.size() == 0) {
|
|
|
|
if(answerId.size() == checkList.size()){
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (answerId.size() == checkList.size()) {
|
|
|
|
boolean correct = true;
|
|
|
|
boolean correct = true;
|
|
|
|
for(int i = 0 ;i <checkList.size();i++){
|
|
|
|
for (int i = 0; i < checkList.size(); i++) {
|
|
|
|
if(answerId.indexOf(checkList.get(i))<0){
|
|
|
|
if (answerId.indexOf(checkList.get(i)) < 0) {
|
|
|
|
correct = false;
|
|
|
|
correct = false;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return correct;
|
|
|
|
return correct;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|