ソースを参照

Merge branch 'master' of http://49.234.186.218:9000/root/ieplus

abpcoder 2 週間 前
コミット
e584b028f2

+ 21 - 9
ie-admin/src/main/java/com/ruoyi/web/controller/learn/LearnPaperController.java

@@ -1,19 +1,17 @@
 package com.ruoyi.web.controller.learn;
 
 import java.util.List;
+import javax.annotation.security.PermitAll;
 import javax.servlet.http.HttpServletResponse;
 
+import com.ruoyi.common.annotation.Anonymous;
+import com.ruoyi.web.service.PaperService;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -31,18 +29,22 @@ import com.ruoyi.common.core.page.TableDataInfo;
  */
 @RestController
 @RequestMapping("/learn/paper")
-@Api("后台-学习 - 卷")
+@Api(tags = "后台-学习 - 卷")
 public class LearnPaperController extends BaseController
 {
     @Autowired
     private ILearnPaperService learnPaperService;
 
+    @Autowired
+    private PaperService paperService;
+
     /**
      * 查询试卷列表
      */
     @PreAuthorize("@ss.hasPermi('learn:paper:list')")
     @GetMapping("/list")
     public TableDataInfo list(LearnPaper learnPaper)
+
     {
         startPage();
         List<LearnPaper> list = learnPaperService.selectLearnPaperList(learnPaper);
@@ -104,4 +106,14 @@ public class LearnPaperController extends BaseController
     {
         return toAjax(learnPaperService.deleteLearnPaperByIds(ids));
     }
+
+
+    @GetMapping(value = "/buildAll")
+    @ApiOperation("批量生成模拟卷一套")
+    @Anonymous
+    public AjaxResult buildAll(@ApiParam("序号") @RequestParam Integer seq)
+    {
+        paperService.buildAllPapers(seq);
+        return success();
+    }
 }

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

@@ -90,7 +90,7 @@ public class ExamService {
             if(UserTypeEnum.isCard(user.getUserType()) && !UserRegStatus.Student.equals(user.getRegStatus())) {
                 throw new RuntimeException("VIP功能不可用");
             }
-            return openExaminee(relatedId, SecurityUtils.getUserId(), getDirectedKey(directed));
+            return openExaminee(relatedId, SecurityUtils.getUserId(), directed);
         } else if(PaperType.Simulated.equals(paperType)) {
             SysUser exist = sysUserService.selectUserById(SecurityUtils.getUserId());
             LearnStudent ls = learnStudentMapper.selectLearnStudentByStudentId(exist.getUserId());
@@ -102,14 +102,6 @@ public class ExamService {
         throw new RuntimeException("错误类型: " + paperType);
     }
 
-    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(examContinue) {
@@ -392,9 +384,14 @@ public class ExamService {
             }
             existPaperIdSet.add(e.getPaperId());
         }
+        LearnPaper paper = getBestPaper(sysUser.getExamType(), plan, 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());
-        if(null == evalCount || existPaperIdSet.size() >= evalCount) {
+        if(null == evalCount || evalCount <= 0) {
             throw new ValidationException("超过最大次数限制" + evalCount );
         }
         SysUser upUser = new SysUser();
@@ -403,12 +400,6 @@ public class ExamService {
         upUser.setEvalCounts(evalCountObj.toJSONString());
         sysUserService.updateUserProfile(upUser);
 
-        existPaperIdSet.clear(); // TODO 临时清除重复检查
-        LearnPaper paper = getBestPaper(sysUser.getExamType(), plan, subjectId, existPaperIdSet);
-        examinee.setPaperId(paper.getId());
-        examinee.setState(ExamineeStatus.Sign.getVal());
-        examinee.setDuration(0L);
-
         JSONObject info = new JSONObject();
         info.put("universityId", ls.getUniversityId());
         info.put("universityName", plan.getUniversityName());
@@ -432,14 +423,26 @@ public class ExamService {
      * 根据知识点生成一次性练习卷并开始做题
      * @return
      */
-    private AnswerSheet openExaminee(Long knowledgeId, Long studentId, String directKey) {
+    private AnswerSheet openExaminee(Long knowledgeId, Long studentId, Boolean directed) {
+        String directKey;
+        AMarjorPlan plan = null;
+        LearnStudent ls = null;
+        if(!directed) {
+            directKey = "";
+        } else {
+            ls = learnStudentMapper.selectLearnStudentByStudentId(SecurityUtils.getUserId());
+            if(null == (plan = marjorPlanService.selectAMarjorPlanById(ls.getMajorPlanId()))) {
+                throw new ValidationException("专业id无效");
+            }
+            directKey = StringUtils.trimToEmpty(ls.getDirectKey());
+        }
         LearnKnowledgeTree knowledgeTree = knowledgeTreeMapper.selectLearnKnowledgeTreeById(knowledgeId);
         LearnPaper paper = new LearnPaper();
         paper.setPaperType(PaperType.Practice.name());
         paper.setRelateId(knowledgeId);
         paper.setYear(Calendar.getInstance().get(Calendar.YEAR));
         paper.setStatus(PaperStatus.TmpValid.getVal());
-        paper.setDirectKey(studentId + "_" + StringUtils.trimToEmpty(directKey));
+        paper.setDirectKey(studentId + "_" + directKey);
         List<LearnPaper> paperList = paperMapper.selectLearnPaperList(paper);
         if (CollectionUtils.isNotEmpty(paperList)) { // 有未做完的
             LearnPaper existPaper = paperList.get(0);
@@ -492,6 +495,14 @@ public class ExamService {
         learnExaminee.setState(ExamineeStatus.Exam.getVal());
         learnExaminee.setBeginTime(new Date());
         learnExaminee.setDuration(0L);
+        if(directed && null != ls.getMajorPlanId()) {
+            JSONObject info = new JSONObject();
+            info.put("universityId", ls.getUniversityId());
+            info.put("universityName", plan.getUniversityName());
+            info.put("planId", ls.getMajorPlanId());
+            info.put("majorName", plan.getMajorName());
+            learnExaminee.setPaperInfo(info.toJSONString());
+        }
         examineeMapper.insertLearnExaminee(learnExaminee);
 
         AnswerSheet answerSheet = buildAnswerSheet(paper, learnExaminee);

+ 41 - 9
ie-admin/src/main/java/com/ruoyi/web/service/PaperService.java

@@ -14,6 +14,7 @@ import com.ruoyi.learn.domain.*;
 import com.ruoyi.learn.mapper.*;
 import com.ruoyi.learn.service.ILearnQuestionsService;
 import com.ruoyi.syzy.domain.BBusiWishUniversities;
+import com.ruoyi.syzy.mapper.BBusiWishUniversitiesMapper;
 import com.ruoyi.syzy.service.IBBusiWishUniversitiesService;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
@@ -23,6 +24,7 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -39,20 +41,40 @@ public class PaperService {
     private final ILearnQuestionsService learnQuestionsService;
     private final LearnDirectedKnowledgeMapper learnDirectedKnowledgeMapper;
     private final IBBusiWishUniversitiesService wishUniversitiesService;
+    private final BBusiWishUniversitiesMapper bBusiWishUniversitiesMapper;
 
 
-    PaperService(LearnPaperMapper paperMapper, LearnPaperQuestionMapper paperQuestionMapper, LearnQuestionsMapper questionsMapper, ILearnQuestionsService learnQuestionsService, LearnDirectedKnowledgeMapper learnDirectedKnowledgeMapper, IBBusiWishUniversitiesService wishUniversitiesService) {
+    PaperService(LearnPaperMapper paperMapper, LearnPaperQuestionMapper paperQuestionMapper, LearnQuestionsMapper questionsMapper, ILearnQuestionsService learnQuestionsService, LearnDirectedKnowledgeMapper learnDirectedKnowledgeMapper, IBBusiWishUniversitiesService wishUniversitiesService, BBusiWishUniversitiesMapper bBusiWishUniversitiesMapper) {
         this.paperMapper = paperMapper;
         this.paperQuestionMapper = paperQuestionMapper;
         this.questionsMapper = questionsMapper;
         this.learnQuestionsService = learnQuestionsService;
         this.learnDirectedKnowledgeMapper = learnDirectedKnowledgeMapper;
         this.wishUniversitiesService = wishUniversitiesService;
+        this.bBusiWishUniversitiesMapper = bBusiWishUniversitiesMapper;
+        // buildAllPapers(0);
         // buildSimulatedPaper(20154L, 1001L);
         // buildSimulatedPaper(20950L, 1001L);
         // test2();
     }
 
+    public void buildAllPapers(Integer seq) {
+        LearnDirectedKnowledge dkCond = new LearnDirectedKnowledge();
+        dkCond.setYear(2025);
+        Map<Long, List<LearnDirectedKnowledge>> universityDirectedMap = learnDirectedKnowledgeMapper.selectLearnDirectedKnowledgeList(dkCond).stream().collect(Collectors.groupingBy(LearnDirectedKnowledge::getUniversityId));
+
+        Map uCond = new HashMap();
+        uCond.put("ids", universityDirectedMap.keySet());
+        Map<Long, BBusiWishUniversities> universityMap = bBusiWishUniversitiesMapper.selectBBusiWishUniversitiesListSimpleByIds(uCond).stream().collect(Collectors.toMap(BBusiWishUniversities::getId, Function.identity()));
+        for(Long universityId : universityDirectedMap.keySet()) {
+            BBusiWishUniversities universities = universityMap.get(universityId);
+            if(null == universities) {
+                continue;
+            }
+            buildSimulatedPaper(1001L, seq, universities, universityDirectedMap.get(universityId));
+        }
+    }
+
     public void test2() {
         TestPaperVO.PaperDef paperDef = new TestPaperVO.PaperDef();
         paperDef.setFillExclude(true);
@@ -168,16 +190,21 @@ public class PaperService {
         return paperQuestionList;
     }
 
+    public int buildSimulatedPaper(Long universityId, Long subjectId, Integer seq) {
+        LearnDirectedKnowledge dkCond = new LearnDirectedKnowledge();
+        dkCond.setUniversityId(universityId);
+        List<LearnDirectedKnowledge> directedKnowledgeList = learnDirectedKnowledgeMapper.selectLearnDirectedKnowledgeList(dkCond);
+        BBusiWishUniversities universities = wishUniversitiesService.selectBBusiWishUniversitiesById(universityId);
+        buildSimulatedPaper(subjectId, seq, universities, directedKnowledgeList);
+        return 0;
+    }
+
     /**
      * 根据院校专业要求生成模拟试卷
      * @return
      */
 
-    public int buildSimulatedPaper(Long universityId, Long subjectId) {
-        LearnDirectedKnowledge dkCond = new LearnDirectedKnowledge();
-        dkCond.setUniversityId(universityId);
-        List<LearnDirectedKnowledge> directedKnowledgeList = learnDirectedKnowledgeMapper.selectLearnDirectedKnowledgeList(dkCond);
-        BBusiWishUniversities universities = wishUniversitiesService.selectBBusiWishUniversitiesById(universityId);
+    public int buildSimulatedPaper(Long subjectId, Integer seq, BBusiWishUniversities universities, List<LearnDirectedKnowledge> directedKnowledgeList) {
         for(LearnDirectedKnowledge dk : directedKnowledgeList) {
             if(StringUtils.isBlank(dk.getConditions())) {
                 continue;
@@ -187,12 +214,17 @@ public class PaperService {
 
             LearnPaper paper = new LearnPaper();
             paper.setSubjectId(subjectId);
-            paper.setPaperName(StringUtils.isNotBlank(dk.getDirectKey()) ? universities.getName() + "(" + dk.getDirectKey() + ")" : universities.getName());
             paper.setPaperType(PaperType.Simulated.name());
             paper.setRelateId(dk.getId()); // 定向ID
             paper.setYear(dk.getYear());
+            paper.setPaperSource(seq);
+            if(CollectionUtils.isNotEmpty(paperMapper.selectLearnPaperList(paper))) {
+                log.warn("已经生成: {}:{}", dk.getId(), seq);
+                continue;
+            }
+            paper.setPaperName(StringUtils.isNotBlank(dk.getDirectKey()) ? universities.getName() + "(" + dk.getDirectKey() + ")" : universities.getName());
+            paper.setDirectKey(universities.getId() + "_" + dk.getExamineeTypes() + "_" + dk.getDirectKey());
             paper.setStatus(PaperStatus.Valid.getVal());
-            paper.setDirectKey(universityId + "_" + dk.getExamineeTypes() + "_" + dk.getDirectKey());
             paper.setNumber(paperDef.getTotal());
             paper.setFenshu(paperDef.getScore().intValue());
             AnswerSheet.PaperCond info = new AnswerSheet.PaperCond();
@@ -203,7 +235,7 @@ public class PaperService {
             try {
                 Pair<LearnPaper, List<LearnPaperQuestion>> paperResult = buildPaper2(null, paper, paperDef);
                 savePaper(paperResult.getKey(), paperResult.getValue());
-            } catch(RuntimeException e) {
+            } catch(Exception e) {
                 log.error(e.getMessage());
             }
         }

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

@@ -32,7 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="level != null "> and level = #{level}</if>
             <if test="questionsCount != null "> and questionsCount = #{questionsCount}</if>
             <if test="locations != null  and locations != ''"> and locations = #{locations}</if>
-            <if test="examineeTypes != null  and examineeTypes != ''"> and examineeTypes = #{examineeTypes}</if>
+            <if test="examineeTypes != null  and examineeTypes != ''"> and (examineeTypes is null or find_in_set(#{examineeTypes}, examineeTypes))</if>
         </where>
     </select>