MyController.java 112 KB

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