浏览代码

1.1.0 update-20250121bug修复

xiaofei 5 月之前
父节点
当前提交
2075003321

+ 16 - 1
src/main/java/com/qmth/eds/service/impl/ExamSyncTotalServiceImpl.java

@@ -20,6 +20,7 @@ import org.springframework.util.CollectionUtils;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -35,6 +36,8 @@ public class ExamSyncTotalServiceImpl extends ServiceImpl<ExamSyncTotalMapper, E
 
     @Resource
     private ExamTypeService examTypeService;
+    @Resource
+    private ExamSyncStudentService examSyncStudentService;
 
     @Resource
     private ExamDownloadRecordService examDownloadRecordService;
@@ -79,7 +82,19 @@ public class ExamSyncTotalServiceImpl extends ServiceImpl<ExamSyncTotalMapper, E
         String filePath = examSyncTotal.getFilePath();
         File file = new File(filePath);
         if (!file.exists()) {
-            throw ExceptionResultEnum.ERROR.exception("文件不存在");
+            // 生成excel文件
+            List<ExamSyncStudent> examSyncStudents = examSyncStudentService.listByExamSyncTotalId(examSyncTotal);
+            File excelFile = null;
+            try {
+                excelFile = WhuDataSyncServiceImpl.createExcel(examSyncTotal, examSyncStudents);
+            } catch (IOException e) {
+                throw ExceptionResultEnum.ERROR.exception("下载文件失败");
+            }
+
+            // 更新文件路径
+            examSyncTotal.setFileName(excelFile.getName());
+            examSyncTotal.setFilePath(excelFile.getPath());
+            this.updateById(examSyncTotal);
         }
 
         if (writeLog) {

+ 3 - 3
src/main/java/com/qmth/eds/service/impl/WhuDataSyncServiceImpl.java

@@ -155,7 +155,7 @@ public class WhuDataSyncServiceImpl implements WhuDataSyncService {
                 examSyncTotal.setId(examSyncTotalId);
                 examSyncTotalService.save(examSyncTotal);
                 // 生成excel文件
-                File excelFile = createExcel(schoolId, examSyncStudents);
+                File excelFile = createExcel(examSyncTotal, examSyncStudents);
 
                 // 更新文件路径
                 examSyncTotal.setFileName(excelFile.getName());
@@ -773,7 +773,7 @@ public class WhuDataSyncServiceImpl implements WhuDataSyncService {
      *
      * @param examSyncStudents 考务数据
      */
-    private File createExcel(Long schoolId, List<ExamSyncStudent> examSyncStudents) throws IOException {
+    public static File createExcel(ExamSyncTotal examSyncTotal, List<ExamSyncStudent> examSyncStudents) throws IOException {
         List<List<String>> head = new ArrayList<>();
         List<String> headTitle0 = new ArrayList<>();
         headTitle0.add("学年");
@@ -835,7 +835,7 @@ public class WhuDataSyncServiceImpl implements WhuDataSyncService {
         head.add(headTitle17);
         head.add(headTitle18);
 
-        String fileName = "file-folder" + File.separator + schoolId + File.separator + System.currentTimeMillis() + ".xlsx";
+        String fileName = "file-folder" + File.separator + examSyncTotal.getSchoolId() + File.separator + examSyncTotal.getId() + ".xlsx";
         File file = new File(fileName);
         if (!file.exists()) {
             file.createNewFile();

+ 1 - 1
src/main/java/com/qmth/eds/start/StartRunning.java

@@ -46,7 +46,7 @@ public class StartRunning implements CommandLineRunner {
         schoolJobMap.computeIfAbsent("name", v -> TimedSyncTaskJob.class.getName());
         quartzService.deleteJob(JobEnum.TIMED_SYNC_TASK_JOB.name(), JobEnum.TIMED_SYNC_TASK_JOB.name());
         // 每天0点定时任务
-//        quartzService.addJob(TimedSyncTaskJob.class, JobEnum.TIMED_SYNC_TASK_JOB.name(), JobEnum.TIMED_SYNC_TASK_JOB.name(), "0 0 0 * * ?", schoolJobMap);
+        quartzService.addJob(TimedSyncTaskJob.class, JobEnum.TIMED_SYNC_TASK_JOB.name(), JobEnum.TIMED_SYNC_TASK_JOB.name(), "0 0 0 * * ?", schoolJobMap);
 
         log.info("服务器启动时执行 end");
     }