|
@@ -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) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- InputStream inputStream = null;
|
|
|
+ @Valid @ApiParam(value = "附件xml") String request) {
|
|
|
+
|
|
|
+
|
|
|
+ Map<String,String> tokenMap = SRMHelperUtils.getSRMToken();
|
|
|
+ if (!"0".equals(tokenMap.get("code"))) {
|
|
|
+ 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 {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- inputStream = Files.newInputStream(Paths.get("C:\\Users\\Administrator\\Desktop\\testsrmatt\\test.pdf"));
|
|
|
-
|
|
|
- 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();
|
|
|
-
|
|
|
-
|
|
|
- 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);
|
|
|
+
|
|
|
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
+
|
|
|
+ int size = connection.getContentLength();
|
|
|
+
|
|
|
+
|
|
|
+ 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("uid", uid.toString() + i);
|
|
|
+
|
|
|
+ attachments.add(attachmentInfo);
|
|
|
+
|
|
|
+ connection.disconnect();
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
|
|
|
+ attachmentInfos.put("attachmentpanel",attachments);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ 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 {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ return returnResult("E", "附件保存异常" + e.getMessage(), null);
|
|
|
}
|
|
|
|
|
|
- return returnResult("S", "成功", null);
|
|
|
+ return returnResult("S", "附件同步成功", null);
|
|
|
}
|
|
|
|
|
|
private String upFileOfBase64(String base64, String fileType, String fileName) {
|