From b81a01c055c6a99f0627b47bf733b1c209a81d5b Mon Sep 17 00:00:00 2001 From: yuxueliang0813 <407010292@qq.com> Date: Mon, 30 Sep 2024 16:56:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E5=8F=8B=E5=AE=9E=E4=BB=98=E6=AC=BE?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recon/opplugin/YongyouBIPOperation.java | 38 +++------- .../java/shkd/repc/task/YongyouBIPTask.java | 69 ++++++++++++++----- .../src/main/java/shkd/utils/DobeDWUtils.java | 16 ++++- 3 files changed, 77 insertions(+), 46 deletions(-) diff --git a/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/recon/opplugin/YongyouBIPOperation.java b/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/recon/opplugin/YongyouBIPOperation.java index 85490e0..9bb1f15 100644 --- a/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/recon/opplugin/YongyouBIPOperation.java +++ b/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/recon/opplugin/YongyouBIPOperation.java @@ -94,26 +94,26 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen DynamicObject prinfo = null; boolean isBipSuccess = false; for (int i = 0; i < dos.length; i++) { - prinfo = dos[i]; + //反审核操作之前系统未把info对象所有属性加载出来,尤其是二开的字段,需要在此处重新load一下 + prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(),dos[i].getDataEntityType().getName()); //如果bip红冲单据号为空则需要调用bip接口,否则不需要 if(!DobeDWUtils.isEmpty(prinfo.getString("qeug_yyhc"))){ 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.setCancelMessage"); - OperateErrorInfo oeInfo = new OperateErrorInfo(); - oeInfo.setMessage("推送BIP红冲数据失败,反审核中断,请排查接口失败原因"); - oeInfo.setErrorLevel(ErrorLevel.Error.name()); - oeInfo.setPkValue(prinfo.getPkValue()); - this.operationResult.addErrorInfo(oeInfo); + e.setCancelMessage("推送BIP红冲数据失败,反审核中断,请排查接口失败原因"); e.setCancel(true); } } @@ -134,7 +134,7 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen boolean isBipSuccess = false; for (int i = 0; i < dos.length; i++) { prinfo = dos[i]; - //如果bip单据号为空则需要调用bip接口,否则不需要 + //如果bip单据号为空则需要调用bip接口,否则不需要(操作之后系统会把对象的所有属性加载出来) if(!DobeDWUtils.isEmpty(prinfo.getString("qeug_yynum"))){ this.operationResult.setSuccess(false); this.operationResult.setMessage("此单已推送BIP,无需再次点击同步按钮");//前端界面提示内容 @@ -143,10 +143,10 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen } //审核时,如果用友单号已有,则不需要再推送给BIP if("recon_payreqbill".equals(prinfo.getDataEntityType().getName()) && !prinfo.getBoolean("nocontractflag")){ - //判断实体名称为合同付款申请单,此时无合同付款 nocontractflag 不需要推送 + //判断实体名称为合同付款申请单,此时无合同付款 nocontractflag 不需要推送 是否事后补单 supplementflag isBipSuccess = handleForBIP(eok,prinfo,false); }else if("recon_connotextbill".equals(prinfo.getDataEntityType().getName())){ - //无文本合同 + //无文本合同 是否事后补单 supplementflag isBipSuccess = handleForBIP(eok,prinfo,true); } if("syncbip".equals(eok)){ @@ -172,24 +172,8 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen return null; } - private String[] getCompanyDeptNumber(String bizDept){ - //根据用款部门的编号获得对应关系表中的财务公司编号和部门编号 - DynamicObject orginfo = BusinessDataServiceHelper.loadSingle("qeug_recon_orgrelation",new QFilter[]{new QFilter("number","=",bizDept)}); - String[] result = new String[3]; - if(orginfo != null){ - result[0] = orginfo.getString("qeug_companynumber");//财务公司编号 - result[1] = orginfo.getString("qeug_deptnumber");//财务部门编号 - result[2] = orginfo.getString("qeug_paynumber");//财务公司付款账户 -// result[2] = "03002635967"; - }else{ - log.error(String.format("用友付款接口根据用款部门编号转换财务编号失败:%s", bizDept)); - } - - return result; - } - private JSONObject zzPayData(String eventName, DynamicObject payrequestinfo, boolean isnotext){ - String[] companyDept = getCompanyDeptNumber(payrequestinfo.getDynamicObject("usedepart").getString("number")); + 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; diff --git a/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/task/YongyouBIPTask.java b/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/task/YongyouBIPTask.java index 13ec9fe..589ff7e 100644 --- a/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/task/YongyouBIPTask.java +++ b/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/task/YongyouBIPTask.java @@ -17,8 +17,10 @@ import kd.bos.servicehelper.operation.OperationServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; import kd.sdk.plugin.Plugin; import nccloud.open.api.auto.token.cur.utils.APICurUtils; +import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; +import okhttp3.Response; import shkd.utils.DobeDWUtils; import java.util.Map; @@ -44,12 +46,11 @@ public class YongyouBIPTask extends AbstractTask implements Plugin { // currentinfo = docs.get(i); // } - //查找无文本合同已审核未付款的单子 - //查找未审核的付款登记单,考虑费用登记和付款申请单如果是事后补单的话,此处是否需要过滤 QFilter statusFilter = new QFilter("billstatus","=","A"); - String selectStr = "id,billno,bizdate,connotextbill.id,connotextbill.billno,connotextbill.qeug_yynum,payreqbill.id,payreqbill.billno,payreqbill.qeug_yynum"; - DynamicObject[] prs = BusinessDataServiceHelper.load(payregisterEntity,selectStr,new QFilter[]{statusFilter}); + QFilter statusB = new QFilter("billstatus","=","B"); +// String selectStr = "id,billno,bizdate,billstatus,connotextbill.id,connotextbill.billno,connotextbill.qeug_yynum,payreqbill.id,payreqbill.billno,payreqbill.qeug_yynum"; + DynamicObject[] prs = BusinessDataServiceHelper.load(payregisterEntity,"id",new QFilter[]{statusFilter.or(statusB)}); if(prs.length == 0){ return; } @@ -77,36 +78,68 @@ public class YongyouBIPTask extends AbstractTask implements Plugin { log.error("用友认证接口返回的accessToken为空"); return; } - Request request = new Request.Builder().url(DobeDWUtils.payQueryUrl) - .post(createFormRequestBody(null)) - .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(); + Request request = null; JSONObject resultData = null; DynamicObject prinfo = null; DynamicObject requestinfo = null; String yynum = null; + String[] companyDept = null; + JSONObject queryParams = new JSONObject(); + OkHttpClient client = new OkHttpClient(); + Response response = null; for (int i = 0; i < prs.length; i++) { - prinfo = prs[i]; + prinfo = BusinessDataServiceHelper.loadSingle(prs[i].getPkValue(),payregisterEntity); //费用登记 requestinfo = prinfo.getDynamicObject("connotextbill"); if(requestinfo == null){ //付款申请 requestinfo = prinfo.getDynamicObject("payreqbill"); } - //看用友的实付款查询接口是一个个查询,还是集中查询 + requestinfo = BusinessDataServiceHelper.loadSingle(requestinfo.getPkValue(),requestinfo.getDataEntityType().getName()); + //看用友的实付款查询接口是一个个查询,还是集中查询;这个字段直接从F7实体对象中获取不到,需要扩展F7实体 yynum = requestinfo.getString("qeug_yynum"); - resultData = JSON.parseObject("用友接口返回值"); + //获取到的yynum为空,则不进行实付查询 + if(DobeDWUtils.isEmpty(yynum)){ + continue; + } + //根据付款申请单的用款部门找到对应财务组织编号 + companyDept = DobeDWUtils.getCompanyDeptNumber(requestinfo.getDynamicObject("usedepart").getString("number")); + if(companyDept[0] == null){ + DobeDWUtils.saveLog(requestinfo.getString("number"),"用友实付查询",requestinfo.getDynamicObject("usedepart").getString("number"),"根据用款部门编号转换财务编号失败",false,"定时任务"); + continue; + } + queryParams.put("pk_org",companyDept[0]); + queryParams.put("bill_no",yynum); + request = new Request.Builder().url(DobeDWUtils.payQueryUrl) + .post(createFormRequestBody(queryParams)) + .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(); + try { + response = client.newCall(request).execute(); + resultData = JSON.parseObject(response.body().string()); + if(!"true".equals(resultData.getString("success"))){ + //增加日志记录 + DobeDWUtils.saveLog(requestinfo.getString("number"),"用友实付查询",queryParams.toString(),resultData.toString(),false,"定时任务"); + continue; + } + } catch (Exception e) { + DobeDWUtils.saveLog(requestinfo.getString("number"),"用友实付查询",queryParams.toString(),e.getMessage(),false,"定时任务"); + continue; + } //根据查询结果设置付款登记对象 - prinfo.set("bizdate",resultData.getDate("bizdate")); - prinfo.set("billno",resultData.getString("billno")); - prinfo.set("status","B"); //单据状态改为已提交 + prinfo.set("bizdate",resultData.getJSONObject("data").getDate("billdate")); + prinfo.set("billno",yynum); + prinfo.set("billstatus","B"); //单据状态改为已提交 SaveServiceHelper.update(prinfo);//保存上述设置内容 + //调用提交方法 +// OperationServiceHelper.executeOperate("submit",payregisterEntity,new DynamicObject[]{prinfo}, OperateOption.create()); //调用付款登记单的审核方法 OperationServiceHelper.executeOperate("audit",payregisterEntity,new DynamicObject[]{prinfo}, OperateOption.create()); + DobeDWUtils.saveLog(requestinfo.getString("number"),"用友实付查询",queryParams.toString(),resultData.toString(),true,"定时任务"); } } diff --git a/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/utils/DobeDWUtils.java b/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/utils/DobeDWUtils.java index 513489c..71b13ee 100644 --- a/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/utils/DobeDWUtils.java +++ b/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/utils/DobeDWUtils.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import kd.bos.context.RequestContext; import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; import okhttp3.MediaType; @@ -38,7 +39,7 @@ public class DobeDWUtils { //用友付款单新增接口 public static final String payUrl = "http://106.14.25.83:9999/nccloud/api/arap/paybill/insertandcommit"; //付款金额查询接口 - public static final String payQueryUrl = "http://106.14.25.83:8090/nccloud/api/arap/paybill/insertandcommit"; + public static final String payQueryUrl = "http://106.14.25.83:8090/nccloud/api/sp/spPaybillQuery/querySettleStatus"; private static final String jklogEntityName = "qeug_recon_jklog"; @@ -46,6 +47,19 @@ public class DobeDWUtils { return value == null || value.trim().length() <= 0; } + public static String[] getCompanyDeptNumber(String bizDept){ + //根据用款部门的编号获得对应关系表中的财务公司编号和部门编号 + DynamicObject orginfo = BusinessDataServiceHelper.loadSingle("qeug_recon_orgrelation",new QFilter[]{new QFilter("number","=",bizDept)}); + String[] result = new String[3]; + if(orginfo != null){ + result[0] = orginfo.getString("qeug_companynumber");//财务公司编号 + result[1] = orginfo.getString("qeug_deptnumber");//财务部门编号 + result[2] = orginfo.getString("qeug_paynumber");//财务公司付款账户 +// result[2] = "03002635967"; + } + return result; + } + public static void saveLog(String billno,String jkname,String inputs,String outputs,boolean isSuccess,String operation){ //保存星瀚与第三方接口调用之间的日志记录 //参数说明:单据编号、接口名称、接口入参、接口返回值、接口执行结果是否成功、操作名称(audit、unaudit等)