Browse Source

Merge remote-tracking branch 'origin/dev0410' into dev1130

# Conflicts:
#	cqb-comm-utils/src/main/java/com/qmth/cqb/utils/enums/PaperStructType.java
#	cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/service/GenPaperService.java
#	cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperStructService.java
#	cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/ExportPaperServiceImpl.java
#	cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/PaperServiceImpl.java
#	cqb-paper/src/main/java/com/qmth/cqb/paper/web/PaperStructController.java
宋悦 7 years ago
parent
commit
5e37d2dd4c
23 changed files with 825 additions and 502 deletions
  1. 1 1
      cqb-comm-utils/pom.xml
  2. 152 8
      cqb-comm-utils/src/main/java/com/qmth/cqb/utils/CommonUtils.java
  3. 49 48
      cqb-comm-utils/src/main/java/com/qmth/cqb/utils/enums/PaperStructType.java
  4. 6 88
      cqb-comm-utils/src/main/java/com/qmth/cqb/utils/word/DocxProcessUtil.java
  5. 40 8
      cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/service/GenPaperService.java
  6. 60 5
      cqb-paper/src/main/java/com/qmth/cqb/paper/dto/ObjectiveQuestionStructure.java
  7. 42 4
      cqb-paper/src/main/java/com/qmth/cqb/paper/dto/SubjectiveQuestionStructure.java
  8. 6 2
      cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetailUnit.java
  9. 17 17
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/ExportPaperService.java
  10. 40 40
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/ExtractConfigFileService.java
  11. 12 4
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperStructService.java
  12. 86 34
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/ExportPaperAbstractService.java
  13. 2 11
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/InitPaperExpService.java
  14. 7 7
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/ExportPaperServiceImpl.java
  15. 36 21
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/ExtractConfigFileServiceImpl.java
  16. 4 0
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/ExtractConfigServiceImpl.java
  17. 126 114
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/PaperDetailServiceImpl.java
  18. 23 1
      cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/PaperServiceImpl.java
  19. 63 62
      cqb-paper/src/main/java/com/qmth/cqb/paper/web/ExportPaperController.java
  20. 8 6
      cqb-paper/src/main/java/com/qmth/cqb/paper/web/ExtractConfigController.java
  21. 14 17
      cqb-question-resource/src/main/java/com/qmth/cqb/question/service/impl/QuesServiceImpl.java
  22. 1 1
      cqb-starter/src/main/resources/application-dev.properties
  23. 30 3
      cqb-starter/src/main/resources/application-prac.properties

+ 1 - 1
cqb-comm-utils/pom.xml

@@ -201,7 +201,7 @@
             <artifactId>ansj_seg</artifactId>
             <version>5.1.1</version>
         </dependency>
-        
+
         <dependency>
 		  <groupId>com.upyun</groupId>
 		  <artifactId>java-sdk</artifactId>

+ 152 - 8
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/CommonUtils.java

@@ -1,8 +1,8 @@
 package com.qmth.cqb.utils;
 
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.*;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
@@ -13,6 +13,8 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Stream;
 
+import com.qmth.cqb.utils.word.DocxProcessUtil;
+import org.apache.commons.lang3.StringEscapeUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.dom4j.Attribute;
 import org.dom4j.Document;
@@ -21,6 +23,8 @@ import org.dom4j.DocumentHelper;
 import org.dom4j.Element;
 
 import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Created by songyue on 16/12/27.
@@ -36,6 +40,8 @@ public final class CommonUtils {
     public static final String PAPER_TITLE="中国石油大学";
     public static final String PAPER_SUB_TITLE="网络教育";
 
+    private static final Logger log = LoggerFactory.getLogger(CommonUtils.class);
+
     /**
      * 加载properties配置文件
      * 
@@ -50,7 +56,7 @@ public final class CommonUtils {
             BufferedReader bf = new BufferedReader(new InputStreamReader(inputStream));
             properties.load(bf);
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error("加载配置异常:",e.getMessage());
         }
         return properties;
     }
@@ -268,13 +274,151 @@ public final class CommonUtils {
 		}
 		return idValues;
     }
-    
 
-    public static void main(String[] args) {
+    /**
+     * 保留两位小数
+     * @param number
+     * @return
+     */
+    public static double formatDouble(double number){
+        BigDecimal formatNumber = new BigDecimal(number);
+        return formatNumber.setScale(2, RoundingMode.HALF_UP).doubleValue();
+    }
+
+    /**
+     * 向下取整,可以取0.5
+     * @param number
+     * @return
+     */
+    public static double formatDoubleFloor(double number){
+        BigDecimal formatNumber = new BigDecimal(number);
+        double floorNumber = formatNumber.setScale(0, RoundingMode.FLOOR).doubleValue();
+        if(number >= floorNumber && number < floorNumber + 0.5){
+            return floorNumber;
+        }else{
+            return floorNumber + 0.5;
+        }
+    }
+
+    /**
+     * 补全html标签
+     * @param htmlStr
+     * @return
+     * @throws Exception
+     */
+    public static String repairHtmlStr(String htmlStr)throws Exception{
+        htmlStr = htmlStr.trim();
+        if(htmlStr.toLowerCase().contains("<!doctype html ")){
+            int index1 = htmlStr.toLowerCase().indexOf("<!doctype html ");
+            int index2 = htmlStr.indexOf('>',index1 + 1);
+            htmlStr = htmlStr.substring(0, index1) + htmlStr.substring(index2 + 1);
+        }
+        while(htmlStr.toLowerCase().contains("<br ")){
+            int index1 = htmlStr.toLowerCase().indexOf("<br ");
+            int index2 = htmlStr.toLowerCase().indexOf(">",index1 + 1);
+            htmlStr = htmlStr.substring(0, index1) + "<br/>" + htmlStr.substring(index2 + 1);
+        }
+        while(htmlStr.toLowerCase().endsWith("<br>") || htmlStr.toLowerCase().endsWith("<br/>")){
+            if(htmlStr.toLowerCase().endsWith("<br>")){
+                htmlStr = htmlStr.substring(0, htmlStr.length()-"<br>".length());
+            }else if(htmlStr.toLowerCase().endsWith("<br/>")){
+                htmlStr = htmlStr.substring(0, htmlStr.length()-"<br/>".length());
+            }
+        }
+        htmlStr = htmlStr.replace("<br>", "<br/>").replace("<BR>", "<br/>");
+
+        {//补全META标签
+            int imgIndex = indexOfRegex(htmlStr,"<((meta)|(META)) ");
+            while(imgIndex > 0){
+                int flag = htmlStr.indexOf(">", imgIndex);
+                if(htmlStr.charAt(flag - 1) != '/'){
+                    htmlStr = htmlStr.substring(0,flag) + "/" + htmlStr.substring(flag);
+                }
+                imgIndex = indexOfRegex(htmlStr,"<((meta)|(META)) ",flag);
+            }
+        }
+
+        {//补全img标签
+            int imgIndex = indexOfRegex(htmlStr,"<((img)|(IMG)) ");
+            while(imgIndex > 0){
+                int flag = htmlStr.indexOf(">", imgIndex);
+                if(htmlStr.charAt(flag - 1) != '/'){
+                    htmlStr = htmlStr.substring(0,flag) + "/" + htmlStr.substring(flag);
+                }
+                imgIndex = indexOfRegex(htmlStr,"<((img)|(IMG)) ",flag);
+            }
+        }
+        //添加body标签
+        if((htmlStr.toLowerCase().contains("<p") || htmlStr.toLowerCase().contains("<span"))
+                && !htmlStr.toLowerCase().contains("<body")){
+            htmlStr = "<body>"+htmlStr+"</body>";
+        }
+        return new String(htmlStr.getBytes("UTF-8"));
+    }
+
+    /**
+     * 从指定的位置开始查找第一个匹配正则表达式的字符串的位置
+     * @param str
+     * @param regex 正则表达式
+     * @param fromIndex 指定的起始位置
+     * @return
+     */
+    public static int indexOfRegex(String str,String regex,int fromIndex){
+        int index = indexOfRegex(str.substring(fromIndex),regex);
+        if(index < 0){
+            return -1;
+        }
+        return fromIndex + index;
+    }
+
+    /**
+     * 查找第一个匹配正则表达式的字符串的位置
+     * @param str
+     * @param regex 正则表达式
+     * @return
+     */
+    public static int indexOfRegex(String str,String regex){
+        Pattern p = Pattern.compile(regex);
+        Matcher m = p.matcher(str);
+        if(m.find()){
+            return m.start();
+        }else{
+            return -1;
+        }
+    }
+
+    /**
+     * 格式化html
+     * @param htmlStr
+     * @return
+     * @throws Exception
+     */
+    public static String formatHtml(String htmlStr)throws Exception{
+        if(StringUtils.isEmpty(htmlStr)){
+            return "";
+        }
+        htmlStr = repairHtmlStr(htmlStr);
+        htmlStr = StringEscapeUtils.unescapeHtml4(htmlStr);
+        return htmlStr;
+    }
+
+    /**
+     * 过滤非空格的空字符
+     * @param str
+     * @return
+     */
+    public static String trimNoBlankSpace(final String str){
+        if(str == null || str.length() == 0){
+            return "";
+        }
+        return str.replaceAll("[\\t\\r\\f]*","");
+    }
+
+    public static void main(String[] args) throws Exception{
         // QuesStructType quesStructType = getEnum(QuesStructType.class,"单选");
         // System.out.println(quesStructType.getName());
         // System.out.println(characterToNumber("A"));
-        System.out.println(toCHNum(111111));
-
+        System.out.println(formatDoubleFloor(3.61));
+        System.out.println(formatDoubleFloor(3.0));
     }
 }

+ 49 - 48
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/enums/PaperStructType.java

@@ -1,48 +1,49 @@
-package com.qmth.cqb.utils.enums;
-
-import org.omg.CORBA.PRIVATE_MEMBER;
-
-/**
- * @describle 试卷结构类型
- * @author weiwenhai
- * @date  2017.12.11
- */
-public enum PaperStructType {
-	/**
-	 * 简易组卷
-	 */
-	SIMPLE("简易组卷"),
-
-	/**
-	 * 精确组卷
-	 */
-	EXACT("精确组卷"),
-	
-	/**
-	 * 蓝图组卷
-	 */
-	BLUEPRINT("蓝图组卷");
-	
-	private String name;
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-	
-	private PaperStructType(String name){
-		this.name = name;
-	}
-	
-	public static PaperStructType strToEnum(String str){
-    	for(PaperStructType paperStructType:PaperStructType.values()){
-    		if(paperStructType.name().equals(str)){
-    			return paperStructType;
-    		}
-    	}
-    	return null;
-    }
-}
+package com.qmth.cqb.utils.enums;
+
+import org.omg.CORBA.PRIVATE_MEMBER;
+
+/**
+ * @describle 试卷结构类型
+ * @author weiwenhai
+ * @date  2017.12.11
+ */
+public enum PaperStructType {
+
+	/**
+	 * 简易组卷
+	 */
+	SIMPLE("简易组卷"),
+
+	/**
+	 * 精确组卷
+	 */
+	EXACT("精确组卷"),
+	
+	/**
+	 * 蓝图组卷
+	 */
+	BLUEPRINT("蓝图组卷");
+	
+	private String name;
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+	
+	private PaperStructType(String name){
+		this.name = name;
+	}
+	
+	public static PaperStructType strToEnum(String str){
+    	for(PaperStructType paperStructType:PaperStructType.values()){
+    		if(paperStructType.name().equals(str)){
+    			return paperStructType;
+    		}
+    	}
+    	return null;
+    }
+}

+ 6 - 88
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/word/DocxProcessUtil.java

@@ -581,14 +581,8 @@ public final class DocxProcessUtil {
         namespaces.stream().forEach(namespace -> {
             root.remove(namespace);
         });
-        List<org.dom4j.Element> elements = root.elements();
-        elements.stream().forEach(element ->{
-        	if("w:bookmarkStart".equals(element.getQualifiedName())||
-                	"w:bookmarkEnd".equals(element.getQualifiedName())){
-        		root.remove(element);
-        	}
-        });
-        return root.asXML();
+        String returnXml = CommonUtils.trimNoBlankSpace(root.asXML());
+        return returnXml;
     }
 
     /**
@@ -900,93 +894,17 @@ public final class DocxProcessUtil {
         XHTMLImporter.setHyperlinkStyle("Hyperlink");
         String wordMl = "";
         wordMLPackage.getMainDocumentPart().getContent().addAll(
-                    XHTMLImporter.convert( repairHtmlStr(html), TEMP_FILE_IMP) );
+                    XHTMLImporter.convert(html, TEMP_FILE_IMP) );
+        //转换完后就初始化image
+        initPkgImage(wordMLPackage);
         // 获取word文档中所有段落
         List<Object> pList = getAllElementFromObject(wordMLPackage.getMainDocumentPart(), P.class);
         for(Object p:pList){
-            wordMl += XmlUtils.marshaltoString(p);
+            wordMl += formatPWordMl(XmlUtils.marshaltoString(p));
         }
-//            wordMl = formatPWordMl(wordMl);
-        initPkgImage(wordMLPackage);
         return wordMl;
     }
 
-    public static String repairHtmlStr(String htmlStr)throws Exception{
-        htmlStr = htmlStr.trim();
-        if(htmlStr.toLowerCase().contains("<!doctype html ")){
-            int index1 = htmlStr.toLowerCase().indexOf("<!doctype html ");
-            int index2 = htmlStr.indexOf('>',index1 + 1);
-            htmlStr = htmlStr.substring(0, index1) + htmlStr.substring(index2 + 1);
-        }
-        while(htmlStr.toLowerCase().contains("<br ")){
-            int index1 = htmlStr.toLowerCase().indexOf("<br ");
-            int index2 = htmlStr.toLowerCase().indexOf(">",index1 + 1);
-            htmlStr = htmlStr.substring(0, index1) + "<br/>" + htmlStr.substring(index2 + 1);
-        }
-        while(htmlStr.toLowerCase().endsWith("<br>") || htmlStr.toLowerCase().endsWith("<br/>")){
-            if(htmlStr.toLowerCase().endsWith("<br>")){
-                htmlStr = htmlStr.substring(0, htmlStr.length()-"<br>".length());
-            }else if(htmlStr.toLowerCase().endsWith("<br/>")){
-                htmlStr = htmlStr.substring(0, htmlStr.length()-"<br/>".length());
-            }
-        }
-        htmlStr = htmlStr.replace("<br>", "<br/>").replace("<BR>", "<br/>");
-
-        {//补全META标签
-            int imgIndex = indexOfRegex(htmlStr,"<((meta)|(META)) ");
-            while(imgIndex > 0){
-                int flag = htmlStr.indexOf(">", imgIndex);
-                if(htmlStr.charAt(flag - 1) != '/'){
-                    htmlStr = htmlStr.substring(0,flag) + "/" + htmlStr.substring(flag);
-                }
-                imgIndex = indexOfRegex(htmlStr,"<((meta)|(META)) ",flag);
-            }
-        }
-
-        {//补全img标签
-            int imgIndex = indexOfRegex(htmlStr,"<((img)|(IMG)) ");
-            while(imgIndex > 0){
-                int flag = htmlStr.indexOf(">", imgIndex);
-                if(htmlStr.charAt(flag - 1) != '/'){
-                    htmlStr = htmlStr.substring(0,flag) + "/" + htmlStr.substring(flag);
-                }
-                imgIndex = indexOfRegex(htmlStr,"<((img)|(IMG)) ",flag);
-            }
-        }
-        return new String(htmlStr.getBytes("UTF-8"));
-    }
-
-    /**
-     * 从指定的位置开始查找第一个匹配正则表达式的字符串的位置
-     * @param str
-     * @param regex 正则表达式
-     * @param fromIndex 指定的起始位置
-     * @return
-     */
-    public static int indexOfRegex(String str,String regex,int fromIndex){
-        int index = indexOfRegex(str.substring(fromIndex),regex);
-        if(index < 0){
-            return -1;
-        }
-        return fromIndex + index;
-    }
-
-    /**
-     * 查找第一个匹配正则表达式的字符串的位置
-     * @param str
-     * @param regex 正则表达式
-     * @return
-     */
-    public static int indexOfRegex(String str,String regex){
-        Pattern p = Pattern.compile(regex);
-        Matcher m = p.matcher(str);
-        if(m.find()){
-            return m.start();
-        }else{
-            return -1;
-        }
-    }
-
     public static byte[] getWordBytesByQuestion(WordprocessingMLPackage wordMLPackage, List<String> wordXmls) throws Exception {
         RelationshipsPart mainRelationshipsPart = wordMLPackage.getMainDocumentPart().getRelationshipsPart();
         // 获取总的资源文件存储

+ 40 - 8
cqb-gen-paper/src/main/java/com/qmth/cqb/genpaper/service/GenPaperService.java

@@ -1,5 +1,7 @@
 package com.qmth.cqb.genpaper.service;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -10,6 +12,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
+import com.qmth.cqb.utils.enums.PaperStructType;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -130,7 +133,7 @@ public class GenPaperService {
             paper.setUnitCount(this.getTotalQuesNum(paperDetailunits));
             paper.setPaperType(PaperType.GENERATE);
             // 数据入库
-            paper = this.persistentPaper(paperDetailunits, paperDetails, paper);
+            paper = this.persistentPaper(PaperStructType.EXACT,paperDetailunits, paperDetails, paper);
             msg = "success";
             paperMsgMap.put("paper", paper);
             paperMsgMap.put("msg", msg);
@@ -147,7 +150,9 @@ public class GenPaperService {
     private boolean checkQuesType(UnitContext uc,Question question){
         List<String> quesNames = uc.getUnitStruct().getQuesNames();
         if(quesNames != null && quesNames.size() > 0){
-            if(quesNames.contains(question.getQuesName()) && !uc.finish() && uc.getUnitStruct().getQuestionType().name().equals(question.getQuestionType().name())){
+            if(quesNames.contains(question.getQuesName())
+                    && !uc.finish()
+                    && (uc.getUnitStruct().getQuestionType() == question.getQuestionType())){
                 return true;
             }
         }
@@ -346,7 +351,7 @@ public class GenPaperService {
         }
         Paper paper = this.constuctPaperByPaperDetails(details, genPaperDto);
         paper.setUnitCount(this.getTotalQuesNum(saveUnits));// 设置小题数量,需统计subQuestion
-        paper = this.persistentPaper(saveUnits, details, paper);
+        paper = this.persistentPaper(PaperStructType.SIMPLE,saveUnits, details, paper);
         return paper;
 
     }
@@ -359,7 +364,10 @@ public class GenPaperService {
      * @param paper
      * @return
      */
-    public Paper persistentPaper(List<PaperDetailUnit> selectedUnits, List<PaperDetail> details, Paper paper) {
+    public Paper persistentPaper(PaperStructType paperStructType,
+                                 List<PaperDetailUnit> selectedUnits,
+                                 List<PaperDetail> details,
+                                 Paper paper) {
         paper = paperRepo.save(paper);
         for (PaperDetail pd : details) {
             pd.setPaper(paper);
@@ -378,6 +386,30 @@ public class GenPaperService {
         		index++;
         		PaperDetailUnit paperDetailUnit = paperDetailUnits.get(i);
         		paperDetailUnit.setNumber(index);
+
+                //重新计算套题小题分
+                if(paperStructType != PaperStructType.SIMPLE){
+                    Question question = paperDetailUnit.getQuestion();
+                    if(question != null && question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION){
+                        List<Question> subQuestions = question.getSubQuestions();
+                        List<Double> subScoreList = new ArrayList<>();
+                        if(subQuestions != null && subQuestions.size() > 0){
+                            int subQuesLen = subQuestions.size();
+                            double subTotalScore = paperDetailUnit.getScore();
+                            for(int j = 0;j < subQuesLen;j++){
+                                double avgScore = subTotalScore / subQuestions.size();
+                                //向下取整,包含0.5
+                                double formatScore = CommonUtils.formatDoubleFloor(avgScore);
+                                if(j == subQuesLen - 1){
+                                    subScoreList.add(subTotalScore - formatScore * j);
+                                }else{
+                                    subScoreList.add(formatScore);
+                                }
+                            }
+                            paperDetailUnit.setSubScoreListNew(subScoreList);
+                        }
+                    }
+                }
         	}
         	unitRepo.save(paperDetailUnits);
         }
@@ -457,7 +489,7 @@ public class GenPaperService {
         return chooseNestNum;
 
     }
-    
+
     /**
      * 蓝图组卷,根据设定试卷结构组卷
      * @param genPaperDto
@@ -556,13 +588,13 @@ public class GenPaperService {
     		for(QuesProperty quesProperty:quesProperties){
     			if(quesProperty.getSecondProperty() != null){
     				//有一级  和  二级
-    				propertyGroup = String.valueOf(quesProperty.getFirstProperty().getId()) + "-" + 
-								    String.valueOf(quesProperty.getSecondProperty().getId()) + "-" + 
+    				propertyGroup = String.valueOf(quesProperty.getFirstProperty().getId()) + "-" +
+								    String.valueOf(quesProperty.getSecondProperty().getId()) + "-" +
 								    String.valueOf(question.getPublicity()) + "-" + question.getDifficulty();
     				propertyGroups.add(propertyGroup);
     			}else {
     				//有一级  无  二级
-    				propertyGroup = String.valueOf(quesProperty.getFirstProperty().getId()) + "-" + 
+    				propertyGroup = String.valueOf(quesProperty.getFirstProperty().getId()) + "-" +
 							   		String.valueOf(question.getPublicity()) + "-" + question.getDifficulty();
     				propertyGroups.add(propertyGroup);
 				}

+ 60 - 5
cqb-paper/src/main/java/com/qmth/cqb/paper/dto/ObjectiveQuestionStructure.java

@@ -30,34 +30,73 @@ public class ObjectiveQuestionStructure implements Serializable{
 	 */
 	@ExcelProperty(name="课程名称",index = 1)
 	private String courseName;
+	
+	/**
+	 * 试卷名称
+	 */
+	@ExcelProperty(name="试卷名称",index = 2)
+	private String paperName;
+	
+	/**
+	 * 试卷类型
+	 */
+	@ExcelProperty(name="试卷类型",index = 3)
+	private String paperType;
 	/**
 	 * 大题号
 	 */
-	@ExcelProperty(name="大题号",index = 2)
+	@ExcelProperty(name="大题号",index = 4)
 	private Integer bigQuestionNo;
 	/**
 	 * 小题号
 	 */
-	@ExcelProperty(name="小题号",index = 3)
+	@ExcelProperty(name="小题号",index = 5)
 	private Integer smallQuestionNo;
 	/**
 	 * 题目类型
 	 */
-	@ExcelProperty(name="题目类型",index = 4)
+	@ExcelProperty(name="题目类型",index = 6)
 	private String questionType;
 	/**
 	 * 标准答案
 	 */
-	@ExcelProperty(name="标准答案",index = 5)
+	@ExcelProperty(name="标准答案",index = 7)
 	private String answer;
 	/**
 	 * 小题分数
 	 */
-	@ExcelProperty(name="小题分数",index = 6)
+	@ExcelProperty(name="小题分数",index = 8)
 	private Double smallQuestionScore;
 	
 	public ObjectiveQuestionStructure(){}
 	
+	public ObjectiveQuestionStructure(PaperExp paperExp,PaperDetailExp paperDetailExp,PaperDetailUnitExp unit,String paperType){
+		this.paperType = paperType;
+		this.paperName = paperExp.getName();
+		this.courseNo = paperExp.getCourseNo();
+		this.courseName = paperExp.getCourseName();
+		this.bigQuestionNo = paperDetailExp.getNumber();
+		this.questionType = unit.getQuestionType().getName();
+		this.smallQuestionNo = unit.getNumber();
+		this.smallQuestionScore = unit.getScore();
+		if(StringUtils.isNotBlank(unit.getQuestion().getQuesAnswer())){
+			if(unit.getQuestionType()==QuesStructType.BOOL_ANSWER_QUESTION){
+				if("正确".equals(unit.getQuestion().getQuesAnswer())){
+					this.answer = "A";
+				}else if("错误".equals(unit.getQuestion().getQuesAnswer())){
+					this.answer = "B";
+				}else if("#".equals(unit.getQuestion().getQuesAnswer())){
+					this.answer = "#";
+				}
+			}else if(unit.getQuestionType()==QuesStructType.MULTIPLE_ANSWER_QUESTION){
+				this.answer = unit.getQuestion().getQuesAnswer().replaceAll(",", "");
+			}else{
+				this.answer = unit.getQuestion().getQuesAnswer();
+			}
+		}
+	}
+	
+	
 	public ObjectiveQuestionStructure(PaperExp paperExp,PaperDetailExp paperDetailExp,PaperDetailUnitExp unit){
 		this.courseNo = paperExp.getCourseNo();
 		this.courseName = paperExp.getCourseName();
@@ -148,6 +187,22 @@ public class ObjectiveQuestionStructure implements Serializable{
 	public void setSmallQuestionScore(Double smallQuestionScore) {
 		this.smallQuestionScore = smallQuestionScore;
 	}
+
+	public String getPaperName() {
+		return paperName;
+	}
+
+	public void setPaperName(String paperName) {
+		this.paperName = paperName;
+	}
+
+	public String getPaperType() {
+		return paperType;
+	}
+
+	public void setPaperType(String paperType) {
+		this.paperType = paperType;
+	}
 	
 }
 

+ 42 - 4
cqb-paper/src/main/java/com/qmth/cqb/paper/dto/SubjectiveQuestionStructure.java

@@ -25,25 +25,36 @@ public class SubjectiveQuestionStructure implements Serializable{
 	 */
 	@ExcelProperty(name="科目名称",index = 1)
 	private String courseName;
+	/**
+	 * 试卷名称
+	 */
+	@ExcelProperty(name="试卷名称",index = 2)
+	private String paperName;
+	
+	/**
+	 * 试卷类型
+	 */
+	@ExcelProperty(name="试卷类型",index = 3)
+	private String paperType;
 	/**
 	 * 大题号
 	 */
-	@ExcelProperty(name="大题号",index = 2)
+	@ExcelProperty(name="大题号",index = 4)
 	private Integer bigQuestionNo;
 	/**
 	 * 大题名称
 	 */
-	@ExcelProperty(name="大题名称",index = 3)
+	@ExcelProperty(name="大题名称",index = 5)
 	private String bigQuestionName;
 	/**
 	 * 小题号
 	 */
-	@ExcelProperty(name="小题号",index = 4)
+	@ExcelProperty(name="小题号",index = 6)
 	private Integer smallQuestionNo;
 	/**
 	 * 小题分数
 	 */
-	@ExcelProperty(name="满分",index = 5)
+	@ExcelProperty(name="满分",index = 7)
 	private Double questionScore;
 	
 	public SubjectiveQuestionStructure(){}
@@ -57,6 +68,17 @@ public class SubjectiveQuestionStructure implements Serializable{
 		this.questionScore = unit.getScore();
 	}
 	
+	public SubjectiveQuestionStructure(PaperExp paperExp,PaperDetailExp paperDetailExp,PaperDetailUnitExp unit,String paperType){
+		this.paperName = paperExp.getName();
+		this.paperType = paperType;
+		this.courseNo = paperExp.getCourseNo();
+		this.courseName = paperExp.getCourseName();
+		this.bigQuestionNo = paperDetailExp.getNumber();
+		this.bigQuestionName = paperDetailExp.getName();
+		this.smallQuestionNo = unit.getNumber();
+		this.questionScore = unit.getScore();
+	}
+	
 	
 	public String getCourseNo() {
 		return courseNo;
@@ -96,6 +118,22 @@ public class SubjectiveQuestionStructure implements Serializable{
 	public void setQuestionScore(Double questionScore) {
 		this.questionScore = questionScore;
 	}
+
+	public String getPaperName() {
+		return paperName;
+	}
+
+	public void setPaperName(String paperName) {
+		this.paperName = paperName;
+	}
+
+	public String getPaperType() {
+		return paperType;
+	}
+
+	public void setPaperType(String paperType) {
+		this.paperType = paperType;
+	}
 	
 }
 

+ 6 - 2
cqb-paper/src/main/java/com/qmth/cqb/paper/model/PaperDetailUnit.java

@@ -201,10 +201,14 @@ public class PaperDetailUnit implements Serializable, Comparable<PaperDetailUnit
                 }
                 totalScore += score;
             }
-            this.score = totalScore;
+            this.score = CommonUtils.formatDouble(totalScore);
         }
     }
 
+    public void setSubScoreListNew(List<Double> subScoreList) {
+        this.subScoreList = subScoreList;
+    }
+
 	@Override
     public int compareTo(PaperDetailUnit unit) {
         /*if (unit != null) {
@@ -258,6 +262,6 @@ public class PaperDetailUnit implements Serializable, Comparable<PaperDetailUnit
                 totalScore += score;
             }
         }
-        return totalScore;
+        return CommonUtils.formatDouble(totalScore);
     }
 }

+ 17 - 17
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ExportPaperService.java

@@ -1,17 +1,17 @@
-package com.qmth.cqb.paper.service;
-
-import javax.servlet.http.HttpServletResponse;
-
-public interface ExportPaperService {
-
-	/**
-	 * 导出试卷,答案,机考数据包
-	 * @param examId
-	 * @param courseNo
-	 * @param paperType
-	 * @param response
-	 * @param exportContentList
-	 * @throws Exception
-	 */
-	public void exportPaperFile(String paperId,String serviceName,String exportContentList,HttpServletResponse response)  throws Exception;
-}
+package com.qmth.cqb.paper.service;
+
+import javax.servlet.http.HttpServletResponse;
+
+public interface ExportPaperService {
+
+	/**
+	 * 导出试卷,答案,机考数据包
+	 * @param examId
+	 * @param courseNo
+	 * @param paperType
+	 * @param response
+	 * @param exportContentList
+	 * @throws Exception
+	 */
+	public void exportPaperFile(String paperId,String serviceName,String exportContentList,HttpServletResponse response, String loginName)  throws Exception;
+}

+ 40 - 40
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ExtractConfigFileService.java

@@ -1,40 +1,40 @@
-package com.qmth.cqb.paper.service;
-
-import javax.servlet.http.HttpServletResponse;
-
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
-
-import com.qmth.cqb.paper.dto.ExportPaperInfoModel;
-import com.qmth.cqb.paper.model.ExtractConfig;
-
-/**
- * @author  	chenken
- * @date    	2017年7月31日 下午6:03:26
- * @company 	QMTH
- * @description 调卷规则--文件处理service
- */
-public interface ExtractConfigFileService {
-	
-	/**
-	 * 保存调卷规则,生成试卷文件
-	 * @param extractConfig
-	 * @param isbuildFile	1:生成试卷文件 0:不生成试卷文件
-	 * @param accessUser
-	 * @throws Exception
-	 */
-	public void saveExtractConfigAndBuildPaperFile(ExtractConfig extractConfig,Integer isbuildFile,AccessUser accessUser)  throws Exception;
-	
-	/**
-	 * 导出考试下的试卷信息  校验
-	 * @param exportModel
-	 * @param response
-	 * @throws Exception
-	 */
-	public void exportExamPaperInfoCheck(ExportPaperInfoModel exportModel,HttpServletResponse response)  throws Exception ;
-	/**
-	 * 导出考试下的试卷信息
-	 * @param exportModel
-	 */
-	public void exportExamPaperInfo(ExportPaperInfoModel exportModel,HttpServletResponse response)  throws Exception ;
-}
-
+package com.qmth.cqb.paper.service;
+
+import javax.servlet.http.HttpServletResponse;
+
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
+
+import com.qmth.cqb.paper.dto.ExportPaperInfoModel;
+import com.qmth.cqb.paper.model.ExtractConfig;
+
+/**
+ * @author  	chenken
+ * @date    	2017年7月31日 下午6:03:26
+ * @company 	QMTH
+ * @description 调卷规则--文件处理service
+ */
+public interface ExtractConfigFileService {
+	
+	/**
+	 * 保存调卷规则,生成试卷文件
+	 * @param extractConfig
+	 * @param isbuildFile	1:生成试卷文件 0:不生成试卷文件
+	 * @param accessUser
+	 * @throws Exception
+	 */
+	public void saveExtractConfigAndBuildPaperFile(ExtractConfig extractConfig,Integer isbuildFile,AccessUser accessUser)  throws Exception;
+	
+	/**
+	 * 导出考试下的试卷信息  校验
+	 * @param exportModel
+	 * @param response
+	 * @throws Exception
+	 */
+	public void exportExamPaperInfoCheck(ExportPaperInfoModel exportModel,HttpServletResponse response)  throws Exception ;
+	/**
+	 * 导出考试下的试卷信息
+	 * @param exportModel
+	 */
+	public void exportExamPaperInfo(ExportPaperInfoModel exportModel,HttpServletResponse response,String loginName)  throws Exception ;
+}
+

+ 12 - 4
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperStructService.java

@@ -16,6 +16,8 @@ import com.qmth.cqb.paper.model.*;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.*;
+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;
@@ -23,10 +25,13 @@ import org.springframework.stereotype.Service;
 
 import com.qmth.cqb.paper.dao.PaperStructRepo;
 import com.qmth.cqb.paper.dto.PaperDetailUnitStructDto;
+import com.qmth.cqb.utils.BeanCopierUtil;
 import com.qmth.cqb.utils.CommonUtils;
 import com.qmth.cqb.utils.enums.PaperStructType;
 
 import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.exact;
 
 /**
  * Created by songyue on 16/12/28.
@@ -61,7 +66,7 @@ public class PaperStructService {
                 .withMatcher("orgId",exact())
                 .withIgnoreNullValues();
         return paperStructRepo.findAll(Example.of(paperStruct, matcher), new PageRequest(curPage - 1, pageSize));*/
-    	
+
     	//create by weiwenhai
     	Query query = new Query();
         query.addCriteria(Criteria.where("orgId").is(searchInfo.getOrgId()));
@@ -118,6 +123,9 @@ public class PaperStructService {
         if (StringUtils.isEmpty(searchInfo.getCreator())) {
             searchInfo.setCreator(null);
         }
+        if (StringUtils.isEmpty(searchInfo.getCourseNo())) {
+            searchInfo.setCourseNo(null);
+        }
     }
 
     public void formatPaperStruct(PaperStruct paperStruct) {
@@ -247,7 +255,7 @@ public class PaperStructService {
         paperStruct.setDetailCount(paperDetailStructs.size());
         return paperStructRepo.save(paperStruct);
     }
-    
+
     /**
      * 构建单个属性组(用来筛选题目)
      * @param unitStruct
@@ -267,8 +275,8 @@ public class PaperStructService {
 				difficultyCount = paperDetailStruct.getPublicDifficultyCount() + paperDetailStruct.getNoPublicDifficultyCount();
 			}
 			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();  
+			BigDecimal b = new BigDecimal(dif);
+			Double difficulty = b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
 			return difficulty;
 		}
 		return (double)0;

+ 86 - 34
cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/ExportPaperAbstractService.java

@@ -8,9 +8,11 @@ import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Map.Entry;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -18,6 +20,7 @@ import java.util.stream.Collectors;
 import javax.xml.bind.JAXBElement;
 
 import com.qmth.cqb.question.dao.QuesPkgPathRepo;
+
 import main.java.com.UpYun;
 
 import org.apache.commons.io.FileUtils;
@@ -231,23 +234,24 @@ public abstract class ExportPaperAbstractService {
 	
 	/**
 	 * 下载试卷
-	 * @param id
-	 * @param response
+	 * @param paperId
+	 * @param zipFileName
 	 * @throws Exception
 	 */
 	public abstract void downloadPaper(String paperId,String zipFileName)throws Exception;
 	/**
 	 * 下载答案
 	 * @param paperId
-	 * @param response
+	 * @param zipFileName
 	 * @throws Exception
 	 */
 	public abstract void downloadPaperAnswer(String paperId,String zipFileName)throws Exception;
 	/**
 	 * 上传试卷相关文件
-	 * @param orgName
-	 * @param examName
+	 * @param extractConfig
 	 * @param paperId
+	 * @param exportStructure
+	 * @param accessUser
 	 * @throws Exception
 	 */
     public abstract void uploadFile(ExtractConfig extractConfig,String paperId,ExportStructure exportStructure,AccessUser accessUser)  throws Exception;
@@ -421,7 +425,6 @@ public abstract class ExportPaperAbstractService {
     /**
 	 * 给小题选项进行排序
 	 * @param paperDetails
-	 * @param startIndxt
 	 * @throws Exception
 	 */
 	public void setUnitExpNumber(List<PaperDetailExp> paperDetails) throws Exception {
@@ -475,17 +478,17 @@ public abstract class ExportPaperAbstractService {
         List<Object> pList = body.getContent();
         int index = 0;
         for(Object pObj:pList){
-            if(index < pList.size()-1){
-                break;
+            if(index == pList.size()-1){
+				P p = (P) pObj;
+				List<Object> pContent = p.getContent();
+				R run = new R();
+				Text text = new Text();
+				text.setValue("("+scores+"分)");
+				run.getContent().add(text);
+				pContent.add(run);
+
             }
-            P p = (P) pObj;
-            List<Object> pContent = p.getContent();
-            R run = new R();
-            Text text = new Text();
-            text.setValue("("+scores+"分)");
-            run.getContent().add(text);
-            pContent.add(run);
-            index++;
+			index++;
         }
         StringBuffer pWordMl = new StringBuffer();
         for(Object pObj:pList){
@@ -516,8 +519,10 @@ public abstract class ExportPaperAbstractService {
     				//判断小题是否为套题
     				if(paperDetailUnit.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION){
     					List<Question> subQuestions = paperDetailUnit.getQuestion().getSubQuestions();
-    					for(Question subQuestion:subQuestions){
-    						String questionBodyWord = appendScoreToQuestionBody(subQuestion.getQuesBodyWord(),subQuestion.getScore());
+    					for(int i = 0;i < subQuestions.size();i++){
+    						Question subQuestion = subQuestions.get(i);
+							double subScore = paperDetailUnit.getSubScoreList().get(i);
+    						String questionBodyWord = appendScoreToQuestionBody(subQuestion.getQuesBodyWord(),subScore);
     						subQuestion.setQuesBodyWord(questionBodyWord);
     					}
     				}else {
@@ -628,14 +633,14 @@ public abstract class ExportPaperAbstractService {
 		for (PaperDetailUnitExp unitExp : paperDetailUnitExps) {
 			//判断套路
 			if(unitExp.getQuestionType()==QuesStructType.NESTED_ANSWER_QUESTION){
-				List<Question> subQuestions = unitExp.getQuestion().getSubQuestions();
-				for(Question subQuestion:subQuestions){
-					scoreSet.add(subQuestion.getScore());
-				}
-				/*List<Double> subScoreList =  unitExp.getSubScoreList();
+//				List<Question> subQuestions = unitExp.getQuestion().getSubQuestions();
+//				for(Question subQuestion:subQuestions){
+//					scoreSet.add(subQuestion.getScore());
+//				}
+				List<Double> subScoreList =  unitExp.getSubScoreList();
 				for(Double score:subScoreList){
 					scoreSet.add(score);
-				}*/
+				}
 			}else{
 				scoreSet.add(unitExp.getScore());
 			}
@@ -649,8 +654,8 @@ public abstract class ExportPaperAbstractService {
    	
     /**
      * 创建机考文件,并打包上传至又拍云
-     * @param paperId
-     * @param currNum
+     * @param extractConfig
+     * @param accessUser
      * @throws IOException 
      */
     protected void uploadComputerTestFile(ExtractConfig extractConfig,AccessUser accessUser) throws IOException{
@@ -730,7 +735,11 @@ public abstract class ExportPaperAbstractService {
 		}
     }
     
-    private void getBodyAndOptionAudioFile(ComputerTestQuestion computerTestQuestion,Sections bodySections,String jsonDirectoryPath,ComputerTestPaper computerTestPaper,String examId){
+    private void getBodyAndOptionAudioFile(ComputerTestQuestion computerTestQuestion,
+										   Sections bodySections,
+										   String jsonDirectoryPath,
+										   ComputerTestPaper computerTestPaper,
+										   String examId){
     	List<Section> sectionList = bodySections.getSections();
 		for(Section section:sectionList){
 			List<Block> blocks = section.getBlocks();
@@ -759,13 +768,19 @@ public abstract class ExportPaperAbstractService {
     
 	/**
      * 生成试卷或答案Word,上传至又拍云
-     * @param orgName
-     * @param dataMap
+     * @param paperExp
      * @param extractConfig
-     * @param paperId
      * @param accessUser
+     * @param currNum
+     * @param template
+	 * @param examFileType
      */
-    protected void uploadPaperOrAnswerFile(PaperExp paperExp,ExtractConfig extractConfig,AccessUser accessUser,String currNum,Template template,ExamFileType examFileType){
+    protected void uploadPaperOrAnswerFile(PaperExp paperExp,
+										   ExtractConfig extractConfig,
+										   AccessUser accessUser,
+										   String currNum,
+										   Template template,
+										   ExamFileType examFileType){
     	String paperfileName = currNum+examFileType.name()+DOCX_SUFFIX;
     	try {
 			DocxProcessUtil.exportWord(paperExp,paperfileName,template);
@@ -801,9 +816,11 @@ public abstract class ExportPaperAbstractService {
     	//根据试卷结构导出设置中的数量补齐客观题
     	List<PaperDetailExp> paperDetailExps = fillObjectiveQuestions(objectiveDetails,questionTypeNums);
     	List<ObjectiveQuestionStructure> objectiveQuestionStructureList = new ArrayList<ObjectiveQuestionStructure>();
+    	
+    	String paperType = findPaperType(extractConfig,paperExp.getId());
     	for(PaperDetailExp paperDetailExp:paperDetailExps){
     		for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
-    			objectiveQuestionStructureList.add(new ObjectiveQuestionStructure(paperExp,paperDetailExp,unit));
+    			objectiveQuestionStructureList.add(new ObjectiveQuestionStructure(paperExp,paperDetailExp,unit,paperType));
     		}
     	}
     	ExcelWriter objectiveExcelExporter = new ExcelWriter(ObjectiveQuestionStructure.class); 
@@ -833,9 +850,10 @@ public abstract class ExportPaperAbstractService {
     	String subjectiveFileName = currNum+ExamFileType.PAPER_STRUCTURE_SUBJECTIVE.name()+EXCEL_SUFFIX;
     	List<PaperDetailExp> subjectiveDetails = getAllSubjectiveDetails(paperExp);
     	List<SubjectiveQuestionStructure> subjectiveQuestionStructureList = new ArrayList<SubjectiveQuestionStructure>();
+    	String paperType = findPaperType(extractConfig,paperExp.getId());
     	for(PaperDetailExp paperDetailExp:subjectiveDetails){
     		for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
-    			subjectiveQuestionStructureList.add(new SubjectiveQuestionStructure(paperExp,paperDetailExp,unit));
+    			subjectiveQuestionStructureList.add(new SubjectiveQuestionStructure(paperExp,paperDetailExp,unit,paperType));
     		}
     	}
     	ExcelWriter subjectiveExcelExporter = new ExcelWriter(SubjectiveQuestionStructure.class); 
@@ -945,9 +963,23 @@ public abstract class ExportPaperAbstractService {
         		newPaperDetailExp.setPaperDetailUnits(newPaperDetailUnits);
     			//设置大题题号
         		newPaperDetailExp.setNumber(Integer.parseInt(quesStructType.getId()+""));
+        		newPaperDetailExp.setSortNumber(paperDetailExp.getSortNumber());
     			paperDetailExps.add(newPaperDetailExp);
     		}
     	}
+		
+		//刷一遍number
+		for(int i = 0;i<paperDetailExps.size();i++){
+			if(paperDetailExps.get(i).getSortNumber() == quesStructType.getId()){
+				List<PaperDetailUnitExp> exps = paperDetailExps.get(i).getPaperDetailUnits();
+				int num = 0;
+				for(int j = 0;j<exps.size();j++){
+					num++;
+					exps.get(j).setNumber(num);
+				}
+			}
+		}
+		
 		//计算差额、补齐试题
 		int quantity = getQuantity(questionTypeNums,quesStructType)-currentSize;
 		PaperDetailExp paperDetailExp = new PaperDetailExp();
@@ -1009,7 +1041,6 @@ public abstract class ExportPaperAbstractService {
 	/**
      * 检查客观题数量是否小于试卷结构导出设置的数量
      * @param paperExp
-     * @param objectiveDetails
      * @param questionTypeNums
      * @return
      */
@@ -1057,5 +1088,26 @@ public abstract class ExportPaperAbstractService {
 		return DocxProcessUtil.getPkg(pkgByte);
 	}
     
+    /**
+     * 筛选出试卷类型
+     * @param extractConfig
+     * @param paperId
+     * @return
+     */
+    private String findPaperType(ExtractConfig extractConfig,String paperId){
+    	String paperType = "";
+    	Map<String,String> paperIdMap = extractConfig.getFinishedPaperIdMap();
+    	Set<Entry<String,String>> entry = paperIdMap.entrySet();
+		Iterator<Entry<String,String>> iterator = entry.iterator();
+		while(iterator.hasNext()){
+			Entry<String,String> next = iterator.next();
+			if(paperId.equals(next.getValue())){
+				paperType = next.getKey();
+				break;
+			}
+		}
+		return paperType;
+    }
+    
 }
 

+ 2 - 11
cqb-paper/src/main/java/com/qmth/cqb/paper/service/export/InitPaperExpService.java

@@ -127,7 +127,7 @@ public  class InitPaperExpService {
     public PaperExp initPaperExp(String paperId) throws Exception{
     	//根据paperId取到paper对象
     	Paper paper = paperRepo.findOne(paperId);
-    	paperService.formatPaper(paper, null);
+    	//paperService.formatPaper(paper, null);
     	if (paper == null) {
 			throw new PaperException("该试卷不存在");
 		}
@@ -257,14 +257,7 @@ public  class InitPaperExpService {
 			Double totalScore = 0.0;
 			//所有小题分数相加,得到大题分数
 			for(PaperDetailUnitExp paperDetailUnitExp:paperDetailUnitExps){
-				if(paperDetailUnitExp.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION){
-					List<Question> subQuestions = paperDetailUnitExp.getQuestion().getSubQuestions();
-					for(Question question:subQuestions){
-						totalScore += question.getScore();
-					}
-				}else{
-					totalScore += paperDetailUnitExp.getScore();
-				}
+				totalScore += paperDetailUnitExp.getScore();
 			}
 			paperDetailExp.setScore(totalScore);
 		}
@@ -504,8 +497,6 @@ public  class InitPaperExpService {
                                     int curNum = num + index;
                                     if(!StringUtils.isEmpty(preStr) && preStr.startsWith("#")){
                                         text.setValue("___"+(curNum)+"___");
-                                    }else{
-                                    	text.setValue(curNum+"");
                                     }
                                     index++;
                                 }

+ 7 - 7
cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/ExportPaperServiceImpl.java

@@ -55,13 +55,13 @@ public class ExportPaperServiceImpl implements ExportPaperService{
 	private PaperDetailService paperDetailService;
 
 	@Override
-	public void exportPaperFile(String paperId,String serviceName,String exportContentList,HttpServletResponse response) throws Exception {
-		ExportPaperAbstractService exportPaperAbstractService = (ExportPaperAbstractService) SpringContextUtils.getBeanById("xajdExportPaperService");
+	public void exportPaperFile(String paperId,String serviceName,String exportContentList,HttpServletResponse response,String loginName) throws Exception {
+		ExportPaperAbstractService exportPaperAbstractService = (ExportPaperAbstractService) SpringContextUtils.getBeanById(serviceName);
 		//根据试卷id查询试卷 
 		Paper paper = paperRepo.findOne(paperId);
 		List<Paper> papers = new ArrayList<Paper>();
 		papers.add(paper);
-		String zipFileName = "paperZip";
+		String zipFileName = loginName;
 		File directory = new File(TEMP_FILE_EXP + File.separator + zipFileName);
 		if(!directory.exists()){
 			directory.mkdirs();
@@ -77,19 +77,19 @@ public class ExportPaperServiceImpl implements ExportPaperService{
 		}
 		FileDisposeUtil.fileToZip(TEMP_FILE_EXP+File.separator+zipFileName,TEMP_FILE_EXP,zipFileName);
 		FileDisposeUtil.downloadFile(paper.getName()+"_"+paper.getCourse().getCode()+".zip", TEMP_FILE_EXP+File.separator+zipFileName+".zip",response);
-		deteleFolder(TEMP_FILE_EXP);
+		deteleFolder(TEMP_FILE_EXP,zipFileName);
 	}
 	
-	private void deteleFolder(String sourceFilePath) {
+	private void deteleFolder(String sourceFilePath,String zipFileName) {
 		File ComputerTestPaperfoler = new File(sourceFilePath + File.separator + "json");
 		if(ComputerTestPaperfoler.exists()){
 			FileUtils.deleteQuietly(ComputerTestPaperfoler);
 		}
-		File zipFolder = new File(sourceFilePath + File.separator + "paperZip");
+		File zipFolder = new File(sourceFilePath + File.separator + zipFileName);
 		if(zipFolder.exists()){
 			FileUtils.deleteQuietly(zipFolder);
 		}
-		File zipFile = new File(sourceFilePath + File.separator + "paperZip.zip");
+		File zipFile = new File(sourceFilePath + File.separator + zipFileName + ".zip");
 		if(zipFile.exists()){
 			FileUtils.deleteQuietly(zipFile);
 		}

+ 36 - 21
cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/ExtractConfigFileServiceImpl.java

@@ -3,6 +3,7 @@ package com.qmth.cqb.paper.service.impl;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -170,11 +171,13 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 	}
 
 	@Override
-	public void exportExamPaperInfo(ExportPaperInfoModel exportModel,HttpServletResponse response) throws Exception {
+	public void exportExamPaperInfo(ExportPaperInfoModel exportModel,HttpServletResponse response,String loginName) throws Exception {
+		String downloadDir = downloadDirectory + loginName;
+		String downZipDir = zipDirectory + loginName;
 		//创建试卷和压缩文件 文件夹
-		FileDisposeUtil.createDirectory(downloadDirectory);
+		FileDisposeUtil.createDirectory(downloadDir);
 		//创建压缩文件的文件夹
-		FileDisposeUtil.createDirectory(zipDirectory);
+		FileDisposeUtil.createDirectory(downZipDir);
 		ExportStructure exportStructure = exportStructureService.findStructureByExamId(exportModel.getExamId()+"");
 		if(exportStructure==null){
 			exportStructure = new ExportStructure();
@@ -182,7 +185,7 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 		}
 		//如果是普通类型的批量导出
 		if(exportModel.getExportWay()==ExportWay.BATCH){
-			List<String> paperIds = checkAllCourseByExamId(exportModel.getExamId(),exportStructure.getExportType());
+			Map<String,String> paperIds = checkAllCourseByExamId(exportModel.getExamId(),exportStructure.getExportType());
 			if(exportStructure.getExportType()==ExportType.NORMAL){
 				if(paperIds.size()>0&&exportModel.getExportContentList().contains(ExamFileType.PAPER_STRUCTURE_OBJECTIVE.name())){
 					makePaperStructure(exportStructure.getExamName(),paperIds,exportStructure);
@@ -195,7 +198,7 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 			for(int i = 0;i<examFiles.size();i++){
 				ExamFile examFile = examFiles.get(i);
 				UpYun upyun = new UpYun(bucketName,userName,password);
-				File file = new File(downloadDirectory+File.separator+examFile.getFileName());
+				File file = new File(downloadDir+File.separator+examFile.getFileName());
 				upyun.readFile(examFile.getFilePath(), file);
 				
 				if(examFile.getExamFileType()==ExamFileType.PAPER){
@@ -218,12 +221,12 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 		//创建压缩文件名称
 		String zipFileName = exportModel.getExamId();
 		//将downloadDirectory文件夹压缩成zip文件,存放到zipDirectory文件夹中
-		FileDisposeUtil.fileToZip(downloadDirectory,zipDirectory,zipFileName);
+		FileDisposeUtil.fileToZip(downloadDir,downZipDir,zipFileName);
 		//下载zip文件到客户端
-		FileDisposeUtil.downloadFile(zipFileName+".zip",zipDirectory+File.separator+zipFileName+".zip",response);
+		FileDisposeUtil.downloadFile(zipFileName+".zip",downZipDir+File.separator+zipFileName+".zip",response);
 		//删除文件夹
-		FileUtils.deleteQuietly(new File(downloadDirectory));
-		FileUtils.deleteQuietly(new File(zipDirectory));
+		FileUtils.deleteQuietly(new File(downloadDir));
+		FileUtils.deleteQuietly(new File(downZipDir));
 	}
 	
 	/**
@@ -291,8 +294,8 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 	 * 查询该考试下是否所有课程都制定了调卷规则
 	 * @param examId
 	 */
-	private List<String> checkAllCourseByExamId(String examId,ExportType exportType) {
-		List<String> paperIdList = new ArrayList<String>();
+	private Map<String,String> checkAllCourseByExamId(String examId,ExportType exportType) {
+		Map<String,String> paperIdMap = new HashMap<String,String>();
 		List<ExamCourseDto> examCourseDtoList = examCourseClient.findExamCourseByExamId(examId);
 		for(ExamCourseDto examCourseDto:examCourseDtoList){
 			ExtractConfig condition = new ExtractConfig();
@@ -310,11 +313,12 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 			Set<Entry<String,String>> entry = finishedPaperIdMap.entrySet();
 			Iterator<Entry<String,String>> iterator = entry.iterator();
 			while(iterator.hasNext()){
-				String paperId = iterator.next().getValue();
-				paperIdList.add(paperId);
+				Entry<String,String> next = iterator.next();
+				//paperId为key,paperType为value
+				paperIdMap.put(next.getValue(),next.getKey());
 			}
 		}
-		return paperIdList;
+		return paperIdMap;
 	}
 	
 	/**
@@ -358,12 +362,12 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 	 * @param exportStructure
 	 * @throws Exception
 	 */
-	private void makePaperStructure(String examName,List<String> paperIds,ExportStructure exportStructure) throws Exception{
+	private void makePaperStructure(String examName,Map<String,String> paperIds,ExportStructure exportStructure) throws Exception{
 		logger.info("正在批量生成试卷结构...");
 		List<QuestionTypeNum> questionTypeNums = exportStructure.getQuestionTypeNums();
-		
+		//客观题集合
 		List<ObjectiveQuestionStructure> objectiveQuestionStructureList = new ArrayList<ObjectiveQuestionStructure>();
-		
+		//主观题集合
 		List<SubjectiveQuestionStructure> subjectiveQuestionStructureList = new ArrayList<SubjectiveQuestionStructure>();
 		
 		ExportServiceManage esm = exportServiceManageRepo.findByOrgName(exportStructure.getOrgName());
@@ -371,28 +375,39 @@ public class ExtractConfigFileServiceImpl implements ExtractConfigFileService {
 			esm = exportServiceManageRepo.findByOrgName("陕西师范大学");
 		}
     	ExportPaperAbstractService exportPaperAbstractService = (ExportPaperAbstractService) SpringContextUtils.getBeanById(esm.getExportServiceName());
-		for(String paperId:paperIds){
+    	Set<Entry<String,String>> entrySet = paperIds.entrySet();
+		Iterator<Entry<String,String>> iterator = entrySet.iterator();
+		
+		while(iterator.hasNext()){
+			Entry<String,String> entry = iterator.next();
+			String paperId = entry.getKey();
+			String paperType = entry.getValue();
+			logger.info("初始化试卷:"+paperId);
 			PaperExp paperExp = initPaperExpService.initPaperExp(paperId);
-			//添加主观题
+			logger.info("处理客观题...");
+			//添加客观题
 			List<PaperDetailExp> objectiveDetails = exportPaperAbstractService.getAllObjectiveDetails(paperExp);
 			//得到补齐后的客观题大题
 			List<PaperDetailExp> paperDetailExps = exportPaperAbstractService.fillObjectiveQuestions(objectiveDetails, questionTypeNums);
 			List<ObjectiveQuestionStructure> objectiveList = new ArrayList<ObjectiveQuestionStructure>();
 	    	for(PaperDetailExp paperDetailExp:paperDetailExps){
 	    		for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
-	    			objectiveList.add(new ObjectiveQuestionStructure(paperExp,paperDetailExp,unit));
+	    			objectiveList.add(new ObjectiveQuestionStructure(paperExp,paperDetailExp,unit,paperType));
 	    		}
 	    	}
 	    	objectiveQuestionStructureList.addAll(objectiveList);
+	    	logger.info("处理客观题完成");
 	    	//添加主观题
+	    	logger.info("处理主观题...");
 	    	List<PaperDetailExp> subjectiveDetails = exportPaperAbstractService.getAllSubjectiveDetails(paperExp);
 	    	List<SubjectiveQuestionStructure> subjectiveList = new ArrayList<SubjectiveQuestionStructure>();
 	    	for(PaperDetailExp paperDetailExp:subjectiveDetails){
 	    		for(PaperDetailUnitExp unit:paperDetailExp.getPaperDetailUnits()){
-	    			subjectiveList.add(new SubjectiveQuestionStructure(paperExp,paperDetailExp,unit));
+	    			subjectiveList.add(new SubjectiveQuestionStructure(paperExp,paperDetailExp,unit,paperType));
 	    		}
 	    	}
 	    	subjectiveQuestionStructureList.addAll(subjectiveList);
+	    	logger.info("处理主观题完成");
 		}
 		
 		ExcelWriter objectiveExcelExporter = new ExcelWriter(ObjectiveQuestionStructure.class); 

+ 4 - 0
cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/ExtractConfigServiceImpl.java

@@ -475,6 +475,8 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
 							subQuesDtos.get(m).setQuesAnswer(subQuesList.get(m).getQuesAnswer());
 						}
                         subQuesDtos.get(m).setNumber(m + 1);
+						//套题分数从小题类中取值
+						subQuesDtos.get(m).setScore(paperDetailUnit.getSubScoreList().get(m));
                     }
                     unitDto.setSubQuestions(subQuesDtos);
                 }
@@ -524,6 +526,8 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
                 subQuesDtos.get(m).setQuesOptions(quesOptionDtos);
                 subQuesDtos.get(m).setQuesAnswer(subQuesList.get(m).getQuesAnswer());
                 subQuesDtos.get(m).setNumber(m + 1);
+				//套题分数从小题类中取值
+				subQuesDtos.get(m).setScore(paperDetailUnit.getSubScoreList().get(m));
                 dto.setSubQuestions(subQuesDtos);
             }
         }

+ 126 - 114
cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/PaperDetailServiceImpl.java

@@ -1,114 +1,126 @@
-package com.qmth.cqb.paper.service.impl;
-
-import java.util.List;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
-
-import com.qmth.cqb.paper.dao.PaperDetailRepo;
-import com.qmth.cqb.paper.dao.PaperRepo;
-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.PaperDetailService;
-import com.qmth.cqb.paper.service.PaperDetailUnitService;
-
-/**
- * @author  	chenken
- * @date    	2017年9月13日 上午11:32:33
- * @company 	QMTH
- * @description PaperDetailServiceImpl.java
- */
-@Service("paperDetailService")
-public class PaperDetailServiceImpl implements PaperDetailService{
-
-    @Autowired
-    PaperDetailRepo paperDetailRepo;
-
-    @Autowired
-    PaperDetailUnitService unitService;
-
-    @Autowired
-    PaperRepo paperRepo;
-
-    /**
-     * 根据Id获得对应所有小题
-     * 
-     * @param id
-     * @return
-     */
-    public List<PaperDetailUnit> getUnitsByPaperDetailId(String id) {
-        return unitService.getUnitsByPaperDetail(paperDetailRepo.findOne(id));
-    }
-
-    /**
-     * 按ID查询大题
-     * 
-     * @param id
-     * @return
-     */
-    public PaperDetail findById(String id) {
-        return paperDetailRepo.findOne(id);
-    }
-
-    /**
-     * 保存大题
-     * 
-     * @param pd
-     * @return
-     */
-    public PaperDetail savePaperDetail(PaperDetail pd, String paperId, AccessUser user) {
-        Paper paper = paperRepo.findOne(paperId);
-        paper.setLastModifyName(user.getName());
-        paper = paperRepo.save(paper);
-        pd.setPaper(paper);
-        return paperDetailRepo.save(pd);
-    }
-
-    /**
-     * 删除大题
-     * 
-     * @param id
-     * @return
-     */
-    public void deletePaperDetail(String id) {
-        paperDetailRepo.delete(id);
-    }
-
-    /**
-     * 查询同一个试卷对象对应大题
-     * 
-     * @param paper
-     * @return
-     */
-    public List<PaperDetail> getPaperDetailsByPaper(Paper paper) {
-        return paperDetailRepo.findByPaperOrderByNumber(paper);
-    }
-
-    /**
-     * 删除试卷大题
-     * 
-     * @param paper
-     */
-    public void deletePaperDetailsByPaper(Paper paper) {
-        List<PaperDetail> details = getPaperDetailsByPaper(paper);
-        unitService.deleteUnitsByPaperDetails(details);
-        paperDetailRepo.delete(details);
-    }
-
-    /**
-     * 批量删除试卷大题
-     * 
-     * @param papers
-     */
-    public void deletePaperDetailsByPapers(List<Paper> papers) {
-        for (Paper paper : papers) {
-            List<PaperDetail> details = getPaperDetailsByPaper(paper);
-            unitService.deleteUnitsByPaperDetails(details);
-            paperDetailRepo.delete(details);
-        }
-    }
-}
-
+package com.qmth.cqb.paper.service.impl;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
+
+import com.qmth.cqb.paper.dao.PaperDetailRepo;
+import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
+import com.qmth.cqb.paper.dao.PaperRepo;
+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.PaperDetailService;
+import com.qmth.cqb.paper.service.PaperDetailUnitService;
+import com.qmth.cqb.paper.service.QuesTypeNameService;
+
+/**
+ * @author  	chenken
+ * @date    	2017年9月13日 上午11:32:33
+ * @company 	QMTH
+ * @description PaperDetailServiceImpl.java
+ */
+@Service("paperDetailService")
+public class PaperDetailServiceImpl implements PaperDetailService{
+
+    @Autowired
+    PaperDetailRepo paperDetailRepo;
+
+    @Autowired
+    PaperDetailUnitService unitService;
+
+    @Autowired
+    PaperRepo paperRepo;
+    
+    @Autowired
+    QuesTypeNameService quesTypeNameService;
+
+
+    @Autowired
+    PaperDetailUnitRepo paperDetailUnitRepo;
+
+    /**
+     * 根据Id获得对应所有小题
+     * 
+     * @param id
+     * @return
+     */
+    public List<PaperDetailUnit> getUnitsByPaperDetailId(String id) {
+        return unitService.getUnitsByPaperDetail(paperDetailRepo.findOne(id));
+    }
+
+    /**
+     * 按ID查询大题
+     * 
+     * @param id
+     * @return
+     */
+    public PaperDetail findById(String id) {
+        return paperDetailRepo.findOne(id);
+    }
+
+    /**
+     * 保存大题
+     * 
+     * @param pd
+     * @return
+     */
+    public PaperDetail savePaperDetail(PaperDetail pd, String paperId, AccessUser user) {
+        Paper paper = paperRepo.findOne(paperId);
+        paper.setLastModifyName(user.getName());
+        paper = paperRepo.save(paper);
+        pd.setPaper(paper);
+        PaperDetail paperDetail = paperDetailRepo.save(pd);
+        List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetailOrderByNumber(paperDetail);
+        quesTypeNameService.saveQuesTypeName(paperDetailUnits);
+        return paperDetail;
+    }
+
+    /**
+     * 删除大题
+     * 
+     * @param id
+     * @return
+     */
+    public void deletePaperDetail(String id) {
+        paperDetailRepo.delete(id);
+    }
+
+    /**
+     * 查询同一个试卷对象对应大题
+     * 
+     * @param paper
+     * @return
+     */
+    public List<PaperDetail> getPaperDetailsByPaper(Paper paper) {
+        return paperDetailRepo.findByPaperOrderByNumber(paper);
+    }
+
+    /**
+     * 删除试卷大题
+     * 
+     * @param paper
+     */
+    public void deletePaperDetailsByPaper(Paper paper) {
+        List<PaperDetail> details = getPaperDetailsByPaper(paper);
+        unitService.deleteUnitsByPaperDetails(details);
+        paperDetailRepo.delete(details);
+    }
+
+    /**
+     * 批量删除试卷大题
+     * 
+     * @param papers
+     */
+    public void deletePaperDetailsByPapers(List<Paper> papers) {
+        for (Paper paper : papers) {
+            List<PaperDetail> details = getPaperDetailsByPaper(paper);
+            unitService.deleteUnitsByPaperDetails(details);
+            paperDetailRepo.delete(details);
+        }
+    }
+}
+

+ 23 - 1
cqb-paper/src/main/java/com/qmth/cqb/paper/service/impl/PaperServiceImpl.java

@@ -5,6 +5,8 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
@@ -542,6 +544,7 @@ public class PaperServiceImpl implements PaperService{
      * @param paperExp
      */
     public void initPaper(PaperExp paperExp) {
+    	DecimalFormat df = new DecimalFormat("#.00");
         if (paperExp.getPaperDetails() == null || paperExp.getPaperDetails().size() == 0) {
             return;
         }
@@ -578,6 +581,8 @@ public class PaperServiceImpl implements PaperService{
         }
     }
 
+
+
     /**
      * 格式化查询条件
      *
@@ -624,7 +629,7 @@ public class PaperServiceImpl implements PaperService{
 					}
 				}
 			}
-			BigDecimal b = new BigDecimal(sum / paperTotalScore);  
+			BigDecimal b = new BigDecimal(sum / paperTotalScore);
 			Double difficulty = b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
 			return difficulty;
 		}
@@ -647,6 +652,7 @@ public class PaperServiceImpl implements PaperService{
             unit.setNumber(i+1);
         }
         paperDetailUnitRepo.save(paperDetailUnitAll);
+        totalScore = CommonUtils.formatDouble(totalScore);
         return totalScore;
 	}
 
@@ -676,6 +682,7 @@ public class PaperServiceImpl implements PaperService{
                     }
                 }
                 count = paperDetailUnits.size() + nestQusNum;
+                score = CommonUtils.formatDouble(score);
                 paperDetail.setScore(score);
                 paperDetail.setUnitCount(count);
                 allQuesCount += count;
@@ -801,6 +808,18 @@ public class PaperServiceImpl implements PaperService{
         for (Question ques : questions) {
             PaperDetailUnit pdu = new PaperDetailUnit(paper,paperDetail,ques);
             pdu.setNumber(paperDetailUnit.getNumber());//设置为大题中最大的number
+            pdu.setScore(paperDetailUnit.getScore());
+            //处理套题
+            if(pdu.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION){
+                List<Question> subQuestions = ques.getSubQuestions();
+                List<Double> subScoreList = new ArrayList<>();
+                if(subQuestions != null && subQuestions.size() > 0){
+                    for(Question subQuestion:subQuestions){
+                        subScoreList.add(CommonUtils.formatDouble(pdu.getScore()/subQuestions.size()));
+                    }
+                }
+                pdu.setSubScoreListNew(subScoreList);
+            }
             saveUnits.add(pdu);
         }
         paperDetailUnitRepo.save(saveUnits);
@@ -1138,5 +1157,8 @@ public class PaperServiceImpl implements PaperService{
 			quesRepo.save(question);
 		}
     }
+
+
+
 }
 

+ 63 - 62
cqb-paper/src/main/java/com/qmth/cqb/paper/web/ExportPaperController.java

@@ -1,62 +1,63 @@
-package com.qmth.cqb.paper.web;
-
-import cn.com.qmth.examcloud.common.uac.annotation.Uac;
-import cn.com.qmth.examcloud.common.uac.enums.RoleMeta;
-import cn.com.qmth.examcloud.common.uac.enums.UacPolicy;
-import io.swagger.annotations.ApiOperation;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import com.qmth.cqb.paper.dao.ExportServiceManageRepo;
-import com.qmth.cqb.paper.model.ExportServiceManage;
-import com.qmth.cqb.paper.service.ExportPaperService;
-import com.qmth.cqb.paper.service.export.SydxExportPaperService;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * Created by songyue on 17/3/30.
- */
-@Controller
-@RequestMapping("${api_cqb}/")
-public class ExportPaperController {
-    protected static final Logger log = LoggerFactory.getLogger(ExportPaperController.class);
-    
-    @Autowired
-    ExportServiceManageRepo exportServiceManageRepo;
-    
-    @Autowired
-    SydxExportPaperService sydxExportPaperService;
-    
-    @Autowired
-    private ExportPaperService exportPaperService;
-    /**
-     * 导出试卷
-     * @param id
-     * @return
-     */
-    @ApiOperation(value="导出试卷",notes="导出试卷")
-    @GetMapping(value = "/paper/export/{id}/{exportContentList}/{orgName}")
-    public void getPaperById(HttpServletRequest request, HttpServletResponse response,
-    						 @PathVariable String id,
-    						 @PathVariable String orgName,
-    						 @PathVariable String exportContentList){
-    	log.info("导出开始");
-    	try {
-    		ExportServiceManage esm = exportServiceManageRepo.findByOrgName(orgName);
-    		exportPaperService.exportPaperFile(id,esm.getExportServiceName(),exportContentList,response);
-		} catch (Exception e) {
-			e.printStackTrace();
-	        log.error("导出异常:"+e.getMessage());
-		}
-    	log.info("导出结束");
-    }
-
-}
+package com.qmth.cqb.paper.web;
+
+import cn.com.qmth.examcloud.common.uac.annotation.Uac;
+import cn.com.qmth.examcloud.common.uac.enums.RoleMeta;
+import cn.com.qmth.examcloud.common.uac.enums.UacPolicy;
+import io.swagger.annotations.ApiOperation;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import com.qmth.cqb.paper.dao.ExportServiceManageRepo;
+import com.qmth.cqb.paper.model.ExportServiceManage;
+import com.qmth.cqb.paper.service.ExportPaperService;
+import com.qmth.cqb.paper.service.export.SydxExportPaperService;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by songyue on 17/3/30.
+ */
+@Controller
+@RequestMapping("${api_cqb}/")
+public class ExportPaperController {
+    protected static final Logger log = LoggerFactory.getLogger(ExportPaperController.class);
+    
+    @Autowired
+    ExportServiceManageRepo exportServiceManageRepo;
+    
+    @Autowired
+    SydxExportPaperService sydxExportPaperService;
+    
+    @Autowired
+    private ExportPaperService exportPaperService;
+    /**
+     * 导出试卷
+     * @param id
+     * @return
+     */
+    @ApiOperation(value="导出试卷",notes="导出试卷")
+    @GetMapping(value = "/paper/export/{id}/{exportContentList}/{orgName}/{loginName}")
+    public void getPaperById(HttpServletRequest request, HttpServletResponse response,
+    						 @PathVariable String id,
+    						 @PathVariable String orgName,
+    						 @PathVariable String exportContentList,
+    						 @PathVariable String loginName){
+    	log.info("导出开始");
+    	try {
+    		ExportServiceManage esm = exportServiceManageRepo.findByOrgName(orgName);
+    		exportPaperService.exportPaperFile(id,esm.getExportServiceName(),exportContentList,response,loginName);
+		} catch (Exception e) {
+			e.printStackTrace();
+	        log.error("导出异常:"+e.getMessage());
+		}
+    	log.info("导出结束");
+    }
+
+}

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

@@ -161,12 +161,13 @@ public class ExtractConfigController {
 	}
 	
 	@ApiOperation(value = "导出单张考试试卷、答案、试卷结构", notes = "导出单张考试试卷、答案、试卷结构")
-	@GetMapping(value = "/exportSingleExamPaperInfo/{exportWay}/{examId}/{courseId}/{exportContentList}")
+	@GetMapping(value = "/exportSingleExamPaperInfo/{exportWay}/{examId}/{courseId}/{exportContentList}/{loginName}")
 	public void exportSingleExamPaperInfo(HttpServletResponse response,
 											@PathVariable String exportWay,
 											@PathVariable String examId,
 											@PathVariable String courseId,
-											@PathVariable String exportContentList){
+											@PathVariable String exportContentList,
+											@PathVariable String loginName){
 		ExportPaperInfoModel exportModel = new ExportPaperInfoModel();
 		exportModel.setExportWay(ExportWay.strToEnum(exportWay));
 		exportModel.setExamId(examId);
@@ -178,7 +179,7 @@ public class ExtractConfigController {
 		}
 		exportModel.setExportContentList(list);
 		try {
-			extractConfigFileService.exportExamPaperInfo(exportModel,response);
+			extractConfigFileService.exportExamPaperInfo(exportModel,response,loginName);
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
@@ -203,11 +204,12 @@ public class ExtractConfigController {
 	
 	
 	@ApiOperation(value = "导出整个考试下所有 课程的试卷、答案、试卷结构", notes = "导出整个考试下所有 课程的试卷、答案、试卷结构")
-	@GetMapping(value = "/exportBatchExamPaperInfo/{exportWay}/{examId}/{exportContentList}")
+	@GetMapping(value = "/exportBatchExamPaperInfo/{exportWay}/{examId}/{exportContentList}/{loginName}")
 	public void exportBatchExamPaperInfo(HttpServletResponse response,
 											@PathVariable String exportWay,
 											@PathVariable String examId,
-											@PathVariable String exportContentList){
+											@PathVariable String exportContentList,
+											@PathVariable String loginName){
 		ExportPaperInfoModel exportModel = new ExportPaperInfoModel();
 		exportModel.setExportWay(ExportWay.strToEnum(exportWay));
 		exportModel.setExamId(examId);
@@ -218,7 +220,7 @@ public class ExtractConfigController {
 		}
 		exportModel.setExportContentList(list);
 		try {
-			extractConfigFileService.exportExamPaperInfo(exportModel,response);
+			extractConfigFileService.exportExamPaperInfo(exportModel,response,loginName);
 		} catch (Exception e) {
 			e.printStackTrace();
 		}

+ 14 - 17
cqb-question-resource/src/main/java/com/qmth/cqb/question/service/impl/QuesServiceImpl.java

@@ -8,6 +8,7 @@ import com.qmth.cqb.question.dao.QuesPkgPathRepo;
 import com.qmth.cqb.question.model.*;
 import org.apache.commons.lang3.StringEscapeUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.docx4j.Docx4J;
 import org.docx4j.openpackaging.exceptions.InvalidFormatException;
 import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -289,7 +290,6 @@ public class QuesServiceImpl implements QuesService{
             question.setQuesBodyWord(null);
             question.setQuesAnswerWord(null);
             question.setQuesAnswerAnalysisWord(null);
-//            question.setQuesPkg(new byte[0]);
             String newQuesBody = question.getQuesBody().replaceAll("<span>", "").replaceAll("</span>", "")
                     .replaceAll("###", "______");
             question.setQuesBody(newQuesBody);
@@ -308,9 +308,12 @@ public class QuesServiceImpl implements QuesService{
      */
     public void updateQuesWord(Question question) {
         try {
-        	if(wordMLPackage==null){
+        	if(wordMLPackage == null){
         		wordMLPackage = WordprocessingMLPackage.createPackage();
-        	}
+        	}else{
+                DocxProcessUtil.initTmpPackage(wordMLPackage);
+        	    wordMLPackage.getRelationshipsPart().remove();
+            }
             updateQuesWordUnit(wordMLPackage, question);
             List<Question> subQuesList = question.getSubQuestions();
             if (subQuesList != null && subQuesList.size() > 0) {
@@ -319,25 +322,25 @@ public class QuesServiceImpl implements QuesService{
                 }
             }
             byte [] pkgByte = DocxProcessUtil.getPkgByte(wordMLPackage);
-            QuestionPkgPath quesPkgPath = quesPkgPathRepo.save(new QuestionPkgPath(pkgByte));
-            question.setQuesPkgPathId(quesPkgPath.getId());
+            QuestionPkgPath quesPkgPath = quesPkgPathRepo.findFirstById(question.getQuesPkgPathId());
+            quesPkgPath.setQuesPkg(pkgByte);
+            quesPkgPathRepo.save(quesPkgPath);
             pkgByte = null;
-            quesPkgPath.setQuesPkg(null);
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
 
     public void updateQuesWordUnit(WordprocessingMLPackage wordMLPackage, Question question) throws Exception {
-        String quesBody = StringEscapeUtils.unescapeHtml4(question.getQuesBody());
-        String quesAnswer = StringEscapeUtils.unescapeHtml4(question.getQuesAnswer());
+        String quesBody = question.getQuesBody();
+        String quesAnswer = question.getQuesAnswer();
         if(!StringUtils.isEmpty(quesBody)){
-            question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, quesBody));
+            question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(quesBody)));
         }
         if(!StringUtils.isEmpty(quesAnswer)
                 && (question.getQuestionType() == QuesStructType.FILL_BLANK_QUESTION
                 || question.getQuestionType() == QuesStructType.TEXT_ANSWER_QUESTION)){
-            question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, quesAnswer));
+            question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(quesAnswer)));
         }
         if(!StringUtils.isEmpty(quesAnswer)&& 
         		(question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
@@ -348,15 +351,9 @@ public class QuesServiceImpl implements QuesService{
         if (quesOptions != null && quesOptions.size() > 0) {
             for (QuesOption quesOption : quesOptions) {
                 quesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage,
-                        StringEscapeUtils.unescapeHtml4(quesOption.getOptionBody())));
-                DocxProcessUtil.initTmpPackage(wordMLPackage);
+                        CommonUtils.formatHtml(quesOption.getOptionBody())));
             }
         }
-        byte [] pkgByte = DocxProcessUtil.getPkgByte(wordMLPackage);
-        QuestionPkgPath quesPkgPath = quesPkgPathRepo.save(new QuestionPkgPath(pkgByte));
-        question.setQuesPkgPathId(quesPkgPath.getId());
-        pkgByte = null;
-        quesPkgPath.setQuesPkg(null);
     }
     
     private String makeQuesAnswerWord(String quesAnswer){

+ 1 - 1
cqb-starter/src/main/resources/application-dev.properties

@@ -3,7 +3,7 @@ spring.data.mongodb.uri=mongodb://192.168.1.99:27017/comm-ques-bank
 spring.data.mongodb.grid-fs-database=comm-ques-bank
 spring.data.mongodb.database=comm-ques-bank
 eureka.client.serviceUrl.defaultZone=http://192.168.1.99:1111/eureka/
-spring.application.name=weiwenhai_ExamCloud-service-question
+spring.application.name=ExamCloud-service-question
 
 spring.redis.host=192.168.1.99
 spring.redis.port=6379

+ 30 - 3
cqb-starter/src/main/resources/application-prac.properties

@@ -1,10 +1,37 @@
-spring.data.mongodb.uri=mongodb://root:Qmth87863577@dds-wz93448b802ba2241.mongodb.rds.aliyuncs.com:3717/?authSource=admin&authMechanism=SCRAM-SHA-1
-spring.data.mongodb.database=comm-ques-bank
+#spring.data.mongodb.uri=mongodb://root:Qmth87863577@119.23.127.95:3717/?authSource=admin&authMechanism=SCRAM-SHA-1
+spring.data.mongodb.uri=mongodb://localhost:27017/comm-ques-bank
 spring.data.mongodb.grid-fs-database=comm-ques-bank
+spring.data.mongodb.database=comm-ques-bank
 eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
 spring.application.name=ExamCloud-service-question
 
 spring.redis.host=127.0.0.1
 spring.redis.port=6379
 
-server.tomcat.max-threads=2000
+upyun.bucketName=exam-cloud-test
+upyun.userName=examcloud
+upyun.password=examcloud123456
+upyun.uploadUrl=/comm-ques-bank/dev/exam-paper-file/
+upyun.audio.uploadUrl=/comm-ques-bank/dev/audio/
+upyun.audio.maxsize=5
+upyun.downloadUrl=http://exam-cloud-test.b0.upaiyun.com
+upyun.downloadDirectory=paperDirectory
+upyun.zipDirectory=paperZipDirectory
+upyun.radioType=mp3,wma
+
+
+spring.datasource.url=jdbc:mysql://127.0.0.1:3306/exam_cloud_test?useUnicode=true&characterEncoding=UTF-8
+spring.datasource.username=root
+spring.datasource.password=root
+spring.datasource.validation-query=SELECT 1 FROM DUAL
+spring.datasource.test-on-borrow=true
+spring.datasource.driver-class-name=com.mysql.jdbc.Driver
+spring.jpa.show-sql=false
+spring.jpa.hibernate.ddl-auto=update
+
+
+spring.rabbitmq.host=127.0.0.1
+spring.rabbitmq.port=5672
+spring.rabbitmq.username=examcloud
+spring.rabbitmq.password=examcloud
+spring.rabbitmq.listener.acknowledgeMode=MANUAL