瀏覽代碼

增加模拟卷批量生成入口

mingfu 2 周之前
父節點
當前提交
5fdde778f9

+ 17 - 8
ie-admin/src/main/java/com/ruoyi/web/controller/learn/LearnPaperController.java

@@ -3,17 +3,13 @@ package com.ruoyi.web.controller.learn;
 import java.util.List;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 
 
+import com.ruoyi.web.service.PaperService;
 import io.swagger.annotations.Api;
 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.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 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.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -37,12 +33,16 @@ public class LearnPaperController extends BaseController
     @Autowired
     @Autowired
     private ILearnPaperService learnPaperService;
     private ILearnPaperService learnPaperService;
 
 
+    @Autowired
+    private PaperService paperService;
+
     /**
     /**
      * 查询试卷列表
      * 查询试卷列表
      */
      */
     @PreAuthorize("@ss.hasPermi('learn:paper:list')")
     @PreAuthorize("@ss.hasPermi('learn:paper:list')")
     @GetMapping("/list")
     @GetMapping("/list")
     public TableDataInfo list(LearnPaper learnPaper)
     public TableDataInfo list(LearnPaper learnPaper)
+
     {
     {
         startPage();
         startPage();
         List<LearnPaper> list = learnPaperService.selectLearnPaperList(learnPaper);
         List<LearnPaper> list = learnPaperService.selectLearnPaperList(learnPaper);
@@ -104,4 +104,13 @@ public class LearnPaperController extends BaseController
     {
     {
         return toAjax(learnPaperService.deleteLearnPaperByIds(ids));
         return toAjax(learnPaperService.deleteLearnPaperByIds(ids));
     }
     }
+
+
+    @GetMapping(value = "/buildAll")
+    @ApiOperation("批量生成模拟卷一套")
+    public AjaxResult buildAll(@ApiParam("序号") @RequestParam Integer seq)
+    {
+        paperService.buildAllPapers(seq);
+        return success();
+    }
 }
 }

+ 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.mapper.*;
 import com.ruoyi.learn.service.ILearnQuestionsService;
 import com.ruoyi.learn.service.ILearnQuestionsService;
 import com.ruoyi.syzy.domain.BBusiWishUniversities;
 import com.ruoyi.syzy.domain.BBusiWishUniversities;
+import com.ruoyi.syzy.mapper.BBusiWishUniversitiesMapper;
 import com.ruoyi.syzy.service.IBBusiWishUniversitiesService;
 import com.ruoyi.syzy.service.IBBusiWishUniversitiesService;
 import lombok.Data;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
@@ -23,6 +24,7 @@ import org.springframework.stereotype.Service;
 
 
 import java.util.*;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import java.util.stream.Stream;
 
 
@@ -39,20 +41,40 @@ public class PaperService {
     private final ILearnQuestionsService learnQuestionsService;
     private final ILearnQuestionsService learnQuestionsService;
     private final LearnDirectedKnowledgeMapper learnDirectedKnowledgeMapper;
     private final LearnDirectedKnowledgeMapper learnDirectedKnowledgeMapper;
     private final IBBusiWishUniversitiesService wishUniversitiesService;
     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.paperMapper = paperMapper;
         this.paperQuestionMapper = paperQuestionMapper;
         this.paperQuestionMapper = paperQuestionMapper;
         this.questionsMapper = questionsMapper;
         this.questionsMapper = questionsMapper;
         this.learnQuestionsService = learnQuestionsService;
         this.learnQuestionsService = learnQuestionsService;
         this.learnDirectedKnowledgeMapper = learnDirectedKnowledgeMapper;
         this.learnDirectedKnowledgeMapper = learnDirectedKnowledgeMapper;
         this.wishUniversitiesService = wishUniversitiesService;
         this.wishUniversitiesService = wishUniversitiesService;
+        this.bBusiWishUniversitiesMapper = bBusiWishUniversitiesMapper;
+        buildAllPapers();
         // buildSimulatedPaper(20154L, 1001L);
         // buildSimulatedPaper(20154L, 1001L);
         // buildSimulatedPaper(20950L, 1001L);
         // buildSimulatedPaper(20950L, 1001L);
         // test2();
         // 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() {
     public void test2() {
         TestPaperVO.PaperDef paperDef = new TestPaperVO.PaperDef();
         TestPaperVO.PaperDef paperDef = new TestPaperVO.PaperDef();
         paperDef.setFillExclude(true);
         paperDef.setFillExclude(true);
@@ -168,16 +190,21 @@ public class PaperService {
         return paperQuestionList;
         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
      * @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) {
         for(LearnDirectedKnowledge dk : directedKnowledgeList) {
             if(StringUtils.isBlank(dk.getConditions())) {
             if(StringUtils.isBlank(dk.getConditions())) {
                 continue;
                 continue;
@@ -187,12 +214,17 @@ public class PaperService {
 
 
             LearnPaper paper = new LearnPaper();
             LearnPaper paper = new LearnPaper();
             paper.setSubjectId(subjectId);
             paper.setSubjectId(subjectId);
-            paper.setPaperName(StringUtils.isNotBlank(dk.getDirectKey()) ? universities.getName() + "(" + dk.getDirectKey() + ")" : universities.getName());
             paper.setPaperType(PaperType.Simulated.name());
             paper.setPaperType(PaperType.Simulated.name());
             paper.setRelateId(dk.getId()); // 定向ID
             paper.setRelateId(dk.getId()); // 定向ID
             paper.setYear(dk.getYear());
             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.setStatus(PaperStatus.Valid.getVal());
-            paper.setDirectKey(universityId + "_" + dk.getExamineeTypes() + "_" + dk.getDirectKey());
             paper.setNumber(paperDef.getTotal());
             paper.setNumber(paperDef.getTotal());
             paper.setFenshu(paperDef.getScore().intValue());
             paper.setFenshu(paperDef.getScore().intValue());
             AnswerSheet.PaperCond info = new AnswerSheet.PaperCond();
             AnswerSheet.PaperCond info = new AnswerSheet.PaperCond();
@@ -203,7 +235,7 @@ public class PaperService {
             try {
             try {
                 Pair<LearnPaper, List<LearnPaperQuestion>> paperResult = buildPaper2(null, paper, paperDef);
                 Pair<LearnPaper, List<LearnPaperQuestion>> paperResult = buildPaper2(null, paper, paperDef);
                 savePaper(paperResult.getKey(), paperResult.getValue());
                 savePaper(paperResult.getKey(), paperResult.getValue());
-            } catch(RuntimeException e) {
+            } catch(Exception e) {
                 log.error(e.getMessage());
                 log.error(e.getMessage());
             }
             }
         }
         }