|
|
@@ -2,17 +2,15 @@ package cn.start.tz.module.pressure2.service.pdf;
|
|
|
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
-import cn.start.tz.framework.common.exception.ServiceException;
|
|
|
-import cn.start.tz.framework.common.pojo.CommonResult;
|
|
|
-import cn.start.tz.module.grape.city.api.GrapeCityApi;
|
|
|
import cn.start.tz.module.grape.city.api.vo.GrapeCityReqDTO;
|
|
|
import cn.start.tz.module.infra.api.file.FileApi;
|
|
|
+import cn.start.tz.module.pressure2.controller.admin.dynamictb.vo.DynamicTbRespVO;
|
|
|
import cn.start.tz.module.pressure2.controller.admin.dynamictbcol.vo.DynamicTbColRespVO;
|
|
|
-import cn.start.tz.module.pressure2.controller.admin.dynamictbcol.vo.DynamicTbImgColRespVO;
|
|
|
-import cn.start.tz.module.pressure2.dal.dataobject.dynamictbcol.DynamicTbColDO;
|
|
|
+import cn.start.tz.module.pressure2.controller.admin.dynamictbval.vo.DynamicTBAndColVO;
|
|
|
+import cn.start.tz.module.pressure2.controller.admin.dynamictbval.vo.DynamicTBViewOrAddVO;
|
|
|
import cn.start.tz.module.pressure2.dal.dataobject.dynamictbins.DynamicTbInsDO;
|
|
|
import cn.start.tz.module.pressure2.dal.dataobject.dynamictbval.DynamicTbValDO;
|
|
|
-import cn.start.tz.module.pressure2.dal.dataobject.standardfile.StandardTemplateDO;
|
|
|
+import cn.start.tz.module.pressure2.service.dynamictb.DynamicTbService;
|
|
|
import cn.start.tz.module.pressure2.service.dynamictbcol.DynamicTbColService;
|
|
|
import cn.start.tz.module.pressure2.service.dynamictbins.DynamicTbInsService;
|
|
|
import cn.start.tz.module.pressure2.service.dynamictbval.DynamicTbValService;
|
|
|
@@ -20,11 +18,9 @@ import cn.start.tz.module.pressure2.service.standardfile.StandardTemplateService
|
|
|
import cn.start.tz.module.pressure2.util.ImageUtil;
|
|
|
import cn.start.tz.module.pressure2.util.WordToPdfUtils;
|
|
|
import cn.start.tz.module.system.api.standard.StandardTemplateApi;
|
|
|
-import cn.start.tz.module.system.api.standard.dto.StandardTemplateRespDTO;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.grapecity.documents.excel.*;
|
|
|
import com.grapecity.documents.excel.drawing.ImageType;
|
|
|
import com.grapecity.documents.excel.template.DataSource.JsonDataSource;
|
|
|
@@ -36,10 +32,10 @@ import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
|
|
import org.apache.pdfbox.pdmodel.font.PDType0Font;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
@@ -59,6 +55,9 @@ public class PdfServiceImpl implements PdfService {
|
|
|
@Resource
|
|
|
private DynamicTbInsService dynamicTbInsService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private DynamicTbService dynamicTbService;
|
|
|
+
|
|
|
@Resource
|
|
|
private FileApi fileApi;
|
|
|
|
|
|
@@ -125,11 +124,11 @@ public class PdfServiceImpl implements PdfService {
|
|
|
for (DynamicTbValDO dynamicTbValDO : list) {
|
|
|
map.put(dynamicTbValDO.getColCode(), dynamicTbValDO.getValValue());
|
|
|
}
|
|
|
- return this.fullPdf(bytes, map, imgIns);
|
|
|
+ return this.fullPdf(bytes, map, imgIns,templateId, instanceId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public byte[] fullPdf(byte[] templateBytes, Map<String, Object> data, List<String> imgIns) throws Exception {
|
|
|
+ public byte[] fullPdf(byte[] templateBytes, Map<String, Object> data, List<String> imgIns, String templateId, String instanceId) throws Exception {
|
|
|
// 将 data 中的 JSON 字符串值解析为实际对象/数组,确保 GcExcel 模板引擎能正确处理表格绑定
|
|
|
normalizeDataForTemplate(data);
|
|
|
if (grapecityUrl != null && !"null".equals(grapecityUrl)) {
|
|
|
@@ -165,6 +164,32 @@ public class PdfServiceImpl implements PdfService {
|
|
|
fullPdfRequest.put("data", data);
|
|
|
fullPdfRequest.put("fileBytes", fileBytes);
|
|
|
|
|
|
+
|
|
|
+ DynamicTbRespVO templateInfo = dynamicTbService.getDynamicTb(templateId);
|
|
|
+ com.alibaba.fastjson.JSONObject copyConfig = templateInfo.getCopyConfig();
|
|
|
+ if (copyConfig != null) {
|
|
|
+ // {"copyRange":{"topLeft":"0,7","topRight":"19,7","bottomLeft":"0,22","bottomRight":"19,22"},"sheetName":"续页","hidden":true,"isContinuePage":true}
|
|
|
+ String isContinuePage = copyConfig.getString("isContinuePage");
|
|
|
+ List<String> existingColCodes = null;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (isContinuePage.equals("true")){
|
|
|
+ DynamicTBViewOrAddVO queryVO = new DynamicTBViewOrAddVO();
|
|
|
+ queryVO.setTemplateId(templateId);
|
|
|
+ DynamicTbInsDO dynamicTBInsDO = dynamicTbInsService.getById(instanceId);
|
|
|
+ queryVO.setRefId(dynamicTBInsDO.getRefId());
|
|
|
+ DynamicTBAndColVO tbData = dynamicTbValService.getDynamicTbInsAndValByRefId(queryVO);
|
|
|
+ existingColCodes = tbData.getDynamicTbColRespVOList().stream()
|
|
|
+ .map(DynamicTbColRespVO::getColCode)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ fullPdfRequest.put("continuePage", isContinuePage);
|
|
|
+ fullPdfRequest.put("copyConfig", copyConfig.toJSONString());
|
|
|
+ fullPdfRequest.put("existingColCodes", existingColCodes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// 调用 fullPdf 接口生成 PDF
|
|
|
String jsonString = JSON.toJSONString(fullPdfRequest);
|
|
|
HttpResponse response = HttpUtil.createPost(grapecityUrl+"/grapecity/pdf")
|