获取发票快照链接并上传文件服务器-龚宇杰
This commit is contained in:
		
							parent
							
								
									47e773b52f
								
							
						
					
					
						commit
						e5165670bf
					
				| 
						 | 
				
			
			@ -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<String> 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");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue