|
@@ -2,14 +2,22 @@ package nckd.jimin.jyyy.fi.webapi;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import kd.bos.cache.CacheFactory;
|
|
|
+import kd.bos.cache.TempFileCache;
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
import kd.bos.dataentity.resource.ResManager;
|
|
|
import kd.bos.dataentity.utils.StringUtils;
|
|
|
+import kd.bos.entity.BillEntityType;
|
|
|
import kd.bos.logging.Log;
|
|
|
import kd.bos.logging.LogFactory;
|
|
|
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.orm.query.QCP;
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.servicehelper.AttachmentServiceHelper;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
import kd.bos.servicehelper.DispatchServiceHelper;
|
|
|
import kd.imc.rim.common.message.exception.MsgException;
|
|
|
import kd.imc.rim.common.utils.FileUploadUtils;
|
|
@@ -37,156 +45,101 @@ public class SRMSynAttacmentApiPlugin implements Serializable {
|
|
|
|
|
|
@ApiPostMapping("synAttacmenthForSRM")
|
|
|
public CustomApiResult<JSONObject> synAttacmenthForSRM(
|
|
|
- @Valid @ApiParam(value = "附件xml") String request
|
|
|
- , @Valid @ApiParam(value = "token") String accesstoken) {
|
|
|
-
|
|
|
-// //获取token
|
|
|
-// Map<String,String> tokenMap = SRMHelperUtils.getSRMToken();
|
|
|
-// if (!"0".equals(tokenMap.get("code"))) {//未获取到token
|
|
|
-// logger.info("get srm token fail" + tokenMap.get("msg"));
|
|
|
-//
|
|
|
-// return returnResult("E", "失败,获取token失败," + tokenMap.get("msg"), null);
|
|
|
-// }
|
|
|
-// String token = tokenMap.get("msg").toString();
|
|
|
-//
|
|
|
-// token = "8862dff0-cf8c-432e-9b4f-453e66604226";
|
|
|
-//
|
|
|
-//
|
|
|
-// if(StringUtils.isEmpty(request)){
|
|
|
-// return returnResult("E", "参数不能为空,", null);
|
|
|
-// }
|
|
|
-// request = parseXMLString(request);
|
|
|
-//
|
|
|
-// request = request.replace("\r\n", "");
|
|
|
-//
|
|
|
-// try {
|
|
|
-// JSONObject requestJSON = XmlUtils.documentToJSONObject(request);
|
|
|
-// JSONArray fileArray = requestJSON.getJSONArray("BillBody")
|
|
|
-// .getJSONObject(0).getJSONArray("Document")
|
|
|
-// .getJSONObject(0).getJSONArray("Files")
|
|
|
-// .getJSONObject(0).getJSONArray("File");
|
|
|
-//
|
|
|
-// for(int i = 0; i < fileArray.size(); i++){
|
|
|
-// JSONObject fileItem = fileArray.getJSONObject(i);
|
|
|
-// String fileSize = fileItem.getString("FILE_SIZE");
|
|
|
-// String fileName = fileItem.getString("FILE_NAME");
|
|
|
-// String fileType = fileItem.getString("FILE_TYPE");
|
|
|
-// String fileUrl = fileItem.getString("URL");
|
|
|
-// }
|
|
|
-//
|
|
|
-// } catch(Exception e){
|
|
|
-// return returnResult("E", "xml参数异常" + e.getMessage(), null);
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-//// String token = accesstoken;
|
|
|
-// JSONObject returnData = new JSONObject();
|
|
|
-//
|
|
|
-// 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 = "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/ssta-settle-header/19694/209b30126cd742049241198ddd7b13b9@%E8%B4%B9%E6%8E%A7%E4%BB%98%E6%AC%BE%E5%8D%95%E6%B5%8B%E8%AF%95%E9%99%84%E4%BB%B6.docx";
|
|
|
-// downloadUrl = downloadUrl + "&access_token=" + token;
|
|
|
-//
|
|
|
-// logger.info("SRMSynAttacmentApiPlugin:downloadUrl " + downloadUrl);
|
|
|
-//
|
|
|
-
|
|
|
- InputStream inputStream = null;
|
|
|
+ @Valid @ApiParam(value = "附件xml") String request) {
|
|
|
+
|
|
|
+ //获取srm token
|
|
|
+ Map<String,String> tokenMap = SRMHelperUtils.getSRMToken();
|
|
|
+ if (!"0".equals(tokenMap.get("code"))) {//未获取到token
|
|
|
+ logger.info("get srm token fail" + tokenMap.get("msg"));
|
|
|
+
|
|
|
+ return returnResult("E", "失败,获取token失败," + tokenMap.get("msg"), null);
|
|
|
+ }
|
|
|
+ String token = tokenMap.get("msg").toString();
|
|
|
+
|
|
|
+ if(StringUtils.isEmpty(request)){
|
|
|
+ return returnResult("E", "参数不能为空,", null);
|
|
|
+ }
|
|
|
+ request = parseXMLString(request);
|
|
|
+ request = request.replace("\r\n", "");
|
|
|
+
|
|
|
try {
|
|
|
-// URL url = new URL(downloadUrl);
|
|
|
-// //这里没有使用 封装后的ResponseEntity 就是也是因为这里不适合一次性的拿到结果,放不下content,会造成内存溢出
|
|
|
-// HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
-//
|
|
|
-// int size = connection.getContentLength();
|
|
|
-//
|
|
|
-// //使用bufferedInputStream 缓存流的方式来获取下载文件,不然大文件会出现内存溢出的情况
|
|
|
-// inputStream = new BufferedInputStream(connection.getInputStream());
|
|
|
-
|
|
|
- inputStream = Files.newInputStream(Paths.get("C:\\Users\\Administrator\\Desktop\\testsrmatt\\test.pdf"));
|
|
|
-
|
|
|
- String base64 = InputStreamToBase64String(inputStream);
|
|
|
- byte[] bytes = InputStreamToBytes(inputStream);
|
|
|
-
|
|
|
- String fileName = fileName("pdf");
|
|
|
-
|
|
|
-// fileName = "pdg测试.pdf";
|
|
|
-
|
|
|
-// String fileUrl1 = upFileOfBytes(bytes, "1", fileName);
|
|
|
-
|
|
|
- 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");
|
|
|
-// map.put("status", "");
|
|
|
-// map.put("updateAttachRelation","1");
|
|
|
-// map.put("updateInvoiceOrg","1");
|
|
|
-// int total = getModel().getEntryRowCount("entryentity");
|
|
|
-// if(total == 0){
|
|
|
-// total = 2;
|
|
|
-// }
|
|
|
- List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
|
|
-// for (int i = 0; i < total; i++) {
|
|
|
-// Map<String, Object> map11 = new HashMap<String, Object>();
|
|
|
-// map11.put("amount", "12");
|
|
|
-// map11.put("serialNo", getModel().getValue("serial_no", i));
|
|
|
-// map11.put("deductionFlag", "1");
|
|
|
-// map11.put("deductionTaxAmount", "23");
|
|
|
-// map11.put("effectiveTaxAmount", "23");
|
|
|
-// map11.put("entryId", "121212");
|
|
|
-// map11.put("status", status);
|
|
|
-// list.add(map11);
|
|
|
-// }
|
|
|
- map.put("invoiceData", list);
|
|
|
- Map<String, Object> extInfo = new HashMap<String, Object>();
|
|
|
-// extInfo.put("二开字段标识", "二开字段值");
|
|
|
- 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);
|
|
|
-
|
|
|
-// connection.disconnect();
|
|
|
- inputStream.close();
|
|
|
-
|
|
|
-
|
|
|
- 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);
|
|
|
+ JSONObject requestJSON = XmlUtils.documentToJSONObject(request);
|
|
|
+ JSONObject billBody = requestJSON.getJSONArray("BillBody").getJSONObject(0);
|
|
|
+ JSONObject bill = billBody.getJSONArray("Bill").getJSONObject(0);
|
|
|
+ JSONArray fileArray = billBody.getJSONArray("Document")
|
|
|
+ .getJSONObject(0).getJSONArray("Files")
|
|
|
+ .getJSONObject(0).getJSONArray("File");
|
|
|
+
|
|
|
+ String billNO = bill.getString("billcode");
|
|
|
+ String entityName = "er_publicreimbursebill";
|
|
|
+ QFilter qFilter = new QFilter("billno", QCP.equals, billNO);
|
|
|
+
|
|
|
+ DynamicObject billInfo = BusinessDataServiceHelper.loadSingle(entityName, qFilter.toArray());
|
|
|
+
|
|
|
+ if(billInfo == null){
|
|
|
+ return returnResult("E", "失败,单据号(" + billNO + ")在星瀚中未匹配到单据", null);
|
|
|
}
|
|
|
|
|
|
+ JSONObject returnData = new JSONObject();
|
|
|
+
|
|
|
+ Map<String, Object> attachmentInfos = new HashMap<>();
|
|
|
+ List<Map<String, Object>> attachments = new ArrayList<>();
|
|
|
+
|
|
|
+ for(int i = 0; i < fileArray.size(); i++){
|
|
|
+ JSONObject fileItem = fileArray.getJSONObject(i);
|
|
|
+ String fileSize = fileItem.getString("FILE_SIZE");
|
|
|
+ String fileName = fileItem.getString("FILE_NAME");
|
|
|
+ String fileType = fileItem.getString("FILE_TYPE");
|
|
|
+ String fileUrl = fileItem.getString("URL");
|
|
|
+
|
|
|
+ fileUrl = fileUrl.replace("&", "&");
|
|
|
+ String downloadUrl = fileUrl + "&access_token=" + token;
|
|
|
+
|
|
|
+ logger.info("SRMSynAttacmentApiPlugin:downloadUrl " + downloadUrl);
|
|
|
+
|
|
|
+ URL url = new URL(downloadUrl);
|
|
|
+ //这里没有使用 封装后的ResponseEntity 就是也是因为这里不适合一次性的拿到结果,放不下content,会造成内存溢出
|
|
|
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
+
|
|
|
+ int size = connection.getContentLength();
|
|
|
+
|
|
|
+ //使用bufferedInputStream 缓存流的方式来获取下载文件,不然大文件会出现内存溢出的情况
|
|
|
+ InputStream inputStream = new BufferedInputStream(connection.getInputStream());
|
|
|
+
|
|
|
+ byte[] fileData = InputStreamToBytes(inputStream);
|
|
|
+
|
|
|
+ TempFileCache cache = CacheFactory.getCommonCacheFactory().getTempFileCache();
|
|
|
+ String tempUrl = cache.saveAsFullUrl(fileName, fileData,3600);
|
|
|
+
|
|
|
+ StringBuffer uid = new StringBuffer();
|
|
|
+ uid.append("rc-upload-").append(new Date().getTime()).append("-");
|
|
|
+ Map<String,Object> attachmentInfo = new HashMap<>();
|
|
|
+ attachmentInfo.put("entityNumber", "entityNumber");
|
|
|
+ attachmentInfo.put("name", fileName);
|
|
|
+ attachmentInfo.put("url", tempUrl);
|
|
|
+ attachmentInfo.put("size", fileSize);
|
|
|
+// attachmentInfo.put("status", map.get("status"));
|
|
|
+ attachmentInfo.put("uid", uid.toString() + i);
|
|
|
+
|
|
|
+ attachments.add(attachmentInfo);
|
|
|
+
|
|
|
+ connection.disconnect();
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
|
|
|
+ attachmentInfos.put("attachmentpanel",attachments);
|
|
|
|
|
|
-// returnData.put("fileUrl", fileUrl == null ? "" : fileUrl);
|
|
|
-// returnData.put("downloadUrl", downloadUrl);
|
|
|
+ BillEntityType dataEntityType = (BillEntityType) billInfo.getDataEntityType();
|
|
|
+ String appId = dataEntityType.getAppId();
|
|
|
|
|
|
+ AttachmentServiceHelper.saveTempAttachments(entityName, billInfo.getLong("id"), appId, attachmentInfos);
|
|
|
+ } catch(Exception e){
|
|
|
+ logger.info("synAttacmenthForSRM:" + (e.getMessage() == null ? "" : e.getMessage()));
|
|
|
|
|
|
- } catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- // 5、关闭资源
|
|
|
-// IOUtils.closeQuietly(outputStream);
|
|
|
-// IOUtils.closeQuietly(inputStream);
|
|
|
+ return returnResult("E", "附件保存异常" + e.getMessage(), null);
|
|
|
}
|
|
|
|
|
|
- return returnResult("S", "成功", null);
|
|
|
+ return returnResult("S", "附件同步成功", null);
|
|
|
}
|
|
|
|
|
|
private String upFileOfBase64(String base64, String fileType, String fileName) {
|