xiatian 1 年之前
父節點
當前提交
c84e84262c

+ 14 - 5
src/main/java/cn/com/qmth/export/Answer.java

@@ -1,9 +1,10 @@
 package cn.com.qmth.export;
 
 public class Answer {
+	private Long aId;
 	private Long questionId;
 	private String body;
-	private Integer right;
+	private Double fraction;
 
 	public String getBody() {
 		return body;
@@ -13,12 +14,12 @@ public class Answer {
 		this.body = body;
 	}
 
-	public Integer getRight() {
-		return right;
+	public Double getFraction() {
+		return fraction;
 	}
 
-	public void setRight(Integer right) {
-		this.right = right;
+	public void setFraction(Double fraction) {
+		this.fraction = fraction;
 	}
 
 	public Long getQuestionId() {
@@ -29,4 +30,12 @@ public class Answer {
 		this.questionId = questionId;
 	}
 
+	public Long getaId() {
+		return aId;
+	}
+
+	public void setaId(Long aId) {
+		this.aId = aId;
+	}
+
 }

+ 35 - 0
src/main/java/cn/com/qmth/export/CusQuesStructType3.java

@@ -0,0 +1,35 @@
+package cn.com.qmth.export;
+
+public enum CusQuesStructType3 {
+	
+	multichoice(1,"单选题",true),
+	multichoiceset(1,"单选题",true),
+	truefalse(3,"判断题",true),
+	;
+	
+	private Integer typeId;
+	private String name;
+	private boolean objective;//是否是客观题
+	
+	private CusQuesStructType3(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;
+	}
+	
+	
+	
+}
+

+ 46 - 39
src/main/java/cn/com/qmth/export/ExportGkProperty.java

@@ -24,14 +24,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 import com.alibaba.fastjson.JSONObject;
 
-/**moodle导出属性
- * @author Administrator
- *
- */
 public class ExportGkProperty {
 	private static Logger logger = LogManager.getLogger(ExportGkProperty.class);
-	private static String dbName="yunkai_question6";
-	private final static String sourceDir = "d:/yunkai/";
+	private static String dbName="guangkai_mdl";
+	private final static String sourceDir = "d:/guangkai/";
 	public static void main(String[] args) {
 		logger.debug("导出开始");
 		try {
@@ -81,12 +77,16 @@ public class ExportGkProperty {
 		System.out.println("总科目数:"+subjectCodes.size());
 		int total=0;
 		for(String code:subjectCodes) {
-			List<PropertyDto> props=getProperty(connect, code);
-			if(CollectionUtils.isNotEmpty(props)) {
-				total++;
-				FileUtil.writeFile(sourceDir+"prop/", code+".json", JSONObject.toJSONString(props));
-			}else {
-				System.out.println("无文件:"+code);
+			try {
+				List<PropertyDto> props=getProperty(connect, code);
+				if(CollectionUtils.isNotEmpty(props)) {
+					total++;
+					FileUtil.writeFile(sourceDir+"prop/", code+".json", JSONObject.toJSONString(props));
+				}else {
+					System.out.println("无文件:"+code);
+				}
+			}catch (Exception e) {
+				throw new RuntimeException("courseCode:"+code,e);
 			}
 		}
 		System.out.println("文件数:"+total);
@@ -100,7 +100,12 @@ public class ExportGkProperty {
 			int rows = sheet.getLastRowNum();
 			for (int i = 1; i <= rows; i++) {
 				XSSFRow row = sheet.getRow(i);
-				String code = row.getCell(1).getStringCellValue().trim();
+				String code;
+				try {
+					code = row.getCell(1).getStringCellValue().trim();
+				} catch (Exception e) {
+					code = (row.getCell(1).getNumericCellValue()+"").trim();
+				}
 				list.add(code);
 			}
 		} catch (IOException e) {
@@ -121,42 +126,35 @@ public class ExportGkProperty {
 		PreparedStatement preState = null;
 		ResultSet resultSet = null;
 		try {
-			String sql = " select k.id,k.parent_id,k.type_name,k.type_seq,k.root_id from wq_knowledge_system k "
-					+" where k.root_id in "
-					+" (select DISTINCT ss.root_id "
-					+" 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 "
-					+" left join wq_question_knowledge_system s on f.question_id=s.question_id "
-					+" left join wq_knowledge_system ss on s.knowledge_system_id=ss.id "
-					+" where sub.subject_code='"+subjectCode+"' and b.rent_id=811 and b.is_deleted=0 "
-					+" and q.is_deleted=0 and q.rent_id=811) "
-					+" ORDER BY k.id ";
+			String sql = " select qc.* from mdl_course c "
+					+" inner join mdl_context ct on c.id=ct.instanceid "
+					+" inner join mdl_question_categories qc on ct.id=qc.contextid "
+					+" where c.idnumber='"+subjectCode+"' "
+					+" order by qc.level,qc.sortorder,qc.id ";
 			preState = connect.prepareStatement(sql);
 
 			resultSet = preState.executeQuery();
 			Map<Long,PropertyDto> map=new HashMap<>();
 			while (resultSet.next()) {
-				Long rootId=resultSet.getLong("root_id");
 				PropertyDto a = new PropertyDto();
 				a.setId(resultSet.getLong("id"));
-				a.setParentId(resultSet.getLong("parent_id"));
-				a.setName(resultSet.getString("type_name"));
-				if(a.getParentId()==0) {
-					as.add(a);
-				}else {
+				a.setParentId(resultSet.getLong("parent"));
+				a.setName(resultSet.getString("name"));
+				map.put(a.getId(), a);
+				if(a.getParentId()!=0) {
 					PropertyDto parent=map.get(a.getParentId());
-					if(parent.getParentId()==0) {
-						a.setName(a.getName());
-					}else {
-						a.setName(parent.getName()+"|"+a.getName());
+					try {
+						if (parent.getParentId() == 0) {
+							as.add(a);
+						} else {
+							a.setName(parent.getName() + "|" + a.getName());
+							PropertyDto root = getRoot(map, a);
+							root.addSub(a);
+						} 
+					} catch (Exception e) {
+						throw e;
 					}
-					PropertyDto root=map.get(rootId);
-					root.addSub(a);
 				}
-				map.put(a.getId(), a);
 			}
 			return as;
 		} finally {
@@ -168,4 +166,13 @@ public class ExportGkProperty {
 			}
 		}
 	}
+	
+	private static PropertyDto getRoot(Map<Long,PropertyDto> map,PropertyDto cur) {
+		PropertyDto parent=map.get(cur.getParentId());
+		if(parent.getParentId()==0) {
+			return cur;
+		}else {
+			return getRoot(map, parent);
+		}
+	}
 }

+ 11 - 4
src/main/java/cn/com/qmth/export/GkExportPaperByCourseCode3.java

@@ -15,29 +15,32 @@ import org.apache.log4j.Logger;
 public class GkExportPaperByCourseCode3 {
 	private static Logger logger = LogManager.getLogger(GkExportPaperByCourseCode3.class);
 	//试卷后缀
-	private static String paperSuff = "(240407)";
+	private static String paperSuff = "(240524)";
 	//数据库名
-	private static String dbName="guangkai2";
+	private static String dbName="guangkai_mdl";
 	private static AtomicInteger count=new AtomicInteger(0);
 	
 	private static AtomicInteger valid=new AtomicInteger(0);
 	
+	private static AtomicInteger imgValid=new AtomicInteger(0);
+	
 	private static AtomicInteger rectify=new AtomicInteger(0);
 	
 	public static void main(String[] args) {
 		logger.debug("导出开始");
 		Date start=new Date();
 		try {
-			MyProducer pro=new MyProducer();
+			MyProducer3 pro=new MyProducer3();
 			Map<String, Object> param=new HashMap<>();
 			param.put("paperSuff", paperSuff);
 			param.put("dbName", dbName);
-			pro.startDispose(MyConsumer.class, 8, param);
+			pro.startDispose(MyConsumer3.class, 8, param);
 		} catch (Exception e) {
 			logger.error(e.getCause(), e);
 		}
 		logger.debug("导出结束,纠正:"+rectify);
 		logger.debug("导出结束,舍弃:"+valid);
+		logger.debug("导出结束,(图片)舍弃:"+imgValid);
 		Date end=new Date();
 		logger.debug("导出结束,耗时:"+((end.getTime()-start.getTime())/1000));
 	}
@@ -54,4 +57,8 @@ public class GkExportPaperByCourseCode3 {
 	public static void  addValid() {
 		valid.addAndGet(1);
 	}
+	
+	public static void  addImgValid() {
+		imgValid.addAndGet(1);
+	}
 }

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

@@ -1,6 +1,7 @@
 package cn.com.qmth.export;
 
 public class KdQuesOption {
+	private Long id;
 	private Boolean select;
 	private Integer number;
 	private String body;
@@ -22,5 +23,11 @@ public class KdQuesOption {
 	public void setSelect(Boolean select) {
 		this.select = select;
 	}
+	public Long getId() {
+		return id;
+	}
+	public void setId(Long id) {
+		this.id = id;
+	}
 	
 }

+ 9 - 0
src/main/java/cn/com/qmth/export/KdQuestion.java

@@ -3,6 +3,7 @@ package cn.com.qmth.export;
 import java.util.List;
 
 public class KdQuestion {
+	private boolean valid=true;
 	private String pname;
 	private String tname;
 	private String cname;
@@ -167,4 +168,12 @@ public class KdQuestion {
 		this.difficultyDegree = difficultyDegree;
 	}
 
+	public boolean isValid() {
+		return valid;
+	}
+
+	public void setValid(boolean valid) {
+		this.valid = valid;
+	}
+
 }

+ 6 - 5
src/main/java/cn/com/qmth/export/Knowledge.java

@@ -9,7 +9,7 @@ public class Knowledge {
 
 	private Long parentId;
 
-	private Long rootId;
+	private Integer level;
 
 	public Long getId() {
 		return id;
@@ -27,12 +27,13 @@ public class Knowledge {
 		this.parentId = parentId;
 	}
 
-	public Long getRootId() {
-		return rootId;
+	public Integer getLevel() {
+		return level;
 	}
 
-	public void setRootId(Long rootId) {
-		this.rootId = rootId;
+	public void setLevel(Integer level) {
+		this.level = level;
 	}
 
+
 }

+ 435 - 0
src/main/java/cn/com/qmth/export/MyConsumer3.java

@@ -0,0 +1,435 @@
+package cn.com.qmth.export;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import com.alibaba.fastjson.JSONObject;
+
+public class MyConsumer3 extends Consumer<PaperExportDto> {
+//	private static String[] sucStr = new String[] { "对", "正确", "√", "是", "True" };
+//	private static String[] errStr = new String[] { "错", "错误", "×", "不正确", "否", "False" };
+//	private static String paperSuff = "(231205)";
+	private int maxqc = 200000;
+
+	private static String paperDir = "d:/guangkai/paper/";
+	private static String imgDir = "d:/guangkai/files/";
+
+	private static Pattern imgPat = Pattern.compile("<img[^<]+src=['\"]([^<\"]+)['\"][^<]*>");
+	
+//	private Pattern xieGangPat = Pattern.compile("\\\\([^\"]|(\",))");
+
+	@Override
+	public void consume(PaperExportDto dto) {
+		Connection connect = null;
+		File sub = new File(paperDir + dto.getCourseCode() + "/");
+		sub.mkdir();
+		try {
+			Class.forName("com.mysql.cj.jdbc.Driver");
+
+			String url = "jdbc:mysql://localhost:3306/" + dto.getDbName() + "?serverTimezone=GMT%2B8";
+
+			String user = "root";
+
+			String password = "123456";
+			connect = DriverManager.getConnection(url, user, password);
+			exportPaper(connect, dto);
+			GkExportPaperByCourseCode.addDisposeCount();
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		} finally {
+			if (connect != null) {
+				try {
+					connect.close();
+				} catch (SQLException e) {
+				}
+			}
+		}
+	}
+
+	private List<KdQuestion> of(List<QuestionVo3> vos) {
+		List<KdQuestion> ret = new ArrayList<>();
+		for (QuestionVo3 vo : vos) {
+			try {
+				KdQuestion q = of(vo);
+				ret.add(q);
+			} catch (StatusException e) {
+				GkExportPaperByCourseCode.addValid();
+				continue;
+			}
+		}
+		return ret;
+	}
+
+
+
+	private KdQuestion of(QuestionVo3 vo) {
+		KdQuestion q = new KdQuestion();
+		q.setPropIds(new ArrayList<>());
+		q.getPropIds().add(vo.getCategory());
+		q.setQuesStructType(QuesStructType.getQuesStructTypeById(vo.getqType().getTypeId()));
+		q.setBody(vo.getBody());
+		q.setDifficultyDegree(0.5);
+		q.setHaveAudio(false);
+		q.setId(vo.getQid().toString());
+		q.setScore(1.0);
+		return q;
+	}
+
+	private List<QuestionVo3> getQuestion(Connection connect, String courseCode) throws SQLException, IOException {
+		List<QuestionVo3> qs = new ArrayList<>();
+		PreparedStatement preState = null;
+		ResultSet resultSet = null;
+		try {
+			String sql = " select q.* from mdl_course c "
+					+" inner join mdl_context ct on ct.instanceid=c.id "
+					+" inner join mdl_question_categories qc on qc.contextid=ct.id "
+					+" inner join mdl_question q on q.category=qc.id "
+					+" where c.idnumber='"+courseCode+"' and q.qtype in('multichoice','multichoiceset','truefalse') "
+					+" and q.parent=0 ";
+
+			preState = connect.prepareStatement(sql);
+
+			resultSet = preState.executeQuery();
+
+			while (resultSet.next()) {
+				QuestionVo3 q = new QuestionVo3();
+				q.setQid(resultSet.getLong("id"));
+				q.setPid(resultSet.getLong("parent"));
+				q.setCategory(resultSet.getLong("category"));
+				q.setqType(CusQuesStructType3.valueOf(resultSet.getString("qType")));
+				q.setBody(resultSet.getString("questiontext"));
+				qs.add(q);
+			}
+			return qs;
+		} finally {
+			if (resultSet != null) {
+				resultSet.close();
+			}
+			if (preState != null) {
+				preState.close();
+			}
+		}
+	}
+	
+	
+//	public static void main(String[] args) {
+//		String s="a\"\\\",b\\h";
+//		System.out.println(s);
+//		System.out.println(fomat(s));
+//	}
+	
+	
+
+	private void disposeQuestionImg(Connection connect,String courseCode,KdQuestion q) throws NumberFormatException, SQLException {
+		q.setBody(disposeImg(connect, courseCode, "questiontext", q.getBody(), Long.valueOf(q.getId())));
+		if (CollectionUtils.isNotEmpty(q.getOptions())) {
+			for (KdQuesOption o : q.getOptions()) {
+				o.setBody(disposeImg(connect, courseCode, "answer", o.getBody(), Long.valueOf(o.getId())));
+			}
+		}
+	}
+
+	private String disposeImg(Connection connect,String courseCode,String filearea,String str, Long itemId) throws SQLException {
+		if (StringUtils.isBlank(str)) {
+			return str;
+		}
+		Matcher matcher = imgPat.matcher(str);
+		Map<String, String> srcMap = new HashMap<>();
+		while (matcher.find()) {
+			String imgSrc = matcher.group(1).trim();
+			if (imgSrc.startsWith("data:image/")) {
+
+			} else if (imgSrc.startsWith("@@PLUGINFILE@@")) {
+				if (srcMap.get(imgSrc) == null) {
+					File img = getImage(connect, imgSrc, courseCode, itemId, filearea);
+					String base64 = FileUtil.fileToBase64Src(img);
+					srcMap.put(imgSrc, base64);
+				}
+			}else {
+				throw new StatusException("图片有误:" + itemId);
+			}
+		}
+		for (String imgSrc : srcMap.keySet()) {
+			str = str.replaceAll(imgSrc.replaceAll("\\?", "\\\\?"), srcMap.get(imgSrc));
+		}
+		return str;
+	}
+	
+	
+	
+	private File getImage(Connection connect,String imgSrc,String courseCode,Long itemId,String filearea) throws SQLException {
+		String fileName=getFileName(imgSrc);
+		PreparedStatement preState = null;
+		ResultSet resultSet = null;
+		try {
+			String hash = null;
+			int count=0;
+			String sql = " select * from mdl_files where itemid = " + itemId + " and source='" + fileName
+					+ "' and component = 'question' and filearea = '"+filearea+"' ";
+			preState = connect.prepareStatement(sql);
+
+			resultSet = preState.executeQuery();
+
+			while (resultSet.next()) {
+				count++;
+				hash = resultSet.getString("contenthash");
+			}
+			if(count!=1) {
+				throw new StatusException("图片有误:" + itemId+filearea);
+			}
+			String suff = fileName.substring(fileName.lastIndexOf("."));
+			File file = new File(imgDir + courseCode + "/" + hash + suff);
+			if (!file.exists()) {
+				throw new StatusException("图片有误:" + itemId+filearea);
+			}
+			return file;
+		} finally {
+			if (resultSet != null) {
+				resultSet.close();
+			}
+			if (preState != null) {
+				preState.close();
+			}
+		}
+	}
+	private String getFileName(String s) {
+		int end = s.length();
+		int f = s.indexOf("?");
+		if (f != -1) {
+			end = f;
+		}
+		try {
+			return URLDecoder.decode(s.substring(s.lastIndexOf("/") + 1, end), "utf-8");
+		} catch (UnsupportedEncodingException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	private void exportPaper(Connection connect, PaperExportDto dto) throws Exception {
+		List<QuestionVo3> vos = getQuestion(connect, dto.getCourseCode());
+		if (CollectionUtils.isEmpty(vos)) {
+			return;
+		}
+		List<KdQuestion> qs = of(vos);
+		fillAnswer(connect, qs, dto.getCourseCode());
+
+		Map<QuesStructType, List<KdQuestion>> qmap = new HashMap<>();
+		for (KdQuestion q : qs) {
+			if(q.isValid()) {
+				List<KdQuestion> list = qmap.get(q.getQuesStructType());
+				if (list == null) {
+					list = new ArrayList<>();
+					qmap.put(q.getQuesStructType(), list);
+				}
+				list.add(q);
+			}
+		}
+		for (QuesStructType qt : qmap.keySet()) {
+			createPapers(qmap.get(qt), qt, dto);
+		}
+	}
+
+	private void fillAnswer(Connection connect, List<KdQuestion> qs, String courseCode) throws NumberFormatException, SQLException {
+		List<Answer> qps = new BatchGetDataUtil<Answer, KdQuestion>() {
+
+			@Override
+			protected List<Answer> getData(List<KdQuestion> paramList) {
+				return getAnswerBatch(connect, paramList);
+			}
+		}.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) {
+			try {
+				List<Answer> as=map.get(Long.valueOf(q.getId()));
+				if (CollectionUtils.isEmpty(as)) {
+					throw new StatusException("没有答案:"+q.getId());
+				}
+				if (QuesStructType.SINGLE_ANSWER_QUESTION.equals(q.getQuesStructType())) {
+					List<KdQuesOption> options = new ArrayList<>();
+					q.setOptions(options);
+					int num = 0;
+					int answerCount = 0;
+					for (Answer a : as) {
+						num++;
+						KdQuesOption o = new KdQuesOption();
+						options.add(o);
+						o.setId(a.getaId());
+						o.setNumber(num);
+						o.setBody(a.getBody());
+						o.setSelect(a.getFraction()>0);
+						if (o.getSelect()) {
+							answerCount++;
+						}
+					}
+					if (answerCount == 0) {
+						throw new StatusException("没有答案:"+q.getId());
+					}
+					if (answerCount > 1) {
+						q.setQuesStructType(QuesStructType.MULTIPLE_ANSWER_QUESTION);
+					}
+				} else if (QuesStructType.BOOL_ANSWER_QUESTION.equals(q.getQuesStructType())) {
+					for (Answer a : as) {
+						if (a.getFraction() > 0) {
+							q.setAnswer("对".equals(a.getBody().trim()) ? "正确" : "错误");
+							break;
+						}
+					}
+					if(StringUtils.isBlank(q.getAnswer())) {
+						throw new StatusException("答案有误:"+q.getId());
+					}
+				} else {
+					throw new StatusException("题型有误:"+q.getId());
+				}
+			}catch (StatusException e) {
+				GkExportPaperByCourseCode3.addValid();
+				q.setValid(false);
+				continue;
+			}
+			try {
+				disposeQuestionImg(connect, courseCode, q);
+			} catch (StatusException e) {
+				GkExportPaperByCourseCode3.addImgValid();
+				q.setValid(false);
+				continue;
+			}
+		}
+		
+	}
+
+
+
+
+	private List<Answer> getAnswerBatch(Connection connect, List<KdQuestion> qs) {
+		List<Answer> as = new ArrayList<>();
+		List<Long> ids = qs.stream().map(e -> Long.valueOf(e.getId())).collect(Collectors.toList());
+		String idsstr = StringUtils.join(ids, ",");
+		PreparedStatement preState = null;
+		ResultSet resultSet = null;
+		try {
+			String sql = " select t.id,t.question,t.answer,t.fraction  from mdl_question_answers t "
+					+ " where t.question in (" + idsstr + ")  ";
+			preState = connect.prepareStatement(sql);
+
+			resultSet = preState.executeQuery();
+
+			while (resultSet.next()) {
+				Answer a = new Answer();
+				a.setBody(resultSet.getString("answer"));
+				a.setFraction(resultSet.getDouble("fraction"));
+				a.setQuestionId(resultSet.getLong("question"));
+				a.setaId(resultSet.getLong("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 createPapers(List<KdQuestion> qs, QuesStructType qt, PaperExportDto dto) {
+		if (qs == null || qs.size() == 0) {
+			return;
+		}
+		if (qs.size() <= maxqc) {
+			createPaper(qs, qt, dto, 1);
+		} else {
+			int size = qs.size();
+			int len = maxqc;
+			int count = (size + len - 1) / len;
+
+			for (int i = 0; i < count; i++) {
+				List<KdQuestion> subList = qs.subList(i * len, ((i + 1) * len > size ? size : len * (i + 1)));
+				createPaper(subList, qt, dto, i + 1);
+			}
+		}
+
+	}
+
+	private void createPaper(List<KdQuestion> qs, QuesStructType qt, PaperExportDto dto, int indx) {
+		if (qs.size() == 0) {
+			return;
+		}
+		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.getName();
+		KdPaper paper = new KdPaper();
+		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(unit);
+		d.setTotalScore(score);
+		d.setQuestions(qs);
+		des.add(d);
+		paper.setDetails(des);
+		paper.setDetailCount(1);
+		paper.setUnitCount(qs.size());
+		File paperdir = new File(paperDir + dto.getCourseCode() + "/" + qt.getId() + "/");
+		paperdir.mkdirs();
+		try {
+			FileUtil.writeFile(paperdir.getAbsolutePath(), "/paper_" + indx + ".json", JSONObject.toJSONString(paper));
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	@Override
+	public void initResult() {
+
+	}
+}

+ 75 - 0
src/main/java/cn/com/qmth/export/MyProducer3.java

@@ -0,0 +1,75 @@
+package cn.com.qmth.export;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.LinkedHashSet;
+import java.util.Map;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+
+public class MyProducer3 extends Producer {
+	private static Logger logger = LogManager.getLogger(MyProducer3.class);
+	private static String dir = "d:/guangkai/";
+	private static String paperDir = "d:/guangkai/paper/";
+
+	@Override
+	protected void produce(Map<String, Object> param) throws Exception {
+		logger.info("***************************任务生产开始");
+		String paperSuff = (String)param.get("paperSuff");
+		String dbName = (String)param.get("dbName");
+		File excelFolder = new File(paperDir);
+		if (excelFolder.exists()) {
+			FileUtil.clearDirectory(paperDir);
+		} else {
+			excelFolder.mkdirs();
+		}
+		LinkedHashSet<String> cs = readSubject();
+		if (CollectionUtils.isEmpty(cs)) {
+			logger.debug("无数据导出");
+			return;
+		} else {
+			logger.debug(cs.size() + "个课程");
+		}
+		for (String c : cs) {
+			offer(new PaperExportDto(c, paperSuff,dbName));
+		}
+		logger.info("***************************任务生产结束");
+	}
+	
+	
+	private static LinkedHashSet<String> readSubject() {
+		LinkedHashSet<String> list = new LinkedHashSet<>();
+		XSSFWorkbook wb = null;
+		try {
+			wb = new XSSFWorkbook(dir + "subject_info.xlsx");
+			XSSFSheet sheet = wb.getSheetAt(0);
+			int rows = sheet.getLastRowNum();
+			for (int i = 1; i <= rows; i++) {
+				XSSFRow row = sheet.getRow(i);
+				String yunkaiCode;
+				try {
+					yunkaiCode = row.getCell(1).getStringCellValue().trim();
+				} catch (Exception e) {
+					yunkaiCode = (row.getCell(1).getNumericCellValue()+"").trim();
+				}
+				list.add(yunkaiCode);
+			}
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		} finally {
+			if (wb != null) {
+				try {
+					wb.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+		return list;
+	}
+}

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

@@ -5,23 +5,23 @@ public enum QuesStructType {
     /**
      * 单选
      */
-    SINGLE_ANSWER_QUESTION(1, "单选", true, false),
+    SINGLE_ANSWER_QUESTION(1, "单选", true, false),
     /**
      * 多选
      */
-    MULTIPLE_ANSWER_QUESTION(2, "多选", true, false),
+    MULTIPLE_ANSWER_QUESTION(2, "多选", true, false),
     /**
      * 判断
      */
-    BOOL_ANSWER_QUESTION(3, "判断", true, false),
+    BOOL_ANSWER_QUESTION(3, "判断", true, false),
     /**
      * 填空
      */
-    FILL_BLANK_QUESTION(4, "填空", false, false),
+    FILL_BLANK_QUESTION(4, "填空", false, false),
     /**
      * 问答
      */
-    TEXT_ANSWER_QUESTION(5, "问答", false, false),
+    TEXT_ANSWER_QUESTION(5, "问答", false, false),
     /**
      * 套题
      */

+ 41 - 0
src/main/java/cn/com/qmth/export/QuestionVo3.java

@@ -0,0 +1,41 @@
+package cn.com.qmth.export;
+
+public class QuestionVo3 {
+	private Long qid;
+	private Long pid;
+	private CusQuesStructType3 qType;
+	private String body;
+	private Long category;
+	public Long getQid() {
+		return qid;
+	}
+	public void setQid(Long qid) {
+		this.qid = qid;
+	}
+	public Long getPid() {
+		return pid;
+	}
+	public void setPid(Long pid) {
+		this.pid = pid;
+	}
+	public CusQuesStructType3 getqType() {
+		return qType;
+	}
+	public void setqType(CusQuesStructType3 qType) {
+		this.qType = qType;
+	}
+	public String getBody() {
+		return body;
+	}
+	public void setBody(String body) {
+		this.body = body;
+	}
+	public Long getCategory() {
+		return category;
+	}
+	public void setCategory(Long category) {
+		this.category = category;
+	}
+
+
+}

+ 15 - 13
src/main/java/cn/com/qmth/export/SetRootId.java → src/main/java/cn/com/qmth/export/SetLevel.java

@@ -11,8 +11,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-public class SetRootId {
-	private static String dbName="yunkai_question6";
+public class SetLevel {
+	private static String dbName="guangkai_mdl";
 	public static void main(String[] args) {
 		System.out.println("开始处理");
 		Connection connect = null;
@@ -27,7 +27,7 @@ public class SetRootId {
 			String password = "123456";
 			connect = DriverManager.getConnection(url, user, password);
 			List<Knowledge> ks=getKnowledge(connect);
-			setRootId(ks);
+			setLevel(ks);
 			if (ks.size() <= 1000) {
 				updateKnowledge(connect, ks);
 				System.out.println("处理:1");
@@ -58,11 +58,11 @@ public class SetRootId {
 	private static void updateKnowledge(Connection connect,List<Knowledge> ks) throws SQLException, IOException {
 		PreparedStatement preState = null;
 		try {
-			String sql = "update wq_knowledge_system set root_id=? where id=?";
+			String sql = "update mdl_question_categories set level=? where id=?";
 			preState = connect.prepareStatement(sql);
 
 			for(Knowledge k:ks) {
-				preState.setLong(1, k.getRootId());
+				preState.setInt(1, k.getLevel());
 				preState.setLong(2, k.getId());
 				preState.addBatch();
 			}
@@ -75,23 +75,25 @@ public class SetRootId {
 		}
 	}
 	
-	private static void setRootId(List<Knowledge> ks) {
+	private static void setLevel(List<Knowledge> ks) {
 		Map<Long,Knowledge> map=new HashMap<>();
 		for(Knowledge k:ks) {
 			map.put(k.getId(), k);
 		}
 		for(Knowledge k:ks) {
-			getAndSetRootId(map, k);
+			getAndSetLevel(map, k);
 		}
 	}
 	
-	private static void getAndSetRootId(Map<Long,Knowledge> map,Knowledge k) {
+	private static void getAndSetLevel(Map<Long,Knowledge> map,Knowledge k) {
 		if(k.getParentId()==0) {
-			k.setRootId(k.getId());
+			k.setLevel(0);
 		}else {
 			Knowledge pk=map.get(k.getParentId());
-			getAndSetRootId(map, pk);
-			k.setRootId(pk.getRootId());
+			if(pk.getLevel()==null) {
+				getAndSetLevel(map, pk);
+			}
+			k.setLevel(pk.getLevel()+1);
 		}
 	}
 
@@ -100,7 +102,7 @@ public class SetRootId {
 		PreparedStatement preState = null;
 		ResultSet resultSet = null;
 		try {
-			String sql = "select id,parent_id,root_id from wq_knowledge_system order by parent_id,id";
+			String sql = "select id,parent from mdl_question_categories";
 			preState = connect.prepareStatement(sql);
 
 			resultSet = preState.executeQuery();
@@ -108,7 +110,7 @@ public class SetRootId {
 			while (resultSet.next()) {
 				Knowledge a = new Knowledge();
 				a.setId(resultSet.getLong("id"));
-				a.setParentId(resultSet.getLong("parent_id"));
+				a.setParentId(resultSet.getLong("parent"));
 				as.add(a);
 			}
 			return as;