|
@@ -2,31 +2,32 @@ package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+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.bean.dto.FieldsDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.PrintTaskDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.PrintTaskTotalDto;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.TaskTotalLeftDto;
|
|
|
import com.qmth.distributed.print.business.bean.result.ExaminationDetailResult;
|
|
|
import com.qmth.distributed.print.business.bean.result.ExaminationResult;
|
|
|
import com.qmth.distributed.print.business.bean.result.SummarizedDataResult;
|
|
|
+import com.qmth.distributed.print.business.entity.BasicAttachment;
|
|
|
import com.qmth.distributed.print.business.entity.BasicExamRule;
|
|
|
import com.qmth.distributed.print.business.entity.ExamDetail;
|
|
|
import com.qmth.distributed.print.business.entity.ExamDetailCourse;
|
|
|
+import com.qmth.distributed.print.business.enums.ExamDetailStatusEnum;
|
|
|
import com.qmth.distributed.print.business.mapper.ExamDetailMapper;
|
|
|
-import com.qmth.distributed.print.business.service.BasicExamRuleService;
|
|
|
-import com.qmth.distributed.print.business.service.CacheService;
|
|
|
-import com.qmth.distributed.print.business.service.ExamDetailCourseService;
|
|
|
-import com.qmth.distributed.print.business.service.ExamDetailService;
|
|
|
+import com.qmth.distributed.print.business.service.*;
|
|
|
import com.qmth.distributed.print.business.util.ServletUtil;
|
|
|
import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
|
import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
|
-
|
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -58,12 +59,18 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
|
|
|
@Resource
|
|
|
private CacheService cacheService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BasicAttachmentService basicAttachmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonService commonService;
|
|
|
+
|
|
|
private final static Logger log = LoggerFactory.getLogger(ExamDetailServiceImpl.class);
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public double calculateTotalSubjects(Long printPlanId) {
|
|
|
- List<ExamDetail> examDetailList = this.list(new QueryWrapper<ExamDetail>().lambda().eq(ExamDetail::getPrintPlanId,printPlanId));
|
|
|
+ List<ExamDetail> examDetailList = this.list(new QueryWrapper<ExamDetail>().lambda().eq(ExamDetail::getPrintPlanId, printPlanId));
|
|
|
return examDetailList.stream().collect(Collectors.summarizingDouble(ExamDetail::getTotalSubjects)).getSum();
|
|
|
}
|
|
|
|
|
@@ -71,7 +78,7 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
|
|
|
@Override
|
|
|
public double calculateTotalPackages(Long printPlanId) {
|
|
|
double result = 0;
|
|
|
- List<ExamDetail> examDetailList = this.list(new QueryWrapper<ExamDetail>().lambda().eq(ExamDetail::getPrintPlanId,printPlanId));
|
|
|
+ List<ExamDetail> examDetailList = this.list(new QueryWrapper<ExamDetail>().lambda().eq(ExamDetail::getPrintPlanId, printPlanId));
|
|
|
for (ExamDetail examDetail : examDetailList) {
|
|
|
double count = examDetailCourseService.calculatePackagesByDetailId(examDetail.getId());
|
|
|
result = result + count;
|
|
@@ -83,17 +90,43 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
|
|
|
public IPage<PrintTaskDto> listPrintTask(Long printPlanId, String status, String courseCode, String paperNumber, String examPlace, String examRoom, Long examStartTime, Long examEndTime, Integer pageNumber, Integer pageSize) {
|
|
|
Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
|
Page<PrintTaskDto> page = new Page<>(pageNumber, pageSize);
|
|
|
- IPage<PrintTaskDto> pirntTaskDtoIPage = this.baseMapper.listPrintTask(page, schoolId, printPlanId,status, courseCode, paperNumber, examPlace,examRoom, examStartTime, examEndTime);
|
|
|
+ IPage<PrintTaskDto> pirntTaskDtoIPage = this.baseMapper.listPrintTask(page, schoolId, printPlanId, status, courseCode, paperNumber, examPlace, examRoom, examStartTime, examEndTime);
|
|
|
return pirntTaskDtoIPage;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PrintTaskTotalDto taskTotalData(Long printPlanId, String status, String courseCode, String paperNumber, String examPlace, String examRoom, Long examStartTime, Long examEndTime) {
|
|
|
- return null;
|
|
|
+ Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
|
+ PrintTaskTotalDto printTaskTotalDto = this.baseMapper.taskTotalData(schoolId, printPlanId, status, courseCode, paperNumber, examPlace, examRoom, examStartTime, examEndTime);
|
|
|
+
|
|
|
+ // 计算A3剩余
|
|
|
+ TaskTotalLeftDto totalLeftDto = this.baseMapper.calcLeftA3(schoolId);
|
|
|
+ if (printTaskTotalDto != null) {
|
|
|
+ // 分别计算张数
|
|
|
+ // 试卷
|
|
|
+ int paperPagesA3 = totalLeftDto.getPaperPagesA3();
|
|
|
+ int printPaperCount = totalLeftDto.getPrintPaperCount();
|
|
|
+ int paperPages = paperPagesA3 % 2 == 0 ? paperPagesA3 / 2 : paperPagesA3 / 2 + 1;
|
|
|
+ int totalPaperPages = paperPages * printPaperCount;
|
|
|
+
|
|
|
+ // 题卡
|
|
|
+ int cardPagesA3 = totalLeftDto.getCardPagesA3();
|
|
|
+ int printCardCount = totalLeftDto.getPrintCardCount();
|
|
|
+ int cardPages = cardPagesA3 % 2 == 0 ? cardPagesA3 / 2 : cardPagesA3 / 2 + 1;
|
|
|
+ int totalCardPages = cardPages * printCardCount;
|
|
|
+ printTaskTotalDto.setPagesA3Left(String.valueOf(totalPaperPages + totalCardPages));
|
|
|
+
|
|
|
+ }
|
|
|
+ return printTaskTotalDto;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String taskViewPDF(Long id) {
|
|
|
+ public String taskViewPDF(Long examDetailId) {
|
|
|
+ ExamDetail examDetail = this.getById(examDetailId);
|
|
|
+ if (examDetail.getAttachmentId() != null) {
|
|
|
+ BasicAttachment attachment = basicAttachmentService.getById(examDetail.getAttachmentId());
|
|
|
+ return attachment == null ? null : commonService.filePreview(attachment.getPath());
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -102,15 +135,15 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
|
|
|
public List<FieldsDto> findExaminationFields(Long schoolId) {
|
|
|
// TODO: 2021/4/9 回复schoolId的获取方式
|
|
|
// BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId();
|
|
|
- BasicExamRule basicExamRule = basicExamRuleService.list(new QueryWrapper<BasicExamRule>().lambda().eq(BasicExamRule::getSchoolId,schoolId)).get(0);
|
|
|
- if (basicExamRule == null){
|
|
|
+ BasicExamRule basicExamRule = basicExamRuleService.list(new QueryWrapper<BasicExamRule>().lambda().eq(BasicExamRule::getSchoolId, schoolId)).get(0);
|
|
|
+ if (basicExamRule == null) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("找不到该学校考务字段信息 + schoolId" + schoolId);
|
|
|
}
|
|
|
String requiredFields = basicExamRule.getRequiredFields();
|
|
|
String extendFields = basicExamRule.getExtendFields();
|
|
|
// 必选字段
|
|
|
- List<FieldsDto> requiredFieldsList = JSONObject.parseArray(requiredFields,FieldsDto.class);
|
|
|
- if (requiredFieldsList.stream().anyMatch(e -> !e.getEnable())){
|
|
|
+ List<FieldsDto> requiredFieldsList = JSONObject.parseArray(requiredFields, FieldsDto.class);
|
|
|
+ if (requiredFieldsList.stream().anyMatch(e -> !e.getEnable())) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("该学校考务字段设置存在必选字段禁用的情况 schoolId = " + schoolId);
|
|
|
}
|
|
|
for (FieldsDto fieldsDto : requiredFieldsList) {
|
|
@@ -118,9 +151,9 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
|
|
|
}
|
|
|
|
|
|
// 扩展字段
|
|
|
- List<FieldsDto> extendFieldsList = JSONObject.parseArray(extendFields,FieldsDto.class);
|
|
|
+ List<FieldsDto> extendFieldsList = JSONObject.parseArray(extendFields, FieldsDto.class);
|
|
|
List<String> extendCodeList = extendFieldsList.stream().map(FieldsDto::getCode).collect(Collectors.toList());
|
|
|
- if (extendCodeList.stream().anyMatch(e -> requiredFieldsList.stream().map(FieldsDto::getCode).collect(Collectors.toList()).contains(e))){
|
|
|
+ if (extendCodeList.stream().anyMatch(e -> requiredFieldsList.stream().map(FieldsDto::getCode).collect(Collectors.toList()).contains(e))) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("该学校考务字段设置存在相同的code schoolId = " + schoolId);
|
|
|
}
|
|
|
// 有效的扩展字段
|
|
@@ -181,11 +214,11 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public IPage<ExaminationResult> findExaminationBriefPage(Long schoolId, Long printPlanId, String courseCode, String paperNumber, String examPlace, String examRoom, String packageCode, int pageNumber, int pageSize) {
|
|
|
- IPage<ExaminationResult> page = examDetailMapper.findBriefPage(new Page<>(pageNumber,pageSize),schoolId,printPlanId,courseCode,paperNumber,examPlace,examRoom,packageCode);
|
|
|
+ IPage<ExaminationResult> page = examDetailMapper.findBriefPage(new Page<>(pageNumber, pageSize), schoolId, printPlanId, courseCode, paperNumber, examPlace, examRoom, packageCode);
|
|
|
List<ExaminationResult> list = page.getRecords();
|
|
|
for (ExaminationResult examinationResult : list) {
|
|
|
String examDetailCourseIds = examinationResult.getExamDetailCourseIds();
|
|
|
- if (examDetailCourseIds == null || examDetailCourseIds.length() == 0){
|
|
|
+ if (examDetailCourseIds == null || examDetailCourseIds.length() == 0) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("考务数据确实课程信息");
|
|
|
}
|
|
|
String[] arr = examDetailCourseIds.split(",");
|
|
@@ -201,8 +234,8 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
|
|
|
courseNameCodeStr = courseNameCodeStr + name + "(" + code + ")" + separator;
|
|
|
paperNumberStr = paperNumberStr + number + separator;
|
|
|
}
|
|
|
- courseNameCodeStr = courseNameCodeStr.substring(0,courseNameCodeStr.length() - separator.length());
|
|
|
- paperNumberStr = paperNumberStr.substring(0,paperNumberStr.length() - separator.length());
|
|
|
+ courseNameCodeStr = courseNameCodeStr.substring(0, courseNameCodeStr.length() - separator.length());
|
|
|
+ paperNumberStr = paperNumberStr.substring(0, paperNumberStr.length() - separator.length());
|
|
|
examinationResult.setCourseNameCode(courseNameCodeStr);
|
|
|
examinationResult.setPaperNumber(paperNumberStr);
|
|
|
}
|
|
@@ -232,13 +265,13 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public IPage<ExaminationDetailResult> findExaminationDetail(Long printPlanId, String courseCode, String paperNumber, String examPlace, String examRoom, String studentParam, int pageNumber, int pageSize) {
|
|
|
- return examDetailMapper.findDetailPage(new Page<>(pageNumber,pageSize),printPlanId,courseCode,paperNumber,examPlace,examRoom,studentParam);
|
|
|
+ return examDetailMapper.findDetailPage(new Page<>(pageNumber, pageSize), printPlanId, courseCode, paperNumber, examPlace, examRoom, studentParam);
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public IPage<ExaminationDetailResult> findExaminationDetail(Long examDetailId, int pageNumber, int pageSize) {
|
|
|
- return examDetailMapper.findDetailPageById(new Page<>(pageNumber,pageSize),examDetailId);
|
|
|
+ return examDetailMapper.findDetailPageById(new Page<>(pageNumber, pageSize), examDetailId);
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -254,4 +287,34 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
|
|
|
List<ExamDetail> examDetail = this.list();
|
|
|
return examDetail.stream().map(ExamDetail::getExamRoom).distinct().collect(Collectors.toList());
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean submitTask(ExamDetail examDetail) {
|
|
|
+ // 检查前置操作是否完成 todo
|
|
|
+ UpdateWrapper<ExamDetail> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.lambda().set(ExamDetail::getStatus, ExamDetailStatusEnum.PRINTING).eq(ExamDetail::getId, examDetail.getId());
|
|
|
+ return this.update(updateWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean taskCancel(ExamDetail examDetail) {
|
|
|
+ ExamDetail detail = this.getById(examDetail.getId());
|
|
|
+ if (!detail.getStatus().name().equals(ExamDetailStatusEnum.WAITING.name())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("印刷状态为“待印刷”的任务可撤回提交");
|
|
|
+ }
|
|
|
+ UpdateWrapper<ExamDetail> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.lambda().set(ExamDetail::getStatus, ExamDetailStatusEnum.READY).eq(ExamDetail::getId, examDetail.getId());
|
|
|
+ return this.update(updateWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean resubmitTask(ExamDetail examDetail) {
|
|
|
+ ExamDetail detail = this.getById(examDetail.getId());
|
|
|
+ if (!detail.getStatus().name().equals(ExamDetailStatusEnum.PRINTING.name())
|
|
|
+ && !detail.getStatus().name().equals(ExamDetailStatusEnum.FINISH.name())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("印刷状态为“印刷中”、“已完成”的任务可重新提交印刷");
|
|
|
+ }
|
|
|
+ // todo 调用生成pdf方法
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|