500 lines
28 KiB
Java
500 lines
28 KiB
Java
package shkd.repc.recon.opplugin;
|
||
|
||
import com.alibaba.fastjson.JSON;
|
||
import com.alibaba.fastjson.JSONArray;
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import kd.bos.context.RequestContext;
|
||
import kd.bos.dataentity.entity.DynamicObject;
|
||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||
import kd.bos.db.DB;
|
||
import kd.bos.db.DBRoute;
|
||
import kd.bos.entity.operate.result.OperateErrorInfo;
|
||
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||
import kd.bos.entity.plugin.PreparePropertysEventArgs;
|
||
import kd.bos.entity.plugin.args.*;
|
||
import kd.bos.entity.validate.ErrorLevel;
|
||
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 nccloud.open.api.auto.token.cur.utils.APICurUtils;
|
||
import okhttp3.*;
|
||
import shkd.utils.DobeDWUtils;
|
||
import java.math.BigDecimal;
|
||
|
||
|
||
/**
|
||
* 单据操作插件
|
||
*/
|
||
public class YongyouBIPOperation extends AbstractOperationServicePlugIn implements Plugin {
|
||
private static final Log log = LogFactory.getLog(YongyouBIPOperation.class);
|
||
|
||
/**
|
||
* 操作执行,加载单据数据包之前,触发此事件;在单据列表上执行单据操作,传入的是单据内码;
|
||
* 系统需要先根据传入的单据内码,加载单据数据包,其中只包含操作要用到的字段,然后再执行操作;
|
||
* 在加载单据数据包之前,操作引擎触发此事件;插件需要在此事件,添加需要用到的字段;
|
||
* 否则,系统加载的单据数据包,可能没有插件要用到的字段值,从而引发中断
|
||
*/
|
||
@Override
|
||
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||
super.onPreparePropertys(e);
|
||
}
|
||
|
||
/**
|
||
* 构建好操作校验器之后,执行校验之前,触发此事件;
|
||
* 插件可以在此事件,增加自定义操作校验器,或者去掉内置的校验器
|
||
*/
|
||
@Override
|
||
public void onAddValidators(AddValidatorsEventArgs e) {
|
||
super.onAddValidators(e);
|
||
}
|
||
|
||
|
||
/**
|
||
* 操作校验通过,开启了事务,准备把数据提交到数据库之前触发此事件;
|
||
* 可以在此事件,进行数据同步处理
|
||
*/
|
||
@Override
|
||
public void beginOperationTransaction(BeginOperationTransactionArgs e) {
|
||
super.beginOperationTransaction(e);
|
||
}
|
||
|
||
/**
|
||
* 单据数据已经提交到数据库之后,事务未提交之前,触发此事件;
|
||
* 可以在此事件,进行数据同步处理;
|
||
*/
|
||
@Override
|
||
public void endOperationTransaction(EndOperationTransactionArgs e) {
|
||
super.endOperationTransaction(e);
|
||
}
|
||
|
||
/**
|
||
* 操作事务提交失败,事务回滚之后触发此事件;
|
||
* 该方法在事务异常后执行,插件可以在此事件,对没有事务保护的数据更新进行补偿
|
||
*/
|
||
@Override
|
||
public void rollbackOperation(RollbackOperationArgs e) {
|
||
super.rollbackOperation(e);
|
||
}
|
||
|
||
|
||
/**
|
||
* 操作校验通过之后,开启事务之前,触发此事件;
|
||
* 插件可以在此事件,对通过校验的数据,进行整理
|
||
*/
|
||
@Override
|
||
public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
|
||
super.beforeExecuteOperationTransaction(e);
|
||
//反审核之前,调用bip接口,如果接口成功则更改标记后继续反审核业务
|
||
String eok = e.getOperationKey();
|
||
if("unaudit".equals(eok)){
|
||
DynamicObject[] dos = e.getDataEntities();
|
||
DynamicObject prinfo = null;
|
||
boolean isBipSuccess = false;
|
||
for (int i = 0; i < dos.length; i++) {
|
||
//反审核操作之前系统未把info对象所有属性加载出来,尤其是二开的字段,需要在此处重新load一下
|
||
prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(),dos[i].getDataEntityType().getName());
|
||
//如果bip红冲单据号为空则需要调用bip接口,否则不需要
|
||
if(!DobeDWUtils.isEmpty(prinfo.getString("qeug_yyhc"))){
|
||
continue;
|
||
}
|
||
//如果bip单据编号为空,则说明审核通过后未推送bip,此时不用推送bip红冲数据
|
||
if(DobeDWUtils.isEmpty(prinfo.getString("qeug_yynum"))){
|
||
continue;
|
||
}
|
||
//supplementflag 事后补单 可能不需要推送BIP,需要排除
|
||
if("recon_payreqbill".equals(prinfo.getDataEntityType().getName()) && !prinfo.getBoolean("nocontractflag")){
|
||
//判断实体名称为合同付款申请单,此时无合同付款 nocontractflag 不需要推送
|
||
isBipSuccess = handleForBIP(eok,prinfo,false);
|
||
}else if("recon_connotextbill".equals(prinfo.getDataEntityType().getName())){
|
||
//无文本合同
|
||
isBipSuccess = handleForBIP(eok,prinfo,true);
|
||
}else {
|
||
//由无文本合同生成的付款申请单走这里
|
||
isBipSuccess = true;
|
||
}
|
||
//如果bip接口失败,记录日志,并中断原有反审核业务
|
||
if(!isBipSuccess){
|
||
e.setCancelMessage("推送BIP红冲数据失败,反审核中断,请排查接口失败原因");
|
||
e.setCancel(true);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* 操作执行完毕,事务提交之后,触发此事件;
|
||
* 插件可以在此事件,处理操作后续事情,与操作事务无关
|
||
*/
|
||
@Override
|
||
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
||
super.afterExecuteOperationTransaction(e);
|
||
//audit审核 syncbip手动同步 两种情况进入如下代码
|
||
String eok = e.getOperationKey();
|
||
if("audit".equals(eok) || "syncbip".equals(eok)){
|
||
DynamicObject[] dos = e.getDataEntities();
|
||
DynamicObject prinfo = null;
|
||
boolean isBipSuccess = false;
|
||
for (int i = 0; i < dos.length; i++) {
|
||
prinfo = dos[i];
|
||
if("audit".equals(eok)){
|
||
prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(),dos[i].getDataEntityType().getName());
|
||
}
|
||
//如果bip单据号为空则需要调用bip接口,否则不需要(操作之后系统会把对象的所有属性加载出来)
|
||
if(!DobeDWUtils.isEmpty(prinfo.getString("qeug_yynum"))){
|
||
this.operationResult.setSuccess(false);
|
||
this.operationResult.setMessage("此单已推送BIP,无需再次点击同步按钮");//前端界面提示内容
|
||
this.operationResult.setShowMessage(true);//前端界面 是否显示提示消息
|
||
continue;
|
||
}
|
||
//审核时,如果用友单号已有,则不需要再推送给BIP
|
||
if("recon_payreqbill".equals(prinfo.getDataEntityType().getName()) && !prinfo.getBoolean("nocontractflag")){
|
||
//判断实体名称为合同付款申请单,此时无合同付款 nocontractflag 不需要推送 是否事后补单 supplementflag
|
||
isBipSuccess = handleForBIP(eok,prinfo,false);
|
||
}else if("recon_connotextbill".equals(prinfo.getDataEntityType().getName())){
|
||
//如果此时在费用登记单的列表界面点击审核按钮的话,二开的grdf字段会识别不到
|
||
//无文本合同 是否事后补单 supplementflag
|
||
isBipSuccess = handleForBIP(eok,prinfo,true);
|
||
}
|
||
if("syncbip".equals(eok)){
|
||
if(isBipSuccess){
|
||
this.operationResult.addSuccessPkId(prinfo.getPkValue());
|
||
}else{
|
||
this.operationResult.setSuccess(false);
|
||
this.operationResult.setMessage("推送BIP接口失败,请排查失败原因");// 提示内容
|
||
this.operationResult.setShowMessage(true);// 是否显示提示消息
|
||
}
|
||
}
|
||
// payrequestinfo.getDynamicObjectType().getAlias();//获取数据库表名
|
||
}
|
||
}
|
||
}
|
||
|
||
private String getInvoiceNumber(DynamicObject payrequestinfo, boolean isnotext){
|
||
if(isnotext){
|
||
//无文本合同,拼接对应发票编号
|
||
}else{
|
||
//合同付款申请单,拼接对应发票编号
|
||
}
|
||
return null;
|
||
}
|
||
|
||
private JSONObject zzPayData(String eventName, DynamicObject payrequestinfo, boolean isnotext){
|
||
String[] companyDept = DobeDWUtils.getCompanyDeptNumber(payrequestinfo.getDynamicObject("usedepart").getString("number"));
|
||
if(companyDept[0] == null){
|
||
DobeDWUtils.saveLog(payrequestinfo.getString("billno"),"用友BIP",payrequestinfo.getDynamicObject("usedepart").getString("number"),"根据用款部门编号转换财务编号失败",false,eventName);
|
||
return null;
|
||
}
|
||
JSONObject payData = new JSONObject();
|
||
payData.put("pk_org",companyDept[0]);//财务公司组织编码,根据当前单据的用款部门获得对应关系表中的财务公司和部门
|
||
payData.put("pk_tradetype","F3-Cxx-03");//交易类型编码,传编码例:D3-采购付款单
|
||
payData.put("billdate",DobeDWUtils.getDateString(payrequestinfo.getDate("auditDate")));//业务日期,YYYY-MM-DD
|
||
String ap_recaccount = null;//收款银行账户编码
|
||
//无文本合同的个人垫付时,是业务员
|
||
boolean isgrdf = isnotext && payrequestinfo.getBoolean("qeug_grdf");
|
||
if(isgrdf){
|
||
payData.put("objtype","3");//往来对象(0-客户 1-供应商 2-部门 3-业务员)
|
||
ap_recaccount = payrequestinfo.getDynamicObject("qeug_personbank").getString("qeug_banknumber");
|
||
payData.put("pk_psndoc",payrequestinfo.getDynamicObject("qeug_personbank").getString("number"));//业务员编码 人员工号 个人业务的时候,3-业务员 必传
|
||
}else{
|
||
payData.put("objtype","0");//往来对象(0-客户 1-供应商 2-部门 3-业务员)
|
||
ap_recaccount = payrequestinfo.getString("receiveno");
|
||
payData.put("pk_psndoc","");//非个人业务 不传
|
||
}
|
||
String supplierNum = payrequestinfo.getDynamicObject("receiveunit").getString("number");
|
||
long supplierid = payrequestinfo.getDynamicObject("receiveunit").getLong("id");
|
||
payData.put("customer",supplierNum);//客户编码 即使是供应商也传入到该字段
|
||
payData.put("pk_dept",companyDept[1]);//部门编码(通过公司主体明细表找部门编码)
|
||
|
||
payData.put("pk_currtype","CNY");//币种,传编码CNY
|
||
payData.put("pk_busitype","AP04");//业务流程,传编码 AP01(生产可能有变化)
|
||
String ap_payaccount = companyDept[2];//付款银行账号
|
||
//付款银行账户编码(德必),传编码例:31001562700050031883-上海德必文化创意产业发展(集团)股份有限公司
|
||
payData.put("ap_payaccount",ap_payaccount);//如何取值?-从数仓获取的组织对应关系中获取默认付款银行账号
|
||
payData.put("ap_recaccount",ap_recaccount);//收款银行账户编码(客商),传编码例:3101040160000098225-上海达洋消防保安工程有限公司
|
||
payData.put("pk_balatype","07");//结算方式编码,传编码例:07-网银
|
||
BigDecimal bcsqje = payrequestinfo.getBigDecimal("amount");//费用登记单据上的本次申请金额
|
||
if(!isnotext){
|
||
bcsqje = payrequestinfo.getBigDecimal("curactualamt");//付款申请单的本期应付金额 curactualamt
|
||
}
|
||
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
|
||
payData.put("grouplocal",bcsqje.toString());//集团本币金额 含税金额,xxxxx.00000000
|
||
payData.put("globalrate","1.00000000");//全局本币汇率 默认1.00000000
|
||
payData.put("globallocal",bcsqje.toString());//全局本币金额 含税金额,xxxxx.00000000
|
||
if("unaudit".equals(eventName)){
|
||
//如果此时是反审核,则需要将金额置为负数
|
||
payData.put("money","-"+bcsqje.toString());
|
||
payData.put("local_money","-"+bcsqje.toString());
|
||
payData.put("grouplocal","-"+bcsqje.toString());
|
||
payData.put("globallocal","-"+bcsqje.toString());
|
||
}
|
||
|
||
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",DobeDWUtils.clientid);//制单人编码 固定传ISC
|
||
payData.put("billstatus","1");//默认1 审批通过
|
||
payData.put("approvestatus","1");//默认1 审批通过
|
||
// String auditor = payrequestinfo.getDynamicObject("auditor").getString("number");
|
||
// payData.put("approver",auditor);//审核人编码 审核人工号
|
||
payData.put("approver",DobeDWUtils.clientid);//审核人编码 固定传ISC
|
||
payData.put("approvedate",DobeDWUtils.getDateString(null));//审核日期 接口推送的日期
|
||
// payData.put("src_syscode","ISC");//单据来源系统编码 非必传
|
||
if(isnotext){
|
||
payData.put("def11","无合同付款");//自定义项11 流程类型:有合同 无合同
|
||
}else{
|
||
payData.put("def11","合同付款");//自定义项11 流程类型:有合同 无合同
|
||
}
|
||
payData.put("def12",payrequestinfo.getString("billno"));//自定义项12 付款申请单的单号(全局唯一才行)
|
||
payData.put("def13",payrequestinfo.getString("description"));//备注。传合同总金额及付款比例等,拼接凭证摘要
|
||
|
||
//------------------以下是表体组装--------------------
|
||
JSONArray jas = new JSONArray();
|
||
JSONObject items = new JSONObject();
|
||
// items.put("contractno",payrequestinfo.getDynamicObject("contractbill"));//合同号
|
||
items.put("scomment",payrequestinfo.getString("qeug_xf"));//摘要 按照现在NC57逻辑先来,涉及银企互联支付,原来是15个字符(7个中文)的样子
|
||
|
||
if(isgrdf){
|
||
items.put("objtype","3");//往来对象(0-客户 1-供应商 2-部门 3-业务员)
|
||
items.put("pk_psndoc",payrequestinfo.getDynamicObject("qeug_personbank").getString("number"));//业务员编码 人员工号 同表头
|
||
}else{
|
||
items.put("objtype","0");//往来对象(0-客户 1-供应商 2-部门 3-业务员)
|
||
items.put("pk_psndoc","");//非个人业务 不传
|
||
}
|
||
items.put("customer",supplierNum);//客户编码 供应商的数据也传入这里
|
||
items.put("pk_dept",companyDept[1]);//部门编码(通过公司主体明细表找部门编码)
|
||
|
||
items.put("pk_recpaytype","货款");//付款业务类型,传编码例:001-货款
|
||
items.put("prepay","0");//付款性质(0=应付款;1=预付款;)
|
||
items.put("pk_currtype","CNY");//币种,传编码CNY
|
||
items.put("money_de",bcsqje.toString());//贷方原币金额 含税金额,xxxxx.00000000
|
||
items.put("rate","1.00000000");//组织本币汇率,默认1.00000000
|
||
items.put("local_money_de",bcsqje.toString());//组织本币金额 含税金额,xxxxx.00000000
|
||
items.put("grouprate","1.00000000");//集团本币汇率,默认1.00000000
|
||
items.put("groupdebit",bcsqje.toString());//集团本币金额 含税金额,xxxxx.00000000
|
||
items.put("globalrate","1.00000000");//全局本币汇率 默认1.00000000
|
||
items.put("globaldebit",bcsqje.toString());//全局本币金额 含税金额,xxxxx.00000000
|
||
if("unaudit".equals(eventName)){
|
||
//如果此时是反审核,则需要将金额置为负数
|
||
items.put("money_de","-"+bcsqje.toString());
|
||
items.put("local_money_de","-"+bcsqje.toString());
|
||
items.put("groupdebit","-"+bcsqje.toString());
|
||
items.put("globaldebit","-"+bcsqje.toString());
|
||
}
|
||
|
||
items.put("taxcodeid","");//税码编码 应该不用传;联调再看;
|
||
if(isnotext){
|
||
//费用登记单的处理方式
|
||
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());//贷方无税金额,除税金额
|
||
if("unaudit".equals(eventName)){
|
||
//如果此时是反审核,则需要将金额置为负数
|
||
items.put("local_tax_de","-"+items.getString("local_tax_de"));
|
||
items.put("notax_de","-"+items.getString("notax_de"));
|
||
}
|
||
}else{
|
||
//付款申请单的处理方式
|
||
BigDecimal invoicetax = payrequestinfo.getBigDecimal("invoicetax");//发票的税额
|
||
if(invoicetax == null || invoicetax.compareTo(BigDecimal.ZERO) == 0){
|
||
items.put("taxrate","0");//税率
|
||
items.put("local_tax_de","0");//税额
|
||
items.put("notax_de",bcsqje.toString());//贷方无税金额,除税金额
|
||
if("unaudit".equals(eventName)){
|
||
//如果此时是反审核,则需要将金额置为负数
|
||
items.put("notax_de","-"+bcsqje.toString());
|
||
}
|
||
}else{
|
||
items.put("taxrate",invoicetax.divide(bcsqje.subtract(invoicetax)).multiply(BigDecimal.valueOf(100)));//税率=税额/不含税 * 100
|
||
items.put("local_tax_de",invoicetax.toString());//税额
|
||
items.put("notax_de",bcsqje.subtract(invoicetax).toString());//贷方无税金额,除税金额
|
||
if("unaudit".equals(eventName)){
|
||
//如果此时是反审核,则需要将金额置为负数
|
||
items.put("local_tax_de","-"+items.getString("local_tax_de"));
|
||
items.put("notax_de","-"+items.getString("notax_de"));
|
||
}
|
||
}
|
||
}
|
||
|
||
items.put("pu_org",companyDept[0]);//业务组织编码 同表头公司编码
|
||
// items.put("pu_deptid",companyDept[1]);//业务部门编码 费用承担部门编码,转换成财务组织编码
|
||
//外部公司:22020104\应付账款\往来单位\外部单位(工程类)
|
||
//集团内部关联公司:22020105\应付账款\往来单位\内部单位(关联方)
|
||
//如果费用登记中用户选择了会计科目,则使用该字段编号,否则还使用集团内外 yxl 20241116
|
||
if(isnotext && payrequestinfo.getDynamicObject("qeug_accountview")!=null){
|
||
items.put("pk_subjcode",payrequestinfo.getDynamicObject("qeug_accountview").getString("number"));
|
||
}else{
|
||
String suptype = getSupplierType(supplierid);
|
||
if("DB01".equals(suptype)){
|
||
items.put("pk_subjcode","22020105");//集团内
|
||
}else{
|
||
items.put("pk_subjcode","22020104");//收支项目编码 费用项目,例:660224-管理费用-服务费 会计科目(一个)
|
||
}
|
||
}
|
||
|
||
items.put("ap_payaccount",ap_payaccount);//付款银行账户编码 同表头
|
||
items.put("ap_recaccount",ap_recaccount);//收款银行账户编码
|
||
items.put("pk_balatype","07");//结算方式编码,传编码例:07-网银
|
||
if(isnotext){
|
||
items.put("def13","");//供应链系统合同号,无合同怎么传递?
|
||
}else{
|
||
items.put("def13",payrequestinfo.getDynamicObject("contractbill").getString("number"));//供应链系统合同号
|
||
}
|
||
items.put("def14",payrequestinfo.getString("id"));//供应链付款单ID
|
||
jas.add(items);
|
||
payData.put("items",jas);//表头关联表体
|
||
return payData;
|
||
}
|
||
|
||
private boolean handleForBIP(String eventName, DynamicObject payrequestinfo, boolean isnotext){
|
||
String accesstoken = null;
|
||
APICurUtils apiutil = new APICurUtils();//处理认证接口的工具类(用友提供的第三方工具),得到accesstoken
|
||
apiutil.init(DobeDWUtils.yyip,DobeDWUtils.yyport,DobeDWUtils.bizcenter,DobeDWUtils.clientid,DobeDWUtils.clientsecret,DobeDWUtils.pubKey,DobeDWUtils.clientid,null);
|
||
try {
|
||
String tokenresult = apiutil.getTokenByClient();
|
||
if(DobeDWUtils.isEmpty(tokenresult)){
|
||
log.error("用友认证接口返回的accessToken为空");
|
||
return false;
|
||
}
|
||
JSONObject json_reuslt = JSON.parseObject(tokenresult);
|
||
if(json_reuslt.getJSONObject("data") == null){
|
||
log.error("用友认证接口返回的data为空");
|
||
return false;
|
||
}
|
||
accesstoken = json_reuslt.getJSONObject("data").getString("access_token");
|
||
} catch (Exception e) {
|
||
log.error(String.format("用友认证接口异常:%s", e.getMessage()));
|
||
throw new RuntimeException(e);
|
||
}
|
||
if(DobeDWUtils.isEmpty(accesstoken)){
|
||
log.error("用友认证接口返回的accessToken为空");
|
||
return false;
|
||
}
|
||
|
||
//处理合同付款申请单的审核推送用友bip,组装付款入参
|
||
JSONObject payData = zzPayData(eventName,payrequestinfo,isnotext);
|
||
if(payData == null){
|
||
return false;
|
||
}
|
||
OkHttpClient client = new OkHttpClient();
|
||
//付款单新增接口,上一步的accesstoken作为header
|
||
Request request = new Request.Builder().url(DobeDWUtils.payUrl)
|
||
.post(createFormRequestBody(payData))
|
||
.header("Content-Type", "application/json;charset=utf-8")
|
||
.header("access_token", accesstoken)
|
||
.header("repeat_check", "Y")
|
||
.header("ucg_flag", "Y")
|
||
.header("client_id", DobeDWUtils.clientid)
|
||
.build();
|
||
String yynum = null;//用友单据编号
|
||
String yyid = null;//用友单据id
|
||
JSONObject json_reuslt = null;
|
||
try {
|
||
Response response = client.newCall(request).execute();
|
||
json_reuslt = JSON.parseObject(response.body().string());
|
||
if(!"true".equals(json_reuslt.getString("success"))){
|
||
log.error(String.format("用友付款接口处理失败,具体原因:%s", json_reuslt.toString()));
|
||
//此时除了日志打印,增加日志记录
|
||
DobeDWUtils.saveLog(payrequestinfo.getString("billno"),"用友BIP",payData.toString(),json_reuslt.toString(),false,eventName);
|
||
return false;
|
||
}else{
|
||
yynum = json_reuslt.getJSONObject("data").getString("billno");
|
||
yyid = json_reuslt.getJSONObject("data").getString("pk_bill");
|
||
}
|
||
} catch (Exception e) {
|
||
log.error(String.format("用友付款接口异常:%s", e.getMessage()));
|
||
// throw new RuntimeException(e);
|
||
DobeDWUtils.saveLog(payrequestinfo.getString("billno"),"用友BIP",payData.toString(),e.getMessage(),false,eventName);
|
||
return false;
|
||
}
|
||
if(DobeDWUtils.isEmpty(yynum)){
|
||
log.error("用友付款接口返回的billno为空");
|
||
DobeDWUtils.saveLog(payrequestinfo.getString("billno"),"用友BIP",payData.toString(),"用友billno为空"+json_reuslt.toString(),false,eventName);
|
||
return false;
|
||
}else{
|
||
//审核推送用友bip成功后,反写费用登记和合同付款申请单的用友付款单编号和id字段值,并清空红冲单据编号字段
|
||
String sql = "UPDATE t_recon_payreqbill SET fk_qeug_yynum=?,fk_qeug_yyhc=?,fk_qeug_yyid=? WHERE fid=?;";
|
||
if(isnotext){
|
||
sql = "UPDATE t_recon_connotextbill SET fk_qeug_yynum=?,fk_qeug_yyhc=?,fk_qeug_yyid=? WHERE fid=?;";
|
||
}
|
||
if("unaudit".equals(eventName)){
|
||
//如果是反审核推送bip成功后,反写红冲单据编号字段,并清空bip单据编号和id
|
||
sql = "UPDATE t_recon_payreqbill SET fk_qeug_yyhc=?,fk_qeug_yynum=?,fk_qeug_yyid=? WHERE fid=?;";
|
||
if(isnotext){
|
||
sql = "UPDATE t_recon_connotextbill SET fk_qeug_yyhc=?,fk_qeug_yynum=?,fk_qeug_yyid=? WHERE fid=?;";
|
||
}
|
||
yyid = "";
|
||
}
|
||
DB.update(DBRoute.of("scm"), sql, new Object[]{yynum,"",yyid,payrequestinfo.getLong("id")});
|
||
DobeDWUtils.saveLog(payrequestinfo.getString("billno"),"用友BIP",payData.toString(),json_reuslt.toString(),true,eventName);
|
||
return true;
|
||
}
|
||
}
|
||
|
||
private String getSupplierType(long supplierid){
|
||
//根据供应商id从供应商F7中得到供应商的分类标准
|
||
DynamicObject supinfo = BusinessDataServiceHelper.loadSingle("resm_supplier_f7",new QFilter[]{new QFilter("id","=",supplierid)});
|
||
DynamicObjectCollection orgcolls = supinfo.getDynamicObjectCollection("entry_org");//供应商所属组织,只查找集团的
|
||
DynamicObject orginfo = null;
|
||
DynamicObjectCollection typecolls = null;//供应商所属组织下的供应商分类分录
|
||
DynamicObject typeinfo = null;
|
||
String supTypeStr = null;
|
||
for (int i = 0; i < orgcolls.size(); i++) {
|
||
orginfo = orgcolls.get(i);
|
||
if(orginfo.getDynamicObject("belongorg") != null && "dobe".equalsIgnoreCase(orginfo.getDynamicObject("belongorg").getString("number"))){
|
||
typecolls = orginfo.getDynamicObjectCollection("entry_org_group");//供应商所属组织下的供应商分类分录
|
||
for (int j = 0; j < typecolls.size(); j++) {
|
||
typeinfo = typecolls.get(j);
|
||
if(typeinfo.getDynamicObject("suppliergroup") != null){
|
||
supTypeStr = typeinfo.getDynamicObject("suppliergroup").getString("number");
|
||
if("DB01".equals(supTypeStr) || "DB02".equals(supTypeStr)){
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if(supTypeStr == null){
|
||
supTypeStr = "DB02";//如果上述未找到对应分类,则默认算集团外
|
||
}
|
||
return supTypeStr;
|
||
}
|
||
|
||
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() {
|
||
FormBody.Builder builder = new FormBody.Builder();
|
||
//如下写法在接口调用后,用友反馈解密失败,猜测是没有给RequestBody使用指定的MediaType 以及 没有使用json格式进行RequestBody设置
|
||
// try {
|
||
// String token = apiutil.getTokenByClient();
|
||
// String enptSecret = URLEncoder.encode(Encryption.pubEncrypt(pubKey,client_secret),"UTF-8");
|
||
// builder.add("grant_type", grant_type)
|
||
// .add("client_id", client_id)
|
||
// .add("client_secret", enptSecret)
|
||
// .add("biz_center", biz_center)
|
||
// .add("usercode", client_id)
|
||
// .add("groupcode", biz_center)
|
||
// .add("signature", SHA256Util.getSHA256(client_id+client_secret+pubKey,pubKey));
|
||
// } catch (Exception e) {
|
||
// throw new RuntimeException(e);
|
||
// }
|
||
return builder.build();
|
||
}
|
||
|
||
} |