MyController.java 106 KB

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