Jelajahi Sumber

修改试卷结构,修复精细组卷bug

宋悦 8 tahun lalu
induk
melakukan
5bf4f0ad5a

+ 9 - 15
cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/service/GenPaperService.java

@@ -1,13 +1,6 @@
 package com.qmth.cqb.genpaper.service;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
+import java.util.*;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -105,8 +98,10 @@ public class GenPaperService {
         for (DetailContext dc : detailContexts) {
             List<PaperDetailUnit> unitsTemp = new ArrayList<PaperDetailUnit>();
             List<UnitContext> units = dc.getUnits();
-            for (UnitContext uc : units) {
-                for (Question ques : quesSet) {
+            Iterator iterator = quesSet.iterator();
+            while(iterator.hasNext()) {
+                for (UnitContext uc : units) {
+                    Question ques = (Question) iterator.next();
                     if (uc.getUnitStruct().getQuestionType() == ques.getQuestionType()) {
                         PaperDetailUnit pdu = new PaperDetailUnit();
                         pdu.setCreateTime(CommonUtils.getCurDateTime());
@@ -114,6 +109,7 @@ public class GenPaperService {
                         pdu.setQuestionType(ques.getQuestionType());
                         pdu.setScore(uc.getUnitStruct().getScore());
                         unitsTemp.add(pdu);
+                        iterator.remove();
                     }
 
                 }
@@ -287,9 +283,8 @@ public class GenPaperService {
     /**
      * 随机构造试卷,根据小题类型 没有定义试卷结构
      * 
-     * @param units
-     * @param number
-     * @param quesName
+     * @param selectedUnits
+     * @param genPaperDto
      * @return
      */
     public Paper constuctPaper(List<PaperDetailUnit> selectedUnits, GenPaperDto genPaperDto) {
@@ -348,8 +343,7 @@ public class GenPaperService {
 
     /**
      * 获取所试题数量
-     * 
-     * @param units小题集合
+     * @param units
      * @return
      */
     public int getTotalQuesNum(List<PaperDetailUnit> units) {

+ 67 - 0
cqb-paper/src/main/java/com/qmth/cqb/paper/dto/PaperDetailUnitStructDto.java

@@ -0,0 +1,67 @@
+package com.qmth.cqb.paper.dto;
+
+import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
+
+import java.io.Serializable;
+
+/**
+ * Created by songyue on 17/3/21.
+ */
+public class PaperDetailUnitStructDto implements Serializable {
+
+    private static final long serialVersionUID = -3766822545462183904L;
+
+    private String id;
+
+    private Integer count;
+
+    private Double score;//小题分数
+
+    private Double totalScore;
+
+    private QuesStructType questionType;//小题类型
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public Integer getCount() {
+        return count;
+    }
+
+    public void setCount(Integer count) {
+        this.count = count;
+    }
+
+    public Double getScore() {
+        return score;
+    }
+
+    public void setScore(Double score) {
+        this.score = score;
+    }
+
+    public Double getTotalScore() {
+        return totalScore;
+    }
+
+    public void setTotalScore(Double totalScore) {
+        this.totalScore = totalScore;
+    }
+
+    public QuesStructType getQuestionType() {
+        return questionType;
+    }
+
+    public void setQuestionType(QuesStructType questionType) {
+        this.questionType = questionType;
+    }
+}

+ 18 - 6
cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetailStruct.java

@@ -1,5 +1,7 @@
 package com.qmth.cqb.paper.model;
 
+import com.qmth.cqb.paper.dto.PaperDetailUnitStructDto;
+
 import java.io.Serializable;
 import java.util.Map;
 import java.util.List;
@@ -19,8 +21,10 @@ public class PaperDetailStruct implements Serializable{
 	
 	private String name;//大题名称
 	
-	private List<PaperDetailUnitStruct> paperDetailUnitStructs;//细分类型
-	
+	private List<PaperDetailUnitStruct> paperDetailUnitStructs;//小题明细
+
+	private List<PaperDetailUnitStructDto> unitStructs;//题目类型统计
+
 	private Double totalScore;//大题总分
 	
 	private Map params;//大题参数
@@ -29,6 +33,10 @@ public class PaperDetailStruct implements Serializable{
 
 	private Integer detailCount;
 
+	public static long getSerialVersionUID() {
+		return serialVersionUID;
+	}
+
 	public String getId() {
 		return id;
 	}
@@ -61,6 +69,14 @@ public class PaperDetailStruct implements Serializable{
 		this.paperDetailUnitStructs = paperDetailUnitStructs;
 	}
 
+	public List<PaperDetailUnitStructDto> getUnitStructs() {
+		return unitStructs;
+	}
+
+	public void setUnitStructs(List<PaperDetailUnitStructDto> unitStructs) {
+		this.unitStructs = unitStructs;
+	}
+
 	public Double getTotalScore() {
 		return totalScore;
 	}
@@ -77,10 +93,6 @@ public class PaperDetailStruct implements Serializable{
 		this.params = params;
 	}
 
-	public static long getSerialVersionUID() {
-		return serialVersionUID;
-	}
-
 	public String getRemark() {
 		return remark;
 	}

+ 9 - 19
cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetailUnitStruct.java

@@ -13,12 +13,10 @@ public class PaperDetailUnitStruct implements Serializable {
 
     private String id;
 
-    private Integer count;
+    private Integer number;
 
     private Double score;//小题分数
 
-    private Double totalScore;
-
     private QuesStructType questionType;//小题类型
 
     public static long getSerialVersionUID() {
@@ -33,6 +31,14 @@ public class PaperDetailUnitStruct implements Serializable {
         this.id = id;
     }
 
+    public Integer getNumber() {
+        return number;
+    }
+
+    public void setNumber(Integer number) {
+        this.number = number;
+    }
+
     public Double getScore() {
         return score;
     }
@@ -48,20 +54,4 @@ public class PaperDetailUnitStruct implements Serializable {
     public void setQuestionType(QuesStructType questionType) {
         this.questionType = questionType;
     }
-
-    public Integer getCount() {
-        return count;
-    }
-
-    public void setCount(Integer count) {
-        this.count = count;
-    }
-
-    public Double getTotalScore() {
-        return totalScore;
-    }
-
-    public void setTotalScore(Double totalScore) {
-        this.totalScore = totalScore;
-    }
 }

+ 37 - 2
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperStructService.java

@@ -1,7 +1,8 @@
 package com.qmth.cqb.paper.service;
 
 
-import com.qmth.cqb.paper.model.PaperStructSearchInfo;
+import com.qmth.cqb.paper.dto.PaperDetailUnitStructDto;
+import com.qmth.cqb.paper.model.*;
 import com.qmth.cqb.utils.BeanCopierUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -12,8 +13,8 @@ import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
 
 import com.qmth.cqb.paper.dao.PaperStructRepo;
-import com.qmth.cqb.paper.model.PaperStruct;
 
+import java.util.ArrayList;
 import java.util.List;
 /**
  * Created by songyue on 16/12/28.
@@ -57,5 +58,39 @@ public class PaperStructService {
         paperStruct.setCreateTime(null);
     }
 
+    /**
+     * 保存试卷结构
+     * @param paperStruct
+     * @return
+     */
+    public PaperStruct save(PaperStruct paperStruct){
+
+        List<PaperDetailStruct> paperDetailStructs = paperStruct.getPaperDetailStructs();
+        int number = 0;
+
+        for(PaperDetailStruct paperDetailStruct:paperDetailStructs){
+            List oldStructs = paperDetailStruct.getPaperDetailUnitStructs();
+            if(oldStructs != null && oldStructs.size() > 0){
+                oldStructs.clear();
+            }
+            List<PaperDetailUnitStruct> unitStructs = new ArrayList<PaperDetailUnitStruct>();
+
+            for(PaperDetailUnitStructDto unitStructDto:paperDetailStruct.getUnitStructs()){
+                for(int i = 0;i < unitStructDto.getCount();i++){
+                    ++number;
+                    PaperDetailUnitStruct unitStruct = new PaperDetailUnitStruct();
+                    unitStruct.setScore(unitStructDto.getScore());
+                    unitStruct.setId(String.valueOf(number));
+                    unitStruct.setNumber(number);
+                    unitStruct.setQuestionType(unitStructDto.getQuestionType());
+                    unitStructs.add(unitStruct);
+                }
+            }
+            paperDetailStruct.setPaperDetailUnitStructs(unitStructs);
+        }
+        paperStruct.setDetailCount(paperDetailStructs.size());
+        return paperStructRepo.save(paperStruct);
+    }
+
 
 }

+ 6 - 8
cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperStructController.java

@@ -61,7 +61,7 @@ public class PaperStructController {
      */
     @ApiOperation(value="获取试卷结构",notes="获取试卷结构")
     @GetMapping(value = "/paperStruct/{id}")
-    public ResponseEntity getPaperStructureById(@PathVariable String id){
+    public ResponseEntity getPaperStructById(@PathVariable String id){
         return new ResponseEntity(paperStructRepo.findOne(id),HttpStatus.OK);
     }
     
@@ -73,9 +73,8 @@ public class PaperStructController {
      */
     @ApiOperation(value="更新试卷结构",notes="更新试卷结构")
     @PutMapping(value = "/paperStruct")
-    public ResponseEntity updatePaperStructure(@RequestBody PaperStruct ps){
-        ps.setDetailCount(ps.getPaperDetailStructs().size());
-    	PaperStruct paperStruct = paperStructRepo.save(ps);
+    public ResponseEntity updatePaperStruct(@RequestBody PaperStruct ps){
+    	PaperStruct paperStruct = paperStructService.save(ps);
     	return new ResponseEntity(paperStruct,HttpStatus.OK);
     }
 
@@ -86,9 +85,8 @@ public class PaperStructController {
      */
     @ApiOperation(value="新增试卷结构",notes="新增试卷结构")
     @PostMapping(value = "/paperStruct")
-    public ResponseEntity addPaperStructure(@RequestBody PaperStruct ps){
-        ps.setDetailCount(ps.getPaperDetailStructs().size());
-    	PaperStruct paperStruct = paperStructRepo.save(ps);
+    public ResponseEntity addPaperStruct(@RequestBody PaperStruct ps){
+        PaperStruct paperStruct = paperStructService.save(ps);
     	return new ResponseEntity(paperStruct,HttpStatus.OK);
     }
 
@@ -99,7 +97,7 @@ public class PaperStructController {
      */
     @ApiOperation(value="删除试卷结构",notes="删除试卷结构")
     @DeleteMapping(value = "/paperStruct/{ids}")
-    public ResponseEntity removePaperStructure(@PathVariable String ids){
+    public ResponseEntity removePaperStruct(@PathVariable String ids){
         List<String> paperList = Stream.of(ids.split(",")).collect(Collectors.toList());
     	paperStructRepo.delete(paperStructRepo.findAll(paperList));
 		return new ResponseEntity(HttpStatus.OK);