123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- package com.qxgmat.controller.api;
- import com.alibaba.fastjson.JSONObject;
- import com.github.pagehelper.Page;
- import com.nuliji.tools.*;
- import com.qxgmat.data.constants.enums.logic.ExerciseLogic;
- import com.qxgmat.data.constants.enums.module.PaperModule;
- import com.qxgmat.data.constants.enums.module.PayModule;
- import com.qxgmat.data.dao.entity.*;
- import com.qxgmat.data.relation.entity.UserExercisePaperRelation;
- import com.qxgmat.data.relation.entity.UserHomeworkPreviewRelation;
- import com.qxgmat.dto.extend.UserExercisePaperExtendDto;
- import com.qxgmat.dto.extend.UserHomeworkPreviewExtendDto;
- import com.qxgmat.dto.request.*;
- import com.qxgmat.dto.response.*;
- import com.qxgmat.help.ShiroHelp;
- import com.qxgmat.service.ExercisePaperService;
- import com.qxgmat.service.HomeworkPreviewService;
- import com.qxgmat.service.UserQuestionService;
- import com.qxgmat.service.extend.QuestionFlowService;
- import com.qxgmat.service.inline.*;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpSession;
- import java.util.Collection;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- @RestController
- @RequestMapping("/api/question")
- @Api(tags = "题目", description = "题目接口")
- public class QuestionController {
- @Autowired
- private ShiroHelp shiroHelp;
- @Autowired
- private HomeworkPreviewService homeworkPreviewService;
- @Autowired
- private ExercisePaperService exercisePaperService;
- @Autowired
- private QuestionNoService questionNoService;
- @Autowired
- private UserQuestionService userQuestionService;
- @Autowired
- private UserClassService userClassService;
- @Autowired
- private UserPayService userPayService;
- @Autowired
- private QuestionFlowService questionFlowService;
- @RequestMapping(value = "/class/process", method = RequestMethod.GET)
- @ApiOperation(value = "获取课程进度", notes = "获取所有课程及状态进度", httpMethod = "GET")
- public Response<List<UserClassDetailDto>> classProcess() {
- User user = (User) shiroHelp.getLoginUser();
- List<UserClass> userClassList = userClassService.getByUser(user.getId());
- List<UserClassDetailDto> dtos = Transform.convert(userClassList, UserClassDetailDto.class);
-
- Map<Object, Collection<UserHomeworkPreviewRelation>> previewMap = homeworkPreviewService.groupByCategory(user.getId(), 3);
- Transform.combine(dtos, previewMap, UserClassDetailDto.class, "category", "previews", UserHomeworkPreviewExtendDto.class);
-
- List<UserPay> pays = userPayService.listUnUse(user.getId(), PayModule.CLASS);
- Collection ids = Transform.getIds(userClassList, UserClass.class, "category");
- for(UserPay pay : pays){
- Integer category = Integer.valueOf(pay.getModuleExtend());
- if (!ids.contains(category)){
- UserClassDetailDto dto = new UserClassDetailDto();
- dto.setCategory(category);
- dto.setPayed(true);
- dtos.add(dto);
- }
- }
- return ResponseHelp.success(dtos);
- }
- @RequestMapping(value = "/preview/list", method = RequestMethod.GET)
- @ApiOperation(value = "获取预习作业列表", notes = "获取预习作业列表", httpMethod = "GET")
- public Response<PageMessage<UserHomeworkPreviewExtendDto>> listPreview(
- @RequestParam(required = false, defaultValue = "1") int page,
- @RequestParam(required = false, defaultValue = "100") int size,
- @RequestParam(required = false) Number category,
- @RequestParam(required = false) String endTime,
- @RequestParam(required = false) Boolean finish
- ) {
- User user = (User) shiroHelp.getLoginUser();
- PageResult<UserHomeworkPreviewRelation> p = homeworkPreviewService.list(page, size, category, user.getId(), endTime, finish);
- List<UserHomeworkPreviewExtendDto> pr = Transform.convert(p, UserHomeworkPreviewExtendDto.class);
-
- Map map = Transform.getMap(p, UserHomeworkPreviewRelation.class, "id", "preview");
- Map<Integer, Integer[]> questionNoIdsMap = new HashMap<>();
- for(Object value : map.keySet()){
- Integer key = (Integer) value;
- HomeworkPreview preview = (HomeworkPreview) map.get(key);
- questionNoIdsMap.put(key, preview.getQuestionNoIds());
- }
- Map statMap = questionNoService.statPaperMap(questionNoIdsMap);
- Transform.combine(pr, statMap, UserHomeworkPreviewExtendDto.class, "id", "stat");
- return ResponseHelp.success(pr, page, size, p.getTotal());
- }
- @RequestMapping(value = "/exercise/process", method = RequestMethod.GET)
- @ApiOperation(value = "练习进度", httpMethod = "GET")
- public Response<List<UserExerciseGroupDto>> exerciseProcess(
- @RequestParam(required = true) Integer structId,
- HttpSession session) {
- Page<UserExerciseGroupDto> p=null;
-
- return ResponseHelp.success(p);
- }
- @RequestMapping(value = "/exercise/place", method = RequestMethod.GET)
- @ApiOperation(value = "练习组卷考点分组条件", httpMethod = "GET")
- public Response<List<String>> exercisePlace(HttpSession session) {
- return ResponseHelp.success(exercisePaperService.groupPlace());
- }
- @RequestMapping(value = "/exercise/paper", method = RequestMethod.GET)
- @ApiOperation(value = "练习组卷列表", httpMethod = "GET")
- public Response<PageMessage<UserExercisePaperExtendDto>> listExercisePaper(
- @RequestParam(required = false, defaultValue = "1") int page,
- @RequestParam(required = false, defaultValue = "100") int size,
- @RequestParam(required = true) Integer structId,
- @RequestParam(required = true) String logic,
- @RequestParam(required = false, name = "logic_extend") String logicExtend,
- @RequestParam(required = false) Integer times,
- HttpSession session) {
- User user = (User) shiroHelp.getLoginUser();
- PageResult<UserExercisePaperRelation> p = exercisePaperService.list(page, size, structId, user.getId(), ExerciseLogic.ValueOf(logic), logicExtend, times);
- List<UserExercisePaperExtendDto> pr = Transform.convert(p, UserExercisePaperExtendDto.class);
-
- Map map = Transform.getMap(p, UserExercisePaperRelation.class, "id", "paper");
- Map<Integer, Integer[]> questionNoIdsMap = new HashMap<>();
- for(Object value : map.keySet()){
- Integer key = (Integer) value;
- ExercisePaper paper = (ExercisePaper) map.get(key);
- questionNoIdsMap.put(key, paper.getQuestionNoIds());
- }
- Map statMap = questionNoService.statPaperMap(questionNoIdsMap);
- Transform.combine(pr, statMap, UserHomeworkPreviewExtendDto.class, "id", "stat");
- return ResponseHelp.success(pr, page, size, p.getTotal());
- }
- @RequestMapping(value = "/examination/process", method = RequestMethod.GET)
- @ApiOperation(value = "模考进度", httpMethod = "GET")
- public Response<PageMessage<ExercisePaper>> examinationProcess(
- @RequestParam(required = false, defaultValue = "1") int page,
- @RequestParam(required = false, defaultValue = "100") int size,
- HttpSession session) {
- Page<ExercisePaper> p = null;
- return ResponseHelp.success(p, page, size, p.getTotal());
- }
- @RequestMapping(value = "/examination/paper", method = RequestMethod.GET)
- @ApiOperation(value = "模考组卷列表", httpMethod = "GET")
- public Response<PageMessage<ExercisePaper>> examinationPaperList(
- @RequestParam(required = false, defaultValue = "1") int page,
- @RequestParam(required = false, defaultValue = "100") int size,
- HttpSession session) {
- Page<ExercisePaper> p = null;
- return ResponseHelp.success(p, page, size, p.getTotal());
- }
- @RequestMapping(value = "/detail", method = RequestMethod.GET)
- @ApiOperation(value = "获取题目详情", notes = "获取题目详情", httpMethod = "GET")
- public Response<UserQuestionDetailDto> detail(
- @RequestParam(required = false) String userQuestionId
- ) {
- User user = (User) shiroHelp.getLoginUser();
- return ResponseHelp.success(null);
- }
- @RequestMapping(value = "/exercise/start", method = RequestMethod.POST)
- @ApiOperation(value = "开始: 练习", notes = "提交考试设置", httpMethod = "POST")
- public Response<UserReportDto> startExercise(@RequestBody @Validated ExerciseStartDto dto) {
- User user = (User) shiroHelp.getLoginUser();
- JSONObject setting = new JSONObject();
- setting.put("disorder", dto.getDisorder());
- UserReport report = questionFlowService.start(user.getId(), PaperModule.HOMEWORK_PREVIEW, dto.getPaperId(), setting);
- return ResponseHelp.success(Transform.convert(report, UserReportDto.class));
- }
- @RequestMapping(value = "/preview/start", method = RequestMethod.POST)
- @ApiOperation(value = "开始: 预习作业", notes = "提交考试设置", httpMethod = "POST")
- public Response<UserReportDto> startPreview(@RequestBody @Validated PreviewStartDto dto) {
- User user = (User) shiroHelp.getLoginUser();
- JSONObject setting = new JSONObject();
- setting.put("disorder", dto.getDisorder());
- UserReport report = questionFlowService.start(user.getId(), PaperModule.HOMEWORK_PREVIEW, dto.getPaperId(), setting);
- return ResponseHelp.success(Transform.convert(report, UserReportDto.class));
- }
- @RequestMapping(value = "/continue", method = RequestMethod.POST)
- @ApiOperation(value = "继续做题", notes = "获取报告信息", httpMethod = "POST")
- public Response<UserReportDto> continueReport(@RequestBody @Validated ReportContinueDto dto) {
- User user = (User) shiroHelp.getLoginUser();
- UserReport report = questionFlowService.continueReport(user.getId(), dto.getUserReportId());
- return ResponseHelp.success(Transform.convert(report, UserReportDto.class));
- }
- @RequestMapping(value = "/next", method = RequestMethod.POST)
- @ApiOperation(value = "获取下一题", notes = "获取下一题", httpMethod = "POST")
- public Response<UserQuestionBaseDto> next(@RequestBody @Validated ReportNextDto dto) {
- User user = (User) shiroHelp.getLoginUser();
-
- UserQuestion userQuestion = questionFlowService.next(user.getId(), dto.getUserReportId());
-
-
-
- return ResponseHelp.success(null);
- }
- @RequestMapping(value = "/submit", method = RequestMethod.POST)
- @ApiOperation(value = "提交题目答案", notes = "提交题目", httpMethod = "POST")
- public Response<Boolean> submit(@RequestBody @Validated QuestionSubmitDto dto) {
- User user = (User) shiroHelp.getLoginUser();
- Boolean result = questionFlowService.submit(user.getId(), dto.getUserQuestionId(), dto.getTime(), dto.getAnswer());
- return ResponseHelp.success(result);
- }
- @RequestMapping(value = "/finish", method = RequestMethod.POST)
- @ApiOperation(value = "完成考试", notes = "完成考试", httpMethod = "POST")
- public Response<Boolean> finish(@RequestBody @Validated ReportFinishDto dto) {
- User user = (User) shiroHelp.getLoginUser();
- Boolean result = questionFlowService.finish(user.getId(), dto.getUserReportId());
- return ResponseHelp.success(result);
- }
- @RequestMapping(value = "/restart", method = RequestMethod.POST)
- @ApiOperation(value = "重置考试", notes = "重置考试", httpMethod = "POST")
- public Response<User> restart(@RequestBody @Validated PaperRestartDto dto) {
- User user = (User) shiroHelp.getLoginUser();
- questionFlowService.restart(dto.getUserPaperId(), user.getId());
- return ResponseHelp.success(null);
- }
- }
|