Преглед на файлове

增加模拟考试科目列表

mingfu преди 3 седмици
родител
ревизия
dd56fe2e50

+ 45 - 8
ie-admin/src/main/java/com/ruoyi/web/controller/front/FrontExamController.java

@@ -1,22 +1,27 @@
 package com.ruoyi.web.controller.front;
 
+import com.alibaba.fastjson2.JSONObject;
 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.DzSubject;
 import com.ruoyi.dz.service.IDzControlService;
+import com.ruoyi.dz.service.IDzSubjectService;
 import com.ruoyi.enums.PaperType;
 import com.ruoyi.learn.domain.AnswerSheet;
 import com.ruoyi.mxjb.domain.MxjbContants;
 import com.ruoyi.system.service.ISysUserService;
 import com.ruoyi.web.domain.PaperDto;
-import com.ruoyi.web.service.CacheService;
-import com.ruoyi.web.service.ExamService;
-import com.ruoyi.web.service.PaperService;
-import com.ruoyi.web.service.SyTestMajorService;
+import com.ruoyi.web.service.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 @RestController
 @RequestMapping("/front/exam")
@@ -25,11 +30,33 @@ public class FrontExamController {
     private final ExamService examService;
     private final SyTestMajorService syTestMajorService;
     private final CacheService cacheService;
+    private final IDzSubjectService dzSubjectService;
+    private final StudentService studentService;
+    private final ISysUserService sysUserService;
 
-    public FrontExamController(ExamService examService, SyTestMajorService syTestMajorService, CacheService cacheService) {
+    public FrontExamController(ExamService examService, SyTestMajorService syTestMajorService, CacheService cacheService, IDzSubjectService dzSubjectService, IDzSubjectService dzSubjectService1, StudentService studentService, ISysUserService sysUserService) {
         this.examService = examService;
         this.syTestMajorService = syTestMajorService;
         this.cacheService = cacheService;
+        this.dzSubjectService = dzSubjectService1;
+        this.studentService = studentService;
+        this.sysUserService = sysUserService;
+    }
+
+    @GetMapping("/subjects")
+    @ApiOperation("科目列表")
+    public AjaxResult subjects()
+    {
+        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
+        List<DzSubject> list = dzSubjectService.selectDzSubjectBySubjectIds(new Long[] {1L, 2L, 3L, 11L});
+        JSONObject evalCounts = JSONObject.parseObject(sysUserService.selectUserById(sysUser.getUserId()).getEvalCounts());
+        return AjaxResult.success(list.stream().map(t -> {
+            JSONObject o = new JSONObject();
+            o.put("subjectId", t.getSubjectId());
+            o.put("subject", t.getSubjectName());
+            o.put("examTime", evalCounts.getIntValue(t.getSubjectId().toString()));
+            return o;
+        }).collect(Collectors.toList()));
     }
 
     // 试卷: 真题卷,批次测试卷,自组卷, 生成考试记录
@@ -40,7 +67,9 @@ public class FrontExamController {
     public AjaxResult openExaminee(@ApiParam("0默认1价值2职业3知识") @RequestParam(required = false) Integer testType,
                                    @ApiParam("定向") @RequestParam(defaultValue = "false") boolean directed,
                                    @ApiParam("考卷类型PaperType") @RequestParam(required = false) PaperType paperType,
-                                   @ApiParam("考卷类型关联ID") @RequestParam Long relateId) {
+                                   @ApiParam("考卷类型关联ID") @RequestParam(required = false) Long relateId,
+                                   @ApiParam("考卷类型关联ID") @RequestParam(required = false) Long subjectId,
+                                   @RequestBody JSONObject body) {
         if(null != testType && testType > 0) {
             PaperDto paperDto = syTestMajorService.loadPaperByTestMajorTypeId(testType);
             Map<String, String> stateMap = cacheService.selectDictDataMapByType(MxjbContants.StateTypeExaminee);
@@ -48,7 +77,12 @@ public class FrontExamController {
             paperDto.calculateAllow();
             return AjaxResult.success(paperDto);
         }
-        return AjaxResult.success(examService.openExaminee(directed, paperType, relateId));
+        if(null == subjectId && null == paperType) {
+            subjectId = body.getLongValue("subjectId");
+            paperType = PaperType.valueOf(body.getString("paperType"));
+        }
+
+        return AjaxResult.success(examService.openExaminee(directed, paperType, relateId, subjectId));
     }
 
     @ApiOperation("04 开始考试")
@@ -60,8 +94,11 @@ public class FrontExamController {
 
     @ApiOperation("04 取答卷")
     @GetMapping(value = "loadExaminee")
-    public AjaxResult loadExaminee(@ApiParam("答卷ID") Long examineeId) {
+    public AjaxResult loadExaminee(@ApiParam("答卷ID") @RequestParam(required = false) Long examineeId, @RequestBody JSONObject body) {
         // 检查状态,以决定是否返回答案
+        if(null == examineeId) {
+            examineeId = body.getLongValue("examineeId");
+        }
         return AjaxResult.success(examService.loadExaminee(examineeId, false));
     }
 

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

@@ -65,20 +65,7 @@ public class FrontPaperController {
     @ApiOperation("02 考试科目")
     @GetMapping(value = "subject")
     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);
-        if(!directed) {
-            return AjaxResult2.success(list);
-        }
-        LearnStudent learnStudent = learnStudentService.selectLearnStudentByStudentId(SecurityUtils.getUserId());
-        Set<Long> subjectIdSet;
-        if(null == learnStudent || CollectionUtils.isEmpty((subjectIdSet = learnTeacherService.getSubjectIdSet(new Long[] {learnStudent.getMajorPlanId()})))) {
-            return AjaxResult2.success(list);
-        }
-        return AjaxResult2.success(list.stream().filter(t -> subjectIdSet.contains(t.getSubjectId())).collect(Collectors.toList()));
+        return AjaxResult2.success(studentService.getSubjectList(directed));
     }
 
     @ApiOperation("03 知识点树")

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

@@ -156,7 +156,7 @@ public class FrontStudentController extends BaseController {
             result.put("subjects", Lists.newArrayList("职业技能"));
         }
         SysUser sysUser = sysUserService.selectUserById(SecurityUtils.getUserId());
-        result.put("evalCount", sysUser.getEvalCount());
+        result.put("evalCount", sysUser.getEvalCounts());
         return AjaxResult.success(result);
     }
 

+ 18 - 13
ie-admin/src/main/java/com/ruoyi/web/service/ExamService.java

@@ -72,7 +72,7 @@ public class ExamService {
      * @return
      */
     @Transactional(rollbackFor = Exception.class)
-    public AnswerSheet openExaminee(boolean directed, PaperType paperType, Long relatedId) {
+    public AnswerSheet openExaminee(boolean directed, PaperType paperType, Long relatedId, Long subjectId) {
         SysUser user = SecurityUtils.getLoginUser().getUser();
         if(paperTypeSet.contains(paperType)) {
             if(UserTypeEnum.isCard(user.getUserType()) && !UserRegStatus.Student.equals(user.getRegStatus())) {
@@ -86,7 +86,11 @@ public class ExamService {
             return openExaminee(relatedId, SecurityUtils.getUserId(), getDirectedKey(directed));
         } else if(PaperType.Simulated.equals(paperType)) {
             SysUser exist = sysUserService.selectUserById(SecurityUtils.getUserId());
-            return openExaminee(relatedId, exist);
+            LearnStudent ls = learnStudentMapper.selectLearnStudentByStudentId(exist.getUserId());
+            if(null == ls) {
+                throw new RuntimeException("请先定设置定向学习" + exist.getUserId());
+            }
+            return openExaminee(ls.getMajorPlanId(), subjectId, exist);
         }
         throw new RuntimeException("错误类型: " + paperType);
     }
@@ -301,7 +305,7 @@ public class ExamService {
         return buildAnswerSheet(paper, learnExaminee);
     }
 
-    private AnswerSheet openExaminee(Long planId, SysUser sysUser) {
+    private AnswerSheet openExaminee(Long planId, Long subjectId, SysUser sysUser) {
         AMarjorPlan plan = marjorPlanService.selectAMarjorPlanById(planId);
         if(null == plan) {
             throw new ValidationException("专业id无效");
@@ -309,24 +313,24 @@ public class ExamService {
         LearnExaminee examinee = new LearnExaminee();
         examinee.setStudentId(SecurityUtils.getLoginUser().getUser().getUserId());
         examinee.setPaperType(PaperType.Simulated.getVal());
+        examinee.setPaperKey(subjectId.toString());
         List<LearnExaminee> examineeList = examineeMapper.selectLearnExamineeList(examinee);
         Set<Long> existPaperIdSet = Sets.newHashSet();
         for(LearnExaminee e : examineeList) {
-            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() >= sysUser.getEvalCount()) {
-            throw new ValidationException("超过最大次数限制" + sysUser.getEvalCount() );
+        JSONObject evalCountObj = JSONObject.parseObject(sysUser.getEvalCounts());
+        Integer evalCount = evalCountObj.getInteger(subjectId.toString());
+        if(null == evalCount || existPaperIdSet.size() >= evalCount) {
+            throw new ValidationException("超过最大次数限制" + evalCount );
         }
         SysUser upUser = new SysUser();
         upUser.setUserId(sysUser.getUserId());
-        upUser.setEvalCount(sysUser.getEvalCount() - 1);
+        evalCountObj.put(subjectId.toString(), evalCount - 1);
+        upUser.setEvalCounts(evalCountObj.toJSONString());
         sysUserService.updateUserProfile(upUser);
 
-        LearnPaper paper = getBestPaper(plan, existPaperIdSet);
-        examinee.setPaperKey(paper.getId().toString());
+        LearnPaper paper = getBestPaper(plan, subjectId, existPaperIdSet);
         examinee.setState(ExamineeStatus.Sign.getVal());
         examinee.setDuration(0L);
         examineeMapper.insertLearnExaminee(examinee);
@@ -402,9 +406,10 @@ public class ExamService {
         return answerSheet;
     }
 
-    private LearnPaper getBestPaper(AMarjorPlan plan, Set<Long> existPaperIdSet) {
+    private LearnPaper getBestPaper(AMarjorPlan plan, Long subjectId, Set<Long> existPaperIdSet) {
         String groupName = StringUtils.trimToEmpty(plan.getMajorGroup());
         LearnPaper paperCond = new LearnPaper();
+        paperCond.setSubjectId(subjectId);
         paperCond.setPaperType(PaperType.Simulated.name());
         for(int i = 3; i>0; i--) {
             if(i == 3) {
@@ -421,7 +426,7 @@ public class ExamService {
                 }
             }
         }
-        throw new ValidationException("未初始化院校定向模拟题库: " + plan.getId());
+        throw new ValidationException("未初始化院校定向模拟题库: " + subjectId + ":" + plan.getId());
     }
 
     private AnswerSheet buildAnswerSheet(LearnPaper paper, LearnExaminee examinee) {

+ 28 - 1
ie-admin/src/main/java/com/ruoyi/web/service/StudentService.java

@@ -2,8 +2,11 @@ package com.ruoyi.web.service;
 
 import cn.hutool.core.lang.Dict;
 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.utils.SecurityUtils;
+import com.ruoyi.dz.domain.DzSubject;
+import com.ruoyi.dz.service.IDzSubjectService;
 import com.ruoyi.enums.ExamineeStatus;
 import com.ruoyi.learn.domain.LearnPaper;
 import com.ruoyi.learn.domain.LearnStudent;
@@ -15,19 +18,43 @@ import com.ruoyi.learn.service.ILearnStudentService;
 import com.ruoyi.system.service.ISysUserService;
 import org.apache.commons.compress.utils.Lists;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 @Service
 public class StudentService {
     private final LearnPaperMapper learnPaperMapper;
     private final LearnTestStudentMapper learnTestStudentMapper;
     private final ILearnStudentService learnStudentService;
+    private final IDzSubjectService dzSubjectService;
+    private final LearnTeacherService learnTeacherService;
 
-    public StudentService(LearnPaperMapper learnPaperMapper, LearnTestStudentMapper learnTestStudentMapper, ILearnStudentService learnStudentService) {
+    public StudentService(LearnPaperMapper learnPaperMapper, LearnTestStudentMapper learnTestStudentMapper, ILearnStudentService learnStudentService, IDzSubjectService dzSubjectService, LearnTeacherService learnTeacherService) {
         this.learnPaperMapper = learnPaperMapper;
         this.learnTestStudentMapper = learnTestStudentMapper;
         this.learnStudentService = learnStudentService;
+        this.dzSubjectService = dzSubjectService;
+        this.learnTeacherService = learnTeacherService;
+    }
+
+    public List<DzSubject> getSubjectList(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);
+        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;
+        }
+        return list.stream().filter(t -> subjectIdSet.contains(t.getSubjectId())).collect(Collectors.toList());
     }
 
     public List<Dict> selectStatsForStudent(Long studentId) {

+ 1 - 1
ie-admin/src/main/java/com/ruoyi/web/service/SysRegisterService.java

@@ -165,7 +165,7 @@ public class SysRegisterService
                 if(!CardStatus.Paid.getVal().equals(card.getStatus())) {
                     throw new RuntimeException("无效卡");
                 }
-                user.setEvalCount(1);
+                user.setEvalCounts("{\"1\":3,\"2\":3,\"3\":3,\"11\":5,\"0\":0}");
                 user.setCardId(card.getCardId());
                 user.setRegStatus(UserRegStatus.Student);
                 card.setStatus(CardStatus.Active.getVal());

+ 7 - 6
ie-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java

@@ -132,10 +132,11 @@ public class SysUser extends BaseEntity
     /** 选科ID **/
     private Integer selectSubject;
 
+    @JsonIgnore
     private String directedStudy;
 
-    @Excel(name = "模拟做卷次数")
-    private Integer evalCount;
+    @JsonIgnore
+    private String evalCounts;
 
     private Long cardId;
 
@@ -478,12 +479,12 @@ public class SysUser extends BaseEntity
         this.cardId = cardId;
     }
 
-    public Integer getEvalCount() {
-        return evalCount;
+    public String getEvalCounts() {
+        return evalCounts;
     }
 
-    public void setEvalCount(Integer evalCount) {
-        this.evalCount = evalCount;
+    public void setEvalCounts(String evalCounts) {
+        this.evalCounts = evalCounts;
     }
 
     public String getCode() {

+ 1 - 0
ie-system/src/main/java/com/ruoyi/dz/mapper/DzSubjectMapper.java

@@ -11,6 +11,7 @@ import com.ruoyi.dz.domain.DzSubject;
  */
 public interface DzSubjectMapper 
 {
+    public List<DzSubject> selectDzSubjectBySubjectIds(Long[] subjectIds);
     /**
      * 查询科目
      * 

+ 2 - 0
ie-system/src/main/java/com/ruoyi/dz/service/IDzSubjectService.java

@@ -11,6 +11,8 @@ import com.ruoyi.dz.domain.DzSubject;
  */
 public interface IDzSubjectService 
 {
+    List<DzSubject> selectDzSubjectBySubjectIds(Long[] subjectIds);
+
     /**
      * 查询科目
      * 

+ 3 - 0
ie-system/src/main/java/com/ruoyi/dz/service/impl/DzSubjectServiceImpl.java

@@ -19,6 +19,9 @@ public class DzSubjectServiceImpl implements IDzSubjectService
     @Autowired
     private DzSubjectMapper dzSubjectMapper;
 
+    public List<DzSubject> selectDzSubjectBySubjectIds(Long[] subjectIds) {
+        return dzSubjectMapper.selectDzSubjectBySubjectIds(subjectIds);
+    }
     /**
      * 查询科目
      * 

+ 5 - 0
ie-system/src/main/resources/mapper/dz/DzSubjectMapper.xml

@@ -17,6 +17,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select subject_id, subject_name, pinyin, sort, locations, exam_types from dz_subject
     </sql>
 
+    <select id="selectDzSubjectBySubjectIds" resultMap="DzSubjectResult">
+        <include refid="selectDzSubjectVo"/>
+        where subject_id in <foreach item="subjectId" collection="array" open="(" separator="," close=")">#{subjectId}</foreach>
+    </select>
+
     <select id="selectWrongSubjectList" parameterType="Long" resultMap="DzSubjectResult">
         SELECT s.subject_id, s.subject_name FROM `learn_wrong_book` wb JOIN dz_subject s ON wb.`subject_id` = s.`subject_id`
         WHERE wb.`student_id` = #{studentId}

+ 4 - 2
ie-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -22,7 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="scores"        column="scores" typeHandler="com.ruoyi.system.handlers.SubjectScoreTypeHandler"        />
 		<result property="selectSubject" column="select_subject"       />
 		<result property="directedStudy" column="directed_study"       />
-		<result property="evalCount"     column="eval_count"       />
+		<result property="evalCounts"     column="eval_counts" />
 		<result property="cardId"        column="card_id"         />
         <result property="status"        column="status"          />
         <result property="delFlag"       column="del_flag"        />
@@ -61,7 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
 	<sql id="selectUserVo">
         select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.pwd_update_date, u.create_by, u.create_time, u.remark,
-		u.location,u.exam_type,u.reg_status,u.end_year,u.invite_code,u.scores,u.select_subject,u.directed_study,u.eval_count,u.card_id,
+		u.location,u.exam_type,u.reg_status,u.end_year,u.invite_code,u.scores,u.select_subject,u.directed_study,u.eval_counts,u.card_id,
         d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
         r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status, u.user_type, u.user_type_id
         from sys_user u
@@ -190,6 +190,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		    <if test="endYear != null">end_year,</if>
 		    <if test="inviteCode != null and inviteCode != ''">invite_code,</if>
 		    <if test="scores != null and scores != ''">scores,</if>
+		    <if test="evalCounts != null">eval_counts,</if>
 		    <if test="selectSubject != null and selectSubject != ''">select_subject,</if>
 		    <if test="directedStudy != null and directedStudy != ''">directed_study,</if>
 		    <if test="cardId != null and cardId != ''">card_id,</if>
@@ -217,6 +218,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="endYear != null and endYear != ''">#{endYear},</if>
  			<if test="inviteCode != null and inviteCode != ''">#{inviteCode},</if>
  			<if test="scores != null and scores != ''">#{scores, typeHandler=com.ruoyi.system.handlers.SubjectScoreTypeHandler},</if>
+		    <if test="evalCounts != null">#{evalCounts},</if>
  			<if test="selectSubject != null and selectSubject != ''">#{selectSubject},</if>
  			<if test="directedStudy != null and directedStudy != ''">#{directedStudy},</if>
  			<if test="cardId != null and cardId != ''">#{cardId},</if>