diff --git a/pom.xml b/pom.xml
index 5739715..9326740 100644
--- a/pom.xml
+++ b/pom.xml
@@ -178,6 +178,12 @@
dlp-othersys-api
${dlp.version}
+
+
+ org.apache.pdfbox
+ pdfbox
+ 2.0.29
+
diff --git a/src/main/java/digital/laboratory/platform/identifybook/controller/IdentifyBookController.java b/src/main/java/digital/laboratory/platform/identifybook/controller/IdentifyBookController.java
index 959d00f..35dc512 100644
--- a/src/main/java/digital/laboratory/platform/identifybook/controller/IdentifyBookController.java
+++ b/src/main/java/digital/laboratory/platform/identifybook/controller/IdentifyBookController.java
@@ -40,15 +40,16 @@ public class IdentifyBookController {
private final OssFile ossFile;
private final IIdentifyBookService identifyBookService;
+
@ApiOperation(value = "根据根据文书ID查看文书", notes = "根据根据文书ID查看文书")
- @ApiImplicitParam(name = "bookId", value = "文书ID" , required = true)
+ @ApiImplicitParam(name = "bookId", value = "文书ID", required = true)
@GetMapping("/view/{id}")
- public R findBook(@PathVariable(value = "bookId") String bookId){
+ public R findBook(@PathVariable(value = "bookId") String bookId) {
try {
IdentifyBook identifyBook = identifyBookService.getById(bookId);
- String uuid= IdWorker.get32UUID();
- return R.ok( uuid+"#"+identifyBook.getPath(), "获取文件成功");
+ String uuid = IdWorker.get32UUID();
+ return R.ok(uuid + "#" + identifyBook.getPath(), "获取文件成功");
} catch (Exception e) {
e.printStackTrace();
}
@@ -56,14 +57,14 @@ public class IdentifyBookController {
}
@ApiOperation(value = "根据根据文书ID删除文书", notes = "根据根据文书ID删除文书")
- @ApiImplicitParam(name = "bookId", value = "文书ID" , required = true)
+ @ApiImplicitParam(name = "bookId", value = "文书ID", required = true)
@DeleteMapping
- public R deleteById(@PathVariable(value = "bookId") String bookId){
+ public R deleteById(@PathVariable(value = "bookId") String bookId) {
try {
IdentifyBook identifyBook = identifyBookService.getById(bookId);
ossFile.fileDelete(identifyBook.getFileName());
boolean b = identifyBookService.removeById(bookId);
- if(b){
+ if (b) {
return R.ok(b, "删除成功!!!");
}
return R.failed(b, "删除失败!!!");
@@ -72,18 +73,25 @@ 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 file){
- Assert.notBlank(attachType,"附件类型参数不能为空");
- Assert.notBlank(businessId,"业务ID参数不能为空");
- return R.ok(identifyBookService.uploadIdentifyBookAttachment(attachType,file,businessId));
+ public R uploadBookAttachment(String attachType, String businessId, List file) {
+ Assert.notBlank(attachType, "附件类型参数不能为空");
+ 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)")
- public R getAttachment(String businessId,String attachType){
- return R.ok(identifyBookService.getAttachment(businessId,attachType));
+ public R getAttachment(String businessId, String attachType) {
+ 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));
+ }
}
diff --git a/src/main/java/digital/laboratory/platform/identifybook/service/IIdentifyBookService.java b/src/main/java/digital/laboratory/platform/identifybook/service/IIdentifyBookService.java
index 2106a2f..7f39f12 100644
--- a/src/main/java/digital/laboratory/platform/identifybook/service/IIdentifyBookService.java
+++ b/src/main/java/digital/laboratory/platform/identifybook/service/IIdentifyBookService.java
@@ -40,4 +40,6 @@ public interface IIdentifyBookService extends IService {
List uploadIdentifyBookAttachment(String attachType, List attachFileList,String businessId);
//获取手动上传的文书附件
String getAttachment(String businessId,String attachType);
+
+ String mergeWord(String entrustId) throws Exception;
}
diff --git a/src/main/java/digital/laboratory/platform/identifybook/service/impl/IdentifyBookServiceImpl.java b/src/main/java/digital/laboratory/platform/identifybook/service/impl/IdentifyBookServiceImpl.java
index 1c35621..2bc8bd2 100644
--- a/src/main/java/digital/laboratory/platform/identifybook/service/impl/IdentifyBookServiceImpl.java
+++ b/src/main/java/digital/laboratory/platform/identifybook/service/impl/IdentifyBookServiceImpl.java
@@ -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 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 paths = ossFile.fileList(dirPath);
+ for (String path : paths) {
+ if (path.endsWith(".docx")) {
+ return dirPath + path;
+ }
+ }
+ return null;
+ }
+
}