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 7833051..85490e0 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 @@ -3,14 +3,17 @@ 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; @@ -48,14 +51,6 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen super.onAddValidators(e); } - /** - * 操作校验通过之后,开启事务之前,触发此事件; - * 插件可以在此事件,对通过校验的数据,进行整理 - */ - @Override - public void beforeExecuteOperationTransaction(BeforeOperationArgs e) { - super.beforeExecuteOperationTransaction(e); - } /** * 操作校验通过,开启了事务,准备把数据提交到数据库之前触发此事件; @@ -84,6 +79,46 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen 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++) { + prinfo = dos[i]; + //如果bip红冲单据号为空则需要调用bip接口,否则不需要 + if(!DobeDWUtils.isEmpty(prinfo.getString("qeug_yyhc"))){ + continue; + } + 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); + } + //如果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.setCancel(true); + } + } + } + } /** * 操作执行完毕,事务提交之后,触发此事件; * 插件可以在此事件,处理操作后续事情,与操作事务无关 @@ -91,25 +126,41 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen @Override public void afterExecuteOperationTransaction(AfterOperationArgs e) { super.afterExecuteOperationTransaction(e); - //audit审核 unaudit反审核 syncbip手动同步 三种情况进入如下代码 + //audit审核 syncbip手动同步 两种情况进入如下代码 String eok = e.getOperationKey(); - if("audit".equals(eok) || "unaudit".equals(eok) || "syncbip".equals(eok)){ + 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]; + //如果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 不需要推送 - handleForBIP(eok,prinfo,false); + isBipSuccess = handleForBIP(eok,prinfo,false); }else if("recon_connotextbill".equals(prinfo.getDataEntityType().getName())){ //无文本合同 - handleForBIP(eok,prinfo,true); + 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();//获取数据库表名 } } - //unaudit } private String getInvoiceNumber(DynamicObject payrequestinfo, boolean isnotext){ @@ -128,8 +179,8 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen if(orginfo != null){ result[0] = orginfo.getString("qeug_companynumber");//财务公司编号 result[1] = orginfo.getString("qeug_deptnumber");//财务部门编号 -// result[2] = orginfo.getString("qeug_deptnumber");//财务公司付款账户 - result[2] = "03002635967"; + result[2] = orginfo.getString("qeug_paynumber");//财务公司付款账户 +// result[2] = "03002635967"; }else{ log.error(String.format("用友付款接口根据用款部门编号转换财务编号失败:%s", bizDept)); } @@ -138,8 +189,12 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen } private JSONObject zzPayData(String eventName, DynamicObject payrequestinfo, boolean isnotext){ - JSONObject payData = new JSONObject(); String[] companyDept = 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 @@ -178,6 +233,13 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen 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]);//业务部门编码 转换成对应财务部门的编码 @@ -226,6 +288,13 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen 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){ @@ -246,10 +315,19 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen 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("taxrate","-"+items.getString("taxrate")); + items.put("notax_de","-"+items.getString("notax_de")); + } } } @@ -269,7 +347,7 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen if(isnotext){ items.put("def13","");//供应链系统合同号,无合同怎么传递? }else{ - items.put("def13",payrequestinfo.getDynamicObject("contractbill").getString("billno"));//供应链系统合同号 + items.put("def13",payrequestinfo.getDynamicObject("contractbill").getString("number"));//供应链系统合同号 } items.put("def14",payrequestinfo.getString("id"));//供应链付款单ID jas.add(items); @@ -277,7 +355,7 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen return payData; } - private void handleForBIP(String eventName, DynamicObject payrequestinfo, boolean isnotext){ + 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); @@ -285,12 +363,12 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen String tokenresult = apiutil.getTokenByClient(); if(DobeDWUtils.isEmpty(tokenresult)){ log.error("用友认证接口返回的accessToken为空"); - return; + return false; } JSONObject json_reuslt = JSON.parseObject(tokenresult); if(json_reuslt.getJSONObject("data") == null){ log.error("用友认证接口返回的data为空"); - return; + return false; } accesstoken = json_reuslt.getJSONObject("data").getString("access_token"); } catch (Exception e) { @@ -299,11 +377,14 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen } if(DobeDWUtils.isEmpty(accesstoken)){ log.error("用友认证接口返回的accessToken为空"); - return; + 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) @@ -323,7 +404,7 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen log.error(String.format("用友付款接口处理失败,具体原因:%s", json_reuslt.toString())); //此时除了日志打印,增加日志记录 DobeDWUtils.saveLog(payrequestinfo.getString("billno"),"用友BIP",payData.toString(),json_reuslt.toString(),false,eventName); - return; + return false; }else{ yynum = json_reuslt.getJSONObject("data").getString("billno"); } @@ -331,18 +412,28 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen 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=? WHERE fid=?;"; + //审核推送用友bip成功后,反写费用登记和合同付款申请单的用友付款单id字段值,并清空红冲单据编号字段 + String sql = "UPDATE t_recon_payreqbill SET fk_qeug_yynum=?,fk_qeug_yyhc=? WHERE fid=?;"; if(isnotext){ - sql = "UPDATE t_recon_connotextbill SET fk_qeug_yynum=? WHERE fid=?;"; + sql = "UPDATE t_recon_connotextbill SET fk_qeug_yynum=?,fk_qeug_yyhc=? WHERE fid=?;"; } - DB.update(DBRoute.of("scm"), sql, new Object[]{yynum, payrequestinfo.getLong("id")}); + if("unaudit".equals(eventName)){ + //如果是反审核推送bip成功后,反写红冲单据编号字段,并清空bip单据编号 + sql = "UPDATE t_recon_payreqbill SET fk_qeug_yyhc=?,fk_qeug_yynum=? WHERE fid=?;"; + if(isnotext){ + sql = "UPDATE t_recon_connotextbill SET fk_qeug_yyhc=?,fk_qeug_yynum=? WHERE fid=?;"; + } + } + DB.update(DBRoute.of("scm"), sql, new Object[]{yynum,"",payrequestinfo.getLong("id")}); DobeDWUtils.saveLog(payrequestinfo.getString("billno"),"用友BIP",payData.toString(),json_reuslt.toString(),true,eventName); + return true; } } diff --git a/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/task/DobeDWorgRelationTask.java b/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/task/DobeDWorgRelationTask.java index c19a49c..155e5be 100644 --- a/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/task/DobeDWorgRelationTask.java +++ b/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/task/DobeDWorgRelationTask.java @@ -27,8 +27,8 @@ import java.util.Map; public class DobeDWorgRelationTask extends AbstractTask implements Plugin { private static Log log = LogFactory.getLog(DobeDWorgRelationTask.class); - private static final String entityName = "qeug_recon_orgrelation";//供应链库 表名 - private static final String dw_menthod = ""; + private static final String entityName = "qeug_recon_orgrelation";//供应链库 表名 tk_qeug_recon_orgrelation + private static final String dw_menthod = "mdm_orgcorp"; @Override public void execute(RequestContext requestContext, Map map) throws KDException { @@ -43,8 +43,9 @@ public class DobeDWorgRelationTask extends AbstractTask implements Plugin { .build(); String resultData = null; + Response response = null; try { - Response response = client.newCall(request).execute(); + response = client.newCall(request).execute(); resultData = response.body().string(); log.info("组织对应关系接口返回结果:\n{}", resultData); } catch (IOException e) { @@ -54,7 +55,30 @@ public class DobeDWorgRelationTask extends AbstractTask implements Plugin { JSONObject json_body = JSON.parseObject(resultData); //接口返回的数据进行了分页 int totalNum = json_body.getIntValue("totalNum");//分页-SQL查询总数据量 + handleOrgRelation(json_body); + int queryCount = DobeDWUtils.getQueryCount(totalNum); + if(queryCount > 1){ + //查询次数不止一次,需要分页查询 + for (int i = 2; i <= queryCount; i++) { + request = new Request.Builder().url(DobeDWUtils.dwUrl+dw_menthod) + .post(DobeDWUtils.createRequestBody("",i)) + .header("Content-Type", "application/json") + .header("Authorization", DobeDWUtils.appCode) + .build(); + try { + response = client.newCall(request).execute(); + resultData = response.body().string(); + } catch (IOException e) { + log.info(String.format("组织对应关系接口异常:%s", e.getMessage())); + throw new RuntimeException(e); + } + json_body = JSON.parseObject(resultData); + handleOrgRelation(json_body); + } + } + } + private void handleOrgRelation(JSONObject json_body) { //解析接口返回值,与系统数据比较 JSONArray detailsJson = json_body.getJSONArray("data"); DynamicObject orginfo = null; @@ -64,28 +88,37 @@ public class DobeDWorgRelationTask extends AbstractTask implements Plugin { String companyName = null; String deptNumber = null; String deptName = null; + String paybank = null; + String paynumber = null; + String taxno = null; for (int i = 0; i < detailsJson.size(); i++) { json_body = detailsJson.getJSONObject(i); - orgNumber = json_body.getString("orgNumber"); - orgName = json_body.getString("orgName"); - companyNumber = json_body.getString("companyNumber"); - companyName = json_body.getString("companyName"); - deptNumber = json_body.getString("deptNumber"); - deptName = json_body.getString("deptName"); - if(DobeDWUtils.isEmpty(orgNumber) || DobeDWUtils.isEmpty(companyNumber) || DobeDWUtils.isEmpty(deptNumber)){ + orgNumber = json_body.getString("oaorg_code");//oa组织code + orgName = json_body.getString("oaorg_name");//oa组织名称 + companyNumber = json_body.getString("corp_code");//财务公司编号 + companyName = json_body.getString("corp_name");//财务公司名称 + deptNumber = json_body.getString("corpdep_code");//财务公司部门编号 + deptName = json_body.getString("corpdep_name");//财务公司部门名称 + paybank = json_body.getString("corp_bank");//财务公司银行 + paynumber = json_body.getString("corp_bankaccount");//财务公司银行账户 + taxno = json_body.getString("corp_tax");//财务公司税号 + if(DobeDWUtils.isEmpty(orgNumber) || DobeDWUtils.isEmpty(companyNumber) || DobeDWUtils.isEmpty(deptNumber) || DobeDWUtils.isEmpty(paynumber)){ log.info(String.format("组织对应关系接口入参为空异常:%s", json_body.toJSONString())); continue; } //根据组织编号查找系统现有数据是否存在 "id,number,name,qeug_companynumber,qeug_companyname,qeug_deptnumber,qeug_deptname", orginfo = BusinessDataServiceHelper.loadSingle(entityName,new QFilter[]{new QFilter("number","=",orgNumber)}); - if(orginfo != null){ + if(orginfo != null && isNeedUpdate(orginfo,companyNumber,deptNumber,paynumber,taxno)){ //QueryServiceHelper.queryOne查出来的对象不是DynamicObject 而是平铺对象plainobject 此对象不能在后续代码中进行修改和更新; orginfo.set("name", orgName); orginfo.set("qeug_companynumber", companyNumber); orginfo.set("qeug_companyname", companyName); orginfo.set("qeug_deptnumber", deptNumber); orginfo.set("qeug_deptname", deptName); + orginfo.set("qeug_paybank", paybank); + orginfo.set("qeug_paynumber", paynumber); + orginfo.set("qeug_taxno", taxno); SaveServiceHelper.update(orginfo); }else{ //不存在,做新增 根据实体名称创建动态对象 @@ -96,11 +129,30 @@ public class DobeDWorgRelationTask extends AbstractTask implements Plugin { orginfo.set("qeug_companyname", companyName); orginfo.set("qeug_deptnumber", deptNumber); orginfo.set("qeug_deptname", deptName); + orginfo.set("qeug_paybank", paybank); + orginfo.set("qeug_paynumber", paynumber); + orginfo.set("qeug_taxno", taxno); orginfo.set("enable", 1); - orginfo.set("creator", 1L);//创建人默认指定为超管 + orginfo.set("creator", 43007523L);//创建人默认指定为金小蝶 //保存数据:直接保存入库,不走操作校验 SaveServiceHelper.save(new DynamicObject[]{orginfo}); } } } + + private boolean isNeedUpdate(DynamicObject orginfo,String companyNumber,String deptNumber,String paynumber,String taxno){ + if(!companyNumber.equals(orginfo.getString("qeug_companynumber"))){ + return true; + } + if(!deptNumber.equals(orginfo.getString("qeug_deptnumber"))){ + return true; + } + if(!paynumber.equals(orginfo.getString("qeug_paynumber"))){ + return true; + } + if(DobeDWUtils.isEmpty(taxno) || !taxno.equals(orginfo.getString("qeug_taxno"))){ + return true; + } + return false; + } } \ No newline at end of file diff --git a/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/task/DobeDWprojectTask.java b/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/task/DobeDWprojectTask.java index 281faac..357178e 100644 --- a/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/task/DobeDWprojectTask.java +++ b/fi/fi/shkd-fi-fi-plugin/src/main/java/shkd/repc/task/DobeDWprojectTask.java @@ -128,7 +128,7 @@ public class DobeDWprojectTask extends AbstractTask implements Plugin { projectinfo.set("isleaf", fisleaf); projectinfo.set("enable", 1);//是否启用 projectinfo.set("billstatus", "A");//单据状态 A保存 B已提交 C已审核 - projectinfo.set("creator", 1L);//创建人默认指定为超管 + projectinfo.set("creator", 43007523L);//创建人默认指定为金小蝶 //保存数据:直接保存入库,不走操作校验 SaveServiceHelper.save(new DynamicObject[]{projectinfo}); } 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 d31d0fe..13ec9fe 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 @@ -16,6 +16,10 @@ import kd.bos.servicehelper.QueryServiceHelper; 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.Request; +import okhttp3.RequestBody; +import shkd.utils.DobeDWUtils; import java.util.Map; @@ -46,6 +50,42 @@ public class YongyouBIPTask extends AbstractTask implements Plugin { 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}); + if(prs.length == 0){ + return; + } + //bip接口认证 + 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; + } + JSONObject json_reuslt = JSON.parseObject(tokenresult); + if(json_reuslt.getJSONObject("data") == null){ + log.error("用友认证接口返回的data为空"); + return; + } + 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; + } + 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(); + JSONObject resultData = null; DynamicObject prinfo = null; DynamicObject requestinfo = null; String yynum = null; @@ -59,7 +99,7 @@ public class YongyouBIPTask extends AbstractTask implements Plugin { } //看用友的实付款查询接口是一个个查询,还是集中查询 yynum = requestinfo.getString("qeug_yynum"); - JSONObject resultData = JSON.parseObject("用友接口返回值"); + resultData = JSON.parseObject("用友接口返回值"); //根据查询结果设置付款登记对象 prinfo.set("bizdate",resultData.getDate("bizdate")); prinfo.set("billno",resultData.getString("billno")); @@ -69,4 +109,9 @@ public class YongyouBIPTask extends AbstractTask implements Plugin { OperationServiceHelper.executeOperate("audit",payregisterEntity,new DynamicObject[]{prinfo}, OperateOption.create()); } } + + private RequestBody createFormRequestBody(JSONObject json_body) { +// return RequestBody.create(ByteString.encodeUtf8(json_body.toJSONString()), DobeDWUtils.MTJSON); + return RequestBody.create(json_body.toJSONString(), DobeDWUtils.MTJSON); + } } \ No newline at end of file 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 d82da5c..513489c 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 @@ -2,6 +2,7 @@ package shkd.utils; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import kd.bos.context.RequestContext; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; @@ -21,7 +22,7 @@ public class DobeDWUtils { public static final MediaType MTJSON = MediaType.get("application/json"); //授权模式,客户端模式为client,密码模式为:password - public static final String granttype = "client_credentials"; +// public static final String granttype = "client_credentials"; //第三方应用id,对应系统中的app_id public static final String clientid = "ISC"; // 第三方应用秘钥,对请求加签使用 @@ -56,6 +57,8 @@ public class DobeDWUtils { billinfo.set("qeug_issuccess",isSuccess); billinfo.set("qeug_operation",operation); billinfo.set("status","A"); //单据状态默认暂存 + long currUserId = RequestContext.get().getCurrUserId();//当前用户 creator + billinfo.set("creator",currUserId); SaveServiceHelper.save(new DynamicObject[]{billinfo}); }