MyController.java 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. package com.qxgmat.controller.api;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.github.pagehelper.Page;
  4. import com.nuliji.tools.*;
  5. import com.nuliji.tools.exception.ParameterException;
  6. import com.nuliji.tools.exception.SystemException;
  7. import com.qxgmat.data.constants.enums.QuestionSubject;
  8. import com.qxgmat.data.constants.enums.QuestionType;
  9. import com.qxgmat.data.constants.enums.SettingKey;
  10. import com.qxgmat.data.constants.enums.module.FeedbackModule;
  11. import com.qxgmat.data.constants.enums.module.PaperModule;
  12. import com.qxgmat.data.constants.enums.module.PaperOrigin;
  13. import com.qxgmat.data.constants.enums.module.QuestionModule;
  14. import com.qxgmat.data.constants.enums.status.DirectionStatus;
  15. import com.qxgmat.data.dao.entity.*;
  16. import com.qxgmat.data.inline.UserQuestionStat;
  17. import com.qxgmat.data.relation.entity.*;
  18. import com.qxgmat.dto.extend.*;
  19. import com.qxgmat.dto.request.*;
  20. import com.qxgmat.dto.request.UserNoteQuestionDto;
  21. import com.qxgmat.dto.response.*;
  22. import com.qxgmat.help.AiHelp;
  23. import com.qxgmat.help.MailHelp;
  24. import com.qxgmat.help.ShiroHelp;
  25. import com.qxgmat.service.*;
  26. import com.qxgmat.service.extend.QuestionFlowService;
  27. import com.qxgmat.service.inline.*;
  28. import io.swagger.annotations.Api;
  29. import io.swagger.annotations.ApiOperation;
  30. import org.apache.logging.log4j.util.Strings;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.beans.factory.annotation.Value;
  33. import org.springframework.http.MediaType;
  34. import org.springframework.validation.annotation.Validated;
  35. import org.springframework.web.bind.annotation.*;
  36. import org.springframework.web.multipart.MultipartFile;
  37. import javax.servlet.http.HttpServletRequest;
  38. import javax.servlet.http.HttpSession;
  39. import javax.validation.Validator;
  40. import java.io.File;
  41. import java.io.IOException;
  42. import java.text.DateFormat;
  43. import java.text.ParseException;
  44. import java.util.*;
  45. import java.util.stream.Collectors;
  46. /**
  47. * Created by GaoJie on 2017/10/31.
  48. */
  49. @RestController
  50. @RequestMapping("/api/my")
  51. @Api(tags = "用户接口", description = "获取与操作当前用户信息", produces = MediaType.APPLICATION_JSON_VALUE)
  52. public class MyController {
  53. @Value("${upload.local_path}")
  54. private String localPath;
  55. @Value("${upload.web_url}")
  56. private String webUrl;
  57. @Autowired
  58. private Validator validator;
  59. @Autowired
  60. private ShiroHelp shiroHelp;
  61. @Autowired
  62. private AiHelp aiHelp;
  63. @Autowired
  64. private MailHelp mailHelp;
  65. @Autowired
  66. private SettingService settingService;
  67. @Autowired
  68. private ExerciseStructService exerciseStructService;
  69. @Autowired
  70. private CourseService courseService;
  71. @Autowired
  72. private CourseNoService courseNoService;
  73. @Autowired
  74. private QuestionService questionService;
  75. @Autowired
  76. private QuestionNoService questionNoService;
  77. @Autowired
  78. private SentenceQuestionService sentenceQuestionService;
  79. @Autowired
  80. private TextbookQuestionService textbookQuestionService;
  81. @Autowired
  82. private UsersService usersService;
  83. @Autowired
  84. private UserMessageService userMessageService;
  85. @Autowired
  86. private UserCourseRecordService userCourseRecordService;
  87. @Autowired
  88. private UserSentenceRecordService userSentenceRecordService;
  89. @Autowired
  90. private UserServiceService userServiceService;
  91. @Autowired
  92. private UserCollectQuestionService userCollectQuestionService;
  93. @Autowired
  94. private UserNoteQuestionService userNoteQuestionService;
  95. @Autowired
  96. private UserAskQuestionService userAskQuestionService;
  97. @Autowired
  98. private UserFeedbackErrorService userFeedbackErrorService;
  99. @Autowired
  100. private UserQuestionService userQuestionService;
  101. @Autowired
  102. private UserReportService userReportService;
  103. @Autowired
  104. private UserPaperService userPaperService;
  105. @Autowired
  106. private UserPaperQuestionService userPaperQuestionService;
  107. @Autowired
  108. private UserOrderRecordService userOrderRecordService;
  109. @Autowired
  110. private QuestionFlowService questionFlowService;
  111. @RequestMapping(value = "/email", method = RequestMethod.POST)
  112. @ApiOperation(value = "绑定邮箱", httpMethod = "POST")
  113. public Response<Boolean> email(@RequestBody @Validated UserEmailDto dto, HttpSession session, HttpServletRequest request) {
  114. User user = (User) shiroHelp.getLoginUser();
  115. usersService.edit(User.builder()
  116. .id(user.getId())
  117. .email(dto.getEmail())
  118. .build());
  119. return ResponseHelp.success(true);
  120. }
  121. @RequestMapping(value = "/info", method = RequestMethod.POST)
  122. @ApiOperation(value = "修改用户信息", httpMethod = "POST")
  123. public Response<Boolean> info(@RequestBody @Validated UserInfoDto dto){
  124. User user = (User) shiroHelp.getLoginUser();
  125. usersService.edit(User.builder()
  126. .id(user.getId())
  127. .nickname(dto.getNickname())
  128. .avatar(dto.getAvatar())
  129. .build());
  130. return ResponseHelp.success(true);
  131. }
  132. @RequestMapping(value = "/real/front", produces = MediaType.IMAGE_JPEG_VALUE, method = RequestMethod.POST)
  133. @ApiOperation(value = "实名认证", notes = "保存用户实名信息", httpMethod = "POST")
  134. public Response<UserRealDto> realFront(@RequestParam("file") MultipartFile file) throws IOException {
  135. if (file.isEmpty()) {
  136. throw new ParameterException("上传文件为空");
  137. }
  138. User user = (User) shiroHelp.getLoginUser();
  139. UserRealDto dto = new UserRealDto();
  140. Map<String, String> map = aiHelp.orcIdcardFront(file.getBytes());
  141. dto.setName(map.get("name"));
  142. dto.setAddress(map.get("address"));
  143. dto.setIdentity(map.get("identity"));
  144. User in = usersService.getByIdentity(map.get("identity"));
  145. if (in != null){
  146. throw new ParameterException("该身份证已被其他账号认证");
  147. }
  148. String frontName = UUID.randomUUID().toString();
  149. try {
  150. File frontDest = new File(localPath + File.separator+frontName);
  151. file.transferTo(frontDest);
  152. dto.setPhotoFront(webUrl+frontName);
  153. usersService.edit(User.builder()
  154. .id(user.getId())
  155. .realAddress(dto.getAddress())
  156. .realName(dto.getName())
  157. .realIdentity(dto.getIdentity())
  158. .realPhotoFront(dto.getPhotoFront())
  159. .build());
  160. return ResponseHelp.success(dto);
  161. } catch (IOException e) {
  162. e.printStackTrace();
  163. return ResponseHelp.exception(new SystemException("图片上传失败"));
  164. }
  165. }
  166. @RequestMapping(value = "/real/back", produces = MediaType.IMAGE_JPEG_VALUE, method = RequestMethod.POST)
  167. @ApiOperation(value = "实名认证", notes = "保存用户实名信息", httpMethod = "POST")
  168. public Response<UserRealDto> realBack(@RequestParam("file") MultipartFile file) throws IOException {
  169. if (file.isEmpty()) {
  170. throw new ParameterException("上传文件为空");
  171. }
  172. User user = (User) shiroHelp.getLoginUser();
  173. UserRealDto dto = new UserRealDto();
  174. aiHelp.orcIdcardBack(file.getBytes());
  175. String backName = UUID.randomUUID().toString();
  176. try {
  177. File backDest = new File(localPath + File.separator+backName);
  178. file.transferTo(backDest);
  179. dto.setPhotoBack(webUrl+backName);
  180. usersService.edit(User.builder()
  181. .id(user.getId())
  182. .realPhotoBack(dto.getPhotoBack())
  183. .build());
  184. return ResponseHelp.success(dto);
  185. } catch (IOException e) {
  186. e.printStackTrace();
  187. return ResponseHelp.exception(new SystemException("图片上传失败"));
  188. }
  189. }
  190. @RequestMapping(value = "/real/finish", produces = MediaType.IMAGE_JPEG_VALUE, method = RequestMethod.POST)
  191. @ApiOperation(value = "实名认证", notes = "保存用户实名信息", httpMethod = "POST")
  192. public Response<UserRealDto> realFinish() {
  193. User user = (User) shiroHelp.getLoginUser();
  194. UserRealDto dto = new UserRealDto();
  195. User in = usersService.get(user.getId());
  196. if (in.getRealAddress() == null || !in.getRealAddress().equals("")){
  197. throw new ParameterException("实名认证流程错误");
  198. }
  199. if (in.getRealIdentity() == null || !in.getRealIdentity().equals("")){
  200. throw new ParameterException("实名认证流程错误");
  201. }
  202. if (in.getRealName() == null || !in.getRealName().equals("")){
  203. throw new ParameterException("实名认证流程错误");
  204. }
  205. if (in.getRealPhotoFront() == null || !in.getRealPhotoFront().equals("")){
  206. throw new ParameterException("实名认证流程错误");
  207. }
  208. if (in.getRealPhotoBack() == null || !in.getRealPhotoBack().equals("")){
  209. throw new ParameterException("实名认证流程错误");
  210. }
  211. usersService.edit(User.builder()
  212. .id(user.getId())
  213. .realStatus(1)
  214. .realTime(new Date())
  215. .build());
  216. // todo 180天vip
  217. return ResponseHelp.success(dto);
  218. }
  219. @RequestMapping(value = "/invite/email", method = RequestMethod.POST)
  220. @ApiOperation(value = "发送邮件邀请", httpMethod = "POST")
  221. public Response<Boolean> inviteEmail(@RequestBody @Validated InviteEmailDto dto) {
  222. User user = (User) shiroHelp.getLoginUser();
  223. Map<String, String> map = new HashMap<>();
  224. mailHelp.sendBaseMail(
  225. Strings.join(Arrays.stream(dto.getEmails()).collect(Collectors.toList()), ';'),
  226. "邮件邀请",
  227. "",
  228. map);
  229. return ResponseHelp.success(true);
  230. }
  231. @RequestMapping(value = "/message", method = RequestMethod.GET)
  232. @ApiOperation(value = "用户站内信", notes = "用户消息列表", httpMethod = "GET")
  233. public Response<PageMessage<UserMessage>> message(
  234. @RequestParam(required = false, defaultValue = "1") int page,
  235. @RequestParam(required = false, defaultValue = "100") int size,
  236. @RequestParam(required = false) String type,
  237. @RequestParam(required = false) Integer read
  238. ) {
  239. User user = (User) shiroHelp.getLoginUser();
  240. Page<UserMessage> p = userMessageService.select(page, size, user.getId(), type, read);
  241. return ResponseHelp.success(p, page, size, p.getTotal());
  242. }
  243. @RequestMapping(value = "/message/read", method = RequestMethod.PUT)
  244. @ApiOperation(value = "读取消息", notes = "读取用户消息/全部", httpMethod = "PUT")
  245. public Response<Boolean> readMessage(@RequestBody @Validated MessageReadDto dto) {
  246. User user = (User) shiroHelp.getLoginUser();
  247. if (dto.getAll()){
  248. userMessageService.clearAll(user.getId());
  249. }else{
  250. userMessageService.clear(user.getId(), dto.getId());
  251. }
  252. return ResponseHelp.success(true);
  253. }
  254. @RequestMapping(value = "/clear/exercise/latest", method = RequestMethod.PUT)
  255. @ApiOperation(value = "清除最后一次做题记录", notes = "清除最后一次做题记录", httpMethod = "PUT")
  256. public Response<Boolean> clearLatestExercise() {
  257. User user = (User) shiroHelp.getLoginUser();
  258. usersService.edit(User.builder().id(user.getId()).latestExercise(0).build());
  259. return ResponseHelp.success(true);
  260. }
  261. @RequestMapping(value = "/clear/error/latest", method = RequestMethod.PUT)
  262. @ApiOperation(value = "清除最后一次错题组卷做题记录", notes = "清除最后一次错题组卷做题记录", httpMethod = "PUT")
  263. public Response<Boolean> clearLatestError() {
  264. User user = (User) shiroHelp.getLoginUser();
  265. usersService.edit(User.builder().id(user.getId()).latestError(0).build());
  266. return ResponseHelp.success(true);
  267. }
  268. @RequestMapping(value = "/prepare", method = RequestMethod.PUT)
  269. @ApiOperation(value = "修改备考信息", notes = "修改用户备考信息", httpMethod = "PUT")
  270. public Response<Boolean> editPrepare(@RequestBody @Validated UserPrepareDto dto) {
  271. User entity = Transform.dtoToEntity(dto);
  272. User user = (User) shiroHelp.getLoginUser();
  273. entity.setId(user.getId());
  274. entity.setPrepareTime(new Date());
  275. usersService.edit(entity);
  276. return ResponseHelp.success(true);
  277. }
  278. @RequestMapping(value = "/prepare", method = RequestMethod.GET)
  279. @ApiOperation(value = "获取备考信息", notes = "获取备考信息及分布", httpMethod = "GET")
  280. public Response<UserPrepareDetailDto> getPrepare() {
  281. User user = (User) shiroHelp.getLoginUser();
  282. User entity = usersService.get(user.getId());
  283. UserPrepareDetailDto dto = Transform.convert(entity, UserPrepareDetailDto.class);
  284. Setting setting = settingService.getByKey(SettingKey.PREPARE_INFO);
  285. JSONObject value = setting.getValue();
  286. return ResponseHelp.success(dto);
  287. }
  288. @RequestMapping(value = "/study", method = RequestMethod.GET)
  289. @ApiOperation(value = "获取学习记录", notes = "获取选择那天的做题信息", httpMethod = "GET")
  290. public Response<UserStudyDayDto> studyTime(
  291. @RequestParam(required = false) String date
  292. ) {
  293. User user = (User) shiroHelp.getLoginUser();
  294. Date day;
  295. try {
  296. day = DateFormat.getDateInstance().parse(date);
  297. } catch (ParseException e) {
  298. throw new ParameterException("日期格式错误");
  299. }
  300. Date endDay = Tools.addDate(day, 1);
  301. String startTime = day.toString();
  302. String endTime = endDay.toString();
  303. UserStudyDayDto dto = new UserStudyDayDto();
  304. List<ExerciseStruct> p = exerciseStructService.main();
  305. Map<String, String> m = new HashMap<>();
  306. for (ExerciseStruct struct : p){
  307. if (struct.getExtend() == null || struct.getExtend().isEmpty()) continue;
  308. m.put(struct.getExtend(), struct.getTitleZh() + (struct.getTitleEn().isEmpty() ? "":" "+struct.getTitleEn()));
  309. }
  310. // 获取总用户数
  311. Integer total = usersService.count();
  312. // 获取练习统计 - 按题型进行分组统计
  313. Integer exerciseTime = 0;
  314. Integer exerciseQuestion = 0;
  315. List<UserExerciseExtendDto> exerciseList = new ArrayList<>();
  316. List<UserStudyStatRelation> typeList = userReportService.statGroupExerciseType(user.getId(), startTime, endTime);
  317. for(UserStudyStatRelation type:typeList){
  318. exerciseTime += type.getUserTime();
  319. exerciseQuestion += type.getUserNumber();
  320. exerciseList.add(new UserExerciseExtendDto(m.get(type.getModule()), type.getUserNumber(), type.getUserTime(), type.getUserCorrect()));
  321. }
  322. // todo 练习统计排行
  323. UserRankStatRelation exerciseRank = userReportService.rankExerciseByTime(user.getId(), startTime, endTime);
  324. exerciseRank.setTotal(total);
  325. dto.setExerciseTime(exerciseTime);
  326. dto.setExerciseQuestion(exerciseQuestion);
  327. dto.setExerciseList(exerciseList);
  328. dto.setExerciseExceed(exerciseRank);
  329. // 获取模考统计 - 按卷子
  330. Integer examinationTime = 0;
  331. Integer examinationPaper = 0;
  332. List<UserReport> userReportList = userReportService.getByModule(user.getId(), PaperModule.EXAMINATION, startTime, endTime);
  333. Collection paperIds = Transform.getIds(userReportList, UserReport.class, "paperId");
  334. List<UserPaper> userPaperList = userPaperService.select(paperIds);
  335. Map userPaper = Transform.getMap(userPaperList, UserPaper.class, "id");
  336. List<UserPaperDetailExtendDto> examinationPaperList = new ArrayList<>(userReportList.size());
  337. for(UserReport report: userReportList){
  338. examinationTime += report.getUserTime();
  339. examinationPaper += 1;
  340. UserPaperDetailExtendDto d = Transform.convert(userPaper.get(report.getPaperId()), UserPaperDetailExtendDto.class);
  341. d.setReport(Transform.convert(report, UserReportExtendDto.class));
  342. examinationPaperList.add(d);
  343. }
  344. // todo 模考统计排行
  345. UserRankStatRelation examinationRank = userReportService.rankExaminationByTime(user.getId(), startTime, endTime);
  346. examinationRank.setTotal(total);
  347. dto.setExaminationTime(examinationTime);
  348. dto.setExaminationPaper(examinationPaper);
  349. dto.setExaminationList(examinationPaperList);
  350. dto.setExaminationExceed(examinationRank);
  351. // 获取课程访问记录 - 按课时
  352. Integer courseTime = 0;
  353. Integer courseNumber = 0;
  354. List<UserCourseRecord> userCourseRecordList = userCourseRecordService.getByTime(user.getId(), startTime, endTime);
  355. Collection courseIds = Transform.getIds(userCourseRecordList, UserCourseRecord.class, "courseId");
  356. Collection courseNoIds = Transform.getIds(userCourseRecordList, UserCourseRecord.class, "noId");
  357. List<Course> courseList = courseService.select(courseIds);
  358. Map courseMap = Transform.getMap(courseList, Course.class, "id", "title");
  359. List<CourseNo> courseNoList = courseNoService.select(courseNoIds);
  360. Map classCourseNoMap = Transform.getMap(courseNoList, CourseNo.class, "id", "content");
  361. List<UserCourseResultExtendDto> courseResultList = new ArrayList<>(userCourseRecordList.size());
  362. for(UserCourseRecord record:userCourseRecordList){
  363. courseTime += record.getUserTime();
  364. courseNumber += 1;
  365. UserCourseResultExtendDto d = Transform.convert(record, UserCourseResultExtendDto.class);
  366. d.setTitle((String)courseMap.get(record.getCourseId()));
  367. d.setContent((String)classCourseNoMap.get(record.getCourseNoId()));
  368. courseResultList.add(d);
  369. }
  370. // todo 听课统计排行
  371. UserRankStatRelation classRank = userCourseRecordService.rankByTime(user.getId(), startTime, endTime);
  372. classRank.setTotal(total);
  373. dto.setCourseTime(courseTime);
  374. dto.setCourseNumber(courseNumber);
  375. dto.setCourseList(courseResultList);
  376. dto.setCourseExceed(classRank);
  377. return ResponseHelp.success(dto);
  378. }
  379. @RequestMapping(value = "/study/week", method = RequestMethod.GET)
  380. @ApiOperation(value = "获取本周记录", notes = "获取本周学习记录", httpMethod = "GET")
  381. public Response<UserStudyDetailDto> studyWeekTime() {
  382. User user = (User) shiroHelp.getLoginUser();
  383. UserStudyDetailDto dto = new UserStudyDetailDto();
  384. dto.setCreateTime(user.getCreateTime());
  385. dto.setDays((int)((user.getCreateTime().getTime() - new Date().getTime()) / (1000*3600*24)));
  386. Integer totalTime = 0;
  387. Map<String, Integer> categoryMap = new HashMap<>();
  388. // 按模块来源分组查询: module=> sentence, examination, collect+error, 忽略exercise,preview
  389. List<UserStudyStatRelation> moduleList = userReportService.statGroupModule(user.getId());
  390. for(UserStudyStatRelation module:moduleList){
  391. // 练习时间过滤
  392. if (module.getModule().equals(PaperModule.EXERCISE.key)){
  393. continue;
  394. }
  395. Integer time = module.getUserTime();
  396. String key = module.getModule();
  397. totalTime += time;
  398. // 收藏及错误组卷合并
  399. if (module.getModule().equals(PaperOrigin.COLLECT.key)
  400. || module.getModule().equals(PaperOrigin.ERROR.key)){
  401. key = "freedom";
  402. time += categoryMap.getOrDefault(key, 0);
  403. }else if (module.getModule().equals(PaperOrigin.PREVIEW.key)){
  404. key = PaperOrigin.EXERCISE.key;
  405. }
  406. categoryMap.put(key, time);
  407. }
  408. // 按题型统计练习
  409. List<UserStudyStatRelation> exerciseList = userReportService.statGroupExerciseType(user.getId(), null, null);
  410. for(UserStudyStatRelation type:exerciseList){
  411. totalTime += type.getUserTime();
  412. categoryMap.put(type.getModule(), type.getUserTime());
  413. }
  414. // 按题型统计预习作业
  415. List<UserStudyStatRelation> previewList = userReportService.statGroupExerciseType(user.getId(), null, null);
  416. for(UserStudyStatRelation type:previewList){
  417. totalTime += type.getUserTime();
  418. categoryMap.put(type.getModule(), type.getUserTime());
  419. }
  420. // 按题型统计课程
  421. List<UserCourseStatRelation> recordList = userCourseRecordService.statGroupType(user.getId(), null, null);
  422. for (UserCourseStatRelation record : recordList){
  423. totalTime += record.getUserTime();
  424. // 累加同类型时间
  425. Integer time = categoryMap.getOrDefault(record.getModule(), 0);
  426. categoryMap.put(record.getModule(), time);
  427. }
  428. // 获取长难句阅读统计
  429. UserSentenceStatRelation sentenceStatRelation = userSentenceRecordService.stat(user.getId(), null, null);
  430. if (sentenceStatRelation != null){
  431. Integer sentenceTime = categoryMap.getOrDefault(PaperModule.SENTENCE.key, 0);
  432. categoryMap.put(PaperModule.SENTENCE.key, sentenceTime + sentenceStatRelation.getUserTime());
  433. }
  434. List<ExerciseStruct> p = exerciseStructService.main();
  435. Map<String, String> m = new HashMap<>();
  436. for (ExerciseStruct struct : p){
  437. if (struct.getExtend() == null || struct.getExtend().isEmpty()) continue;
  438. m.put(struct.getExtend(), struct.getTitleZh() + (struct.getTitleEn().isEmpty() ? "":" "+struct.getTitleEn()));
  439. }
  440. // 组装数据
  441. List<UserStudyExtendDto> categorys = new ArrayList<>();
  442. if (categoryMap.containsKey(PaperModule.SENTENCE.key)) categorys.add(new UserStudyExtendDto(m.get(PaperModule.SENTENCE.key), categoryMap.get(PaperModule.SENTENCE.key)));
  443. if (categoryMap.containsKey(QuestionType.SC.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.SC.key), categoryMap.get(QuestionType.SC.key)));
  444. if (categoryMap.containsKey(QuestionType.RC.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.RC.key), categoryMap.get(QuestionType.RC.key)));
  445. if (categoryMap.containsKey(QuestionType.CR.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.CR.key), categoryMap.get(QuestionType.CR.key)));
  446. if (categoryMap.containsKey(QuestionType.PS.key)){
  447. // 累加数学
  448. Integer time = categoryMap.getOrDefault(QuestionSubject.QUANT.key, 0);
  449. categoryMap.put(QuestionSubject.QUANT.key, time + categoryMap.get(QuestionType.PS.key));
  450. }
  451. if (categoryMap.containsKey(QuestionType.DS.key)){
  452. // 累加数学
  453. Integer time = categoryMap.getOrDefault(QuestionSubject.QUANT.key, 0);
  454. categoryMap.put(QuestionSubject.QUANT.key, time + categoryMap.get(QuestionType.DS.key));
  455. }
  456. if (categoryMap.containsKey(QuestionSubject.QUANT.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionSubject.QUANT.key), categoryMap.get(QuestionSubject.QUANT.key)));
  457. if (categoryMap.containsKey(QuestionType.IR.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.IR.key), categoryMap.get(QuestionType.IR.key)));
  458. if (categoryMap.containsKey(QuestionType.AWA.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.AWA.key), categoryMap.get(QuestionType.AWA.key)));
  459. if (categoryMap.containsKey(PaperModule.EXAMINATION.key)) categorys.add(new UserStudyExtendDto("模考", categoryMap.get(PaperModule.EXAMINATION.key)));
  460. if (categoryMap.containsKey("freedom")) categorys.add(new UserStudyExtendDto("自由组卷", categoryMap.get("freedom")));
  461. dto.setTime(totalTime);
  462. dto.setCategorys(categorys);
  463. return ResponseHelp.success(dto);
  464. }
  465. @RequestMapping(value = "/study/total", method = RequestMethod.GET)
  466. @ApiOperation(value = "获取总学习记录", notes = "获取总学习记录", httpMethod = "GET")
  467. public Response<UserStudyDetailDto> studyTotalTime() {
  468. User user = (User) shiroHelp.getLoginUser();
  469. UserStudyDetailDto dto = new UserStudyDetailDto();
  470. dto.setCreateTime(user.getCreateTime());
  471. dto.setDays((int)((user.getCreateTime().getTime() - new Date().getTime()) / (1000*3600*24)));
  472. Integer totalTime = 0;
  473. Map<String, Integer> categoryMap = new HashMap<>();
  474. // 按模块来源分组查询: module=> sentence, examination, collect+error, 忽略exercise,preview
  475. List<UserStudyStatRelation> moduleList = userReportService.statGroupModule(user.getId());
  476. for(UserStudyStatRelation module:moduleList){
  477. // 练习时间过滤
  478. if (module.getModule().equals(PaperModule.EXERCISE.key)){
  479. continue;
  480. }
  481. Integer time = module.getUserTime();
  482. String key = module.getModule();
  483. totalTime += time;
  484. // 收藏及错误组卷合并
  485. if (module.getModule().equals(PaperOrigin.COLLECT.key)
  486. || module.getModule().equals(PaperOrigin.ERROR.key)){
  487. key = "freedom";
  488. time += categoryMap.getOrDefault(key, 0);
  489. }else if (module.getModule().equals(PaperOrigin.PREVIEW.key)){
  490. key = PaperOrigin.EXERCISE.key;
  491. }
  492. categoryMap.put(key, time);
  493. }
  494. // 按题型统计练习
  495. List<UserStudyStatRelation> exerciseList = userReportService.statGroupExerciseType(user.getId(), null, null);
  496. for(UserStudyStatRelation type:exerciseList){
  497. totalTime += type.getUserTime();
  498. categoryMap.put(type.getModule(), type.getUserTime());
  499. }
  500. // 按题型统计预习作业
  501. List<UserStudyStatRelation> previewList = userReportService.statGroupExerciseType(user.getId(), null, null);
  502. for(UserStudyStatRelation type:previewList){
  503. totalTime += type.getUserTime();
  504. categoryMap.put(type.getModule(), type.getUserTime());
  505. }
  506. // 按题型统计课程
  507. List<UserCourseStatRelation> recordList = userCourseRecordService.statGroupType(user.getId(), null, null);
  508. for (UserCourseStatRelation record : recordList){
  509. totalTime += record.getUserTime();
  510. // 累加同类型时间
  511. Integer time = categoryMap.getOrDefault(record.getModule(), 0);
  512. categoryMap.put(record.getModule(), time);
  513. }
  514. // 获取长难句阅读统计
  515. UserSentenceStatRelation sentenceStatRelation = userSentenceRecordService.stat(user.getId(), null, null);
  516. if (sentenceStatRelation != null){
  517. Integer sentenceTime = categoryMap.getOrDefault(PaperModule.SENTENCE.key, 0);
  518. categoryMap.put(PaperModule.SENTENCE.key, sentenceTime + sentenceStatRelation.getUserTime());
  519. }
  520. List<ExerciseStruct> p = exerciseStructService.main();
  521. Map<String, String> m = new HashMap<>();
  522. for (ExerciseStruct struct : p){
  523. if (struct.getExtend() == null || struct.getExtend().isEmpty()) continue;
  524. m.put(struct.getExtend(), struct.getTitleZh() + (struct.getTitleEn().isEmpty() ? "":" "+struct.getTitleEn()));
  525. }
  526. // 组装数据
  527. List<UserStudyExtendDto> categorys = new ArrayList<>();
  528. if (categoryMap.containsKey(PaperModule.SENTENCE.key)) categorys.add(new UserStudyExtendDto(m.get(PaperModule.SENTENCE.key), categoryMap.get(PaperModule.SENTENCE.key)));
  529. if (categoryMap.containsKey(QuestionType.SC.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.SC.key), categoryMap.get(QuestionType.SC.key)));
  530. if (categoryMap.containsKey(QuestionType.RC.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.RC.key), categoryMap.get(QuestionType.RC.key)));
  531. if (categoryMap.containsKey(QuestionType.CR.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.CR.key), categoryMap.get(QuestionType.CR.key)));
  532. if (categoryMap.containsKey(QuestionType.PS.key)){
  533. // 累加数学
  534. Integer time = categoryMap.getOrDefault(QuestionSubject.QUANT.key, 0);
  535. categoryMap.put(QuestionSubject.QUANT.key, time + categoryMap.get(QuestionType.PS.key));
  536. }
  537. if (categoryMap.containsKey(QuestionType.DS.key)){
  538. // 累加数学
  539. Integer time = categoryMap.getOrDefault(QuestionSubject.QUANT.key, 0);
  540. categoryMap.put(QuestionSubject.QUANT.key, time + categoryMap.get(QuestionType.DS.key));
  541. }
  542. if (categoryMap.containsKey(QuestionSubject.QUANT.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionSubject.QUANT.key), categoryMap.get(QuestionSubject.QUANT.key)));
  543. if (categoryMap.containsKey(QuestionType.IR.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.IR.key), categoryMap.get(QuestionType.IR.key)));
  544. if (categoryMap.containsKey(QuestionType.AWA.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.AWA.key), categoryMap.get(QuestionType.AWA.key)));
  545. if (categoryMap.containsKey(PaperModule.EXAMINATION.key)) categorys.add(new UserStudyExtendDto("模考", categoryMap.get(PaperModule.EXAMINATION.key)));
  546. if (categoryMap.containsKey("freedom")) categorys.add(new UserStudyExtendDto("自由组卷", categoryMap.get("freedom")));
  547. dto.setTime(totalTime);
  548. dto.setCategorys(categorys);
  549. return ResponseHelp.success(dto);
  550. }
  551. @RequestMapping(value = "/data", method = RequestMethod.GET)
  552. @ApiOperation(value = "获取做题数据", notes = "获取做题数据", httpMethod = "GET")
  553. public Response<UserStudyDayDto> questionData(
  554. @RequestParam(required = false) String startTime,
  555. @RequestParam(required = false) String endTime
  556. ) {
  557. User user = (User) shiroHelp.getLoginUser();
  558. UserStudyDayDto dto = new UserStudyDayDto();
  559. // todo
  560. return ResponseHelp.success(dto);
  561. }
  562. @RequestMapping(value = "/collect/question/add", method = RequestMethod.PUT)
  563. @ApiOperation(value = "添加收藏", notes = "添加收藏", httpMethod = "PUT")
  564. public Response<Boolean> addQuestionCollect(@RequestBody @Validated UserCollectDto dto) {
  565. UserCollectQuestion entity = Transform.dtoToEntity(dto);
  566. User user = (User) shiroHelp.getLoginUser();
  567. switch (QuestionModule.ValueOf(dto.getQuestionModule())){
  568. case BASE:
  569. entity.setQuestionModule(QuestionModule.BASE.key);
  570. QuestionNo questionNo = questionNoService.get(dto.getQuestionNoId());
  571. entity.setQuestionId(questionNo.getQuestionId());
  572. entity.setQuestionNoId(questionNo.getId());
  573. break;
  574. case SENTENCE:
  575. entity.setQuestionModule(QuestionModule.SENTENCE.key);
  576. SentenceQuestion sentenceQuestion = sentenceQuestionService.get(dto.getQuestionNoId());
  577. entity.setQuestionId(sentenceQuestion.getQuestionId());
  578. entity.setQuestionNoId(sentenceQuestion.getId());
  579. break;
  580. case TEXTBOOK:
  581. entity.setQuestionModule(QuestionModule.SENTENCE.key);
  582. TextbookQuestion textbookQuestion = textbookQuestionService.get(dto.getQuestionNoId());
  583. entity.setQuestionId(textbookQuestion.getQuestionId());
  584. entity.setQuestionNoId(textbookQuestion.getId());
  585. break;
  586. }
  587. entity.setUserId(user.getId());
  588. userCollectQuestionService.addQuestion(entity);
  589. return ResponseHelp.success(true);
  590. }
  591. @RequestMapping(value = "/collect/question/delete", method = RequestMethod.DELETE)
  592. @ApiOperation(value = "移除收藏", notes = "移除收藏", httpMethod = "DELETE")
  593. public Response<Boolean> deleteQuestionCollect(String questionModule, Integer questionNoId) {
  594. User user = (User) shiroHelp.getLoginUser();
  595. Boolean result = userCollectQuestionService.deleteQuestion(user.getId(), QuestionModule.ValueOf(questionModule), questionNoId);
  596. return ResponseHelp.success(result);
  597. }
  598. @RequestMapping(value = "/collect/question/bind", method = RequestMethod.POST)
  599. @ApiOperation(value = "收藏组卷", notes = "收藏组卷", httpMethod = "POST")
  600. public Response<Boolean> bindQuestionCollect(@RequestBody @Validated UserCustomBindDto dto) {
  601. User user = (User) shiroHelp.getLoginUser();
  602. questionFlowService.makePaper(
  603. user.getId(),
  604. QuestionModule.ValueOf(dto.getQuestionModule()),
  605. PaperOrigin.COLLECT,
  606. Arrays.stream(dto.getQuestionNoIds()).collect(Collectors.toList()),
  607. dto.getFilterTimes()
  608. );
  609. return ResponseHelp.success(true);
  610. }
  611. @RequestMapping(value = "/collect/question/list", method = RequestMethod.GET)
  612. @ApiOperation(value = "获取收藏题目列表", notes = "获取收藏题目列表", httpMethod = "GET")
  613. public Response<PageMessage<UserCollectQuestionDto>> listQuestionCollect(
  614. @RequestParam(required = false, defaultValue = "1") int page,
  615. @RequestParam(required = false, defaultValue = "100") int size,
  616. @RequestParam(required = true) String questionModule,
  617. @RequestParam(required = false) String questionType,
  618. @RequestParam(required = false) String startTime,
  619. @RequestParam(required = false) String endTime,
  620. @RequestParam(required = false, defaultValue = "id") String order,
  621. @RequestParam(required = false, defaultValue = "desc") String direction,
  622. HttpSession session) {
  623. User user = (User) shiroHelp.getLoginUser();
  624. QuestionModule qm = QuestionModule.ValueOf(questionModule);
  625. PageResult<UserCollectQuestionRelation> p = userCollectQuestionService.listQuestion(page, size, user.getId(), qm, QuestionType.ValueOf(questionType), startTime, endTime, order, DirectionStatus.ValueOf(direction));
  626. List<UserCollectQuestionDto> pr = Transform.convert(p, UserCollectQuestionDto.class);
  627. // 获取题目信息
  628. Collection questionIds = Transform.getIds(pr, UserCollectQuestionDto.class, "questionId");
  629. List<Question> questionList = questionService.select(questionIds);
  630. Transform.combine(pr, questionList, UserCollectQuestionDto.class, "questionId", "question", Question.class, "id", QuestionExtendDto.class);
  631. Collection questionNoIds = Transform.getIds(pr, UserCollectQuestionDto.class, "questionNoId");
  632. switch(qm){
  633. case BASE:
  634. List<QuestionNo> questionNoList = questionNoService.select(questionNoIds);
  635. Transform.combine(pr, questionNoList, UserCollectQuestionDto.class, "questionNoId", "questionNo", QuestionNo.class, "id", QuestionNoExtendDto.class);
  636. break;
  637. case SENTENCE:
  638. List<SentenceQuestion> sentenceQuestionList = sentenceQuestionService.select(questionNoIds);
  639. Transform.combine(pr, sentenceQuestionList, UserCollectQuestionDto.class, "questionNoId", "questionNo", SentenceQuestion.class, "id", QuestionNoExtendDto.class);
  640. break;
  641. case TEXTBOOK:
  642. List<TextbookQuestion> textbookQuestionList = textbookQuestionService.select(questionNoIds);
  643. Transform.combine(pr, textbookQuestionList, UserCollectQuestionDto.class, "questionNoId", "questionNo", TextbookQuestion.class, "id", QuestionNoExtendDto.class);
  644. break;
  645. }
  646. // 绑定题目统计
  647. List<UserQuestion> userQuestionList = userQuestionService.listByQuestion(user.getId(), questionIds);
  648. Map<Object, UserQuestionStat> stats = userQuestionService.statQuestionMap(userQuestionList);
  649. Transform.combine(pr, stats, UserCollectQuestionDto.class, "questionId", "stat");
  650. return ResponseHelp.success(pr, page, size, p.getTotal());
  651. }
  652. @RequestMapping(value = "/error/list", method = RequestMethod.GET)
  653. @ApiOperation(value = "获取错题列表", notes = "获取错题列表", httpMethod = "GET")
  654. public Response<PageMessage<UserQuestionErrorListDto>> listError(
  655. @RequestParam(required = false, defaultValue = "1") int page,
  656. @RequestParam(required = false, defaultValue = "100") int size,
  657. @RequestParam(required = true) String questionModule
  658. ) {
  659. User user = (User) shiroHelp.getLoginUser();
  660. QuestionModule qm = QuestionModule.ValueOf(questionModule);
  661. PageResult<UserQuestion> p = userQuestionService.listError(page, size, user.getId());
  662. List<UserQuestionErrorListDto> pr = Transform.convert(p, UserQuestionErrorListDto.class);
  663. // 获取题目信息
  664. Collection questionIds = Transform.getIds(pr, UserQuestionErrorListDto.class, "questionId");
  665. List<Question> questionList = questionService.select(questionIds);
  666. Transform.combine(pr, questionList, UserQuestionErrorListDto.class, "questionId", "question", Question.class, "id", QuestionExtendDto.class);
  667. Collection questionNoIds = Transform.getIds(pr, UserQuestionErrorListDto.class, "questionNoId");
  668. switch(qm){
  669. case BASE:
  670. List<QuestionNo> questionNoList = questionNoService.select(questionNoIds);
  671. Transform.combine(pr, questionNoList, UserQuestionErrorListDto.class, "questionNoId", "questionNo", QuestionNo.class, "id", QuestionNoExtendDto.class);
  672. break;
  673. case SENTENCE:
  674. List<SentenceQuestion> sentenceQuestionList = sentenceQuestionService.select(questionNoIds);
  675. Transform.combine(pr, sentenceQuestionList, UserQuestionErrorListDto.class, "questionNoId", "questionNo", SentenceQuestion.class, "id", QuestionNoExtendDto.class);
  676. break;
  677. case TEXTBOOK:
  678. List<TextbookQuestion> textbookQuestionList = textbookQuestionService.select(questionNoIds);
  679. Transform.combine(pr, textbookQuestionList, UserQuestionErrorListDto.class, "questionNoId", "questionNo", TextbookQuestion.class, "id", QuestionNoExtendDto.class);
  680. break;
  681. }
  682. return ResponseHelp.success(pr, page, size, p.getTotal());
  683. }
  684. @RequestMapping(value = "/error/bind", method = RequestMethod.POST)
  685. @ApiOperation(value = "错题组卷", notes = "错题组卷", httpMethod = "POST")
  686. public Response<Boolean> bindError(@RequestBody @Validated UserCustomBindDto dto) {
  687. User user = (User) shiroHelp.getLoginUser();
  688. questionFlowService.makePaper(
  689. user.getId(),
  690. QuestionModule.ValueOf(dto.getQuestionModule()),
  691. PaperOrigin.ERROR,
  692. Arrays.stream(dto.getQuestionNoIds()).collect(Collectors.toList()),
  693. dto.getFilterTimes()
  694. );
  695. return ResponseHelp.success(true);
  696. }
  697. @RequestMapping(value = "/error/clear", method = RequestMethod.POST)
  698. @ApiOperation(value = "错题移除", notes = "错题移除", httpMethod = "POST")
  699. public Response<Boolean> clearError(@RequestBody @Validated UserQuestionIdsDto dto) {
  700. User user = (User) shiroHelp.getLoginUser();
  701. List<UserQuestion> questionList = userQuestionService.select(dto.getQuestionNoIds());
  702. userPaperQuestionService.addRemoveError(questionList);
  703. return ResponseHelp.success(true);
  704. }
  705. @RequestMapping(value = "/error/remove", method = RequestMethod.POST)
  706. @ApiOperation(value = "移除正确题", notes = "移除正确题", httpMethod = "POST")
  707. public Response<Boolean> removeError(@RequestBody @Validated ErrorReportDto dto) {
  708. User user = (User) shiroHelp.getLoginUser();
  709. UserReport report = userReportService.get(dto.getUserReportId());
  710. if (report.getIsFinish() == 0){
  711. throw new ParameterException("试卷未完成");
  712. }
  713. List<UserQuestion> questionList = userQuestionService.listByReport(user.getId(), dto.getUserReportId());
  714. userPaperQuestionService.addRemoveError(questionList);
  715. return ResponseHelp.success(true);
  716. }
  717. @RequestMapping(value = "/note/question", method = RequestMethod.PUT)
  718. @ApiOperation(value = "更新笔记", notes = "更新笔记", httpMethod = "PUT")
  719. public Response<Boolean> updateNoteQuestion(@RequestBody @Validated UserNoteQuestionDto dto) {
  720. UserNoteQuestion entity = Transform.dtoToEntity(dto);
  721. User user = (User) shiroHelp.getLoginUser();
  722. entity.setUserId(user.getId());
  723. switch (QuestionModule.ValueOf(dto.getQuestionModule())){
  724. case BASE:
  725. entity.setQuestionModule(QuestionModule.BASE.key);
  726. QuestionNo questionNo = questionNoService.get(dto.getQuestionNoId());
  727. entity.setQuestionId(questionNo.getQuestionId());
  728. entity.setQuestionNoId(questionNo.getId());
  729. break;
  730. case SENTENCE:
  731. entity.setQuestionModule(QuestionModule.SENTENCE.key);
  732. SentenceQuestion sentenceQuestion = sentenceQuestionService.get(dto.getQuestionNoId());
  733. entity.setQuestionId(sentenceQuestion.getQuestionId());
  734. entity.setQuestionNoId(sentenceQuestion.getId());
  735. break;
  736. case TEXTBOOK:
  737. entity.setQuestionModule(QuestionModule.SENTENCE.key);
  738. TextbookQuestion textbookQuestion = textbookQuestionService.get(dto.getQuestionNoId());
  739. entity.setQuestionId(textbookQuestion.getQuestionId());
  740. entity.setQuestionNoId(textbookQuestion.getId());
  741. break;
  742. }
  743. userNoteQuestionService.update(entity);
  744. return ResponseHelp.success(true);
  745. }
  746. @RequestMapping(value = "/note/question/list", method = RequestMethod.GET)
  747. @ApiOperation(value = "获取题目笔记列表", notes = "获取笔记列表", httpMethod = "GET")
  748. public Response<PageMessage<com.qxgmat.dto.response.UserNoteQuestionDto>> listNoteQuestion(
  749. @RequestParam(required = false, defaultValue = "1") int page,
  750. @RequestParam(required = false, defaultValue = "100") int size,
  751. @RequestParam(required = true) String questionModule,
  752. @RequestParam(required = false) String questionType,
  753. @RequestParam(required = false) String startTime,
  754. @RequestParam(required = false) String endTime,
  755. @RequestParam(required = false, defaultValue = "id") String order,
  756. @RequestParam(required = false, defaultValue = "desc") String direction,
  757. HttpSession session) {
  758. User user = (User) shiroHelp.getLoginUser();
  759. QuestionModule qm = QuestionModule.ValueOf(questionModule);
  760. PageResult<UserNoteQuestionRelation> p = userNoteQuestionService.list(page, size, user.getId(), qm, QuestionType.ValueOf(questionType), startTime, endTime, order, DirectionStatus.ValueOf(direction));
  761. List<com.qxgmat.dto.response.UserNoteQuestionDto> pr = Transform.convert(p, com.qxgmat.dto.response.UserNoteQuestionDto.class);
  762. // 获取题目信息
  763. Collection questionIds = Transform.getIds(pr, com.qxgmat.dto.response.UserNoteQuestionDto.class, "questionId");
  764. List<Question> questionList = questionService.select(questionIds);
  765. Transform.combine(pr, questionList, com.qxgmat.dto.response.UserNoteQuestionDto.class, "questionId", "question", Question.class, "id", QuestionExtendDto.class);
  766. Collection questionNoIds = Transform.getIds(pr, UserQuestionErrorListDto.class, "questionNoId");
  767. switch(qm){
  768. case BASE:
  769. List<QuestionNo> questionNoList = questionNoService.select(questionNoIds);
  770. Transform.combine(pr, questionNoList, UserQuestionErrorListDto.class, "questionNoId", "questionNo", QuestionNo.class, "id", QuestionNoExtendDto.class);
  771. break;
  772. case SENTENCE:
  773. List<SentenceQuestion> sentenceQuestionList = sentenceQuestionService.select(questionNoIds);
  774. Transform.combine(pr, sentenceQuestionList, UserQuestionErrorListDto.class, "questionNoId", "questionNo", SentenceQuestion.class, "id", QuestionNoExtendDto.class);
  775. break;
  776. case TEXTBOOK:
  777. List<TextbookQuestion> textbookQuestionList = textbookQuestionService.select(questionNoIds);
  778. Transform.combine(pr, textbookQuestionList, UserQuestionErrorListDto.class, "questionNoId", "questionNo", TextbookQuestion.class, "id", QuestionNoExtendDto.class);
  779. break;
  780. }
  781. return ResponseHelp.success(pr, page, size, p.getTotal());
  782. }
  783. @RequestMapping(value = "/report/list", method = RequestMethod.GET)
  784. @ApiOperation(value = "获取报告列表", notes = "获取报告列表", httpMethod = "GET")
  785. public Response<PageMessage<UserPaperDto>> reportList(
  786. @RequestParam(required = false, defaultValue = "1") int page,
  787. @RequestParam(required = false, defaultValue = "100") int size,
  788. @RequestParam(required = true) String origin,
  789. @RequestParam(required = false) Integer structId,
  790. @RequestParam(required = false) String startTime,
  791. @RequestParam(required = false) String endTime,
  792. @RequestParam(required = false, defaultValue = "id") String order,
  793. @RequestParam(required = false, defaultValue = "desc") String direction,
  794. HttpSession session) {
  795. User user = (User) shiroHelp.getLoginUser();
  796. PaperOrigin paperOrigin = PaperOrigin.ValueOf(origin);
  797. PageResult<UserPaper> p = userPaperService.list(page, size, user.getId(), paperOrigin, structId, startTime, endTime, order, DirectionStatus.ValueOf(direction));
  798. List<UserPaperDto> pr = Transform.convert(p, UserPaperDto.class);
  799. Collection paperIds = Transform.getIds(p, UserPaper.class, "id");
  800. // 绑定用户报告
  801. Map<Object, Collection<UserReport>> reportByPaper = userReportService.mapByPaper(paperIds);
  802. Transform.combine(pr, reportByPaper, UserPaperDto.class, "id", "reports", UserReportExtendDto.class);
  803. // 错题 -> 题型
  804. return ResponseHelp.success(pr, page, size, p.getTotal());
  805. }
  806. @RequestMapping(value = "/ask/question", method = RequestMethod.POST)
  807. @ApiOperation(value = "添加提问", notes = "添加提问", httpMethod = "POST")
  808. public Response<Boolean> addAskQuestion(@RequestBody @Validated UserAskDto dto) {
  809. UserAskQuestion entity = Transform.dtoToEntity(dto);
  810. User user = (User) shiroHelp.getLoginUser();
  811. entity.setUserId(user.getId());
  812. switch (QuestionModule.ValueOf(dto.getQuestionModule())){
  813. case BASE:
  814. entity.setQuestionModule(QuestionModule.BASE.key);
  815. QuestionNo questionNo = questionNoService.get(dto.getQuestionNoId());
  816. entity.setQuestionId(questionNo.getQuestionId());
  817. entity.setQuestionNoId(questionNo.getId());
  818. break;
  819. case SENTENCE:
  820. entity.setQuestionModule(QuestionModule.SENTENCE.key);
  821. SentenceQuestion sentenceQuestion = sentenceQuestionService.get(dto.getQuestionNoId());
  822. entity.setQuestionId(sentenceQuestion.getQuestionId());
  823. entity.setQuestionNoId(sentenceQuestion.getId());
  824. break;
  825. case TEXTBOOK:
  826. entity.setQuestionModule(QuestionModule.SENTENCE.key);
  827. TextbookQuestion textbookQuestion = textbookQuestionService.get(dto.getQuestionNoId());
  828. entity.setQuestionId(textbookQuestion.getQuestionId());
  829. entity.setQuestionNoId(textbookQuestion.getId());
  830. break;
  831. }
  832. userAskQuestionService.add(entity);
  833. return ResponseHelp.success(true);
  834. }
  835. @RequestMapping(value = "/feedback/error/question", method = RequestMethod.POST)
  836. @ApiOperation(value = "添加题目勘误", notes = "添加勘误", httpMethod = "POST")
  837. public Response<Boolean> addFeedbackErrorQuestion(@RequestBody @Validated UserFeedbackErrorDto dto) {
  838. UserFeedbackError entity = Transform.dtoToEntity(dto);
  839. User user = (User) shiroHelp.getLoginUser();
  840. entity.setUserId(user.getId());
  841. entity.setModule(FeedbackModule.QUESTION.key);
  842. entity.setStatus(0);
  843. userFeedbackErrorService.add(entity);
  844. return ResponseHelp.success(true);
  845. }
  846. @RequestMapping(value = "/feedback/error/data", method = RequestMethod.POST)
  847. @ApiOperation(value = "添加资料勘误", notes = "添加勘误", httpMethod = "POST")
  848. public Response<Boolean> addFeedbackError(@RequestBody @Validated UserFeedbackErrorDto dto) {
  849. UserFeedbackError entity = Transform.dtoToEntity(dto);
  850. User user = (User) shiroHelp.getLoginUser();
  851. entity.setUserId(user.getId());
  852. entity.setModule(FeedbackModule.DATA.key);
  853. entity.setStatus(0);
  854. userFeedbackErrorService.add(entity);
  855. return ResponseHelp.success(true);
  856. }
  857. @RequestMapping(value = "/order/record", method = RequestMethod.GET)
  858. @ApiOperation(value = "获取订单记录", notes = "获取订单记录", httpMethod = "GET")
  859. public Response<UserOrderRecord> getOrderRecord(
  860. @RequestParam(required = true) Integer id
  861. ) {
  862. User user = (User) shiroHelp.getLoginUser();
  863. UserOrderRecord record = userOrderRecordService.get(id);
  864. if (!record.getUserId().equals(user.getId())){
  865. throw new ParameterException("记录不存在");
  866. }
  867. return ResponseHelp.success(record);
  868. }
  869. @RequestMapping(value = "/record/use", method = RequestMethod.GET)
  870. @ApiOperation(value = "开通", notes = "开通", httpMethod = "GET")
  871. public Response<UserOrderRecord> useRecord(
  872. @RequestParam(required = true) Integer id
  873. ) {
  874. User user = (User) shiroHelp.getLoginUser();
  875. UserOrderRecord record = userOrderRecordService.get(id);
  876. if (!record.getUserId().equals(user.getId())){
  877. throw new ParameterException("记录不存在");
  878. }
  879. return ResponseHelp.success(record);
  880. }
  881. }