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.QuestionSubject; 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.UserNoteQuestionDto; import com.qxgmat.dto.response.*; import com.qxgmat.help.AiHelp; import com.qxgmat.help.MailHelp; 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.apache.logging.log4j.util.Strings; 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 AiHelp aiHelp; @Autowired private MailHelp mailHelp; @Autowired private SettingService settingService; @Autowired private ExerciseStructService exerciseStructService; @Autowired private CourseService courseService; @Autowired private CourseNoService courseNoService; @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 UserOrderRecordService userOrderRecordService; @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/front", produces = MediaType.IMAGE_JPEG_VALUE, method = RequestMethod.POST) @ApiOperation(value = "实名认证", notes = "保存用户实名信息", httpMethod = "POST") public Response realFront(@RequestParam("file") MultipartFile file) throws IOException { if (file.isEmpty()) { throw new ParameterException("上传文件为空"); } User user = (User) shiroHelp.getLoginUser(); UserRealDto dto = new UserRealDto(); Map map = aiHelp.orcIdcardFront(file.getBytes()); dto.setName(map.get("name")); dto.setAddress(map.get("address")); dto.setIdentity(map.get("identity")); User in = usersService.getByIdentity(map.get("identity")); if (in != null){ throw new ParameterException("该身份证已被其他账号认证"); } String frontName = UUID.randomUUID().toString(); try { File frontDest = new File(localPath + File.separator+frontName); file.transferTo(frontDest); dto.setPhotoFront(webUrl+frontName); usersService.edit(User.builder() .id(user.getId()) .realAddress(dto.getAddress()) .realName(dto.getName()) .realIdentity(dto.getIdentity()) .realPhotoFront(dto.getPhotoFront()) .build()); return ResponseHelp.success(dto); } catch (IOException e) { e.printStackTrace(); return ResponseHelp.exception(new SystemException("图片上传失败")); } } @RequestMapping(value = "/real/back", produces = MediaType.IMAGE_JPEG_VALUE, method = RequestMethod.POST) @ApiOperation(value = "实名认证", notes = "保存用户实名信息", httpMethod = "POST") public Response realBack(@RequestParam("file") MultipartFile file) throws IOException { if (file.isEmpty()) { throw new ParameterException("上传文件为空"); } User user = (User) shiroHelp.getLoginUser(); UserRealDto dto = new UserRealDto(); aiHelp.orcIdcardBack(file.getBytes()); String backName = UUID.randomUUID().toString(); try { File backDest = new File(localPath + File.separator+backName); file.transferTo(backDest); dto.setPhotoBack(webUrl+backName); usersService.edit(User.builder() .id(user.getId()) .realPhotoBack(dto.getPhotoBack()) .build()); return ResponseHelp.success(dto); } catch (IOException e) { e.printStackTrace(); return ResponseHelp.exception(new SystemException("图片上传失败")); } } @RequestMapping(value = "/real/finish", produces = MediaType.IMAGE_JPEG_VALUE, method = RequestMethod.POST) @ApiOperation(value = "实名认证", notes = "保存用户实名信息", httpMethod = "POST") public Response realFinish() { User user = (User) shiroHelp.getLoginUser(); UserRealDto dto = new UserRealDto(); User in = usersService.get(user.getId()); if (in.getRealAddress() == null || !in.getRealAddress().equals("")){ throw new ParameterException("实名认证流程错误"); } if (in.getRealIdentity() == null || !in.getRealIdentity().equals("")){ throw new ParameterException("实名认证流程错误"); } if (in.getRealName() == null || !in.getRealName().equals("")){ throw new ParameterException("实名认证流程错误"); } if (in.getRealPhotoFront() == null || !in.getRealPhotoFront().equals("")){ throw new ParameterException("实名认证流程错误"); } if (in.getRealPhotoBack() == null || !in.getRealPhotoBack().equals("")){ throw new ParameterException("实名认证流程错误"); } usersService.edit(User.builder() .id(user.getId()) .realStatus(1) .realTime(new Date()) .build()); // todo 180天vip return ResponseHelp.success(dto); } @RequestMapping(value = "/invite/email", method = RequestMethod.POST) @ApiOperation(value = "发送邮件邀请", httpMethod = "POST") public Response inviteEmail(@RequestBody @Validated InviteEmailDto dto) { User user = (User) shiroHelp.getLoginUser(); Map map = new HashMap<>(); mailHelp.sendBaseMail( Strings.join(Arrays.stream(dto.getEmails()).collect(Collectors.toList()), ';'), "邮件邀请", "", map); return ResponseHelp.success(true); } @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 = "/clear/exercise/latest", method = RequestMethod.PUT) @ApiOperation(value = "清除最后一次做题记录", notes = "清除最后一次做题记录", httpMethod = "PUT") public Response clearLatestExercise() { User user = (User) shiroHelp.getLoginUser(); usersService.edit(User.builder().id(user.getId()).latestExercise(0).build()); return ResponseHelp.success(true); } @RequestMapping(value = "/clear/error/latest", method = RequestMethod.PUT) @ApiOperation(value = "清除最后一次错题组卷做题记录", notes = "清除最后一次错题组卷做题记录", httpMethod = "PUT") public Response clearLatestError() { User user = (User) shiroHelp.getLoginUser(); usersService.edit(User.builder().id(user.getId()).latestError(0).build()); 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()); entity.setPrepareTime(new Date()); 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; UserPaperDetailExtendDto d = Transform.convert(userPaper.get(report.getPaperId()), UserPaperDetailExtendDto.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 courseTime = 0; Integer courseNumber = 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 courseList = courseService.select(courseIds); Map courseMap = Transform.getMap(courseList, Course.class, "id", "title"); List courseNoList = courseNoService.select(courseNoIds); Map classCourseNoMap = Transform.getMap(courseNoList, CourseNo.class, "id", "content"); List courseResultList = new ArrayList<>(userCourseRecordList.size()); for(UserCourseRecord record:userCourseRecordList){ courseTime += record.getUserTime(); courseNumber += 1; UserCourseResultExtendDto d = Transform.convert(record, UserCourseResultExtendDto.class); d.setTitle((String)courseMap.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.setCourseTime(courseTime); dto.setCourseNumber(courseNumber); dto.setCourseList(courseResultList); dto.setCourseExceed(classRank); return ResponseHelp.success(dto); } @RequestMapping(value = "/study/week", method = RequestMethod.GET) @ApiOperation(value = "获取本周记录", notes = "获取本周学习记录", httpMethod = "GET") public Response studyWeekTime() { 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)){ // 累加数学 Integer time = categoryMap.getOrDefault(QuestionSubject.QUANT.key, 0); categoryMap.put(QuestionSubject.QUANT.key, time + categoryMap.get(QuestionType.PS.key)); } if (categoryMap.containsKey(QuestionType.DS.key)){ // 累加数学 Integer time = categoryMap.getOrDefault(QuestionSubject.QUANT.key, 0); categoryMap.put(QuestionSubject.QUANT.key, time + categoryMap.get(QuestionType.DS.key)); } if (categoryMap.containsKey(QuestionSubject.QUANT.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionSubject.QUANT.key), categoryMap.get(QuestionSubject.QUANT.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 = "/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)){ // 累加数学 Integer time = categoryMap.getOrDefault(QuestionSubject.QUANT.key, 0); categoryMap.put(QuestionSubject.QUANT.key, time + categoryMap.get(QuestionType.PS.key)); } if (categoryMap.containsKey(QuestionType.DS.key)){ // 累加数学 Integer time = categoryMap.getOrDefault(QuestionSubject.QUANT.key, 0); categoryMap.put(QuestionSubject.QUANT.key, time + categoryMap.get(QuestionType.DS.key)); } if (categoryMap.containsKey(QuestionSubject.QUANT.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionSubject.QUANT.key), categoryMap.get(QuestionSubject.QUANT.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/question/add", method = RequestMethod.PUT) @ApiOperation(value = "添加收藏", notes = "添加收藏", httpMethod = "PUT") public Response addQuestionCollect(@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/question/delete", method = RequestMethod.DELETE) @ApiOperation(value = "移除收藏", notes = "移除收藏", httpMethod = "DELETE") public Response deleteQuestionCollect(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/question/bind", method = RequestMethod.POST) @ApiOperation(value = "收藏组卷", notes = "收藏组卷", httpMethod = "POST") public Response bindQuestionCollect(@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/list", method = RequestMethod.GET) @ApiOperation(value = "获取收藏题目列表", notes = "获取收藏题目列表", httpMethod = "GET") public Response> listQuestionCollect( @RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "100") int size, @RequestParam(required = true) String questionModule, @RequestParam(required = false) String questionType, @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 qm = QuestionModule.ValueOf(questionModule); PageResult p = userCollectQuestionService.listQuestion(page, size, user.getId(), qm, QuestionType.ValueOf(questionType), 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(qm){ 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; } // 绑定题目统计 List userQuestionList = userQuestionService.listByQuestion(user.getId(), questionIds); Map stats = userQuestionService.statQuestionMap(userQuestionList); 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 questionModule ) { User user = (User) shiroHelp.getLoginUser(); QuestionModule qm = QuestionModule.ValueOf(questionModule); 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(qm){ 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 UserNoteQuestionDto 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 questionModule, @RequestParam(required = false) String questionType, @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 qm = QuestionModule.ValueOf(questionModule); PageResult p = userNoteQuestionService.list(page, size, user.getId(), qm, QuestionType.ValueOf(questionType), startTime, endTime, order, DirectionStatus.ValueOf(direction)); List pr = Transform.convert(p, com.qxgmat.dto.response.UserNoteQuestionDto.class); // 获取题目信息 Collection questionIds = Transform.getIds(pr, com.qxgmat.dto.response.UserNoteQuestionDto.class, "questionId"); List questionList = questionService.select(questionIds); Transform.combine(pr, questionList, com.qxgmat.dto.response.UserNoteQuestionDto.class, "questionId", "question", Question.class, "id", QuestionExtendDto.class); Collection questionNoIds = Transform.getIds(pr, UserQuestionErrorListDto.class, "questionNoId"); switch(qm){ 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); } @RequestMapping(value = "/order/record", method = RequestMethod.GET) @ApiOperation(value = "获取订单记录", notes = "获取订单记录", httpMethod = "GET") public Response getOrderRecord( @RequestParam(required = true) Integer id ) { User user = (User) shiroHelp.getLoginUser(); UserOrderRecord record = userOrderRecordService.get(id); if (!record.getUserId().equals(user.getId())){ throw new ParameterException("记录不存在"); } return ResponseHelp.success(record); } @RequestMapping(value = "/record/use", method = RequestMethod.GET) @ApiOperation(value = "开通", notes = "开通", httpMethod = "GET") public Response useRecord( @RequestParam(required = true) Integer id ) { User user = (User) shiroHelp.getLoginUser(); UserOrderRecord record = userOrderRecordService.get(id); if (!record.getUserId().equals(user.getId())){ throw new ParameterException("记录不存在"); } return ResponseHelp.success(record); } }