|
@@ -8,12 +8,12 @@ import com.google.gson.Gson;
|
|
import com.itextpdf.text.DocumentException;
|
|
import com.itextpdf.text.DocumentException;
|
|
import com.qmth.distributed.print.business.bean.dto.ExamStudentDto;
|
|
import com.qmth.distributed.print.business.bean.dto.ExamStudentDto;
|
|
import com.qmth.distributed.print.business.bean.dto.PdfDto;
|
|
import com.qmth.distributed.print.business.bean.dto.PdfDto;
|
|
|
|
+import com.qmth.distributed.print.business.cache.CreatePdfCacheUtil;
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
import com.qmth.distributed.print.business.enums.*;
|
|
import com.qmth.distributed.print.business.enums.*;
|
|
import com.qmth.distributed.print.business.service.BasicAttachmentService;
|
|
import com.qmth.distributed.print.business.service.BasicAttachmentService;
|
|
import com.qmth.distributed.print.business.service.CommonService;
|
|
import com.qmth.distributed.print.business.service.CommonService;
|
|
import com.qmth.distributed.print.business.service.ExamDetailService;
|
|
import com.qmth.distributed.print.business.service.ExamDetailService;
|
|
-import com.qmth.distributed.print.business.templete.service.impl.TaskLogicServiceImpl;
|
|
|
|
import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
@@ -26,7 +26,6 @@ import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
-import java.util.concurrent.ConcurrentMap;
|
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -55,15 +54,18 @@ public class CreatePdfUtil {
|
|
@Resource
|
|
@Resource
|
|
ExamDetailService detailService;
|
|
ExamDetailService detailService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ RedisUtil redisUtil;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 创建登记表
|
|
* 创建登记表
|
|
*
|
|
*
|
|
- * @param examDetailCourse
|
|
|
|
|
|
+ * @param examDetail
|
|
* @param basicAttachment
|
|
* @param basicAttachment
|
|
* @param ordinaryPdfList
|
|
* @param ordinaryPdfList
|
|
* @param printCount
|
|
* @param printCount
|
|
*/
|
|
*/
|
|
- public void createCheckIn(ExamDetailCourse examDetailCourse, BasicAttachment basicAttachment, List<PdfDto> ordinaryPdfList, Integer printCount) throws IOException, DocumentException {
|
|
|
|
|
|
+ public void createCheckIn(ExamDetail examDetail, BasicAttachment basicAttachment, List<PdfDto> ordinaryPdfList, Integer printCount) throws IOException, DocumentException {
|
|
if (Objects.isNull(basicAttachment)) {
|
|
if (Objects.isNull(basicAttachment)) {
|
|
throw ExceptionResultEnum.ERROR.exception("找不到附件");
|
|
throw ExceptionResultEnum.ERROR.exception("找不到附件");
|
|
}
|
|
}
|
|
@@ -78,7 +80,7 @@ public class CreatePdfUtil {
|
|
ordinaryPdfList.add(new PdfDto(localFile.getPath(), PageSizeEnum.A4, pdfDto.getPageCount()));
|
|
ordinaryPdfList.add(new PdfDto(localFile.getPath(), PageSizeEnum.A4, pdfDto.getPageCount()));
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- basicAttachmentService.saveAttachmentPdf(ClassifyEnum.CHECK_IN, examDetailCourse, basicAttachment, ordinaryPdfList, printCount, 0);
|
|
|
|
|
|
+ basicAttachmentService.saveAttachmentPdf(ClassifyEnum.CHECK_IN, examDetail, basicAttachment, ordinaryPdfList, printCount, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -154,7 +156,7 @@ public class CreatePdfUtil {
|
|
htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
|
|
htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
|
|
htmlMap.computeIfAbsent("printCount", v -> printCount);
|
|
htmlMap.computeIfAbsent("printCount", v -> printCount);
|
|
htmlMap.computeIfAbsent("sequence", v -> 1);
|
|
htmlMap.computeIfAbsent("sequence", v -> 1);
|
|
- htmlMap.computeIfAbsent("examDetailCourse", v -> examDetailCourse);
|
|
|
|
|
|
+ htmlMap.computeIfAbsent("examDetail", v -> examDetail);
|
|
htmlMap.computeIfAbsent("printType", v -> ClassifyEnum.PACKAGE);
|
|
htmlMap.computeIfAbsent("printType", v -> ClassifyEnum.PACKAGE);
|
|
freemarkerUtil.createPaperPackage(htmlMap);
|
|
freemarkerUtil.createPaperPackage(htmlMap);
|
|
}
|
|
}
|
|
@@ -252,7 +254,7 @@ public class CreatePdfUtil {
|
|
htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
|
|
htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
|
|
htmlMap.computeIfAbsent("printCount", v -> printCount);
|
|
htmlMap.computeIfAbsent("printCount", v -> printCount);
|
|
htmlMap.computeIfAbsent("sequence", v -> 2);
|
|
htmlMap.computeIfAbsent("sequence", v -> 2);
|
|
- htmlMap.computeIfAbsent("examDetailCourse", v -> examDetailCourse);
|
|
|
|
|
|
+ htmlMap.computeIfAbsent("examDetail", v -> examDetail);
|
|
htmlMap.computeIfAbsent("printType", v -> ClassifyEnum.SIGN);
|
|
htmlMap.computeIfAbsent("printType", v -> ClassifyEnum.SIGN);
|
|
freemarkerUtil.createSignBook(htmlMap);
|
|
freemarkerUtil.createSignBook(htmlMap);
|
|
}
|
|
}
|
|
@@ -341,43 +343,69 @@ public class CreatePdfUtil {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public String getPaperType(ExamPrintPlan examPrintPlan, ExamTaskDetail examTaskDetail, ExamDetail examDetail, ExamDetailCourse examDetailCourse) {
|
|
public String getPaperType(ExamPrintPlan examPrintPlan, ExamTaskDetail examTaskDetail, ExamDetail examDetail, ExamDetailCourse examDetailCourse) {
|
|
- ConcurrentMap<Integer, String> paperTypeMap = TaskLogicServiceImpl.getPaperTypeMap();
|
|
|
|
|
|
+ Map<String, Object> paperTypeMap = CreatePdfCacheUtil.getCurrentPaperType(examPrintPlan.getId());
|
|
|
|
+ paperTypeMap = Objects.isNull(paperTypeMap) ? paperTypeMap = new HashMap<>() : paperTypeMap;
|
|
String key = examDetail.getSchoolId()
|
|
String key = examDetail.getSchoolId()
|
|
+ Math.abs(examDetail.getExamStartTime() + examDetail.getExamEndTime())
|
|
+ Math.abs(examDetail.getExamStartTime() + examDetail.getExamEndTime())
|
|
+ examDetail.getExamPlace()
|
|
+ examDetail.getExamPlace()
|
|
+ examDetailCourse.getCourseCode()
|
|
+ examDetailCourse.getCourseCode()
|
|
+ examDetailCourse.getPaperNumber();
|
|
+ examDetailCourse.getPaperNumber();
|
|
String paperType = null;
|
|
String paperType = null;
|
|
- if (paperTypeMap.containsKey(key.hashCode())) {
|
|
|
|
- paperType = paperTypeMap.get(key.hashCode());
|
|
|
|
- } else {
|
|
|
|
- //抽取卷型
|
|
|
|
- DrawRuleEnum drawRule = Objects.nonNull(examPrintPlan.getDrawRule()) ? examPrintPlan.getDrawRule() : DrawRuleEnum.ONE;
|
|
|
|
- //未曝光卷型
|
|
|
|
- String unexposedPaperType = examTaskDetail.getUnexposedPaperType();
|
|
|
|
- //已曝光卷型
|
|
|
|
- String exposedPaperType = examTaskDetail.getExposedPaperType();
|
|
|
|
- String[] paperTypes = null;
|
|
|
|
- if (drawRule == DrawRuleEnum.ONE) {
|
|
|
|
- if (Objects.isNull(unexposedPaperType)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
|
|
|
|
- } else {
|
|
|
|
- paperTypes = unexposedPaperType.split(",");
|
|
|
|
|
|
+ boolean lock = true;
|
|
|
|
+ for (int i = 0; i < SystemConstant.MAX_RETRY_COUNT; i++) {
|
|
|
|
+ lock = redisUtil.lock(key, SystemConstant.REDIS_CACHE_TIME_OUT);
|
|
|
|
+ if (lock) {
|
|
|
|
+ try {
|
|
|
|
+ if (paperTypeMap.containsKey(key)) {
|
|
|
|
+ paperType = (String) paperTypeMap.get(key);
|
|
|
|
+ } else {
|
|
|
|
+ //抽取卷型
|
|
|
|
+ DrawRuleEnum drawRule = Objects.nonNull(examPrintPlan.getDrawRule()) ? examPrintPlan.getDrawRule() : DrawRuleEnum.ONE;
|
|
|
|
+ //未曝光卷型
|
|
|
|
+ String unexposedPaperType = examTaskDetail.getUnexposedPaperType();
|
|
|
|
+ //已曝光卷型
|
|
|
|
+ String exposedPaperType = examTaskDetail.getExposedPaperType();
|
|
|
|
+ String[] paperTypes = null;
|
|
|
|
+ if (drawRule == DrawRuleEnum.ONE) {
|
|
|
|
+ if (Objects.isNull(unexposedPaperType)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
|
|
|
|
+ } else {
|
|
|
|
+ paperTypes = unexposedPaperType.split(",");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (Objects.isNull(exposedPaperType) && Objects.isNull(unexposedPaperType)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(unexposedPaperType)) {
|
|
|
|
+ paperTypes = unexposedPaperType.split(",");
|
|
|
|
+ } else {
|
|
|
|
+ paperTypes = exposedPaperType.split(",");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ int paperRandom = new Random().nextInt(paperTypes.length);
|
|
|
|
+ paperType = paperTypes[paperRandom];
|
|
|
|
+ String finalPaperType = paperType;
|
|
|
|
+ paperTypeMap.computeIfAbsent(key, v -> finalPaperType);
|
|
|
|
+ CreatePdfCacheUtil.setCurrentPaperType(examPrintPlan.getId(), paperTypeMap);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("请求出错", e);
|
|
|
|
+ } finally {
|
|
|
|
+ redisUtil.releaseLock(key);
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- if (Objects.isNull(exposedPaperType) && Objects.isNull(unexposedPaperType)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
|
|
|
|
- }
|
|
|
|
- if (Objects.nonNull(unexposedPaperType)) {
|
|
|
|
- paperTypes = unexposedPaperType.split(",");
|
|
|
|
- } else {
|
|
|
|
- paperTypes = exposedPaperType.split(",");
|
|
|
|
|
|
+ } else {//未获取到锁,等待500毫秒继续获取
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(500);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- int paperRandom = new Random().nextInt(paperTypes.length);
|
|
|
|
- paperType = paperTypes[paperRandom];
|
|
|
|
- String finalPaperType = paperType;
|
|
|
|
- paperTypeMap.computeIfAbsent(key.hashCode(), v -> finalPaperType);
|
|
|
|
|
|
+ }
|
|
|
|
+ log.info("getPaperType key:{},paperType:{},lock:{},examDetailId:{},examDetailCourseId:{}", key, paperType, lock, examDetail.getId(), examDetailCourse.getId());
|
|
|
|
+ if (!lock) {
|
|
|
|
+ log.info("getPaperType 未获取到锁,key:{}", key);
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未获取到试卷类型");
|
|
}
|
|
}
|
|
return paperType;
|
|
return paperType;
|
|
}
|
|
}
|