|
@@ -28,11 +28,13 @@ import com.qmth.teachcloud.common.util.OssUtil;
|
|
|
import com.qmth.teachcloud.common.util.RedisUtil;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.hibernate.validator.internal.util.logging.formatter.CollectionOfClassesObjectFormatter;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
@@ -440,6 +442,8 @@ public class CreatePdfUtil {
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
public PaperPdfDto getPaperPdfFile(String paperType, ExamTaskDetail examTaskDetail) throws IOException {
|
|
|
+ String[] paperTypes = paperType.split(",");
|
|
|
+ List<PaperPdfDto> paperPdfDtoList = new ArrayList<>();
|
|
|
PaperPdfDto paperPdfDto = null;
|
|
|
JSONArray jsonArrayPaper = JSONArray.parseArray(examTaskDetail.getPaperAttachmentIds());
|
|
|
for (int i = 0; i < jsonArrayPaper.size(); i++) {
|
|
@@ -451,12 +455,16 @@ public class CreatePdfUtil {
|
|
|
throw ExceptionResultEnum.ATTACHMENT_IS_NULL.exception();
|
|
|
}
|
|
|
String name = (String) object.get("name");
|
|
|
- if (Objects.equals(name.toUpperCase(), paperType.toUpperCase())) {
|
|
|
- File file = teachcloudCommonService.getFile(basicAttachment.getPath(), false);
|
|
|
- int pages = (int) object.get("pages");
|
|
|
- paperPdfDto = new PaperPdfDto(file, pages);
|
|
|
- break;
|
|
|
+ for (String type : paperTypes) {
|
|
|
+ if (Objects.equals(name.toUpperCase(), type.toUpperCase())) {
|
|
|
+ File file = teachcloudCommonService.getFile(basicAttachment.getPath(), false);
|
|
|
+ int pages = (int) object.get("pages");
|
|
|
+ paperPdfDto = new PaperPdfDto(file, pages);
|
|
|
+ paperPdfDtoList.add(paperPdfDto);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
return paperPdfDto;
|
|
@@ -477,6 +485,8 @@ public class CreatePdfUtil {
|
|
|
String unexposedPaperType = examTaskDetail.getUnexposedPaperType();
|
|
|
//已曝光卷型
|
|
|
String exposedPaperType = examTaskDetail.getExposedPaperType();
|
|
|
+ // 单次抽取套数
|
|
|
+ int drawCount = examTaskDetail.getDrawCount().intValue();
|
|
|
if (drawRule == DrawRuleEnum.ONE) {
|
|
|
if (Objects.isNull(unexposedPaperType) || Objects.equals(unexposedPaperType.trim(), "")) {
|
|
|
CreatePdfCacheUtil.deletePaperType(key);
|
|
@@ -499,6 +509,9 @@ public class CreatePdfUtil {
|
|
|
if (Objects.isNull(paperType) || (StringUtils.isNotBlank(unexposedPaperType) && !unexposedPaperType.contains(paperType))) {
|
|
|
if (drawRule == DrawRuleEnum.ONE) {
|
|
|
paperTypes = unexposedPaperType.split(",");
|
|
|
+ if (paperTypes.length - drawCount < 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有可用卷型");
|
|
|
+ }
|
|
|
} else {
|
|
|
if (Objects.nonNull(unexposedPaperType)) {
|
|
|
paperTypes = unexposedPaperType.split(",");
|
|
@@ -506,8 +519,7 @@ public class CreatePdfUtil {
|
|
|
paperTypes = exposedPaperType.split(",");
|
|
|
}
|
|
|
}
|
|
|
- int paperRandom = new Random().nextInt(paperTypes.length);
|
|
|
- paperType = paperTypes[paperRandom];
|
|
|
+ paperType = randomPaperType(paperTypes, exposedPaperType.split(","), drawCount);
|
|
|
CreatePdfCacheUtil.setPaperType(key, paperType);
|
|
|
}
|
|
|
break;
|
|
@@ -532,6 +544,32 @@ public class CreatePdfUtil {
|
|
|
return paperType;
|
|
|
}
|
|
|
|
|
|
+ private String randomPaperType(String[] unexposedPaperTypes, String[] exposedPaperTypes, int drawCount) {
|
|
|
+ List<String> finalTypes = new ArrayList<>();
|
|
|
+ List<String> unexposedPaperTypesList = Arrays.asList(unexposedPaperTypes);
|
|
|
+ List<String> exposedPaperTypesList = Arrays.asList(exposedPaperTypes);
|
|
|
+ if (unexposedPaperTypesList.size() - drawCount >= 0) {
|
|
|
+ for (int i = 0; i < drawCount; i++) {
|
|
|
+ int paperRandom = new Random().nextInt(unexposedPaperTypesList.size());
|
|
|
+ finalTypes.add(unexposedPaperTypesList.get(paperRandom));
|
|
|
+ unexposedPaperTypesList.remove(paperRandom);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ for (int i = 0; i < unexposedPaperTypesList.size(); i++) {
|
|
|
+ int paperRandom = new Random().nextInt(unexposedPaperTypesList.size());
|
|
|
+ finalTypes.add(unexposedPaperTypesList.get(paperRandom));
|
|
|
+ unexposedPaperTypesList.remove(paperRandom);
|
|
|
+ }
|
|
|
+ for (int i = 0; i < drawCount - unexposedPaperTypesList.size(); i++) {
|
|
|
+ int paperRandom = new Random().nextInt(exposedPaperTypesList.size());
|
|
|
+ finalTypes.add(exposedPaperTypesList.get(paperRandom));
|
|
|
+ exposedPaperTypesList.remove(paperRandom);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return String.join(",", finalTypes);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 合并A3 pdf
|
|
|
*
|