xiatian 4 년 전
부모
커밋
60bd9afef7

+ 89 - 14
examcloud-core-questions-api-provider/src/main/java/cn/com/qmth/examcloud/core/questions/api/controller/PaperController.java

@@ -13,8 +13,10 @@ import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
 import cn.com.qmth.examcloud.core.questions.base.excel.ExportUtils;
 import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
 import cn.com.qmth.examcloud.core.questions.dao.ExportServiceManageRepo;
+import cn.com.qmth.examcloud.core.questions.dao.PaperDetailUnitRepo;
 import cn.com.qmth.examcloud.core.questions.dao.PaperRepo;
 import cn.com.qmth.examcloud.core.questions.dao.entity.Paper;
+import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetailUnit;
 import cn.com.qmth.examcloud.core.questions.dao.entity.PaperSearchInfo;
 import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
 import cn.com.qmth.examcloud.core.questions.service.PaperService;
@@ -37,6 +39,8 @@ import cn.com.qmth.examcloud.web.support.Naked;
 import com.google.gson.Gson;
 import freemarker.template.TemplateException;
 import io.swagger.annotations.ApiOperation;
+
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Example;
@@ -54,6 +58,7 @@ import javax.validation.constraints.NotNull;
 import java.io.File;
 import java.io.IOException;
 import java.io.StringWriter;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -91,6 +96,8 @@ public class PaperController extends ControllerSupport {
     @Autowired
     OrgCloudService orgCloudService;
 
+    @Autowired
+    PaperDetailUnitRepo paperDetailUnitRepo;
     /**
      * 根据Id获取试卷
      *
@@ -227,16 +234,17 @@ public class PaperController extends ControllerSupport {
      */
     @ResponseBody
     @ApiOperation(value = "查询所有导入试卷(not in paperIds)", notes = "查询所有导入试卷(not in paperIds)")
-    @GetMapping(value = "/genPaper/{ids}/{curPage}/{pageSize}")
+    @GetMapping(value = "/genPaper/huoge/{curPage}/{pageSize}")
     public ResponseEntity<Object> getGenPapersNotInIds(@ModelAttribute PaperSearchInfo paperSearchInfo,
-                                                       @PathVariable String[] ids, @PathVariable int curPage, @PathVariable int pageSize) {
-        User user = getAccessUser();
+                                                       @RequestParam String ids, @PathVariable int curPage, @PathVariable int pageSize) {
+    	User user = getAccessUser();
         paperSearchInfo.setOrgId(user.getRootOrgId().toString());
-        Page<Paper> ret;
-        if (ids != null && ids.length > 0) {
-            ret = paperService.getPapersNotInIds(paperSearchInfo, ids, curPage, pageSize, PaperType.GENERATE);
+        Page<Paper> ret=null;
+        if (StringUtils.isNotBlank(ids)) {
+        	String[] idArr=ids.split(",");
+            ret = paperService.getPapersNotInIds(paperSearchInfo, idArr, curPage, pageSize, PaperType.GENERATE);
             if (ret.getContent().size() == 0 && ret.getTotalElements() > 0 && curPage > 1) {
-                ret = paperService.getPapersNotInIds(paperSearchInfo, ids, curPage - 1, pageSize, PaperType.GENERATE);
+                ret = paperService.getPapersNotInIds(paperSearchInfo, idArr, curPage - 1, pageSize, PaperType.GENERATE);
             }
         } else {
             ret = paperService.getGenPapers(paperSearchInfo, curPage, pageSize);
@@ -244,6 +252,9 @@ public class PaperController extends ControllerSupport {
                 ret = paperService.getGenPapers(paperSearchInfo, curPage - 1, pageSize);
             }
         }
+        if(ret!=null&&CollectionUtils.isNotEmpty(ret.getContent())) {
+        	setPaperQuesCountAndScore(ret.getContent());
+        }
         return new ResponseEntity<>(ret, HttpStatus.OK);
     }
 
@@ -574,16 +585,17 @@ public class PaperController extends ControllerSupport {
      */
     @ResponseBody
     @ApiOperation(value = "查询所有导入试卷(not in paperIds)", notes = "查询所有导入试卷(not in paperIds)")
-    @GetMapping(value = "/importPaper/{ids}/{curPage}/{pageSize}")
-    public ResponseEntity<Object> getImportPapersNotInIds(@ModelAttribute PaperSearchInfo paperSearchInfo, @PathVariable String[] ids, @PathVariable int curPage,
+    @GetMapping(value = "/importPaper/huoge/{curPage}/{pageSize}")
+    public ResponseEntity<Object> getImportPapersNotInIds(@ModelAttribute PaperSearchInfo paperSearchInfo, @RequestParam String ids, @PathVariable int curPage,
                                                           @PathVariable int pageSize) {
-        User user = getAccessUser();
+    	User user = getAccessUser();
         paperSearchInfo.setOrgId(user.getRootOrgId().toString());
-        Page<Paper> ret;
-        if (ids != null && ids.length > 0) {
-            ret = paperService.getPapersNotInIds(paperSearchInfo, ids, curPage, pageSize, PaperType.IMPORT);
+        Page<Paper> ret=null;
+        if (StringUtils.isNotBlank(ids)) {
+        	String[] idArr=ids.split(",");
+            ret = paperService.getPapersNotInIds(paperSearchInfo, idArr, curPage, pageSize, PaperType.IMPORT);
             if (ret.getContent().size() == 0 && ret.getTotalElements() > 0 && curPage > 1) {
-                ret = paperService.getPapersNotInIds(paperSearchInfo, ids, curPage - 1, pageSize, PaperType.IMPORT);
+                ret = paperService.getPapersNotInIds(paperSearchInfo, idArr, curPage - 1, pageSize, PaperType.IMPORT);
             }
         } else {
             ret = paperService.getImportPapers(paperSearchInfo, curPage, pageSize);
@@ -591,8 +603,71 @@ public class PaperController extends ControllerSupport {
                 ret = paperService.getImportPapers(paperSearchInfo, curPage - 1, pageSize);
             }
         }
+        if(ret!=null&&CollectionUtils.isNotEmpty(ret.getContent())) {
+        	setPaperQuesCountAndScore(ret.getContent());
+        }
         return new ResponseEntity<>(ret, HttpStatus.OK);
     }
+    
+    private void setPaperQuesCountAndScore(List<Paper> paperList) {
+        if (paperList == null || paperList.size() == 0) {
+            return;
+        }
+        for (Paper paper : paperList) {
+            initQuesCountAndScore(paper);
+            Map<String, Integer> quesCount = paper.getQuesCount();
+            Map<String, Double> quesScore = paper.getQuesScore();
+            List<PaperDetailUnit> units = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
+            if (units != null && units.size() > 0) {
+                for (PaperDetailUnit unit : units) {
+                    if (unit.getQuestion().getPublicity() == null) {
+                        unit.getQuestion().setPublicity(true);
+                    }
+                    if (unit.getQuestion().getDifficulty() == null) {
+                        unit.getQuestion().setDifficulty("中");
+                    }
+                    String key = getKey(unit.getQuestion().getPublicity(), unit.getQuestion().getDifficulty());
+                    quesCount.put(key, quesCount.get(key) + 1);
+                    quesScore.put(key, BigDecimal.valueOf(quesScore.get(key)).add(BigDecimal.valueOf(unit.getScore())).doubleValue());
+                }
+            }
+        }
+    }
+
+    private String getKey(Boolean publicity, String difficultyType) {
+        String difficulty = null;
+        if ("易".equals(difficultyType)) {
+            difficulty = "1";
+        } else if ("中".equals(difficultyType)) {
+            difficulty = "2";
+        } else {
+            difficulty = "3";
+        }
+        if (publicity == null || publicity) {
+            return "1-" + difficulty;
+        } else {
+            return "0-" + difficulty;
+        }
+    }
+
+    private void initQuesCountAndScore(Paper paper) {
+        Map<String, Integer> quesCount = new HashMap<>();
+        quesCount.put("0-1", 0);
+        quesCount.put("0-2", 0);
+        quesCount.put("0-3", 0);
+        quesCount.put("1-1", 0);
+        quesCount.put("1-2", 0);
+        quesCount.put("1-3", 0);
+        Map<String, Double> quesScore = new HashMap<>();
+        quesScore.put("0-1", 0.0);
+        quesScore.put("0-2", 0.0);
+        quesScore.put("0-3", 0.0);
+        quesScore.put("1-1", 0.0);
+        quesScore.put("1-2", 0.0);
+        quesScore.put("1-3", 0.0);
+        paper.setQuesCount(quesCount);
+        paper.setQuesScore(quesScore);
+    }
 
     /**
      * @param paperSearchInfo

+ 1 - 1
examcloud-core-questions-dao/src/main/java/cn/com/qmth/examcloud/core/questions/dao/entity/PaperSearchInfo.java

@@ -7,7 +7,7 @@ import java.io.Serializable;
 public class PaperSearchInfo implements Serializable {
 
     private static final long serialVersionUID = 1L;
-
+    
     private String name;// 试卷名称
 
     private String createTime;// 创建时间

+ 1 - 64
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/PaperServiceImpl.java

@@ -213,8 +213,6 @@ public class PaperServiceImpl implements PaperService {
             return Page.empty();
         }
 
-        setPaperQuesCountAndScore(paperList);// todo 待优化
-
         return new PageImpl<>(paperList, pageable, total);
     }
 
@@ -379,7 +377,6 @@ public class PaperServiceImpl implements PaperService {
         query.limit(pageSize);
         query.skip((curPage - 1L) * pageSize);
         List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
-        setPaperQuesCountAndScore(paperList);
         return new PageImpl<Paper>(paperList, PageRequest.of(curPage - 1, pageSize), total);
     }
 
@@ -418,7 +415,6 @@ public class PaperServiceImpl implements PaperService {
         query.limit(pageSize);
         query.skip((curPage - 1L) * pageSize);
         List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
-        setPaperQuesCountAndScore(paperList);
         return new PageImpl<Paper>(paperList, PageRequest.of(curPage - 1, pageSize), total);
     }
 
@@ -1150,7 +1146,6 @@ public class PaperServiceImpl implements PaperService {
         query.skip((curPage - 1L) * pageSize);
         List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
         Page<Paper> paperPageList = new PageImpl<Paper>(paperList, PageRequest.of(curPage - 1, pageSize), total);
-        setPaperQuesCountAndScore(paperList);
         return paperPageList;
     }
 
@@ -2329,64 +2324,6 @@ public class PaperServiceImpl implements PaperService {
         return Integer.valueOf(s.trim());
     }
 
-    private void setPaperQuesCountAndScore(List<Paper> paperList) {
-        if (paperList == null || paperList.size() == 0) {
-            return;
-        }
-        for (Paper paper : paperList) {
-            initQuesCountAndScore(paper);
-            Map<String, Integer> quesCount = paper.getQuesCount();
-            Map<String, Double> quesScore = paper.getQuesScore();
-            List<PaperDetailUnit> units = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
-            if (units != null && units.size() > 0) {
-                for (PaperDetailUnit unit : units) {
-                    if (unit.getQuestion().getPublicity() == null) {
-                        unit.getQuestion().setPublicity(true);
-                    }
-                    if (unit.getQuestion().getDifficulty() == null) {
-                        unit.getQuestion().setDifficulty("中");
-                    }
-                    String key = getKey(unit.getQuestion().getPublicity(), unit.getQuestion().getDifficulty());
-                    quesCount.put(key, quesCount.get(key) + 1);
-                    quesScore.put(key, BigDecimal.valueOf(quesScore.get(key)).add(BigDecimal.valueOf(unit.getScore())).doubleValue());
-                }
-            }
-        }
-    }
-
-    private String getKey(Boolean publicity, String difficultyType) {
-        String difficulty = null;
-        if ("易".equals(difficultyType)) {
-            difficulty = "1";
-        } else if ("中".equals(difficultyType)) {
-            difficulty = "2";
-        } else {
-            difficulty = "3";
-        }
-        if (publicity == null || publicity) {
-            return "1-" + difficulty;
-        } else {
-            return "0-" + difficulty;
-        }
-    }
-
-    private void initQuesCountAndScore(Paper paper) {
-        Map<String, Integer> quesCount = new HashMap<>();
-        quesCount.put("0-1", 0);
-        quesCount.put("0-2", 0);
-        quesCount.put("0-3", 0);
-        quesCount.put("1-1", 0);
-        quesCount.put("1-2", 0);
-        quesCount.put("1-3", 0);
-        Map<String, Double> quesScore = new HashMap<>();
-        quesScore.put("0-1", 0.0);
-        quesScore.put("0-2", 0.0);
-        quesScore.put("0-3", 0.0);
-        quesScore.put("1-1", 0.0);
-        quesScore.put("1-2", 0.0);
-        quesScore.put("1-3", 0.0);
-        paper.setQuesCount(quesCount);
-        paper.setQuesScore(quesScore);
-    }
+    
 
 }

+ 1 - 0
examcloud-core-questions-starter/src/main/resources/application.properties

@@ -4,3 +4,4 @@ sys.config.center.address=192.168.10.39:8888
 sys.config.center.namespace=examcloud
 sys.config.center.appCode=Q
 sys.config.center.secretKey=
+spring.application.name=XT-EC-CORE-QUESTION