用友付款接口初步调试调整
This commit is contained in:
parent
7014c3b7f0
commit
27e4729ff8
|
@ -12,19 +12,21 @@ import kd.bos.entity.plugin.PreparePropertysEventArgs;
|
|||
import kd.bos.entity.plugin.args.*;
|
||||
import kd.bos.logging.Log;
|
||||
import kd.bos.logging.LogFactory;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
import okhttp3.*;
|
||||
//import okio.ByteString;
|
||||
import shkd.utils.DobeDWUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 单据操作插件
|
||||
*/
|
||||
public class YongyouBIPOperation extends AbstractOperationServicePlugIn implements Plugin {
|
||||
private static Log log = LogFactory.getLog(YongyouBIPOperation.class);
|
||||
private static final Log log = LogFactory.getLog(YongyouBIPOperation.class);
|
||||
|
||||
// 授权模式,客户端模式为client,密码模式为:password
|
||||
private static final String grant_type = "client_credentials";
|
||||
|
@ -39,9 +41,9 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
|
|||
//公钥,加解密使用
|
||||
private static final String pubKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0IwYK6tDUauBggUzzfBed9l5gP+iYCCbqWNbH5YQ0E+L+d8Q8nSCU7iwy88z/JhRiXqZJi77h5W3dVvP5jwLISYzrNq7g/jcQIZgKhAzWt2NpcojKAUk/RkKjrAlIshDf1RVdGmfkZCgo3MZfnhSKQHCVniEY2yjgYeIrq5xiHW+Bk5cEhYHKDsZsGQ/1yp9YnWJUOInTB2cxebwW3yYeCN6y7NQczywSwSrrFgzvfo3iDgTPSzA+VXuGRfisTxxDHkcT5sM2KeWvQhgNFKPtgKOU9jrv3UA+EkxRl76VWDG7XQomez/gYGlAyc6dahYv13SrLWGdIjnBgCcovEJ5wIDAQAB";
|
||||
//认证接口地址
|
||||
private static final String tokenUrl = "http://106.14.25.83:8090/nccloud/opm/accesstoken";
|
||||
private static final String tokenUrl = "http://106.14.25.83:9999/nccloud/opm/accesstoken";
|
||||
//付款单新增接口
|
||||
private static final String payUrl = "http://106.14.25.83:8090/nccloud/api/arap/arap/paybill/insertandcommit";
|
||||
private static final String payUrl = "http://106.14.25.83:9999/nccloud/api/arap/arap/paybill/insertandcommit";
|
||||
|
||||
/**
|
||||
* 操作执行,加载单据数据包之前,触发此事件;在单据列表上执行单据操作,传入的是单据内码;
|
||||
|
@ -107,7 +109,7 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
|
|||
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
||||
super.afterExecuteOperationTransaction(e);
|
||||
//audit审核通过后,判断当前是合同付款申请单还是无文本合同
|
||||
if(!"save".equals(e.getOperationKey())){
|
||||
if("save".equals(e.getOperationKey())){
|
||||
DynamicObject[] dos = e.getDataEntities();
|
||||
DynamicObject payrequestinfo = null;
|
||||
for (int i = 0; i < dos.length; i++) {
|
||||
|
@ -141,28 +143,36 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
|
|||
|
||||
private String[] getCompanyDeptNumber(String bizDept){
|
||||
//根据用款部门的编号获得对应关系表中的财务公司编号和部门编号
|
||||
|
||||
DynamicObject orginfo = BusinessDataServiceHelper.loadSingle("qeug_recon_orgrelation",new QFilter[]{new QFilter("number","=",bizDept)});
|
||||
String[] result = new String[2];
|
||||
if(orginfo != null){
|
||||
result[0] = orginfo.getString("qeug_companynumber");//财务公司编号
|
||||
result[1] = orginfo.getString("qeug_deptnumber");//财务部门编号
|
||||
}else{
|
||||
log.error(String.format("用友付款接口根据用款部门编号转换财务编号失败:%s", bizDept));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<String, String> zzPayData(String eventName, DynamicObject payrequestinfo, boolean isnotext){
|
||||
Map<String, String> payData = new HashMap<>();
|
||||
private JSONObject zzPayData(String eventName, DynamicObject payrequestinfo, boolean isnotext){
|
||||
JSONObject payData = new JSONObject();
|
||||
String[] companyDept = getCompanyDeptNumber(payrequestinfo.getDynamicObject("usedepart").getString("number"));
|
||||
payData.put("pk_org",companyDept[0]);//财务公司组织编码,根据当前单据的用款部门获得对应关系表中的财务公司和部门
|
||||
payData.put("pk_tradetype","D3");//交易类型,传编码例:D3-采购付款单
|
||||
payData.put("billdate",DobeDWUtils.getDateString(payrequestinfo.getDate("bizdate")));//业务日期,YYYY-MM-DD
|
||||
String ap_recaccount = null;//收款银行账户编码
|
||||
//无文本合同的个人垫付时,是业务员
|
||||
boolean isgrdf = isnotext && payrequestinfo.getBoolean("grdf");
|
||||
// boolean isgrdf = isnotext && payrequestinfo.getBoolean("grdf");
|
||||
boolean isgrdf = isnotext && false;
|
||||
if(isgrdf){
|
||||
payData.put("objtype","3");//往来对象(0-客户 1-供应商 2-部门 3-业务员)
|
||||
ap_recaccount = "";
|
||||
}else{
|
||||
payData.put("objtype","0");//往来对象(0-客户 1-供应商 2-部门 3-业务员)
|
||||
ap_recaccount = "";
|
||||
ap_recaccount = payrequestinfo.getString("receiveno");
|
||||
}
|
||||
String supplierNum = payrequestinfo.getDynamicObject("supplier").getString("number");
|
||||
String supplierNum = payrequestinfo.getDynamicObject("receiveunit").getString("number");
|
||||
// payData.put("supplier",);//供应商编码 非必传
|
||||
payData.put("customer",supplierNum);//客户编码 即使是供应商也传入到该字段
|
||||
payData.put("pk_dept",companyDept[1]);//部门编码(通过公司主体明细表找部门编码)
|
||||
|
@ -174,13 +184,13 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
|
|||
|
||||
payData.put("pk_currtype","CNY");//币种,传编码CNY
|
||||
payData.put("pk_busitype","AP01");//业务流程,传编码 AP01(生产可能有变化)
|
||||
String ap_payaccount = "";//付款银行账号
|
||||
//付款银行账户编码(德必),传编码例:31001562700050031883-上海德必文化创意产业发展(集团)股份有限公司
|
||||
payData.put("ap_payaccoun","");//如何取值?-从数仓获取的组织对应关系中获取默认付款银行账号
|
||||
|
||||
payData.put("ap_payaccount",ap_payaccount);//如何取值?-从数仓获取的组织对应关系中获取默认付款银行账号
|
||||
payData.put("ap_recaccount",ap_recaccount);//收款银行账户编码(客商),传编码例:3101040160000098225-上海达洋消防保安工程有限公司
|
||||
payData.put("pk_balatype","07");//结算方式编码,传编码例:07-网银
|
||||
BigDecimal bcsqje = payrequestinfo.getBigDecimal("");//单据上的本次申请金额
|
||||
payData.put("money","");//原币金额 取含税金额
|
||||
BigDecimal bcsqje = payrequestinfo.getBigDecimal("amount");//单据上的本次申请金额
|
||||
payData.put("money",bcsqje.toString());//原币金额 取含税金额
|
||||
payData.put("rate","1.00000000");//组织本币汇率,默认1.00000000
|
||||
payData.put("local_money",bcsqje.toString());//组织本币金额 含税金额,xxxxx.00000000
|
||||
payData.put("grouprate","1.00000000");//集团本币汇率,默认1.00000000
|
||||
|
@ -188,16 +198,16 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
|
|||
payData.put("globalrate","1.00000000");//全局本币汇率 默认1.00000000
|
||||
payData.put("globallocal",bcsqje.toString());//全局本币金额 含税金额,xxxxx.00000000
|
||||
|
||||
payData.put("pu_org","");//业务组织编码 转换成对应财务的编码
|
||||
payData.put("pu_deptid","");//业务部门编码 转换成对应财务的编码
|
||||
payData.put("pu_org",companyDept[0]);//业务组织编码 转换成对应财务公司的编码
|
||||
payData.put("pu_deptid",companyDept[1]);//业务部门编码 转换成对应财务部门的编码
|
||||
// payData.put("pu_psndoc","");//业务人员编码 业务人员和制单人是否同一个?先注释
|
||||
|
||||
String creator = payrequestinfo.getDynamicObject("handler").getString("number");
|
||||
payData.put("billmaker",creator);//制单人编码 制单人工号
|
||||
payData.put("billstatus","1");//默认1 审批通过
|
||||
payData.put("approvestatus","1");//默认1 审批通过
|
||||
String auditor = payrequestinfo.getDynamicObject("auditor").getString("number");
|
||||
payData.put("approver",auditor);//审核人编码 审核人工号
|
||||
// String auditor = payrequestinfo.getDynamicObject("auditor").getString("number");
|
||||
// payData.put("approver",auditor);//审核人编码 审核人工号
|
||||
payData.put("approvedate",DobeDWUtils.getDateString(payrequestinfo.getDate("auditDate")));//审核日期 YYYY-MM-DD
|
||||
payData.put("src_syscode","kingdee");//单据来源系统编码 非必传
|
||||
if(isnotext){
|
||||
|
@ -229,30 +239,38 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
|
|||
items.put("customer",supplierNum);//客户编码 供应商的数据也传入这里
|
||||
items.put("pk_dept",companyDept[1]);//部门编码(通过公司主体明细表找部门编码)
|
||||
if(isgrdf){
|
||||
|
||||
items.put("pk_psndoc","");//业务员编码 人员工号 同表头
|
||||
}else{
|
||||
items.put("pk_psndoc","");//非个人业务 不传
|
||||
}
|
||||
items.put("pk_psndoc","");//业务员编码 人员工号 同表头
|
||||
|
||||
items.put("pk_recpaytype","001");//付款业务类型,传编码例:001-货款
|
||||
items.put("prepay","0");//付款性质(0=应付款;1=预付款;)
|
||||
items.put("pk_currtype","CNY");//币种,传编码CNY
|
||||
items.put("money_de","");//贷方原币金额 含税金额,xxxxx.00000000
|
||||
items.put("money_de",bcsqje.toString());//贷方原币金额 含税金额,xxxxx.00000000
|
||||
items.put("rate","1.00000000");//组织本币汇率,默认1.00000000
|
||||
items.put("local_money_de","");//组织本币金额 含税金额,xxxxx.00000000
|
||||
items.put("local_money_de",bcsqje.toString());//组织本币金额 含税金额,xxxxx.00000000
|
||||
items.put("grouprate","1.00000000");//集团本币汇率,默认1.00000000
|
||||
items.put("groupdebit","");//集团本币金额 含税金额,xxxxx.00000000
|
||||
items.put("groupdebit",bcsqje.toString());//集团本币金额 含税金额,xxxxx.00000000
|
||||
items.put("globalrate","1.00000000");//全局本币汇率 默认1.00000000
|
||||
items.put("globaldebit","");//全局本币金额 含税金额,xxxxx.00000000
|
||||
items.put("globaldebit",bcsqje.toString());//全局本币金额 含税金额,xxxxx.00000000
|
||||
|
||||
items.put("taxcodeid","");//税码编码 应该不用传;联调再看;
|
||||
items.put("taxrate","");//税率
|
||||
items.put("local_tax_de","");//税额
|
||||
items.put("notax_de","");//贷方无税金额,除税金额
|
||||
BigDecimal rate = payrequestinfo.getBigDecimal("taxrate");
|
||||
if(rate == null){
|
||||
items.put("taxrate","0");//税率
|
||||
items.put("local_tax_de","0");//税额
|
||||
}else{
|
||||
items.put("taxrate",rate.toString());//税率
|
||||
items.put("local_tax_de",payrequestinfo.getBigDecimal("tax").toString());//税额
|
||||
}
|
||||
items.put("notax_de",payrequestinfo.getBigDecimal("notaxamt").toString());//贷方无税金额,除税金额
|
||||
|
||||
items.put("pu_org",companyDept[0]);//业务组织编码 同表头公司编码
|
||||
items.put("pu_deptid","");//业务部门编码 费用承担部门编码,转换成财务组织编码
|
||||
items.put("pu_deptid",companyDept[1]);//业务部门编码 费用承担部门编码,转换成财务组织编码
|
||||
|
||||
items.put("pk_subjcode","");//收支项目编码 费用项目,例:660224-管理费用-服务费 会计科目(一个)
|
||||
items.put("ap_payaccount","");//付款银行账户编码 同表头
|
||||
items.put("ap_payaccount",ap_payaccount);//付款银行账户编码 同表头
|
||||
items.put("ap_recaccount",ap_recaccount);//收款银行账户编码
|
||||
items.put("pk_balatype","07");//结算方式编码,传编码例:07-网银
|
||||
|
||||
|
@ -262,7 +280,7 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
|
|||
items.put("def8","");//抵暂支金额,xxxxx.00000000?
|
||||
|
||||
jas.add(items);
|
||||
payData.put("items",jas.toJSONString());//表头关联表体
|
||||
payData.put("items",jas);//表头关联表体
|
||||
return payData;
|
||||
}
|
||||
|
||||
|
@ -286,12 +304,12 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
|
|||
log.error("用友认证接口返回的accessToken为空");
|
||||
}
|
||||
//处理合同付款申请单的审核推送用友bip,组装付款入参
|
||||
Map<String, String> payData = zzPayData(eventName,payrequestinfo,false);
|
||||
JSONObject payData = zzPayData(eventName,payrequestinfo,isnotext);
|
||||
//付款单新增接口,上一步的accesstoken作为header
|
||||
request = new Request.Builder().url(payUrl)
|
||||
.post(createFormRequestBody(payData))
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
.header("accessToken", accesstoken)
|
||||
// .header("access_Token", accesstoken)
|
||||
.build();
|
||||
String yynum = null;//用友单据编号
|
||||
try {
|
||||
|
@ -300,8 +318,9 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
|
|||
if(!"true".equals(json_reuslt.getString("success"))){
|
||||
log.error(String.format("用友付款接口处理失败,具体原因:%s", json_reuslt.getString("message")));
|
||||
//此时除了日志打印,还需要补偿机制,应该加入MQ走后续定时触发?
|
||||
}else{
|
||||
yynum = json_reuslt.getJSONObject("data").getString("billno");
|
||||
}
|
||||
yynum = json_reuslt.getJSONObject("data").getString("billno");
|
||||
} catch (Exception e) {
|
||||
log.error(String.format("用友付款接口异常:%s", e.getMessage()));
|
||||
throw new RuntimeException(e);
|
||||
|
@ -323,17 +342,9 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
|
|||
DB.update(DBRoute.of("scm"), sql, new Object[]{yyid, payrequestinfo.getLong("id")});
|
||||
}
|
||||
|
||||
private RequestBody createFormRequestBody(Map<String, String> formData) {
|
||||
FormBody.Builder builder = new FormBody.Builder();
|
||||
for (Map.Entry<String, String> entry : formData.entrySet()) {
|
||||
// if("items".equals(entry.getKey())){
|
||||
// Map<String, String> itemsData = (Map<String, String>) entry.getValue();
|
||||
// itemsData.toString();
|
||||
// }else{
|
||||
// }
|
||||
builder.add(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return builder.build();
|
||||
private RequestBody createFormRequestBody(JSONObject json_body) {
|
||||
// return RequestBody.create(ByteString.encodeUtf8(json_body.toJSONString()), DobeDWUtils.MTJSON);
|
||||
return RequestBody.create(json_body.toJSONString(), DobeDWUtils.MTJSON);
|
||||
}
|
||||
|
||||
private RequestBody createAccessTokenBody() {
|
||||
|
|
|
@ -23,6 +23,9 @@ public class DobeDWUtils {
|
|||
//创建一个SimpleDateFormat对象,定义目标日期格式
|
||||
SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
//格式化Date对象为新的字符串格式
|
||||
if(billDate == null){
|
||||
return targetFormat.format(new Date());
|
||||
}
|
||||
return targetFormat.format(billDate);
|
||||
}
|
||||
|
||||
|
@ -72,7 +75,7 @@ public class DobeDWUtils {
|
|||
}else{
|
||||
json_body.put("params",new JSONArray());
|
||||
}
|
||||
|
||||
//如下写法创建的请求只是json格式,不带charset-utf8,有些接口控制了这两者区别,故需要特别指定
|
||||
return RequestBody.create(ByteString.encodeUtf8(json_body.toJSONString()), MTJSON);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue