|
@@ -1,90 +1,92 @@
|
|
|
-package cn.com.qmth.examcloud.task.service.job;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import javax.persistence.criteria.Predicate;
|
|
|
-
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
-import org.springframework.data.domain.Sort;
|
|
|
-import org.springframework.data.jpa.domain.Specification;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.commons.base.util.PathUtil;
|
|
|
-import cn.com.qmth.examcloud.task.base.AbstractTask;
|
|
|
-import cn.com.qmth.examcloud.task.base.ScheduleJob;
|
|
|
-import cn.com.qmth.examcloud.task.base.TaskTracker;
|
|
|
-import cn.com.qmth.examcloud.task.dao.ExamStudentImportRepo;
|
|
|
-import cn.com.qmth.examcloud.task.dao.ExamStudentTempRepo;
|
|
|
-import cn.com.qmth.examcloud.task.dao.entity.ExamStudentImportEntity;
|
|
|
-
|
|
|
-/**
|
|
|
- * 考生导入-数据清理
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @date 2018年7月31日
|
|
|
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
- */
|
|
|
-@Component("examStudentImportCleanTask")
|
|
|
-public class ExamStudentImportCleanTask extends AbstractTask {
|
|
|
-
|
|
|
- @Value("${$dir}")
|
|
|
- private String dir;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- TaskTracker TaskTracker;
|
|
|
-
|
|
|
- private static final String EXAM_STUDENT_IMPORT_FILES = "exam_student_import_files";
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamStudentImportRepo examStudentImportRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamStudentTempRepo examStudentTempRepo;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void run(ScheduleJob scheduleJob) throws Exception {
|
|
|
- Specification<ExamStudentImportEntity> specification = (root, query, cb) -> {
|
|
|
- List<Predicate> predicates = new ArrayList<>();
|
|
|
- // 清理过去30天前的数据
|
|
|
- Calendar c = Calendar.getInstance();
|
|
|
- c.setTime(new Date());
|
|
|
- c.add(Calendar.DATE, -30);
|
|
|
- Date d = c.getTime();
|
|
|
- Predicate p3 = cb.lessThan(root.get("creationTime"), d);
|
|
|
- predicates.add(p3);
|
|
|
-
|
|
|
- return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
- };
|
|
|
-
|
|
|
- Pageable pageable = new PageRequest(0, 100, Sort.Direction.ASC, "creationTime");
|
|
|
- Page<ExamStudentImportEntity> list = examStudentImportRepo.findAll(specification, pageable);
|
|
|
- for (ExamStudentImportEntity cur : list) {
|
|
|
-
|
|
|
- examStudentTempRepo.deleteByBatchId(cur.getBatchId());
|
|
|
-
|
|
|
- String destFilePath = PathUtil.getCanonicalPath(
|
|
|
- dir + "/" + EXAM_STUDENT_IMPORT_FILES + "/" + cur.getFilePath());
|
|
|
- String resultFilePath = PathUtil.getCanonicalPath(
|
|
|
- dir + "/" + EXAM_STUDENT_IMPORT_FILES + "/" + cur.getResultFilePath());
|
|
|
-
|
|
|
- FileUtils.deleteQuietly(new File(destFilePath));
|
|
|
- FileUtils.deleteQuietly(new File(resultFilePath));
|
|
|
-
|
|
|
- examStudentImportRepo.delete(cur);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public TaskTracker getTaskTracker() {
|
|
|
- return TaskTracker;
|
|
|
- }
|
|
|
-}
|
|
|
+package cn.com.qmth.examcloud.task.service.job;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.PathUtil;
|
|
|
+import cn.com.qmth.examcloud.task.base.AbstractTask;
|
|
|
+import cn.com.qmth.examcloud.task.base.ScheduleJob;
|
|
|
+import cn.com.qmth.examcloud.task.base.TaskTracker;
|
|
|
+import cn.com.qmth.examcloud.task.dao.ExamStudentImportRepo;
|
|
|
+import cn.com.qmth.examcloud.task.dao.ExamStudentTempRepo;
|
|
|
+import cn.com.qmth.examcloud.task.dao.entity.ExamStudentImportEntity;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 考生导入-数据清理
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @date 2018年7月31日
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
+ */
|
|
|
+@Transactional
|
|
|
+@Component("examStudentImportCleanTask")
|
|
|
+public class ExamStudentImportCleanTask extends AbstractTask {
|
|
|
+
|
|
|
+ @Value("${$dir}")
|
|
|
+ private String dir;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ TaskTracker TaskTracker;
|
|
|
+
|
|
|
+ private static final String EXAM_STUDENT_IMPORT_FILES = "exam_student_import_files";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentImportRepo examStudentImportRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentTempRepo examStudentTempRepo;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run(ScheduleJob scheduleJob) throws Exception {
|
|
|
+ Specification<ExamStudentImportEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ // 清理过去30天前的数据
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
+ c.setTime(new Date());
|
|
|
+ c.add(Calendar.DATE, -30);
|
|
|
+ Date d = c.getTime();
|
|
|
+ Predicate p3 = cb.lessThan(root.get("creationTime"), d);
|
|
|
+ predicates.add(p3);
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ Pageable pageable = new PageRequest(0, 100, Sort.Direction.ASC, "creationTime");
|
|
|
+ Page<ExamStudentImportEntity> list = examStudentImportRepo.findAll(specification, pageable);
|
|
|
+ for (ExamStudentImportEntity cur : list) {
|
|
|
+
|
|
|
+ examStudentTempRepo.deleteByBatchId(cur.getBatchId());
|
|
|
+
|
|
|
+ String destFilePath = PathUtil.getCanonicalPath(
|
|
|
+ dir + "/" + EXAM_STUDENT_IMPORT_FILES + "/" + cur.getFilePath());
|
|
|
+ String resultFilePath = PathUtil.getCanonicalPath(
|
|
|
+ dir + "/" + EXAM_STUDENT_IMPORT_FILES + "/" + cur.getResultFilePath());
|
|
|
+
|
|
|
+ FileUtils.deleteQuietly(new File(destFilePath));
|
|
|
+ FileUtils.deleteQuietly(new File(resultFilePath));
|
|
|
+
|
|
|
+ examStudentImportRepo.delete(cur);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TaskTracker getTaskTracker() {
|
|
|
+ return TaskTracker;
|
|
|
+ }
|
|
|
+}
|