Browse Source

增加接口定向参数

mingfu 1 month ago
parent
commit
f59d98a4bb

+ 13 - 5
ie-admin/src/main/java/com/ruoyi/web/controller/front/FrontExamController.java

@@ -51,16 +51,24 @@ public class FrontExamController {
     // 组卷: 知识点 错题 必刷题 实时组卷后才生成记录
     @ApiOperation("01 开卷")
     @PostMapping(value = "openExaminee")
-    public AjaxResult openExamineePaper(@ApiParam("考卷类型PaperType") @RequestParam PaperType paperType,
-                                        @ApiParam("考卷类型关联ID") @RequestParam Long relateId) {
-        return AjaxResult.success(examService.openExaminee(paperType, relateId));
+    public AjaxResult openExaminee(@ApiParam("定向") @RequestParam(defaultValue = "false") boolean directed,
+                                   @ApiParam("考卷类型PaperType") @RequestParam PaperType paperType,
+                                   @ApiParam("考卷类型关联ID") @RequestParam Long relateId) {
+        return AjaxResult.success(examService.openExaminee(directed, paperType, relateId));
+    }
+
+    @ApiOperation("04 开始考试")
+    @GetMapping(value = "beginExaminee")
+    public AjaxResult beginExaminee(@ApiParam("答卷ID") Long examineeId) {
+        // 检查状态,以决定是否返回答案
+        return AjaxResult.success(examService.loadExaminee(examineeId, true));
     }
 
     @ApiOperation("04 取答卷")
     @GetMapping(value = "loadExaminee")
-    public AjaxResult loadAnswers(@ApiParam("答卷ID") Long examineeId) {
+    public AjaxResult loadExaminee(@ApiParam("答卷ID") Long examineeId) {
         // 检查状态,以决定是否返回答案
-        return AjaxResult.success(examService.loadExaminee(examineeId));
+        return AjaxResult.success(examService.loadExaminee(examineeId, false));
     }
 
     @ApiOperation("02 交卷")

+ 8 - 2
ie-admin/src/main/java/com/ruoyi/web/controller/front/FrontPaperController.java

@@ -5,6 +5,8 @@ import com.google.common.collect.Maps;
 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.utils.SecurityUtils;
 import com.ruoyi.dz.domain.DzControl;
 import com.ruoyi.dz.domain.DzSubject;
 import com.ruoyi.dz.service.IDzControlService;
@@ -23,6 +25,7 @@ import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.List;
@@ -57,15 +60,18 @@ public class FrontPaperController {
 
     @ApiOperation("02 考试科目")
     @GetMapping(value = "subject")
-    public AjaxResult2<List<DzSubject>> getSubject() {
+    public AjaxResult2<List<DzSubject>> getSubject(@ApiParam("定向") @RequestParam(defaultValue = "false") boolean directed) {
+        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
         DzSubject sCond = new DzSubject();
+        sCond.setLocations(sysUser.getLocation());
+        sCond.setExamTypes(sysUser.getExamType().name());
         List<DzSubject> list = dzSubjectService.selectDzSubjectList(sCond);
         return AjaxResult2.success(list);
     }
 
     @ApiOperation("03 知识点树")
     @GetMapping(value = "knowledge")
-    public AjaxResult getKnowledge(@ApiParam("科目ID") Long subjectId) {
+    public AjaxResult getKnowledge(@ApiParam("定向") @RequestParam(defaultValue = "false") boolean directed, @ApiParam("科目ID") Long subjectId) {
         return AjaxResult.success(learnTeacherService.getKnowledgeTree(subjectId, null, true));
     }
 

+ 1 - 1
ie-admin/src/main/java/com/ruoyi/web/controller/front/FrontStudentController.java

@@ -73,7 +73,7 @@ public class FrontStudentController extends BaseController {
 
     @ApiOperation("02 考试科目")
     @GetMapping(value = "subject")
-    public AjaxResult2<List<DzSubject>> getSubject() {
+    public AjaxResult2<List<DzSubject>> getSubject(@ApiParam("定向") @RequestParam(defaultValue = "false") boolean directed) {
         SysUser sysUser = SecurityUtils.getLoginUser().getUser();
         DzSubject sCond = new DzSubject();
         sCond.setLocations(sysUser.getLocation());

+ 52 - 23
ie-admin/src/main/java/com/ruoyi/web/service/ExamService.java

@@ -1,8 +1,10 @@
 package com.ruoyi.web.service;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.alibaba.fastjson2.util.DateUtils;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
+import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.enums.ExamineeStatus;
 import com.ruoyi.enums.PaperStatus;
@@ -10,11 +12,9 @@ import com.ruoyi.enums.PaperType;
 import com.ruoyi.ie.domain.AMarjorPlan;
 import com.ruoyi.ie.service.IAMarjorPlanService;
 import com.ruoyi.learn.domain.*;
-import com.ruoyi.learn.mapper.LearnAnswerMapper;
-import com.ruoyi.learn.mapper.LearnExamineeMapper;
-import com.ruoyi.learn.mapper.LearnKnowledgeTreeMapper;
-import com.ruoyi.learn.mapper.LearnPaperMapper;
+import com.ruoyi.learn.mapper.*;
 import com.ruoyi.learn.service.ILearnPaperService;
+import com.ruoyi.system.service.ISysUserService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
@@ -31,6 +31,7 @@ import java.util.stream.Collectors;
 public class ExamService {
     private final LearnAnswerMapper learnAnswerMapper;
     private final LearnExamineeMapper learnExamineeMapper;
+    private final LearnStudentMapper learnStudentMapper;
     private Set<PaperType> paperTypeSet = Sets.newHashSet(PaperType.Real, PaperType.Custom, PaperType.Test);
     private final LearnPaperMapper paperMapper;
     private final LearnKnowledgeTreeMapper knowledgeTreeMapper;
@@ -38,8 +39,9 @@ public class ExamService {
     private final ILearnPaperService learnPaperService;
     private final PaperService paperService;
     private final IAMarjorPlanService marjorPlanService;
+    private final ISysUserService sysUserService;
 
-    public ExamService(LearnPaperMapper paperMapper, LearnKnowledgeTreeMapper knowledgeTreeMapper, LearnExamineeMapper examineeMapper, ILearnPaperService learnPaperService, PaperService paperService, IAMarjorPlanService marjorPlanService, LearnAnswerMapper learnAnswerMapper, LearnExamineeMapper learnExamineeMapper) {
+    public ExamService(LearnPaperMapper paperMapper, LearnKnowledgeTreeMapper knowledgeTreeMapper, LearnExamineeMapper examineeMapper, ILearnPaperService learnPaperService, PaperService paperService, IAMarjorPlanService marjorPlanService, LearnAnswerMapper learnAnswerMapper, LearnExamineeMapper learnExamineeMapper, ISysUserService sysUserService, LearnStudentMapper learnStudentMapper) {
         this.paperMapper = paperMapper;
         this.knowledgeTreeMapper = knowledgeTreeMapper;
         this.examineeMapper = examineeMapper;
@@ -48,6 +50,8 @@ public class ExamService {
         this.marjorPlanService = marjorPlanService;
         this.learnAnswerMapper = learnAnswerMapper;
         this.learnExamineeMapper = learnExamineeMapper;
+        this.sysUserService = sysUserService;
+        this.learnStudentMapper = learnStudentMapper;
     }
 
     /**
@@ -55,28 +59,46 @@ public class ExamService {
      * @return
      */
     @Transactional(rollbackFor = Exception.class)
-    public AnswerSheet openExaminee(PaperType paperType, Long relatedId) {
+    public AnswerSheet openExaminee(boolean directed, PaperType paperType, Long relatedId) {
         if(paperTypeSet.contains(paperType)) {
             return openExaminee(paperType, relatedId, SecurityUtils.getUserId());
-        } else if(PaperType.Practice.equals(paperType)) { // TODO 先连接学生的定向信息
-            return openExaminee(relatedId, SecurityUtils.getUserId(), "");
+        } else if(PaperType.Practice.equals(paperType)) {
+            return openExaminee(relatedId, SecurityUtils.getUserId(), getDirectedKey(directed));
         } else if(PaperType.Simulated.equals(paperType)) {
-            Integer cnt = 3;
-            return openExaminee(SecurityUtils.getUserId(), cnt);
+            SysUser exist = sysUserService.selectUserById(SecurityUtils.getUserId());
+            return openExaminee(relatedId, exist);
         }
         throw new RuntimeException("错误类型: " + paperType);
     }
 
-    public AnswerSheet loadExaminee(Long examineeId) {
+    private String getDirectedKey(boolean directed) {
+        if(!directed) {
+            return "";
+        }
+        LearnStudent ls = learnStudentMapper.selectLearnStudentByStudentId(SecurityUtils.getUserId());
+        return StringUtils.trimToEmpty(ls.getDirectKey());
+    }
+
+    public AnswerSheet loadExaminee(Long examineeId, Boolean examContinue) {
         LearnExaminee examinee = examineeMapper.selectLearnExamineeByExamineeId(examineeId);
-        if(ExamineeStatus.Exam.getVal().equals(examinee.getState())) {
+        if(examContinue) {
+            if(ExamineeStatus.Sign.getVal().equals(examinee.getState())) {
+                LearnExaminee upExaminee = new LearnExaminee();
+                upExaminee.setExamineeId(examineeId);
+                upExaminee.setBeginTime(new Date());
+                upExaminee.setState(ExamineeStatus.Exam.getVal());
+                examineeMapper.updateLearnExaminee(upExaminee);
+            } else if(!ExamineeStatus.Exam.getVal().equals(examinee.getState())) {
+                throw new RuntimeException("已考完的卷不能继续做");
+            }
+        } else if(ExamineeStatus.Exam.getVal().equals(examinee.getState())) {
             throw new RuntimeException("考试中,不能提取答案");
         }
         LearnAnswer aCond = new LearnAnswer();
         aCond.setExamineeId(examineeId);
         Map<Long, LearnAnswer> answerMap = learnAnswerMapper.selectLearnAnswerList(aCond).stream().collect(Collectors.toMap(LearnAnswer::getQuestionId, t -> t));
         LearnPaper learnPaper = learnPaperService.selectLearnPaperById(examinee.getPaperId());
-        List<PaperVO.QuestionSeq> questionList = paperService.loadPaperQuestions(examinee.getPaperId(), answerMap, true);
+        List<PaperVO.QuestionSeq> questionList = paperService.loadPaperQuestions(examinee.getPaperId(), answerMap, !examContinue);
         AnswerSheet answerSheet = buildAnswerSheet(learnPaper, examinee);
         answerSheet.setTotalCount(questionList.size());
         answerSheet.setWrongCount(examinee.getWrongCount());
@@ -170,29 +192,33 @@ public class ExamService {
         return buildAnswerSheet(paper, learnExaminee);
     }
 
-    private AnswerSheet openExaminee(Long planId, Integer maxCount) {
+    private AnswerSheet openExaminee(Long planId, SysUser sysUser) {
+        AMarjorPlan plan = marjorPlanService.selectAMarjorPlanById(planId);
+        if(null == plan) {
+            throw new ValidationException("专业id无效");
+        }
         LearnExaminee examinee = new LearnExaminee();
         examinee.setStudentId(SecurityUtils.getLoginUser().getUser().getUserId());
         examinee.setPaperType(PaperType.Simulated.getVal());
         List<LearnExaminee> examineeList = examineeMapper.selectLearnExamineeList(examinee);
         Set<Long> existPaperIdSet = Sets.newHashSet();
         for(LearnExaminee e : examineeList) {
-            if(ExamineeStatus.Exam.getVal().equals(e.getState())) {
+            if((ExamineeStatus.Exam.getVal().equals(e.getState()) || ExamineeStatus.Sign.getVal().equals(e.getState())) && e.getPaperKey().equals(planId.toString())) {
                 return buildAnswerSheet(learnPaperService.selectLearnPaperById(e.getPaperId()), e);
             }
             existPaperIdSet.add(e.getPaperId());
         }
-        if(existPaperIdSet.size() >= maxCount) {
-            throw new ValidationException("超过最大次数限制" + maxCount );
-        }
-        AMarjorPlan plan = marjorPlanService.selectAMarjorPlanById(planId);
-        if(null == plan) {
-            throw new ValidationException("专业id无效");
+        if(existPaperIdSet.size() >= sysUser.getEvalCount()) {
+            throw new ValidationException("超过最大次数限制" + sysUser.getEvalCount() );
         }
+        SysUser upUser = new SysUser();
+        upUser.setUserId(sysUser.getUserId());
+        upUser.setEvalCount(sysUser.getEvalCount() - 1);
+        sysUserService.updateUserProfile(upUser);
+
         LearnPaper paper = getBestPaper(plan, existPaperIdSet);
         examinee.setPaperKey(paper.getId().toString());
-        examinee.setState(ExamineeStatus.Exam.getVal());
-        examinee.setBeginTime(new Date());
+        examinee.setState(ExamineeStatus.Sign.getVal());
         examinee.setDuration(0L);
         examineeMapper.insertLearnExaminee(examinee);
         return buildAnswerSheet(paper, examinee);
@@ -295,6 +321,9 @@ public class ExamService {
         answerSheet.setPaperId(examinee.getPaperId());
         answerSheet.setName(paper.getPaperName());
         answerSheet.setBeginTime(examinee.getBeginTime());
+        if(StringUtils.isNotBlank(paper.getConditions())) {
+            answerSheet.setConditions(JSONObject.parseObject(paper.getConditions(), AnswerSheet.PaperCond.class));
+        }
         answerSheet.setScoringType("1");
         answerSheet.setMode(0L);
         answerSheet.setState(examinee.getState());

+ 19 - 2
ie-system/src/main/java/com/ruoyi/learn/domain/AnswerSheet.java

@@ -1,7 +1,10 @@
 package com.ruoyi.learn.domain;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.enums.ExamType;
+import com.ruoyi.enums.PaperType;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -26,8 +29,6 @@ public class AnswerSheet {
     @ApiModelProperty("考试结束时间")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     Date endTime;
-    @ApiModelProperty("考试时间 单位秒")
-    Long remaining;
     @ApiModelProperty("阅卷类型 1 自阅卷 2 老师阅卷")
     private String scoringType;
     @ApiModelProperty("考场分钟 90, 120, xxx")
@@ -41,6 +42,9 @@ public class AnswerSheet {
     @ApiModelProperty("是否可阅卷")
     Boolean allowScore;
 
+    @ApiModelProperty("题定义, time, score, types")
+    PaperCond conditions;
+
     @ApiModelProperty("做题时长")
     private Long duration;
     @ApiModelProperty("总题数")
@@ -49,4 +53,17 @@ public class AnswerSheet {
     private Integer wrongCount;
 
     List<PaperVO.QuestionSeq> questions;
+
+    @Data
+    public static class PaperCond {
+        Integer time; // 秒
+        Integer score; // 总分
+        List<PaperCondType> types;
+    }
+    @Data
+    public static class PaperCondType {
+        String type;
+        Integer count;
+        Integer score; // 本类分
+    }
 }

+ 10 - 0
ie-system/src/main/java/com/ruoyi/learn/domain/LearnExaminee.java

@@ -72,6 +72,8 @@ public class LearnExaminee extends BaseEntity
     @Excel(name = "年排名次")
     private Long gradeRanking;
 
+    private String stats;
+
     @Excel(name = "错题总数")
     private Integer wrongCount;
 
@@ -177,6 +179,14 @@ public class LearnExaminee extends BaseEntity
         return state;
     }
 
+    public String getStats() {
+        return stats;
+    }
+
+    public void setStats(String stats) {
+        this.stats = stats;
+    }
+
     public Integer getWrongCount() {
         return wrongCount;
     }

+ 10 - 0
ie-system/src/main/java/com/ruoyi/learn/domain/LearnPaper.java

@@ -78,6 +78,8 @@ public class LearnPaper extends BaseEntity
     @Excel(name = "适用考生")
     private String examineeTypes;
 
+    private String conditions;
+
     public void setId(Long id) 
     {
         this.id = id;
@@ -236,6 +238,14 @@ public class LearnPaper extends BaseEntity
         return examineeTypes;
     }
 
+    public String getConditions() {
+        return conditions;
+    }
+
+    public void setConditions(String conditions) {
+        this.conditions = conditions;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

+ 4 - 1
ie-system/src/main/resources/mapper/learn/LearnExamineeMapper.xml

@@ -28,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectLearnExamineeVo">
-        select examinee_id, student_id, paper_type, paper_id, begin_time, end_time, duration, state, score_level, score, score_rate, ranking, grade_ranking, wrong_count, choose_count, choose_total, subjective_count, subjective_total, create_time, update_time from learn_examinee
+        select examinee_id, student_id, paper_type, paper_id, begin_time, end_time, duration, stats, state, score_level, score, score_rate, ranking, grade_ranking, wrong_count, choose_count, choose_total, subjective_count, subjective_total, create_time, update_time from learn_examinee
     </sql>
 
     <select id="selectLearnExamineeList" parameterType="LearnExaminee" resultMap="LearnExamineeResult">
@@ -68,6 +68,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="beginTime != null">begin_time,</if>
             <if test="endTime != null">end_time,</if>
             <if test="duration != null">duration,</if>
+            <if test="stats != null">stats,</if>
             <if test="state != null">state,</if>
             <if test="scoreLevel != null">score_level,</if>
             <if test="score != null">score,</if>
@@ -89,6 +90,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="beginTime != null">#{beginTime},</if>
             <if test="endTime != null">#{endTime},</if>
             <if test="duration != null">#{duration},</if>
+            <if test="stats != null">#{stats},</if>
             <if test="state != null">#{state},</if>
             <if test="scoreLevel != null">#{scoreLevel},</if>
             <if test="score != null">#{score},</if>
@@ -114,6 +116,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="beginTime != null">begin_time = #{beginTime},</if>
             <if test="endTime != null">end_time = #{endTime},</if>
             <if test="duration != null">duration = #{duration},</if>
+            <if test="stats != null">stats = #{stats},</if>
             <if test="state != null">state = #{state},</if>
             <if test="scoreLevel != null">score_level = #{scoreLevel},</if>
             <if test="score != null">score = #{score},</if>

+ 6 - 6
ie-system/src/main/resources/mapper/sy/SyMajorMapper.xml

@@ -119,12 +119,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectSyMajorByPlan" resultMap="SyMajorResult">
         SELECT mp.id, m.`type`, m.`code`, m.`name`, CONCAT(m2.`name`, '&gt;', m1.`name`) `ancestors`
-         FROM `a_marjor_plan` mp
-         JOIN `sy_major` m ON mp.`majorName` = m.`name` AND mp.`level` = m.`type`
-         LEFT JOIN `sy_major` m1 ON m1.`code` = m.`parent_code`
-         LEFT JOIN `sy_major` m2 ON m2.`code` = m1.`parent_code`
-        WHERE mp.`year` = #{year} AND mp.`examineeType` = #{examType} AND mp.`universityId` = #{universityId} AND mp.`location` = #{location}
-        order by m.`type`, m.`code`
+        FROM `a_marjor_plan` mp
+                 JOIN `sy_major` m ON mp.`majorName` = m.`name` AND mp.`level` = m.`type` AND mp.`examineeType` = m.`exam_type`
+                 LEFT JOIN `sy_major` m1 ON m1.`code` = m.`parent_code` AND m1.`exam_type` = m.`exam_type` AND m1.type = m.type AND m1.level + 1 = m.level
+                 LEFT JOIN `sy_major` m2 ON m2.`code` = m1.`parent_code` AND m1.`exam_type` = m.`exam_type` AND m2.type = m1.type AND m2.level + 1 = m1.level
+        WHERE mp.`year` = #{year} AND mp.`examineeType` = #{examType} AND mp.`universityId` = #{universityId}  AND mp.`location` = #{location}
+        ORDER BY m.`type`, m.`code`
     </select>
 
 </mapper>