From e5165670bfccc2e8443cdd7fb8d9583aaeca9479 Mon Sep 17 00:00:00 2001 From: ggxl <194689125@qq.com> Date: Fri, 30 May 2025 10:12:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=8F=91=E7=A5=A8=E5=BF=AB?= =?UTF-8?q?=E7=85=A7=E9=93=BE=E6=8E=A5=E5=B9=B6=E4=B8=8A=E4=BC=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=9C=8D=E5=8A=A1=E5=99=A8-=E9=BE=9A=E5=AE=87?= =?UTF-8?q?=E6=9D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../print/TripReimbursePrintPlugin.java | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/main/java/zf47/jdgz1/fi/em/plugin/print/TripReimbursePrintPlugin.java b/src/main/java/zf47/jdgz1/fi/em/plugin/print/TripReimbursePrintPlugin.java index effd073..a031918 100644 --- a/src/main/java/zf47/jdgz1/fi/em/plugin/print/TripReimbursePrintPlugin.java +++ b/src/main/java/zf47/jdgz1/fi/em/plugin/print/TripReimbursePrintPlugin.java @@ -26,6 +26,7 @@ import kd.fi.er.business.invoicecloud.cache.model.InvoiceCloudCfgBO; import kd.fi.er.business.invoicecloud.kingdee.KingdeeInvoiceCloudConfig; import kd.fi.er.common.utils.MD5; import kd.sdk.plugin.Plugin; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; @@ -40,6 +41,8 @@ import org.ofdrw.converter.ImageMaker; import org.ofdrw.reader.OFDReader; import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.spi.ImageReaderSpi; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; @@ -192,7 +195,7 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu JSONObject obj = (JSONObject) JSONObject.parse(sendPost(url, header, body)); JSONArray data = (JSONArray) obj.get("data"); JSONObject invoice = (JSONObject) data.get(0); - result.put("downloadUrl", (String) invoice.get("downloadUrl")); + result.put("snapshotUrl", (String) invoice.get("snapshotUrl")); result.put("originalFileName", (String) invoice.get("originalFileName")); } else { log.warn("TripReimbursePrintPlugin:GetInvoiceDetailDataHeader参数未配置"); @@ -238,14 +241,15 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu ArrayList resUrls = new ArrayList<>(); try { FileService fs = FileServiceFactory.getAttachmentFileService(); - String uploadPrefix = "/invoiceApi/tripreimburse/image/"; + String uploadPrefix = "/invoiceApi/image/"; String file = result.get("originalFileName"); - String url = result.get("downloadUrl"); + String url = result.get("snapshotUrl"); String newFileName = ""; - int index = file.lastIndexOf("."); - String fileType = file.substring(index + 1); - String fileName = URLEncoder.encode(file.substring(0, index), "utf-8"); + int index = url.lastIndexOf("."); + int index1 = file.lastIndexOf("."); + String fileType = url.substring(index + 1); + String fileName = file.substring(0, index1); URL Url = new URL(url); HttpURLConnection conn = (HttpURLConnection) Url.openConnection(); InputStream inputStream = conn.getInputStream(); @@ -259,15 +263,15 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 1000, ImageType.RGB); ImageIO.write(bim, "jpg", outputStream); inputStream.close(); + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(outputStream.toByteArray()); + FileItem fileItem = new FileItem(newFileName, uploadPrefix + newFileName, byteArrayInputStream); + String upload = fs.upload(fileItem); + deleteUrl.add(upload); + String uploadUrl = UrlService.getAttachmentDownloadUrl(upload); + String uploadEncreptURL = AttachmentServiceHelper.getEncreptURL(uploadUrl); + byteArrayInputStream.close(); + resUrls.add(uploadEncreptURL); } - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(outputStream.toByteArray()); - FileItem fileItem = new FileItem(newFileName, uploadPrefix + newFileName, byteArrayInputStream); - String upload = fs.upload(fileItem); - deleteUrl.add(upload); - String uploadUrl = UrlService.getAttachmentDownloadUrl(upload); - String uploadEncreptURL = AttachmentServiceHelper.getEncreptURL(uploadUrl); - byteArrayInputStream.close(); - resUrls.add(uploadEncreptURL); document.close(); } else if ("ofd".equals(fileType)) { try (OFDReader reader = new OFDReader(inputStream);) { @@ -292,8 +296,11 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu } } else if ("jpg".equalsIgnoreCase(fileType) || "jpeg".equalsIgnoreCase(fileType) || "png".equalsIgnoreCase(fileType) || "bmp".equalsIgnoreCase(fileType) || "gif".equalsIgnoreCase(fileType)) { + IOUtils.copy(inputStream, outputStream); + inputStream.close(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(outputStream.toByteArray()); - FileItem fileItem = new FileItem(fileName, uploadPrefix + fileName, byteArrayInputStream); + outputStream.close(); + FileItem fileItem = new FileItem(fileName + "." + fileType, uploadPrefix + fileName + "." + fileType, byteArrayInputStream); String upload = fs.upload(fileItem); deleteUrl.add(upload); String uploadUrl = UrlService.getAttachmentDownloadUrl(upload); @@ -303,7 +310,7 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu } } } catch (Exception e) { - log.error("message" + e.getMessage()); + log.error("TripReimbursePrintPlugin error" + e.getMessage()); } return resUrls; } @@ -381,7 +388,7 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu document.close(); } } catch (Exception e) { - log.error("message" + e.getMessage()); + log.error("TripReimbursePrintPlugin error" + e.getMessage()); } return resUrls; } @@ -439,7 +446,7 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu resUrls.add(uploadEncreptURL); } } catch (Exception e) { - log.error("message" + e.getMessage()); + log.error("TripReimbursePrintPlugin error" + e.getMessage()); } } return resUrls; @@ -454,7 +461,7 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu String fileName = realPath.substring(realPath.lastIndexOf("/") + 1); realPath = realPath.substring(0, realPath.lastIndexOf("/")) + "/" + URLEncoder.encode(fileName, "utf-8"); } catch (Exception e) { - log.error("TripReimbursePrintPlugin:" + e.getMessage()); + log.error("TripReimbursePrintPlugin error:" + e.getMessage()); } String fileserver = System.getProperty("fileserver");