xiatian 7 months ago
parent
commit
043900f9cb

+ 128 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/BatchQuestionsCountDto.java

@@ -0,0 +1,128 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
+
+import cn.com.qmth.dp.examcloud.oe.excel.ExcelProperty;
+
+public class BatchQuestionsCountDto {
+
+    @ExcelProperty(name = "课程名称", width = 25, index = 1)
+    private String courseName;
+
+    @ExcelProperty(name = "课程代码", width = 25, index = 2)
+    private String courseCode;
+
+    @ExcelProperty(name = "230517", width = 15, index = 3)
+    private int c1;
+
+    @ExcelProperty(name = "230821", width = 15, index = 4)
+    private int c2;
+
+    @ExcelProperty(name = "230914", width = 15, index = 5)
+    private int c3;
+
+    @ExcelProperty(name = "231205", width = 15, index = 6)
+    private int c4;
+
+    @ExcelProperty(name = "231219", width = 15, index = 7)
+    private int c5;
+
+    @ExcelProperty(name = "240313", width = 15, index = 8)
+    private int c6;
+
+    @ExcelProperty(name = "240320", width = 15, index = 9)
+    private int c7;
+
+    @ExcelProperty(name = "240612", width = 15, index = 10)
+    private int c8;
+
+    @ExcelProperty(name = "240618", width = 15, index = 11)
+    private int c9;
+
+    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 int getC1() {
+        return c1;
+    }
+
+    public void setC1(int c1) {
+        this.c1 = c1;
+    }
+
+    public int getC2() {
+        return c2;
+    }
+
+    public void setC2(int c2) {
+        this.c2 = c2;
+    }
+
+    public int getC3() {
+        return c3;
+    }
+
+    public void setC3(int c3) {
+        this.c3 = c3;
+    }
+
+    public int getC4() {
+        return c4;
+    }
+
+    public void setC4(int c4) {
+        this.c4 = c4;
+    }
+
+    public int getC5() {
+        return c5;
+    }
+
+    public void setC5(int c5) {
+        this.c5 = c5;
+    }
+
+    public int getC6() {
+        return c6;
+    }
+
+    public void setC6(int c6) {
+        this.c6 = c6;
+    }
+
+    public int getC7() {
+        return c7;
+    }
+
+    public void setC7(int c7) {
+        this.c7 = c7;
+    }
+
+    public int getC8() {
+        return c8;
+    }
+
+    public void setC8(int c8) {
+        this.c8 = c8;
+    }
+
+    public int getC9() {
+        return c9;
+    }
+
+    public void setC9(int c9) {
+        this.c9 = c9;
+    }
+
+}

+ 122 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/FomatExcelFileUtil.java

@@ -0,0 +1,122 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_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.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import cn.com.qmth.dp.examcloud.oe.excel.ExportUtils;
+
+/**
+ * 整合excel数据,来自ExportQuestionsCountBySuffService数据
+ */
+public class FomatExcelFileUtil {
+
+    private static String dir = "d:/examcloud-data-export/ret/";
+
+    public static void main(String[] args) {
+        Map<String, BatchQuestionsCountDto> map = new HashMap<>();
+        File dirFile = new File(dir);
+        for (File f : dirFile.listFiles()) {
+            fillData(f, map);
+        }
+        List<BatchQuestionsCountDto> ret = new ArrayList<>();
+        ret.addAll(map.values());
+        Collections.sort(ret, new Comparator<BatchQuestionsCountDto>() {
+
+            @Override
+            public int compare(BatchQuestionsCountDto o1, BatchQuestionsCountDto o2) {
+                String c1 = o1.getCourseCode();
+                String c2 = o2.getCourseCode();
+                return c1.compareTo(c2);
+            }
+
+        });
+        FileOutputStream fos = null;
+        try {
+            File file = new File("d:/examcloud-data-export/qcount.xlsx");
+            if (file.exists()) {
+                file.delete();
+            }
+            file.createNewFile();
+            fos = new FileOutputStream(file);
+            ExportUtils.makeExcel(BatchQuestionsCountDto.class, ret, fos);
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (fos != null) {
+                try {
+                    fos.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    private static void fillData(File file, Map<String, BatchQuestionsCountDto> map) {
+        String fileName = file.getName();
+        String fn = fileName.substring(0, fileName.lastIndexOf("."));
+        XSSFWorkbook wb = null;
+        try {
+            wb = new XSSFWorkbook(file);
+            XSSFSheet sheet = wb.getSheetAt(0);
+            int rows = sheet.getLastRowNum();
+            for (int i = 1; i <= rows; i++) {
+                XSSFRow row = sheet.getRow(i);
+                int total = 0;
+                String subjectName = row.getCell(0).getStringCellValue().trim();
+                String subjectCode = row.getCell(1).getStringCellValue().trim();
+                for (int c = 2; c <= 7; c++) {
+                    String val = row.getCell(c).getStringCellValue().trim();
+                    total = total + Integer.valueOf(val);
+                }
+                BatchQuestionsCountDto dto = map.get(subjectCode);
+                if (dto == null) {
+                    dto = new BatchQuestionsCountDto();
+                    dto.setCourseCode(subjectCode);
+                    dto.setCourseName(subjectName);
+                    map.put(subjectCode, dto);
+                }
+                if ("230517".equals(fn)) {
+                    dto.setC1(total);
+                } else if ("230821".equals(fn)) {
+                    dto.setC2(total);
+                } else if ("230914".equals(fn)) {
+                    dto.setC3(total);
+                } else if ("231205".equals(fn)) {
+                    dto.setC4(total);
+                } else if ("231219".equals(fn)) {
+                    dto.setC5(total);
+                } else if ("240313".equals(fn)) {
+                    dto.setC6(total);
+                } else if ("240320".equals(fn)) {
+                    dto.setC7(total);
+                } else if ("240612".equals(fn)) {
+                    dto.setC8(total);
+                } else if ("240618".equals(fn)) {
+                    dto.setC9(total);
+                }
+
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (wb != null) {
+                try {
+                    wb.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+    }
+}