Selaa lähdekoodia

难度题数导出

xiatian 2 vuotta sitten
vanhempi
commit
df9221a0b7

+ 117 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_diff_count/CourseQuestionsCountRetDto.java

@@ -0,0 +1,117 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_diff_count;
+
+import cn.com.qmth.dp.examcloud.oe.excel.ExcelProperty;
+
+public class CourseQuestionsCountRetDto {
+	@ExcelProperty(name = "课程代码", width = 25, index =1)
+	private String courseCode;
+	@ExcelProperty(name = "课程名称", width = 25, index = 2)
+	private String courseName;
+	@ExcelProperty(name = "单选-难", width = 15, index = 3)
+	private long singleNan;
+	@ExcelProperty(name = "单选-中", width = 15, index = 4)
+	private long singleZhong;
+	@ExcelProperty(name = "单选-易", width = 15, index = 5)
+	private long singleYi;
+	@ExcelProperty(name = "多选-难", width = 15, index = 6)
+	private long multiNan;
+	@ExcelProperty(name = "多选--中", width = 15, index = 7)
+	private long multiZhong;
+	@ExcelProperty(name = "多选--易", width = 15, index = 8)
+	private long multiYi;
+	@ExcelProperty(name = "判断-难", width = 15, index = 9)
+	private long boolNan;
+	@ExcelProperty(name = "判断--中", width = 15, index = 10)
+	private long boolZhong;
+	@ExcelProperty(name = "判断--易", width = 15, index = 11)
+	private long boolYi;
+
+	public String getCourseCode() {
+		return courseCode;
+	}
+
+	public void setCourseCode(String courseCode) {
+		this.courseCode = courseCode;
+	}
+
+	public String getCourseName() {
+		return courseName;
+	}
+
+	public void setCourseName(String courseName) {
+		this.courseName = courseName;
+	}
+
+	public long getSingleNan() {
+		return singleNan;
+	}
+
+	public void setSingleNan(long singleNan) {
+		this.singleNan = singleNan;
+	}
+
+	public long getSingleZhong() {
+		return singleZhong;
+	}
+
+	public void setSingleZhong(long singleZhong) {
+		this.singleZhong = singleZhong;
+	}
+
+	public long getSingleYi() {
+		return singleYi;
+	}
+
+	public void setSingleYi(long singleYi) {
+		this.singleYi = singleYi;
+	}
+
+	public long getMultiNan() {
+		return multiNan;
+	}
+
+	public void setMultiNan(long multiNan) {
+		this.multiNan = multiNan;
+	}
+
+	public long getMultiZhong() {
+		return multiZhong;
+	}
+
+	public void setMultiZhong(long multiZhong) {
+		this.multiZhong = multiZhong;
+	}
+
+	public long getMultiYi() {
+		return multiYi;
+	}
+
+	public void setMultiYi(long multiYi) {
+		this.multiYi = multiYi;
+	}
+
+	public long getBoolNan() {
+		return boolNan;
+	}
+
+	public void setBoolNan(long boolNan) {
+		this.boolNan = boolNan;
+	}
+
+	public long getBoolZhong() {
+		return boolZhong;
+	}
+
+	public void setBoolZhong(long boolZhong) {
+		this.boolZhong = boolZhong;
+	}
+
+	public long getBoolYi() {
+		return boolYi;
+	}
+
+	public void setBoolYi(long boolYi) {
+		this.boolYi = boolYi;
+	}
+
+}

+ 37 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_diff_count/ExportCourseQuestionsDiffCountService.java

@@ -0,0 +1,37 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_diff_count;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.web.support.SpringContextHolder;
+
+/**
+ * 按科目导出小题各题型数.多线程处理
+ * 
+ * @author chenken
+ *
+ */
+@Service
+public class ExportCourseQuestionsDiffCountService {
+	private String rootOrgId = "17351";
+	private int threadCount=20;
+
+	public void start() {
+		Date s=new Date();
+		ExportQuesDiffProducer pr = SpringContextHolder.getBean(ExportQuesDiffProducer.class);
+		try {
+			Map<String, Object> param=new HashMap<>();
+			param.put("rootOrgId", rootOrgId);
+			pr.startDispose(ExportQuesDiffConsumer.class, threadCount, param);
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+
+		}
+		Date e=new Date();
+		System.out.println("time:" + (e.getTime()-s.getTime()));
+	}
+
+}

+ 84 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_diff_count/ExportQuesDiffConsumer.java

@@ -0,0 +1,84 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_diff_count;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.aggregation.Aggregation;
+import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
+import org.springframework.data.mongodb.core.aggregation.AggregationResults;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.dp.examcloud.oe.entity.question.Course;
+import cn.com.qmth.dp.examcloud.oe.entity.question.Question;
+import cn.com.qmth.dp.examcloud.oe.enums.question.QuesStructType;
+import cn.com.qmth.dp.examcloud.oe.multithread.Consumer;
+
+@Service
+@Scope("prototype")
+public class ExportQuesDiffConsumer extends Consumer<Course> {
+
+	@Autowired
+	private MongoTemplate mongoTemplate;
+
+	@Override
+	public void consume(Map<String, Object> param, Course c) {
+		CourseQuestionsCountRetDto rd = new CourseQuestionsCountRetDto();
+		addRet(rd);
+		String rootOrgId = (String) param.get("rootOrgId");
+		rd.setCourseCode(c.getCode());
+		rd.setCourseName(c.getName());
+		List<QuestionTypeCount> tc = countByType(c.getCode(), rootOrgId);
+		if (CollectionUtils.isNotEmpty(tc)) {
+			setCount(rd, tc);
+		}
+
+	}
+
+	private void setCount(CourseQuestionsCountRetDto rd, List<QuestionTypeCount> tc) {
+		for (QuestionTypeCount t : tc) {
+			if (t.getQuestionType().equals(QuesStructType.SINGLE_ANSWER_QUESTION.name())) {
+				if("难".equals(t.getDifficulty())) {
+					rd.setSingleNan(t.getCount());
+				}else if("中".equals(t.getDifficulty())) {
+					rd.setSingleZhong(t.getCount());
+				}else if("易".equals(t.getDifficulty())) {
+					rd.setSingleYi(t.getCount());
+				}
+			} else if (t.getQuestionType().equals(QuesStructType.MULTIPLE_ANSWER_QUESTION.name())) {
+				if("难".equals(t.getDifficulty())) {
+					rd.setMultiNan(t.getCount());
+				}else if("中".equals(t.getDifficulty())) {
+					rd.setMultiZhong(t.getCount());
+				}else if("易".equals(t.getDifficulty())) {
+					rd.setMultiYi(t.getCount());
+				}
+			} else if (t.getQuestionType().equals(QuesStructType.BOOL_ANSWER_QUESTION.name())) {
+				if("难".equals(t.getDifficulty())) {
+					rd.setBoolNan(t.getCount());
+				}else if("中".equals(t.getDifficulty())) {
+					rd.setBoolZhong(t.getCount());
+				}else if("易".equals(t.getDifficulty())) {
+					rd.setBoolYi(t.getCount());
+				}
+			}
+		}
+	}
+
+	private List<QuestionTypeCount> countByType(String courseCode, String rootOrgId) {
+		List<AggregationOperation> operations = new ArrayList<>();
+		operations.add(Aggregation.match(Criteria.where("orgId").is(rootOrgId).and("course.code").is(courseCode)));
+		operations.add(Aggregation.group("questionType", "difficulty").count().as("count"));
+		operations.add(Aggregation.project("count").andInclude("questionType").andInclude("difficulty"));
+		Aggregation aggregation = Aggregation.newAggregation(operations);
+		AggregationResults<QuestionTypeCount> outputTypeCount = mongoTemplate.aggregate(aggregation, Question.class,
+				QuestionTypeCount.class);
+		return outputTypeCount.getMappedResults();
+	}
+
+}

+ 133 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_diff_count/ExportQuesDiffProducer.java

@@ -0,0 +1,133 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_diff_count;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.dp.examcloud.oe.entity.question.Course;
+import cn.com.qmth.dp.examcloud.oe.entity.question.Question;
+import cn.com.qmth.dp.examcloud.oe.excel.ExportUtils;
+import cn.com.qmth.dp.examcloud.oe.multithread.Consumer;
+import cn.com.qmth.dp.examcloud.oe.multithread.Producer;
+import cn.com.qmth.dp.examcloud.oe.util.ResouceUtil;
+
+@Service
+public class ExportQuesDiffProducer extends Producer {
+
+	@Autowired
+	private JdbcTemplate jdbcTemplate;
+	
+	@Autowired
+	private MongoTemplate mongoTemplate;
+	
+	@Override
+	protected void produce(Map<String, Object> param) throws Exception {
+		List<Course> cs = getCourse();
+		if (CollectionUtils.isNotEmpty(cs)) {
+			for (Course c : cs) {
+				offer(c);
+			}
+		}
+		List<CourseQuestionsCountRetDto> ret = new ArrayList<CourseQuestionsCountRetDto>();
+		int index=0;
+		for(Consumer c:getConsumers()) {
+			ret.addAll(c.getRet());
+			index++;
+		}
+		Collections.sort(ret, new Comparator<CourseQuestionsCountRetDto>() {
+			@Override
+			public int compare(CourseQuestionsCountRetDto o1, CourseQuestionsCountRetDto o2) {
+				String c1 = o1.getCourseCode();
+				String c2 = o2.getCourseCode();
+				return c1.compareTo(c2);
+			}
+
+		});
+		FileOutputStream fos = null;
+		try {
+			File file = new File("d:/ret.xlsx");
+			if (file.exists()) {
+				file.delete();
+			}
+			file.createNewFile();
+			fos = new FileOutputStream(file);
+			ExportUtils.makeExcel(CourseQuestionsCountRetDto.class, ret, fos);
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			if (fos != null) {
+				try {
+					fos.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+		System.out.println("courseCount:" + cs.size());
+		System.out.println("finish! TotalQuestionCount:" + getTotalQuestionCount((String)param.get("rootOrgId")));
+	}
+	
+	private List<Course> getCourse(String rootOrgId) {
+		String sql = "select t.code,t.name,t.id from ec_b_course t where t.root_org_id=" + rootOrgId
+				+ " order by t.code";
+		RowMapper<Course> rowMapper = new BeanPropertyRowMapper<Course>(Course.class);
+		List<Course> ret = jdbcTemplate.query(sql, rowMapper);
+		return ret;
+	}
+	
+	private List<Course> getCourse() {
+		List<Course> list=new ArrayList<>();
+		XSSFWorkbook wb = null;
+		try {
+			wb = new XSSFWorkbook(ResouceUtil.getStream("subject_codes.xlsx"));
+			XSSFSheet sheet = wb.getSheetAt(0);
+			int rows = sheet.getLastRowNum();
+			for (int i = 2; i <= rows; i++) {
+				Course c = new Course();
+				XSSFRow row = sheet.getRow(i);
+				String ecCode = row.getCell(0).getStringCellValue().trim();
+				String name = row.getCell(1).getStringCellValue().trim();
+				c.setCode(ecCode);
+				c.setName(name);
+				list.add(c);
+				
+			}
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		} finally {
+			if (wb != null) {
+				try {
+					wb.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+		return list;
+	}
+	
+	private long getTotalQuestionCount(String rootOrgId) {
+		Query query = new Query();
+		query.addCriteria(Criteria.where("orgId").is(rootOrgId));
+		long count = mongoTemplate.count(query, Question.class, "question");
+		return count;
+	}
+
+}

+ 22 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_diff_count/IdBean.java

@@ -0,0 +1,22 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_diff_count;
+
+import javax.persistence.Id;
+
+import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+
+public class IdBean implements JsonSerializable {
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -1424624250300317437L;
+	@Id
+    protected String id;
+	public String getId() {
+		return id;
+	}
+	public void setId(String id) {
+		this.id = id;
+	}
+	
+	
+}

+ 32 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_diff_count/QuestionTypeCount.java

@@ -0,0 +1,32 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_diff_count;
+
+public class QuestionTypeCount {
+	private String questionType;
+	private String difficulty;
+	private long count;
+
+	public long getCount() {
+		return count;
+	}
+
+	public void setCount(long count) {
+		this.count = count;
+	}
+
+	public String getQuestionType() {
+		return questionType;
+	}
+
+	public void setQuestionType(String questionType) {
+		this.questionType = questionType;
+	}
+
+	public String getDifficulty() {
+		return difficulty;
+	}
+
+	public void setDifficulty(String difficulty) {
+		this.difficulty = difficulty;
+	}
+
+}

+ 63 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/util/ResouceUtil.java

@@ -0,0 +1,63 @@
+package cn.com.qmth.dp.examcloud.oe.util;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import org.apache.commons.io.IOUtils;
+
+public class ResouceUtil {
+	public static URL getUrl(String path) {
+		try {
+			ClassLoader classLoader = ResouceUtil.class.getClassLoader();
+
+			URL url = classLoader.getResource(path);
+			return url;
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+	}
+	public static InputStream getStream(String path) {
+		try {
+			ClassLoader classLoader = ResouceUtil.class.getClassLoader();
+
+			URL url = classLoader.getResource(path);
+			return url.openStream();
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+	}
+	public static String getContent(String path) {
+		try {
+			ClassLoader classLoader = ResouceUtil.class.getClassLoader();
+
+			URL url = classLoader.getResource(path);
+			return readFileContent(url.openStream());
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+	}
+	
+	private static String readFileContent(InputStream in) {
+		StringBuilder content = new StringBuilder();
+		InputStreamReader streamReader = null;
+		BufferedReader bufferedReader = null;
+		try {
+			String encoding = "UTF-8";
+			streamReader = new InputStreamReader(in, encoding);
+			bufferedReader = new BufferedReader(streamReader);
+			String line;
+			while ((line = bufferedReader.readLine()) != null) {
+				content.append(line);
+			}
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		} finally {
+			IOUtils.closeQuietly(in);
+			IOUtils.closeQuietly(streamReader);
+			IOUtils.closeQuietly(bufferedReader);
+		}
+		return content.toString();
+	}
+}