update
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -178,6 +178,12 @@
|
||||
<artifactId>dlp-othersys-api</artifactId>
|
||||
<version>${dlp.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>pdfbox</artifactId>
|
||||
<version>2.0.29</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -40,6 +40,7 @@ public class IdentifyBookController {
|
||||
private final OssFile ossFile;
|
||||
|
||||
private final IIdentifyBookService identifyBookService;
|
||||
|
||||
@ApiOperation(value = "根据根据文书ID查看文书", notes = "根据根据文书ID查看文书")
|
||||
@ApiImplicitParam(name = "bookId", value = "文书ID", required = true)
|
||||
@GetMapping("/view/{id}")
|
||||
@@ -72,6 +73,7 @@ public class IdentifyBookController {
|
||||
}
|
||||
return R.failed("获取鉴定文书失败");
|
||||
}
|
||||
|
||||
@PostMapping("/uploadBookAttachment")
|
||||
@ApiOperation(value = "上传文书的附件,主要包含 鉴定事项确认书(1),委托书(2),检材照片(3),送检人证件照(4),原鉴定情况(5)", notes = "上传文书的附件,主要包含 鉴定事项确认书(1),委托书(2),检材照片(3),送检人证件照(4),原鉴定情况(5)")
|
||||
public R uploadBookAttachment(String attachType, String businessId, List<MultipartFile> file) {
|
||||
@@ -79,6 +81,7 @@ public class IdentifyBookController {
|
||||
Assert.notBlank(businessId, "业务ID参数不能为空");
|
||||
return R.ok(identifyBookService.uploadIdentifyBookAttachment(attachType, file, businessId));
|
||||
}
|
||||
|
||||
//获取手动上传的文书附件
|
||||
@GetMapping("/getUploadBookAttachment")
|
||||
@ApiOperation(value = "获取手动上传的文书附件,主要包含 鉴定事项确认书(1),委托书(2),检材照片(3),送检人证件照(4),原鉴定情况(5)", notes = "上传文书的附件,主要包含 鉴定事项确认书(1),委托书(2),检材照片(3),送检人证件照(4),原鉴定情况(5)")
|
||||
@@ -86,4 +89,9 @@ public class IdentifyBookController {
|
||||
return R.ok(identifyBookService.getAttachment(businessId, attachType));
|
||||
}
|
||||
|
||||
@GetMapping("/mergeWord")
|
||||
@ApiOperation(value = "合并所有", notes = "合并word")
|
||||
public R mergeWord(String entrustId) throws Exception {
|
||||
return R.ok(identifyBookService.mergeWord(entrustId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,4 +40,6 @@ public interface IIdentifyBookService extends IService<IdentifyBook> {
|
||||
List<String> uploadIdentifyBookAttachment(String attachType, List<MultipartFile> attachFileList,String businessId);
|
||||
//获取手动上传的文书附件
|
||||
String getAttachment(String businessId,String attachType);
|
||||
|
||||
String mergeWord(String entrustId) throws Exception;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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.core.conditions.query.LambdaQueryWrapper;
|
||||
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.R;
|
||||
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.identifybook.dto.EntrustCaseDTO;
|
||||
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.feign.RemoteTestToIdentifyService;
|
||||
import digital.laboratory.platform.sys.feign.RemoteUserService;
|
||||
import feign.Response;
|
||||
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.mock.web.MockMultipartFile;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -66,6 +73,8 @@ public class IdentifyBookServiceImpl extends ServiceImpl<IdentifyBookMapper, Ide
|
||||
@Resource
|
||||
private RemoteTestToIdentifyService remoteTestToIdentifyService;
|
||||
@Resource
|
||||
private RemoteWord2PDFService remoteWord2PDFService;
|
||||
@Resource
|
||||
private OssFile ossFile;
|
||||
//格式化日期
|
||||
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 + "/";
|
||||
break;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user