|
|
@ -1,6 +1,6 @@ |
|
|
|
package digital.laboratory.platform.identifybook.service.impl; |
|
|
|
package digital.laboratory.platform.identifybook.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.baomidou.mybatisplus.annotation.IdType; |
|
|
|
import com.baomidou.mybatisplus.annotation.IdType; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
@ -11,6 +11,7 @@ import digital.laboratory.platform.common.core.constant.OSSDirectoryConstants; |
|
|
|
import digital.laboratory.platform.common.core.util.ClassUtils; |
|
|
|
import digital.laboratory.platform.common.core.util.ClassUtils; |
|
|
|
import digital.laboratory.platform.common.core.util.R; |
|
|
|
import digital.laboratory.platform.common.core.util.R; |
|
|
|
import digital.laboratory.platform.common.feign.RemoteGenerateWordService; |
|
|
|
import digital.laboratory.platform.common.feign.RemoteGenerateWordService; |
|
|
|
|
|
|
|
import digital.laboratory.platform.common.feign.RemoteWord2PDFService; |
|
|
|
import digital.laboratory.platform.common.oss.service.OssFile; |
|
|
|
import digital.laboratory.platform.common.oss.service.OssFile; |
|
|
|
import digital.laboratory.platform.identifybook.dto.EntrustCaseDTO; |
|
|
|
import digital.laboratory.platform.identifybook.dto.EntrustCaseDTO; |
|
|
|
import digital.laboratory.platform.identifybook.emums.UnitEnums; |
|
|
|
import digital.laboratory.platform.identifybook.emums.UnitEnums; |
|
|
@ -23,13 +24,19 @@ import digital.laboratory.platform.inspetion.api.entity.EntrustInfo; |
|
|
|
import digital.laboratory.platform.inspetion.api.entity.IdentificationBookDTO; |
|
|
|
import digital.laboratory.platform.inspetion.api.entity.IdentificationBookDTO; |
|
|
|
import digital.laboratory.platform.inspetion.api.feign.RemoteTestToIdentifyService; |
|
|
|
import digital.laboratory.platform.inspetion.api.feign.RemoteTestToIdentifyService; |
|
|
|
import digital.laboratory.platform.sys.feign.RemoteUserService; |
|
|
|
import digital.laboratory.platform.sys.feign.RemoteUserService; |
|
|
|
|
|
|
|
import feign.Response; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
|
|
|
|
|
import org.apache.pdfbox.multipdf.PDFMergerUtility; |
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
|
|
|
|
import org.springframework.mock.web.MockMultipartFile; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.annotation.Resource; |
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.text.DecimalFormat; |
|
|
|
import java.text.DecimalFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
@ -66,6 +73,8 @@ public class IdentifyBookServiceImpl extends ServiceImpl<IdentifyBookMapper, Ide |
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private RemoteTestToIdentifyService remoteTestToIdentifyService; |
|
|
|
private RemoteTestToIdentifyService remoteTestToIdentifyService; |
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
|
|
|
|
private RemoteWord2PDFService remoteWord2PDFService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private OssFile ossFile; |
|
|
|
private OssFile ossFile; |
|
|
|
//格式化日期
|
|
|
|
//格式化日期
|
|
|
|
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日"); |
|
|
|
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日"); |
|
|
@ -680,8 +689,91 @@ public class IdentifyBookServiceImpl extends ServiceImpl<IdentifyBookMapper, Ide |
|
|
|
targetPath = OSSDirectoryConstants.IDENTIFY_BOOK_DIRECTORY + "/" + businessId + "/" + attachType + "/"; |
|
|
|
targetPath = OSSDirectoryConstants.IDENTIFY_BOOK_DIRECTORY + "/" + businessId + "/" + attachType + "/"; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case "2": { |
|
|
|
case "2": { |
|
|
|
targetPath = OSSDirectoryConstants.IDENTIFY_BOOK_DIRECTORY + "/" + businessId + "/" + attachType + "/"; |
|
|
|
targetPath = OSSDirectoryConstants.IDENTIFY_BOOK_DIRECTORY + businessId + attachType + "/"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String mergeWord(String entrustId) throws Exception { |
|
|
|
|
|
|
|
String reportPath = "document/appraisalReport/" + entrustId + "/" + "鉴定报告.pdf"; |
|
|
|
|
|
|
|
boolean ret = ossFile.objectExist(reportPath); |
|
|
|
|
|
|
|
if (ret) { |
|
|
|
|
|
|
|
return reportPath; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Entrustment entrustment = entrustmentService.getById(entrustId); |
|
|
|
|
|
|
|
String synEntrustId = entrustment.getSynEntrustId(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取 .docx 文件路径
|
|
|
|
|
|
|
|
String entrustBookPath = getDocxPath(OSSDirectoryConstants.DOCUMENT_ENTRUSTMENT_DIRECTORY + "/" + synEntrustId + "/"); |
|
|
|
|
|
|
|
String entrustVerifyBookPath = getDocxPath(OSSDirectoryConstants.IDENTIFY_BOOK_DIRECTORY + "/" + synEntrustId + "/"); |
|
|
|
|
|
|
|
String materialPath = OSSDirectoryConstants.DOCUMENT_ACCEPT_DIRECTORY + "/" + synEntrustId + "/materialPhoto/materialallpic.docx"; |
|
|
|
|
|
|
|
String testRecordPath = getDocxPath("document/testRecord/" + entrustId + "/"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IdentifyBookRelevance bookRelevance = identifyBookRelevanceService.lambdaQuery() |
|
|
|
|
|
|
|
.eq(IdentifyBookRelevance::getRelevanceBusinessId, entrustId) |
|
|
|
|
|
|
|
.one(); |
|
|
|
|
|
|
|
IdentifyBook identifyBook = identifyBookService.lambdaQuery() |
|
|
|
|
|
|
|
.eq(IdentifyBook::getIdentifyBookRelevanceId, bookRelevance.getId()) |
|
|
|
|
|
|
|
.orderByDesc(IdentifyBook::getCreateTime) |
|
|
|
|
|
|
|
.list() |
|
|
|
|
|
|
|
.get(0); |
|
|
|
|
|
|
|
String verificationReportPath = identifyBook.getPath(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> docxPaths = Arrays.asList( |
|
|
|
|
|
|
|
entrustBookPath, entrustVerifyBookPath, materialPath, testRecordPath, verificationReportPath |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 合并 PDF 工具类
|
|
|
|
|
|
|
|
PDFMergerUtility merger = new PDFMergerUtility(); |
|
|
|
|
|
|
|
ByteArrayOutputStream mergedOut = new ByteArrayOutputStream(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (String path : docxPaths) { |
|
|
|
|
|
|
|
if (StrUtil.isBlank(path)) continue; |
|
|
|
|
|
|
|
System.out.println("文件的路径:" + path); |
|
|
|
|
|
|
|
ByteArrayOutputStream fosWord = new ByteArrayOutputStream(); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
ossFile.fileGet(path, fosWord); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 转成 MultipartFile
|
|
|
|
|
|
|
|
ByteArrayInputStream fisWord = new ByteArrayInputStream(fosWord.toByteArray()); |
|
|
|
|
|
|
|
MockMultipartFile mockMultipartFile = new MockMultipartFile("file", path, "image/jpg", fisWord); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 调用远程 word2pdf 接口
|
|
|
|
|
|
|
|
Response response = remoteWord2PDFService.word2pdf(mockMultipartFile); |
|
|
|
|
|
|
|
ByteArrayOutputStream outPDF = new ByteArrayOutputStream(); |
|
|
|
|
|
|
|
IOUtils.copy(response.body().asInputStream(), outPDF); |
|
|
|
|
|
|
|
ByteArrayInputStream isPDF = new ByteArrayInputStream(outPDF.toByteArray()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 加入合并工具
|
|
|
|
|
|
|
|
merger.addSource(isPDF); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 关闭流(推荐放 finally 或用 try-with-resources 简化)
|
|
|
|
|
|
|
|
fosWord.close(); |
|
|
|
|
|
|
|
fisWord.close(); |
|
|
|
|
|
|
|
outPDF.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 合并并输出到内存中
|
|
|
|
|
|
|
|
merger.setDestinationStream(mergedOut); |
|
|
|
|
|
|
|
merger.mergeDocuments(null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayInputStream finalPdfInputStream = new ByteArrayInputStream(mergedOut.toByteArray()); |
|
|
|
|
|
|
|
ossFile.fileSave(reportPath, finalPdfInputStream); |
|
|
|
|
|
|
|
return reportPath; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取文件夹中第一个 .docx 路径
|
|
|
|
|
|
|
|
private String getDocxPath(String dirPath) { |
|
|
|
|
|
|
|
List<String> paths = ossFile.fileList(dirPath); |
|
|
|
|
|
|
|
for (String path : paths) { |
|
|
|
|
|
|
|
if (path.endsWith(".docx")) { |
|
|
|
|
|
|
|
return dirPath + path; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|