Compare commits

...

2 Commits

Author SHA1 Message Date
yuxueliang0813 27e4729ff8 用友付款接口初步调试调整 2024-09-08 12:25:48 +08:00
yuxueliang0813 7014c3b7f0 组织和人员同步数仓代码调整 2024-09-06 17:40:58 +08:00
4 changed files with 88 additions and 55 deletions

View File

@ -50,7 +50,7 @@ public class DobeDWorgTask extends AbstractTask implements Plugin {
try {
response = client.newCall(request).execute();
resultData = response.body().string();
log.info("组织接口返回结果:\n{}", resultData);
// log.info("组织接口返回结果:\n{}", resultData);
} catch (IOException e) {
log.info(String.format("组织接口异常:%s", e.getMessage()));
throw new RuntimeException(e);
@ -72,7 +72,7 @@ public class DobeDWorgTask extends AbstractTask implements Plugin {
try {
response = client.newCall(request).execute();
resultData = response.body().string();
log.info("组织接口返回结果:\n{}", resultData);
// log.info("组织接口返回结果:\n{}", resultData);
} catch (IOException e) {
log.info(String.format("组织接口异常:%s", e.getMessage()));
throw new RuntimeException(e);

View File

@ -8,10 +8,13 @@ import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.exception.KDException;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.permission.model.UserParam;
import kd.bos.schedule.executor.AbstractTask;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.servicehelper.user.UserServiceHelper;
import kd.sdk.plugin.Plugin;
import okhttp3.OkHttpClient;
@ -47,7 +50,7 @@ public class DobeDWpersonTask extends AbstractTask implements Plugin {
try {
response = client.newCall(request).execute();
resultData = response.body().string();
log.info("人员接口返回结果:\n{}", resultData);
// log.info("人员接口返回结果:\n{}", resultData);
} catch (IOException e) {
log.info(String.format("人员接口异常:%s", e.getMessage()));
throw new RuntimeException(e);
@ -55,7 +58,8 @@ public class DobeDWpersonTask extends AbstractTask implements Plugin {
JSONObject json_body = JSON.parseObject(resultData);
//接口返回的数据进行了分页
int totalNum = json_body.getIntValue("totalNum");//分页-SQL查询总数据量
handleUser(json_body);
List<String> exprtNumber = new ArrayList<>();//存储此次入参的所有工号用于后续排除
handleUser(json_body,exprtNumber);
int queryCount = DobeDWUtils.getQueryCount(totalNum);
if(queryCount > 1){
//查询次数不止一次需要分页查询
@ -68,18 +72,32 @@ public class DobeDWpersonTask extends AbstractTask implements Plugin {
try {
response = client.newCall(request).execute();
resultData = response.body().string();
log.info("人员接口返回结果:\n{}", resultData);
// log.info("人员接口返回结果:\n{}", resultData);
} catch (IOException e) {
log.info(String.format("人员接口异常:%s", e.getMessage()));
throw new RuntimeException(e);
}
json_body = JSON.parseObject(resultData);
handleUser(json_body);
handleUser(json_body,exprtNumber);
}
}
//处理离职人员
QFilter exprtFilter = new QFilter("number", QCP.not_in, exprtNumber);
QFilter dwFilter = new QFilter("source", QCP.equals, "dw");
DynamicObject[] dos = BusinessDataServiceHelper.load("bos_user","id,enable,isforbidden",new QFilter[]{exprtFilter.and(dwFilter)});
if(dos.length > 0){
DynamicObject currentUser = null;
for (int i = 0; i < dos.length; i++) {
currentUser = dos[i];
currentUser.set("enable", "0");//人员禁用
currentUser.set("isforbidden", true);//用户禁用
}
//保存数据直接保存入库不走操作校验
SaveServiceHelper.save(dos);
}
}
private void handleUser(JSONObject json_body) {
private void handleUser(JSONObject json_body,List<String> exprtNumber) {
//解析接口返回值与系统数据比较
JSONArray detailsJson = json_body.getJSONArray("data");
String userID = null;
@ -110,6 +128,7 @@ public class DobeDWpersonTask extends AbstractTask implements Plugin {
log.info(String.format("人员入参为空异常:%s", json_body.toJSONString()));
continue;
}
exprtNumber.add(number);
currentUser = QueryServiceHelper.queryOne(entityName,"id,number,name",new QFilter[]{new QFilter("number","=",number)});
user = new UserParam();//常用或者重要的参数详情请查看参数对象UserParam
dataMap = new HashMap<>();

View File

@ -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() {

View File

@ -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);
}
@ -70,9 +73,9 @@ public class DobeDWUtils {
ps.add(psjson);
json_body.put("params",ps);
}else{
json_body.put("params","[]");
json_body.put("params",new JSONArray());
}
//如下写法创建的请求只是json格式不带charset-utf8有些接口控制了这两者区别故需要特别指定
return RequestBody.create(ByteString.encodeUtf8(json_body.toJSONString()), MTJSON);
}