浏览代码

蓝图组卷功能提交

weiwenhai 7 年之前
父节点
当前提交
3cf344407f
共有 17 个文件被更改,包括 827 次插入567 次删除
  1. 135 108
      cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/web/GenPaperController.java
  2. 253 243
      cqb-paper/src/main/java/com/qmth/cqb/paper/dto/PaperExp.java
  3. 11 1
      cqb-paper/src/main/java/com/qmth/cqb/paper/model/Paper.java
  4. 78 20
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java
  5. 5 2
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperStructService.java
  6. 185 185
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/PaperDetailUnitServiceImpl.java
  7. 22 0
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/PaperServiceImpl.java
  8. 2 0
      cqb-question-resource/src/main/java/com/qmth/cqb/question/dao/CoursePropertyRepo.java
  9. 10 0
      cqb-question-resource/src/main/java/com/qmth/cqb/question/dto/CoursePropertyDto.java
  10. 11 0
      cqb-question-resource/src/main/java/com/qmth/cqb/question/model/CourseProperty.java
  11. 35 0
      cqb-question-resource/src/main/java/com/qmth/cqb/question/model/QuesProperty.java
  12. 7 0
      cqb-question-resource/src/main/java/com/qmth/cqb/question/service/CoursePropertyService.java
  13. 14 0
      cqb-question-resource/src/main/java/com/qmth/cqb/question/service/PropertyService.java
  14. 10 7
      cqb-question-resource/src/main/java/com/qmth/cqb/question/service/impl/CoursePropertyServiceImpl.java
  15. 12 0
      cqb-question-resource/src/main/java/com/qmth/cqb/question/service/impl/PropertyServiceImpl.java
  16. 13 1
      cqb-question-resource/src/main/java/com/qmth/cqb/question/web/CoursePropertyController.java
  17. 24 0
      cqb-question-resource/src/main/java/com/qmth/cqb/question/web/PropertyController.java

+ 135 - 108
cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/web/GenPaperController.java

@@ -1,108 +1,135 @@
-package com.qmth.cqb.genpaper.web;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import com.qmth.cqb.genpaper.model.GenPaperDto;
-import com.qmth.cqb.genpaper.service.GenPaperService;
-import com.qmth.cqb.utils.enums.RandomGenPaperPolicy;
-
-import cn.com.qmth.examcloud.common.uac.annotation.Uac;
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
-import cn.com.qmth.examcloud.common.uac.enums.RoleMeta;
-import cn.com.qmth.examcloud.common.uac.enums.UacPolicy;
-import io.swagger.annotations.ApiOperation;
-
-/**
- * Created by songyue on 16/12/28.
- */
-@RestController
-@RequestMapping("${api_cqb}/")
-public class GenPaperController {
-
-    @Autowired
-    GenPaperService genPaperService;
-
-    @ApiOperation(value = "简易随机组卷", notes = "简易随机组卷")
-    @Uac(roles={RoleMeta.QUESTION_ADMIN,RoleMeta.SUPER_ADMIN},policy=UacPolicy.IN)
-    @PostMapping("/genPaper/simple")
-    public ResponseEntity genPaperSimple(HttpServletRequest request, @RequestBody GenPaperDto genPaperDto) {
-        AccessUser user = (AccessUser) request.getAttribute("accessUser");
-        genPaperDto.setOrgId(user.getRootOrgId().toString());
-        genPaperDto.setCreator(user.getName());
-        Map<String, Object> paperMap = new HashMap<String, Object>();
-        String paperName = genPaperDto.getPaperName();
-        if (genPaperDto.getGenNumber() == 1) {
-            if (genPaperDto.getSimpleGenPaperPolicy().getKey() == 1L) {
-                paperMap = genPaperService.genPaperByQuestionNum(genPaperDto);
-            } else if (genPaperDto.getSimpleGenPaperPolicy().getKey() == 2L) {
-                paperMap = genPaperService.genPaperByScore(genPaperDto);
-            }
-        } else if (genPaperDto.getGenNumber() > 1) {
-            if (genPaperDto.getSimpleGenPaperPolicy() == RandomGenPaperPolicy.BY_QUESTIONNUM) {
-                for (int i = 1; i <= genPaperDto.getGenNumber(); i++) {
-                    genPaperDto.setPaperName(paperName + "_" + i);
-                    paperMap.putAll(genPaperService.genPaperByQuestionNum(genPaperDto));
-                    if (!paperMap.get("msg").equals("success")) {
-                        break;
-                    }
-                }
-
-            } else if (genPaperDto.getSimpleGenPaperPolicy() == RandomGenPaperPolicy.BY_SCORE) {
-                for (int i = 1; i <= genPaperDto.getGenNumber(); i++) {
-                    genPaperDto.setPaperName(paperName + "_" + i);
-                    paperMap.putAll(genPaperService.genPaperByScore(genPaperDto));
-                    if (!paperMap.get("msg").equals("success")) {
-                        break;
-                    }
-                }
-
-            }
-
-        }
-        if (paperMap.get("msg").equals("success")) {
-            return new ResponseEntity(paperMap, HttpStatus.OK);
-        } else {
-            return new ResponseEntity(paperMap, HttpStatus.INTERNAL_SERVER_ERROR);
-        }
-
-    }
-
-    @ApiOperation(value = "精细组卷", notes = "精细组卷")
-    @Uac(roles={RoleMeta.QUESTION_ADMIN,RoleMeta.SUPER_ADMIN},policy=UacPolicy.IN)
-    @PostMapping("/genPaper/normal")
-    public ResponseEntity genPaperNormal(HttpServletRequest request, @RequestBody GenPaperDto genPaperDto) {
-        AccessUser user = (AccessUser) request.getAttribute("accessUser");
-        genPaperDto.setOrgId(user.getRootOrgId().toString());
-        genPaperDto.setCreator(user.getName());
-        Map<String, Object> paperMap = new HashMap<String, Object>();
-        String paperName = genPaperDto.getPaperName();
-        if (genPaperDto.getGenNumber() > 1) {
-            for (int i = 1; i <= genPaperDto.getGenNumber(); i++) {
-                genPaperDto.setPaperName(paperName + "_" + i);
-                paperMap.putAll(genPaperService.genPaper(genPaperDto));
-                if (!paperMap.get("msg").equals("success")) {
-                    break;
-                }
-            }
-        } else if (genPaperDto.getGenNumber() == 1) {
-            paperMap = genPaperService.genPaper(genPaperDto);
-        }
-        if (paperMap.get("msg").equals("success")) {
-            return new ResponseEntity(paperMap, HttpStatus.OK);
-        } else {
-            return new ResponseEntity(paperMap, HttpStatus.INTERNAL_SERVER_ERROR);
-        }
-    }
-
-}
+package com.qmth.cqb.genpaper.web;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.qmth.cqb.genpaper.model.GenPaperDto;
+import com.qmth.cqb.genpaper.service.GenPaperService;
+import com.qmth.cqb.utils.enums.RandomGenPaperPolicy;
+
+import cn.com.qmth.examcloud.common.uac.annotation.Uac;
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
+import cn.com.qmth.examcloud.common.uac.enums.RoleMeta;
+import cn.com.qmth.examcloud.common.uac.enums.UacPolicy;
+import io.swagger.annotations.ApiOperation;
+
+/**
+ * Created by songyue on 16/12/28.
+ */
+@RestController
+@RequestMapping("${api_cqb}/")
+public class GenPaperController {
+
+    @Autowired
+    GenPaperService genPaperService;
+
+    @ApiOperation(value = "简易随机组卷", notes = "简易随机组卷")
+    @Uac(roles={RoleMeta.QUESTION_ADMIN,RoleMeta.SUPER_ADMIN},policy=UacPolicy.IN)
+    @PostMapping("/genPaper/simple")
+    public ResponseEntity genPaperSimple(HttpServletRequest request, @RequestBody GenPaperDto genPaperDto) {
+        AccessUser user = (AccessUser) request.getAttribute("accessUser");
+        genPaperDto.setOrgId(user.getRootOrgId().toString());
+        genPaperDto.setCreator(user.getName());
+        Map<String, Object> paperMap = new HashMap<String, Object>();
+        String paperName = genPaperDto.getPaperName();
+        if (genPaperDto.getGenNumber() == 1) {
+            if (genPaperDto.getSimpleGenPaperPolicy().getKey() == 1L) {
+                paperMap = genPaperService.genPaperByQuestionNum(genPaperDto);
+            } else if (genPaperDto.getSimpleGenPaperPolicy().getKey() == 2L) {
+                paperMap = genPaperService.genPaperByScore(genPaperDto);
+            }
+        } else if (genPaperDto.getGenNumber() > 1) {
+            if (genPaperDto.getSimpleGenPaperPolicy() == RandomGenPaperPolicy.BY_QUESTIONNUM) {
+                for (int i = 1; i <= genPaperDto.getGenNumber(); i++) {
+                    genPaperDto.setPaperName(paperName + "_" + i);
+                    paperMap.putAll(genPaperService.genPaperByQuestionNum(genPaperDto));
+                    if (!paperMap.get("msg").equals("success")) {
+                        break;
+                    }
+                }
+
+            } else if (genPaperDto.getSimpleGenPaperPolicy() == RandomGenPaperPolicy.BY_SCORE) {
+                for (int i = 1; i <= genPaperDto.getGenNumber(); i++) {
+                    genPaperDto.setPaperName(paperName + "_" + i);
+                    paperMap.putAll(genPaperService.genPaperByScore(genPaperDto));
+                    if (!paperMap.get("msg").equals("success")) {
+                        break;
+                    }
+                }
+
+            }
+
+        }
+        if (paperMap.get("msg").equals("success")) {
+            return new ResponseEntity(paperMap, HttpStatus.OK);
+        } else {
+            return new ResponseEntity(paperMap, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+
+    }
+
+    @ApiOperation(value = "精细组卷", notes = "精细组卷")
+    @Uac(roles={RoleMeta.QUESTION_ADMIN,RoleMeta.SUPER_ADMIN},policy=UacPolicy.IN)
+    @PostMapping("/genPaper/normal")
+    public ResponseEntity genPaperNormal(HttpServletRequest request, @RequestBody GenPaperDto genPaperDto) {
+        AccessUser user = (AccessUser) request.getAttribute("accessUser");
+        genPaperDto.setOrgId(user.getRootOrgId().toString());
+        genPaperDto.setCreator(user.getName());
+        Map<String, Object> paperMap = new HashMap<String, Object>();
+        String paperName = genPaperDto.getPaperName();
+        if (genPaperDto.getGenNumber() > 1) {
+            for (int i = 1; i <= genPaperDto.getGenNumber(); i++) {
+                genPaperDto.setPaperName(paperName + "_" + i);
+                paperMap.putAll(genPaperService.genPaper(genPaperDto));
+                if (!paperMap.get("msg").equals("success")) {
+                    break;
+                }
+            }
+        } else if (genPaperDto.getGenNumber() == 1) {
+            paperMap = genPaperService.genPaper(genPaperDto);
+        }
+        if (paperMap.get("msg").equals("success")) {
+            return new ResponseEntity(paperMap, HttpStatus.OK);
+        } else {
+            return new ResponseEntity(paperMap, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+    
+    @ApiOperation(value = "蓝图组卷", notes = "蓝图组卷")
+    @Uac(roles={RoleMeta.QUESTION_ADMIN,RoleMeta.SUPER_ADMIN},policy=UacPolicy.IN)
+    @PostMapping("/genPaper/blue")
+    public ResponseEntity genPaperBlue(HttpServletRequest request, @RequestBody GenPaperDto genPaperDto) {
+        AccessUser user = (AccessUser) request.getAttribute("accessUser");
+        genPaperDto.setOrgId(user.getRootOrgId().toString());
+        genPaperDto.setCreator(user.getName());
+        Map<String, Object> paperMap = new HashMap<String, Object>();
+        String paperName = genPaperDto.getPaperName();
+        if (genPaperDto.getGenNumber() > 1) {
+            for (int i = 1; i <= genPaperDto.getGenNumber(); i++) {
+                genPaperDto.setPaperName(paperName + "_" + i);
+                paperMap.putAll(genPaperService.genBluePaper(genPaperDto));
+                if (!paperMap.get("msg").equals("success")) {
+                    break;
+                }
+            }
+        } else if (genPaperDto.getGenNumber() == 1) {
+            paperMap = genPaperService.genBluePaper(genPaperDto);
+        }
+        if (paperMap.get("msg").equals("success")) {
+            return new ResponseEntity(paperMap, HttpStatus.OK);
+        } else {
+            return new ResponseEntity(paperMap, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+}

+ 253 - 243
cqb-paper/src/main/java/com/qmth/cqb/paper/dto/PaperExp.java

@@ -1,243 +1,253 @@
-package com.qmth.cqb.paper.dto;
-
-import com.qmth.cqb.base.model.Course;
-import com.qmth.cqb.utils.enums.PaperStatus;
-import com.qmth.cqb.utils.enums.PaperType;
-
-import java.io.Serializable;
-import java.util.*;
-
-/**
- * 试卷导出dto
- * Created by songyue on 17/3/15.
- */
-public class PaperExp implements Serializable{
-    private static final long serialVersionUID = -4673013279766466337L;
-
-    private String id;
-
-    private String name;//试卷名称
-
-    private String title;//试卷标题
-
-    private String subTitle;//试卷子标题
-
-    private Double totalScore;//试卷总分
-
-    private PaperStatus paperStatus;//试卷状态(待审核、通过、不通过)
-
-    private PaperType paperType;//试卷类型(导入、组卷)
-
-    private String courseNo;
-
-    private String courseName;
-    
-    private Course course;
-
-    private List<PaperDetailExp> paperDetails;
-
-    private Map<String,String> params;//导入试卷属性
-    
-    /**
-     * 客观题
-     */
-    private List<PaperDetailExp> objectiveDetails;
-    /**
-     * 主观题
-     */
-    private List<PaperDetailExp> subjectiveDetails;
-    
-    /**
-     * 客观题标题
-     */
-    private String objectiveTitle;
-    
-    /**
-     * 主观题标题
-     */
-    private String subjectiveTitle;
-    
-    private Double objectiveScore;
-    
-    private Double subjectiveScore;
-
-    private String courseLevel;
-
-    /**
-     * 不参与持久化,只做查询显示使用
-     * 是否包含音频题
-     */
-    private Boolean hasAudio;
-    
-    public static long getSerialVersionUID() {
-        return serialVersionUID;
-    }
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getTitle() {
-        return title;
-    }
-
-    public void setTitle(String title) {
-        this.title = title;
-    }
-
-    public Double getTotalScore() {
-        return totalScore;
-    }
-
-    public void setTotalScore(Double totalScore) {
-        this.totalScore = totalScore;
-    }
-
-    public PaperStatus getPaperStatus() {
-        return paperStatus;
-    }
-
-    public void setPaperStatus(PaperStatus paperStatus) {
-        this.paperStatus = paperStatus;
-    }
-
-    public PaperType getPaperType() {
-        return paperType;
-    }
-
-    public void setPaperType(PaperType paperType) {
-        this.paperType = paperType;
-    }
-
-    public String getCourseNo() {
-        return courseNo;
-    }
-
-    public void setCourseNo(String courseNo) {
-        this.courseNo = courseNo;
-    }
-
-    public String getCourseName() {
-        return courseName;
-    }
-
-    public void setCourseName(String courseName) {
-        this.courseName = courseName;
-    }
-
-    public List<PaperDetailExp> getPaperDetails() {
-        return paperDetails;
-    }
-
-    public void setPaperDetails(List<PaperDetailExp> paperDetails) {
-        this.paperDetails = paperDetails;
-    }
-
-    public Map<String, String> getParams() {
-        return params;
-    }
-
-    public void setParams(Map<String, String> params) {
-        this.params = params;
-    }
-
-    public String getSubTitle() {
-        return subTitle;
-    }
-
-    public void setSubTitle(String subTitle) {
-        this.subTitle = subTitle;
-    }
-
-    /**
-     * 得到客观题
-     * @return
-     */
-	public List<PaperDetailExp> getObjectiveDetails() {
-		return objectiveDetails;
-	}
-
-	public void setObjectiveDetails(List<PaperDetailExp> objectiveDetails) {
-		this.objectiveDetails = objectiveDetails;
-	}
-	 /**
-     * 得到主观题
-     * @return
-     */
-	public List<PaperDetailExp> getSubjectiveDetails() {
-		return subjectiveDetails;
-	}
-
-	public void setSubjectiveDetails(List<PaperDetailExp> subjectiveDetails) {
-		this.subjectiveDetails = subjectiveDetails;
-	}
-
-	public Double getObjectiveScore() {
-		return objectiveScore;
-	}
-
-	public void setObjectiveScore(Double objectiveScore) {
-		this.objectiveScore = objectiveScore;
-	}
-
-	public Double getSubjectiveScore() {
-		return subjectiveScore;
-	}
-
-	public void setSubjectiveScore(Double subjectiveScore) {
-		this.subjectiveScore = subjectiveScore;
-	}
-
-	public String getCourseLevel() {
-		return courseLevel;
-	}
-
-	public void setCourseLevel(String courseLevel) {
-		this.courseLevel = courseLevel;
-	}
-
-	public Course getCourse() {
-		return course;
-	}
-
-	public void setCourse(Course course) {
-		this.course = course;
-	}
-
-	public Boolean getHasAudio() {
-		return hasAudio;
-	}
-
-	public void setHasAudio(Boolean hasAudio) {
-		this.hasAudio = hasAudio;
-	}
-
-	public String getObjectiveTitle() {
-		return objectiveTitle;
-	}
-
-	public void setObjectiveTitle(String objectiveTitle) {
-		this.objectiveTitle = objectiveTitle;
-	}
-
-	public String getSubjectiveTitle() {
-		return subjectiveTitle;
-	}
-
-	public void setSubjectiveTitle(String subjectiveTitle) {
-		this.subjectiveTitle = subjectiveTitle;
-	}
-    
-}
+package com.qmth.cqb.paper.dto;
+
+import com.qmth.cqb.base.model.Course;
+import com.qmth.cqb.utils.enums.PaperStatus;
+import com.qmth.cqb.utils.enums.PaperType;
+
+import java.io.Serializable;
+import java.util.*;
+
+/**
+ * 试卷导出dto
+ * Created by songyue on 17/3/15.
+ */
+public class PaperExp implements Serializable{
+    private static final long serialVersionUID = -4673013279766466337L;
+
+    private String id;
+
+    private String name;//试卷名称
+
+    private String title;//试卷标题
+
+    private String subTitle;//试卷子标题
+
+    private Double totalScore;//试卷总分
+
+    private PaperStatus paperStatus;//试卷状态(待审核、通过、不通过)
+
+    private PaperType paperType;//试卷类型(导入、组卷)
+
+    private String courseNo;
+
+    private String courseName;
+    
+    private Course course;
+
+    private List<PaperDetailExp> paperDetails;
+
+    private Map<String,String> params;//导入试卷属性
+    
+    /**
+     * 客观题
+     */
+    private List<PaperDetailExp> objectiveDetails;
+    /**
+     * 主观题
+     */
+    private List<PaperDetailExp> subjectiveDetails;
+    
+    /**
+     * 客观题标题
+     */
+    private String objectiveTitle;
+    
+    /**
+     * 主观题标题
+     */
+    private String subjectiveTitle;
+    
+    private Double objectiveScore;
+    
+    private Double subjectiveScore;
+
+    private String courseLevel;
+
+    /**
+     * 不参与持久化,只做查询显示使用
+     * 是否包含音频题
+     */
+    private Boolean hasAudio;
+    
+    private Double difficultyDegree ; //难度系数
+    
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public Double getTotalScore() {
+        return totalScore;
+    }
+
+    public void setTotalScore(Double totalScore) {
+        this.totalScore = totalScore;
+    }
+
+    public PaperStatus getPaperStatus() {
+        return paperStatus;
+    }
+
+    public void setPaperStatus(PaperStatus paperStatus) {
+        this.paperStatus = paperStatus;
+    }
+
+    public PaperType getPaperType() {
+        return paperType;
+    }
+
+    public void setPaperType(PaperType paperType) {
+        this.paperType = paperType;
+    }
+
+    public String getCourseNo() {
+        return courseNo;
+    }
+
+    public void setCourseNo(String courseNo) {
+        this.courseNo = courseNo;
+    }
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
+
+    public List<PaperDetailExp> getPaperDetails() {
+        return paperDetails;
+    }
+
+    public void setPaperDetails(List<PaperDetailExp> paperDetails) {
+        this.paperDetails = paperDetails;
+    }
+
+    public Map<String, String> getParams() {
+        return params;
+    }
+
+    public void setParams(Map<String, String> params) {
+        this.params = params;
+    }
+
+    public String getSubTitle() {
+        return subTitle;
+    }
+
+    public void setSubTitle(String subTitle) {
+        this.subTitle = subTitle;
+    }
+
+    /**
+     * 得到客观题
+     * @return
+     */
+	public List<PaperDetailExp> getObjectiveDetails() {
+		return objectiveDetails;
+	}
+
+	public void setObjectiveDetails(List<PaperDetailExp> objectiveDetails) {
+		this.objectiveDetails = objectiveDetails;
+	}
+	 /**
+     * 得到主观题
+     * @return
+     */
+	public List<PaperDetailExp> getSubjectiveDetails() {
+		return subjectiveDetails;
+	}
+
+	public void setSubjectiveDetails(List<PaperDetailExp> subjectiveDetails) {
+		this.subjectiveDetails = subjectiveDetails;
+	}
+
+	public Double getObjectiveScore() {
+		return objectiveScore;
+	}
+
+	public void setObjectiveScore(Double objectiveScore) {
+		this.objectiveScore = objectiveScore;
+	}
+
+	public Double getSubjectiveScore() {
+		return subjectiveScore;
+	}
+
+	public void setSubjectiveScore(Double subjectiveScore) {
+		this.subjectiveScore = subjectiveScore;
+	}
+
+	public String getCourseLevel() {
+		return courseLevel;
+	}
+
+	public void setCourseLevel(String courseLevel) {
+		this.courseLevel = courseLevel;
+	}
+
+	public Course getCourse() {
+		return course;
+	}
+
+	public void setCourse(Course course) {
+		this.course = course;
+	}
+
+	public Boolean getHasAudio() {
+		return hasAudio;
+	}
+
+	public void setHasAudio(Boolean hasAudio) {
+		this.hasAudio = hasAudio;
+	}
+
+	public String getObjectiveTitle() {
+		return objectiveTitle;
+	}
+
+	public void setObjectiveTitle(String objectiveTitle) {
+		this.objectiveTitle = objectiveTitle;
+	}
+
+	public String getSubjectiveTitle() {
+		return subjectiveTitle;
+	}
+
+	public void setSubjectiveTitle(String subjectiveTitle) {
+		this.subjectiveTitle = subjectiveTitle;
+	}
+
+	public Double getDifficultyDegree() {
+		return difficultyDegree;
+	}
+
+	public void setDifficultyDegree(Double difficultyDegree) {
+		this.difficultyDegree = difficultyDegree;
+	}
+    
+}

+ 11 - 1
cqb-paper/src/main/java/com/qmth/cqb/paper/model/Paper.java

@@ -66,6 +66,8 @@ public class Paper implements Serializable {
     private Map<String, String> params;// 导入试卷属性
     
     private Specialty specialty;
+    
+    private Double difficultyDegree ; //难度系数
 
     public static long getSerialVersionUID() {
         return serialVersionUID;
@@ -234,5 +236,13 @@ public class Paper implements Serializable {
 	public void setSpecialty(Specialty specialty) {
 		this.specialty = specialty;
 	}
-    
+
+	public Double getDifficultyDegree() {
+		return difficultyDegree;
+	}
+
+	public void setDifficultyDegree(Double difficultyDegree) {
+		this.difficultyDegree = difficultyDegree;
+	}
+	
 }

+ 78 - 20
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java

@@ -3,14 +3,18 @@ package com.qmth.cqb.paper.service;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.OutputStream;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.UUID;
 import java.util.regex.Pattern;
 
+import com.netflix.infix.lang.infix.antlr.EventFilterParser.null_predicate_return;
 import com.qmth.cqb.base.dao.CourseRepo;
 import com.qmth.cqb.base.model.Course;
 import com.qmth.cqb.question.dao.CoursePropertyRepo;
@@ -735,14 +739,14 @@ public class ImportPaperService {
             else if (tmpText.startsWith(ImportPaperMsg.difficulty)) {
             	// 检测到难度开始段落  difficultyDegree
             	String dif = getContent(tmpText, ImportPaperMsg.difficulty);
-            	checkDiffculty(difficulty,dif,importPaperCheck,subQuesNum,question);
+            	difficulty = checkDiffculty(difficulty,dif,importPaperCheck,subQuesNum,question);
             	question.setDifficultyDegree(difficulty);
             	answerStart = false;
 			}
             else if (tmpText.startsWith(ImportPaperMsg.publicity)) {
             	// 检测到公安度开始段落
             	String pub = getContent(tmpText, ImportPaperMsg.publicity);
-            	checkPublicity(publicity,pub,importPaperCheck,subQuesNum);
+            	publicity = checkPublicity(publicity,pub,importPaperCheck,subQuesNum);
             	question.setPublicity(publicity);
             	answerStart = false;
 			}
@@ -766,14 +770,14 @@ public class ImportPaperService {
         }
 
         // 设置预设分数
-        if (quesScore.matches("^\\d+(\\.\\d+)?$")) {
+        if (quesScore != null && quesScore.matches("^\\d+(\\.\\d+)?$")) {
             question.setScore(Double.parseDouble(quesScore));
         }
         // 一般大题明细需要设置分数
-        if (!isNested && quesScore.matches("^\\d+(\\.\\d+)?$")) {
+        if (!isNested && quesScore != null && quesScore.matches("^\\d+(\\.\\d+)?$")) {
             paperDetailUnit.setScore(Double.parseDouble(quesScore));
         }
-        //校验小题尾信息是否含有"一节属性","二级属性","难度","公开"
+    	//校验小题尾信息是否含有"一节属性","二级属性","难度","公开"
         checkAttributeIsFull(firstProperty,secondProperty,difficulty,publicity,importPaperCheck,subQuesNum);
         //试题一级属性与二级属性校验
         checkProperty(firstProperty,secondProperty,importPaperCheck,subQuesNum,paper,quesProperties);
@@ -800,7 +804,11 @@ public class ImportPaperService {
 		//一级属性,二级属性都有值
 		else if(StringUtils.isNotBlank(firstProperty) && StringUtils.isNotBlank(secondProperty)){
 			//根据课程查询所有课程属性树
-			List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseId(Long.parseLong(paper.getCourse().getId()));
+			List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseCode(paper.getCourse().getCode());
+			if(courseProperties == null || courseProperties.size()<1){
+				importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,没有设置课程属性结构,请先设置课程属性结构");
+	    		throw new PaperException(importPaperCheck.errorInfo);
+			}
 			for(CourseProperty courseProperty:courseProperties){
 				Property propertyParent = new Property(firstProperty,0l,courseProperty.getId());
 				//查询一级属性是否存在
@@ -816,6 +824,8 @@ public class ImportPaperService {
 							for(Property proSon:propertieSons){
 								//保存一级和二级属性
 								QuesProperty quesProperty = new QuesProperty(proParent, proSon,courseProperty);
+								String idNumber = quesProperty.getCoursePropertyName() + "-" + quesProperty.getFirstProperty().getId() + "-" + quesProperty.getSecondProperty().getId();
+								quesProperty.setId(idNumber);
 								quesProperties.add(quesProperty);
 							}
 						}else{
@@ -832,7 +842,11 @@ public class ImportPaperService {
 		//一级属性有值,二级属性为空
 		else {
 			//根据课程查询所有课程属性树
-			List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseId(Long.parseLong(paper.getCourse().getId()));
+			List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseCode(paper.getCourse().getCode());
+			if(courseProperties == null || courseProperties.size()<1){
+				importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,没有设置课程属性结构,请先设置课程属性结构");
+	    		throw new PaperException(importPaperCheck.errorInfo);
+			}
 			for(CourseProperty courseProperty:courseProperties){
 				//查询一级属性
 				Property propertyParent = new Property(firstProperty,0l,courseProperty.getId());
@@ -849,6 +863,8 @@ public class ImportPaperService {
 						}else {
 							//保存试题属性
 							QuesProperty quesProperty = new QuesProperty(proParent, null,courseProperty);
+							String idNumber = quesProperty.getCoursePropertyName() + "-" + quesProperty.getFirstProperty().getId();
+							quesProperty.setId(idNumber);
 							quesProperties.add(quesProperty);
 						}
 					}
@@ -947,6 +963,7 @@ public class ImportPaperService {
                     throw new PaperException(importPaperCheck.errorInfo);
                 }
                 subQues = new Question();
+                subQues.setId(UUID.randomUUID().toString());
                 subQues.setQuestionType(getQuesStructType(nestedQuesType));
                 if (StringUtils.isNumeric(importPaperCheck.getQuesScore())) {
                     subQues.setScore(Double.parseDouble(importPaperCheck.getQuesScore()));
@@ -984,6 +1001,8 @@ public class ImportPaperService {
             }
         }
         question.setSubQuestions(subQuesList);
+        // 设置套题主题干的 难度,公开度,一级属性,二级属性
+        setAttributes(question,subQuesList);
         // 计算套题总分
         double totalScore = 0;
         List<Double> scoreList = new ArrayList<>();
@@ -1000,7 +1019,41 @@ public class ImportPaperService {
         paperDetailUnit.setSubScoreList(scoreList);
     }
 
-    /**
+    // 设置套题主题干的 难度,公开度,一级属性,二级属性
+    private void setAttributes(Question question,List<Question> subQuesList) {
+    	if(subQuesList != null && subQuesList.size()>0){
+    		Double sum = 0.0;
+    		Boolean publicity = false;
+    		List<QuesProperty> subQuesProperties = new ArrayList<QuesProperty>();
+    		for(Question subQuestion:subQuesList){
+    			//设置一级属性,二级属性
+    			List<QuesProperty> quesProperties = subQuestion.getQuesProperties();
+    			if(quesProperties!=null && quesProperties.size()>0){
+    				for(QuesProperty quesProperty:quesProperties){
+    					subQuesProperties.add(quesProperty);
+    				}
+    			}
+    			//设置公开度
+    			if(subQuestion.getPublicity()){
+    				publicity = true;
+    			}
+    			sum = subQuestion.getDifficultyDegree() + sum;
+    		}
+    		BigDecimal b = new BigDecimal(sum / (subQuesList.size()));  
+			Double difficulty = b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
+			//给属性去重
+			Set<QuesProperty> ts = new HashSet<QuesProperty>();
+			ts.addAll(subQuesProperties);
+			subQuesProperties.clear();
+			subQuesProperties.addAll(ts);
+			question.setDifficultyDegree(difficulty);
+			question.setPublicity(publicity);
+			question.setQuesProperties(subQuesProperties);
+			question.setDifficulty(setDiff(difficulty));
+    	}
+	}
+
+	/**
      * 获取试题类型
      *
      * @param quesType
@@ -1059,7 +1112,6 @@ public class ImportPaperService {
 
     /**
      * 获取课程代码
-     *
      * @param importPaperCheck
      * @return
      */
@@ -1235,7 +1287,7 @@ public class ImportPaperService {
      * @param subQuesNum
      * @throws Exception
      */
-    private void checkDiffculty(Double difficulty,String tmpText,ImportPaperCheck importPaperCheck,int subQuesNum,Question question)throws Exception{
+    private Double checkDiffculty(Double difficulty,String tmpText,ImportPaperCheck importPaperCheck,int subQuesNum,Question question)throws Exception{
     	if(StringUtils.isBlank(tmpText)){
     		//如果为空,默认难度0.5
     		difficulty = 0.5;
@@ -1245,14 +1297,19 @@ public class ImportPaperService {
     		importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,试题难度只能是1到10之间整数");
     		throw new PaperException(importPaperCheck.errorInfo);
     	}else {
-    		difficulty = Double.parseDouble(tmpText)%10;
-    		if(difficulty>0 && difficulty<0.4){
-    			question.setDifficulty("易");
-    		}else if (difficulty>0.3 && difficulty<0.8) {
-    			question.setDifficulty("中");
-			}else {
-				question.setDifficulty("难");
-			}
+    		difficulty = Double.parseDouble(tmpText)/10;
+    		question.setDifficulty(setDiff(difficulty));
+		}
+    	return difficulty;
+    }
+    
+    private String setDiff(Double difficulty){
+    	if(difficulty>0 && difficulty<0.4){
+			return"难";
+		}else if (difficulty>0.3 && difficulty<0.8) {
+			return"中";
+		}else {
+			return"易";
 		}
     }
     
@@ -1264,11 +1321,11 @@ public class ImportPaperService {
     * @param subQuesNum
     * @throws Exception
     */
-    private void checkPublicity(Boolean publicity,String tmpText,ImportPaperCheck importPaperCheck,int subQuesNum)throws Exception{
+    private Boolean checkPublicity(Boolean publicity,String tmpText,ImportPaperCheck importPaperCheck,int subQuesNum)throws Exception{
     	if(StringUtils.isBlank(tmpText)){
     		//如果为空,默认是公开
     		publicity = true;
-    	}else if(!tmpText.equals("公开") || !tmpText.equals("非公开")){
+    	}else if(!tmpText.equals("公开") && !tmpText.equals("非公开")){
     		//如果不是公开和非公开,就报错
     		importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,试题公开度只能是公开和非公开");
     		throw new PaperException(importPaperCheck.errorInfo);
@@ -1279,6 +1336,7 @@ public class ImportPaperService {
     			publicity = true;
 			}
 		}
+    	return publicity;
     }
 
     /**

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

@@ -1,5 +1,6 @@
 package com.qmth.cqb.paper.service;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -176,7 +177,7 @@ public class PaperStructService {
                 List<PaperDetailUnitStruct> unitStructs = new ArrayList<PaperDetailUnitStruct>();
                 for(CoursePropertyNumberDto coursePropertyNumberDto:paperDetailStruct.getCoursePropertyNumberDtos()){
                 	//取到子节点上的题目
-                	if(coursePropertyNumberDto.getDisable()){
+                	if(!coursePropertyNumberDto.getDisable()){
                 		//公开简单数量
                     	for(int i=0;i<coursePropertyNumberDto.getPublicSimple();i++){
                     		++number;
@@ -265,7 +266,9 @@ public class PaperStructService {
 				mediumCount = paperDetailStruct.getPublicMediumCount() + paperDetailStruct.getNoPublicMediumCount();
 				difficultyCount = paperDetailStruct.getPublicDifficultyCount() + paperDetailStruct.getNoPublicDifficultyCount();
 			}
-			Double difficulty = ((simpleCount * 0.8) + (mediumCount * 0.5) + (difficultyCount * 0.2))/(simpleCount + mediumCount + difficultyCount);
+			Double dif = ((simpleCount * 0.8) + (mediumCount * 0.5) + (difficultyCount * 0.2))/(simpleCount + mediumCount + difficultyCount);
+			BigDecimal b = new BigDecimal(dif);  
+			Double difficulty = b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();  
 			return difficulty;
 		}
 		return (double)0;

+ 185 - 185
cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/PaperDetailUnitServiceImpl.java

@@ -1,185 +1,185 @@
-package com.qmth.cqb.paper.service.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Sort;
-import org.springframework.data.domain.Sort.Direction;
-import org.springframework.data.domain.Sort.Order;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.data.mongodb.core.query.Criteria;
-import org.springframework.data.mongodb.core.query.Query;
-import org.springframework.stereotype.Service;
-
-import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
-
-import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
-import com.qmth.cqb.paper.dto.PaperDetailUnitExp;
-import com.qmth.cqb.paper.model.Paper;
-import com.qmth.cqb.paper.model.PaperDetail;
-import com.qmth.cqb.paper.model.PaperDetailUnit;
-import com.qmth.cqb.paper.service.PaperDetailUnitService;
-import com.qmth.cqb.paper.service.PaperService;
-import com.qmth.cqb.question.model.Question;
-import com.qmth.cqb.question.service.QuesService;
-import com.qmth.cqb.utils.enums.PaperType;
-
-/**
- * @author  	chenken
- * @date    	2017年9月13日 上午11:29:56
- * @company 	QMTH
- * @description PaperDetailUnitServiceImpl.java
- */
-@Service("paperDetailUnitService")
-public class PaperDetailUnitServiceImpl implements PaperDetailUnitService{
-
-    @Autowired
-    PaperDetailUnitRepo paperDetailUnitRepo;
-
-    @Autowired
-    QuesService quesService;
-
-    @Autowired
-    PaperService paperService;
-    
-    @Autowired
-    MongoTemplate mongoTemplate;
-
-    /**
-     * 根据Id获得对应的试题对象
-     *
-     * @param id
-     * @return
-     */
-    public Question getQuestionByPaperDetailUnitId(String id) {
-        return paperDetailUnitRepo.findOne(id).getQuestion();
-    }
-
-    /**
-     * 按ID查询小题
-     *
-     * @param id
-     * @return
-     */
-    public PaperDetailUnit findById(String id) {
-        return paperDetailUnitRepo.findOne(id);
-    }
-
-    /**
-     * 保存小题
-     *
-     * @param pduExp
-     * @return
-     */
-    public PaperDetailUnit savePaperDetailUnit(PaperDetailUnitExp pduExp, AccessUser user) {
-        PaperDetailUnit oldPdu = paperDetailUnitRepo.findOne(pduExp.getId());
-        if (oldPdu.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
-            if (pduExp.getQuestion().getId().equals(oldPdu.getQuestion().getId())) {
-                // 更新对象为套题本身
-                oldPdu.setQuestion(quesService.saveQues(pduExp.getQuestion()));
-            } else {
-                List<Double> subScoreList = oldPdu.getSubScoreList();
-                int size = oldPdu.getQuestion().getSubQuestions().size();
-                boolean match = false;
-                // 判断更新的对象是哪个子题
-                for (int index = 1; index <= size; index++) {
-                    // 检查子题分数,确保没有错误数据
-                    if (subScoreList.size() < index) {
-                        subScoreList.add(0d);
-                    }
-                    Question sub = oldPdu.getQuestion().getSubQuestions().get(index - 1);
-                    if (pduExp.getQuestion().getId().equals(sub.getId())) {
-                        // 匹配到子题
-                        subScoreList.set(index - 1, pduExp.getScore());
-                        oldPdu.getQuestion().getSubQuestions().set(index - 1, pduExp.getQuestion());
-                        match = true;
-                    }
-                }
-                if (match) {
-                    oldPdu.setQuestion(quesService.saveQues(oldPdu.getQuestion()));
-                }
-                // 更新套题unit当前总分与子题分数
-                oldPdu.setSubScoreList(subScoreList);
-            }
-        } else {
-            oldPdu.setQuestion(quesService.saveQues(pduExp.getQuestion()));
-            oldPdu.setScore(pduExp.getScore());
-        }
-        // 同时要跟新小题里面的Qustion对象
-        oldPdu = paperDetailUnitRepo.save(oldPdu);
-        paperService.formatPaper(oldPdu.getPaper(), user);
-        return oldPdu;
-    }
-
-    /**
-     * 删除小题
-     *
-     * @param id
-     * @return
-     */
-    public void deletePaperDetailUnit(String id, AccessUser user) {
-        Paper paper = paperDetailUnitRepo.findOne(id).getPaper();
-        paperDetailUnitRepo.delete(id);
-        paperService.formatPaper(paper, user);
-    }
-
-    /**
-     * 根据大题查小题
-     *
-     * @param paperDetail
-     * @return
-     */
-    public List<PaperDetailUnit> getUnitsByPaperDetail(PaperDetail paperDetail) {
-        return paperDetailUnitRepo.findByPaperDetailOrderByNumber(paperDetail);
-    }
-
-    /**
-     * 根据大题集合删除小题
-     *
-     * @param paperDetails
-     */
-    public void deleteUnitsByPaperDetails(List<PaperDetail> paperDetails) {
-        List<PaperDetailUnit> units = new ArrayList<PaperDetailUnit>();
-        for (PaperDetail pd : paperDetails) {
-            units.addAll(getUnitsByPaperDetail(pd));
-        }
-        paperDetailUnitRepo.delete(units);
-    }
-    
-    public List<PaperDetailUnit> findByQuestionAndPaperTypes(Question question,List<PaperType> paperTypes){
-    	Query query = new Query();
-    	query.addCriteria(Criteria.where("paperType").in(paperTypes));
-    	query.addCriteria(Criteria.where("question").is(question));
-    	return this.mongoTemplate.find(query, PaperDetailUnit.class);
-    }
-    
-    /**
-     * 查询大题下的小题
-     * 按number升序或降序排列,取第一个
-     * @return
-     */
-    public PaperDetailUnit findTopOrderByNumber(PaperDetail paperDetail,String orderType){
-    	if("ASC".equals(orderType)){
-    		return paperDetailUnitRepo.findTopByPaperDetailOrderByNumberAsc(paperDetail);
-    	}else if("DESC".equals(orderType)){
-    		return paperDetailUnitRepo.findTopByPaperDetailOrderByNumberDesc(paperDetail);
-    	}
-		return null;
-    }
-    
-    /**
-     * 按试卷 查询 小题,并将小题按number,createTime排序
-     * @param paper
-     * @return
-     */
-    public List<PaperDetailUnit> findByPaperAndSort(Paper paper){
-    	Query query = new Query();
-    	query.addCriteria(Criteria.where("paper").is(paper));
-    	query.with(new Sort(new Order(Direction.ASC,"number")));
-    	query.with(new Sort(new Order(Direction.ASC,"createTime")));
-    	return this.mongoTemplate.find(query, PaperDetailUnit.class);
-    }
-}
-
+package com.qmth.cqb.paper.service.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
+import org.springframework.data.domain.Sort.Order;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
+
+import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
+import com.qmth.cqb.paper.dto.PaperDetailUnitExp;
+import com.qmth.cqb.paper.model.Paper;
+import com.qmth.cqb.paper.model.PaperDetail;
+import com.qmth.cqb.paper.model.PaperDetailUnit;
+import com.qmth.cqb.paper.service.PaperDetailUnitService;
+import com.qmth.cqb.paper.service.PaperService;
+import com.qmth.cqb.question.model.Question;
+import com.qmth.cqb.question.service.QuesService;
+import com.qmth.cqb.utils.enums.PaperType;
+
+/**
+ * @author  	chenken
+ * @date    	2017年9月13日 上午11:29:56
+ * @company 	QMTH
+ * @description PaperDetailUnitServiceImpl.java
+ */
+@Service("paperDetailUnitService")
+public class PaperDetailUnitServiceImpl implements PaperDetailUnitService{
+
+    @Autowired
+    PaperDetailUnitRepo paperDetailUnitRepo;
+
+    @Autowired
+    QuesService quesService;
+
+    @Autowired
+    PaperService paperService;
+    
+    @Autowired
+    MongoTemplate mongoTemplate;
+
+    /**
+     * 根据Id获得对应的试题对象
+     *
+     * @param id
+     * @return
+     */
+    public Question getQuestionByPaperDetailUnitId(String id) {
+        return paperDetailUnitRepo.findOne(id).getQuestion();
+    }
+
+    /**
+     * 按ID查询小题
+     *
+     * @param id
+     * @return
+     */
+    public PaperDetailUnit findById(String id) {
+        return paperDetailUnitRepo.findOne(id);
+    }
+
+    /**
+     * 保存小题
+     *
+     * @param pduExp
+     * @return
+     */
+    public PaperDetailUnit savePaperDetailUnit(PaperDetailUnitExp pduExp, AccessUser user) {
+        PaperDetailUnit oldPdu = paperDetailUnitRepo.findOne(pduExp.getId());
+        if (oldPdu.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
+            if (pduExp.getQuestion().getId().equals(oldPdu.getQuestion().getId())) {
+                // 更新对象为套题本身
+                oldPdu.setQuestion(quesService.saveQues(pduExp.getQuestion()));
+            } else {
+                List<Double> subScoreList = oldPdu.getSubScoreList();
+                int size = oldPdu.getQuestion().getSubQuestions().size();
+                boolean match = false;
+                // 判断更新的对象是哪个子题
+                for (int index = 1; index <= size; index++) {
+                    // 检查子题分数,确保没有错误数据
+                    if (subScoreList.size() < index) {
+                        subScoreList.add(0d);
+                    }
+                    Question sub = oldPdu.getQuestion().getSubQuestions().get(index - 1);
+                    if (pduExp.getQuestion().getId().equals(sub.getId())) {
+                        // 匹配到子题
+                        subScoreList.set(index - 1, pduExp.getScore());
+                        oldPdu.getQuestion().getSubQuestions().set(index - 1, pduExp.getQuestion());
+                        match = true;
+                    }
+                }
+                if (match) {
+                    oldPdu.setQuestion(quesService.saveQues(oldPdu.getQuestion()));
+                }
+                // 更新套题unit当前总分与子题分数
+                oldPdu.setSubScoreList(subScoreList);
+            }
+        } else {
+            oldPdu.setQuestion(quesService.saveQues(pduExp.getQuestion()));
+            oldPdu.setScore(pduExp.getScore());
+        }
+        // 同时要跟新小题里面的Qustion对象
+        oldPdu = paperDetailUnitRepo.save(oldPdu);
+        paperService.formatPaper(oldPdu.getPaper(), user);
+        return oldPdu;
+    }
+
+    /**
+     * 删除小题
+     *
+     * @param id
+     * @return
+     */
+    public void deletePaperDetailUnit(String id, AccessUser user) {
+        Paper paper = paperDetailUnitRepo.findOne(id).getPaper();
+        paperDetailUnitRepo.delete(id);
+        paperService.formatPaper(paper, user);
+    }
+
+    /**
+     * 根据大题查小题
+     *
+     * @param paperDetail
+     * @return
+     */
+    public List<PaperDetailUnit> getUnitsByPaperDetail(PaperDetail paperDetail) {
+        return paperDetailUnitRepo.findByPaperDetailOrderByNumber(paperDetail);
+    }
+
+    /**
+     * 根据大题集合删除小题
+     *
+     * @param paperDetails
+     */
+    public void deleteUnitsByPaperDetails(List<PaperDetail> paperDetails) {
+        List<PaperDetailUnit> units = new ArrayList<PaperDetailUnit>();
+        for (PaperDetail pd : paperDetails) {
+            units.addAll(getUnitsByPaperDetail(pd));
+        }
+        paperDetailUnitRepo.delete(units);
+    }
+    
+    public List<PaperDetailUnit> findByQuestionAndPaperTypes(Question question,List<PaperType> paperTypes){
+    	Query query = new Query();
+    	query.addCriteria(Criteria.where("paperType").in(paperTypes));
+    	query.addCriteria(Criteria.where("question").is(question));
+    	return this.mongoTemplate.find(query, PaperDetailUnit.class);
+    }
+    
+    /**
+     * 查询大题下的小题
+     * 按number升序或降序排列,取第一个
+     * @return
+     */
+    public PaperDetailUnit findTopOrderByNumber(PaperDetail paperDetail,String orderType){
+    	if("ASC".equals(orderType)){
+    		return paperDetailUnitRepo.findTopByPaperDetailOrderByNumberAsc(paperDetail);
+    	}else if("DESC".equals(orderType)){
+    		return paperDetailUnitRepo.findTopByPaperDetailOrderByNumberDesc(paperDetail);
+    	}
+		return null;
+    }
+    
+    /**
+     * 按试卷 查询 小题,并将小题按number,createTime排序
+     * @param paper
+     * @return
+     */
+    public List<PaperDetailUnit> findByPaperAndSort(Paper paper){
+    	Query query = new Query();
+    	query.addCriteria(Criteria.where("paper").is(paper));
+    	query.with(new Sort(new Order(Direction.ASC,"number")));
+    	query.with(new Sort(new Order(Direction.ASC,"createTime")));
+    	return this.mongoTemplate.find(query, PaperDetailUnit.class);
+    }
+}
+

+ 22 - 0
cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/PaperServiceImpl.java

@@ -4,6 +4,7 @@ import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
@@ -605,10 +606,31 @@ public class PaperServiceImpl implements PaperService{
      */
     public void formatPaper(Paper paper, AccessUser user) {
         double paperTotalScore = reSetPaperDetailUnit(paper);
+        paper.setDifficultyDegree(reSetDifficulty(paper,paperTotalScore));
         Map<String,Object> paperInfoMap = reSetPaperDetail(paper);
         reSetPaper(paper,user,paperInfoMap,paperTotalScore);
     }
     
+	private Double reSetDifficulty(Paper paper,double paperTotalScore) {
+		Double sum = 0.0;
+		List<PaperDetail> paperDetails = paperDetailRepo.findByPaperOrderByNumber(paper);
+		if(paperDetails != null && paperDetails.size()>0){
+			for(PaperDetail paperDetail:paperDetails){
+				//获取每个大题下面的所有小题
+				List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetailOrderByNumber(paperDetail);
+				if(paperDetailUnits!=null && paperDetailUnits.size()>0){
+					for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
+						sum = paperDetailUnit.getScore() * paperDetailUnit.getQuestion().getDifficultyDegree() + sum;
+					}
+				}
+			}
+			BigDecimal b = new BigDecimal(sum / paperTotalScore);  
+			Double difficulty = b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
+			return difficulty;
+		}
+		return 0.0;
+	}
+
 	/**
      * 重新设置小题number,并返回试卷总分
      * @param paper

+ 2 - 0
cqb-question-resource/src/main/java/com/qmth/cqb/question/dao/CoursePropertyRepo.java

@@ -22,5 +22,7 @@ public interface CoursePropertyRepo extends JpaRepository<CourseProperty, Long>,
 	
 	//根据课程id查询
 	List<CourseProperty> findByCourseId(Long courseId);
+	
+	List<CourseProperty> findByCourseCode(String code);
 
 }

+ 10 - 0
cqb-question-resource/src/main/java/com/qmth/cqb/question/dto/CoursePropertyDto.java

@@ -16,6 +16,8 @@ public class CoursePropertyDto {
 	private Long orgId;
 	
 	private String enable;
+	
+	private String courseCode;
 
 	public Long getId() {
 		return id;
@@ -56,5 +58,13 @@ public class CoursePropertyDto {
 	public void setEnable(String enable) {
 		this.enable = enable;
 	}
+
+	public String getCourseCode() {
+		return courseCode;
+	}
+
+	public void setCourseCode(String courseCode) {
+		this.courseCode = courseCode;
+	}
 	
 }

+ 11 - 0
cqb-question-resource/src/main/java/com/qmth/cqb/question/model/CourseProperty.java

@@ -34,6 +34,8 @@ public class CourseProperty implements Serializable{
 	@NotNull
 	private Long orgId;
 	
+	private String courseCode;
+	
 	private Boolean enable;
 
 	public CourseProperty(){}
@@ -43,6 +45,7 @@ public class CourseProperty implements Serializable{
 		this.name = coursePropertyDto.getName();
 		this.courseId = coursePropertyDto.getCourseId();
 		this.orgId = coursePropertyDto.getOrgId();
+		this.courseCode = coursePropertyDto.getCourseCode();
 		if(coursePropertyDto.getEnable() != null && coursePropertyDto.getEnable().equals("0")){
 			this.enable = false;
 		}else if(coursePropertyDto.getEnable() != null && coursePropertyDto.getEnable().equals("1")){
@@ -95,5 +98,13 @@ public class CourseProperty implements Serializable{
 	public void setEnable(Boolean enable) {
 		this.enable = enable;
 	}
+
+	public String getCourseCode() {
+		return courseCode;
+	}
+
+	public void setCourseCode(String courseCode) {
+		this.courseCode = courseCode;
+	}
 	
 }

+ 35 - 0
cqb-question-resource/src/main/java/com/qmth/cqb/question/model/QuesProperty.java

@@ -7,6 +7,8 @@ public class QuesProperty implements Serializable{
 
 	private static final long serialVersionUID = -2303143377325064933L;
 	
+	private String id;
+	
 	private String coursePropertyName;//课程属性名
 
 	private Property firstProperty;//一级属性
@@ -23,6 +25,14 @@ public class QuesProperty implements Serializable{
 		this.coursePropertyName = courseProperty.getName();
 	}
 
+	public String getId() {
+		return id;
+	}
+
+	public void setId(String id) {
+		this.id = id;
+	}
+
 	public Property getFirstProperty() {
 		return firstProperty;
 	}
@@ -50,5 +60,30 @@ public class QuesProperty implements Serializable{
 	public void setCoursePropertyName(String coursePropertyName) {
 		this.coursePropertyName = coursePropertyName;
 	}
+
+	@Override
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((id == null) ? 0 : id.hashCode());
+		return result;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj)
+			return true;
+		if (obj == null)
+			return false;
+		if (getClass() != obj.getClass())
+			return false;
+		QuesProperty other = (QuesProperty) obj;
+		if (id == null) {
+			if (other.id != null)
+				return false;
+		} else if (!id.equals(other.id))
+			return false;
+		return true;
+	}
 	
 }

+ 7 - 0
cqb-question-resource/src/main/java/com/qmth/cqb/question/service/CoursePropertyService.java

@@ -56,4 +56,11 @@ public interface CoursePropertyService {
 	 * @return
 	 */
 	public List<CourseProperty> findAllByCourseId(Long courseId);
+	
+	/**
+	 * 根据课程code查询所有课程属性
+	 * @param courseId
+	 * @return
+	 */
+	public List<CourseProperty> findAllByCourseCode(String code);
 }

+ 14 - 0
cqb-question-resource/src/main/java/com/qmth/cqb/question/service/PropertyService.java

@@ -55,4 +55,18 @@ public interface PropertyService {
 	 * @return
 	 */
 	public List<Property> findPropertySons(Property property);
+	
+	/**
+	 * 查询某个树下的子节点
+	 * @param property
+	 * @return
+	 */
+	public List<Property> findPropertySons(Long propertyId);
+	
+	/**
+	 * 查询课程属性下面的所有父节点
+	 * @param property
+	 * @return
+	 */
+	public List<Property> findPropertyParents(Long coursePropertyId, AccessUser user);
 }

+ 10 - 7
cqb-question-resource/src/main/java/com/qmth/cqb/question/service/impl/CoursePropertyServiceImpl.java

@@ -14,12 +14,6 @@ import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
-
-
-
-
-
-
 import com.qmth.cqb.question.dao.CoursePropertyRepo;
 import com.qmth.cqb.question.dto.CoursePropertyDto;
 import com.qmth.cqb.question.model.CourseProperty;
@@ -80,7 +74,7 @@ public class CoursePropertyServiceImpl implements CoursePropertyService{
 		};
 		return specification;
 	}
-
+	
 	@Override
 	public void openCourseProperty(Long id, Long orgId) {
 		CourseProperty courseProperty = coursePropertyRepo.findOne(id);
@@ -100,4 +94,13 @@ public class CoursePropertyServiceImpl implements CoursePropertyService{
 		List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseId(courseId);
 		return courseProperties;
 	}
+
+	@Override
+	public List<CourseProperty> findAllByCourseCode(String code) {
+		List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseCode(code);
+		return courseProperties;
+	}
+
+	
+	
 }

+ 12 - 0
cqb-question-resource/src/main/java/com/qmth/cqb/question/service/impl/PropertyServiceImpl.java

@@ -119,4 +119,16 @@ public class PropertyServiceImpl implements PropertyService{
 		return properySonsList;
 	}
 
+	@Override
+	public List<Property> findPropertySons(Long propertyId) {
+		List<Property> properySonsList = propertyRepo.findByParentIdOrderByNumber(propertyId);
+		return properySonsList;
+	}
+
+	@Override
+	public List<Property> findPropertyParents(Long coursePropertyId, AccessUser user) {
+		List<Property> properties = propertyRepo.findByOrgIdAndCoursePropertyIdAndParentIdOrderByNumber(user.getRootOrgId(), coursePropertyId, 0l);
+		return properties;
+	}
+
 }

+ 13 - 1
cqb-question-resource/src/main/java/com/qmth/cqb/question/web/CoursePropertyController.java

@@ -11,6 +11,7 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
@@ -63,7 +64,7 @@ public class CoursePropertyController {
 			 return new ResponseEntity(HttpStatus.NOT_FOUND);
 		 }
 		 coursePropertyDto.setOrgId(accessUser.getRootOrgId());
-		 Page<CourseProperty> coursePropertiesPage = coursePropertyService.findAllByOrg(coursePropertyDto, new PageRequest(curPage - 1,pageSize));
+		 Page<CourseProperty> coursePropertiesPage = coursePropertyService.findAllByOrg(coursePropertyDto, new PageRequest(curPage - 1,pageSize,new Sort(Direction.DESC, "id")));
 		 return new ResponseEntity<Object>(coursePropertiesPage,HttpStatus.OK);
 	}
 	
@@ -115,4 +116,15 @@ public class CoursePropertyController {
 		}
 		return new ResponseEntity<Object>(HttpStatus.NOT_FOUND);
 	}
+	
+	@ApiOperation(value="根据courseCode查询所有课程属性", notes="不带分页")
+	@GetMapping(value="/courseProperty/code/{courseCode}")
+	public ResponseEntity<Object> findAllByCourseCode(HttpServletRequest request,@PathVariable String courseCode){
+		AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
+		if(accessUser != null){
+			List<CourseProperty> courseProperties = coursePropertyService.findAllByCourseCode(courseCode);
+			return new ResponseEntity<Object>(courseProperties,HttpStatus.OK);
+		}
+		return new ResponseEntity<Object>(HttpStatus.NOT_FOUND);
+	}
 }

+ 24 - 0
cqb-question-resource/src/main/java/com/qmth/cqb/question/web/PropertyController.java

@@ -1,11 +1,13 @@
 package com.qmth.cqb.question.web;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
 
 import io.swagger.annotations.ApiOperation;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -90,4 +92,26 @@ public class PropertyController {
 		}
 		return new ResponseEntity<Object>(HttpStatus.NOT_FOUND);
 	}
+	
+	@ApiOperation(value="根据一级查询二级所有属性", notes="查询所有属性")
+	@GetMapping(value="/property/second/{propertyId}")
+	public ResponseEntity<Object> findSons(HttpServletRequest request, @PathVariable Long propertyId){
+		AccessUser accessUser = (AccessUser)request.getAttribute("accessUser");
+		if(accessUser != null){
+			List<Property> properties = propertyService.findPropertySons(propertyId);
+			return new ResponseEntity<Object>(properties,HttpStatus.OK);
+		}
+		return new ResponseEntity<Object>(HttpStatus.NOT_FOUND);
+	}
+	
+	@ApiOperation(value="根据课程属性id所有一级属性", notes="查询所有属性")
+	@GetMapping(value="/property/first/{coursePropertyId}")
+	public ResponseEntity<Object> findParents(HttpServletRequest request, @PathVariable Long coursePropertyId){
+		AccessUser accessUser = (AccessUser)request.getAttribute("accessUser");
+		if(accessUser != null){
+			List<Property> properties = propertyService.findPropertyParents(coursePropertyId, accessUser);
+			return new ResponseEntity<Object>(properties,HttpStatus.OK);
+		}
+		return new ResponseEntity<Object>(HttpStatus.NOT_FOUND);
+	}
 }