From bd024f2081dd68ddd2289b3f8fcbacfae1a6d104 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Sat, 11 Jun 2022 21:31:33 +0800
Subject: [PATCH] 新增定时任务重新计算当天成绩
---
src/main/java/org/springblade/modules/quartz/task/Task.java | 95 +++++++++++++++++++++++++++++++++++++++++------
1 files changed, 83 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/springblade/modules/quartz/task/Task.java b/src/main/java/org/springblade/modules/quartz/task/Task.java
index e2d9194..0ee03de 100644
--- a/src/main/java/org/springblade/modules/quartz/task/Task.java
+++ b/src/main/java/org/springblade/modules/quartz/task/Task.java
@@ -9,6 +9,10 @@
import org.apache.commons.net.ftp.FTPReply;
import org.springblade.common.utils.DesensitizedUtil;
import org.springblade.modules.FTP.*;
+import org.springblade.modules.exam.entity.ExamAnswerRecord;
+import org.springblade.modules.exam.entity.ExamScore;
+import org.springblade.modules.exam.service.ExamAnswerRecordService;
+import org.springblade.modules.exam.service.ExamScoreService;
import org.springblade.modules.log.entity.HandlerLog;
import org.springblade.modules.log.service.HandlerLogService;
import org.springblade.modules.system.entity.User;
@@ -56,6 +60,13 @@
@Autowired
private MyAsyncService myAsyncService;
+
+
+ @Autowired
+ private ExamAnswerRecordService examAnswerRecordService;
+
+ @Autowired
+ private ExamScoreService examScoreService;
public void testTask(){
System.out.println("测试定时任务执行-----------------");
@@ -121,7 +132,6 @@
FTPFile[] files = ftp.listFiles();
if (files.length==0){
- ftp.logout();
return false;
}
else {
@@ -167,13 +177,18 @@
}
}
//关闭流
- ftp.completePendingCommand();
- ftp.logout();
+// ftp.completePendingCommand();
+// ftp.logout();
}
} catch (Exception e) {
System.out.println("ftp连接失败");
e.printStackTrace();
} finally {
+ try {
+ ftp.logout();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
if (ftp.isConnected()) {
try {
ftp.disconnect();
@@ -225,7 +240,7 @@
//文件个数大于10个时开始处理
// if (files.length==0 || files.length<10){
if (files.length==0){
- ftp.logout();
+// ftp.logout();
return false;
}
else {
@@ -270,13 +285,18 @@
}
}
//关闭流
- ftp.completePendingCommand();
- ftp.logout();
+// ftp.completePendingCommand();
+// ftp.logout();
}
} catch (Exception e) {
System.out.println("ftp连接失败");
e.printStackTrace();
} finally {
+ try {
+ ftp.logout();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
if (ftp.isConnected()) {
try {
ftp.disconnect();
@@ -327,7 +347,7 @@
FTPFile[] files = ftp.listFiles();
//文件个数大于10个时开始处理
if (files.length==0){
- ftp.logout();
+
return false;
}
else {
@@ -369,13 +389,18 @@
}
}
//关闭流
- ftp.completePendingCommand();
- ftp.logout();
+// ftp.completePendingCommand();
+// ftp.logout();
}
} catch (Exception e) {
System.out.println("ftp连接失败");
e.printStackTrace();
} finally {
+ try {
+ ftp.logout();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
if (ftp.isConnected()) {
try {
ftp.disconnect();
@@ -524,7 +549,7 @@
FTPFile[] files = ftp.listFiles();
//文件个数大于10个时开始处理
if (files.length==0){
- ftp.logout();
+// ftp.logout();
return false;
}
else {
@@ -562,13 +587,18 @@
}
}
//关闭流
- ftp.completePendingCommand();
- ftp.logout();
+// ftp.completePendingCommand();
+// ftp.logout();
}
} catch (Exception e) {
System.out.println("ftp连接失败");
e.printStackTrace();
} finally {
+ try {
+ ftp.logout();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
if (ftp.isConnected()) {
try {
ftp.disconnect();
@@ -847,5 +877,46 @@
}
}
+ /**
+ * 考试成绩同步
+ * @return
+ */
+ public void examScoreSync() {
+ System.out.println("考试成绩同步"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+ //查询当天的考试成绩
+ List<ExamScore> examScoreList = examScoreService.getExamScoreList();
+ if (examScoreList.size()>0) {
+ //遍历计算成绩
+ for (ExamScore examScore : examScoreList) {
+ ExamAnswerRecord record = new ExamAnswerRecord();
+ record.setScoreId(examScore.getId());
+ List<ExamAnswerRecord> list = examAnswerRecordService.list(new QueryWrapper<>(record));
+ if (list.size()>0){
+ int num = 0;
+ for (ExamAnswerRecord examAnswerRecord : list) {
+ num = num + examAnswerRecord.getAnswerScore();
+ examScore.setExamEndTime(examAnswerRecord.getAnswerTime());
+ }
+ examScore.setTheoryGrade(num);
+ examScore.setAllGrade(Math.round(num/2));
+ //设置状态
+ if (num >= 60) {
+ examScore.setQualified(2);
+ } else {
+ examScore.setQualified(1);
+ }
+ String s1 =
+ "update exam_score set exam_id = " + examScore.getExamId() +
+ ",theory_grade = " + "'" + examScore.getTheoryGrade() + "'" +
+ ",all_grade = " + "'" + examScore.getAllGrade() + "'" +
+ ",exam_end_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:dd").format(examScore.getExamEndTime()) + "'" +
+ ",qualified = " + "'" + examScore.getQualified() + "'" +
+ " " + "where id = " + "'" + examScore.getId() + "'";
+ myAsyncService.FTP(s1);
+ }
+ }
+ }
+ }
+
}
--
Gitblit v1.9.3