请购单

This commit is contained in:
xiang2lin 2025-06-12 10:26:59 +08:00
parent 5fa3cf64aa
commit 91a768bae5
3 changed files with 146 additions and 71 deletions

View File

@ -45,9 +45,9 @@
</properties>
</profile>
<profile>
<id>zqtlocal</id> <!--曾庆拓-->
<id>jianhui</id><!-- 建辉环境打包用这个-->
<properties>
<profile.active>zqtlocal</profile.active>
<profile.active>jianhui</profile.active>
</properties>
</profile>

View File

@ -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;
@ -35,6 +44,8 @@ public class RequisitionOrderPluginServiceImpl implements IRequisitionOrderPlugi
private IIntegrationTaskLivingDetailsService taskLivingDetailsService;
@Autowired
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<JSONObject> 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);
//组装请购单报文
JSONArray reqParams = praybillVaueOf(headers, formmainData, forsonData);
String req = JSONObject.toJSONString(reqParams);
logger.info("======OA请购单传NCC请求参数:{}======",req);
String result = HttpRequest.post(baseUrl)
@ -163,12 +111,19 @@ public class RequisitionOrderPluginServiceImpl implements IRequisitionOrderPlugi
JSONObject headVO = data.getJSONObject("headVO");
if (null != headVO){
String vbillcode = headVO.getString("code");
String pk_bill = headVO.getString("id");
logger.info("======vbillcode======:{}",vbillcode);
RequisitionOrderEntity requisitionOrderEntity = new RequisitionOrderEntity();
requisitionOrderEntity.setField0059(vbillcode);
requisitionOrderEntity.setDataSourceCode(datasourceCode);
requisitionOrderEntity.setId(formmainData.getString("id"));
requisitionOrderService.updateOrder(requisitionOrderEntity);
//下载OA附件上传到NCC
try {
uploadFile(summaryId, headers, fileApiCode, pk_bill);
}catch (Exception e){
logger.error("下载OA附件上传到NCC出错:{}",e);
}
}
}
}
@ -178,6 +133,122 @@ public class RequisitionOrderPluginServiceImpl implements IRequisitionOrderPlugi
return BaseResult.getSuccessMessageEntity("请购单推NCC成功");
}
/**
* 下载OA附件上传到NCC
* @param summaryId
* @param headers
* @param fileApiCode
* @param pk_bill
*/
public void uploadFile(String summaryId, JSONObject headers, String fileApiCode, String pk_bill) {
String token = oaRestUtil.getToken(null, fileApiCode);
List<CollAttachmentResDTO> 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<JSONObject> 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){

View File

@ -2,5 +2,5 @@
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="byName">
<bean name="requisitionOrderPluginInitializer" class="com.hzya.frame.plugin.oa.praybill.plugin.RequisitionOrderPluginInitializer" />
<bean name="requisitionOrderPluginInitializer" class="com.hzya.frame.plugin.ncc.plugin.PoOrderPluginInitializer" />
<bean name="poOrderPluginInitializer" class="com.hzya.frame.plugin.ncc.plugin.PoOrderPluginInitializer" />
</beans>