获取发票快照链接并上传文件服务器-龚宇杰

This commit is contained in:
ggxl 2025-05-30 10:12:36 +08:00
parent 47e773b52f
commit e5165670bf
1 changed files with 26 additions and 19 deletions

View File

@ -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.business.invoicecloud.kingdee.KingdeeInvoiceCloudConfig;
import kd.fi.er.common.utils.MD5; import kd.fi.er.common.utils.MD5;
import kd.sdk.plugin.Plugin; import kd.sdk.plugin.Plugin;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
@ -40,6 +41,8 @@ import org.ofdrw.converter.ImageMaker;
import org.ofdrw.reader.OFDReader; import org.ofdrw.reader.OFDReader;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.spi.ImageReaderSpi;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp; import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage; 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)); JSONObject obj = (JSONObject) JSONObject.parse(sendPost(url, header, body));
JSONArray data = (JSONArray) obj.get("data"); JSONArray data = (JSONArray) obj.get("data");
JSONObject invoice = (JSONObject) data.get(0); 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")); result.put("originalFileName", (String) invoice.get("originalFileName"));
} else { } else {
log.warn("TripReimbursePrintPluginGetInvoiceDetailDataHeader参数未配置"); log.warn("TripReimbursePrintPluginGetInvoiceDetailDataHeader参数未配置");
@ -238,14 +241,15 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu
ArrayList<String> resUrls = new ArrayList<>(); ArrayList<String> resUrls = new ArrayList<>();
try { try {
FileService fs = FileServiceFactory.getAttachmentFileService(); FileService fs = FileServiceFactory.getAttachmentFileService();
String uploadPrefix = "/invoiceApi/tripreimburse/image/"; String uploadPrefix = "/invoiceApi/image/";
String file = result.get("originalFileName"); String file = result.get("originalFileName");
String url = result.get("downloadUrl"); String url = result.get("snapshotUrl");
String newFileName = ""; String newFileName = "";
int index = file.lastIndexOf("."); int index = url.lastIndexOf(".");
String fileType = file.substring(index + 1); int index1 = file.lastIndexOf(".");
String fileName = URLEncoder.encode(file.substring(0, index), "utf-8"); String fileType = url.substring(index + 1);
String fileName = file.substring(0, index1);
URL Url = new URL(url); URL Url = new URL(url);
HttpURLConnection conn = (HttpURLConnection) Url.openConnection(); HttpURLConnection conn = (HttpURLConnection) Url.openConnection();
InputStream inputStream = conn.getInputStream(); InputStream inputStream = conn.getInputStream();
@ -259,7 +263,6 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu
BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 1000, ImageType.RGB); BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 1000, ImageType.RGB);
ImageIO.write(bim, "jpg", outputStream); ImageIO.write(bim, "jpg", outputStream);
inputStream.close(); inputStream.close();
}
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(outputStream.toByteArray()); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(outputStream.toByteArray());
FileItem fileItem = new FileItem(newFileName, uploadPrefix + newFileName, byteArrayInputStream); FileItem fileItem = new FileItem(newFileName, uploadPrefix + newFileName, byteArrayInputStream);
String upload = fs.upload(fileItem); String upload = fs.upload(fileItem);
@ -268,6 +271,7 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu
String uploadEncreptURL = AttachmentServiceHelper.getEncreptURL(uploadUrl); String uploadEncreptURL = AttachmentServiceHelper.getEncreptURL(uploadUrl);
byteArrayInputStream.close(); byteArrayInputStream.close();
resUrls.add(uploadEncreptURL); resUrls.add(uploadEncreptURL);
}
document.close(); document.close();
} else if ("ofd".equals(fileType)) { } else if ("ofd".equals(fileType)) {
try (OFDReader reader = new OFDReader(inputStream);) { 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) } else if ("jpg".equalsIgnoreCase(fileType) || "jpeg".equalsIgnoreCase(fileType) || "png".equalsIgnoreCase(fileType)
|| "bmp".equalsIgnoreCase(fileType) || "gif".equalsIgnoreCase(fileType)) { || "bmp".equalsIgnoreCase(fileType) || "gif".equalsIgnoreCase(fileType)) {
IOUtils.copy(inputStream, outputStream);
inputStream.close();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(outputStream.toByteArray()); 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); String upload = fs.upload(fileItem);
deleteUrl.add(upload); deleteUrl.add(upload);
String uploadUrl = UrlService.getAttachmentDownloadUrl(upload); String uploadUrl = UrlService.getAttachmentDownloadUrl(upload);
@ -303,7 +310,7 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("message" + e.getMessage()); log.error("TripReimbursePrintPlugin error" + e.getMessage());
} }
return resUrls; return resUrls;
} }
@ -381,7 +388,7 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu
document.close(); document.close();
} }
} catch (Exception e) { } catch (Exception e) {
log.error("message" + e.getMessage()); log.error("TripReimbursePrintPlugin error" + e.getMessage());
} }
return resUrls; return resUrls;
} }
@ -439,7 +446,7 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu
resUrls.add(uploadEncreptURL); resUrls.add(uploadEncreptURL);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("message" + e.getMessage()); log.error("TripReimbursePrintPlugin error" + e.getMessage());
} }
} }
return resUrls; return resUrls;
@ -454,7 +461,7 @@ public class TripReimbursePrintPlugin extends AbstractPrintPlugin implements Plu
String fileName = realPath.substring(realPath.lastIndexOf("/") + 1); String fileName = realPath.substring(realPath.lastIndexOf("/") + 1);
realPath = realPath.substring(0, realPath.lastIndexOf("/")) + "/" + URLEncoder.encode(fileName, "utf-8"); realPath = realPath.substring(0, realPath.lastIndexOf("/")) + "/" + URLEncoder.encode(fileName, "utf-8");
} catch (Exception e) { } catch (Exception e) {
log.error("TripReimbursePrintPlugin" + e.getMessage()); log.error("TripReimbursePrintPlugin error" + e.getMessage());
} }
String fileserver = System.getProperty("fileserver"); String fileserver = System.getProperty("fileserver");