From 91a768bae5c7a3992355bf83c4e98dfc026db73b Mon Sep 17 00:00:00 2001 From: xiang2lin <251481237@qq.com> Date: Thu, 12 Jun 2025 10:26:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E8=B4=AD=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base-buildpackage/pom.xml | 4 +- .../RequisitionOrderPluginServiceImpl.java | 211 ++++++++++++------ .../ncc/spring/spring-buildpackage-plugin.xml | 2 +- 3 files changed, 146 insertions(+), 71 deletions(-) diff --git a/base-buildpackage/pom.xml b/base-buildpackage/pom.xml index 2467d45d..b91e52ac 100644 --- a/base-buildpackage/pom.xml +++ b/base-buildpackage/pom.xml @@ -45,9 +45,9 @@ - zqtlocal + jianhui - zqtlocal + jianhui diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/oa/praybill/service/impl/RequisitionOrderPluginServiceImpl.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/oa/praybill/service/impl/RequisitionOrderPluginServiceImpl.java index 49b42f3f..68710684 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/oa/praybill/service/impl/RequisitionOrderPluginServiceImpl.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/oa/praybill/service/impl/RequisitionOrderPluginServiceImpl.java @@ -1,5 +1,7 @@ package com.hzya.frame.plugin.oa.praybill.service.impl; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; @@ -8,17 +10,24 @@ import com.alibaba.fastjson.JSONObject; import com.hzya.frame.plugin.oa.praybill.entity.RequisitionOrderEntity; import com.hzya.frame.plugin.oa.praybill.service.IRequisitionOrderPluginService; import com.hzya.frame.plugin.oa.praybill.service.IRequisitionOrderService; +import com.hzya.frame.seeyon.entity.CollAttachmentResDTO; import com.hzya.frame.seeyon.enums.ColEventTypeEnum; +import com.hzya.frame.seeyon.util.OARestUtil; import com.hzya.frame.sysnew.integtationTaskLivingDetails.entity.IntegrationTaskLivingDetailsEntity; import com.hzya.frame.sysnew.integtationTaskLivingDetails.service.IIntegrationTaskLivingDetailsService; import com.hzya.frame.uuid.UUIDUtils; import com.hzya.frame.web.entity.BaseResult; import com.hzya.frame.web.entity.JsonResultEntity; +import org.apache.commons.collections.CollectionUtils; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import java.io.File; +import java.net.URLDecoder; +import java.util.Base64; import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -34,7 +43,9 @@ public class RequisitionOrderPluginServiceImpl implements IRequisitionOrderPlugi @Autowired private IIntegrationTaskLivingDetailsService taskLivingDetailsService; @Autowired - private IRequisitionOrderService requisitionOrderService; + private IRequisitionOrderService requisitionOrderService; + @Autowired + private OARestUtil oaRestUtil; Logger logger = LoggerFactory.getLogger(IRequisitionOrderPluginService.class); /** * 请购单同步到ncc @@ -48,85 +59,22 @@ public class RequisitionOrderPluginServiceImpl implements IRequisitionOrderPlugi String datasourceCode = requestJson.getString("sourceCode"); String task_living_details_id = requestJson.getString("integration_task_living_details_id"); String headersStr = requestJson.getString("headers");//请求头 - //String formAppId = requestJson.getString("formApp"); String eventType = requestJson.getString("eventType"); + String summaryId = requestJson.getString("summaryId"); JSONObject headers = requestJson.getJSONObject("headers"); - // Assert.notEmpty(formAppId,"formAppId不能为空"); Assert.notEmpty(eventType,"eventType不能为空"); Assert.notEmpty(headersStr,"headers不能为空"); String formmainTableName = headers.getString("formmainTableName"); String forsonTableName = headers.getString("forsonTableName"); + String fileApiCode = headers.getString("fileApiCode"); JSONObject jsonStrObj = requestJson.getJSONObject("jsonStr"); JSONObject businessData = jsonStrObj.getJSONObject("businessDataStr"); JSONObject formmainData = businessData.getJSONObject(formmainTableName); JSONArray forsonData = businessData.getJSONArray(forsonTableName); //流程结束 if (ColEventTypeEnum.ONPROCESSFINISHED.getType().equals(eventType)){ - JSONObject paramObj = new JSONObject(); - JSONObject praybill = new JSONObject(); - paramObj.put("head", praybill); - praybill.put("pk_group",formmainData.getString("field0058"));//集团 - praybill.put("pk_org",formmainData.getString("field0027"));//库存组织 - praybill.put("pk_org_v",formmainData.getString("field0051"));//库存组织v - //praybill.put("vbillcode",formmainData.getString("field0001"));//请购单号 - praybill.put("dbilldate",formmainData.getString("field0004"));//请购日期 - boolean bsctype = false; - if ("1".equals(formmainData.getString("field0009"))){ - bsctype = true; - } - praybill.put("bsctype",bsctype);//委外 - praybill.put("pk_planpsn",formmainData.getString("field0030"));//计划员 - praybill.put("pk_plandept",formmainData.getString("field0052"));//计划部门 - praybill.put("pk_plandept_v",formmainData.getString("field0053"));//计划部门v - praybill.put("vmemo",formmainData.getString("field0013"));//备注 - praybill.put("fbillstatus",headers.getString("fbillstatus"));//单据状态 - praybill.put("bdirecttransit",false);//zhiyun - praybill.put("billmaker", headers.getString("billmaker"));//制单人 yonyou99 - praybill.put("dmakedate", formmainData.getString("field0004"));//制单日期 - praybill.put("ctrantypeid", formmainData.getString("field0039"));//请购类型 - praybill.put("bislatest", true);//最新版本 - praybill.put("vdef1",formmainData.getString("field0002")); - praybill.put("creator",headers.getString("creator"));// - praybill.put("fpraysource",headers.getString("fpraysource"));// - praybill.put("ccurrencyid",headers.getString("ccurrencyid"));// - praybill.put("nversion",headers.getString("nversion"));// - praybill.put("nversion",headers.getString("nversion"));// - List parybillList = new LinkedList<>(); - paramObj.put("body",parybillList); - String pk_org = formmainData.getString("field0027"); - String pk_org_v = formmainData.getString("field0051"); - for(int i=0; i collAttachmentList = oaRestUtil.getColAttachments(summaryId, "0", fileApiCode, token); + if (CollectionUtils.isNotEmpty(collAttachmentList)){ + //获取OA token + for (CollAttachmentResDTO collAttachment : collAttachmentList) { + try { + String fileName = URLDecoder.decode(collAttachment.getFilename(), "UTF-8"); + byte[] bytes = oaRestUtil.downloadFileBytes("hzya", fileApiCode, collAttachment.getFileUrl(), fileName, token); + String base64File = Base64.getEncoder().encodeToString(bytes); + JSONObject fileParams = new JSONObject(); + fileParams.put("creator", headers.getString("creator")); + fileParams.put("pk_bill", pk_bill); + fileParams.put("filename",fileName); + fileParams.put("file",base64File); + String result = HttpRequest.post(baseUrl) + .header("appId", "800065")//NCC应用 + .header("apiCode", "8000650001")//NCC附件上传接口 + .header("publicKey", "ZJYAbkr9+XjnDrlfQCRKXtpVvg/BjxqtxzcLgg5TIGagEKJCe7eDIk+3zDUT+v578prj")//OA公钥 + .header("secretKey", "2GR4+yrcx+Ev+pN0Q6V6wxCdvisPX7wzNKBgc5SsIYGxYI5GTISXT6GvTPfp1u2Rj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")//OA密钥 + .body(fileParams.toString())//表单内容 + .timeout(30000)//超时,毫秒 + .execute().body(); + logger.info("======OA请购单附件上传到NCC响应参数:{}======",result); + }catch(Exception e){ + e.printStackTrace(); + logger.error("下载OA附件出错:{}",e); + } + } + } + } + + /** + * 组装请购单报文 + * @param headers 请求头 + * @param formmainData 主表数据 + * @param forsonData 子表数据 + * @return + */ + @NotNull + private static JSONArray praybillVaueOf(JSONObject headers, JSONObject formmainData, JSONArray forsonData) { + JSONObject paramObj = new JSONObject(); + JSONObject praybill = new JSONObject(); + paramObj.put("head", praybill); + praybill.put("pk_group", formmainData.getString("field0058"));//集团 + praybill.put("pk_org", formmainData.getString("field0027"));//库存组织 + praybill.put("pk_org_v", formmainData.getString("field0051"));//库存组织v + //praybill.put("vbillcode",formmainData.getString("field0001"));//请购单号 + praybill.put("dbilldate", formmainData.getString("field0004"));//请购日期 + boolean bsctype = false; + if ("1".equals(formmainData.getString("field0009"))){ + bsctype = true; + } + praybill.put("bsctype",bsctype);//委外 + praybill.put("pk_planpsn", formmainData.getString("field0030"));//计划员 + praybill.put("pk_plandept", formmainData.getString("field0052"));//计划部门 + praybill.put("pk_plandept_v", formmainData.getString("field0053"));//计划部门v + praybill.put("vmemo", formmainData.getString("field0013"));//备注 + praybill.put("fbillstatus", headers.getString("fbillstatus"));//单据状态 + praybill.put("bdirecttransit",false);//zhiyun + praybill.put("billmaker", headers.getString("billmaker"));//制单人 yonyou99 + praybill.put("dmakedate", formmainData.getString("field0004"));//制单日期 + praybill.put("ctrantypeid", formmainData.getString("field0039"));//请购类型 + praybill.put("bislatest", true);//最新版本 + praybill.put("vdef1", formmainData.getString("field0037")); + praybill.put("creator", headers.getString("creator"));// + praybill.put("fpraysource", headers.getString("fpraysource"));// + praybill.put("ccurrencyid", headers.getString("ccurrencyid"));// + praybill.put("nversion", headers.getString("nversion"));// + praybill.put("nversion", headers.getString("nversion"));// + List parybillList = new LinkedList<>(); + paramObj.put("body",parybillList); + String pk_org = formmainData.getString("field0027"); + String pk_org_v = formmainData.getString("field0051"); + for(int i = 0; i< forsonData.size(); i++){ + JSONObject forson = forsonData.getJSONObject(i); + JSONObject praybillB = new JSONObject(); + praybillB.put("crowno",forson.getString("field0014")); + praybillB.put("nnum",forson.getString("field0020")); + praybillB.put("pk_org",pk_org); + praybillB.put("pk_org_v",pk_org_v); + praybillB.put("vchangerate","1"); + praybillB.put("pk_srcmaterial",forson.getString("field0054"));//物料pk带版本的那个 + praybillB.put("pk_material",forson.getString("field0031"));//物料pk + praybillB.put("castunitid",forson.getString("field0055"));//计量单位pk + praybillB.put("cunitid",forson.getString("field0055"));//计量单位pk + praybillB.put("nastnum",forson.getString("field0020"));//数量 + praybillB.put("dreqdate",forson.getString("field0021"));//需求日期 + praybillB.put("dsuggestdate",forson.getString("field0022"));//建议订货日期 + praybillB.put("pk_purchaseorg",pk_org);//采购组织 + praybillB.put("pk_purchaseorg_v",pk_org_v);//采购组织 带版本的那个 + praybillB.put("pk_suggestsupplier",forson.getString("field0056"));//建议供应商 + praybillB.put("pk_suggestsupplier_v",forson.getString("field0056"));//建议供应商 + praybillB.put("pk_reqstoorg",pk_org); + praybillB.put("pk_reqstoorg_v",pk_org_v); + praybillB.put("pk_group", formmainData.getString("field0058")); + praybillB.put("browclose","N");//行关闭 + praybillB.put("vbdef1",forson.getString("field0032"));//现存量 + praybillB.put("vbdef2",forson.getString("field0033"));//在途量 + praybillB.put("vbdef3",forson.getString("field0035"));//月度消耗 + praybillB.put("vbdef4",forson.getString("field0034"));//安全库存 + parybillList.add(praybillB); + } + //调用NCC接口 + JSONArray reqParams = new JSONArray(); + reqParams.add(paramObj); + return reqParams; + } + public static void main(String[] args) { String result = "{\"msg\":\"转发失败\",\"type\":null,\"flag\":false,\"status\":\"500\",\"attribute\":{\"code\":\"success\",\"data\":{\"bodyVOList\":[{\"rowno\":\"1\",\"pk_material\":\"1001P1100000000IT34Q\",\"id\":\"1001A3100000001B2UOG\"}],\"headVO\":{\"code\":\"QG2025060800000182\",\"id\":\"1001A3100000001B2UOF\",\"vtrantypeid\":\"1001P1100000000IR21W\"}},\"message\":\"提示:========NCC-请购单保存提交《成功》!!!========。单据信息:《id》 = 1001A3100000001B2UOF ,《code》 = QG2025060800000182\"}}"; JSONObject resultJson = JSONObject.parseObject(result); @@ -195,6 +266,10 @@ public class RequisitionOrderPluginServiceImpl implements IRequisitionOrderPlugi } } } + JSONObject headers =new JSONObject(); + headers.put("creator","1001P1100000000NUULI"); + RequisitionOrderPluginServiceImpl service = new RequisitionOrderPluginServiceImpl(); + service.uploadFile("-333447786976688302",headers,"8000640003","1001A3100000001B4COB"); } //保存日志 public void saveLog(String integration_task_living_details_id, Boolean flag, IntegrationTaskLivingDetailsEntity taskLivingDetail){ diff --git a/base-buildpackage/src/main/resources/cfgHome/plugin/ncc/spring/spring-buildpackage-plugin.xml b/base-buildpackage/src/main/resources/cfgHome/plugin/ncc/spring/spring-buildpackage-plugin.xml index a1c8db1a..c37cfb36 100644 --- a/base-buildpackage/src/main/resources/cfgHome/plugin/ncc/spring/spring-buildpackage-plugin.xml +++ b/base-buildpackage/src/main/resources/cfgHome/plugin/ncc/spring/spring-buildpackage-plugin.xml @@ -2,5 +2,5 @@ - +