| | |
| | | |
| | | import com.mindskip.xzs.base.BaseApiController; |
| | | import com.mindskip.xzs.base.RestResponse; |
| | | import com.mindskip.xzs.domain.TaskExam; |
| | | import com.mindskip.xzs.domain.TaskExamCustomerAnswer; |
| | | import com.mindskip.xzs.domain.TextContent; |
| | | import com.mindskip.xzs.domain.User; |
| | | import com.mindskip.xzs.domain.*; |
| | | import com.mindskip.xzs.domain.enums.ExamPaperTypeEnum; |
| | | import com.mindskip.xzs.domain.task.TaskItemAnswerObject; |
| | | import com.mindskip.xzs.domain.task.TaskItemObject; |
| | | import com.mindskip.xzs.domain.vo.ExamTemplatesUserCountVO; |
| | | import com.mindskip.xzs.domain.vo.ExamTemplatesVO; |
| | | import com.mindskip.xzs.repository.ExamPaperAnswerMapper; |
| | | import com.mindskip.xzs.repository.ExamTemplatesMapper; |
| | | import com.mindskip.xzs.repository.ExamTemplatesUserCountMapper; |
| | | import com.mindskip.xzs.repository.ExamTemplatesUserMapper; |
| | | import com.mindskip.xzs.service.*; |
| | | import com.mindskip.xzs.utility.DateTimeUtil; |
| | | import com.mindskip.xzs.utility.JsonUtil; |
| | | import com.mindskip.xzs.viewmodel.student.dashboard.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | |
| | | private final TaskExamService taskExamService; |
| | | private final TaskExamCustomerAnswerService taskExamCustomerAnswerService; |
| | | private final TextContentService textContentService; |
| | | private final ExamPaperUserService examPaperUserService; |
| | | private final ExamPaperAnswerMapper answerMapper; |
| | | private final ExamTemplatesMapper templatesMapper; |
| | | private final ExamTemplatesUserCountMapper templatesUserCountMapper; |
| | | private final ExamTemplatesUserMapper examTemplatesUserMapper; |
| | | |
| | | @Autowired |
| | | public DashboardController(UserService userService, ExamPaperService examPaperService, QuestionService questionService, TaskExamService taskExamService, TaskExamCustomerAnswerService taskExamCustomerAnswerService, TextContentService textContentService) { |
| | | public DashboardController(UserService userService, ExamPaperService examPaperService, |
| | | QuestionService questionService, TaskExamService taskExamService, |
| | | TaskExamCustomerAnswerService taskExamCustomerAnswerService, |
| | | TextContentService textContentService, ExamPaperUserService examPaperUserService, |
| | | ExamPaperAnswerMapper answerMapper, ExamTemplatesMapper templatesMapper, ExamTemplatesUserCountMapper templatesUserCountMapper, ExamTemplatesUserMapper examTemplatesUserMapper) { |
| | | this.userService = userService; |
| | | this.examPaperService = examPaperService; |
| | | this.questionService = questionService; |
| | | this.taskExamService = taskExamService; |
| | | this.taskExamCustomerAnswerService = taskExamCustomerAnswerService; |
| | | this.textContentService = textContentService; |
| | | this.examPaperUserService = examPaperUserService; |
| | | this.answerMapper = answerMapper; |
| | | this.templatesMapper = templatesMapper; |
| | | this.templatesUserCountMapper = templatesUserCountMapper; |
| | | this.examTemplatesUserMapper = examTemplatesUserMapper; |
| | | } |
| | | |
| | | @RequestMapping(value = "/qualification/{paperId}", method = RequestMethod.GET) |
| | | public RestResponse qualification(@PathVariable("paperId") String paperId) { |
| | | User user = getCurrentUser(); |
| | | ExamTemplatesUserCount count = new ExamTemplatesUserCount(); |
| | | List<ExamTemplatesUserCount> examTemplatesUserCountList = new ArrayList<>(); |
| | | List<PaperInfo> paperInfos = new ArrayList<>(); |
| | | count.setUserId(user.getId()); |
| | | count.setExamPaperId(Integer.parseInt(paperId)); |
| | | examTemplatesUserCountList.add(count); |
| | | List<ExamPaperAnswer> list1 = answerMapper.getByExamPaperIdAndUserId(examTemplatesUserCountList); |
| | | if(list1.size()>0){ |
| | | return RestResponse.fail(500,"当前试卷已完成考试!"); |
| | | } |
| | | return RestResponse.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/index", method = RequestMethod.POST) |
| | |
| | | |
| | | PaperFilter fixedPaperFilter = new PaperFilter(); |
| | | fixedPaperFilter.setGradeLevel(user.getUserLevel()); |
| | | fixedPaperFilter.setExamPaperType(ExamPaperTypeEnum.Fixed.getCode()); |
| | | indexVM.setFixedPaper(examPaperService.indexPaper(fixedPaperFilter)); |
| | | Integer[] type = {ExamPaperTypeEnum.Fixed.getCode(),ExamPaperTypeEnum.Random.getCode()}; |
| | | fixedPaperFilter.setExamPaperType(type); |
| | | fixedPaperFilter.setUserId(user.getId()); |
| | | //试卷 |
| | | List<PaperInfo> list = examPaperService.indexPaper(fixedPaperFilter); |
| | | ExamTemplatesUserCount count = new ExamTemplatesUserCount(); |
| | | List<ExamTemplatesUserCount> examTemplatesUserCountList = new ArrayList<>(); |
| | | List<PaperInfo> paperInfos = new ArrayList<>(); |
| | | for (PaperInfo info : list) { |
| | | count.setUserId(user.getId()); |
| | | count.setExamPaperId(info.getId()); |
| | | examTemplatesUserCountList.add(count); |
| | | List<ExamPaperAnswer> list1 = answerMapper.getByExamPaperIdAndUserId(examTemplatesUserCountList); |
| | | examTemplatesUserCountList.clear(); |
| | | if(list1.size()>0){ |
| | | continue; |
| | | } |
| | | info.setStatus("0"); |
| | | paperInfos.add(info); |
| | | } |
| | | |
| | | ExamTemplatesVO vo = new ExamTemplatesVO(); |
| | | vo.setStatus("0"); |
| | | vo.setUserId(user.getId()); |
| | | vo.setNow(LocalDateTime.now()); |
| | | List<ExamTemplates> gets = templatesMapper.gets(vo); |
| | | ExamTemplatesUserCountVO templatesUserCountVO = new ExamTemplatesUserCountVO(); |
| | | templatesUserCountVO.setUserId(user.getId()); |
| | | |
| | | for (ExamTemplates get : gets) { |
| | | templatesUserCountVO.setId(get.getId()); |
| | | Integer number = templatesUserCountMapper.getCountByUserIdAndTemplatesId(templatesUserCountVO); |
| | | if(number==0){ |
| | | PaperInfo info = new PaperInfo(); |
| | | info.setId(get.getId()); |
| | | info.setName(get.getName()); |
| | | info.setStatus("1"); |
| | | info.setCreateTime(get.getCtime()); |
| | | paperInfos.add(info); |
| | | } |
| | | } |
| | | paperInfos = paperInfos.stream().sorted(Comparator.comparing(PaperInfo::getCreateTime).reversed()).collect(Collectors.toList()); |
| | | indexVM.setFixedPaper(paperInfos); |
| | | |
| | | PaperFilter timeLimitPaperFilter = new PaperFilter(); |
| | | timeLimitPaperFilter.setDateTime(new Date()); |
| | | timeLimitPaperFilter.setGradeLevel(user.getUserLevel()); |
| | | timeLimitPaperFilter.setExamPaperType(ExamPaperTypeEnum.TimeLimit.getCode()); |
| | | Integer[] time = {ExamPaperTypeEnum.TimeLimit.getCode()}; |
| | | timeLimitPaperFilter.setExamPaperType(time); |
| | | timeLimitPaperFilter.setUserId(user.getId()); |
| | | |
| | | ExamTemplatesUserCount count1 = new ExamTemplatesUserCount(); |
| | | List<ExamTemplatesUserCount> examTemplatesUserCountList1 = new ArrayList<>(); |
| | | List<PaperInfo> paperInfos1 = new ArrayList<>(); |
| | | List<PaperInfo> limitPaper = examPaperService.indexPaper(timeLimitPaperFilter); |
| | | List<PaperInfoVM> paperInfoVMS = limitPaper.stream().map(d -> { |
| | | for (PaperInfo info : limitPaper) { |
| | | count1.setUserId(user.getId()); |
| | | count1.setExamPaperId(info.getId()); |
| | | examTemplatesUserCountList1.add(count1); |
| | | List<ExamPaperAnswer> list1 = answerMapper.getByExamPaperIdAndUserId(examTemplatesUserCountList1); |
| | | examTemplatesUserCountList1.clear(); |
| | | if(list1.size()>0){ |
| | | continue; |
| | | } |
| | | paperInfos1.add(info); |
| | | } |
| | | List<PaperInfoVM> paperInfoVMS = paperInfos1.stream().map(d -> { |
| | | PaperInfoVM vm = modelMapper.map(d, PaperInfoVM.class); |
| | | vm.setStartTime(DateTimeUtil.dateFormat(d.getLimitStartTime())); |
| | | vm.setEndTime(DateTimeUtil.dateFormat(d.getLimitEndTime())); |
| | |
| | | @RequestMapping(value = "/task", method = RequestMethod.POST) |
| | | public RestResponse<List<TaskItemVm>> task() { |
| | | User user = getCurrentUser(); |
| | | List<TaskExam> taskExams = taskExamService.getByGradeLevel(user.getUserLevel()); |
| | | Integer[] ids = examPaperUserService.getByUserId(user.getId()) |
| | | .stream().map(ExamPaperUser::getExamPaperId).toArray(Integer[]::new); |
| | | List<TaskExam> taskExams = new ArrayList<>(); |
| | | if(ids.length!=0){ |
| | | List<ExamPaper> list = examPaperService.gets(ids).stream() |
| | | .filter(e -> e.getPaperType() == 6).collect(Collectors.toList()); |
| | | if(list.size() != 0){ |
| | | Integer[] taskIds = list.stream().map(ExamPaper::getTaskExamId).toArray(Integer[]::new); |
| | | taskExams = taskExamService.gets(taskIds); |
| | | } |
| | | |
| | | } |
| | | |
| | | // List<TaskExam> taskExams = taskExamService.getByGradeLevel(user.getUserLevel()); |
| | | if (taskExams.size() == 0) { |
| | | return RestResponse.ok(new ArrayList<>()); |
| | | } |