Parcourir la source

Merge branch 'dev' of http://git.qmth.com.cn/wangliang/distributed-print-service into dev

xiaof il y a 4 ans
Parent
commit
599d3aaa16
14 fichiers modifiés avec 174 ajouts et 34 suppressions
  1. 18 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/PdfDto.java
  2. 2 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/BasicAttachmentService.java
  3. 0 2
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/CommonService.java
  4. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamDetailService.java
  5. 8 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamTaskService.java
  6. 3 2
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicAttachmentServiceImpl.java
  7. 3 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamDetailServiceImpl.java
  8. 49 4
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java
  9. 31 17
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java
  10. 22 4
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java
  11. 1 2
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/FreemarkerUtil.java
  12. 2 0
      distributed-print-task/src/main/java/com/qmth/distributed/print/task/job/TimedSyncSchoolJob.java
  13. 5 0
      distributed-print-task/src/main/java/com/qmth/distributed/print/task/job/service/JobService.java
  14. 29 0
      distributed-print-task/src/main/java/com/qmth/distributed/print/task/job/service/impl/JobServiceImpl.java

+ 18 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/PdfDto.java

@@ -21,6 +21,9 @@ public class PdfDto {
     @ApiModelProperty(name = "页面大小")
     PageSizeEnum pageSize;
 
+    @ApiModelProperty(name = "序号")
+    Integer sequence = 0;
+
     public PdfDto() {
 
     }
@@ -36,6 +39,21 @@ public class PdfDto {
         this.pageCount = pageCount;
     }
 
+    public PdfDto(String path, PageSizeEnum pageSize, Integer pageCount, Integer sequence) {
+        this.path = path;
+        this.pageSize = pageSize;
+        this.pageCount = pageCount;
+        this.sequence = sequence;
+    }
+
+    public Integer getSequence() {
+        return sequence;
+    }
+
+    public void setSequence(Integer sequence) {
+        this.sequence = sequence;
+    }
+
     public String getPath() {
         return path;
     }

+ 2 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/BasicAttachmentService.java

@@ -69,10 +69,11 @@ public interface BasicAttachmentService extends IService<BasicAttachment> {
      * @param basicAttachment
      * @param pdfList
      * @param printCount
+     * @param sequence
      * @return
      * @throws IOException
      */
-    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount) throws IOException, DocumentException;
+    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException;
 
     /**
      * 删除附件

+ 0 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/CommonService.java

@@ -165,8 +165,6 @@ public interface CommonService {
      */
     public void checkData(Long schoolId, String courseCode, String paperNumber,SysUser user) throws IOException;
 
-//    public void checkDataForExamination()
-
     /**
      * 根据orgId查询所有子机构ID集合
      * @return

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamDetailService.java

@@ -131,7 +131,7 @@ public interface ExamDetailService extends IService<ExamDetail> {
      * @param userId 当前用户id
      * @param serialNumberParams 序列号生成参数
      */
-    void disposeExamDetailByExaminationExcel(List<Map<String, Object>> dataList, Long userId, SerialNumberParams serialNumberParams);
+    List<Long> disposeExamDetailByExaminationExcel(List<Map<String, Object>> dataList, Long userId, SerialNumberParams serialNumberParams);
 
     /**
      * 根据考务数据Excel数据处理考务-科目表

+ 8 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamTaskService.java

@@ -8,6 +8,7 @@ import com.qmth.distributed.print.business.bean.result.WorkResult;
 import com.qmth.distributed.print.business.entity.ExamTask;
 import com.qmth.distributed.print.business.entity.ExamTaskDetail;
 import com.qmth.distributed.print.business.entity.ExamTaskReviewLog;
+import com.qmth.distributed.print.business.entity.SysUser;
 import com.qmth.distributed.print.business.enums.ExamStatusEnum;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -101,4 +102,11 @@ public interface ExamTaskService extends IService<ExamTask> {
      * @param courseCode 考务数据导入的课程代码
      */
     void verifyCourseCodeByPaperNumber(Long schoolId,String paperNumber,String courseCode);
+
+    /**
+     * 根据考务-考场检验该考场下的所有命题任务是否已经完成,全部完成则生成pdf
+     * @param examDetailId 考务考场id
+     * @param user 用户id
+     */
+    void checkDataByExamination(Long examDetailId, SysUser user) throws IOException;
 }

+ 3 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicAttachmentServiceImpl.java

@@ -211,12 +211,13 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
      * @param basicAttachment
      * @param pdfList
      * @param printCount
+     * @param sequence
      * @return
      * @throws IOException
      */
     @Override
     @Transactional
-    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount) throws IOException, DocumentException {
+    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException {
         try {
             boolean oss = dictionaryConfig.sysDomain().isOss();
             JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
@@ -259,7 +260,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
             }
             basicAttachment.setPath(jsonObject.toJSONString());
             for (int i = 0; i < printCount; i++) {
-                pdfList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A4, pageCount));
+                pdfList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A4, pageCount, sequence));
             }
             this.updateById(basicAttachment);
         } catch (Exception e) {

+ 3 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamDetailServiceImpl.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.distributed.print.business.base.BaseEntity;
 import com.qmth.distributed.print.business.bean.dto.*;
 import com.qmth.distributed.print.business.bean.params.SerialNumberParams;
 import com.qmth.distributed.print.business.bean.result.ExaminationDetailResult;
@@ -344,7 +345,7 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public void disposeExamDetailByExaminationExcel(List<Map<String, Object>> dataList, Long userId, SerialNumberParams serialNumberParams) {
+    public List<Long> disposeExamDetailByExaminationExcel(List<Map<String, Object>> dataList, Long userId, SerialNumberParams serialNumberParams) {
         List<Map<String, Object>> examDetailKeyList = dataList.stream().flatMap(e -> {
             Map<String, Object> map = new HashMap<>();
             map.put("schoolId", e.get("schoolId"));
@@ -391,6 +392,7 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
             examDetailList.add(examDetail);
         }
         this.saveBatch(examDetailList);
+        return examDetailList.stream().map(ExamDetail::getId).distinct().collect(Collectors.toList());
     }
 
     @Transactional(rollbackFor = Exception.class)

+ 49 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java

@@ -12,12 +12,10 @@ import com.google.gson.Gson;
 import com.qmth.distributed.print.business.bean.dto.*;
 import com.qmth.distributed.print.business.bean.result.WorkResult;
 import com.qmth.distributed.print.business.entity.*;
-import com.qmth.distributed.print.business.enums.DrawRuleEnum;
-import com.qmth.distributed.print.business.enums.ExamCardStatusEnum;
-import com.qmth.distributed.print.business.enums.ExamStatusEnum;
-import com.qmth.distributed.print.business.enums.ReviewStatusEnum;
+import com.qmth.distributed.print.business.enums.*;
 import com.qmth.distributed.print.business.mapper.ExamTaskMapper;
 import com.qmth.distributed.print.business.service.*;
+import com.qmth.distributed.print.business.templete.execute.AsyncCreatePdfTempleteService;
 import com.qmth.distributed.print.business.util.ConvertUtil;
 import com.qmth.distributed.print.business.util.ExcelUtil;
 import com.qmth.distributed.print.business.util.ServletUtil;
@@ -25,6 +23,7 @@ import com.qmth.distributed.print.business.util.excel.ExcelError;
 import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.velocity.runtime.directive.contrib.For;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -88,6 +87,15 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
     @Autowired
     private ConvertUtil convertUtil;
 
+    @Resource
+    private ExamDetailService examDetailService;
+
+    @Resource
+    TBTaskService tbTaskService;
+
+    @Resource
+    AsyncCreatePdfTempleteService asyncCreatePdfTempleteService;
+
     @Override
     public List<ExamTask> listByCourseCode(Long schoolId, String code) {
         QueryWrapper<ExamTask> queryWrapper = new QueryWrapper<>();
@@ -754,4 +762,41 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
             }
         }
     }
+
+    @Override
+    public void checkDataByExamination(Long examDetailId,SysUser user) throws IOException {
+        boolean judge = true;
+        ExamDetail examDetail = examDetailService.getById(examDetailId);
+        if (Objects.isNull(examDetail)){
+            throw ExceptionResultEnum.ERROR.exception("考务-考场不存在");
+        }
+        List<ExamDetailCourse> examDetailCourseList = examDetailCourseService.list(new QueryWrapper<ExamDetailCourse>().lambda()
+                .eq(ExamDetailCourse::getExamDetailId,examDetailId)
+                .eq(ExamDetailCourse::getSchoolId,examDetail.getSchoolId()));
+        if (examDetailCourseList.size() < 1){
+            throw ExceptionResultEnum.ERROR.exception("考务-课程不存在");
+        }
+        for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
+            String courseCode = examDetailCourse.getCourseCode();
+            String paperNumber = examDetailCourse.getPaperNumber();
+            Long schoolId = examDetailCourse.getSchoolId();
+            ExamTask examTask = this.getOne(new QueryWrapper<ExamTask>().lambda()
+                    .eq(ExamTask::getSchoolId,schoolId)
+                    .eq(ExamTask::getCourseCode,courseCode)
+                    .eq(ExamTask::getPaperNumber,paperNumber));
+            if (examTask == null){
+                judge = false;
+            }else if (!ExamStatusEnum.FINISH.equals(examTask.getStatus())){
+                judge = false;
+            }
+        }
+        if (judge){
+            Map<String, Object> map = tbTaskService.saveTask(TaskTypeEnum.CREATE_PDF, examDetail.getPrintPlanId(), user);
+            if (Objects.nonNull(examDetail.getId())) {
+                map.computeIfAbsent("examDetailId", v -> examDetail.getId());
+            }
+            map.computeIfAbsent("schoolId", v -> examDetail.getSchoolId());
+            asyncCreatePdfTempleteService.createPdf(map, null);
+        }
+    }
 }

+ 31 - 17
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -24,6 +24,7 @@ import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
 import com.qmth.distributed.print.common.util.FileUtil;
 import com.qmth.distributed.print.common.util.HexUtils;
+import com.qmth.distributed.print.common.util.JacksonUtil;
 import com.qmth.distributed.print.common.util.ResultUtil;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -263,6 +264,13 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                     }
                                 }
 
+                                Collections.sort(variablePdfList, new Comparator<PdfDto>() {
+                                    @Override
+                                    public int compare(PdfDto o1, PdfDto o2) {
+                                        return o1.getSequence() > o2.getSequence() ? 1 : -1;
+                                    }
+                                });
+
                                 for (ExamStudent t : examStudentList) {
                                     basicAttachmentList.add(createPdfUtil.examStudentHtml(attachmentIds, studentContent, t, paperType, examCard, sysUser.getId(), examStudentTempPdfList));
                                 }
@@ -420,7 +428,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             String examDate = null;
             String examTime = null;
             String paperNumber = null;
-            List<FieldsDto> secondaryFieldList = new ArrayList<>();
+            List<FieldsDto> secondaryFieldList = new ArrayList<>(); // 备选字段
             for (FieldsDto fieldsDto : fieldsDtoList) {
                 String name = fieldsDto.getName();
                 String code = fieldsDto.getCode();
@@ -472,7 +480,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 }
             }
             // 校验试卷编号
-            examTaskService.verifyCourseCodeByPaperNumber(schoolId,paperNumber,courseCode);
+            examTaskService.verifyCourseCodeByPaperNumber(schoolId, paperNumber, courseCode);
 
             // 校验课程信息
             basicCourseService.verifyCourseInfo(schoolId, courseCode, courseName, userId);
@@ -527,27 +535,33 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         Long value = counter.get();
         try {
             // 组装exam_detail数据
-            examDetailService.disposeExamDetailByExaminationExcel(dataList, userId, serialNumberParams);
+            List<Long> examDetailIdList = examDetailService.disposeExamDetailByExaminationExcel(dataList, userId, serialNumberParams);
             // 组装exam_detail_course数据
             examDetailService.disposeExamDetailCourseByExaminationExcel(dataList, userId);
             // 组装exam_student数据
             examDetailService.disposeExamStudentByExaminationExcel(dataList, userId);
 
-            List<Map<String, Object>> checkList = dataList.stream().flatMap(e -> {
-                Map<String, Object> tmp = new HashMap<>();
-                tmp.put("schoolId", e.get("schoolId"));
-                tmp.put("courseCode", e.get("courseCode"));
-                tmp.put("paperNumber", e.get("paperNumber"));
-                return Stream.of(tmp);
-            }).distinct().collect(Collectors.toList());
-            for (Map<String, Object> stringObjectMap : checkList) {
-                Long checkSchoolId = SystemConstant.convertIdToLong(String.valueOf(stringObjectMap.get("schoolId")));
-                String checkCourseCode = String.valueOf(stringObjectMap.get("courseCode"));
-                String checkPaperNumber = String.valueOf(stringObjectMap.get("paperNumber"));
-                SysUser user = (SysUser) map.get(SystemConstant.USER);
-                user.setSchoolId(schoolId);
-                commonService.checkData(checkSchoolId, checkCourseCode, checkPaperNumber, user);
+            // 按照考场检验命题任务是否全部完成,完成生成pdf
+            SysUser user = (SysUser) map.get(SystemConstant.USER);
+            for (Long examDetailId : examDetailIdList) {
+                examTaskService.checkDataByExamination(examDetailId, user);
             }
+
+//            List<Map<String, Object>> checkList = dataList.stream().flatMap(e -> {
+//                Map<String, Object> tmp = new HashMap<>();
+//                tmp.put("schoolId", e.get("schoolId"));
+//                tmp.put("courseCode", e.get("courseCode"));
+//                tmp.put("paperNumber", e.get("paperNumber"));
+//                return Stream.of(tmp);
+//            }).distinct().collect(Collectors.toList());
+//            for (Map<String, Object> stringObjectMap : checkList) {
+//                Long checkSchoolId = SystemConstant.convertIdToLong(String.valueOf(stringObjectMap.get("schoolId")));
+//                String checkCourseCode = String.valueOf(stringObjectMap.get("courseCode"));
+//                String checkPaperNumber = String.valueOf(stringObjectMap.get("paperNumber"));
+//                SysUser user = (SysUser) map.get(SystemConstant.USER);
+//                user.setSchoolId(schoolId);
+//                commonService.checkData(checkSchoolId, checkCourseCode, checkPaperNumber, user);
+//            }
             map.put("dataCount", dataList.size());
         } catch (Exception e) {
             redisTemplate.opsForValue().set(key, value);

+ 22 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -82,7 +82,7 @@ public class CreatePdfUtil {
                 ordinaryPdfList.add(new PdfDto(localFile.getPath(), PageSizeEnum.A4, pageCount));
             }
         } else {
-            basicAttachmentService.saveAttachmentPdf(basicAttachment, ordinaryPdfList, printCount);
+            basicAttachmentService.saveAttachmentPdf(basicAttachment, ordinaryPdfList, printCount, 0);
         }
     }
 
@@ -152,7 +152,6 @@ public class CreatePdfUtil {
                 return 0;
             }
         }).get().getSiteNumber();
-        minSite = Objects.isNull(minSite) ? "" : minSite;
 
         String maxSite = examStudentList.stream().max((a, b) -> {
             if (Objects.nonNull(a.getSiteNumber()) && Objects.nonNull(a.getSiteNumber())) {
@@ -161,17 +160,17 @@ public class CreatePdfUtil {
                 return 0;
             }
         }).get().getSiteNumber();
-        maxSite = Objects.isNull(maxSite) ? "" : maxSite;
 
         htmlMap.put("minSite", minSite);
         htmlMap.put("maxSite", maxSite);
         htmlMap.put("studentCount", examStudentList.size());
 
-        htmlMap.put("tag", tag ? "订" : "");
+        htmlMap.put("tag", tag ? "订" : null);
 
         htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
         htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
         htmlMap.computeIfAbsent("printCount", v -> printCount);
+        htmlMap.computeIfAbsent("sequence", v -> 1);
         freemarkerUtil.createPaperPackage(htmlMap);
     }
 
@@ -244,11 +243,13 @@ public class CreatePdfUtil {
                 for (int j = 0; j < htmlTableCount; j++) {
                     ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
                     examStudentDto.setIndex(j + 1);
+                    examStudentDto.setExtendFields(getClassName(examStudentDto.getExtendFields()));
                     examStudentList1.add(examStudentDto);
                 }
                 for (int j = htmlTableCount; j < subStudents.size(); j++) {
                     ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
                     examStudentDto.setIndex(j + 1);
+                    examStudentDto.setExtendFields(getClassName(examStudentDto.getExtendFields()));
                     examStudentList2.add(examStudentDto);
                 }
                 if (examStudentList1.size() > examStudentList2.size()) {
@@ -265,6 +266,7 @@ public class CreatePdfUtil {
         htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
         htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
         htmlMap.computeIfAbsent("printCount", v -> printCount);
+        htmlMap.computeIfAbsent("sequence", v -> 2);
         freemarkerUtil.createSignBook(htmlMap);
     }
 
@@ -513,4 +515,20 @@ public class CreatePdfUtil {
         jsonArray.add(object);
         return cardAttachment;
     }
+
+    /**
+     * 获取班级名称
+     *
+     * @param extendCloumn
+     * @return
+     */
+    private String getClassName(String extendCloumn) {
+        List<Map> mapList = JSONObject.parseArray(extendCloumn, Map.class);
+        for (Map map : mapList) {
+            if (Objects.equals("className", map.get("code").toString())) {
+                return map.get("value").toString();
+            }
+        }
+        return null;
+    }
 }

+ 1 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/FreemarkerUtil.java

@@ -116,9 +116,8 @@ public class FreemarkerUtil {
                         UploadFileEnum.HTML
                 });
                 basicAttachment.setPath(jsonObject.toJSONString());
-                basicAttachmentService.saveAttachmentPdf(basicAttachment, (List<PdfDto>) dataMap.get("variablePdfList"), (Integer) dataMap.get("printCount"));
+                basicAttachmentService.saveAttachmentPdf(basicAttachment, (List<PdfDto>) dataMap.get("variablePdfList"), (Integer) dataMap.get("printCount"), (Integer) dataMap.get("sequence"));
             }
-            log.info("{}文件创建成功", htmlFile.toString());
             htmlFile.delete();
         } catch (Exception e) {
             log.error("请求出错", e);

+ 2 - 0
distributed-print-task/src/main/java/com/qmth/distributed/print/task/job/TimedSyncSchoolJob.java

@@ -14,12 +14,14 @@ import java.io.IOException;
  * @Date: 2021-04-19
  */
 public class TimedSyncSchoolJob extends QuartzJobBean {
+
     @Resource
     JobService jobService;
 
     @Override
     protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
         try {
+            jobService.updatePrintPlan();
             jobService.updateSchoolInfo();
         } catch (IOException e) {
             e.printStackTrace();

+ 5 - 0
distributed-print-task/src/main/java/com/qmth/distributed/print/task/job/service/JobService.java

@@ -15,4 +15,9 @@ public interface JobService {
      * 同步学校信息
      */
     void updateSchoolInfo() throws IOException;
+
+    /**
+     * 更新印刷计划状态
+     */
+    void updatePrintPlan();
 }

+ 29 - 0
distributed-print-task/src/main/java/com/qmth/distributed/print/task/job/service/impl/JobServiceImpl.java

@@ -1,13 +1,20 @@
 package com.qmth.distributed.print.task.job.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.qmth.distributed.print.business.entity.ExamPrintPlan;
+import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
+import com.qmth.distributed.print.business.service.ExamPrintPlanService;
 import com.qmth.distributed.print.business.service.OrgCenterDataDisposeService;
 import com.qmth.distributed.print.task.job.service.JobService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.io.IOException;
+import java.util.List;
+import java.util.Objects;
 
 /**
  * @Description: job service impl
@@ -23,8 +30,30 @@ public class JobServiceImpl implements JobService {
     @Resource
     OrgCenterDataDisposeService orgCenterDataDisposeService;
 
+    @Resource
+    ExamPrintPlanService examPrintPlanService;
+
     @Override
     public void updateSchoolInfo() throws IOException {
         orgCenterDataDisposeService.updateSchoolInfo();
     }
+
+    /**
+     * 更新印刷计划状态
+     */
+    @Override
+    @Transactional
+    public void updatePrintPlan() {
+        QueryWrapper<ExamPrintPlan> examPrintPlanQueryWrapper = new QueryWrapper<>();
+        examPrintPlanQueryWrapper.lambda().ne(ExamPrintPlan::getStatus, PrintPlanStatusEnum.END);
+        List<ExamPrintPlan> examPrintPlanList = examPrintPlanService.list(examPrintPlanQueryWrapper);
+        if (Objects.nonNull(examPrintPlanList) && examPrintPlanList.size() > 0) {
+            for (ExamPrintPlan examPrintPlan : examPrintPlanList) {
+                if (Objects.nonNull(examPrintPlan.getExamEndTime()) && System.currentTimeMillis() >= examPrintPlan.getExamEndTime()) {
+                    examPrintPlan.setStatus(PrintPlanStatusEnum.END);
+                }
+            }
+        }
+        examPrintPlanService.saveOrUpdateBatch(examPrintPlanList);
+    }
 }