MyController.java 105 KB

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