Просмотр исходного кода

增加必刷题和非定向模拟真题卷

mingfu 2 недель назад
Родитель
Сommit
5f77b65ef8

+ 3 - 2
ie-admin/src/main/java/com/ruoyi/web/controller/front/FrontExamController.java

@@ -108,6 +108,7 @@ public class FrontExamController {
                                    @ApiParam("考卷类型PaperType") @RequestParam(required = false) PaperType paperType,
                                    @ApiParam("考卷类型关联ID") @RequestParam(required = false) Long relateId,
                                    @ApiParam("考卷类型关联ID") @RequestParam(required = false) Long subjectId,
+                                   @ApiParam("考卷题类别0普通2必刷") @RequestParam(required = false) Integer questionType,
                                    @RequestBody JSONObject body) {
         if(null != testType && testType > 0) {
             PaperDto paperDto = syTestMajorService.loadPaperByTestMajorTypeId(testType);
@@ -119,9 +120,9 @@ public class FrontExamController {
         if(null == subjectId && null == paperType) {
             subjectId = body.getLongValue("subjectId");
             paperType = PaperType.valueOf(body.getString("paperType"));
+            questionType = body.getInteger("questionType");
         }
-
-        return AjaxResult.success(examService.openExaminee(directed, paperType, relateId, subjectId));
+        return AjaxResult.success(examService.openExaminee(directed, paperType, relateId, subjectId, questionType));
     }
 
     @ApiOperation("04 开始考试")

+ 23 - 3
ie-admin/src/main/java/com/ruoyi/web/controller/front/FrontPaperController.java

@@ -4,14 +4,18 @@ import com.ruoyi.common.core.content.VistorContextHolder;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.AjaxResult2;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.utils.NumberUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.dz.domain.DzControl;
 import com.ruoyi.dz.domain.DzSubject;
 import com.ruoyi.dz.service.IDzControlService;
 import com.ruoyi.dz.service.IDzSubjectService;
 import com.ruoyi.enums.PaperType;
+import com.ruoyi.learn.domain.LearnPaper;
 import com.ruoyi.learn.domain.LearnStudent;
 import com.ruoyi.learn.domain.LearnTest;
+import com.ruoyi.learn.service.ILearnPaperService;
 import com.ruoyi.learn.service.ILearnStudentService;
 import com.ruoyi.learn.service.ILearnTestService;
 import com.ruoyi.web.service.LearnTeacherService;
@@ -21,6 +25,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.apache.commons.compress.utils.Lists;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -38,15 +43,17 @@ public class FrontPaperController {
     private final IDzControlService dzControlService;
     private final IDzSubjectService dzSubjectService;
     private final PaperService paperService;
+    private final ILearnPaperService learnPaperService;
     private final ILearnTestService testService;
     private final ILearnStudentService learnStudentService;
     private final LearnTeacherService learnTeacherService;
     private final StudentService studentService;
 
-    public FrontPaperController(IDzControlService dzControlService, IDzSubjectService dzSubjectService, PaperService paperService, ILearnTestService testService, ILearnStudentService learnStudentService, LearnTeacherService learnTeacherService, StudentService studentService) {
+    public FrontPaperController(IDzControlService dzControlService, IDzSubjectService dzSubjectService, PaperService paperService, ILearnPaperService learnPaperService, ILearnTestService testService, ILearnStudentService learnStudentService, LearnTeacherService learnTeacherService, StudentService studentService) {
         this.dzControlService = dzControlService;
         this.dzSubjectService = dzSubjectService;
         this.paperService = paperService;
+        this.learnPaperService = learnPaperService;
         this.testService = testService;
         this.learnStudentService = learnStudentService;
         this.learnTeacherService = learnTeacherService;
@@ -64,8 +71,9 @@ public class FrontPaperController {
 
     @ApiOperation("02 考试科目")
     @GetMapping(value = "subject")
-    public AjaxResult2<List<DzSubject>> getSubject(@ApiParam("定向") @RequestParam(defaultValue = "false") boolean directed) {
-        return AjaxResult2.success(studentService.getSubjectList(directed));
+    public AjaxResult2<List<DzSubject>> getSubject(@ApiParam("定向") @RequestParam(defaultValue = "false") boolean directed,
+                                                   @ApiParam("类型") @RequestParam(required = false) Integer subjectId) {
+        return AjaxResult2.success(studentService.getSubjectList(directed, subjectId));
     }
 
     @ApiOperation("03 知识点树")
@@ -122,4 +130,16 @@ public class FrontPaperController {
     public AjaxResult loadPaper(@ApiParam("考卷类型PaperType") PaperType type, @ApiParam("考卷标识") Long id) {
         return AjaxResult.success(paperService.loadPaper(id));
     }
+
+    @ApiOperation("05 取模拟卷列表")
+    @GetMapping("/list")
+    public List<LearnPaper> list(LearnPaper learnPaper) {
+        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
+        learnPaper.setPaperType(PaperType.Simulated.name());
+        String subjectKey = NumberUtils.isPositive(learnPaper.getSubjectId()) ? String.valueOf(sysUser.getSelectSubject()) : "0";
+        learnPaper.setLocations(sysUser.getLocation());
+        learnPaper.setDirectKey(sysUser.getExamType().name() + "_" + subjectKey);
+        List<LearnPaper> list = learnPaperService.selectLearnPaperList(learnPaper);
+        return list;
+    }
 }

+ 38 - 19
ie-admin/src/main/java/com/ruoyi/web/service/ExamService.java

@@ -81,7 +81,7 @@ public class ExamService {
      * @return
      */
     @Transactional(rollbackFor = Exception.class)
-    public AnswerSheet openExaminee(boolean directed, PaperType paperType, Long relatedId, Long subjectId) {
+    public AnswerSheet openExaminee(boolean directed, PaperType paperType, Long relatedId, Long subjectId, Integer questionType) {
         SysUser user = SecurityUtils.getLoginUser().getUser();
         if(paperTypeSet.contains(paperType)) {
             if(UserTypeEnum.isCard(user.getUserType()) && !UserRegStatus.Student.equals(user.getRegStatus())) {
@@ -92,19 +92,22 @@ public class ExamService {
             if(UserTypeEnum.isCard(user.getUserType()) && !UserRegStatus.Student.equals(user.getRegStatus())) {
                 throw new RuntimeException("VIP功能不可用");
             }
-            return openExamineeForPractice(relatedId, SecurityUtils.getUserId(), directed);
+            return openExamineeForPractice(relatedId, SecurityUtils.getUserId(), directed, questionType);
         } else if(PaperType.Course.equals(paperType)) {
             if(UserTypeEnum.isCard(user.getUserType()) && !UserRegStatus.Student.equals(user.getRegStatus())) {
                 throw new RuntimeException("VIP功能不可用");
             }
             return openExamineeForCourse(relatedId, SecurityUtils.getUserId(), directed);
         } else if(PaperType.Simulated.equals(paperType)) {
-            SysUser exist = sysUserService.selectUserById(SecurityUtils.getUserId());
-            LearnStudent ls = learnStudentMapper.selectLearnStudentByStudentId(exist.getUserId());
-            if(null == ls) {
-                throw new RuntimeException("请先定设置定向学习" + exist.getUserId());
+            if(null == relatedId) { // 直接打开Paper的模拟卷
+                SysUser exist = sysUserService.selectUserById(SecurityUtils.getUserId());
+                LearnStudent ls = learnStudentMapper.selectLearnStudentByStudentId(exist.getUserId());
+                if(null == ls) {
+                    throw new RuntimeException("请先定设置专业学习" + exist.getUserId());
+                }
+                return openExaminee(ls, subjectId, exist);
             }
-            return openExaminee(ls, subjectId, exist);
+            return openExamineeByPaper(relatedId);
         } else if(PaperType.Test.equals(paperType)) {
             SysUser exist = sysUserService.selectUserById(SecurityUtils.getUserId());
             LearnTestStudent ts = learnTestStudentMapper.selectLearnTestStudentById(relatedId);
@@ -442,9 +445,6 @@ public class ExamService {
             existPaperIdSet.add(e.getPaperId());
         }
         LearnPaper paper = getBestPaper(sysUser.getExamType(), plan, subjectId, existPaperIdSet); // getAvailPaper(sysUser.getExamType(), ls, subjectId, existPaperIdSet)
-        examinee.setPaperId(paper.getId());
-        examinee.setState(ExamineeStatus.Sign.getVal());
-        examinee.setDuration(0L);
 
         JSONObject evalCountObj = JSONObject.parseObject(sysUser.getEvalCounts());
         Integer evalCount = evalCountObj.getInteger(subjectId.toString());
@@ -458,13 +458,32 @@ public class ExamService {
         sysUserService.updateUserProfile(upUser);
 
         examinee.setPaperInfo(buildPaperInfo(ls, plan));
-        examineeMapper.insertLearnExaminee(examinee);
-        AnswerSheet answerSheet = buildAnswerSheet(paper, examinee);
-
+        AnswerSheet answerSheet = openExamineeByPaper(examinee, paper);
         answerSheet.setCollegeId(ls.getUniversityId());
         answerSheet.setCollegeName(plan.getUniversityName());
         answerSheet.setMajorId(ls.getMajorPlanId());
         answerSheet.setMajorName(plan.getMajorName());
+        return answerSheet;
+    }
+    private AnswerSheet openExamineeByPaper(Long paperId) {
+        LearnExaminee examinee = new LearnExaminee();
+        examinee.setStudentId(SecurityUtils.getLoginUser().getUser().getUserId());
+        examinee.setPaperType(PaperType.Simulated.getVal());
+        examinee.setPaperKey("P" + "_" + paperId);
+        examinee.setState(ExamineeStatus.Sign.getVal());
+        List<LearnExaminee> examineeList = examineeMapper.selectLearnExamineeList(examinee);
+        LearnPaper learnPaper = paperMapper.selectLearnPaperById(paperId);
+        if(CollectionUtils.isNotEmpty(examineeList)) {
+            return buildAnswerSheet(learnPaper, examineeList.get(0));
+        }
+        return openExamineeByPaper(examinee, learnPaper);
+    }
+    private AnswerSheet openExamineeByPaper(LearnExaminee examinee, LearnPaper paper) {
+        examinee.setPaperId(paper.getId());
+        examinee.setState(ExamineeStatus.Sign.getVal());
+        examinee.setDuration(0L);
+        examineeMapper.insertLearnExaminee(examinee);
+        AnswerSheet answerSheet = buildAnswerSheet(paper, examinee);
         answerSheet.setSubjectId(paper.getSubjectId());
         answerSheet.setSubjectName(dzSubjectService.selectDzSubjectBySubjectId(paper.getSubjectId()).getSubjectName());
         return answerSheet;
@@ -486,10 +505,10 @@ public class ExamService {
             throw new RuntimeException("无效同步知识点");
         }
         return openExaminee(PaperType.Course, knowledgeId, Stream.of(kc.getKnowledges().split(",")).map(Long::parseLong).collect(Collectors.toList()), studentId, false,
-                0L, kc.getName(), null, null, "") ;
+                0L, kc.getName(), null, null, "", 0) ;
     }
 
-    private AnswerSheet openExamineeForPractice(Long knowledgeId, Long studentId, Boolean directed) {
+    private AnswerSheet openExamineeForPractice(Long knowledgeId, Long studentId, Boolean directed, Integer questionType) {
         String directKey;
         AMarjorPlan plan = null;
         LearnStudent ls = null;
@@ -504,7 +523,7 @@ public class ExamService {
         }
         LearnKnowledgeTree knowledgeTree = knowledgeTreeMapper.selectLearnKnowledgeTreeById(knowledgeId);
         return openExaminee(PaperType.Practice, knowledgeId, Lists.newArrayList(knowledgeId), studentId, directed,
-                knowledgeTree.getSubjectId(), knowledgeTree.getName(), ls, plan, directKey) ;
+                knowledgeTree.getSubjectId(), knowledgeTree.getName(), ls, plan, directKey, questionType) ;
     }
 
     /**
@@ -512,13 +531,13 @@ public class ExamService {
      * @return
      */
     private AnswerSheet openExaminee(PaperType paperType, Long knowledgeId, List<Long> useKnowledgeIds, Long studentId, Boolean directed,
-                                     Long subjectId, String knowledName, LearnStudent ls, AMarjorPlan plan, String directKey) {
+                                     Long subjectId, String knowledName, LearnStudent ls, AMarjorPlan plan, String directKey, Integer questionType) {
         LearnPaper paper = new LearnPaper();
         paper.setPaperType(paperType.name());
         paper.setRelateId(knowledgeId);
         paper.setYear(Calendar.getInstance().get(Calendar.YEAR));
         paper.setStatus(PaperStatus.TmpValid.getVal());
-        paper.setDirectKey(studentId + "_" + directKey);
+        paper.setDirectKey(studentId + "_" + directKey + "_" + (null == questionType ? "0" : questionType));
         List<LearnPaper> paperList = paperMapper.selectLearnPaperList(paper);
         if (CollectionUtils.isNotEmpty(paperList)) { // 有未做完的
             LearnPaper existPaper = paperList.get(0);
@@ -545,7 +564,7 @@ public class ExamService {
             up.setStatus(PaperStatus.Valid.getVal());
             paperMapper.updateLearnPaper(up);
         }
-        List<LearnPaperQuestion> pqList = paperService.getQuestionsByRandom(studentId,  15, useKnowledgeIds, Arrays.stream(QuestionType.values()).map(QuestionType::getTitle).collect(Collectors.toList()));
+        List<LearnPaperQuestion> pqList = paperService.getQuestionsByRandom(studentId,  15, useKnowledgeIds, Arrays.stream(QuestionType.values()).map(QuestionType::getTitle).collect(Collectors.toList()), 0);
         if(CollectionUtils.isEmpty(pqList)) {
             throw new RuntimeException("本知识点题已做完");
         }

+ 7 - 5
ie-admin/src/main/java/com/ruoyi/web/service/PaperService.java

@@ -548,7 +548,7 @@ public class PaperService {
             newKnownList.addAll(tailKnownList);
             ktd.setKnowledges(newKnownList);
             String isSubType = null == ktd.getSubType() ? "0" : ktd.getSubType().toString();
-            Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, isSubType, ktd.getTypes().get(0).getCount(), ktd.getTypes().stream().map(t -> t.getType().getTitle()).collect(Collectors.toList()), newKnownList, paperDef.getFillExclude());
+            Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, isSubType, ktd.getTypes().get(0).getCount(), ktd.getTypes().stream().map(t -> t.getType().getTitle()).collect(Collectors.toList()), newKnownList, paperDef.getFillExclude(), 0);
             assignTypeFirst(paperDef.getFillExclude(), ktd, knowTypeAssignMap);
             pqList.addAll(getQuestions2(studentId, ktd.getCount(), pqList.size(), newKnownList, isSubType, ktd.getTypes(), knowTypeAssignMap, existQuestionSet));
         }
@@ -556,14 +556,15 @@ public class PaperService {
         return pqList;
     }
 
-    public List<LearnPaperQuestion> getQuestionsByRandom(Long studentId, Integer total, Collection<Long> knowledgeIds, List<String> types) {
-        Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, "2", null, types, knowledgeIds, true);
+    public List<LearnPaperQuestion> getQuestionsByRandom(Long studentId, Integer total, Collection<Long> knowledgeIds, List<String> types, Integer questionType) {
+        Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, "2", null, types, knowledgeIds, true, 0);
         List<KnowTypeAssign> knowTypeAssignList = Lists.newArrayList(knowTypeAssignMap.values());
         List<LearnPaperQuestion> pqList = Lists.newArrayList();
         Set<String> existQuestionSet = Sets.newHashSet();
         Random random = ThreadLocalRandom.current();
         Map<String, List<LearnQuestions>> typeQuestionMap = Maps.newHashMap();
         LearnQuestions qCond = new LearnQuestions();
+        qCond.setTypeId(questionType);
         do {
             if(knowTypeAssignList.isEmpty()) {
                 break;
@@ -1036,7 +1037,7 @@ public class PaperService {
      * @return
      */
     private Map<String, KnowTypeAssign> buildKnowTypeAssignMap(Long studentId, TestPaperVO.PaperDef paperDef) {
-        return buildKnowTypeAssignMap(studentId, "0", null, paperDef.getTypes().stream().map(TestPaperVO.TypeDef::getType).collect(Collectors.toList()), paperDef.getKnowIds(), paperDef.getFillExclude());
+        return buildKnowTypeAssignMap(studentId, "0", null, paperDef.getTypes().stream().map(TestPaperVO.TypeDef::getType).collect(Collectors.toList()), paperDef.getKnowIds(), paperDef.getFillExclude(), 0);
     }
 
     /**
@@ -1047,9 +1048,10 @@ public class PaperService {
      * @param fillExclude
      * @return
      */
-    private Map<String, KnowTypeAssign> buildKnowTypeAssignMap(Long studentId, String isSubType, Integer subCnt, List<String> types, Collection<Long> knownIds, Boolean fillExclude) {
+    private Map<String, KnowTypeAssign> buildKnowTypeAssignMap(Long studentId, String isSubType, Integer subCnt, List<String> types, Collection<Long> knownIds, Boolean fillExclude, Integer questionType) {
         Map<String, KnowTypeAssign> knowTypeAssignMap = Maps.newHashMap();
         Map cond = Maps.newHashMap();
+        cond.put("typeId", questionType);
         cond.put("studentId", studentId);
         cond.put("knowIds", knownIds);
         cond.put("types", types);

+ 17 - 7
ie-admin/src/main/java/com/ruoyi/web/service/StudentService.java

@@ -3,9 +3,11 @@ package com.ruoyi.web.service;
 import cn.hutool.core.lang.Dict;
 import com.alibaba.fastjson2.JSONObject;
 import com.alibaba.fastjson2.util.DateUtils;
+import com.google.common.collect.Sets;
 import com.ruoyi.common.annotation.Excel;
 import com.ruoyi.common.core.domain.AjaxResult2;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.enums.SubjectType;
 import com.ruoyi.common.utils.CommonUtils;
 import com.ruoyi.common.utils.NumberUtils;
 import com.ruoyi.common.utils.SecurityUtils;
@@ -50,19 +52,27 @@ public class StudentService {
         this.learnAnswerMapper = learnAnswerMapper;
     }
 
-    public List<DzSubject> getSubjectList(boolean directed) {
+    public List<DzSubject> getSubjectList(boolean directed, Integer subjectId) {
         SysUser sysUser = SecurityUtils.getLoginUser().getUser();
         DzSubject sCond = new DzSubject();
         sCond.setLocations(sysUser.getLocation());
         sCond.setExamTypes(sysUser.getExamType().name());
         List<DzSubject> list = dzSubjectService.selectDzSubjectList(sCond);
-        if (!directed) {
-            return list;
-        }
-        LearnStudent learnStudent = learnStudentService.selectLearnStudentByStudentId(SecurityUtils.getUserId());
         Set<Long> subjectIdSet;
-        if (null == learnStudent || CollectionUtils.isEmpty((subjectIdSet = learnTeacherService.getSubjectIdSet(new Long[]{learnStudent.getMajorPlanId()})))) {
-            return list;
+        if (!directed) {
+            if(null == subjectId || null == (subjectId = SecurityUtils.getLoginUser().getUser().getSelectSubject())) {
+                return list;
+            }
+            if(subjectId > 0) {
+                subjectIdSet = Sets.newHashSet(subjectId.longValue());
+            } else {
+                subjectIdSet = Sets.newHashSet(1L, 2L, 3L);
+            }
+        } else {
+            LearnStudent learnStudent = learnStudentService.selectLearnStudentByStudentId(SecurityUtils.getUserId());
+            if (null == learnStudent || CollectionUtils.isEmpty((subjectIdSet = learnTeacherService.getSubjectIdSet(new Long[]{learnStudent.getMajorPlanId()})))) {
+                return list;
+            }
         }
         return list.stream().filter(t -> subjectIdSet.contains(t.getSubjectId())).collect(Collectors.toList());
     }

+ 2 - 0
ie-system/src/main/resources/mapper/learn/LearnQuestionsMapper.xml

@@ -329,6 +329,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="knowIds != null"> and kq.`knowledge_id` in <foreach item="id" collection="knowIds" open="(" separator="," close=")">#{id}</foreach></if>
             <if test="types != null"> and q.`qtpye` in <foreach item="id" collection="types" open="(" separator="," close=")">#{id}</foreach></if>
             <if test="studentId != null"> AND a.`student_id` IS NULL</if>
+            <if test="typeId != null"> AND kq.`type` = #{typeId}</if>
         </where>
         GROUP BY kq.knowledge_id, q.`qtpye`
     </select>
@@ -345,6 +346,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isSubType != null  and isSubType == 2"> and (kq.sub = 0 or q.knowId = q.id <if test="subCnt != null"> and kq.sub = #{subCnt}</if>)</if>
             <if test="isSubType != null  and isSubType == 0"> and (kq.sub = 0)</if>
             <if test="qtpye != null  and qtpye != ''"> and qtpye = #{qtpye}</if>
+            <if test="typeId != null"> and kq.type = #{typeId}</if>
             <if test="id != null ">  AND a.`student_id` IS NULL</if>
             <if test="knowledgeId != null "> and kq.knowledge_id  = #{knowledgeId}</if>
         </where>