|
@@ -10,19 +10,21 @@ import kd.bos.openapi.common.custom.annotation.ApiController;
|
|
|
import kd.bos.openapi.common.custom.annotation.ApiParam;
|
|
|
import kd.bos.openapi.common.custom.annotation.ApiPostMapping;
|
|
|
import kd.bos.openapi.common.result.CustomApiResult;
|
|
|
+import kd.bos.servicehelper.DispatchServiceHelper;
|
|
|
import kd.imc.rim.common.message.exception.MsgException;
|
|
|
import kd.imc.rim.common.utils.FileUploadUtils;
|
|
|
import kd.imc.rim.common.utils.FileUtils;
|
|
|
import kd.imc.rim.common.utils.MD5;
|
|
|
+import nckd.jimin.jyyy.fi.common.XmlUtils;
|
|
|
import nckd.jimin.jyyy.fi.plugin.operate.SRMHelperUtils;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.*;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
-import java.util.Base64;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.UUID;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@ApiController(
|
|
|
desc = "对接SRM预付款、付款附件,上传到发票",
|
|
@@ -46,36 +48,136 @@ public class SRMSynAttacmentApiPlugin implements Serializable {
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- String token = accesstoken;
|
|
|
- JSONObject returnData = new JSONObject();
|
|
|
+ InputStream inputStream = null;
|
|
|
+ try {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- String downloadUrl = "https://gateway.test.isrm.going-link.com/hfle/v1/19694/files/download?bucketName=private-bucket&url=https://isrm-test-private-bucket.obs.cn-east-2.myhuaweicloud.com:443/2025-05/cusz-attachment-default/19694/744f2e7425f7468283578f48879bb4be@%E5%B1%B1%E7%A6%BE%E8%AE%A2%E5%8D%95%E6%A8%A1%E6%9D%BF.pdf";
|
|
|
- downloadUrl = downloadUrl + "&access_token=" + token;
|
|
|
+ inputStream = Files.newInputStream(Paths.get("C:\\Users\\Administrator\\Desktop\\testsrmatt\\test.pdf"));
|
|
|
|
|
|
- logger.info("SRMSynAttacmentApiPlugin:downloadUrl " + downloadUrl);
|
|
|
+ String base64 = InputStreamToBase64String(inputStream);
|
|
|
+ byte[] bytes = InputStreamToBytes(inputStream);
|
|
|
+
|
|
|
+ String fileName = fileName("pdf");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ String fileUrl = upFileOfBase64(base64, "10", fileName);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("billId", "2219015625274035200");
|
|
|
+ map.put("billNo", "DGBX-250520-0082");
|
|
|
+ map.put("billType", "er_publicreimbursebill");
|
|
|
+ map.put("entityId", "6B2CW570E+4");
|
|
|
+ map.put("viewPage", "er_publicreimbursebill");
|
|
|
+ map.put("billUser", "18679139819");
|
|
|
+ map.put("userName", "18679139819");
|
|
|
+ map.put("resource", "1");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ map.put("invoiceData", list);
|
|
|
+ Map<String, Object> extInfo = new HashMap<String, Object>();
|
|
|
+
|
|
|
+ map.put("extInfo", extInfo);
|
|
|
+
|
|
|
+ List<Map<String, Object>> coverList = new ArrayList<>();
|
|
|
+
|
|
|
+ Map<String, Object> coverMap = new HashMap<>();
|
|
|
+
|
|
|
+ coverMap.put("attachName", "测试pdf");
|
|
|
+ coverMap.put("attachType", "1");
|
|
|
+ coverMap.put("attachUrl", fileUrl);
|
|
|
+
|
|
|
+ coverList.add(coverMap);
|
|
|
+
|
|
|
+ map.put("attachData", coverList);
|
|
|
+
|
|
|
+
|
|
|
+ inputStream.close();
|
|
|
|
|
|
- InputStream inputStream = null;
|
|
|
- try {
|
|
|
- URL url = new URL(downloadUrl);
|
|
|
-
|
|
|
- HttpURLConnection connection =(HttpURLConnection) url.openConnection();
|
|
|
|
|
|
- connection.getContentLength();
|
|
|
+ JSONObject result = DispatchServiceHelper.invokeBizService("imc", "rim", "FpzsService", "save", map);
|
|
|
+ if ("0000".equals(result.getString("errcode"))) {
|
|
|
+ return returnResult("S", "保存成功", null);
|
|
|
+ } else {
|
|
|
+ return returnResult("S", "保存失败" + result.getString("description"), null);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- inputStream = new BufferedInputStream(connection.getInputStream());
|
|
|
|
|
|
- String base64 = InputStreamToBase64String(inputStream);
|
|
|
|
|
|
- String fileName = fileName("1");
|
|
|
- String fileUrl = upFileOfBase64(base64, fileName, "测试srm上传发票附件");
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- returnData.put("fileUrl", fileUrl == null ? "" : fileUrl);
|
|
|
- returnData.put("downloadUrl", downloadUrl);
|
|
|
|
|
|
- connection.disconnect();
|
|
|
- inputStream.close();
|
|
|
} catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
@@ -84,7 +186,7 @@ public class SRMSynAttacmentApiPlugin implements Serializable {
|
|
|
|
|
|
}
|
|
|
|
|
|
- return returnResult("S", "成功", returnData);
|
|
|
+ return returnResult("S", "成功", null);
|
|
|
}
|
|
|
|
|
|
private String upFileOfBase64(String base64, String fileType, String fileName) {
|
|
@@ -102,6 +204,23 @@ public class SRMSynAttacmentApiPlugin implements Serializable {
|
|
|
return path;
|
|
|
}
|
|
|
|
|
|
+ private String upFileOfBytes(byte[] bytes, String fileType, String fileName) {
|
|
|
+ String url = FileUploadUtils.getInvoiceDir("invoice") + fileName;
|
|
|
+ String fileId = MD5.SHA256Hex(fileType + bytes.toString());
|
|
|
+ String path = FileUtils.queryFilePath(fileId);
|
|
|
+ if (StringUtils.isEmpty(path)) {
|
|
|
+ path = FileUploadUtils.uploadBytes(url, fileName, bytes);
|
|
|
+ FileUtils.saveFilePath("", path, fileId, fileType);
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.info("SRMSynAttacmentApiPlugin 上传服务器:fileName:" + fileName + ", url:" + url + ", fileId: " + fileId);
|
|
|
+ logger.info("SRMSynAttacmentApiPlugin:" + (path == null ? "path is null" : path));
|
|
|
+
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private String fileName(String fileType) {
|
|
|
String fileName = String.valueOf(UUID.randomUUID());
|
|
|
String filePix = "";
|
|
@@ -117,6 +236,8 @@ public class SRMSynAttacmentApiPlugin implements Serializable {
|
|
|
filePix = ".ofd";
|
|
|
} else if (FileUtils.isImage(fileType)) {
|
|
|
filePix = ".jpg";
|
|
|
+ } else {
|
|
|
+ filePix = "." + fileType;
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(filePix)) {
|
|
@@ -134,8 +255,8 @@ public class SRMSynAttacmentApiPlugin implements Serializable {
|
|
|
*/
|
|
|
private String InputStreamToBase64String(InputStream inputStream){
|
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
-
|
|
|
- byte[] buffer = new byte[1024 * 1024 * 5];
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+
|
|
|
int bytesRead;
|
|
|
try {
|
|
|
|
|
@@ -164,6 +285,45 @@ public class SRMSynAttacmentApiPlugin implements Serializable {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private byte[] InputStreamToBytes(InputStream inputStream){
|
|
|
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+
|
|
|
+ int bytesRead;
|
|
|
+ try {
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ try {
|
|
|
+ if (!((bytesRead = inputStream.read(buffer)) != -1)) break;
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ byteArrayOutputStream.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ byte[] bytes = byteArrayOutputStream.toByteArray();
|
|
|
+
|
|
|
+ byteArrayOutputStream.close();
|
|
|
+
|
|
|
+ return bytes;
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static String parseXMLString(String xml) {
|
|
|
+ int strIndex = xml.indexOf("<?xml ");
|
|
|
+ int endIndex = xml.indexOf("</DATA>");
|
|
|
+ String conStr = xml.substring(strIndex, endIndex + 7);
|
|
|
+
|
|
|
+
|
|
|
+ return conStr;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
* 自定义返回data对象
|