MyController.java 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182
  1. package com.qxgmat.controller.api;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.github.pagehelper.Page;
  5. import com.nuliji.tools.*;
  6. import com.nuliji.tools.exception.AuthException;
  7. import com.nuliji.tools.exception.ParameterException;
  8. import com.nuliji.tools.exception.SystemException;
  9. import com.qxgmat.data.constants.enums.*;
  10. import com.qxgmat.data.constants.enums.module.*;
  11. import com.qxgmat.data.constants.enums.status.AnswerStatus;
  12. import com.qxgmat.data.constants.enums.status.DirectionStatus;
  13. import com.qxgmat.data.constants.enums.user.DataType;
  14. import com.qxgmat.data.dao.entity.*;
  15. import com.qxgmat.data.inline.PaperStat;
  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.CommentDto;
  21. import com.qxgmat.dto.request.FaqDto;
  22. import com.qxgmat.dto.request.UserCollectQuestionDto;
  23. import com.qxgmat.dto.request.UserNoteQuestionDto;
  24. import com.qxgmat.dto.response.*;
  25. import com.qxgmat.help.AiHelp;
  26. import com.qxgmat.help.MailHelp;
  27. import com.qxgmat.help.ShiroHelp;
  28. import com.qxgmat.service.*;
  29. import com.qxgmat.service.extend.*;
  30. import com.qxgmat.service.inline.*;
  31. import io.swagger.annotations.Api;
  32. import io.swagger.annotations.ApiOperation;
  33. import org.springframework.beans.factory.annotation.Autowired;
  34. import org.springframework.beans.factory.annotation.Value;
  35. import org.springframework.http.MediaType;
  36. import org.springframework.validation.annotation.Validated;
  37. import org.springframework.web.bind.annotation.*;
  38. import org.springframework.web.multipart.MultipartFile;
  39. import javax.servlet.http.HttpServletRequest;
  40. import javax.servlet.http.HttpSession;
  41. import javax.validation.Validator;
  42. import java.io.File;
  43. import java.io.IOException;
  44. import java.text.DateFormat;
  45. import java.text.ParseException;
  46. import java.text.SimpleDateFormat;
  47. import java.util.*;
  48. import java.util.stream.Collectors;
  49. /**
  50. * Created by GaoJie on 2017/10/31.
  51. */
  52. @RestController
  53. @RequestMapping("/api/my")
  54. @Api(tags = "用户接口", description = "获取与操作当前用户信息", produces = MediaType.APPLICATION_JSON_VALUE)
  55. public class MyController {
  56. @Value("${upload.local_path}")
  57. private String localPath;
  58. @Value("${upload.web_url}")
  59. private String webUrl;
  60. @Autowired
  61. private Validator validator;
  62. @Autowired
  63. private ShiroHelp shiroHelp;
  64. @Autowired
  65. private AiHelp aiHelp;
  66. @Autowired
  67. private MailHelp mailHelp;
  68. @Autowired
  69. private PreviewService previewService;
  70. @Autowired
  71. private SettingService settingService;
  72. @Autowired
  73. private ExerciseStructService exerciseStructService;
  74. @Autowired
  75. private CourseService courseService;
  76. @Autowired
  77. private CourseNoService courseNoService;
  78. @Autowired
  79. private QuestionService questionService;
  80. @Autowired
  81. private QuestionNoService questionNoService;
  82. @Autowired
  83. private SentenceQuestionService sentenceQuestionService;
  84. @Autowired
  85. private TextbookQuestionService textbookQuestionService;
  86. @Autowired
  87. private TextbookTopicService textbookTopicService;
  88. @Autowired
  89. private TextbookLibraryService textbookLibraryService;
  90. @Autowired
  91. private CourseDataService courseDataService;
  92. @Autowired
  93. private CourseExperienceService courseExperienceService;
  94. @Autowired
  95. private CourseDataHistoryService courseDataHistoryService;
  96. @Autowired
  97. private CourseTeacherService courseTeacherService;
  98. @Autowired
  99. private ExaminationPaperService examinationPaperService;
  100. @Autowired
  101. private FaqService faqService;
  102. @Autowired
  103. private CommentService commentService;
  104. @Autowired
  105. private PreviewAssignService previewAssignService;
  106. @Autowired
  107. private UsersService usersService;
  108. @Autowired
  109. private UserMessageService userMessageService;
  110. @Autowired
  111. private UserCourseRecordService userCourseRecordService;
  112. @Autowired
  113. private UserCourseAppointmentService userCourseAppointmentService;
  114. @Autowired
  115. private UserCourseAppointmentCommentService userCourseAppointmentCommentService;
  116. @Autowired
  117. private UserCourseProgressService userCourseProgressService;
  118. @Autowired
  119. private UserCourseDataSubscribeService userCourseDataSubscribeService;
  120. @Autowired
  121. private UserSentenceRecordService userSentenceRecordService;
  122. @Autowired
  123. private UserServiceService userServiceService;
  124. @Autowired
  125. private UserExportService userExportService;
  126. @Autowired
  127. private UserCollectQuestionService userCollectQuestionService;
  128. @Autowired
  129. private UserCollectExperienceService userCollectExperienceService;
  130. @Autowired
  131. private UserNoteQuestionService userNoteQuestionService;
  132. @Autowired
  133. private UserNoteCourseService userNoteCourseService;
  134. @Autowired
  135. private UserAskQuestionService userAskQuestionService;
  136. @Autowired
  137. private UserAskCourseService userAskCourseService;
  138. @Autowired
  139. private UserFeedbackErrorService userFeedbackErrorService;
  140. @Autowired
  141. private UserTextbookFeedbackService userTextbookFeedbackService;
  142. @Autowired
  143. private UserReadyRoomFeedbackService userReadyRoomFeedbackService;
  144. @Autowired
  145. private UserQuestionService userQuestionService;
  146. @Autowired
  147. private UserReportService userReportService;
  148. @Autowired
  149. private UserPaperService userPaperService;
  150. @Autowired
  151. private UserPaperQuestionService userPaperQuestionService;
  152. @Autowired
  153. private UserOrderService userOrderService;
  154. @Autowired
  155. private UserOrderRecordService userOrderRecordService;
  156. @Autowired
  157. private UserOrderCheckoutService userOrderCheckoutService;
  158. @Autowired
  159. private QuestionFlowService questionFlowService;
  160. @Autowired
  161. private SentenceService sentenceService;
  162. @Autowired
  163. private CourseExtendService courseExtendService;
  164. @Autowired
  165. private OrderFlowService orderFlowService;
  166. @Autowired
  167. private MessageExtendService messageExtendService;
  168. @Autowired
  169. private ExportService exportService;
  170. @Autowired
  171. private UserSearchHistoryService userSearchHistoryService;
  172. @RequestMapping(value = "/email", method = RequestMethod.POST)
  173. @ApiOperation(value = "绑定邮箱", httpMethod = "POST")
  174. public Response<Boolean> email(@RequestBody @Validated UserEmailDto dto, HttpSession session, HttpServletRequest request) {
  175. User user = (User) shiroHelp.getLoginUser();
  176. User in = usersService.get(user.getId());
  177. if (in.getEmail().equals(dto.getEmail())) {
  178. return ResponseHelp.success(true);
  179. }
  180. User other = usersService.getByEmail(dto.getEmail());
  181. if (other != null){
  182. throw new ParameterException("该邮箱已绑定其他账号,请更换邮箱地址。");
  183. }
  184. usersService.edit(User.builder()
  185. .id(user.getId())
  186. .email(dto.getEmail())
  187. .build());
  188. messageExtendService.sendEmailChange(in, dto.getEmail());
  189. return ResponseHelp.success(true);
  190. }
  191. @RequestMapping(value = "/mobile", method = RequestMethod.POST)
  192. @ApiOperation(value = "绑定手机", httpMethod = "POST")
  193. public Response<Boolean> mobile(@RequestBody @Validated UserMobileDto dto, HttpSession session, HttpServletRequest request) {
  194. User user = (User) shiroHelp.getLoginUser();
  195. User in = usersService.get(user.getId());
  196. if (in.getArea().equals(dto.getArea()) && in.getMobile().equals(dto.getMobile())) {
  197. return ResponseHelp.success(true);
  198. }
  199. User other = usersService.getByMobile(dto.getArea(), dto.getMobile());
  200. if (other != null){
  201. throw new ParameterException("该手机已绑定其他账号,请更换手机号码");
  202. }
  203. usersService.edit(User.builder()
  204. .id(user.getId())
  205. .area(dto.getArea())
  206. .mobile(dto.getMobile())
  207. .build());
  208. return ResponseHelp.success(true);
  209. }
  210. @RequestMapping(value = "/info", method = RequestMethod.POST)
  211. @ApiOperation(value = "修改用户信息", httpMethod = "POST")
  212. public Response<Boolean> info(@RequestBody @Validated UserInfoDto dto){
  213. User user = (User) shiroHelp.getLoginUser();
  214. usersService.edit(User.builder()
  215. .id(user.getId())
  216. .nickname(dto.getNickname())
  217. .avatar(dto.getAvatar())
  218. .build());
  219. return ResponseHelp.success(true);
  220. }
  221. @RequestMapping(value = "/real/front", method = RequestMethod.POST)
  222. @ApiOperation(value = "实名认证", notes = "保存用户实名信息", httpMethod = "POST")
  223. public Response<UserRealDto> realFront(@RequestParam("file") MultipartFile file) throws IOException {
  224. if (file.isEmpty()) {
  225. throw new ParameterException("上传文件为空");
  226. }
  227. User user = (User) shiroHelp.getLoginUser();
  228. UserRealDto dto = new UserRealDto();
  229. Map<String, String> map = aiHelp.orcIdcardFront(file.getBytes());
  230. dto.setName(map.get("name"));
  231. dto.setAddress(map.get("address"));
  232. dto.setIdentity(map.get("identity"));
  233. User in = usersService.getByIdentity(map.get("identity"));
  234. if (in != null && !in.getId().equals(user.getId())){
  235. throw new ParameterException("该身份证已被其他账号认证");
  236. }
  237. String filename = file.getOriginalFilename();
  238. String suffix = filename.substring(filename.lastIndexOf(".")+1);
  239. String frontName = UUID.randomUUID().toString()+"."+suffix;
  240. try {
  241. File dir = new File(localPath);
  242. File dest = new File(dir.getAbsolutePath() + File.separator+frontName);
  243. file.transferTo(dest);
  244. dto.setPhotoFront(webUrl+frontName);
  245. usersService.edit(User.builder()
  246. .id(user.getId())
  247. .realAddress(dto.getAddress())
  248. .realName(dto.getName())
  249. .realIdentity(dto.getIdentity())
  250. .realPhotoFront(dto.getPhotoFront())
  251. .build());
  252. return ResponseHelp.success(dto);
  253. } catch (IOException e) {
  254. e.printStackTrace();
  255. return ResponseHelp.exception(new SystemException("图片上传失败"));
  256. }
  257. }
  258. @RequestMapping(value = "/real/back", method = RequestMethod.POST)
  259. @ApiOperation(value = "实名认证", notes = "保存用户实名信息", httpMethod = "POST")
  260. public Response<UserRealDto> realBack(@RequestParam("file") MultipartFile file) throws IOException {
  261. if (file.isEmpty()) {
  262. throw new ParameterException("上传文件为空");
  263. }
  264. User user = (User) shiroHelp.getLoginUser();
  265. UserRealDto dto = new UserRealDto();
  266. aiHelp.orcIdcardBack(file.getBytes());
  267. String filename = file.getOriginalFilename();
  268. String suffix = filename.substring(filename.lastIndexOf(".")+1);
  269. String backName = UUID.randomUUID().toString()+"."+suffix;
  270. try {
  271. File dir = new File(localPath);
  272. File dest = new File(dir.getAbsolutePath() + File.separator+backName);
  273. file.transferTo(dest);
  274. dto.setPhotoBack(webUrl+backName);
  275. usersService.edit(User.builder()
  276. .id(user.getId())
  277. .realPhotoBack(dto.getPhotoBack())
  278. .build());
  279. return ResponseHelp.success(dto);
  280. } catch (IOException e) {
  281. e.printStackTrace();
  282. return ResponseHelp.exception(new SystemException("图片上传失败"));
  283. }
  284. }
  285. @RequestMapping(value = "/real/finish", method = RequestMethod.POST)
  286. @ApiOperation(value = "实名认证", notes = "保存用户实名信息", httpMethod = "POST")
  287. public Response<UserRealDto> realFinish() {
  288. User user = (User) shiroHelp.getLoginUser();
  289. UserRealDto dto = new UserRealDto();
  290. User in = usersService.get(user.getId());
  291. if (in.getRealAddress() == null || in.getRealAddress().equals("")){
  292. throw new ParameterException("实名认证流程错误");
  293. }
  294. if (in.getRealIdentity() == null || in.getRealIdentity().equals("")){
  295. throw new ParameterException("实名认证流程错误");
  296. }
  297. if (in.getRealName() == null || in.getRealName().equals("")){
  298. throw new ParameterException("实名认证流程错误");
  299. }
  300. if (in.getRealPhotoFront() == null || in.getRealPhotoFront().equals("")){
  301. throw new ParameterException("实名认证流程错误");
  302. }
  303. if (in.getRealPhotoBack() == null || in.getRealPhotoBack().equals("")){
  304. throw new ParameterException("实名认证流程错误");
  305. }
  306. usersService.edit(User.builder()
  307. .id(user.getId())
  308. .realStatus(1)
  309. .realTime(new Date())
  310. .build());
  311. UserOrderRecord record = orderFlowService.giveReal(in);
  312. dto.setRecord(Transform.convert(record, UserOrderRecordExtendDto.class));
  313. return ResponseHelp.success(dto);
  314. }
  315. @RequestMapping(value = "/invite/email", method = RequestMethod.POST)
  316. @ApiOperation(value = "发送邮件邀请", httpMethod = "POST")
  317. public Response<Boolean> inviteEmail(@RequestBody @Validated InviteEmailDto dto) {
  318. User user = (User) shiroHelp.getLoginUser();
  319. messageExtendService.sendInviteEmail(user, dto.getEmails(), user.getInviteCode());
  320. return ResponseHelp.success(true);
  321. }
  322. @RequestMapping(value = "/vip/info", method = RequestMethod.GET)
  323. @ApiOperation(value = "vip信息", httpMethod = "GET")
  324. public Response<UserVipInfoDto> info(HttpSession session) {
  325. User user = (User) shiroHelp.getLoginUser();
  326. UserVipInfoDto dto = new UserVipInfoDto();
  327. if (user != null){
  328. UserService userService = userServiceService.getService(user.getId(), ServiceKey.VIP);
  329. dto.setHasService(userService != null);
  330. UserOrderRecord record = userOrderRecordService.getUnUseService(user.getId(), ServiceKey.VIP);
  331. dto.setUnUseRecord(Transform.convert(record, UserServiceRecordExtendDto.class));
  332. dto.setStartTime(userService!=null ? userService.getStartTime() : null);
  333. dto.setExpireTime(userService != null ? userService.getExpireTime() : null);
  334. }
  335. return ResponseHelp.success(dto);
  336. }
  337. @RequestMapping(value = "/message", method = RequestMethod.GET)
  338. @ApiOperation(value = "用户站内信", notes = "用户消息列表", httpMethod = "GET")
  339. public Response<PageMessage<UserMessage>> message(
  340. @RequestParam(required = false, defaultValue = "1") int page,
  341. @RequestParam(required = false, defaultValue = "100") int size,
  342. @RequestParam(required = false) String messageType,
  343. @RequestParam(required = false) Integer read
  344. ) {
  345. User user = (User) shiroHelp.getLoginUser();
  346. Page<UserMessage> p = userMessageService.list(page, size, user.getId(), MessageType.ValueOf(messageType), read);
  347. messageExtendService.refreshMessage(p);
  348. return ResponseHelp.success(p, page, size, p.getTotal());
  349. }
  350. @RequestMapping(value = "/message/read", method = RequestMethod.PUT)
  351. @ApiOperation(value = "读取消息", notes = "读取用户消息/全部", httpMethod = "PUT")
  352. public Response<Boolean> readMessage(@RequestBody @Validated MessageReadDto dto) {
  353. User user = (User) shiroHelp.getLoginUser();
  354. if (dto.getAll()){
  355. userMessageService.clearAll(user.getId());
  356. }else{
  357. userMessageService.clear(user.getId(), dto.getId());
  358. }
  359. return ResponseHelp.success(true);
  360. }
  361. @RequestMapping(value = "/clear/exercise/latest", method = RequestMethod.PUT)
  362. @ApiOperation(value = "清除最后一次做题记录", notes = "清除最后一次做题记录", httpMethod = "PUT")
  363. public Response<Boolean> clearLatestExercise() {
  364. User user = (User) shiroHelp.getLoginUser();
  365. usersService.edit(User.builder().id(user.getId()).latestExercise(0).build());
  366. return ResponseHelp.success(true);
  367. }
  368. @RequestMapping(value = "/clear/error/latest", method = RequestMethod.PUT)
  369. @ApiOperation(value = "清除最后一次错题组卷做题记录", notes = "清除最后一次错题组卷做题记录", httpMethod = "PUT")
  370. public Response<Boolean> clearLatestError() {
  371. User user = (User) shiroHelp.getLoginUser();
  372. usersService.edit(User.builder().id(user.getId()).latestError(0).build());
  373. return ResponseHelp.success(true);
  374. }
  375. @RequestMapping(value = "/clear/collect/latest", method = RequestMethod.PUT)
  376. @ApiOperation(value = "清除最后一次收藏组卷做题记录", notes = "清除最后一次收藏组卷做题记录", httpMethod = "PUT")
  377. public Response<Boolean> clearLatestCollect() {
  378. User user = (User) shiroHelp.getLoginUser();
  379. usersService.edit(User.builder().id(user.getId()).latestCollect(0).build());
  380. return ResponseHelp.success(true);
  381. }
  382. @RequestMapping(value = "/prepare", method = RequestMethod.PUT)
  383. @ApiOperation(value = "修改备考信息", notes = "修改用户备考信息", httpMethod = "PUT")
  384. public Response<Boolean> editPrepare(@RequestBody @Validated UserPrepareDto dto) {
  385. User entity = Transform.dtoToEntity(dto);
  386. User user = (User) shiroHelp.getLoginUser();
  387. entity.setId(user.getId());
  388. if (user.getPrepareTime() == null){
  389. // 邀请奖励
  390. orderFlowService.givePrepare(user);
  391. }
  392. entity.setPrepareTime(new Date());
  393. usersService.edit(entity);
  394. return ResponseHelp.success(true);
  395. }
  396. @RequestMapping(value = "/prepare", method = RequestMethod.GET)
  397. @ApiOperation(value = "获取备考信息", notes = "获取备考信息及分布", httpMethod = "GET")
  398. public Response<UserPrepareDetailDto> getPrepare() {
  399. User user = (User) shiroHelp.getLoginUser();
  400. User entity = usersService.get(user.getId());
  401. UserPrepareDetailDto dto = Transform.convert(entity, UserPrepareDetailDto.class);
  402. Setting settingStat = settingService.getByKey(SettingKey.PREPARE_STAT);
  403. JSONObject valueStat = settingStat.getValue();
  404. dto.setStat(valueStat);
  405. Setting settingInfo = settingService.getByKey(SettingKey.PREPARE_INFO);
  406. JSONObject valueInfo = settingInfo.getValue();
  407. dto.setInfo(valueInfo);
  408. return ResponseHelp.success(dto);
  409. }
  410. @RequestMapping(value = "/study", method = RequestMethod.GET)
  411. @ApiOperation(value = "获取学习记录", notes = "获取选择那天的做题信息", httpMethod = "GET")
  412. public Response<UserStudyDayDto> studyTime(
  413. @RequestParam(required = false) String date
  414. ) {
  415. User user = (User) shiroHelp.getLoginUser();
  416. Date start;
  417. try {
  418. start = DateFormat.getDateInstance().parse(date);
  419. } catch (ParseException e) {
  420. throw new ParameterException("日期格式错误");
  421. }
  422. Date end = Tools.addDate(start, 1);
  423. String startTime = start.toString();
  424. String endTime = end.toString();
  425. UserStudyDayDto dto = new UserStudyDayDto();
  426. List<ExerciseStruct> p = exerciseStructService.main();
  427. Map<String, String> m = new HashMap<>();
  428. for (ExerciseStruct struct : p){
  429. if (struct.getExtend() == null || struct.getExtend().isEmpty()) continue;
  430. m.put(struct.getExtend(), struct.getTitleZh() + (struct.getTitleEn().isEmpty() ? "":" "+struct.getTitleEn()));
  431. }
  432. // 获取总用户数
  433. Integer total = usersService.count();
  434. // 获取练习统计 - 按题型进行分组统计
  435. Integer exerciseTime = 0;
  436. Integer exerciseQuestion = 0;
  437. List<UserExerciseExtendDto> exerciseList = new ArrayList<>();
  438. List<UserStudyStatRelation> typeList = userReportService.statGroupExerciseType(user.getId(), start, end);
  439. for(UserStudyStatRelation type:typeList){
  440. exerciseTime += type.getUserTime();
  441. exerciseQuestion += type.getUserNumber();
  442. exerciseList.add(new UserExerciseExtendDto(m.get(type.getModule()), type.getUserNumber(), type.getUserTime(), type.getUserCorrect()));
  443. }
  444. // todo 练习统计排行
  445. UserRankStatRelation exerciseRank = userReportService.rankExerciseByTime(user.getId(), start, end);
  446. if (exerciseRank != null)
  447. exerciseRank.setTotal(total);
  448. dto.setExerciseTime(exerciseTime);
  449. dto.setExerciseQuestion(exerciseQuestion);
  450. dto.setExerciseList(exerciseList);
  451. dto.setExerciseExceed(exerciseRank);
  452. // 获取模考统计 - 按卷子
  453. Integer examinationTime = 0;
  454. Integer examinationPaper = 0;
  455. List<UserReport> userReportList = userReportService.getByModule(user.getId(), PaperModule.EXAMINATION, start, end);
  456. Collection paperIds = Transform.getIds(userReportList, UserReport.class, "paperId");
  457. List<UserPaper> userPaperList = userPaperService.select(paperIds);
  458. Map userPaper = Transform.getMap(userPaperList, UserPaper.class, "id");
  459. List<UserPaperDetailExtendDto> examinationPaperList = new ArrayList<>(userReportList.size());
  460. for(UserReport report: userReportList){
  461. examinationTime += report.getUserTime();
  462. examinationPaper += 1;
  463. UserPaperDetailExtendDto d = Transform.convert(userPaper.get(report.getPaperId()), UserPaperDetailExtendDto.class);
  464. d.setReport(Transform.convert(report, UserReportExtendDto.class));
  465. examinationPaperList.add(d);
  466. }
  467. // todo 模考统计排行
  468. UserRankStatRelation examinationRank = userReportService.rankExaminationByTime(user.getId(), start, end);
  469. if (examinationRank != null)
  470. examinationRank.setTotal(total);
  471. dto.setExaminationTime(examinationTime);
  472. dto.setExaminationPaper(examinationPaper);
  473. dto.setExaminationList(examinationPaperList);
  474. dto.setExaminationExceed(examinationRank);
  475. // 获取课程访问记录 - 按课时
  476. Integer courseTime = 0;
  477. Integer courseNumber = 0;
  478. List<UserCourseRecord> userCourseRecordList = userCourseRecordService.getByTime(user.getId(), start, end);
  479. Collection courseIds = Transform.getIds(userCourseRecordList, UserCourseRecord.class, "courseId");
  480. Collection courseNoIds = Transform.getIds(userCourseRecordList, UserCourseRecord.class, "noId");
  481. List<Course> courseList = courseService.select(courseIds);
  482. Map courseMap = Transform.getMap(courseList, Course.class, "id");
  483. List<CourseNo> courseNoList = courseNoService.select(courseNoIds);
  484. Map courseNoMap = Transform.getMap(courseNoList, CourseNo.class, "id");
  485. List<UserCourseResultExtendDto> courseResultList = new ArrayList<>(userCourseRecordList.size());
  486. for(UserCourseRecord record:userCourseRecordList){
  487. courseTime += record.getUserTime();
  488. courseNumber += 1;
  489. UserCourseResultExtendDto d = Transform.convert(record, UserCourseResultExtendDto.class);
  490. d.setExtend(((Course)courseMap.get(record.getCourseId())).getExtend());
  491. d.setTitle(((CourseNo)courseNoMap.get(record.getCourseNoId())).getTitle());
  492. d.setNo(((CourseNo)courseNoMap.get(record.getCourseNoId())).getNo());
  493. courseResultList.add(d);
  494. }
  495. // todo 听课统计排行
  496. UserRankStatRelation courseRank = userCourseRecordService.rankByTime(user.getId(), start, end);
  497. if (courseRank != null)
  498. courseRank.setTotal(total);
  499. dto.setCourseTime(courseTime);
  500. // 课时数量:不按学完的课时计算
  501. dto.setCourseNumber(courseNoIds.size());
  502. dto.setCourseList(courseResultList);
  503. dto.setCourseExceed(courseRank);
  504. dto.setCourse(user.getIsCourse()!=null && user.getIsCourse() > 0);
  505. return ResponseHelp.success(dto);
  506. }
  507. @RequestMapping(value = "/study/week", method = RequestMethod.GET)
  508. @ApiOperation(value = "获取本周记录", notes = "获取本周学习记录", httpMethod = "GET")
  509. public Response<UserStudyDetailDto> studyWeekTime(
  510. @RequestParam(required = false) Integer week
  511. ) {
  512. User user = (User) shiroHelp.getLoginUser();
  513. UserStudyDetailDto dto = new UserStudyDetailDto();
  514. dto.setCreateTime(user.getCreateTime());
  515. dto.setDays((int)((new Date().getTime() - user.getCreateTime().getTime()) / (1000*3600*24)));
  516. Date now = Tools.today();
  517. int day = Tools.getDayOfWeek(now);
  518. Date start = Tools.addDate(now, -1 * (day + week * 7));
  519. Date end = Tools.addDate(start, 7);
  520. Integer time = 0;
  521. time += courseExtendService.studyTime(user.getId(), start, end);
  522. time += sentenceService.studyTime(user.getId(), start, end);
  523. time += questionFlowService.studyTime(user.getId(), start, end);
  524. dto.setTime(time);
  525. Integer avgTime = 0;
  526. avgTime += courseExtendService.studyAvgTime(start, end);
  527. avgTime += sentenceService.studyAvgTime(start, end);
  528. avgTime += questionFlowService.studyAvgTime(start, end);
  529. dto.setAvgTime(avgTime);
  530. return ResponseHelp.success(dto);
  531. }
  532. @RequestMapping(value = "/study/total", method = RequestMethod.GET)
  533. @ApiOperation(value = "获取总学习记录", notes = "获取总学习记录", httpMethod = "GET")
  534. public Response<UserStudyDetailDto> studyTotalTime() {
  535. User user = (User) shiroHelp.getLoginUser();
  536. UserStudyDetailDto dto = new UserStudyDetailDto();
  537. dto.setCreateTime(user.getCreateTime());
  538. dto.setDays((int)((new Date().getTime() - user.getCreateTime().getTime()) / (1000*3600*24)));
  539. Integer totalTime = 0;
  540. Map<String, Integer> categoryMap = new HashMap<>();
  541. // 按模块来源分组查询: module=> sentence, examination, collect+error, 忽略exercise,preview
  542. List<UserStudyStatRelation> originList = userReportService.statGroupOrigin(user.getId());
  543. for(UserStudyStatRelation relation:originList){
  544. // 练习时间过滤
  545. if (relation.getModule().equals(PaperOrigin.EXERCISE.key) || relation.getModule().equals(PaperOrigin.PREVIEW.key)){
  546. continue;
  547. }
  548. Integer time = relation.getUserTime();
  549. String key = relation.getModule();
  550. totalTime += time;
  551. // 收藏及错误组卷合并
  552. if (relation.getModule().equals(PaperOrigin.COLLECT.key)
  553. || relation.getModule().equals(PaperOrigin.ERROR.key)){
  554. key = "freedom";
  555. time += categoryMap.getOrDefault(key, 0);
  556. }
  557. categoryMap.put(key, time);
  558. }
  559. // 按题型统计练习
  560. List<UserStudyStatRelation> exerciseList = userReportService.statGroupExerciseType(user.getId(), null, null);
  561. for(UserStudyStatRelation type:exerciseList){
  562. totalTime += type.getUserTime();
  563. Integer time = categoryMap.getOrDefault(type.getModule(), 0);
  564. categoryMap.put(type.getModule(), time + type.getUserTime());
  565. }
  566. // 按题型统计预习作业
  567. List<UserStudyStatRelation> previewList = userReportService.statGroupPreviewType(user.getId(), null, null);
  568. for(UserStudyStatRelation type:previewList){
  569. totalTime += type.getUserTime();
  570. Integer time = categoryMap.getOrDefault(type.getModule(), 0);
  571. categoryMap.put(type.getModule(), time + type.getUserTime());
  572. }
  573. // 按题型统计课程
  574. List<UserModuleRecordStatRelation> recordList = userCourseRecordService.statGroupType(user.getId(), null, null);
  575. for (UserModuleRecordStatRelation record : recordList){
  576. totalTime += record.getUserTime();
  577. // 累加同类型时间
  578. Integer time = categoryMap.getOrDefault(record.getModule(), 0);
  579. categoryMap.put(record.getModule(), time + record.getUserTime());
  580. }
  581. // 获取长难句阅读统计
  582. UserRecordStatRelation sentenceStatRelation = userSentenceRecordService.stat(user.getId(), null, null);
  583. if (sentenceStatRelation != null){
  584. totalTime += sentenceStatRelation.getUserTime();
  585. Integer sentenceTime = categoryMap.getOrDefault(PaperModule.SENTENCE.key, 0);
  586. categoryMap.put(PaperModule.SENTENCE.key, sentenceTime + sentenceStatRelation.getUserTime());
  587. }
  588. List<ExerciseStruct> p = exerciseStructService.main();
  589. Map<String, String> m = new HashMap<>();
  590. for (ExerciseStruct struct : p){
  591. if (struct.getExtend() == null || struct.getExtend().isEmpty()) continue;
  592. m.put(struct.getExtend(), struct.getTitleZh() + (struct.getTitleEn().isEmpty() ? "":" "+struct.getTitleEn()));
  593. }
  594. // 组装数据
  595. List<UserStudyExtendDto> categorys = new ArrayList<>();
  596. if (categoryMap.containsKey(QuestionType.SENTENCE.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.SENTENCE.key), categoryMap.get(PaperModule.SENTENCE.key)));
  597. if (categoryMap.containsKey(QuestionType.SC.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.SC.key), categoryMap.get(QuestionType.SC.key)));
  598. if (categoryMap.containsKey(QuestionType.RC.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.RC.key), categoryMap.get(QuestionType.RC.key)));
  599. if (categoryMap.containsKey(QuestionType.CR.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.CR.key), categoryMap.get(QuestionType.CR.key)));
  600. if (categoryMap.containsKey(QuestionType.PS.key)){
  601. // 累加数学
  602. Integer time = categoryMap.getOrDefault(QuestionSubject.QUANT.key, 0);
  603. categoryMap.put(QuestionSubject.QUANT.key, time + categoryMap.get(QuestionType.PS.key));
  604. }
  605. if (categoryMap.containsKey(QuestionType.DS.key)){
  606. // 累加数学
  607. Integer time = categoryMap.getOrDefault(QuestionSubject.QUANT.key, 0);
  608. categoryMap.put(QuestionSubject.QUANT.key, time + categoryMap.get(QuestionType.DS.key));
  609. }
  610. if (categoryMap.containsKey(QuestionSubject.QUANT.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionSubject.QUANT.key), categoryMap.get(QuestionSubject.QUANT.key)));
  611. if (categoryMap.containsKey(QuestionType.IR.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.IR.key), categoryMap.get(QuestionType.IR.key)));
  612. if (categoryMap.containsKey(QuestionType.AWA.key)) categorys.add(new UserStudyExtendDto(m.get(QuestionType.AWA.key), categoryMap.get(QuestionType.AWA.key)));
  613. if (categoryMap.containsKey(PaperModule.EXAMINATION.key)) categorys.add(new UserStudyExtendDto("模考", categoryMap.get(PaperModule.EXAMINATION.key)));
  614. if (categoryMap.containsKey("freedom")) categorys.add(new UserStudyExtendDto("自由组卷", categoryMap.get("freedom")));
  615. dto.setTime(totalTime);
  616. dto.setCategorys(categorys);
  617. return ResponseHelp.success(dto);
  618. }
  619. @RequestMapping(value = "/data", method = RequestMethod.GET)
  620. @ApiOperation(value = "获取做题数据", notes = "获取做题数据", httpMethod = "GET")
  621. public Response<Map<String, UserDataDto>> questionData(
  622. @RequestParam(required = true) String module,
  623. @RequestParam(required = true) String subject,
  624. @RequestParam(required = false) Integer[] structIds,
  625. @RequestParam(required = false) String startTime,
  626. @RequestParam(required = false) String endTime
  627. ) {
  628. User user = (User) shiroHelp.getLoginUser();
  629. QuestionSubject questionSubject = QuestionSubject.ValueOf(subject);
  630. StructModule structModule = StructModule.ValueOf(module);
  631. List<QuestionNo> questionNoList = questionNoService.listByStruct(structModule, structIds);
  632. List<QuestionNoRelation> relationList = questionNoService.relation(questionNoList);
  633. Map<Number, QuestionNoRelation> relationMap = new HashMap<>();
  634. for(QuestionNoRelation relation : relationList){
  635. relationMap.put(relation.getId(), relation);
  636. }
  637. List<String> questionTypes = QuestionType.FromSubject(questionSubject);
  638. Map<String, UserDataDto> dtoMap = new HashMap<>();
  639. for(String questionType : questionTypes){
  640. UserDataDto dto = new UserDataDto();
  641. dto.setQuestionType(questionType);
  642. JSONObject placeMap = new JSONObject();
  643. JSONObject difficultMap = new JSONObject();
  644. Integer correctTime = 0;
  645. Integer incorrectTime = 0;
  646. List<QuestionNo> list = relationList.stream().filter((row)->row.getQuestion().getQuestionType().equals(questionType)).collect(Collectors.toList());
  647. dto.setQuestionNumber(list.size());
  648. PaperStat stat = questionNoService.statPaper(list);
  649. dto.setTotalCorrect(stat.getTotalCorrect());
  650. dto.setTotalNumber(stat.getTotalNumber());
  651. dto.setTotalTime(stat.getTotalTime());
  652. Collection questionNoIds = Transform.getIds(list, QuestionNo.class, "id");
  653. List<UserQuestion> userQuestionList = userQuestionService.listByQuestionWithTime(user.getId(), QuestionModule.BASE, questionNoIds, Tools.baseTime(startTime), Tools.baseTime(endTime));
  654. Map userQuestionMap = Transform.getMap(userQuestionList, UserQuestion.class, "questionNoId");
  655. dto.setUserQuestion(userQuestionMap.size());
  656. UserQuestionStat userQuestionStat = userQuestionService.statQuestion(userQuestionList);
  657. dto.setUserCorrect(userQuestionStat.getUserCorrect());
  658. dto.setUserNumber(userQuestionStat.getUserNumber());
  659. dto.setUserTime(userQuestionStat.getUserTime());
  660. for (UserQuestion userQuestion:userQuestionList){
  661. QuestionNoRelation relation = relationMap.get(userQuestion.getQuestionNoId());
  662. // 考点用时,以及正确度
  663. String placeKey = relation.getQuestion().getPlace();
  664. JSONObject place = placeMap.getJSONObject(placeKey);
  665. if (place == null){
  666. place = new JSONObject();
  667. place.put("key", placeKey);
  668. place.put("userNumber", 1);
  669. place.put("userCorrect", userQuestion.getIsCorrect());
  670. place.put("userTime", userQuestion.getUserTime());
  671. placeMap.put(placeKey, place);
  672. }else{
  673. place.put("userNumber", place.getInteger("userNumber") + 1);
  674. place.put("userCorrect", place.getInteger("userCorrect") + userQuestion.getIsCorrect());
  675. place.put("userTime", place.getInteger("userTime") + userQuestion.getUserTime());
  676. }
  677. // 难度正确度
  678. String difficultKey = relation.getQuestion().getDifficult();
  679. JSONObject difficult = difficultMap.getJSONObject(difficultKey);
  680. if (difficult == null){
  681. difficult = new JSONObject();
  682. difficult.put("key", difficultKey);
  683. difficult.put("userNumber", 1);
  684. difficult.put("userCorrect", userQuestion.getIsCorrect());
  685. difficult.put("totalNumber", relation.getTotalNumber());
  686. difficult.put("totalCorrect", relation.getTotalCorrect());
  687. difficultMap.put(difficultKey, difficult);
  688. }else{
  689. difficult.put("userNumber", difficult.getInteger("userNumber") + 1);
  690. difficult.put("userCorrect", difficult.getInteger("userCorrect") + userQuestion.getIsCorrect());
  691. difficult.put("totalNumber", difficult.getInteger("totalNumber") + relation.getTotalNumber());
  692. difficult.put("totalCorrect", difficult.getInteger("totalCorrect") + relation.getTotalCorrect());
  693. }
  694. if (userQuestion.getIsCorrect() > 0){
  695. correctTime += userQuestion.getUserTime();
  696. }else{
  697. incorrectTime += userQuestion.getUserTime();
  698. }
  699. }
  700. JSONArray difficult = new JSONArray();
  701. JSONArray place = new JSONArray();
  702. difficult.addAll(difficultMap.values());
  703. place.addAll(placeMap.values());
  704. dto.setDifficult(difficult);
  705. dto.setPlace(place);
  706. dto.setCorrectTime(correctTime);
  707. dto.setIncorrectTime(incorrectTime);
  708. dtoMap.put(questionType, dto);
  709. }
  710. return ResponseHelp.success(dtoMap);
  711. }
  712. @RequestMapping(value = "/collect/experience/add", method = RequestMethod.PUT)
  713. @ApiOperation(value = "添加心经收藏", notes = "添加心经收藏", httpMethod = "PUT")
  714. public Response<Boolean> addExperienceCollect(@RequestBody @Validated UserCollectExperienceDto dto) {
  715. UserCollectExperience entity = Transform.dtoToEntity(dto);
  716. User user = (User) shiroHelp.getLoginUser();
  717. entity.setUserId(user.getId());
  718. userCollectExperienceService.addExperience(entity);
  719. return ResponseHelp.success(true);
  720. }
  721. @RequestMapping(value = "/collect/experience/delete", method = RequestMethod.DELETE)
  722. @ApiOperation(value = "移除心经收藏", notes = "移除心经收藏", httpMethod = "DELETE")
  723. public Response<Boolean> deleteExperienceCollect(Integer experienceId) {
  724. User user = (User) shiroHelp.getLoginUser();
  725. Boolean result = userCollectExperienceService.deleteExperience(user.getId(), experienceId);
  726. return ResponseHelp.success(result);
  727. }
  728. @RequestMapping(value = "/collect/experience/list", method = RequestMethod.GET)
  729. @ApiOperation(value = "获取收藏心经列表", notes = "获取收藏心经列表", httpMethod = "GET")
  730. public Response<PageMessage<CourseExperience>> listExperienceCollect(
  731. @RequestParam(required = false, defaultValue = "1") int page,
  732. @RequestParam(required = false, defaultValue = "100") int size,
  733. @RequestParam(required = false) String startTime,
  734. @RequestParam(required = false) String endTime,
  735. @RequestParam(required = false, defaultValue = "id") String order, // collect_time, update_time
  736. @RequestParam(required = false, defaultValue = "desc") String direction,
  737. HttpSession session) {
  738. User user = (User) shiroHelp.getLoginUser();
  739. Page<CourseExperience> p = courseExperienceService.listWithUser(page, size, user.getId(), Tools.baseTime(startTime), Tools.baseTime(endTime), order, DirectionStatus.ValueOf(direction));
  740. return ResponseHelp.success(p, page, size, p.getTotal());
  741. }
  742. @RequestMapping(value = "/collect/question/add", method = RequestMethod.PUT)
  743. @ApiOperation(value = "添加题目收藏", notes = "添加题目收藏", httpMethod = "PUT")
  744. public Response<Boolean> addQuestionCollect(@RequestBody @Validated UserCollectQuestionDto dto) {
  745. UserCollectQuestion entity = Transform.dtoToEntity(dto);
  746. User user = (User) shiroHelp.getLoginUser();
  747. QuestionNo questionNo = questionNoService.get(dto.getQuestionNoId());
  748. QuestionNoModule questionNoModule = QuestionNoModule.ValueOf(questionNo.getModule());
  749. QuestionModule questionModule = QuestionModule.WithQuestionNo(questionNoModule);
  750. entity.setQuestionModule(questionModule.key);
  751. entity.setQuestionId(questionNo.getQuestionId());
  752. entity.setQuestionNoId(questionNo.getId());
  753. entity.setUserId(user.getId());
  754. userCollectQuestionService.addQuestion(entity);
  755. return ResponseHelp.success(true);
  756. }
  757. @RequestMapping(value = "/collect/question/delete", method = RequestMethod.DELETE)
  758. @ApiOperation(value = "移除题目收藏", notes = "移除题目收藏", httpMethod = "DELETE")
  759. public Response<Boolean> deleteQuestionCollect(Integer questionNoId) {
  760. User user = (User) shiroHelp.getLoginUser();
  761. QuestionNo questionNo = questionNoService.get(questionNoId);
  762. Integer questionId = questionNo.getQuestionId();
  763. Boolean result = userCollectQuestionService.deleteQuestion(user.getId(), questionId);
  764. return ResponseHelp.success(result);
  765. }
  766. @RequestMapping(value = "/collect/question/clear", method = RequestMethod.DELETE)
  767. @ApiOperation(value = "移除题目收藏", notes = "移除题目收藏", httpMethod = "DELETE")
  768. public Response<Boolean> clearQuestionCollect(@RequestBody @Validated UserQuestionNoIdsDto dto) {
  769. User user = (User) shiroHelp.getLoginUser();
  770. List<QuestionNo> questionNoList = questionNoService.select(dto.getQuestionNoIds());
  771. for(QuestionNo questionNo : questionNoList){
  772. userCollectQuestionService.deleteQuestion(user.getId(), questionNo.getQuestionId());
  773. }
  774. return ResponseHelp.success(true);
  775. }
  776. @RequestMapping(value = "/collect/question/group", method = RequestMethod.POST)
  777. @ApiOperation(value = "收藏题目组卷", notes = "收藏题目组卷", httpMethod = "POST")
  778. public Response<UserPaper> bindQuestionCollect(@RequestBody @Validated UserCustomGroupDto dto) {
  779. User user = (User) shiroHelp.getLoginUser();
  780. QuestionModule questionModule = questionFlowService.validGroup(dto.getQuestionNoIds());
  781. UserPaper userPaper = questionFlowService.makePaper(
  782. user.getId(),
  783. questionModule,
  784. PaperOrigin.COLLECT,
  785. Arrays.stream(dto.getQuestionNoIds()).collect(Collectors.toList()),
  786. dto.getFilterTimes()
  787. );
  788. return ResponseHelp.success(userPaper);
  789. }
  790. @RequestMapping(value = "/collect/question/remove", method = RequestMethod.POST)
  791. @ApiOperation(value = "移除正确题", notes = "移除正确题", httpMethod = "POST")
  792. public Response<Boolean> removeCollect(@RequestBody @Validated ErrorReportDto dto) {
  793. User user = (User) shiroHelp.getLoginUser();
  794. UserReport report = userReportService.get(dto.getUserReportId());
  795. if (report.getIsFinish() == 0){
  796. throw new ParameterException("试卷未完成");
  797. }
  798. List<UserQuestion> questionList = userQuestionService.listByReport(user.getId(), dto.getUserReportId());
  799. Collection questionNoIds = Transform.getIds(questionList, UserQuestion.class, "questionNoId");
  800. List<QuestionNo> questionNoList = questionNoService.select(questionNoIds);
  801. List<QuestionNoRelation> relationList = questionNoService.relation(questionNoList);
  802. userPaperQuestionService.addRemoveError(user.getId(), relationList);
  803. return ResponseHelp.success(true);
  804. }
  805. @RequestMapping(value = "/collect/question/list", method = RequestMethod.GET)
  806. @ApiOperation(value = "获取收藏题目列表", notes = "获取收藏题目列表", httpMethod = "GET")
  807. public Response<PageMessage<UserCollectQuestionInfoDto>> listQuestionCollect(
  808. @RequestParam(required = false, defaultValue = "1") int page,
  809. @RequestParam(required = false, defaultValue = "100") int size,
  810. @RequestParam(required = false) String keyword,
  811. @RequestParam(required = false) String module,
  812. @RequestParam(required = false) String[] questionTypes,
  813. @RequestParam(required = false) Integer[] structIds,
  814. @RequestParam(required = false) String startTime,
  815. @RequestParam(required = false) String endTime,
  816. @RequestParam(required = false) Boolean latest,
  817. @RequestParam(required = false) String year,
  818. @RequestParam(required = false) String order, // (pid asc, no asc), time, correct, question_type, latest_time
  819. HttpSession session) {
  820. User user = (User) shiroHelp.getLoginUser();
  821. QuestionNoModule questionNoModule = QuestionNoModule.ValueOf(module);
  822. Page<UserCollectQuestion> p = null;
  823. if(questionNoModule == QuestionNoModule.EXERCISE){
  824. p = userCollectQuestionService.listExercise(page, size, user.getId(), keyword, questionTypes, structIds, Tools.baseTime(startTime), Tools.baseTime(endTime), order != null ? order.replace("|", " ") : null);
  825. }else if (questionNoModule == QuestionNoModule.EXAMINATION){
  826. Integer libraryId = null;
  827. if (latest != null){
  828. if (latest) {
  829. TextbookLibrary textbookLibrary = textbookLibraryService.getLatest();
  830. libraryId = textbookLibrary.getId();
  831. year = null;
  832. }else{
  833. libraryId = 0;
  834. }
  835. }
  836. p = userCollectQuestionService.listExamination(page, size, user.getId(), keyword, questionTypes, structIds, libraryId, year, Tools.baseTime(startTime), Tools.baseTime(endTime), order != null ? order.replace("|", " ") : null);
  837. }else{
  838. throw new ParameterException("参数逻辑错误");
  839. }
  840. List<UserCollectQuestionInfoDto> pr = Transform.convert(p, UserCollectQuestionInfoDto.class);
  841. // 获取题目信息
  842. Collection questionIds = Transform.getIds(pr, UserCollectQuestionInfoDto.class, "questionId");
  843. List<Question> questionList = questionService.select(questionIds);
  844. Transform.combine(pr, questionList, UserCollectQuestionInfoDto.class, "questionId", "question", Question.class, "id", QuestionExtendDto.class);
  845. Collection questionNoIds = Transform.getIds(pr, UserCollectQuestionInfoDto.class, "questionNoId");
  846. List<QuestionNo> questionNoList = questionNoService.select(questionNoIds);
  847. Transform.combine(pr, questionNoList, UserCollectQuestionInfoDto.class, "questionNoId", "questionNo", QuestionNo.class, "id", QuestionNoExtendDto.class);
  848. // 绑定题目统计
  849. List<UserQuestion> userQuestionList = userQuestionService.listByQuestion(user.getId(), questionIds);
  850. Map<Object, UserQuestionStat> stats = userQuestionService.statQuestionMap(userQuestionList);
  851. Transform.combine(pr, stats, UserCollectQuestionInfoDto.class, "questionId", "stat");
  852. // 最近做题
  853. List<UserQuestion> lastList = userQuestionService.listWithLast(user.getId(), questionIds);
  854. Map lastMap = Transform.getMap(lastList, UserQuestion.class, "id", "createTime");
  855. Transform.combine(pr, lastMap, UserCollectQuestionInfoDto.class, "questionId", "latestTime");
  856. // 收藏、笔记
  857. List<UserCollectQuestion> userCollectQuestionList = userCollectQuestionService.listByUserAndQuestions(user.getId(), questionIds);
  858. Map collectMap = Transform.getMap(userCollectQuestionList, UserCollectQuestion.class, "questionId", "id");
  859. List<UserNoteQuestion> userNoteQuestionList = userNoteQuestionService.listByUserAndQuestions(user.getId(), questionIds);
  860. Map noteMap = Transform.getMap(userNoteQuestionList, UserNoteQuestion.class, "questionId", "id");
  861. for(UserCollectQuestionInfoDto dto : pr){
  862. dto.setCollect(collectMap.containsKey(dto.getQuestionId()));
  863. dto.setNote(noteMap.containsKey(dto.getQuestionId()));
  864. }
  865. return ResponseHelp.success(pr, page, size, p.getTotal());
  866. }
  867. @RequestMapping(value = "/error/list", method = RequestMethod.GET)
  868. @ApiOperation(value = "获取错题列表", notes = "获取错题列表", httpMethod = "GET")
  869. public Response<PageMessage<UserQuestionErrorInfoDto>> listError(
  870. @RequestParam(required = false, defaultValue = "1") int page,
  871. @RequestParam(required = false, defaultValue = "100") int size,
  872. @RequestParam(required = false) String keyword,
  873. @RequestParam(required = false) String module,
  874. @RequestParam(required = false) String[] questionTypes,
  875. @RequestParam(required = false) Integer[] structIds,
  876. @RequestParam(required = false) String startTime,
  877. @RequestParam(required = false) String endTime,
  878. @RequestParam(required = false) Boolean latest,
  879. @RequestParam(required = false) String year,
  880. @RequestParam(required = false) String order // (pid asc, no asc), time, correct, question_type, latest_time
  881. ) {
  882. User user = (User) shiroHelp.getLoginUser();
  883. QuestionNoModule questionNoModule = QuestionNoModule.ValueOf(module);
  884. Page<UserQuestion> p = null;
  885. if(questionNoModule == QuestionNoModule.EXERCISE){
  886. p = userQuestionService.listExerciseError(page, size, user.getId(), keyword, questionTypes, structIds, Tools.baseTime(startTime), Tools.baseTime(endTime), order != null ? order.replace("|", " ") : null);
  887. }else if (questionNoModule == QuestionNoModule.EXAMINATION){
  888. Integer libraryId = null;
  889. if (latest != null){
  890. if (latest) {
  891. TextbookLibrary textbookLibrary = textbookLibraryService.getLatest();
  892. libraryId = textbookLibrary.getId();
  893. year = null;
  894. }else{
  895. libraryId = 0;
  896. }
  897. }
  898. p = userQuestionService.listExaminationError(page, size, user.getId(), keyword, questionTypes, structIds, libraryId, year, Tools.baseTime(startTime), Tools.baseTime(endTime), order != null ? order.replace("|", " ") : null);
  899. }else{
  900. throw new ParameterException("参数逻辑错误");
  901. }
  902. List<UserQuestionErrorInfoDto> pr = Transform.convert(p, UserQuestionErrorInfoDto.class);
  903. // 获取题目信息
  904. Collection questionIds = Transform.getIds(pr, UserQuestionErrorInfoDto.class, "questionId");
  905. List<Question> questionList = questionService.select(questionIds);
  906. Transform.combine(pr, questionList, UserQuestionErrorInfoDto.class, "questionId", "question", Question.class, "id", QuestionExtendDto.class);
  907. Collection questionNoIds = Transform.getIds(pr, UserQuestionErrorInfoDto.class, "questionId");
  908. List<QuestionNo> questionNoList = questionNoService.select(questionNoIds);
  909. Transform.combine(pr, questionNoList, UserQuestionErrorInfoDto.class, "questionNoId", "questionNo", QuestionNo.class, "id", QuestionNoExtendDto.class);
  910. // 绑定题目统计
  911. List<UserQuestion> userQuestionList = userQuestionService.listByQuestion(user.getId(), questionIds);
  912. Map<Object, UserQuestionStat> stats = userQuestionService.statQuestionMap(userQuestionList);
  913. Transform.combine(pr, stats, UserQuestionErrorInfoDto.class, "questionId", "stat");
  914. // 最近做题
  915. List<UserQuestion> lastList = userQuestionService.listWithLast(user.getId(), questionIds);
  916. Map lastMap = Transform.getMap(lastList, UserQuestion.class, "id", "createTime");
  917. Transform.combine(pr, lastMap, UserQuestionErrorInfoDto.class, "questionId", "latestTime");
  918. // 收藏、笔记
  919. List<UserCollectQuestion> userCollectQuestionList = userCollectQuestionService.listByUserAndQuestions(user.getId(), questionIds);
  920. Map collectMap = Transform.getMap(userCollectQuestionList, UserCollectQuestion.class, "questionId", "id");
  921. List<UserNoteQuestion> userNoteQuestionList = userNoteQuestionService.listByUserAndQuestions(user.getId(), questionIds);
  922. Map noteMap = Transform.getMap(userNoteQuestionList, UserNoteQuestion.class, "questionId", "id");
  923. for(UserQuestionErrorInfoDto dto : pr){
  924. dto.setCollect(collectMap.containsKey(dto.getQuestionId()));
  925. dto.setNote(noteMap.containsKey(dto.getQuestionId()));
  926. }
  927. return ResponseHelp.success(pr, page, size, p.getTotal());
  928. }
  929. @RequestMapping(value = "/error/group", method = RequestMethod.POST)
  930. @ApiOperation(value = "错题组卷", notes = "错题组卷", httpMethod = "POST")
  931. public Response<UserPaper> bindError(@RequestBody @Validated UserCustomGroupDto dto) {
  932. User user = (User) shiroHelp.getLoginUser();
  933. QuestionModule questionModule = questionFlowService.validGroup(dto.getQuestionNoIds());
  934. UserPaper userPaper = questionFlowService.makePaper(
  935. user.getId(),
  936. questionModule,
  937. PaperOrigin.ERROR,
  938. Arrays.stream(dto.getQuestionNoIds()).collect(Collectors.toList()),
  939. dto.getFilterTimes()
  940. );
  941. return ResponseHelp.success(userPaper);
  942. }
  943. @RequestMapping(value = "/error/clear", method = RequestMethod.POST)
  944. @ApiOperation(value = "错题移除", notes = "错题移除", httpMethod = "POST")
  945. public Response<Boolean> clearError(@RequestBody @Validated UserQuestionNoIdsDto dto) {
  946. User user = (User) shiroHelp.getLoginUser();
  947. List<QuestionNo> questionNoList = questionNoService.select(dto.getQuestionNoIds());
  948. List<QuestionNoRelation> relationList = questionNoService.relation(questionNoList);
  949. userPaperQuestionService.addRemoveError(user.getId(), relationList);
  950. return ResponseHelp.success(true);
  951. }
  952. @RequestMapping(value = "/error/remove", method = RequestMethod.POST)
  953. @ApiOperation(value = "移除正确题", notes = "移除正确题", httpMethod = "POST")
  954. public Response<Boolean> removeError(@RequestBody @Validated ErrorReportDto dto) {
  955. User user = (User) shiroHelp.getLoginUser();
  956. UserReport report = userReportService.get(dto.getUserReportId());
  957. if (report.getIsFinish() == 0){
  958. throw new ParameterException("试卷未完成");
  959. }
  960. List<UserQuestion> questionList = userQuestionService.listByReport(user.getId(), dto.getUserReportId());
  961. Collection questionNoIds = Transform.getIds(questionList, UserQuestion.class, "questionNoId");
  962. List<QuestionNo> questionNoList = questionNoService.select(questionNoIds);
  963. List<QuestionNoRelation> relationList = questionNoService.relation(questionNoList);
  964. userPaperQuestionService.addRemoveError(user.getId(), relationList);
  965. return ResponseHelp.success(true);
  966. }
  967. @RequestMapping(value = "/note/question", method = RequestMethod.PUT)
  968. @ApiOperation(value = "更新题目笔记", notes = "更新题目笔记", httpMethod = "PUT")
  969. public Response<Boolean> updateNoteQuestion(@RequestBody @Validated UserNoteQuestionDto dto) {
  970. UserNoteQuestion entity = Transform.dtoToEntity(dto);
  971. User user = (User) shiroHelp.getLoginUser();
  972. entity.setUserId(user.getId());
  973. QuestionNo questionNo = questionNoService.get(dto.getQuestionNoId());
  974. QuestionNoModule questionNoModule = QuestionNoModule.ValueOf(questionNo.getModule());
  975. QuestionModule questionModule = QuestionModule.WithQuestionNo(questionNoModule);
  976. entity.setQuestionModule(questionModule.key);
  977. entity.setQuestionId(questionNo.getQuestionId());
  978. entity.setQuestionNoId(questionNo.getId());
  979. userNoteQuestionService.updateNote(entity);
  980. return ResponseHelp.success(true);
  981. }
  982. @RequestMapping(value = "/note/question/clear", method = RequestMethod.POST)
  983. @ApiOperation(value = "笔记移除", notes = "笔记移除", httpMethod = "POST")
  984. public Response<Boolean> clearNoteQuestion(@RequestBody @Validated UserQuestionNoIdsDto dto) {
  985. User user = (User) shiroHelp.getLoginUser();
  986. List<QuestionNo> questionNoList = questionNoService.select(dto.getQuestionNoIds());
  987. for(QuestionNo questionNo : questionNoList){
  988. userNoteQuestionService.deleteNote(user.getId(), questionNo.getQuestionId());
  989. }
  990. return ResponseHelp.success(true);
  991. }
  992. @RequestMapping(value = "/note/question/list", method = RequestMethod.GET)
  993. @ApiOperation(value = "获取题目笔记列表", notes = "获取笔记列表", httpMethod = "GET")
  994. public Response<PageMessage<UserNoteQuestionInfoDto>> listNoteQuestion(
  995. @RequestParam(required = false, defaultValue = "1") int page,
  996. @RequestParam(required = false, defaultValue = "100") int size,
  997. @RequestParam(required = false) String keyword,
  998. @RequestParam(required = false) String module,
  999. @RequestParam(required = false) String[] questionTypes,
  1000. @RequestParam(required = false) Integer[] structIds,
  1001. @RequestParam(required = false) String startTime,
  1002. @RequestParam(required = false) String endTime,
  1003. @RequestParam(required = false) Boolean latest,
  1004. @RequestParam(required = false) String year,
  1005. @RequestParam(required = false) String order, // update_time
  1006. HttpSession session) {
  1007. User user = (User) shiroHelp.getLoginUser();
  1008. QuestionNoModule questionNoModule = QuestionNoModule.ValueOf(module);
  1009. Page<UserNoteQuestion> p = null;
  1010. if(questionNoModule == QuestionNoModule.EXERCISE){
  1011. p = userNoteQuestionService.listExercise(page, size, user.getId(), keyword, questionTypes, structIds, Tools.baseTime(startTime), Tools.baseTime(endTime), order != null ? order.replace("|", " ") : null);
  1012. }else if (questionNoModule == QuestionNoModule.EXAMINATION){
  1013. Integer libraryId = null;
  1014. if (latest != null){
  1015. if (latest) {
  1016. TextbookLibrary textbookLibrary = textbookLibraryService.getLatest();
  1017. libraryId = textbookLibrary.getId();
  1018. year = null;
  1019. }else{
  1020. libraryId = 0;
  1021. }
  1022. }
  1023. p = userNoteQuestionService.listExamination(page, size, user.getId(), keyword, questionTypes, structIds, libraryId, year, Tools.baseTime(startTime), Tools.baseTime(endTime), order != null ? order.replace("|", " ") : null);
  1024. }else{
  1025. throw new ParameterException("参数逻辑错误");
  1026. }
  1027. List<UserNoteQuestionInfoDto> pr = Transform.convert(p, UserNoteQuestionInfoDto.class);
  1028. // 获取题目信息
  1029. Collection questionIds = Transform.getIds(pr, UserNoteQuestionInfoDto.class, "questionId");
  1030. List<Question> questionList = questionService.select(questionIds);
  1031. Transform.combine(pr, questionList, UserNoteQuestionInfoDto.class, "questionId", "question", Question.class, "id", QuestionExtendDto.class);
  1032. Collection questionNoIds = Transform.getIds(pr, UserNoteQuestionInfoDto.class, "questionNoId");
  1033. List<QuestionNo> questionNoList = questionNoService.select(questionNoIds);
  1034. Transform.combine(pr, questionNoList, UserNoteQuestionInfoDto.class, "questionNoId", "questionNo", QuestionNo.class, "id", QuestionNoExtendDto.class);
  1035. return ResponseHelp.success(pr, page, size, p.getTotal());
  1036. }
  1037. @RequestMapping(value = "/note/course", method = RequestMethod.PUT)
  1038. @ApiOperation(value = "更新课程笔记", notes = "更新课程笔记", httpMethod = "PUT")
  1039. public Response<Boolean> updateNoteCourse(@RequestBody @Validated UserNoteCourseDto dto) {
  1040. UserNoteCourse entity = Transform.dtoToEntity(dto);
  1041. User user = (User) shiroHelp.getLoginUser();
  1042. entity.setUserId(user.getId());
  1043. userNoteCourseService.update(entity);
  1044. return ResponseHelp.success(true);
  1045. }
  1046. @RequestMapping(value = "/note/course/clear", method = RequestMethod.POST)
  1047. @ApiOperation(value = "笔记移除", notes = "笔记移除", httpMethod = "POST")
  1048. public Response<Boolean> clearNoteCourse(@RequestBody @Validated UserCourseNoIdsDto dto) {
  1049. User user = (User) shiroHelp.getLoginUser();
  1050. List<CourseNo> courseNoList = courseNoService.select(dto.getCourseNoIds());
  1051. for(CourseNo courseNo : courseNoList){
  1052. userNoteCourseService.deleteNote(user.getId(), courseNo.getId());
  1053. }
  1054. return ResponseHelp.success(true);
  1055. }
  1056. @RequestMapping(value = "/note/course/list", method = RequestMethod.GET)
  1057. @ApiOperation(value = "获取课程笔记列表", notes = "获取笔记列表", httpMethod = "GET")
  1058. public Response<PageMessage<UserNoteCourse>> listNoteCourse(
  1059. @RequestParam(required = false, defaultValue = "1") int page,
  1060. @RequestParam(required = false, defaultValue = "100") int size,
  1061. @RequestParam(required = false) String keyword,
  1062. @RequestParam(required = false) Integer courseId,
  1063. @RequestParam(required = false, defaultValue = "") String order, // update_time, no
  1064. @RequestParam(required = false, defaultValue = "desc") String direction,
  1065. HttpSession session) {
  1066. User user = (User) shiroHelp.getLoginUser();
  1067. Page<UserNoteCourse> p = userNoteCourseService.listByCourse(page, size, keyword, user.getId(), courseId, order, DirectionStatus.ValueOf(direction));
  1068. return ResponseHelp.success(p, page, size, p.getTotal());
  1069. }
  1070. @RequestMapping(value = "/report/list", method = RequestMethod.GET)
  1071. @ApiOperation(value = "获取报告列表", notes = "获取报告列表", httpMethod = "GET")
  1072. public Response<PageMessage<UserPaperDto>> listReport(
  1073. @RequestParam(required = false, defaultValue = "1") int page,
  1074. @RequestParam(required = false, defaultValue = "100") int size,
  1075. @RequestParam(required = false) String keyword,
  1076. @RequestParam(required = false) String module,
  1077. @RequestParam(required = false) String origin,
  1078. @RequestParam(required = false) String[] questionTypes,
  1079. @RequestParam(required = false) Integer[] structIds,
  1080. @RequestParam(required = false) String startTime,
  1081. @RequestParam(required = false) String endTime,
  1082. @RequestParam(required = false) Boolean latest,
  1083. @RequestParam(required = false) String year,
  1084. @RequestParam(required = false) String[] courseModules,
  1085. @RequestParam(required = false) String order, // title, latest_time,correct,time
  1086. HttpSession session) {
  1087. User user = (User) shiroHelp.getLoginUser();
  1088. PaperOrigin paperOrigin = PaperOrigin.ValueOf(origin);
  1089. QuestionNoModule questionNoModule = QuestionNoModule.ValueOf(module);
  1090. Page<UserPaper> p = null;
  1091. if (paperOrigin == PaperOrigin.COLLECT || paperOrigin == PaperOrigin.ERROR){
  1092. p = userPaperService.list(page, size, user.getId(), keyword, paperOrigin, Tools.baseTime(startTime), Tools.baseTime(endTime), order != null ? order.replace("|", " ") : null);
  1093. }else if(questionNoModule == QuestionNoModule.EXERCISE){
  1094. p = userPaperService.listExercise(page, size, user.getId(), keyword, questionTypes, structIds, courseModules, Tools.baseTime(startTime), Tools.baseTime(endTime), order != null ? order.replace("|", " ") : null);
  1095. }else if (questionNoModule == QuestionNoModule.EXAMINATION){
  1096. Integer libraryId = null;
  1097. if (latest != null){
  1098. paperOrigin = PaperOrigin.TEXTBOOK;
  1099. if (latest) {
  1100. TextbookLibrary textbookLibrary = textbookLibraryService.getLatest();
  1101. libraryId = textbookLibrary.getId();
  1102. year = null;
  1103. }else{
  1104. libraryId = 0;
  1105. }
  1106. }
  1107. p = userPaperService.listExamination(page, size, user.getId(), keyword, structIds, libraryId, year, Tools.baseTime(startTime), Tools.baseTime(endTime), order != null ? order.replace("|", " ") : null);
  1108. }else{
  1109. throw new ParameterException("参数逻辑错误");
  1110. }
  1111. List<UserPaperDto> pr = Transform.convert(p, UserPaperDto.class);
  1112. if (questionNoModule == QuestionNoModule.EXAMINATION){
  1113. Collection originIds = Transform.getIds(p, UserPaper.class, "originId");
  1114. List<ExaminationPaper> examinationPapers = examinationPaperService.select(originIds);
  1115. Transform.combine(pr, examinationPapers, UserPaperDto.class, "originId", "origin", ExaminationPaper.class, "id", PaperExtendDto.class);
  1116. }
  1117. Collection paperIds = Transform.getIds(p, UserPaper.class, "id");
  1118. // 绑定用户报告
  1119. Map<Object, Collection<UserReport>> reportByPaper = userReportService.mapByPaper(paperIds);
  1120. Transform.combine(pr, reportByPaper, UserPaperDto.class, "id", "reports", UserReportExtendDto.class);
  1121. // 获取试卷统计信息
  1122. Map<Integer, Integer[]> idsMap = new HashMap<>();
  1123. for(UserPaperDto paper : pr){
  1124. if (paper.getQuestionNoIds() == null) continue;
  1125. idsMap.put(paper.getId(), paper.getQuestionNoIds());
  1126. }
  1127. Map statMap = questionNoService.statPaperMap(idsMap);
  1128. Transform.combine(pr, statMap, UserPaperDto.class, "id", "stat");
  1129. // 获取试卷题型
  1130. Map questionTypMap = questionNoService.questionTypeMap(idsMap);
  1131. Transform.combine(pr, questionTypMap, UserPaperDto.class, "id", "questionTypes");
  1132. return ResponseHelp.success(pr, page, size, p.getTotal());
  1133. }
  1134. @RequestMapping(value = "/ask/question", method = RequestMethod.POST)
  1135. @ApiOperation(value = "添加题目提问", notes = "添加题目提问", httpMethod = "POST")
  1136. public Response<Boolean> addAskQuestion(@RequestBody @Validated UserAskQuestionDto dto) {
  1137. UserAskQuestion entity = Transform.dtoToEntity(dto);
  1138. User user = (User) shiroHelp.getLoginUser();
  1139. entity.setUserId(user.getId());
  1140. QuestionNo questionNo = questionNoService.get(dto.getQuestionNoId());
  1141. QuestionNoModule questionNoModule = QuestionNoModule.ValueOf(questionNo.getModule());
  1142. QuestionModule questionModule = QuestionModule.WithQuestionNo(questionNoModule);
  1143. entity.setQuestionModule(questionModule.key);
  1144. entity.setQuestionId(questionNo.getQuestionId());
  1145. entity.setQuestionNoId(questionNo.getId());
  1146. Question question = questionService.get(questionNo.getQuestionId());
  1147. Integer assignId = null;
  1148. PaperModule paperModule = null;
  1149. if (dto.getUserQuestionId() != null && dto.getUserQuestionId() > 0){
  1150. UserQuestion userQuestion = userQuestionService.get(dto.getUserQuestionId());
  1151. UserReport userReport = userReportService.get(userQuestion.getReportId());
  1152. UserPaper userPaper = userPaperService.get(userReport.getPaperId());
  1153. if(userPaper != null && userPaper.getPaperOrigin().equals(PaperOrigin.PREVIEW.key)){
  1154. assignId = userPaper.getOriginId();
  1155. }
  1156. paperModule = PaperModule.ValueOf(userPaper.getPaperModule());
  1157. }else{
  1158. paperModule = PaperModule.WithQuestionNo(questionNoModule);
  1159. }
  1160. entity.setAskModule(AskModule.WithPaper(paperModule).key);
  1161. Integer recordId = questionFlowService.questionRelationCourse(user.getId(), assignId, QuestionType.ValueOf(question.getQuestionType()));
  1162. if (recordId != null){
  1163. // 绑定提问权限
  1164. entity.setRecordId(recordId);
  1165. UserOrderRecord record = userOrderRecordService.get(recordId);
  1166. entity.setAskTime(record.getAskTime());
  1167. Date now = new Date();
  1168. entity.setExpireTime(Tools.addHour(now, record.getAskTime() / 3600));
  1169. }else{
  1170. // todo 判断题目是否有提问权限
  1171. }
  1172. userAskQuestionService.add(entity);
  1173. return ResponseHelp.success(true);
  1174. }
  1175. @RequestMapping(value = "/ask/question/delete", method = RequestMethod.DELETE)
  1176. @ApiOperation(value = "提问删除", httpMethod = "DELETE")
  1177. public Response<Boolean> deleteAskQuestion(@RequestParam int id, HttpServletRequest request) {
  1178. UserAskQuestion in = userAskQuestionService.get(id);
  1179. User user = (User) shiroHelp.getLoginUser();
  1180. if(in == null){
  1181. throw new ParameterException("提问不存在");
  1182. }
  1183. if (!in.getUserId().equals(user.getId())){
  1184. throw new ParameterException("提问不存在");
  1185. }
  1186. if (in.getAnswerStatus()== AnswerStatus.ANSWER.index){
  1187. throw new ParameterException("提问已回答");
  1188. }
  1189. userAskQuestionService.delete(id);
  1190. // 如果
  1191. return ResponseHelp.success(true);
  1192. }
  1193. @RequestMapping(value = "/ask/question/list", method = RequestMethod.GET)
  1194. @ApiOperation(value = "获取题目提问列表", notes = "获取题目提问列表", httpMethod = "GET")
  1195. public Response<PageMessage<UserAskQuestionInfoDto>> listAskQuestion(
  1196. @RequestParam(required = false, defaultValue = "1") int page,
  1197. @RequestParam(required = false, defaultValue = "100") int size,
  1198. @RequestParam(required = false) String keyword,
  1199. @RequestParam(required = false) String module,
  1200. @RequestParam(required = false) String[] questionTypes,
  1201. @RequestParam(required = false) Integer[] structIds,
  1202. @RequestParam(required = false) String startTime,
  1203. @RequestParam(required = false) String endTime,
  1204. @RequestParam(required = false) Integer answerStatus,
  1205. @RequestParam(required = false) Boolean latest,
  1206. @RequestParam(required = false) String year,
  1207. @RequestParam(required = false) String order, // create_time, answer_time
  1208. HttpSession session) {
  1209. User user = (User) shiroHelp.getLoginUser();
  1210. QuestionNoModule questionNoModule = QuestionNoModule.ValueOf(module);
  1211. Page<UserAskQuestion> p = null;
  1212. if(questionNoModule == QuestionNoModule.EXERCISE){
  1213. p = userAskQuestionService.listExercise(page, size, user.getId(), keyword, questionTypes, structIds, AnswerStatus.ValueOf(answerStatus), Tools.baseTime(startTime), Tools.baseTime(endTime), order != null ? order.replace("|", " ") : null);
  1214. }else if (questionNoModule == QuestionNoModule.EXAMINATION){
  1215. Integer libraryId = null;
  1216. if (latest != null){
  1217. if (latest) {
  1218. TextbookLibrary textbookLibrary = textbookLibraryService.getLatest();
  1219. libraryId = textbookLibrary.getId();
  1220. year = null;
  1221. }else{
  1222. libraryId = 0;
  1223. }
  1224. }
  1225. p = userAskQuestionService.listExamination(page, size, user.getId(), keyword, questionTypes, structIds, libraryId, year, AnswerStatus.ValueOf(answerStatus), Tools.baseTime(startTime), Tools.baseTime(endTime), order != null ? order.replace("|", " ") : null);
  1226. }else{
  1227. throw new ParameterException("参数逻辑错误");
  1228. }
  1229. List<UserAskQuestionInfoDto> pr = Transform.convert(p, UserAskQuestionInfoDto.class);
  1230. // 获取题目信息
  1231. Collection questionIds = Transform.getIds(pr, UserAskQuestionInfoDto.class, "questionId");
  1232. List<Question> questionList = questionService.select(questionIds);
  1233. Transform.combine(pr, questionList, UserAskQuestionInfoDto.class, "questionId", "question", Question.class, "id", QuestionExtendDto.class);
  1234. Collection questionNoIds = Transform.getIds(pr, UserAskQuestionInfoDto.class, "questionNoId");
  1235. List<QuestionNo> questionNoList = questionNoService.select(questionNoIds);
  1236. Transform.combine(pr, questionNoList, UserAskQuestionInfoDto.class, "questionNoId", "questionNo", QuestionNo.class, "id", QuestionNoExtendDto.class);
  1237. return ResponseHelp.success(pr, page, size, p.getTotal());
  1238. }
  1239. @RequestMapping(value = "/ask/course", method = RequestMethod.POST)
  1240. @ApiOperation(value = "添加课程提问", notes = "添加课程提问", httpMethod = "POST")
  1241. public Response<Boolean> addAskCourse(@RequestBody @Validated UserAskCourseDto dto) {
  1242. UserAskCourse entity = Transform.dtoToEntity(dto);
  1243. User user = (User) shiroHelp.getLoginUser();
  1244. entity.setUserId(user.getId());
  1245. UserCourse userCourse = courseExtendService.userCourse(user.getId(), dto.getCourseId());
  1246. if (userCourse != null){
  1247. // 绑定提问权限
  1248. entity.setRecordId(userCourse.getRecordId());
  1249. UserOrderRecord record = userOrderRecordService.get(userCourse.getRecordId());
  1250. entity.setAskTime(record.getAskTime());
  1251. Date now = new Date();
  1252. entity.setExpireTime(Tools.addHour(now, record.getAskTime() / 3600));
  1253. }else{
  1254. throw new ParameterException("课程需开通后才能提问");
  1255. }
  1256. userAskCourseService.add(entity);
  1257. return ResponseHelp.success(true);
  1258. }
  1259. @RequestMapping(value = "/ask/course/delete", method = RequestMethod.DELETE)
  1260. @ApiOperation(value = "提问课程提问", httpMethod = "DELETE")
  1261. public Response<Boolean> deleteAskCourse(@RequestParam int id, HttpServletRequest request) {
  1262. UserAskCourse in = userAskCourseService.get(id);
  1263. User user = (User) shiroHelp.getLoginUser();
  1264. if(in == null){
  1265. throw new ParameterException("提问不存在");
  1266. }
  1267. if (!in.getUserId().equals(user.getId())){
  1268. throw new ParameterException("提问不存在");
  1269. }
  1270. if (in.getAnswerStatus()== AnswerStatus.ANSWER.index){
  1271. throw new ParameterException("提问已回答");
  1272. }
  1273. userAskCourseService.delete(id);
  1274. // 如果
  1275. return ResponseHelp.success(true);
  1276. }
  1277. @RequestMapping(value = "/ask/course/list", method = RequestMethod.GET)
  1278. @ApiOperation(value = "获取课程提问列表", notes = "获取课程提问列表", httpMethod = "GET")
  1279. public Response<PageMessage<UserAskCourse>> listAskCourse(
  1280. @RequestParam(required = false, defaultValue = "1") int page,
  1281. @RequestParam(required = false, defaultValue = "100") int size,
  1282. @RequestParam(required = false) String keyword,
  1283. @RequestParam(required = false) Integer courseId,
  1284. @RequestParam(required = false) Integer courseNoId,
  1285. @RequestParam(required = false) Integer answerStatus,
  1286. @RequestParam(required = false) Integer position,
  1287. @RequestParam(required = false) String order, // create_time, answer_time
  1288. @RequestParam(required = false,defaultValue = "desc") String direction,
  1289. HttpSession session) {
  1290. User user = (User) shiroHelp.getLoginUser();
  1291. Page<UserAskCourse> p = userAskCourseService.listByUser(page, size, keyword, user.getId(), courseId, courseNoId, position, AnswerStatus.ValueOf(answerStatus), order, DirectionStatus.ValueOf(direction));
  1292. return ResponseHelp.success(p, page, size, p.getTotal());
  1293. }
  1294. @RequestMapping(value = "/feedback/error/question", method = RequestMethod.POST)
  1295. @ApiOperation(value = "添加题目勘误", notes = "添加勘误", httpMethod = "POST")
  1296. public Response<Boolean> addFeedbackErrorQuestion(@RequestBody @Validated UserFeedbackErrorQuestionDto dto) {
  1297. UserFeedbackError entity = Transform.dtoToEntity(dto);
  1298. User user = (User) shiroHelp.getLoginUser();
  1299. entity.setUserId(user.getId());
  1300. entity.setStatus(0);
  1301. entity.setModule(FeedbackModule.QUESTION.key);
  1302. QuestionNo questionNo = questionNoService.get(dto.getQuestionNoId());
  1303. QuestionNoModule questionNoModule = QuestionNoModule.ValueOf(questionNo.getModule());
  1304. QuestionModule questionModule = QuestionModule.WithQuestionNo(questionNoModule);
  1305. entity.setQuestionModule(questionModule.key);
  1306. entity.setQuestionNoId(questionNo.getId());
  1307. entity.setModuleId(questionNo.getQuestionId());
  1308. Question question = questionService.get(questionNo.getQuestionId());
  1309. entity.setQuestionType(question.getQuestionType());
  1310. userFeedbackErrorService.add(entity);
  1311. return ResponseHelp.success(true);
  1312. }
  1313. @RequestMapping(value = "/feedback/error/data", method = RequestMethod.POST)
  1314. @ApiOperation(value = "添加资料勘误", notes = "添加勘误", httpMethod = "POST")
  1315. public Response<Boolean> addFeedbackError(@RequestBody @Validated UserFeedbackErrorDataDto dto) {
  1316. UserFeedbackError entity = Transform.dtoToEntity(dto);
  1317. User user = (User) shiroHelp.getLoginUser();
  1318. entity.setUserId(user.getId());
  1319. entity.setModule(FeedbackModule.DATA.key);
  1320. entity.setModuleId(dto.getDataId());
  1321. entity.setStatus(0);
  1322. userFeedbackErrorService.add(entity);
  1323. return ResponseHelp.success(true);
  1324. }
  1325. @RequestMapping(value = "/feedback/textbook", method = RequestMethod.POST)
  1326. @ApiOperation(value = "添加机经反馈", notes = "添加反馈", httpMethod = "POST")
  1327. public Response<Boolean> addFeedbackTextbook(@RequestBody @Validated UserTextbookFeedbackDto dto) {
  1328. UserTextbookFeedback entity = Transform.dtoToEntity(dto);
  1329. User user = (User) shiroHelp.getLoginUser();
  1330. TextbookLibrary latest = textbookLibraryService.getLatest();
  1331. entity.setLibraryId(latest.getId());
  1332. entity.setUserId(user.getId());
  1333. entity.setStatus(0);
  1334. if (entity.getNo() != null && entity.getNo() > 0){
  1335. TextbookTopic textbookTopic = textbookTopicService.getByNo(entity.getLibraryId(), entity.getTextbookSubject(), entity.getNo());
  1336. if (textbookTopic == null){
  1337. throw new ParameterException("题目不存在");
  1338. }
  1339. if (textbookTopic != null){
  1340. entity.setTopicId(textbookTopic.getId());
  1341. }
  1342. }
  1343. userTextbookFeedbackService.add(entity);
  1344. return ResponseHelp.success(true);
  1345. }
  1346. @RequestMapping(value = "/feedback/ready/room", method = RequestMethod.POST)
  1347. @ApiOperation(value = "添加考场反馈", notes = "添加考场反馈", httpMethod = "POST")
  1348. public Response<Boolean> addFeedbackTextbook(@RequestBody @Validated UserReadyRoomFeedbackDto dto) {
  1349. UserReadyRoomFeedback entity = Transform.dtoToEntity(dto);
  1350. User user = (User) shiroHelp.getLoginUser();
  1351. entity.setUserId(user.getId());
  1352. userReadyRoomFeedbackService.add(entity);
  1353. return ResponseHelp.success(true);
  1354. }
  1355. @RequestMapping(value = "/faq", method = RequestMethod.POST)
  1356. @ApiOperation(value = "添加faq", notes = "添加faq", httpMethod = "POST")
  1357. public Response<Boolean> addFaq(@RequestBody @Validated FaqDto dto) {
  1358. Faq entity = Transform.dtoToEntity(dto);
  1359. User user = (User) shiroHelp.getLoginUser();
  1360. entity.setUserId(user.getId());
  1361. entity.setMessage(1);
  1362. // 取消邮箱发送
  1363. // entity.setEmail(user.getEmail());
  1364. faqService.add(entity);
  1365. return ResponseHelp.success(true);
  1366. }
  1367. @RequestMapping(value = "/comment", method = RequestMethod.POST)
  1368. @ApiOperation(value = "添加评论", notes = "添加评论", httpMethod = "POST")
  1369. public Response<Boolean> addComment(@RequestBody @Validated CommentDto dto) {
  1370. Comment entity = Transform.dtoToEntity(dto);
  1371. User user = (User) shiroHelp.getLoginUser();
  1372. entity.setUserId(user.getId());
  1373. commentService.add(entity);
  1374. return ResponseHelp.success(true);
  1375. }
  1376. @RequestMapping(value = "/data/email/subscribe", method = RequestMethod.POST)
  1377. @ApiOperation(value = "资料订阅", notes = "资料订阅", httpMethod = "POST")
  1378. public Response<Boolean> subscribeDataEmail(@RequestBody @Validated DataEmailSubscribeDto dto) {
  1379. User user = (User) shiroHelp.getLoginUser();
  1380. if (user == null){
  1381. throw new AuthException("请先登录");
  1382. }
  1383. usersService.edit(User.builder()
  1384. .id(user.getId())
  1385. .dataEmailSubscribe(dto.getSubscribe() ? 1 : 0)
  1386. .build());
  1387. return ResponseHelp.success(true);
  1388. }
  1389. @RequestMapping(value = "/data/subscribe", method = RequestMethod.POST)
  1390. @ApiOperation(value = "资料订阅", httpMethod = "POST")
  1391. public Response<Boolean> subscribeData(@RequestBody @Validated DataSubscribeDto dto) {
  1392. User user = (User) shiroHelp.getLoginUser();
  1393. UserCourseDataSubscribe subscribe = userCourseDataSubscribeService.getByData(user.getId(), dto.getDataId());
  1394. if (dto.getSubscribe()){
  1395. if (subscribe == null){
  1396. userCourseDataSubscribeService.add(UserCourseDataSubscribe.builder()
  1397. .userId(user.getId())
  1398. .dataId(dto.getDataId())
  1399. .build());
  1400. }
  1401. }else{
  1402. if (subscribe!=null){
  1403. userCourseDataSubscribeService.delete(subscribe.getId());
  1404. }
  1405. }
  1406. return ResponseHelp.success(true);
  1407. }
  1408. @RequestMapping(value = "/data/history", method = RequestMethod.GET)
  1409. @ApiOperation(value = "资料更新记录", httpMethod = "GET")
  1410. public Response<PageMessage<CourseDataHistoryInfoDto>> listDataHistory(
  1411. @RequestParam(required = false, defaultValue = "1") int page,
  1412. @RequestParam(required = false, defaultValue = "100") int size,
  1413. @RequestParam(required = false) Integer dataId,
  1414. HttpSession session) {
  1415. User user = (User) shiroHelp.getLoginUser();
  1416. Page<CourseDataHistory> p = courseDataHistoryService.listByUser(page, size, dataId, user.getId());
  1417. List<CourseDataHistoryInfoDto> pr = Transform.convert(p, CourseDataHistoryInfoDto.class);
  1418. // 绑定资料
  1419. Collection dataIds = Transform.getIds(p, CourseDataHistory.class, "dataId");
  1420. List<CourseData> dataList = courseDataService.select(dataIds);
  1421. Transform.combine(pr, dataList, CourseDataHistoryInfoDto.class, "dataId", "data", CourseData.class, "id", CourseDataExtendDto.class);
  1422. return ResponseHelp.success(pr, page, size, p.getTotal());
  1423. }
  1424. @RequestMapping(value = "/data/list", method = RequestMethod.GET)
  1425. @ApiOperation(value = "订阅资料记录", httpMethod = "GET")
  1426. public Response<PageMessage<CourseDataListDto>> listData(
  1427. @RequestParam(required = false, defaultValue = "1") int page,
  1428. @RequestParam(required = false, defaultValue = "100") int size,
  1429. @RequestParam(required = false) Integer structId,
  1430. @RequestParam(required = false) String dataType,
  1431. @RequestParam(required = false, defaultValue = "id") String order, // latest_time, sale_number
  1432. @RequestParam(required = false, defaultValue = "desc") String direction,
  1433. HttpSession session) {
  1434. User user = (User) shiroHelp.getLoginUser();
  1435. Page<CourseData> p = courseDataService.listByUser(page, size, user.getId(), structId, DataType.ValueOf(dataType),order, DirectionStatus.ValueOf(direction));
  1436. courseExtendService.refreshDataResource(user, p);
  1437. List<CourseDataListDto> pr = Transform.convert(p, CourseDataListDto.class);
  1438. Collection ids = Transform.getIds(p, CourseData.class, "id");
  1439. // 已购买: 查看当前服务
  1440. List<UserOrderRecord> userOrderRecordList = userOrderRecordService.listWithUserData(user.getId(), ids);
  1441. Map userOrderRecordMap = Transform.getMap(userOrderRecordList, UserOrderRecord.class, "productId");
  1442. // 添加购物车
  1443. List<UserOrderCheckout> userOrderCheckoutList = userOrderCheckoutService.listWithProduct(user.getId(), ProductType.DATA, ids);
  1444. Map userOrderCheckoutMap = Transform.getMap(userOrderCheckoutList, UserOrderCheckout.class, "productId");
  1445. for(CourseDataListDto dto : pr){
  1446. dto.setHave(userOrderRecordMap.containsKey(dto.getId()));
  1447. dto.setAdd(userOrderCheckoutMap.containsKey(dto.getId()));
  1448. }
  1449. return ResponseHelp.success(pr, page, size, p.getTotal());
  1450. }
  1451. @RequestMapping(value = "/course/list", method = RequestMethod.GET)
  1452. @ApiOperation(value = "购买的课程记录", httpMethod = "GET")
  1453. public Response<PageMessage<UserCourseDetailDto>> listCourse(
  1454. @RequestParam(required = false, defaultValue = "1") int page,
  1455. @RequestParam(required = false, defaultValue = "100") int size,
  1456. @RequestParam(required = false) String courseModule,
  1457. @RequestParam(required = false) Boolean isUsed,
  1458. @RequestParam(required = false) Boolean isEnd,
  1459. @RequestParam(required = false, defaultValue = "id") String order, // useEndTime desc
  1460. @RequestParam(required = false, defaultValue = "desc") String direction,
  1461. HttpSession session) {
  1462. User user = (User) shiroHelp.getLoginUser();
  1463. CourseModule module = CourseModule.ValueOf(courseModule);
  1464. Page<UserOrderRecord> p;
  1465. if (module == CourseModule.ONLINE){
  1466. // 在线课程包含:视频课程、小班课程
  1467. p = userOrderRecordService.listWithCourse(page, size, user.getId(), new String[]{CourseModule.VIDEO.key}, isUsed,isEnd, order, DirectionStatus.ValueOf(direction));
  1468. } else if (module == CourseModule.VS){
  1469. // 1v1课程:只有系统授课有作业
  1470. p = userOrderRecordService.listWithCourse(page, size, user.getId(), new String[]{CourseModule.VS.key}, isUsed,isEnd, order, DirectionStatus.ValueOf(direction));
  1471. }else{
  1472. throw new ParameterException("课程类型错误");
  1473. }
  1474. List<UserCourseDetailDto> pr = Transform.convert(p, UserCourseDetailDto.class);
  1475. Map<Integer, UserOrderRecord> map = new HashMap<>();
  1476. for(UserOrderRecord record : p){
  1477. map.put(record.getId(), record);
  1478. }
  1479. Collection recordIds = Transform.getIds(p, UserOrderRecord.class,"id");
  1480. // 绑定课程
  1481. Collection courseIds = Transform.getIds(p, UserOrderRecord.class, "productId");
  1482. List<Course> courseList = courseService.select(courseIds);
  1483. Map courseMap = Transform.getMap(courseList, Course.class, "id");
  1484. Transform.combine(pr, courseList, UserCourseDetailDto.class, "productId", "course", Course.class, "id", CourseExtendDto.class);
  1485. // 绑定课时、预约、进度
  1486. Map<Object, Collection<CourseNo>> courseNoMap = courseNoService.groupByCourseId(courseIds);
  1487. Transform.combine(pr, courseNoMap, UserCourseDetailDto.class, "productId", "courseNos", CourseNoExtendDto.class);
  1488. Map<Object, Collection<UserCourseAppointment>> appointmentMap = userCourseAppointmentService.groupByRecordId(recordIds);
  1489. Transform.combine(pr, appointmentMap, UserCourseDetailDto.class, "id", "appointments", UserCourseAppointmentExtendDto.class);
  1490. Map<Object, Collection<UserCourseProgress>> progressMap = userCourseProgressService.groupByRecordId(recordIds);
  1491. Transform.combine(pr, progressMap, UserCourseDetailDto.class, "id", "progress", UserCourseProgressExtendDto.class);
  1492. Map<Object, Collection<UserCourseRecord>> recordMap = userCourseRecordService.groupByRecordId(recordIds);
  1493. for(UserCourseDetailDto dto : pr){
  1494. dto.setTotalDays(courseExtendService.computeCourseDay(map.get(dto.getId())));
  1495. Collection<CourseNo> courseNos = courseNoMap.get(dto.getProductId());
  1496. if (courseNos == null || courseNos.size() == 0) continue;
  1497. Collection<UserCourseProgress> list = progressMap.get(dto.getId());
  1498. if (list == null || list.size() == 0) continue;
  1499. dto.setCurrentNo(courseExtendService.computeCourseNoCurrent(courseNos, list));
  1500. Collection<UserCourseRecord> userCourseRecords = recordMap.get(dto.getId());
  1501. dto.setTotalTime(courseExtendService.computeCourseTime(userCourseRecords));
  1502. }
  1503. // 获取每个科目的所有作业
  1504. Map<Object, Collection<UserPreviewPaperRelation>> previewMap = previewService.groupByRecordId(user.getId(), recordIds, 1000);
  1505. Transform.combine(pr, previewMap, UserCourseDetailDto.class, "id", "papers", BasePaperExtendDto.class);
  1506. for(UserCourseDetailDto dto : pr){
  1507. Collection<UserPreviewPaperRelation> list = previewMap.get(dto.getId());
  1508. if (list == null || list.size() == 0) continue;
  1509. int finish = 0;
  1510. for(UserPreviewPaperRelation relation : list){
  1511. if (relation.getPaper() == null) continue;
  1512. UserPaper paper = relation.getPaper();
  1513. if (paper.getTimes() > 0){
  1514. finish += 1;
  1515. }
  1516. }
  1517. dto.setPreviewProgress(list.size()> 0 ? finish * 100 / list.size(): 0);
  1518. }
  1519. // 绑定老师
  1520. Collection teacherIds = Transform.getIds(p, UserOrderRecord.class, "teacherId");
  1521. List<CourseTeacher> teacherList = courseTeacherService.select(teacherIds);
  1522. Transform.combine(pr, teacherList, UserCourseDetailDto.class, "teacherId", "teacher", CourseTeacher.class, "id", CourseTeacherExtendDto.class);
  1523. // 提问数、笔记数
  1524. Map<Object, Collection<UserAskCourse>> askMap = userAskCourseService.groupByRecordId(recordIds);
  1525. Map<Object, Collection<UserNoteCourse>> noteMap = userNoteCourseService.groupByCourse(user.getId(), courseIds);
  1526. for(UserCourseDetailDto dto : pr){
  1527. Collection<CourseNoExtendDto> courseNos = dto.getCourseNos();
  1528. if (courseNos == null) continue;
  1529. Collection<UserAskCourse> askList = askMap.get(dto.getId());
  1530. Map<Object, List<UserAskCourse>> askListMap = Transform.getMapList(askList, UserAskCourse.class, "courseNoId");
  1531. Collection<UserNoteCourse> noteList = noteMap.get(dto.getProductId());
  1532. Map notes = Transform.getMap(noteList, UserNoteCourse.class, "courseNoId");
  1533. int noteNumber = 0;
  1534. int askNumber = askList == null ? 0: askList.size();
  1535. int answerNumber = askList == null ? 0 : (int)askList.stream().filter(r->r.getAnswerStatus()== AnswerStatus.ANSWER.index).count();
  1536. for(CourseNoExtendDto courseNo : courseNos){
  1537. if (notes.get(courseNo.getId()) != null){
  1538. courseNo.setNote(true);
  1539. noteNumber += 1;
  1540. }
  1541. List<UserAskCourse> askListNo = askListMap.get(courseNo.getId());
  1542. if (askListNo != null){
  1543. courseNo.setAskNumber(askListNo.size());
  1544. courseNo.setAnswerNumber((int)askListNo.stream().filter(r->r.getAnswerStatus()== AnswerStatus.ANSWER.index).count());
  1545. }
  1546. }
  1547. dto.setNoteNumber(noteNumber);
  1548. dto.setAskNumber(askNumber);
  1549. dto.setAnswerNumber(answerNumber);
  1550. }
  1551. // vs预约comment
  1552. Map<Object, Collection<UserCourseAppointmentComment>> commentMap = userCourseAppointmentCommentService.groupByRecordId(recordIds);
  1553. Transform.combine(pr, commentMap, UserCourseDetailDto.class, "id", "comments", UserCourseAppointmentComment.class);
  1554. return ResponseHelp.success(pr, page, size, p.getTotal());
  1555. }
  1556. @RequestMapping(value = "/course/detail", method = RequestMethod.GET)
  1557. @ApiOperation(value = "购买的课程记录", httpMethod = "GET")
  1558. public Response<UserCourseDetailDto> detailCourse(int recordId,
  1559. HttpSession session) {
  1560. User user = (User) shiroHelp.getLoginUser();
  1561. UserOrderRecord record = userOrderRecordService.get(recordId);
  1562. UserCourseDetailDto dto = Transform.convert(record, UserCourseDetailDto.class);
  1563. // 绑定课程
  1564. Course course = courseService.get(record.getProductId());
  1565. dto.setCourse(Transform.convert(course, CourseExtendDto.class));
  1566. // 绑定课时、预约、进度
  1567. List<CourseNo> courseNoList = courseNoService.allCourse(course.getId());
  1568. dto.setCourseNos(Transform.convert(courseNoList, CourseNoExtendDto.class));
  1569. List<UserCourseAppointment> appointmentList = userCourseAppointmentService.listByRecord(recordId);
  1570. dto.setAppointments(Transform.convert(appointmentList, UserCourseAppointmentExtendDto.class));
  1571. List<UserCourseProgress> progressList = userCourseProgressService.listCourse(recordId, course.getId());
  1572. List<UserCourseRecord> recordList = userCourseRecordService.allWithRecord(recordId);
  1573. if(progressList != null)dto.setCurrentNo(courseExtendService.computeCourseNoCurrent(courseNoList, progressList));
  1574. if(recordList != null)dto.setTotalTime(courseExtendService.computeCourseTime(recordList));
  1575. dto.setTotalDays(courseExtendService.computeCourseDay(record));
  1576. // 获取每个科目的所有作业
  1577. List<UserPreviewPaperRelation> previewList = previewService.list(1, 1000, recordId, user.getId(), null,null);
  1578. dto.setPapers(Transform.convert(previewList, BasePaperExtendDto.class));
  1579. int finish = 0;
  1580. for(UserPreviewPaperRelation relation : previewList){
  1581. if (relation.getPaper() == null) continue;
  1582. UserPaper paper = relation.getPaper();
  1583. if (paper.getTimes() > 0){
  1584. finish += 1;
  1585. }
  1586. }
  1587. dto.setPreviewProgress(previewList.size() > 0 ? finish * 100 / previewList.size(): 0);
  1588. // 绑定老师
  1589. CourseTeacher teacher = courseTeacherService.get(record.getTeacherId());
  1590. dto.setTeacher(Transform.convert(teacher, CourseTeacherExtendDto.class));
  1591. // 提问数、笔记数
  1592. Collection<CourseNoExtendDto> courseNos = dto.getCourseNos();
  1593. if (courseNos != null && courseNos.size() > 0) {
  1594. Collection<UserAskCourse> askList = userAskCourseService.listByRecord(recordId);
  1595. Map<Object, List<UserAskCourse>> askListMap = Transform.getMapList(askList, UserAskCourse.class, "courseNoId");
  1596. Collection<UserNoteCourse> noteList = userNoteCourseService.listByCourse(course.getId());
  1597. Map notes = Transform.getMap(noteList, UserNoteCourse.class, "courseNoId");
  1598. int noteNumber = 0;
  1599. int askNumber = askList.size();
  1600. int answerNumber = (int)askList.stream().filter(r->r.getAnswerStatus()== AnswerStatus.ANSWER.index).count();
  1601. for(CourseNoExtendDto courseNo : courseNos){
  1602. if (notes.get(courseNo.getId()) != null){
  1603. courseNo.setNote(true);
  1604. noteNumber += 1;
  1605. }
  1606. List<UserAskCourse> askListNo = askListMap.get(courseNo.getId());
  1607. if (askListNo != null){
  1608. courseNo.setAskNumber(askListNo.size());
  1609. courseNo.setAnswerNumber((int)askListNo.stream().filter(r->r.getAnswerStatus()== AnswerStatus.ANSWER.index).count());
  1610. }
  1611. }
  1612. dto.setNoteNumber(noteNumber);
  1613. dto.setAskNumber(askNumber);
  1614. dto.setAnswerNumber(answerNumber);
  1615. }
  1616. // vs预约comment
  1617. List<UserCourseAppointmentComment> commentList = userCourseAppointmentCommentService.listByRecord(recordId);
  1618. dto.setComments(commentList);
  1619. return ResponseHelp.success(dto);
  1620. }
  1621. @RequestMapping(value = "/course/cctalk_name", method = RequestMethod.POST)
  1622. @ApiOperation(value = "设置课程cctalk", notes = "设置课程cctalk", httpMethod = "POST")
  1623. public Response<Boolean> setCourseCCTalkName(@RequestBody @Validated UserCourseCCTalkNameDto dto) {
  1624. User user = (User) shiroHelp.getLoginUser();
  1625. UserOrderRecord entity = Transform.dtoToEntity(dto);
  1626. UserOrderRecord in = userOrderRecordService.get(dto.getId());
  1627. if (!in.getUserId().equals(user.getId())){
  1628. throw new ParameterException("记录不存在");
  1629. }
  1630. entity = userOrderRecordService.edit(entity);
  1631. return ResponseHelp.success(true);
  1632. }
  1633. @RequestMapping(value = "/course/appointment/question", method = RequestMethod.POST)
  1634. @ApiOperation(value = "预约提交答疑文档", notes = "预约提交答疑文档", httpMethod = "POST")
  1635. public Response<Boolean> uploadAppointmentQuestion(@RequestBody @Validated UserCourseAppointmentQuestionDto dto) {
  1636. User user = (User) shiroHelp.getLoginUser();
  1637. UserCourseAppointment entity = Transform.dtoToEntity(dto);
  1638. UserCourseAppointment in = userCourseAppointmentService.get(dto.getId());
  1639. if (!in.getUserId().equals(user.getId())){
  1640. throw new ParameterException("记录不存在");
  1641. }
  1642. entity = userCourseAppointmentService.edit(entity);
  1643. return ResponseHelp.success(true);
  1644. }
  1645. @RequestMapping(value = "/course/appointment/comment/add", method = RequestMethod.POST)
  1646. @ApiOperation(value = "预约评论添加", notes = "预约评论添加", httpMethod = "POST")
  1647. public Response<Boolean> addAppointmentComment(@RequestBody @Validated UserCourseAppointmentCommentDto dto) {
  1648. User user = (User) shiroHelp.getLoginUser();
  1649. UserCourseAppointmentComment entity = Transform.dtoToEntity(dto);
  1650. UserCourseAppointment appointment = userCourseAppointmentService.get(entity.getAppointmentId());
  1651. entity.setUserId(user.getId());
  1652. entity.setRecordId(appointment.getRecordId());
  1653. if (entity.getParentId() > 0){
  1654. UserCourseAppointmentComment comment = userCourseAppointmentCommentService.get(entity.getParentId());
  1655. if (comment != null){
  1656. entity.setReply(comment.getContent());
  1657. }
  1658. }
  1659. entity = userCourseAppointmentCommentService.add(entity);
  1660. return ResponseHelp.success(true);
  1661. }
  1662. @RequestMapping(value = "/course/appointment/comment/edit", method = RequestMethod.POST)
  1663. @ApiOperation(value = "预约评论编辑", notes = "预约评论编辑", httpMethod = "POST")
  1664. public Response<Boolean> editAppointmentComment(@RequestBody @Validated UserCourseAppointmentCommentDto dto) {
  1665. User user = (User) shiroHelp.getLoginUser();
  1666. UserCourseAppointmentComment entity = Transform.dtoToEntity(dto);
  1667. UserCourseAppointmentComment in = userCourseAppointmentCommentService.get(dto.getId());
  1668. if (!in.getUserId().equals(user.getId())){
  1669. throw new ParameterException("记录不存在");
  1670. }
  1671. entity = userCourseAppointmentCommentService.edit(entity);
  1672. return ResponseHelp.success(true);
  1673. }
  1674. @RequestMapping(value = "/course/appointment/comment/delete", method = RequestMethod.DELETE)
  1675. @ApiOperation(value = "预约评论删除", notes = "预约评论删除", httpMethod = "DELETE")
  1676. public Response<Boolean> deleteAppointmentComment(int id) {
  1677. User user = (User) shiroHelp.getLoginUser();
  1678. UserCourseAppointmentComment in = userCourseAppointmentCommentService.get(id);
  1679. if (!in.getUserId().equals(user.getId())){
  1680. throw new ParameterException("记录不存在");
  1681. }
  1682. userCourseAppointmentCommentService.delete(id);
  1683. return ResponseHelp.success(true);
  1684. }
  1685. @RequestMapping(value = "/course/suspend", method = RequestMethod.POST)
  1686. @ApiOperation(value = "申请停课", notes = "申请停课", httpMethod = "POST")
  1687. public Response<Boolean> suspendCourse(@RequestBody @Validated CourseSuspendDto dto) {
  1688. User user = (User) shiroHelp.getLoginUser();
  1689. courseExtendService.suspendCourse(user.getId(), dto.getRecordId());
  1690. return ResponseHelp.success(true);
  1691. }
  1692. @RequestMapping(value = "/course/restore", method = RequestMethod.POST)
  1693. @ApiOperation(value = "恢复停课", notes = "恢复停课", httpMethod = "POST")
  1694. public Response<Boolean> restoreCourse(@RequestBody @Validated CourseRestoreDto dto) {
  1695. User user = (User) shiroHelp.getLoginUser();
  1696. courseExtendService.restoreCourse(user.getId(), dto.getRecordId());
  1697. return ResponseHelp.success(true);
  1698. }
  1699. @RequestMapping(value = "/course/time", method = RequestMethod.GET)
  1700. @ApiOperation(value = "时间表", notes = "时间表", httpMethod = "GET")
  1701. public Response<List<UserCourseTimeDto>> timeCourse(int recordId) {
  1702. User user = (User) shiroHelp.getLoginUser();
  1703. List<UserCourseTimeDto> dtos = new ArrayList<>();
  1704. UserOrderRecord record = userOrderRecordService.get(recordId);
  1705. if (record == null){
  1706. throw new ParameterException("记录不存在");
  1707. }
  1708. if (!record.getUserId().equals(user.getId())){
  1709. throw new ParameterException("记录不存在");
  1710. }
  1711. Integer courseId = record.getProductId();
  1712. // 获取停课记录
  1713. Date suspend = record.getSuspendTime();
  1714. if (suspend != null){
  1715. Date restore = record.getRestoreTime();
  1716. if (restore == null) restore = new Date();
  1717. while(suspend.before(restore)){
  1718. UserCourseTimeDto dto = new UserCourseTimeDto();
  1719. dto.setType("stop");
  1720. dto.setDay(Tools.day(suspend));
  1721. dtos.add(dto);
  1722. suspend = Tools.addDate(suspend, 1);
  1723. }
  1724. }
  1725. List<Long> tmpList = new ArrayList<>();
  1726. // 获取听课记录
  1727. List<UserCourseRecord> userCourseRecordList = userCourseRecordService.allWithRecord(recordId);
  1728. tmpList.clear();
  1729. for(UserCourseRecord userCourseRecord:userCourseRecordList){
  1730. Date day = Tools.day(userCourseRecord.getCreateTime());
  1731. if (!tmpList.contains(day.getTime())){
  1732. tmpList.add(day.getTime());
  1733. UserCourseTimeDto dto = new UserCourseTimeDto();
  1734. dto.setType("course");
  1735. dto.setDay(day);
  1736. dtos.add(dto);
  1737. }
  1738. }
  1739. // 预习作业
  1740. List<CourseNo> courseNoList = courseNoService.allCourse(courseId);
  1741. Collection courseNoIds = Transform.getIds(courseNoList, CourseNo.class, "id");
  1742. List<PreviewAssign> previewAssignList = previewAssignService.listByCourseNos(courseId, courseNoIds);
  1743. Collection assignIds = Transform.getIds(previewAssignList, PreviewAssign.class, "id");
  1744. List<UserPaper> userPaperList = userPaperService.listWithCourse(user.getId(), assignIds, recordId);
  1745. Collection paperIds = Transform.getIds(userPaperList, UserPaper.class, "id");
  1746. List<UserReport> userReportList = userReportService.listByPaper(paperIds);
  1747. tmpList.clear();
  1748. for(UserReport userReport:userReportList){
  1749. Date day = Tools.day(userReport.getCreateTime());
  1750. if (!tmpList.contains(day.getTime())){
  1751. tmpList.add(day.getTime());
  1752. UserCourseTimeDto dto = new UserCourseTimeDto();
  1753. dto.setType("preview");
  1754. dto.setDay(day);
  1755. dtos.add(dto);
  1756. }
  1757. }
  1758. return ResponseHelp.success(dtos);
  1759. }
  1760. @RequestMapping(value = "/export/question/collect", method = RequestMethod.POST)
  1761. @ApiOperation(value = "导出题目", notes = "导出题目", httpMethod = "POST")
  1762. public Response<Integer> exportQuestionCollect(@RequestBody @Validated UserExportDto dto) {
  1763. User user = (User) shiroHelp.getLoginUser();
  1764. UserExport entity = exportService.addQuestionCollect(user.getId(), JSONObject.parseObject(JSONObject.toJSONString(dto.getSetting())));
  1765. return ResponseHelp.success(entity.getId());
  1766. }
  1767. @RequestMapping(value = "/export/question/error", method = RequestMethod.POST)
  1768. @ApiOperation(value = "导出题目", notes = "导出题目", httpMethod = "POST")
  1769. public Response<Integer> exportQuestionError(@RequestBody @Validated UserExportDto dto) {
  1770. User user = (User) shiroHelp.getLoginUser();
  1771. UserExport entity = exportService.addQuestionError(user.getId(), JSONObject.parseObject(JSONObject.toJSONString(dto.getSetting())));
  1772. return ResponseHelp.success(entity.getId());
  1773. }
  1774. @RequestMapping(value = "/export/note/question", method = RequestMethod.POST)
  1775. @ApiOperation(value = "导出题目笔记", notes = "导出题目笔记", httpMethod = "POST")
  1776. public Response<Integer> exportNoteQuestion(@RequestBody @Validated UserExportDto dto) {
  1777. User user = (User) shiroHelp.getLoginUser();
  1778. UserExport entity = exportService.addQuestionNote(user.getId(), JSONObject.parseObject(JSONObject.toJSONString(dto.getSetting())));
  1779. return ResponseHelp.success(entity.getId());
  1780. }
  1781. @RequestMapping(value = "/export/note/course", method = RequestMethod.POST)
  1782. @ApiOperation(value = "导出课程笔记", notes = "导出课程笔记", httpMethod = "POST")
  1783. public Response<Integer> exportNoteCourse(@RequestBody @Validated UserExportDto dto) {
  1784. User user = (User) shiroHelp.getLoginUser();
  1785. UserExport entity = exportService.addCourseNote(user.getId(), JSONObject.parseObject(JSONObject.toJSONString(dto.getSetting())));
  1786. return ResponseHelp.success(entity.getId());
  1787. }
  1788. @RequestMapping(value = "/export/detail", method = RequestMethod.GET)
  1789. @ApiOperation(value = "导出详情", notes = "导出详情", httpMethod = "GET")
  1790. public Response<UserExport> exportDetail(int id) {
  1791. User user = (User) shiroHelp.getLoginUser();
  1792. UserExport entity = userExportService.get(id);
  1793. if (!user.getId().equals(entity.getUserId())){
  1794. throw new ParameterException("记录不存在");
  1795. }
  1796. return ResponseHelp.success(entity);
  1797. }
  1798. @RequestMapping(value = "/export/tips", method = RequestMethod.POST)
  1799. @ApiOperation(value = "关闭提示", notes = "关闭提示", httpMethod = "POST")
  1800. public Response<Boolean> exportTips() {
  1801. User user = (User) shiroHelp.getLoginUser();
  1802. User in = usersService.get(user.getId());
  1803. usersService.edit(User.builder()
  1804. .id(user.getId())
  1805. .exportTips(1)
  1806. .build());
  1807. return ResponseHelp.success(true);
  1808. }
  1809. @RequestMapping(value = "/textbook/tips", method = RequestMethod.POST)
  1810. @ApiOperation(value = "关闭提示", notes = "关闭提示", httpMethod = "POST")
  1811. public Response<Boolean> textbookTips() {
  1812. User user = (User) shiroHelp.getLoginUser();
  1813. User in = usersService.get(user.getId());
  1814. usersService.edit(User.builder()
  1815. .id(user.getId())
  1816. .textbookTips(1)
  1817. .build());
  1818. return ResponseHelp.success(true);
  1819. }
  1820. @RequestMapping(value = "/course/comment/tips", method = RequestMethod.POST)
  1821. @ApiOperation(value = "关闭评论提示提示", notes = "关闭评论提示提示", httpMethod = "POST")
  1822. public Response<Boolean> closeCommentTips(@RequestBody @Validated RecordCommentTipsDto dto) {
  1823. User user = (User) shiroHelp.getLoginUser();
  1824. UserOrderRecord record = userOrderRecordService.get(dto.getRecordId());
  1825. userOrderRecordService.edit(UserOrderRecord.builder()
  1826. .id(dto.getRecordId())
  1827. .commentTips(1)
  1828. .build());
  1829. return ResponseHelp.success(true);
  1830. }
  1831. @RequestMapping(value = "/search/history", method = RequestMethod.POST)
  1832. @ApiOperation(value = "添加搜索记录", notes = "添加搜索记录", httpMethod = "POST")
  1833. public Response<Boolean> addSearchHistory(@RequestBody @Validated SearchHistoryDto dto) {
  1834. User user = (User) shiroHelp.getLoginUser();
  1835. QuestionNo questionNo = questionNoService.get(dto.getQuestionNoId());
  1836. userSearchHistoryService.add(UserSearchHistory.builder()
  1837. .userId(user.getId())
  1838. .questionNoId(questionNo.getId())
  1839. .questionId(questionNo.getQuestionId())
  1840. .build());
  1841. return ResponseHelp.success(true);
  1842. }
  1843. @RequestMapping(value = "/search/history/clear", method = RequestMethod.POST)
  1844. @ApiOperation(value = "清除搜索记录", notes = "清除搜索记录", httpMethod = "POST")
  1845. public Response<Boolean> addSearchHistory(@RequestBody @Validated SearchHistoryClearDto dto) {
  1846. User user = (User) shiroHelp.getLoginUser();
  1847. Date end;
  1848. Date start;
  1849. try{
  1850. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  1851. start = sdf.parse(dto.getDate());
  1852. end = Tools.addDate(start, 1);
  1853. }catch (Exception e){
  1854. throw new ParameterException("日期格式错误");
  1855. }
  1856. userSearchHistoryService.clearDate(user.getId(), start, end);
  1857. return ResponseHelp.success(true);
  1858. }
  1859. @RequestMapping(value = "/search/history/list", method = RequestMethod.GET)
  1860. @ApiOperation(value = "搜索历史记录", httpMethod = "GET")
  1861. public Response<List<UserSearchHistoryDto>> listSearchHistory(
  1862. HttpSession session) {
  1863. User user = (User) shiroHelp.getLoginUser();
  1864. int week = 0;
  1865. Date now = Tools.today();
  1866. int day = Tools.getDayOfWeek(now);
  1867. Date start = Tools.addDate(now, -6);
  1868. Date end = Tools.addDate(start, 7);
  1869. List<UserSearchHistory> p = userSearchHistoryService.listByUser(user.getId(), start, end);
  1870. List<UserSearchHistoryDto> pr = Transform.convert(p, UserSearchHistoryDto.class);
  1871. Collection questionIds = Transform.getIds(p, UserSearchHistory.class, "questionId");
  1872. List<Question> questionList = questionService.select(questionIds);
  1873. Transform.combine(pr, questionList, UserSearchHistoryDto.class, "questionId", "question", Question.class, "id", QuestionExtendDto.class);
  1874. Collection questionNoIds = Transform.getIds(p, UserSearchHistory.class, "questionNoId");
  1875. List<QuestionNo> questionNoList = questionNoService.select(questionNoIds);
  1876. Transform.combine(pr, questionNoList, UserSearchHistoryDto.class, "questionNoId", "questionNo", QuestionNo.class, "id", QuestionNoExtendDto.class);
  1877. return ResponseHelp.success(pr);
  1878. }
  1879. }