This commit is contained in:
weiyunlong 2025-06-21 14:39:10 +08:00
parent 4de20edbbf
commit 243dd7707f
3 changed files with 60 additions and 72 deletions

View File

@ -135,6 +135,9 @@ public class PayBillSubmitOperation extends AbstractOperationServicePlugIn imple
if (null != bill.getDynamicObject("openorg")) {
BUKRS = bill.getDynamicObject("openorg").getString("number");
}
if (StringUtils.isEmpty(BUKRS)) {
BUKRS = bill.getDynamicObject("org").getString("number");
}
DynamicObjectCollection entry = bill.getDynamicObjectCollection("entry");
if (!entry.isEmpty()) {
for (DynamicObject dynamicObject : entry) {

View File

@ -17,6 +17,7 @@ import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.util.StringUtils;
import kd.sdk.plugin.Plugin;
import shjh.jhzj7.fi.fi.utils.ApiUtils;
import shjh.jhzj7.fi.fi.utils.JhzjUtils;
@ -182,6 +183,9 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
if (null != bill.getDynamicObject("openorg")) {
BUKRS = bill.getDynamicObject("openorg").getString("number");
}
if (StringUtils.isEmpty(BUKRS)) {
BUKRS = bill.getDynamicObject("org").getString("number");
}
IS_HEADER.put("BUKRS", BUKRS);//公司代码_核算组织(付款单)
IS_HEADER.put("BLART", "KZ");//凭证类型
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
@ -370,23 +374,6 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
}
IT_ITEMS.put("DMBTR", String.valueOf(amountToPut));
}
//当前科目是特殊总账标识W时设置汇票字段
if ("W".equals(IT_ITEMS.getString("UMSKZ"))) {
// IT_ITEMS.put("UMSKZ", "W");//特殊总账标识-汇票时需设置为W
DynamicObjectCollection draftInfo = bill.getDynamicObjectCollection("cas_draftinfo");
if (null != draftInfo && !draftInfo.isEmpty()) {
//应收应付票据登记单
DynamicObject draftBillInfo = draftInfo.get(0).getDynamicObject("draftbillinfo");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date draftBillExpireDate = draftBillInfo.getDate("draftbillexpiredate");
IT_ITEMS.put("ZFBDT", draftBillExpireDate !=null ? format.format(draftBillExpireDate) : "");//汇票到期日
Date issueDate = draftBillInfo.getDate("issuedate");
IT_ITEMS.put("WDATE",issueDate !=null ? format.format(issueDate) : "");//汇票签发日期-出票日期
IT_ITEMS.put("WNAME",draftBillInfo.getString("drawername"));//出票人
IT_ITEMS.put("WBZOG",draftBillInfo.getString("receivername"));//受票人
IT_ITEMS.put("WBANK",draftBillInfo.getString("draftbillno"));//票据号
}
}
IT_ITEM.add(IT_ITEMS);
}
}
@ -396,17 +383,18 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
private JSONArray getIT_CLEAR(DynamicObject bill) {
JSONArray IT_CLEAR = new JSONArray();//清账数据参考IT_CLEAR仅清账需要输入
String BUKRS;
String BUKRS = "";
if (null != bill.getDynamicObject("openorg")) {
BUKRS = bill.getDynamicObject("openorg").getString("number");
} else {
BUKRS = "";
}
if (StringUtils.isEmpty(BUKRS)) {
BUKRS = bill.getDynamicObject("org").getString("number");
}
//客户(bd_customer)||供应商(bd_supplier) 收款人id:payee
String payeetype = bill.getString("payeetype");//收款人类型
AtomicReference<String> customerOrsupnum = new AtomicReference<>(getCustomerOrSupplierNumber(payeetype, bill, "payee"));
DynamicObjectCollection entrys = bill.getDynamicObjectCollection("entry");
entrys.forEach(entry -> {
for (DynamicObject entry : entrys) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("BUKRS", BUKRS);//公司代码
jsonObject.put("BELNR", entry.getString("shjh_vouchernums"));//会计凭证编号
@ -429,60 +417,57 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
jsonObject.put("UMSKZ", JhzjUtils.getUMSKZ(HKONT));//特殊总账标识
jsonObject.put("DMBTR1", entry.getBigDecimal("e_actamt"));//清账金额_实付金额
IT_CLEAR.add(jsonObject);
});
}
// 票据信息
DynamicObjectCollection casDraftinfos = bill.getDynamicObjectCollection("cas_draftinfo");
if (!casDraftinfos.isEmpty()) {
List<String> draftbillnos = new ArrayList<>();
// 缓存所有票据号码:draftbillno
List<String> draftbillnos = new ArrayList<>();
for (DynamicObject casDraftinfo : casDraftinfos) {
DynamicObject draftbillinfo = casDraftinfo.getDynamicObject("draftbillinfo");
if (null != draftbillinfo) {
draftbillnos.add(draftbillinfo.getString("draftbillno"));
}
draftbillnos.add(casDraftinfo.getString("draftbillno"));//票据号码
}
// 批量查询收款单:casRecbills
QFilter q2 = new QFilter("openorg.number", QCP.equals, BUKRS);
List<QFilter> allFilters = draftbillnos.stream()
.map(d -> new QFilter("cas_draftinfo.draftbillinfo.draftbillno", QCP.equals, d))
.collect(Collectors.toList());
List<QFilter> allFilters = new ArrayList<>();
for (String d : draftbillnos) {
allFilters.add(new QFilter("cas_draftinfo.draftbillno", QCP.equals, d));
}
allFilters.add(q2);
QFilter[] filtersArray = allFilters.toArray(new QFilter[0]);
DynamicObject[] casRecbills = BusinessDataServiceHelper.load("cas_recbill",
"id,cas_draftinfo,cas_draftinfo.draftbillno,openorg,shjh_vouchernum,shjh_sapfiscalyear,shjh_sapline" +
"payertype,payer,entry,entry.shjh_accountsap,entry.e_actamt", filtersArray);
// 1. 过滤出收款单, 2. 遍历收款单明细, 3. 组装IT_CLEAR数据
Arrays.stream(casRecbills)
.forEach(casRecbill -> {
DynamicObjectCollection entryss = casRecbill.getDynamicObjectCollection("entry");
entryss.forEach(entr -> {
JSONObject jsonObject = new JSONObject();
String payertype = casRecbill.getString("payertype");
customerOrsupnum.set(getCustomerOrSupplierNumber(payertype, casRecbill, "payer"));
jsonObject.put("BUKRS", BUKRS);
jsonObject.put("BELNR", casRecbill.getString("shjh_vouchernum"));
jsonObject.put("GJAHR", casRecbill.getString("shjh_sapfiscalyear"));
jsonObject.put("BUZEI", casRecbill.getString("shjh_sapline"));
switch (payertype) {
case "bd_customer":
jsonObject.put("KUNNR", customerOrsupnum);
break;
case "bd_supplier":
jsonObject.put("LIFNR", customerOrsupnum);
break;
}
String HKONT = "";
DynamicObject shjhSapkjkm = entr.getDynamicObject("shjh_accountsap");
if (shjhSapkjkm != null) {
HKONT = shjhSapkjkm.getString("number");
}
jsonObject.put("HKONT", HKONT);//科目编号
jsonObject.put("UMSKZ", JhzjUtils.getUMSKZ(HKONT));//特殊总账标识
jsonObject.put("DMBTR", entr.getBigDecimal("e_actamt"));
IT_CLEAR.add(jsonObject);
});
});
for (DynamicObject casRecbill : casRecbills) {
DynamicObjectCollection entryss = casRecbill.getDynamicObjectCollection("entry");
for (DynamicObject entr : entryss) {
JSONObject jsonObject = new JSONObject();
String payertype = casRecbill.getString("payertype");
customerOrsupnum.set(getCustomerOrSupplierNumber(payertype, casRecbill, "payer"));
jsonObject.put("BUKRS", BUKRS);
jsonObject.put("BELNR", casRecbill.getString("shjh_vouchernum"));
jsonObject.put("GJAHR", casRecbill.getString("shjh_sapfiscalyear"));
jsonObject.put("BUZEI", casRecbill.getString("shjh_sapline"));
switch (payertype) {
case "bd_customer":
jsonObject.put("KUNNR", customerOrsupnum);
break;
case "bd_supplier":
jsonObject.put("LIFNR", customerOrsupnum);
break;
}
String HKONT = "";
DynamicObject shjhSapkjkm = entr.getDynamicObject("shjh_accountsap");
if (shjhSapkjkm != null) {
HKONT = shjhSapkjkm.getString("number");
}
jsonObject.put("HKONT", HKONT);//科目编号
jsonObject.put("UMSKZ", JhzjUtils.getUMSKZ(HKONT));//特殊总账标识
jsonObject.put("DMBTR", entr.getBigDecimal("e_actamt"));
IT_CLEAR.add(jsonObject);
}
}
}
return IT_CLEAR;

View File

@ -78,19 +78,19 @@ public class QuerySapCreatePayApplyTask extends AbstractTask {
OperationResult saveResult = OperationServiceHelper.executeOperate("save", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
if (!saveResult.isSuccess()) {
handleAndLogError(saveResult, "保存失败", apimenthod, fkBillNum, IT_ITEMs.toString());
return;
continue;
}
OperationResult submitResult = OperationServiceHelper.executeOperate("submit", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
if (!submitResult.isSuccess()) {
// 提交失败将保存的数据删除,记录日志
OperationServiceHelper.executeOperate("delete", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
handleAndLogError(submitResult, "提交失败", apimenthod, fkBillNum, IT_ITEMs.toString());
return;
continue;
}
OperationResult auditResult = OperationServiceHelper.executeOperate("audit", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
if (!auditResult.isSuccess()) {
handleAndLogError(auditResult, "审核失败", apimenthod, fkBillNum, IT_ITEMs.toString());
return;
continue;
}
logger.error("审核成功,凭证号:" + fkBillNum);
JhzjUtils.saveLog(fkBillNum, apimenthod, IT_ITEMs.toString(), null, true, "API");
@ -174,7 +174,7 @@ public class QuerySapCreatePayApplyTask extends AbstractTask {
amount = wrbtr;
} catch (NumberFormatException e) {
logger.error("未清金额格式错误", e.getMessage());
return null;
continue;
}
// 往来类型 shjh_payee
// 往来户 party
@ -197,7 +197,7 @@ public class QuerySapCreatePayApplyTask extends AbstractTask {
boolean shjhSapwhetherlocking = ap_payapplys.getBoolean("shjh_sapwhetherlocking");//SAP是否锁定
if (shjhSapwhetherlocking) {
logger.error("同步失败,凭证号:" + fkBillNum + "的费控单据已锁定");
return null;
continue;
} else {
//todo:存在且单据中SAP锁定状态为未锁定,更新数据
ap_payapply = ap_payapplys;
@ -244,7 +244,7 @@ public class QuerySapCreatePayApplyTask extends AbstractTask {
KURSF = KURSF.setScale(5, RoundingMode.HALF_UP);
ap_payapply.set("exchangerate", KURSF);
} catch (NumberFormatException e) {
return null;
continue;
}
//申请金额折结算币别
@ -252,7 +252,7 @@ public class QuerySapCreatePayApplyTask extends AbstractTask {
dmbtr = dmbtr.setScale(2, RoundingMode.HALF_UP);
ap_payapply.set("appseleamount", dmbtr);
} catch (NumberFormatException e) {
return null;
continue;
}
DynamicObjectCollection entry = ap_payapply.getDynamicObjectCollection("entry");//明细
@ -283,17 +283,17 @@ public class QuerySapCreatePayApplyTask extends AbstractTask {
if (bankaccount == null || bankaccount.trim().isEmpty()) {
logger.error("同步失败,凭证号:" + fkBillNum + "的银行账号为空(供应商)");
JhzjUtils.saveLog(fkBillNum, apimenthod, it_list.toJSONString(), "同步失败,凭证号:" + fkBillNum + "的银行账号为空(供应商)", false, "API");
return null;
continue;
}
if (null == bank) {
logger.error("同步失败,凭证号:" + fkBillNum + "的开户银行为空(供应商)");
JhzjUtils.saveLog(fkBillNum, apimenthod, it_list.toJSONString(), "同步失败,凭证号:" + fkBillNum + "的开户银行为空(供应商)", false, "API");
return null;
continue;
}
if (accountname == null || accountname.trim().isEmpty()) {
logger.error("同步失败,凭证号:" + fkBillNum + "的账户名称为空(供应商)");
JhzjUtils.saveLog(fkBillNum, apimenthod, it_list.toJSONString(), "同步失败,凭证号:" + fkBillNum + "的账户名称为空(供应商)", false, "API");
return null;
continue;
}
ap_payapply_entry.set("e_assacct", bankaccount);//银行账号
ap_payapply_entry.set("e_bebank", bank);//开户银行
@ -303,12 +303,12 @@ public class QuerySapCreatePayApplyTask extends AbstractTask {
if (!ispp) {
logger.error("同步失败,凭证号:" + fkBillNum + "的合作银行类型无匹配数据(供应商)");
JhzjUtils.saveLog(fkBillNum, apimenthod, it_list.toJSONString(), "同步失败,凭证号:" + fkBillNum + "的合作银行类型无匹配数据(供应商)", false, "API");
return null;
continue;
}
}else {
logger.error("同步失败,凭证号:" + fkBillNum + "的供应商不存在银行信息");
JhzjUtils.saveLog(fkBillNum, apimenthod, it_list.toJSONString(), "同步失败,凭证号:" + fkBillNum + "的供应商不存在银行信息", false, "API");
return null;
continue;
}
}else {
//客户