package com.qxgmat.controller.api; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.Page; import com.nuliji.tools.*; import com.nuliji.tools.exception.ParameterException; import com.nuliji.tools.exception.SystemException; import com.qxgmat.data.constants.enums.QuestionType; import com.qxgmat.data.constants.enums.SettingKey; import com.qxgmat.data.constants.enums.module.FeedbackModule; import com.qxgmat.data.constants.enums.module.PaperModule; import com.qxgmat.data.constants.enums.module.PaperOrigin; import com.qxgmat.data.constants.enums.module.QuestionModule; import com.qxgmat.data.constants.enums.status.DirectionStatus; import com.qxgmat.data.dao.entity.*; import com.qxgmat.data.inline.UserQuestionStat; import com.qxgmat.data.relation.entity.*; import com.qxgmat.dto.extend.*; import com.qxgmat.dto.request.*; import com.qxgmat.dto.request.UserNoteDto; import com.qxgmat.dto.response.*; import com.qxgmat.help.ShiroHelp; import com.qxgmat.service.*; import com.qxgmat.service.extend.QuestionFlowService; import com.qxgmat.service.inline.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.validation.Validator; import java.io.File; import java.io.IOException; import java.text.DateFormat; import java.text.ParseException; import java.util.*; import java.util.stream.Collectors; /** * Created by GaoJie on 2017/10/31. */ @RestController @RequestMapping("/api/my") @Api(tags = "用户接口", description = "获取与操作当前用户信息", produces = MediaType.APPLICATION_JSON_VALUE) public class MyController { @Value("${upload.local_path}") private String localPath; @Value("${upload.web_url}") private String webUrl; @Autowired private Validator validator; @Autowired private ShiroHelp shiroHelp; @Autowired private SettingService settingService; @Autowired private ExerciseStructService exerciseStructService; @Autowired private ClassCourseService classCourseService; @Autowired private ClassCourseNoService classCourseNoService; @Autowired private QuestionService questionService; @Autowired private QuestionNoService questionNoService; @Autowired private SentenceQuestionService sentenceQuestionService; @Autowired private TextbookQuestionService textbookQuestionService; @Autowired private UsersService usersService; @Autowired private UserMessageService userMessageService; @Autowired private UserCourseRecordService userCourseRecordService; @Autowired private UserSentenceRecordService userSentenceRecordService; @Autowired private UserServiceService userServiceService; @Autowired private UserCollectQuestionService userCollectQuestionService; @Autowired private UserNoteQuestionService userNoteQuestionService; @Autowired private UserAskQuestionService userAskQuestionService; @Autowired private UserFeedbackErrorService userFeedbackErrorService; @Autowired private UserQuestionService userQuestionService; @Autowired private UserReportService userReportService; @Autowired private UserPaperService userPaperService; @Autowired private UserPaperQuestionService userPaperQuestionService; @Autowired private QuestionFlowService questionFlowService; @RequestMapping(value = "/email", method = RequestMethod.POST) @ApiOperation(value = "绑定邮箱", httpMethod = "POST") public Response email(@RequestBody @Validated UserEmailDto dto, HttpSession session, HttpServletRequest request) { User user = (User) shiroHelp.getLoginUser(); usersService.edit(User.builder() .id(user.getId()) .email(dto.getEmail()) .build()); return ResponseHelp.success(true); } @RequestMapping(value = "/info", method = RequestMethod.POST) @ApiOperation(value = "修改用户信息", httpMethod = "POST") public Response info(@RequestBody @Validated UserInfoDto dto){ User user = (User) shiroHelp.getLoginUser(); usersService.edit(User.builder() .id(user.getId()) .nickname(dto.getNickname()) .avatar(dto.getAvatar()) .build()); return ResponseHelp.success(true); } @RequestMapping(value = "/real", produces = MediaType.IMAGE_JPEG_VALUE, method = RequestMethod.POST) @ApiOperation(value = "实名认证", notes = "保存用户实名信息", httpMethod = "POST") public Response real(@RequestParam("file") MultipartFile multipartFile) { if (multipartFile.isEmpty()) { throw new ParameterException("上传文件为空"); } String contentType = multipartFile.getContentType(); if (!contentType.contains("")) { throw new ParameterException("文件类型错误"); } User user = (User) shiroHelp.getLoginUser(); UserRealDto dto = new UserRealDto(); // todo 第三方验证 String file = UUID.randomUUID().toString(); try { File dest = new File(localPath + File.separator+file); multipartFile.transferTo(dest); dto.setPhoto(webUrl+file); usersService.edit(User.builder() .id(user.getId()) .realAddress(dto.getAddress()) .realName(dto.getName()) .realIdentity(dto.getIdentity()) .realPhoto(dto.getPhoto()) .build()); return ResponseHelp.success(dto); } catch (IOException e) { e.printStackTrace(); return ResponseHelp.exception(new SystemException("图片上传失败")); } } @RequestMapping(value = "/message", method = RequestMethod.GET) @ApiOperation(value = "用户站内信", notes = "用户消息列表", httpMethod = "GET") public Response> message( @RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "100") int size, @RequestParam(required = false) String type, @RequestParam(required = false) Integer read ) { User user = (User) shiroHelp.getLoginUser(); Page p = userMessageService.select(page, size, user.getId(), type, read); return ResponseHelp.success(p, page, size, p.getTotal()); } @RequestMapping(value = "/message/read", method = RequestMethod.PUT) @ApiOperation(value = "读取消息", notes = "读取用户消息/全部", httpMethod = "PUT") public Response readMessage(@RequestBody @Validated MessageReadDto dto) { User user = (User) shiroHelp.getLoginUser(); if (dto.getAll()){ userMessageService.clearAll(user.getId()); }else{ userMessageService.clear(user.getId(), dto.getId()); } return ResponseHelp.success(true); } @RequestMapping(value = "/prepare", method = RequestMethod.PUT) @ApiOperation(value = "修改备考信息", notes = "修改用户备考信息", httpMethod = "PUT") public Response editPrepare(@RequestBody @Validated UserPrepareDto dto) { User entity = Transform.dtoToEntity(dto); User user = (User) shiroHelp.getLoginUser(); entity.setId(user.getId()); usersService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/prepare", method = RequestMethod.GET) @ApiOperation(value = "获取备考信息", notes = "获取备考信息及分布", httpMethod = "GET") public Response getPrepare() { User user = (User) shiroHelp.getLoginUser(); User entity = usersService.get(user.getId()); UserPrepareDetailDto dto = Transform.convert(entity, UserPrepareDetailDto.class); Setting setting = settingService.getByKey(SettingKey.PREPARE_INFO); JSONObject value = setting.getValue(); return ResponseHelp.success(dto); } @RequestMapping(value = "/study", method = RequestMethod.GET) @ApiOperation(value = "获取学习记录", notes = "获取选择那天的做题信息", httpMethod = "GET") public Response studyTime( @RequestParam(required = false) String date ) { User user = (User) shiroHelp.getLoginUser(); Date day; try { day = DateFormat.getDateInstance().parse(date); } catch (ParseException e) { throw new ParameterException("日期格式错误"); } Date endDay = Tools.addDate(day, 1); String startTime = day.toString(); String endTime = endDay.toString(); UserStudyDayDto dto = new UserStudyDayDto(); List p = exerciseStructService.main(); Map m = new HashMap<>(); for (ExerciseStruct struct : p){ if (struct.getExtend() == null || struct.getExtend().isEmpty()) continue; m.put(struct.getExtend(), struct.getTitleZh() + (struct.getTitleEn().isEmpty() ? "":" "+struct.getTitleEn())); } // 获取总用户数 Integer total = usersService.count(); // 获取练习统计 - 按题型进行分组统计 Integer exerciseTime = 0; Integer exerciseQuestion = 0; List exerciseList = new ArrayList<>(); List typeList = userReportService.statGroupExerciseType(user.getId(), startTime, endTime); for(UserStudyStatRelation type:typeList){ exerciseTime += type.getUserTime(); exerciseQuestion += type.getUserNumber(); exerciseList.add(new UserExerciseExtendDto(m.get(type.getModule()), type.getUserNumber(), type.getUserTime(), type.getUserCorrect())); } // todo 练习统计排行 UserRankStatRelation exerciseRank = userReportService.rankExerciseByTime(user.getId(), startTime, endTime); exerciseRank.setTotal(total); dto.setExerciseTime(exerciseTime); dto.setExerciseQuestion(exerciseQuestion); dto.setExerciseList(exerciseList); dto.setExerciseExceed(exerciseRank); // 获取模考统计 - 按卷子 Integer examinationTime = 0; Integer examinationPaper = 0; List userReportList = userReportService.getByModule(user.getId(), PaperModule.EXAMINATION, startTime, endTime); Collection paperIds = Transform.getIds(userReportList, UserReport.class, "paperId"); List userPaperList = userPaperService.select(paperIds); Map userPaper = Transform.getMap(userPaperList, UserPaper.class, "id"); List examinationPaperList = new ArrayList<>(userReportList.size()); for(UserReport report: userReportList){ examinationTime += report.getUserTime(); examinationPaper += 1; UserPaperBaseExtendDto d = Transform.convert(userPaper.get(report.getPaperId()), UserPaperBaseExtendDto.class); d.setReport(Transform.convert(report, UserReportExtendDto.class)); examinationPaperList.add(d); } // todo 模考统计排行 UserRankStatRelation examinationRank = userReportService.rankExaminationByTime(user.getId(), startTime, endTime); examinationRank.setTotal(total); dto.setExaminationTime(examinationTime); dto.setExaminationPaper(examinationPaper); dto.setExaminationList(examinationPaperList); dto.setExaminationExceed(examinationRank); // 获取课程访问记录 - 按课时 Integer classTime = 0; Integer classCourse = 0; List userCourseRecordList = userCourseRecordService.getByTime(user.getId(), startTime, endTime); Collection courseIds = Transform.getIds(userCourseRecordList, UserCourseRecord.class, "courseId"); Collection courseNoIds = Transform.getIds(userCourseRecordList, UserCourseRecord.class, "noId"); List classCourseList = classCourseService.select(courseIds); Map classCourseMap = Transform.getMap(classCourseList, ClassCourse.class, "id", "title"); List classCourseNoList = classCourseNoService.select(courseNoIds); Map classCourseNoMap = Transform.getMap(classCourseNoList, ClassCourseNo.class, "id", "content"); List courseResultList = new ArrayList<>(userCourseRecordList.size()); for(UserCourseRecord record:userCourseRecordList){ classTime += record.getUserTime(); classCourse += 1; UserCourseResultExtendDto d = Transform.convert(record, UserCourseResultExtendDto.class); d.setTitle((String)classCourseMap.get(record.getCourseId())); d.setContent((String)classCourseNoMap.get(record.getCourseNoId())); courseResultList.add(d); } // todo 听课统计排行 UserRankStatRelation classRank = userCourseRecordService.rankByTime(user.getId(), startTime, endTime); classRank.setTotal(total); dto.setClassTime(classTime); dto.setClassCourse(classCourse); dto.setClassList(courseResultList); dto.setClassExceed(classRank); return ResponseHelp.success(dto); } @RequestMapping(value = "/study/total", method = RequestMethod.GET) @ApiOperation(value = "获取总学习记录", notes = "获取总学习记录", httpMethod = "GET") public Response studyTotalTime() { User user = (User) shiroHelp.getLoginUser(); UserStudyDetailDto dto = new UserStudyDetailDto(); dto.setCreateTime(user.getCreateTime()); dto.setDays((int)((user.getCreateTime().getTime() - new Date().getTime()) / (1000*3600*24))); Integer totalTime = 0; Map categoryMap = new HashMap<>(); // 按模块来源分组查询: module=> sentence, examination, collect+error, 忽略exercise,preview List moduleList = userReportService.statGroupModule(user.getId()); for(UserStudyStatRelation module:moduleList){ // 练习时间过滤 if (module.getModule().equals(PaperModule.EXERCISE.key)){ continue; } Integer time = module.getUserTime(); String key = module.getModule(); totalTime += time; // 收藏及错误组卷合并 if (module.getModule().equals(PaperOrigin.COLLECT.key) || module.getModule().equals(PaperOrigin.ERROR.key)){ key = "freedom"; time += categoryMap.getOrDefault(key, 0); }else if (module.getModule().equals(PaperOrigin.PREVIEW.key)){ key = PaperOrigin.EXERCISE.key; } categoryMap.put(key, time); } // 按题型统计练习 List exerciseList = userReportService.statGroupExerciseType(user.getId(), null, null); for(UserStudyStatRelation type:exerciseList){ totalTime += type.getUserTime(); categoryMap.put(type.getModule(), type.getUserTime()); } // 按题型统计预习作业 List previewList = userReportService.statGroupExerciseType(user.getId(), null, null); for(UserStudyStatRelation type:previewList){ totalTime += type.getUserTime(); categoryMap.put(type.getModule(), type.getUserTime()); } // 按题型统计课程 List recordList = userCourseRecordService.statGroupType(user.getId(), null, null); for (UserCourseStatRelation record : recordList){ totalTime += record.getUserTime(); // 累加同类型时间 Integer time = categoryMap.getOrDefault(record.getModule(), 0); categoryMap.put(record.getModule(), time); } // 获取长难句阅读统计 UserSentenceStatRelation sentenceStatRelation = userSentenceRecordService.stat(user.getId(), null, null); if (sentenceStatRelation != null){ Integer sentenceTime = categoryMap.getOrDefault(PaperModule.SENTENCE.key, 0); categoryMap.put(PaperModule.SENTENCE.key, sentenceTime + sentenceStatRelation.getUserTime()); } List p = exerciseStructService.main(); Map m = new HashMap<>(); for (ExerciseStruct struct : p){ if (struct.getExtend() == null || struct.getExtend().isEmpty()) continue; m.put(struct.getExtend(), struct.getTitleZh() + (struct.getTitleEn().isEmpty() ? "":" "+struct.getTitleEn())); } // 组装数据 List categorys = new ArrayList<>(); if (categoryMap.containsKey(PaperModule.SENTENCE.key)) categorys.add(new UserStudyExtendDto(m.get(PaperModule.SENTENCE.key), categoryMap.get(PaperModule.SENTENCE.key))); if (categoryMap.containsKey(QuestionType.SC.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.SC.key), categoryMap.get(QuestionType.SC.key))); if (categoryMap.containsKey(QuestionType.RC.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.RC.key), categoryMap.get(QuestionType.RC.key))); if (categoryMap.containsKey(QuestionType.CR.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.CR.key), categoryMap.get(QuestionType.CR.key))); if (categoryMap.containsKey(QuestionType.PS.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.PS.key), categoryMap.get(QuestionType.PS.key))); if (categoryMap.containsKey(QuestionType.DS.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.DS.key), categoryMap.get(QuestionType.DS.key))); if (categoryMap.containsKey(QuestionType.IR.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.IR.key), categoryMap.get(QuestionType.IR.key))); if (categoryMap.containsKey(QuestionType.AWA.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.AWA.key), categoryMap.get(QuestionType.AWA.key))); if (categoryMap.containsKey(PaperModule.EXAMINATION.key)) categorys.add(new UserStudyExtendDto("模考", categoryMap.get(PaperModule.EXAMINATION.key))); if (categoryMap.containsKey("freedom")) categorys.add(new UserStudyExtendDto("自由组卷", categoryMap.get("freedom"))); dto.setTime(totalTime); dto.setCategorys(categorys); return ResponseHelp.success(dto); } @RequestMapping(value = "/data", method = RequestMethod.GET) @ApiOperation(value = "获取做题数据", notes = "获取做题数据", httpMethod = "GET") public Response questionData( @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime ) { User user = (User) shiroHelp.getLoginUser(); UserStudyDayDto dto = new UserStudyDayDto(); // todo return ResponseHelp.success(dto); } @RequestMapping(value = "/collect/add", method = RequestMethod.PUT) @ApiOperation(value = "添加收藏", notes = "添加收藏", httpMethod = "PUT") public Response addCollect(@RequestBody @Validated UserCollectDto dto) { UserCollectQuestion entity = Transform.dtoToEntity(dto); User user = (User) shiroHelp.getLoginUser(); switch (QuestionModule.ValueOf(dto.getQuestionModule())){ case BASE: entity.setQuestionModule(QuestionModule.BASE.key); QuestionNo questionNo = questionNoService.get(dto.getQuestionNoId()); entity.setQuestionId(questionNo.getQuestionId()); entity.setQuestionNoId(questionNo.getId()); break; case SENTENCE: entity.setQuestionModule(QuestionModule.SENTENCE.key); SentenceQuestion sentenceQuestion = sentenceQuestionService.get(dto.getQuestionNoId()); entity.setQuestionId(sentenceQuestion.getQuestionId()); entity.setQuestionNoId(sentenceQuestion.getId()); break; case TEXTBOOK: entity.setQuestionModule(QuestionModule.SENTENCE.key); TextbookQuestion textbookQuestion = textbookQuestionService.get(dto.getQuestionNoId()); entity.setQuestionId(textbookQuestion.getQuestionId()); entity.setQuestionNoId(textbookQuestion.getId()); break; } entity.setUserId(user.getId()); userCollectQuestionService.addQuestion(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/collect/delete", method = RequestMethod.DELETE) @ApiOperation(value = "移除收藏", notes = "移除收藏", httpMethod = "DELETE") public Response deleteCollect(String questionModule, Integer questionNoId) { User user = (User) shiroHelp.getLoginUser(); Boolean result = userCollectQuestionService.deleteQuestion(user.getId(), QuestionModule.ValueOf(questionModule), questionNoId); return ResponseHelp.success(result); } @RequestMapping(value = "/collect/bind", method = RequestMethod.POST) @ApiOperation(value = "收藏组卷", notes = "收藏组卷", httpMethod = "POST") public Response bindCollect(@RequestBody @Validated UserCustomBindDto dto) { User user = (User) shiroHelp.getLoginUser(); questionFlowService.makePaper( user.getId(), QuestionModule.ValueOf(dto.getQuestionModule()), PaperOrigin.COLLECT, Arrays.stream(dto.getQuestionNoIds()).collect(Collectors.toList()), dto.getFilterTimes() ); return ResponseHelp.success(true); } @RequestMapping(value = "/collect/question", method = RequestMethod.GET) @ApiOperation(value = "获取收藏题目列表", notes = "获取收藏题目列表", httpMethod = "GET") public Response> listCollect( @RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "100") int size, @RequestParam(required = true) String module, @RequestParam(required = false) String type, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam(required = false, defaultValue = "id") String order, @RequestParam(required = false, defaultValue = "desc") String direction, HttpSession session) { User user = (User) shiroHelp.getLoginUser(); QuestionModule questionModule = QuestionModule.ValueOf(module); PageResult p = userCollectQuestionService.listQuestion(page, size, user.getId(), questionModule, QuestionType.ValueOf(type), startTime, endTime, order, DirectionStatus.ValueOf(direction)); List pr = Transform.convert(p, UserCollectQuestionDto.class); // 获取题目信息 Collection questionIds = Transform.getIds(pr, UserCollectQuestionDto.class, "questionId"); List questionList = questionService.select(questionIds); Transform.combine(pr, questionList, UserCollectQuestionDto.class, "questionId", "question", Question.class, "id", QuestionExtendDto.class); Collection questionNoIds = Transform.getIds(pr, UserCollectQuestionDto.class, "questionNoId"); switch(questionModule){ case BASE: List questionNoList = questionNoService.select(questionNoIds); Transform.combine(pr, questionNoList, UserCollectQuestionDto.class, "questionNoId", "questionNo", QuestionNo.class, "id", QuestionNoExtendDto.class); break; case SENTENCE: List sentenceQuestionList = sentenceQuestionService.select(questionNoIds); Transform.combine(pr, sentenceQuestionList, UserCollectQuestionDto.class, "questionNoId", "questionNo", SentenceQuestion.class, "id", QuestionNoExtendDto.class); break; case TEXTBOOK: List textbookQuestionList = textbookQuestionService.select(questionNoIds); Transform.combine(pr, textbookQuestionList, UserCollectQuestionDto.class, "questionNoId", "questionNo", TextbookQuestion.class, "id", QuestionNoExtendDto.class); break; } // 绑定题目统计 Map stats = userQuestionService.statQuestionMap(questionIds); Transform.combine(pr, stats, UserCollectQuestionDto.class, "questionId", "stat"); return ResponseHelp.success(pr, page, size, p.getTotal()); } @RequestMapping(value = "/error/list", method = RequestMethod.GET) @ApiOperation(value = "获取错题列表", notes = "获取错题列表", httpMethod = "GET") public Response> listError( @RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "100") int size, @RequestParam(required = true) String module, @RequestParam(required = false) Number category ) { User user = (User) shiroHelp.getLoginUser(); QuestionModule questionModule = QuestionModule.ValueOf(module); PageResult p = userQuestionService.listError(page, size, user.getId()); List pr = Transform.convert(p, UserQuestionErrorListDto.class); // 获取题目信息 Collection questionIds = Transform.getIds(pr, UserQuestionErrorListDto.class, "questionId"); List questionList = questionService.select(questionIds); Transform.combine(pr, questionList, UserQuestionErrorListDto.class, "questionId", "question", Question.class, "id", QuestionExtendDto.class); Collection questionNoIds = Transform.getIds(pr, UserQuestionErrorListDto.class, "questionNoId"); switch(questionModule){ case BASE: List questionNoList = questionNoService.select(questionNoIds); Transform.combine(pr, questionNoList, UserQuestionErrorListDto.class, "questionNoId", "questionNo", QuestionNo.class, "id", QuestionNoExtendDto.class); break; case SENTENCE: List sentenceQuestionList = sentenceQuestionService.select(questionNoIds); Transform.combine(pr, sentenceQuestionList, UserQuestionErrorListDto.class, "questionNoId", "questionNo", SentenceQuestion.class, "id", QuestionNoExtendDto.class); break; case TEXTBOOK: List textbookQuestionList = textbookQuestionService.select(questionNoIds); Transform.combine(pr, textbookQuestionList, UserQuestionErrorListDto.class, "questionNoId", "questionNo", TextbookQuestion.class, "id", QuestionNoExtendDto.class); break; } return ResponseHelp.success(pr, page, size, p.getTotal()); } @RequestMapping(value = "/error/bind", method = RequestMethod.POST) @ApiOperation(value = "错题组卷", notes = "错题组卷", httpMethod = "POST") public Response bindError(@RequestBody @Validated UserCustomBindDto dto) { User user = (User) shiroHelp.getLoginUser(); questionFlowService.makePaper( user.getId(), QuestionModule.ValueOf(dto.getQuestionModule()), PaperOrigin.ERROR, Arrays.stream(dto.getQuestionNoIds()).collect(Collectors.toList()), dto.getFilterTimes() ); return ResponseHelp.success(true); } @RequestMapping(value = "/error/clear", method = RequestMethod.POST) @ApiOperation(value = "错题移除", notes = "错题移除", httpMethod = "POST") public Response clearError(@RequestBody @Validated UserQuestionIdsDto dto) { User user = (User) shiroHelp.getLoginUser(); List questionList = userQuestionService.select(dto.getQuestionNoIds()); userPaperQuestionService.addRemoveError(questionList); return ResponseHelp.success(true); } @RequestMapping(value = "/error/remove", method = RequestMethod.POST) @ApiOperation(value = "移除正确题", notes = "移除正确题", httpMethod = "POST") public Response removeError(@RequestBody @Validated ErrorReportDto dto) { User user = (User) shiroHelp.getLoginUser(); UserReport report = userReportService.get(dto.getUserReportId()); if (report.getIsFinish() == 0){ throw new ParameterException("试卷未完成"); } List questionList = userQuestionService.listByReport(user.getId(), dto.getUserReportId()); userPaperQuestionService.addRemoveError(questionList); return ResponseHelp.success(true); } @RequestMapping(value = "/note/question", method = RequestMethod.PUT) @ApiOperation(value = "更新笔记", notes = "更新笔记", httpMethod = "PUT") public Response updateNoteQuestion(@RequestBody @Validated UserNoteDto dto) { UserNoteQuestion entity = Transform.dtoToEntity(dto); User user = (User) shiroHelp.getLoginUser(); entity.setUserId(user.getId()); switch (QuestionModule.ValueOf(dto.getQuestionModule())){ case BASE: entity.setQuestionModule(QuestionModule.BASE.key); QuestionNo questionNo = questionNoService.get(dto.getQuestionNoId()); entity.setQuestionId(questionNo.getQuestionId()); entity.setQuestionNoId(questionNo.getId()); break; case SENTENCE: entity.setQuestionModule(QuestionModule.SENTENCE.key); SentenceQuestion sentenceQuestion = sentenceQuestionService.get(dto.getQuestionNoId()); entity.setQuestionId(sentenceQuestion.getQuestionId()); entity.setQuestionNoId(sentenceQuestion.getId()); break; case TEXTBOOK: entity.setQuestionModule(QuestionModule.SENTENCE.key); TextbookQuestion textbookQuestion = textbookQuestionService.get(dto.getQuestionNoId()); entity.setQuestionId(textbookQuestion.getQuestionId()); entity.setQuestionNoId(textbookQuestion.getId()); break; } userNoteQuestionService.update(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/note/question/list", method = RequestMethod.GET) @ApiOperation(value = "获取题目笔记列表", notes = "获取笔记列表", httpMethod = "GET") public Response> listNoteQuestion( @RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "100") int size, @RequestParam(required = true) String module, @RequestParam(required = false) String type, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam(required = false, defaultValue = "id") String order, @RequestParam(required = false, defaultValue = "desc") String direction, HttpSession session) { User user = (User) shiroHelp.getLoginUser(); QuestionModule questionModule = QuestionModule.ValueOf(module); PageResult p = userNoteQuestionService.list(page, size, user.getId(), questionModule, QuestionType.ValueOf(type), startTime, endTime, order, DirectionStatus.ValueOf(direction)); List pr = Transform.convert(p, UserNoteQuestionDto.class); // 获取题目信息 Collection questionIds = Transform.getIds(pr, UserNoteQuestionDto.class, "questionId"); List questionList = questionService.select(questionIds); Transform.combine(pr, questionList, UserNoteQuestionDto.class, "questionId", "question", Question.class, "id", QuestionExtendDto.class); Collection questionNoIds = Transform.getIds(pr, UserQuestionErrorListDto.class, "questionNoId"); switch(questionModule){ case BASE: List questionNoList = questionNoService.select(questionNoIds); Transform.combine(pr, questionNoList, UserQuestionErrorListDto.class, "questionNoId", "questionNo", QuestionNo.class, "id", QuestionNoExtendDto.class); break; case SENTENCE: List sentenceQuestionList = sentenceQuestionService.select(questionNoIds); Transform.combine(pr, sentenceQuestionList, UserQuestionErrorListDto.class, "questionNoId", "questionNo", SentenceQuestion.class, "id", QuestionNoExtendDto.class); break; case TEXTBOOK: List textbookQuestionList = textbookQuestionService.select(questionNoIds); Transform.combine(pr, textbookQuestionList, UserQuestionErrorListDto.class, "questionNoId", "questionNo", TextbookQuestion.class, "id", QuestionNoExtendDto.class); break; } return ResponseHelp.success(pr, page, size, p.getTotal()); } @RequestMapping(value = "/report/list", method = RequestMethod.GET) @ApiOperation(value = "获取报告列表", notes = "获取报告列表", httpMethod = "GET") public Response> reportList( @RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "100") int size, @RequestParam(required = true) String origin, @RequestParam(required = false) Integer structId, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam(required = false, defaultValue = "id") String order, @RequestParam(required = false, defaultValue = "desc") String direction, HttpSession session) { User user = (User) shiroHelp.getLoginUser(); PaperOrigin paperOrigin = PaperOrigin.ValueOf(origin); PageResult p = userPaperService.list(page, size, user.getId(), paperOrigin, structId, startTime, endTime, order, DirectionStatus.ValueOf(direction)); List pr = Transform.convert(p, UserPaperDto.class); Collection paperIds = Transform.getIds(p, UserPaper.class, "id"); // 绑定用户报告 Map> reportByPaper = userReportService.mapByPaper(paperIds); Transform.combine(pr, reportByPaper, UserPaperDto.class, "id", "reports", UserReportExtendDto.class); // 错题 -> 题型 return ResponseHelp.success(pr, page, size, p.getTotal()); } @RequestMapping(value = "/ask/question", method = RequestMethod.POST) @ApiOperation(value = "添加提问", notes = "添加提问", httpMethod = "POST") public Response addAskQuestion(@RequestBody @Validated UserAskDto dto) { UserAskQuestion entity = Transform.dtoToEntity(dto); User user = (User) shiroHelp.getLoginUser(); entity.setUserId(user.getId()); switch (QuestionModule.ValueOf(dto.getQuestionModule())){ case BASE: entity.setQuestionModule(QuestionModule.BASE.key); QuestionNo questionNo = questionNoService.get(dto.getQuestionNoId()); entity.setQuestionId(questionNo.getQuestionId()); entity.setQuestionNoId(questionNo.getId()); break; case SENTENCE: entity.setQuestionModule(QuestionModule.SENTENCE.key); SentenceQuestion sentenceQuestion = sentenceQuestionService.get(dto.getQuestionNoId()); entity.setQuestionId(sentenceQuestion.getQuestionId()); entity.setQuestionNoId(sentenceQuestion.getId()); break; case TEXTBOOK: entity.setQuestionModule(QuestionModule.SENTENCE.key); TextbookQuestion textbookQuestion = textbookQuestionService.get(dto.getQuestionNoId()); entity.setQuestionId(textbookQuestion.getQuestionId()); entity.setQuestionNoId(textbookQuestion.getId()); break; } userAskQuestionService.add(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/feedback/error/question", method = RequestMethod.POST) @ApiOperation(value = "添加题目勘误", notes = "添加勘误", httpMethod = "POST") public Response addFeedbackErrorQuestion(@RequestBody @Validated UserFeedbackErrorDto dto) { UserFeedbackError entity = Transform.dtoToEntity(dto); User user = (User) shiroHelp.getLoginUser(); entity.setUserId(user.getId()); entity.setModule(FeedbackModule.QUESTION.key); entity.setStatus(0); userFeedbackErrorService.add(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/feedback/error/data", method = RequestMethod.POST) @ApiOperation(value = "添加资料勘误", notes = "添加勘误", httpMethod = "POST") public Response addFeedbackError(@RequestBody @Validated UserFeedbackErrorDto dto) { UserFeedbackError entity = Transform.dtoToEntity(dto); User user = (User) shiroHelp.getLoginUser(); entity.setUserId(user.getId()); entity.setModule(FeedbackModule.DATA.key); entity.setStatus(0); userFeedbackErrorService.add(entity); return ResponseHelp.success(true); } }