xiatian 1 년 전
부모
커밋
11fc7e54a5

+ 25 - 0
src/main/java/cn/com/qmth/export/AnswerVo.java

@@ -0,0 +1,25 @@
+package cn.com.qmth.export;
+
+import java.util.List;
+
+public class AnswerVo {
+	private List<String> answer;
+	private List<String> subArea;
+
+	public List<String> getAnswer() {
+		return answer;
+	}
+
+	public void setAnswer(List<String> answer) {
+		this.answer = answer;
+	}
+
+	public List<String> getSubArea() {
+		return subArea;
+	}
+
+	public void setSubArea(List<String> subArea) {
+		this.subArea = subArea;
+	}
+
+}

+ 169 - 0
src/main/java/cn/com/qmth/export/Calculator.java

@@ -0,0 +1,169 @@
+package cn.com.qmth.export;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+import org.apache.commons.collections4.CollectionUtils;
+
+
+/**
+ * 计算器
+ *
+ * @author
+ * @date 2019年7月30日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class Calculator {
+
+    /**
+     * 加法 保留两位小数
+     * 
+     * @param v1
+     * @param v2
+     * @return
+     */
+    public static double add(double v1, double v2) {
+        return add(v1, v2, 2);
+
+    }
+
+    /**
+     * 加法 保留指定位小数
+     * 
+     * @param v1
+     * @param v2
+     * @param len
+     * @return
+     */
+    public static double add(double v1, double v2, int len) {
+        BigDecimal b1 = new BigDecimal(v1);
+        BigDecimal b2 = new BigDecimal(v2);
+        return b1.add(b2).setScale(len, BigDecimal.ROUND_HALF_UP).doubleValue();
+
+    }
+    
+    /** 加法 保留指定位小数
+     * @param ds
+     * @param len
+     * @return
+     */
+    public static double add(List<Double> ds, int len) {
+        if(CollectionUtils.isEmpty(ds)) {
+            throw new StatusException("数组为空");
+        }
+        BigDecimal ret = new BigDecimal(0.0);
+        for(Double d:ds) {
+            if(d==null) {
+                throw new StatusException("数组元素为空");
+            }
+            ret=ret.add(new BigDecimal(d));
+        }
+        return ret.setScale(len, BigDecimal.ROUND_HALF_UP).doubleValue();
+
+    }
+
+    /**
+     * 减法 保留两位小数
+     * 
+     * @param v1
+     * @param v2
+     * @return
+     */
+    public static double subtract(double v1, double v2) {
+        return subtract(v1, v2, 2);
+
+    }
+
+    /**
+     * 减法 保留指定位小数
+     * 
+     * @param v1
+     * @param v2
+     * @param len
+     * @return
+     */
+    public static double subtract(double v1, double v2, int len) {
+        BigDecimal b1 = new BigDecimal(v1);
+        BigDecimal b2 = new BigDecimal(v2);
+        return b1.subtract(b2).setScale(len, BigDecimal.ROUND_HALF_UP).doubleValue();
+
+    }
+    /**差值绝对值
+     * @param v1
+     * @param v2
+     * @param len
+     * @return
+     */
+    public static double absoluteDiff(double v1, double v2, int len) {
+        BigDecimal b1 = new BigDecimal(v1);
+        BigDecimal b2 = new BigDecimal(v2);
+        if(v1>v2) {
+            return b1.subtract(b2).setScale(len, BigDecimal.ROUND_HALF_UP).doubleValue();
+        }else {
+            return b2.subtract(b1).setScale(len, BigDecimal.ROUND_HALF_UP).doubleValue();
+        }
+
+    }
+    /**
+     * 乘法 保留两位小数
+     * 
+     * @param v1
+     * @param v2
+     * @return
+     */
+    public static double multiply(double v1, double v2) {
+        return multiply(v1, v2, 2);
+
+    }
+
+    /**
+     * 乘法 保留指定位小数
+     * 
+     * @param v1
+     * @param v2
+     * @param len
+     * @return
+     */
+    public static double multiply(double v1, double v2, int len) {
+        BigDecimal b1 = new BigDecimal(v1);
+        BigDecimal b2 = new BigDecimal(v2);
+        return b1.multiply(b2).setScale(len, BigDecimal.ROUND_HALF_UP).doubleValue();
+
+    }
+    
+    
+    /**
+     * 除法 保留两位小数
+     * 
+     * @param v1
+     * @param v2
+     * @param len
+     * @return
+     */
+    public static double divide(double v1, double v2) {
+        return divide(v1, v2, 2);
+    }
+
+    /**
+     * 除法 保留指定位小数
+     * 
+     * @param v1
+     * @param v2
+     * @param len
+     * @return
+     */
+    public static double divide(double v1, double v2, int len) {
+        BigDecimal b1 = new BigDecimal(v1);
+        BigDecimal b2 = new BigDecimal(v2);
+        return b1.divide(b2, len, BigDecimal.ROUND_HALF_UP).doubleValue();
+    }
+
+    public static String divide2String(Double v1, Double v2, int len) {
+        if(v1==null||v2==null||v2==0) {
+            return "-";
+        }
+        BigDecimal b1 = new BigDecimal(v1);
+        BigDecimal b2 = new BigDecimal(v2);
+        return String.valueOf(b1.divide(b2, len, BigDecimal.ROUND_HALF_UP).doubleValue());
+    }
+}

+ 36 - 0
src/main/java/cn/com/qmth/export/CusQuesStructType.java

@@ -0,0 +1,36 @@
+package cn.com.qmth.export;
+
+public enum CusQuesStructType {
+	
+	singlechoice(1,"单选题",true),
+	cloze(6,"套题",false),
+	complex(6,"套题",false),
+	textarea(5,"问答",false),
+	;
+	
+	private Integer typeId;
+	private String name;
+	private boolean objective;//是否是客观题
+	
+	private CusQuesStructType(Integer typeId, String name, boolean objective) {
+		this.typeId = typeId;
+		this.name = name;
+		this.objective = objective;
+	}
+
+	public Integer getTypeId() {
+		return typeId;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public boolean isObjective() {
+		return objective;
+	}
+	
+	
+	
+}
+

+ 55 - 0
src/main/java/cn/com/qmth/export/DetailDto.java

@@ -0,0 +1,55 @@
+package cn.com.qmth.export;
+
+public class DetailDto {
+	private String typeId;
+	private String typeName;
+	
+	
+	public DetailDto(String typeId, String typeName) {
+		super();
+		this.typeId = typeId;
+		this.typeName = typeName;
+	}
+	public String getTypeId() {
+		return typeId;
+	}
+	public void setTypeId(String typeId) {
+		this.typeId = typeId;
+	}
+	public String getTypeName() {
+		return typeName;
+	}
+	public void setTypeName(String typeName) {
+		this.typeName = typeName;
+	}
+	@Override
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((typeId == null) ? 0 : typeId.hashCode());
+		result = prime * result + ((typeName == null) ? 0 : typeName.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;
+		DetailDto other = (DetailDto) obj;
+		if (typeId == null) {
+			if (other.typeId != null)
+				return false;
+		} else if (!typeId.equals(other.typeId))
+			return false;
+		if (typeName == null) {
+			if (other.typeName != null)
+				return false;
+		} else if (!typeName.equals(other.typeName))
+			return false;
+		return true;
+	}
+	
+}

+ 2 - 2
src/main/java/cn/com/qmth/export/ExportPaperByCourseCode.java

@@ -11,9 +11,9 @@ import org.apache.log4j.Logger;
 public class ExportPaperByCourseCode {
 	private static Logger logger = LogManager.getLogger(ExportPaperByCourseCode.class);
 	//试卷后缀
-	private static String paperSuff = "(240313)";
+	private static String paperSuff = "(240318)";
 	//数据库名
-	private static String dbName="yunkai_question6";
+	private static String dbName="guangkai3";
 	private static AtomicInteger count=new AtomicInteger(0);
 	
 	public static void main(String[] args) {

+ 7 - 0
src/main/java/cn/com/qmth/export/KdPaper.java

@@ -8,6 +8,7 @@ public class KdPaper {
 	private String name;
 	private Double totalScore;
 	private Integer detailCount;
+	private Integer unitCount;
 	private List<KdDetail> details;
 	public String getCourseCode() {
 		return courseCode;
@@ -45,5 +46,11 @@ public class KdPaper {
 	public void setCourseName(String courseName) {
 		this.courseName = courseName;
 	}
+	public Integer getUnitCount() {
+		return unitCount;
+	}
+	public void setUnitCount(Integer unitCount) {
+		this.unitCount = unitCount;
+	}
 	
 }

+ 56 - 49
src/main/java/cn/com/qmth/export/KdQuestion.java

@@ -3,42 +3,43 @@ package cn.com.qmth.export;
 import java.util.List;
 
 public class KdQuestion {
-	private Long id;
-	private Integer number;
-	private YunkaiQuesStructType qst;
-	private Integer structType;
-	private Boolean objective;
+	private String id;
+	private String typeId;
+	private String detailName;
+	private CusQuesStructType cusType;
+	private QuesStructType quesStructType;
 	private YunkaiDifficulty difficulty;
 	private String body;
 	private String answer;
-	private String qtype;
 	private Boolean haveAudio;
 	private List<KdQuesOption> options;
 	private List<Long> propIds;
-	private Boolean valid;
+	private Double score;
+	private List<Double> subScores;
+	private List<KdQuestion> subQuestions;
 
-	public Integer getNumber() {
-		return number;
+	public String getId() {
+		return id;
 	}
 
-	public void setNumber(Integer number) {
-		this.number = number;
+	public void setId(String id) {
+		this.id = id;
 	}
 
-	public Integer getStructType() {
-		return structType;
+	public QuesStructType getQuesStructType() {
+		return quesStructType;
 	}
 
-	public void setStructType(Integer structType) {
-		this.structType = structType;
+	public void setQuesStructType(QuesStructType quesStructType) {
+		this.quesStructType = quesStructType;
 	}
 
-	public Boolean getObjective() {
-		return objective;
+	public YunkaiDifficulty getDifficulty() {
+		return difficulty;
 	}
 
-	public void setObjective(Boolean objective) {
-		this.objective = objective;
+	public void setDifficulty(YunkaiDifficulty difficulty) {
+		this.difficulty = difficulty;
 	}
 
 	public String getBody() {
@@ -57,6 +58,14 @@ public class KdQuestion {
 		this.answer = answer;
 	}
 
+	public Boolean getHaveAudio() {
+		return haveAudio;
+	}
+
+	public void setHaveAudio(Boolean haveAudio) {
+		this.haveAudio = haveAudio;
+	}
+
 	public List<KdQuesOption> getOptions() {
 		return options;
 	}
@@ -65,62 +74,60 @@ public class KdQuestion {
 		this.options = options;
 	}
 
-	public Long getId() {
-		return id;
+	public List<Long> getPropIds() {
+		return propIds;
 	}
 
-	public void setId(Long id) {
-		this.id = id;
+	public void setPropIds(List<Long> propIds) {
+		this.propIds = propIds;
 	}
 
-	public String getQtype() {
-		return qtype;
+	public Double getScore() {
+		return score;
 	}
 
-	public void setQtype(String qtype) {
-		this.qtype = qtype;
+	public void setScore(Double score) {
+		this.score = score;
 	}
 
-	public Boolean getHaveAudio() {
-		return haveAudio;
+	public List<Double> getSubScores() {
+		return subScores;
 	}
 
-	public void setHaveAudio(Boolean haveAudio) {
-		this.haveAudio = haveAudio;
+	public void setSubScores(List<Double> subScores) {
+		this.subScores = subScores;
 	}
 
-	public Boolean getValid() {
-		return valid;
+	public List<KdQuestion> getSubQuestions() {
+		return subQuestions;
 	}
 
-	public void setValid(Boolean valid) {
-		this.valid = valid;
+	public void setSubQuestions(List<KdQuestion> subQuestions) {
+		this.subQuestions = subQuestions;
 	}
 
-
-	public List<Long> getPropIds() {
-		return propIds;
+	public String getDetailName() {
+		return detailName;
 	}
 
-	public void setPropIds(List<Long> propIds) {
-		this.propIds = propIds;
+	public void setDetailName(String detailName) {
+		this.detailName = detailName;
 	}
 
-	public YunkaiQuesStructType getQst() {
-		return qst;
+	public CusQuesStructType getCusType() {
+		return cusType;
 	}
 
-	public void setQst(YunkaiQuesStructType qst) {
-		this.qst = qst;
+	public void setCusType(CusQuesStructType cusType) {
+		this.cusType = cusType;
 	}
 
-	public YunkaiDifficulty getDifficulty() {
-		return difficulty;
+	public String getTypeId() {
+		return typeId;
 	}
 
-	public void setDifficulty(YunkaiDifficulty difficulty) {
-		this.difficulty = difficulty;
+	public void setTypeId(String typeId) {
+		this.typeId = typeId;
 	}
 
-
 }

+ 185 - 272
src/main/java/cn/com/qmth/export/MyConsumer.java

@@ -22,12 +22,12 @@ import org.apache.commons.lang3.StringUtils;
 import com.alibaba.fastjson.JSONObject;
 
 public class MyConsumer extends Consumer<PaperExportDto> {
-	private static String[] sucStr = new String[] { "对", "正确", "√", "是", "True" };
-	private static String[] errStr = new String[] { "错", "错误", "×", "不正确", "否", "False" };
+//	private static String[] sucStr = new String[] { "对", "正确", "√", "是", "True" };
+//	private static String[] errStr = new String[] { "错", "错误", "×", "不正确", "否", "False" };
 //	private static String paperSuff = "(231205)";
 	private int maxqc = 200;
 
-	private static String paperDir = "d:/yunkai/paper/";
+	private static String paperDir = "d:/guangkai/paper/";
 
 	private Pattern imgPat = Pattern.compile("<img[^<]+src=\"([^<\"]+)\"[^<]*>");
 
@@ -39,7 +39,7 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 		try {
 			Class.forName("com.mysql.cj.jdbc.Driver");
 
-			String url = "jdbc:mysql://localhost:3306/"+dto.getDbName()+"?serverTimezone=GMT%2B8";
+			String url = "jdbc:mysql://localhost:3306/" + dto.getDbName() + "?serverTimezone=GMT%2B8";
 
 			String user = "root";
 
@@ -59,34 +59,162 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 		}
 	}
 
-	private List<KdQuestion> getQuestion(Connection connect, String courseCode) throws SQLException, IOException {
-		List<KdQuestion> qs = new ArrayList<>();
+	private List<KdQuestion> of(List<QuestionVo> vos,List<QuestionVo> subvosList) {
+		List<KdQuestion> ret=new ArrayList<>();
+		Map<String,List<QuestionVo>> submap=new HashMap<>();
+		if(CollectionUtils.isNotEmpty(subvosList)) {
+			for(QuestionVo vo:subvosList) {
+				List<QuestionVo> tem=submap.get(vo.getPid());
+				if(tem==null) {
+					tem=new ArrayList<>();
+					submap.put(vo.getPid(), tem);
+				}
+				tem.add(vo);
+			}
+		}
+		for(QuestionVo vo:vos) {
+			KdQuestion q=of(vo);
+			ret.add(q);
+			if(QuesStructType.NESTED_ANSWER_QUESTION.equals(q.getQuesStructType())) {
+				List<QuestionVo> subvos=submap.get(q.getId());
+				q.setScore((double)subvos.size());
+				List<Double> subScores=new ArrayList<>();
+				List<KdQuestion> subQues=new ArrayList<>();
+				q.setSubScores(subScores);
+				q.setSubQuestions(subQues);
+				int num=0;
+				for(QuestionVo subvo:subvos) {
+					num++;
+					subScores.add(1.0);
+					KdQuestion subq=of(subvo);
+					subq.setId(null);
+					if(CusQuesStructType.cloze.equals(q.getCusType())&&StringUtils.isBlank(subq.getBody())) {
+						subq.setBody("___"+num+"___");
+					}
+					subQues.add(subq);
+				}
+				if(CusQuesStructType.cloze.equals(q.getCusType())) {
+					q.setBody(changeCloze(q.getBody()));
+				}
+			}
+		}
+		return ret;
+	}
+	
+	private String changeCloze(String text) {
+		StringBuffer buffer = new StringBuffer();
+        String regex = "<fillblank/>";
+
+        Pattern pattern = Pattern.compile(regex);
+        Matcher matcher = pattern.matcher(text);
+        // 使用find()方法查找匹配项
+        int num=0;
+        while (matcher.find()) {
+        	num++;
+        	matcher.appendReplacement(buffer, "___"+num+"___");
+        }
+        matcher.appendTail(buffer);
+        return buffer.toString();
+	}
+	
+	private KdQuestion of(QuestionVo vo) {
+		KdQuestion q=new KdQuestion();
+		q.setCusType(vo.getqType());
+		q.setQuesStructType(QuesStructType.getQuesStructTypeById(vo.getqType().getTypeId()));
+		if(QuesStructType.SINGLE_ANSWER_QUESTION.equals(q.getQuesStructType())) {
+			List<KdQuesOption> options=new ArrayList<>();
+			q.setOptions(options);
+			int num=0;
+			boolean cel=false;
+			for(String a:vo.getAnswer().getSubArea()) {
+				num++;
+				KdQuesOption o=new KdQuesOption();
+				options.add(o);
+				o.setNumber(num);
+				o.setBody(a);
+				o.setSelect(vo.getAnswer().getAnswer().contains(""+(num-1)));
+				if(o.getSelect()) {
+					cel=true;
+				}
+			}
+			if(!cel) {
+				throw new StatusException("没有答案");
+			}
+		}
+		if(!QuesStructType.NESTED_ANSWER_QUESTION.equals(q.getQuesStructType())) {
+			q.setAnswer(StringUtils.join(vo.getAnswer().getAnswer(),""));
+		}
+		q.setTypeId(vo.getTypeId());
+		q.setDetailName(vo.getTypeName());
+		q.setBody(vo.getBody());
+		q.setDifficulty(YunkaiDifficulty.ZHONGDENG);
+		q.setHaveAudio(false);
+		q.setId(vo.getQid());
+		q.setScore(1.0);
+		return q;
+	}
+
+	private List<QuestionVo> getQuestion(Connection connect, String courseCode) throws SQLException, IOException {
+		List<QuestionVo> qs = new ArrayList<>();
 		PreparedStatement preState = null;
 		ResultSet resultSet = null;
 		try {
-			String sql = " select q.id,q.question_type,q.topic,q.difficulty,q.answer "
-					+ " from wq_question_bank_subject t " + " left join wq_subject sub on t.subject_id=sub.id"
-					+ " left join wq_question_bank b on t.question_bank_id=b.id "
-					+ " left join wq_question_question_bank f on t.question_bank_id=f.question_bank_id "
-					+ " left join wq_question q on f.question_id=q.id " + " where sub.subject_code='" + courseCode
-					+ "' and b.rent_id=811 and b.is_deleted=0 " + " and q.is_deleted=0 and q.rent_id=811 ";
+			String sql = " select q.TYPE_ID typeId,f.name typeName,f.ANSWER_TYPE qType " + " ,q.ID qid,q.TITLE body,q.FATHER_ID pid "
+					+ " ,q.answer,q.SHOW_ORDER seq  " + " from pe_question_bank t  "
+					+ " INNER JOIN pe_questions q on t.id=q.BANK_ID "
+					+ " INNER JOIN pe_question_type f on f.id=q.TYPE_ID " + " where t.course_id=" + courseCode;
 
 			preState = connect.prepareStatement(sql);
 
 			resultSet = preState.executeQuery();
 
 			while (resultSet.next()) {
-				KdQuestion q = new KdQuestion();
-				q.setId(resultSet.getLong("id"));
-				q.setBody(disposeImg(resultSet.getString("topic"), courseCode));
-				q.setQst(YunkaiQuesStructType.getByYunKaiType(resultSet.getInt("question_type")));
-				q.setDifficulty(YunkaiDifficulty.getByYunKaiType(resultSet.getInt("difficulty")));
-//				if (!q.getQst().isObjective()) {
-//					continue;
-//				}
-//				q.setDifficulty(YunkaiDifficulty.ZHONGDENG);
-				q.setAnswer(disposeImg(resultSet.getString("answer"), courseCode));
-				q.setObjective(q.getQst().isObjective());
+				QuestionVo q = new QuestionVo();
+				q.setQid(resultSet.getString("qid"));
+				q.setTypeId(resultSet.getString("typeId"));
+				q.setTypeName(resultSet.getString("typeName"));
+				q.setPid(resultSet.getString("pid"));
+				q.setqType(CusQuesStructType.valueOf(resultSet.getString("qType")));
+				q.setBody(disposeImg(resultSet.getString("body"), courseCode));
+				q.setAnswer(JSONObject.parseObject(resultSet.getString("answer"), AnswerVo.class));
+				q.setSeq(resultSet.getInt("seq"));
+				qs.add(q);
+			}
+			return qs;
+		} finally {
+			if (resultSet != null) {
+				resultSet.close();
+			}
+			if (preState != null) {
+				preState.close();
+			}
+		}
+	}
+
+	private List<QuestionVo> getSubQuestion(Connection connect, String courseCode, List<String> pids)
+			throws SQLException, IOException {
+		List<QuestionVo> qs = new ArrayList<>();
+		PreparedStatement preState = null;
+		ResultSet resultSet = null;
+		try {
+			String sql = " select f.name typeName,f.ANSWER_TYPE qType " + " ,q.ID qid,q.TITLE body,q.FATHER_ID pid "
+					+ " ,q.answer,q.SHOW_ORDER seq  " + " from  pe_questions q  "
+					+ " INNER JOIN pe_question_type f on f.id=q.TYPE_ID " + " where q.FATHER_ID in ('"
+					+ StringUtils.join(pids, "','") + "') order by q.SHOW_ORDER";
+
+			preState = connect.prepareStatement(sql);
+
+			resultSet = preState.executeQuery();
+
+			while (resultSet.next()) {
+				QuestionVo q = new QuestionVo();
+				q.setQid(resultSet.getString("qid"));
+				q.setTypeName(resultSet.getString("typeName"));
+				q.setPid(resultSet.getString("pid"));
+				q.setqType(CusQuesStructType.valueOf(resultSet.getString("qType")));
+				q.setBody(disposeImg(resultSet.getString("body"), courseCode));
+				q.setAnswer(JSONObject.parseObject(resultSet.getString("answer"), AnswerVo.class));
+				q.setSeq(resultSet.getInt("seq"));
 				qs.add(q);
 			}
 			return qs;
@@ -125,263 +253,35 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 		return str;
 	}
 
-	private List<QuestionProp> getQuestionProp(Connection connect, List<KdQuestion> qs) {
-		List<QuestionProp> as = new ArrayList<>();
-		List<Long> ids = qs.stream().map(e -> e.getId()).collect(Collectors.toList());
-		String idsstr = StringUtils.join(ids, ",");
-		PreparedStatement preState = null;
-		ResultSet resultSet = null;
-		try {
-			String sql = " select t.knowledge_system_id,t.question_id " + " from wq_question_knowledge_system t "
-					+ " where t.question_id in (" + idsstr + ") ";
-			preState = connect.prepareStatement(sql);
-
-			resultSet = preState.executeQuery();
-
-			while (resultSet.next()) {
-				QuestionProp a = new QuestionProp();
-				a.setKnowledgeId(resultSet.getLong("knowledge_system_id"));
-				a.setQuestionId(resultSet.getLong("question_id"));
-				as.add(a);
-			}
-			return as;
-		} catch (Exception e1) {
-			throw new RuntimeException(e1);
-		} finally {
-			if (resultSet != null) {
-				try {
-					resultSet.close();
-				} catch (SQLException e1) {
-				}
-			}
-			if (preState != null) {
-				try {
-					preState.close();
-				} catch (SQLException e1) {
-				}
-			}
-		}
-	}
-
-	private void fillProp(Connection connect, List<KdQuestion> qs) {
-		List<QuestionProp> qps = new BatchGetDataUtil<QuestionProp, KdQuestion>() {
-
-			@Override
-			protected List<QuestionProp> getData(List<KdQuestion> paramList) {
-				return getQuestionProp(connect, paramList);
-			}
-		}.getDataForBatch(qs, 200);
-		if (CollectionUtils.isEmpty(qps)) {
-			return;
-		}
-		Map<Long, KdQuestion> map = new HashMap<>();
-		for (KdQuestion q : qs) {
-			map.put(q.getId(), q);
-		}
-		for (QuestionProp qp : qps) {
-			KdQuestion q = map.get(qp.getQuestionId());
-			List<Long> qpids = q.getPropIds();
-			if (qpids == null) {
-				qpids = new ArrayList<>();
-				q.setPropIds(qpids);
-			}
-			qpids.add(qp.getKnowledgeId());
-		}
-	}
-
-	private void fillAnswer(Connection connect, List<KdQuestion> qs, String courseCode) {
-		List<Answer> qps = new BatchGetDataUtil<Answer, KdQuestion>() {
-
-			@Override
-			protected List<Answer> getData(List<KdQuestion> paramList) {
-				return getAnswerBatch(connect, paramList, courseCode);
-			}
-		}.getDataForBatch(qs, 200);
-		if (CollectionUtils.isEmpty(qps)) {
-			return;
-		}
-
-		Map<Long, List<Answer>> map = new HashMap<>();
-		for (Answer qp : qps) {
-			List<Answer> list = map.get(qp.getQuestionId());
-			if (list == null) {
-				list = new ArrayList<>();
-				map.put(qp.getQuestionId(), list);
-			}
-			list.add(qp);
-		}
-
-		for (KdQuestion q : qs) {
-			if (YunkaiQuesStructType.DANXUAN.equals(q.getQst())) {
-				List<KdQuesOption> ops = new ArrayList<>();
-				q.setOptions(ops);
-				int num = 0;
-				for (Answer a : map.get(q.getId())) {
-					num++;
-					KdQuesOption op = new KdQuesOption();
-					ops.add(op);
-					op.setNumber(num);
-					op.setBody(a.getBody());
-					op.setSelect(a.getRight() == 1);
-					if (op.getSelect()) {
-						q.setAnswer(getOptionNum(num));
-					}
-				}
-			} else if (YunkaiQuesStructType.DUOXUAN.equals(q.getQst())
-					|| YunkaiQuesStructType.BUDINGXIANG.equals(q.getQst())) {
-				List<String> as = new ArrayList<>();
-				List<KdQuesOption> ops = new ArrayList<>();
-				q.setOptions(ops);
-				int num = 0;
-				for (Answer a : map.get(q.getId())) {
-					num++;
-					KdQuesOption op = new KdQuesOption();
-					ops.add(op);
-					op.setNumber(num);
-					op.setBody(a.getBody());
-					op.setSelect(a.getRight() == 1);
-					if (op.getSelect()) {
-						as.add(getOptionNum(num));
-					}
-				}
-				q.setAnswer(StringUtils.join(as, ","));
-			} else if (YunkaiQuesStructType.PANDUAN.equals(q.getQst())) {
-				for (Answer a : map.get(q.getId())) {
-					if (a.getRight() == 1) {
-						q.setAnswer(getBool(a.getBody()));
-					}
-				}
-
-			} else if (YunkaiQuesStructType.TIANKONGTI.equals(q.getQst())) {
-				q.setBody(relaceQuestionIdx(q.getBody()));
-				if (map.get(q.getId()) != null) {
-					List<String> as = new ArrayList<>();
-					try {
-						for (Answer a : map.get(q.getId())) {
-							if (a.getRight() == 1) {
-								as.add(a.getBody());
-							}
-						}
-					} catch (Exception e) {
-						throw e;
-					}
-					q.setAnswer(StringUtils.join(as, "##"));
-				}
-			} else {
-				// nothing
-			}
-		}
-	}
-
-	private String relaceQuestionIdx(String str) {
-		StringBuffer sb = new StringBuffer("");
-		Pattern pattern = Pattern.compile("__(\\d+)__");
-
-		Matcher matcher = pattern.matcher(str);
-
-		while (matcher.find()) {
-			matcher.appendReplacement(sb, "###");
-		}
-
-		if (StringUtils.isEmpty(sb.toString())) {
-			return str;
-		} else {
-			matcher.appendTail(sb);
-			return sb.toString();
-		}
-	}
-
-	/**
-	 * 将数字1,2,3,4转化成A,B,C,D
-	 *
-	 * @param number
-	 * @return
-	 */
-	private String getOptionNum(int number) {
-		char optionNum = (char) (65 + number);
-		return String.valueOf(optionNum);
-	}
-
-	private String getBool(String val) {
-		String valid = "错答案:正确";
-		if (val.contains(valid)) {
-			return "正确";
-		}
-		for (String suc : sucStr) {
-			if (val.contains(suc)) {
-				return "正确";
-			}
-		}
-		for (String err : errStr) {
-			if (val.contains(err)) {
-				return "错误";
-			}
-		}
-		return "正确";
-	}
-
-	private List<Answer> getAnswerBatch(Connection connect, List<KdQuestion> qs, String courseCode) {
-		List<Answer> as = new ArrayList<>();
-		List<Long> ids = qs.stream().map(e -> e.getId()).collect(Collectors.toList());
-		String idsstr = StringUtils.join(ids, ",");
-		PreparedStatement preState = null;
-		ResultSet resultSet = null;
-		try {
-			String sql = " select t.question_id,t.answer_text,t.is_right " + " from wq_question_answer_item t "
-					+ " where t.question_id in (" + idsstr + ")  " + " order by t.question_id,t.sequence ";
-			preState = connect.prepareStatement(sql);
-
-			resultSet = preState.executeQuery();
-
-			while (resultSet.next()) {
-				Answer a = new Answer();
-				a.setBody(disposeImg(resultSet.getString("answer_text"), courseCode));
-				a.setRight(resultSet.getInt("is_right"));
-				a.setQuestionId(resultSet.getLong("question_id"));
-				as.add(a);
-			}
-			return as;
-		} catch (Exception e1) {
-			throw new RuntimeException(e1);
-		} finally {
-			if (resultSet != null) {
-				try {
-					resultSet.close();
-				} catch (SQLException e1) {
-				}
-			}
-			if (preState != null) {
-				try {
-					preState.close();
-				} catch (SQLException e1) {
-				}
-			}
-		}
-	}
 
 	private void exportPaper(Connection connect, PaperExportDto dto) throws Exception {
-		List<KdQuestion> qs = getQuestion(connect, dto.getCourseCode());
-		if (qs.size() == 0) {
+		List<QuestionVo> vos = getQuestion(connect, dto.getCourseCode());
+		if (CollectionUtils.isEmpty(vos)) {
 			return;
 		}
-		fillProp(connect, qs);
-		fillAnswer(connect, qs, dto.getCourseCode());
-
-		Map<YunkaiQuesStructType, List<KdQuestion>> qmap = new HashMap<>();
+		List<String> pids = vos.stream().filter(e -> e.getqType().getTypeId() == 6).map(QuestionVo::getQid)
+				.collect(Collectors.toList());
+		List<QuestionVo> subvos = getSubQuestion(connect, dto.getCourseCode(),pids);
+		List<KdQuestion> qs=of(vos,subvos);
+//		fillProp(connect, qs);
+//		fillAnswer(connect, qs, dto.getCourseCode());
+
+		Map<DetailDto, List<KdQuestion>> qmap = new HashMap<>();
 		for (KdQuestion q : qs) {
-			List<KdQuestion> list = qmap.get(q.getQst());
+			DetailDto tem=new DetailDto(q.getTypeId(), q.getDetailName());
+			List<KdQuestion> list = qmap.get(tem);
 			if (list == null) {
 				list = new ArrayList<>();
-				qmap.put(q.getQst(), list);
+				qmap.put(tem, list);
 			}
 			list.add(q);
 		}
-		for (YunkaiQuesStructType qt : qmap.keySet()) {
+		for (DetailDto qt : qmap.keySet()) {
 			createPapers(qmap.get(qt), qt, dto);
 		}
 	}
 
-	private void createPapers(List<KdQuestion> qs, YunkaiQuesStructType qt, PaperExportDto dto) {
+	private void createPapers(List<KdQuestion> qs, DetailDto qt, PaperExportDto dto) {
 		if (qs == null || qs.size() == 0) {
 			return;
 		}
@@ -400,26 +300,39 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 
 	}
 
-	private void createPaper(List<KdQuestion> qs, YunkaiQuesStructType qt, PaperExportDto dto, int indx) {
+	private void createPaper(List<KdQuestion> qs, DetailDto qt, PaperExportDto dto, int indx) {
 		if (qs.size() == 0) {
 			return;
 		}
-		String detailName = qt.getYunKaiDesc();
+		double score=0.0;
+		int unit=0;
+		for(KdQuestion q:qs) {
+			if(CollectionUtils.isNotEmpty(q.getSubQuestions())) {
+				unit=unit+q.getSubQuestions().size();
+			}else {
+				unit++;
+			}
+			score=Calculator.add(score, q.getScore(),1);
+		}
+		String detailName = qt.getTypeName();
 		KdPaper paper = new KdPaper();
-		paper.setTotalScore((double) qs.size());
+		paper.setDetailCount(1);
+		paper.setUnitCount(unit);
+		paper.setTotalScore(score);
 		paper.setName(dto.getPaperSuff() + detailName + "_" + indx);
 		paper.setCourseCode(dto.getCourseCode());
 		List<KdDetail> des = new ArrayList<>();
 		KdDetail d = new KdDetail();
 		d.setName(detailName);
 		d.setNumber(1);
-		d.setQuestionCount(qs.size());
-		d.setTotalScore((double) qs.size());
+		d.setQuestionCount(unit);
+		d.setTotalScore(score);
 		d.setQuestions(qs);
 		des.add(d);
 		paper.setDetails(des);
 		paper.setDetailCount(1);
-		File paperdir = new File(paperDir + dto.getCourseCode() + "/" + qt.getYunKaiType() + "/");
+		paper.setUnitCount(qs.size());
+		File paperdir = new File(paperDir + dto.getCourseCode() + "/" + qt.getTypeId()+ "/");
 		paperdir.mkdirs();
 		try {
 			FileUtil.writeFile(paperdir.getAbsolutePath(), "/paper_" + indx + ".json", JSONObject.toJSONString(paper));

+ 2 - 2
src/main/java/cn/com/qmth/export/MyProducer.java

@@ -15,8 +15,8 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 public class MyProducer extends Producer {
 	private static Logger logger = LogManager.getLogger(MyProducer.class);
-	private static String dir = "d:/yunkai/";
-	private static String paperDir = "d:/yunkai/paper/";
+	private static String dir = "d:/guangkai/";
+	private static String paperDir = "d:/guangkai/paper/";
 
 	@Override
 	protected void produce(Map<String, Object> param) throws Exception {

+ 77 - 0
src/main/java/cn/com/qmth/export/QuesStructType.java

@@ -0,0 +1,77 @@
+package cn.com.qmth.export;
+
+public enum QuesStructType {
+
+    /**
+     * 单选
+     */
+    SINGLE_ANSWER_QUESTION(1, "单选", true, false),
+    /**
+     * 多选
+     */
+    MULTIPLE_ANSWER_QUESTION(2, "多选", true, false),
+    /**
+     * 判断
+     */
+    BOOL_ANSWER_QUESTION(3, "判断", true, false),
+    /**
+     * 填空
+     */
+    FILL_BLANK_QUESTION(4, "填空", false, false),
+    /**
+     * 问答
+     */
+    TEXT_ANSWER_QUESTION(5, "问答", false, false),
+    /**
+     * 套题
+     */
+    NESTED_ANSWER_QUESTION(6, "套题", false, true);
+
+    private Integer id;
+    private String name;
+    private boolean objective;//是否是客观题
+    private boolean combline;//是否是组合题
+
+    QuesStructType(Integer id, String name, boolean objective, boolean combline) {
+        this.id = id;
+        this.name = name;
+        this.objective = objective;
+        this.combline = combline;
+    }
+
+    /**
+     * 通过ID获取试题类型
+     *
+     * @param id
+     * @return
+     */
+    public static QuesStructType getQuesStructTypeById(Integer id) {
+        for (QuesStructType type : QuesStructType.values()) {
+            if (id.equals(type.getId())) {
+                return type;
+            }
+        }
+        return null;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public boolean isObjective() {
+        return objective;
+    }
+
+    public boolean isCombline() {
+        return combline;
+    }
+
+    public String toString() {
+        return getName();
+    }
+
+}

+ 0 - 26
src/main/java/cn/com/qmth/export/Question.java

@@ -1,26 +0,0 @@
-package cn.com.qmth.export;
-
-public class Question {
-	private String body;
-	private String answer;
-	private String type;
-	public String getBody() {
-		return body;
-	}
-	public void setBody(String body) {
-		this.body = body;
-	}
-	public String getAnswer() {
-		return answer;
-	}
-	public void setAnswer(String answer) {
-		this.answer = answer;
-	}
-	public String getType() {
-		return type;
-	}
-	public void setType(String type) {
-		this.type = type;
-	}
-	
-}

+ 77 - 0
src/main/java/cn/com/qmth/export/QuestionVo.java

@@ -0,0 +1,77 @@
+package cn.com.qmth.export;
+
+public class QuestionVo {
+	private String typeId;
+	private String typeName;
+	private CusQuesStructType qType;
+	private String qid;
+	private String body;
+	private String pid;
+	private AnswerVo answer;
+	private Integer seq;
+
+	public String getTypeName() {
+		return typeName;
+	}
+
+	public void setTypeName(String typeName) {
+		this.typeName = typeName;
+	}
+
+	public CusQuesStructType getqType() {
+		return qType;
+	}
+
+	public void setqType(CusQuesStructType qType) {
+		this.qType = qType;
+	}
+
+	public String getQid() {
+		return qid;
+	}
+
+	public void setQid(String qid) {
+		this.qid = qid;
+	}
+
+	public String getBody() {
+		return body;
+	}
+
+	public void setBody(String body) {
+		this.body = body;
+	}
+
+	public String getPid() {
+		return pid;
+	}
+
+	public void setPid(String pid) {
+		this.pid = pid;
+	}
+
+	public AnswerVo getAnswer() {
+		return answer;
+	}
+
+	public void setAnswer(AnswerVo answer) {
+		this.answer = answer;
+	}
+
+	public Integer getSeq() {
+		return seq;
+	}
+
+	public void setSeq(Integer seq) {
+		this.seq = seq;
+	}
+
+	public String getTypeId() {
+		return typeId;
+	}
+
+	public void setTypeId(String typeId) {
+		this.typeId = typeId;
+	}
+
+}

+ 0 - 109
src/main/java/cn/com/qmth/export/YunkaiQuesStructType.java

@@ -1,109 +0,0 @@
-package cn.com.qmth.export;
-
-public enum YunkaiQuesStructType {
-	
-	DANXUAN(1,"单选题",1,"单选题",true),
-	DUOXUAN(2,"多选题",2,"多选题",true),
-	BUDINGXIANG(3,"不定项选择题",2,"多选题",true),
-	PANDUAN(4,"判断题",3,"判断题",true),
-	JIANDA(5,"简答题",5,"问答题",false),
-	MIGNCIJIESHI(6,"名词解释",5,"问答题",false),
-	LIJIETI(7,"理解题",5,"问答题",false),
-	ANLITI(8,"案例题",5,"问答题",false),
-	LUNSHUTI(9,"论述题",5,"问答题",false),
-	FENXITI(10,"分析题",5,"问答题",false),
-	ZONGHETI(11,"综合题",5,"问答题",false),
-	JISUANTI(12,"计算题",5,"问答题",false),
-	TIANKONGTI(13,"填空题",4,"填空题",false),
-	;
-	
-	private Integer yunKaiType;
-	private String yunKaiDesc;
-	private Integer type;
-	private String desc;
-	private boolean objective;//是否是客观题
-	
-	private YunkaiQuesStructType(Integer yunKaiType, String yunKaiDesc, Integer type, String desc, boolean objective) {
-		this.yunKaiType = yunKaiType;
-		this.yunKaiDesc = yunKaiDesc;
-		this.type = type;
-		this.desc = desc;
-		this.objective = objective;
-	}
-	
-	
-		
-	public Integer getYunKaiType() {
-		return yunKaiType;
-	}
-
-
-
-	public void setYunKaiType(Integer yunKaiType) {
-		this.yunKaiType = yunKaiType;
-	}
-
-
-
-	public String getYunKaiDesc() {
-		return yunKaiDesc;
-	}
-
-
-
-	public void setYunKaiDesc(String yunKaiDesc) {
-		this.yunKaiDesc = yunKaiDesc;
-	}
-
-
-
-	public Integer getType() {
-		return type;
-	}
-
-
-
-	public void setType(Integer type) {
-		this.type = type;
-	}
-
-
-
-	public String getDesc() {
-		return desc;
-	}
-
-
-
-	public void setDesc(String desc) {
-		this.desc = desc;
-	}
-
-
-
-	public boolean isObjective() {
-		return objective;
-	}
-
-
-
-	public void setObjective(boolean objective) {
-		this.objective = objective;
-	}
-
-
-
-	public static YunkaiQuesStructType getByYunKaiType(Integer yunKaiType) {
-		if(yunKaiType==null) {
-			throw new RuntimeException("题型异常");
-		}
-		for(YunkaiQuesStructType t:YunkaiQuesStructType.values()) {
-			if(t.getYunKaiType().equals(yunKaiType)) {
-				return t;
-			}
-		}
-		throw new RuntimeException("题型异常");
-	}
-	
-}
-