|
@@ -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) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|