MyController.java 47 KB

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