|
@@ -172,66 +172,54 @@ public class PrintCommonServiceImpl implements PrintCommonService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public BasicAttachment saveAttachmentPdf(ClassifyEnum classifyEnum, ExamDetail examDetail, BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException {
|
|
|
+ File htmlFileTemp = null;
|
|
|
try {
|
|
|
boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
|
|
|
- String type = basicAttachment.getType();
|
|
|
- String filePath = null;
|
|
|
- String url = null;
|
|
|
+ String type = basicAttachment.getType(), filePath = null, url = null, ossStr = null;
|
|
|
File htmlFile = null;
|
|
|
- if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.FTL_PREFIX)) {
|
|
|
- filePath = (String) jsonObject.get(SystemConstant.HTML_PATH);
|
|
|
- if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig()) && filePath.contains(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
- url = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + filePath;
|
|
|
- htmlFile = new File(url);
|
|
|
- } else {
|
|
|
- htmlFile = new File(dictionaryConfig.fssPublicDomain().getConfig(), filePath);
|
|
|
- }
|
|
|
- } else if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.HTML_PREFIX)) {
|
|
|
+
|
|
|
+ StringJoiner pdfStringJoiner = new StringJoiner("");
|
|
|
+ if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.HTML_PREFIX)) {
|
|
|
filePath = (String) jsonObject.get(SystemConstant.PATH);
|
|
|
UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class, (String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
|
if (oss) {
|
|
|
- htmlFile = fileStoreUtil.ossDownload(filePath, url, uploadType.getFssType());
|
|
|
+ ossStr = SystemConstant.OSS;
|
|
|
+ htmlFileTemp = SystemConstant.getFileTempVar(SystemConstant.HTML_PREFIX);
|
|
|
+ htmlFile = fileStoreUtil.ossDownload(filePath, htmlFileTemp.getPath(), uploadType.getFssType());
|
|
|
} else {
|
|
|
+ ossStr = SystemConstant.LOCAL;
|
|
|
if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig()) && filePath.contains(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
url = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + filePath;
|
|
|
htmlFile = new File(url);
|
|
|
} else {
|
|
|
htmlFile = new File(dictionaryConfig.fssPublicDomain().getConfig(), filePath);
|
|
|
}
|
|
|
+ if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
|
|
|
+ pdfStringJoiner.add(dictionaryConfig.fssLocalPdfDomain().getConfig()).add(File.separator);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- StringJoiner pdfStringJoiner = SystemConstant.getDirName(UploadFileEnum.PDF, true);
|
|
|
- pdfStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.PDF_PREFIX);
|
|
|
|
|
|
+ pdfStringJoiner = SystemConstant.getDirName(pdfStringJoiner, UploadFileEnum.PDF, true);
|
|
|
+ pdfStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.PDF_PREFIX);
|
|
|
String pdfDirName = pdfStringJoiner.toString();
|
|
|
- String pdfDirNameStr = pdfStringJoiner.toString().replace("\\", "/");
|
|
|
- String destUrl = null;
|
|
|
- if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
- destUrl = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + pdfDirName;
|
|
|
- } else {
|
|
|
- destUrl = dictionaryConfig.fssPublicDomain().getConfig() + File.separator + pdfDirName;
|
|
|
- }
|
|
|
-
|
|
|
- File pdfFile = new File(destUrl);
|
|
|
- if (!pdfFile.exists()) {
|
|
|
- pdfFile.getParentFile().mkdirs();
|
|
|
- pdfFile.createNewFile();
|
|
|
- }
|
|
|
- HtmlToPdfUtil.convert(htmlFile.getPath(), destUrl, PageSizeEnum.A4);
|
|
|
+ File pdfFileTemp = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
|
|
|
+ HtmlToPdfUtil.convert(htmlFile.getPath(), pdfFileTemp.getPath(), PageSizeEnum.A4);
|
|
|
|
|
|
// File pdfFile = asposePdfUtil.documentToPdf(htmlFile.getPath(), destUrl, PaperSize.A4);
|
|
|
String htmlFileMd5 = DigestUtils.md5Hex(new FileInputStream(htmlFile));
|
|
|
- byte[] data = ByteArray.fromFile(pdfFile).value();
|
|
|
- String md5 = ByteArray.md5(data).toHexString();
|
|
|
- InputStream ins = new ByteArrayInputStream(data);
|
|
|
- //String pdfFileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
|
|
|
- PdfDto pdfDto = PdfUtil.addPdfPage(pdfFile);
|
|
|
- if (oss) {//上传至oss
|
|
|
- fileStoreUtil.ossUpload(pdfDirNameStr, ins, md5, fileStoreUtil.getUploadEnumByPath(pdfDirNameStr).getFssType());
|
|
|
-// htmlFile.delete();
|
|
|
- ins.close();
|
|
|
+ String pdfFileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFileTemp));
|
|
|
+ if (oss) {
|
|
|
+ fileStoreUtil.ossUpload(pdfDirName, pdfFileTemp, pdfFileMd5, fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
|
|
|
+ } else {
|
|
|
+ if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
|
|
|
+ File file = new File(pdfStringJoiner.toString());
|
|
|
+ FileCopyUtils.copy(file, pdfFileTemp);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ PdfDto pdfDto = PdfUtil.addPdfPage(pdfFileTemp);
|
|
|
JSONObject attachmentPath = JSONObject.parseObject(examDetail.getAttachmentPath());
|
|
|
attachmentPath = Objects.isNull(attachmentPath) ? new JSONObject() : attachmentPath;
|
|
|
JSONArray jsonArray = (JSONArray) attachmentPath.get(SystemConstant.PATH);
|
|
@@ -240,14 +228,9 @@ public class PrintCommonServiceImpl implements PrintCommonService {
|
|
|
object.put("printType", classifyEnum.name());
|
|
|
object.put(SystemConstant.HTML_PATH, filePath);
|
|
|
object.put("htmlMd5", htmlFileMd5);
|
|
|
- object.put("pdfMd5", md5);
|
|
|
- if (!oss) {
|
|
|
- object.put(SystemConstant.PDF_PATH, pdfFile.getPath());
|
|
|
- object.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
- } else {
|
|
|
- object.put(SystemConstant.PDF_PATH, pdfDirNameStr);
|
|
|
- object.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
- }
|
|
|
+ object.put("pdfMd5", pdfFileMd5);
|
|
|
+ object.put(SystemConstant.PDF_PATH, pdfDirName);
|
|
|
+ object.put(SystemConstant.TYPE, ossStr);
|
|
|
object.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
|
|
|
UploadFileEnum.HTML,
|
|
|
UploadFileEnum.PDF
|
|
@@ -257,7 +240,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
|
|
|
examDetail.setAttachmentPath(attachmentPath.toJSONString());
|
|
|
basicAttachment.setPages(pdfDto.getActualPageCount());
|
|
|
for (int i = 0; i < printCount; i++) {
|
|
|
- pdfList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A4, pdfDto.getPageCount(), sequence));
|
|
|
+ pdfList.add(new PdfDto(pdfFileTemp.getPath(), PageSizeEnum.A4, pdfDto.getPageCount(), sequence));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error(SystemConstant.LOG_ERROR, e);
|
|
@@ -280,51 +263,44 @@ public class PrintCommonServiceImpl implements PrintCommonService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void saveAttachmentSignPdf(PdfSignDto pdfFillDto, ExamDetail examDetail, List<PdfDto> pdfList, Integer printCount) {
|
|
|
+ File pdfFileTemp = null;
|
|
|
try {
|
|
|
boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
- StringJoiner pdfStringJoiner = SystemConstant.getDirName(UploadFileEnum.PDF, true);
|
|
|
+ StringJoiner pdfStringJoiner = new StringJoiner("");
|
|
|
+ String ossStr = null;
|
|
|
+ if (!oss && Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
|
|
|
+ pdfStringJoiner.add(dictionaryConfig.fssLocalPdfDomain().getConfig()).add(File.separator);
|
|
|
+ }
|
|
|
+ pdfStringJoiner = SystemConstant.getDirName(pdfStringJoiner, UploadFileEnum.PDF, true);
|
|
|
pdfStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.PDF_PREFIX);
|
|
|
|
|
|
- String pdfDirName = pdfStringJoiner.toString();
|
|
|
- String pdfDirNameStr = pdfStringJoiner.toString().replace("\\", "/");
|
|
|
+ pdfFileTemp = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
|
|
|
+ createPrintPdfUtil.createSignPdf(pdfFillDto, pdfFileTemp.getPath());
|
|
|
|
|
|
- String destUrl = null;
|
|
|
- if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
|
|
|
- destUrl = dictionaryConfig.fssLocalPdfDomain().getConfig() + File.separator + pdfDirName;
|
|
|
+ String pdfDirName = pdfStringJoiner.toString().replaceAll("\\\\", "/");
|
|
|
+ //pdf生成和上传
|
|
|
+ String pdfFileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFileTemp));
|
|
|
+ if (oss) {
|
|
|
+ ossStr = SystemConstant.OSS;
|
|
|
+ fileStoreUtil.ossUpload(pdfDirName, pdfFileTemp, pdfFileMd5, fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
|
|
|
} else {
|
|
|
- destUrl = dictionaryConfig.fssPublicDomain().getConfig() + File.separator + pdfDirName;
|
|
|
- }
|
|
|
-
|
|
|
- createPrintPdfUtil.createSignPdf(pdfFillDto, destUrl);
|
|
|
-
|
|
|
- File pdfFile = new File(destUrl);
|
|
|
- if (!pdfFile.exists()) {
|
|
|
- pdfFile.getParentFile().mkdirs();
|
|
|
- pdfFile.createNewFile();
|
|
|
+ ossStr = SystemConstant.LOCAL;
|
|
|
+ if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
|
|
|
+ File file = new File(pdfStringJoiner.toString());
|
|
|
+ FileCopyUtils.copy(file, pdfFileTemp);
|
|
|
+ }
|
|
|
}
|
|
|
- PdfDto pdfDto = PdfUtil.addPdfPage(pdfFile);
|
|
|
+ PdfDto pdfDto = PdfUtil.addPdfPage(pdfFileTemp);
|
|
|
|
|
|
- byte[] data = ByteArray.fromFile(pdfFile).value();
|
|
|
- String md5 = ByteArray.md5(data).toHexString();
|
|
|
- InputStream ins = new ByteArrayInputStream(data);
|
|
|
- if (oss) {//上传至oss
|
|
|
- fileStoreUtil.ossUpload(pdfDirNameStr, ins, md5, fileStoreUtil.getUploadEnumByPath(pdfDirNameStr).getFssType());
|
|
|
- ins.close();
|
|
|
- }
|
|
|
JSONObject attachmentPath = JSONObject.parseObject(examDetail.getAttachmentPath());
|
|
|
attachmentPath = Objects.isNull(attachmentPath) ? new JSONObject() : attachmentPath;
|
|
|
JSONArray jsonArray = (JSONArray) attachmentPath.get(SystemConstant.PATH);
|
|
|
jsonArray = Objects.isNull(jsonArray) ? new JSONArray() : jsonArray;
|
|
|
JSONObject object = new JSONObject();
|
|
|
object.put("printType", ClassifyEnum.SIGN.name());
|
|
|
- object.put("pdfMd5", md5);
|
|
|
- if (!oss) {
|
|
|
- object.put(SystemConstant.PDF_PATH, pdfFile.getPath());
|
|
|
- object.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
- } else {
|
|
|
- object.put(SystemConstant.PDF_PATH, pdfDirNameStr);
|
|
|
- object.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
- }
|
|
|
+ object.put("pdfMd5", pdfFileMd5);
|
|
|
+ object.put(SystemConstant.PDF_PATH, pdfDirName);
|
|
|
+ object.put(SystemConstant.TYPE, ossStr);
|
|
|
object.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
|
|
|
UploadFileEnum.PDF
|
|
|
});
|
|
@@ -332,7 +308,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
|
|
|
attachmentPath.put(SystemConstant.PATH, jsonArray);
|
|
|
examDetail.setAttachmentPath(attachmentPath.toJSONString());
|
|
|
for (int i = 0; i < printCount; i++) {
|
|
|
- pdfList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A4, pdfDto.getPageCount(), 2));
|
|
|
+ pdfList.add(new PdfDto(pdfFileTemp.getPath(), PageSizeEnum.A4, pdfDto.getPageCount(), 2));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error(SystemConstant.LOG_ERROR, e);
|
|
@@ -359,93 +335,67 @@ public class PrintCommonServiceImpl implements PrintCommonService {
|
|
|
public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long userId, List<PdfDto> localFileList) throws IOException {
|
|
|
BasicAttachment basicAttachment = null;
|
|
|
PdfDto pdfDto = null;
|
|
|
+ File htmlFileTemp = null, pdfFileTemp = null;
|
|
|
try {
|
|
|
- byte[] bytes = htmlContent.getBytes();
|
|
|
- int size = bytes.length;
|
|
|
+ htmlFileTemp = SystemConstant.getFileTempVar(SystemConstant.HTML_PREFIX);
|
|
|
+ pdfFileTemp = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
|
|
|
+ FileCopyUtils.copy(htmlContent.getBytes(), htmlFileTemp);
|
|
|
boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
StringJoiner stringJoiner = new StringJoiner("");
|
|
|
+ StringJoiner pdfStringJoiner = new StringJoiner("");
|
|
|
if (!oss && Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
stringJoiner.add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator);
|
|
|
}
|
|
|
+ if (!oss && Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
|
|
|
+ pdfStringJoiner.add(dictionaryConfig.fssLocalPdfDomain().getConfig()).add(File.separator);
|
|
|
+ }
|
|
|
stringJoiner = SystemConstant.getDirName(stringJoiner, UploadFileEnum.HTML, true);
|
|
|
stringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.HTML_PREFIX);
|
|
|
|
|
|
+ pdfStringJoiner = SystemConstant.getDirName(pdfStringJoiner, UploadFileEnum.PDF, true);
|
|
|
+ pdfStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.PDF_PREFIX);
|
|
|
+
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
- String fileMd5 = null;
|
|
|
- if (oss) {//上传至oss
|
|
|
- String dirName = stringJoiner.toString().replaceAll("\\\\", "/");
|
|
|
-// ossUtil.ossUpload(dirName, htmlContent);
|
|
|
- fileStoreUtil.ossUpload(dirName, htmlContent, fileStoreUtil.getUploadEnumByPath(dirName).getFssType());
|
|
|
- jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
- jsonObject.put(SystemConstant.HTML_PATH, dirName);
|
|
|
+ String htmlDirName = stringJoiner.toString().replaceAll("\\\\", "/");
|
|
|
+ String pdfDirName = pdfStringJoiner.toString().replaceAll("\\\\", "/");
|
|
|
|
|
|
- String url = null;
|
|
|
+ //html生成和上传
|
|
|
+ String htmlFileMd5 = DigestUtils.md5Hex(new FileInputStream(htmlFileTemp));
|
|
|
+ if (oss) {
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
+ fileStoreUtil.ossUpload(htmlDirName, htmlFileTemp, htmlFileMd5, fileStoreUtil.getUploadEnumByPath(htmlDirName).getFssType());
|
|
|
+ } else {
|
|
|
if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
- url = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + dirName;
|
|
|
- } else {
|
|
|
- url = dirName;
|
|
|
+ File file = new File(stringJoiner.toString());
|
|
|
+ FileCopyUtils.copy(file, htmlFileTemp);
|
|
|
}
|
|
|
-// File localHtmlFile = ossUtil.ossDownload(dirName, url);
|
|
|
- File localHtmlFile = fileStoreUtil.ossDownload(dirName, url, fileStoreUtil.getUploadEnumByPath(dirName).getFssType());
|
|
|
- StringJoiner pdfStringJoiner = SystemConstant.getDirName(UploadFileEnum.PDF, true);
|
|
|
- pdfStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.PDF_PREFIX);
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
+ }
|
|
|
+ jsonObject.put(SystemConstant.HTML_PATH, htmlDirName);
|
|
|
|
|
|
- String pdfDirName = pdfStringJoiner.toString();
|
|
|
+ HtmlToPdfUtil.convert(htmlFileTemp.getPath(), pdfFileTemp.getPath(), PageSizeEnum.A3);
|
|
|
|
|
|
- String destUrl = null;
|
|
|
+ //pdf生成和上传
|
|
|
+ String pdfFileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFileTemp));
|
|
|
+ if (oss) {
|
|
|
+ fileStoreUtil.ossUpload(pdfDirName, pdfFileTemp, pdfFileMd5, fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
|
|
|
+ } else {
|
|
|
if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
|
|
|
- destUrl = dictionaryConfig.fssLocalPdfDomain().getConfig() + File.separator + pdfDirName;
|
|
|
- } else {
|
|
|
- destUrl = pdfDirName;
|
|
|
+ File file = new File(pdfStringJoiner.toString());
|
|
|
+ FileCopyUtils.copy(file, pdfFileTemp);
|
|
|
}
|
|
|
-// destUrl = destUrl.replaceAll("\\\\","/");
|
|
|
+ }
|
|
|
|
|
|
- HtmlToPdfUtil.convert(localHtmlFile.getPath(), destUrl, PageSizeEnum.A3);
|
|
|
-// File pdfFile = asposePdfUtil.documentToPdf(localHtmlFile.getPath(), destUrl, PaperSize.A3);
|
|
|
- File pdfFile = new File(destUrl);
|
|
|
- if (!pdfFile.exists()) {
|
|
|
- pdfFile.getParentFile().mkdirs();
|
|
|
- pdfFile.createNewFile();
|
|
|
- }
|
|
|
- pdfDto = PdfUtil.addPdfPage(pdfFile);
|
|
|
- localFileList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A3, pdfDto.getPageCount()));
|
|
|
- fileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
|
|
|
-// ossUtil.ossUpload(pdfDirName, pdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(fileMd5)));
|
|
|
- pdfDirName = pdfDirName.replaceAll("\\\\", "/");
|
|
|
- fileStoreUtil.ossUpload(pdfDirName, pdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(fileMd5)), fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
|
|
|
-// localHtmlFile.delete();
|
|
|
- jsonObject.put(SystemConstant.PATH, pdfDirName);
|
|
|
- // htmlMd5
|
|
|
- jsonObject.put("htmlMd5", DigestUtils.md5Hex(new FileInputStream(localHtmlFile)));
|
|
|
- jsonObject.put("pdfMd5", fileMd5);
|
|
|
- } else {//上传至服务器
|
|
|
- File finalFile = new File(stringJoiner.toString());
|
|
|
- if (!finalFile.exists()) {
|
|
|
- finalFile.getParentFile().mkdirs();
|
|
|
- finalFile.createNewFile();
|
|
|
- }
|
|
|
- FileCopyUtils.copy(bytes, new File(stringJoiner.toString()));
|
|
|
- jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
- jsonObject.put(SystemConstant.HTML_PATH, stringJoiner.toString());
|
|
|
- String destUrl = finalFile.getPath().replaceAll(UploadFileEnum.HTML.name().toLowerCase(), UploadFileEnum.PDF.name().toLowerCase());
|
|
|
- HtmlToPdfUtil.convert(finalFile.getPath(), destUrl, PageSizeEnum.A3);
|
|
|
- File pdfFile = new File(destUrl);
|
|
|
- if (!pdfFile.exists()) {
|
|
|
- pdfFile.getParentFile().mkdirs();
|
|
|
- pdfFile.createNewFile();
|
|
|
- }
|
|
|
- pdfDto = PdfUtil.addPdfPage(pdfFile);
|
|
|
- fileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
|
|
|
- localFileList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A3, pdfDto.getPageCount()));
|
|
|
+ pdfDto = PdfUtil.addPdfPage(pdfFileTemp);
|
|
|
+ localFileList.add(new PdfDto(pdfFileTemp.getPath(), PageSizeEnum.A3, pdfDto.getPageCount()));
|
|
|
+ jsonObject.put(SystemConstant.PATH, pdfDirName);
|
|
|
+ jsonObject.put("htmlMd5", htmlFileMd5);
|
|
|
+ jsonObject.put("pdfMd5", pdfFileMd5);
|
|
|
|
|
|
- jsonObject.put(SystemConstant.PATH, destUrl);
|
|
|
- jsonObject.put("htmlMd5", DigestUtils.md5Hex(new FileInputStream(finalFile)));
|
|
|
- jsonObject.put("pdfMd5", fileMd5);
|
|
|
- }
|
|
|
jsonObject.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
|
|
|
UploadFileEnum.HTML, UploadFileEnum.PDF
|
|
|
});
|
|
|
- basicAttachment = new BasicAttachment(jsonObject.toJSONString(), fileName, SystemConstant.HTML_PREFIX, new BigDecimal(size), fileMd5, userId);
|
|
|
+ basicAttachment = new BasicAttachment(jsonObject.toJSONString(), fileName, SystemConstant.HTML_PREFIX, new BigDecimal(htmlContent.getBytes().length), htmlFileMd5, userId);
|
|
|
basicAttachment.setPages(pdfDto.getActualPageCount());
|
|
|
basicAttachmentService.save(basicAttachment);
|
|
|
} catch (Exception e) {
|
|
@@ -576,9 +526,8 @@ public class PrintCommonServiceImpl implements PrintCommonService {
|
|
|
*/
|
|
|
@Override
|
|
|
public BasicAttachment saveAttachmentCommon(MultipartFile file, String md5, UploadFileEnum type, Long objId) {
|
|
|
- if (Objects.isNull(type)) {
|
|
|
- throw ExceptionResultEnum.ATTACHMENT_TYPE_EMPTY.exception();
|
|
|
- }
|
|
|
+ Optional.ofNullable(type).orElseThrow(() -> ExceptionResultEnum.ATTACHMENT_TYPE_EMPTY.exception());
|
|
|
+
|
|
|
BasicAttachment basicAttachment = null;
|
|
|
try {
|
|
|
SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
|
|
@@ -1355,51 +1304,44 @@ public class PrintCommonServiceImpl implements PrintCommonService {
|
|
|
|
|
|
@Override
|
|
|
public void saveAttachmentPackagePdf(PdfPackageDto pdfPackageDto, ExamDetail examDetail, List<PdfDto> pdfList, Integer printCount) {
|
|
|
+ File pdfFileTemp = null;
|
|
|
try {
|
|
|
boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
- StringJoiner pdfStringJoiner = SystemConstant.getDirName(UploadFileEnum.PDF, true);
|
|
|
+ StringJoiner pdfStringJoiner = new StringJoiner("");
|
|
|
+ String ossStr = null;
|
|
|
+ if (!oss && Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
|
|
|
+ pdfStringJoiner.add(dictionaryConfig.fssLocalPdfDomain().getConfig()).add(File.separator);
|
|
|
+ }
|
|
|
+ pdfStringJoiner = SystemConstant.getDirName(pdfStringJoiner, UploadFileEnum.PDF, true);
|
|
|
pdfStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.PDF_PREFIX);
|
|
|
|
|
|
- String pdfDirName = pdfStringJoiner.toString();
|
|
|
- String pdfDirNameStr = pdfStringJoiner.toString().replace("\\", "/");
|
|
|
-
|
|
|
- String destUrl = null;
|
|
|
- if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
|
|
|
- destUrl = dictionaryConfig.fssLocalPdfDomain().getConfig() + File.separator + pdfDirName;
|
|
|
+ String pdfDirName = pdfStringJoiner.toString().replaceAll("\\\\", "/");
|
|
|
+ pdfFileTemp = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
|
|
|
+ createPrintPdfUtil.createPackagePdf(pdfPackageDto, pdfFileTemp.getPath());
|
|
|
+ //pdf生成和上传
|
|
|
+ String pdfFileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFileTemp));
|
|
|
+ if (oss) {
|
|
|
+ ossStr = SystemConstant.OSS;
|
|
|
+ fileStoreUtil.ossUpload(pdfDirName, pdfFileTemp, pdfFileMd5, fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
|
|
|
} else {
|
|
|
- destUrl = dictionaryConfig.fssPublicDomain().getConfig() + File.separator + pdfDirName;
|
|
|
+ ossStr = SystemConstant.LOCAL;
|
|
|
+ if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
|
|
|
+ File file = new File(pdfStringJoiner.toString());
|
|
|
+ FileCopyUtils.copy(file, pdfFileTemp);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- createPrintPdfUtil.createPackagePdf(pdfPackageDto, destUrl);
|
|
|
+ PdfDto pdfDto = PdfUtil.addPdfPage(pdfFileTemp);
|
|
|
|
|
|
- File pdfFile = new File(destUrl);
|
|
|
- if (!pdfFile.exists()) {
|
|
|
- pdfFile.getParentFile().mkdirs();
|
|
|
- pdfFile.createNewFile();
|
|
|
- }
|
|
|
- PdfDto pdfDto = PdfUtil.addPdfPage(pdfFile);
|
|
|
-
|
|
|
- byte[] data = ByteArray.fromFile(pdfFile).value();
|
|
|
- String md5 = ByteArray.md5(data).toHexString();
|
|
|
- InputStream ins = new ByteArrayInputStream(data);
|
|
|
- if (oss) {//上传至oss
|
|
|
- fileStoreUtil.ossUpload(pdfDirNameStr, ins, md5, fileStoreUtil.getUploadEnumByPath(pdfDirNameStr).getFssType());
|
|
|
- ins.close();
|
|
|
- }
|
|
|
JSONObject attachmentPath = JSON.parseObject(examDetail.getAttachmentPath());
|
|
|
attachmentPath = Objects.isNull(attachmentPath) ? new JSONObject() : attachmentPath;
|
|
|
JSONArray jsonArray = (JSONArray) attachmentPath.get(SystemConstant.PATH);
|
|
|
jsonArray = Objects.isNull(jsonArray) ? new JSONArray() : jsonArray;
|
|
|
JSONObject object = new JSONObject();
|
|
|
object.put("printType", ClassifyEnum.PACKAGE.name());
|
|
|
- object.put("pdfMd5", md5);
|
|
|
- if (!oss) {
|
|
|
- object.put(SystemConstant.PDF_PATH, pdfFile.getPath());
|
|
|
- object.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
- } else {
|
|
|
- object.put(SystemConstant.PDF_PATH, pdfDirNameStr);
|
|
|
- object.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
- }
|
|
|
+ object.put("pdfMd5", pdfFileMd5);
|
|
|
+ object.put(SystemConstant.PDF_PATH, pdfDirName);
|
|
|
+ object.put(SystemConstant.TYPE, ossStr);
|
|
|
object.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
|
|
|
UploadFileEnum.HTML,
|
|
|
UploadFileEnum.PDF
|
|
@@ -1408,7 +1350,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
|
|
|
attachmentPath.put(SystemConstant.PATH, jsonArray);
|
|
|
examDetail.setAttachmentPath(attachmentPath.toJSONString());
|
|
|
for (int i = 0; i < printCount; i++) {
|
|
|
- pdfList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A4, pdfDto.getPageCount(), 2));
|
|
|
+ pdfList.add(new PdfDto(pdfFileTemp.getPath(), PageSizeEnum.A4, pdfDto.getPageCount(), 2));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error(SystemConstant.LOG_ERROR, e);
|
|
@@ -1429,32 +1371,21 @@ public class PrintCommonServiceImpl implements PrintCommonService {
|
|
|
@Override
|
|
|
public JSONObject uploadPdfFile(File pdfFile, ClassifyEnum classifyEnum) {
|
|
|
try {
|
|
|
+ StringJoiner pdfStringJoiner = SystemConstant.getDirName(UploadFileEnum.PDF, true);
|
|
|
+ pdfStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.PDF_PREFIX);
|
|
|
+ String pdfDirName = pdfStringJoiner.toString();
|
|
|
+ pdfDirName = SystemConstant.getPdfFilePath(pdfDirName, pdfFile);
|
|
|
boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
- String pdfDirName = pdfFile.getPath();
|
|
|
-
|
|
|
- String pdfDirNameStr = null;
|
|
|
- if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
|
|
|
- String sysConfigPath = dictionaryConfig.fssLocalPdfDomain().getConfig() + File.separator;
|
|
|
- pdfDirNameStr = pdfDirName.replace("\\", "/").replaceAll(sysConfigPath.replace("\\", "/"), "");
|
|
|
- } else {
|
|
|
- pdfDirNameStr = pdfDirName;
|
|
|
- }
|
|
|
|
|
|
byte[] data = ByteArray.fromFile(pdfFile).value();
|
|
|
String md5 = ByteArray.md5(data).toHexString();
|
|
|
- InputStream ins = new ByteArrayInputStream(data);
|
|
|
- if (oss) {//上传至oss
|
|
|
- fileStoreUtil.ossUpload(pdfDirNameStr, ins, md5, UploadFileEnum.PDF.getFssType());
|
|
|
- ins.close();
|
|
|
- }
|
|
|
JSONObject object = new JSONObject();
|
|
|
object.put("printType", classifyEnum);
|
|
|
object.put("pdfMd5", md5);
|
|
|
+ object.put(SystemConstant.PATH, pdfDirName);
|
|
|
if (!oss) {
|
|
|
- object.put(SystemConstant.PATH, pdfDirName);
|
|
|
object.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
} else {
|
|
|
- object.put(SystemConstant.PATH, pdfDirNameStr);
|
|
|
object.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
}
|
|
|
object.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.PDF);
|