MyController.java 115 KB

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