|
@@ -0,0 +1,89 @@
|
|
|
+package cn.com.qmth.dp.examcloud.oe.modules.export_paper_data;
|
|
|
+
|
|
|
+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 org.apache.commons.collections4.CollectionUtils;
|
|
|
+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.stereotype.Service;
|
|
|
+
|
|
|
+import cn.com.qmth.dp.examcloud.oe.entity.question.Paper;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.enums.question.PaperType;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.excel.ExportUtils;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.util.FileUtil;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ExportPaperDataService {
|
|
|
+
|
|
|
+ private String rootOrgId = "718";
|
|
|
+
|
|
|
+ private String dir = "e:/files/";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
+ public void start() {
|
|
|
+ List<Paper> papers = getAllPaper(rootOrgId);
|
|
|
+ List<PaperDataDto> ret = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(papers)) {
|
|
|
+ for (Paper paper : papers) {
|
|
|
+ PaperDataDto dto = new PaperDataDto();
|
|
|
+ ret.add(dto);
|
|
|
+ dto.setCourseCode(paper.getCourse().getCode());
|
|
|
+ dto.setCourseName(paper.getCourse().getName());
|
|
|
+ dto.setCreateTime(paper.getCreateTime());
|
|
|
+ dto.setName(paper.getName());
|
|
|
+ dto.setPaperDetailCount(paper.getPaperDetailCount());
|
|
|
+ dto.setUnitCount(paper.getUnitCount());
|
|
|
+ }
|
|
|
+ Collections.sort(ret, new Comparator<PaperDataDto>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int compare(PaperDataDto o1, PaperDataDto o2) {
|
|
|
+ String c1 = o1.getCourseCode();
|
|
|
+ String c2 = o2.getCourseCode();
|
|
|
+ return c1.compareTo(c2);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ FileOutputStream fos = null;
|
|
|
+ File file = FileUtil.createFile(dir, "data" + ".xlsx");
|
|
|
+ try {
|
|
|
+ file.createNewFile();
|
|
|
+ fos = new FileOutputStream(file);
|
|
|
+ ExportUtils.makeExcel(PaperDataDto.class, ret, fos);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } finally {
|
|
|
+ if (fos != null) {
|
|
|
+ try {
|
|
|
+ fos.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("finish all! ");
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Paper> getAllPaper(String rootOrgId) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(rootOrgId));
|
|
|
+ query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT));
|
|
|
+ List<Paper> ret = mongoTemplate.find(query, Paper.class, "paper");
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|