MyController.java 115 KB

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