xiatian пре 2 месеци
родитељ
комит
dfb1e08ed3

+ 89 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_paper_data/ExportPaperDataService.java

@@ -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;
+    }
+
+}

+ 73 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_paper_data/PaperDataDto.java

@@ -0,0 +1,73 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_paper_data;
+
+import cn.com.qmth.dp.examcloud.oe.excel.ExcelProperty;
+
+public class PaperDataDto {
+
+    @ExcelProperty(name = "课程名称", width = 25, index = 1)
+    private String courseName;
+
+    @ExcelProperty(name = "课程代码", width = 25, index = 2)
+    private String courseCode;
+
+    @ExcelProperty(name = "试卷名称", width = 25, index = 3)
+    private String name;
+
+    @ExcelProperty(name = "大题数", width = 25, index = 4)
+    private int paperDetailCount;
+
+    @ExcelProperty(name = "小题数", width = 25, index = 5)
+    private int unitCount;
+
+    @ExcelProperty(name = "创建时间", width = 25, index = 6)
+    private String createTime;
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
+
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getPaperDetailCount() {
+        return paperDetailCount;
+    }
+
+    public void setPaperDetailCount(int paperDetailCount) {
+        this.paperDetailCount = paperDetailCount;
+    }
+
+    public int getUnitCount() {
+        return unitCount;
+    }
+
+    public void setUnitCount(int unitCount) {
+        this.unitCount = unitCount;
+    }
+
+    public String getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(String createTime) {
+        this.createTime = createTime;
+    }
+
+}