优化手工拉取SAP,不中断以及日志优化

--s
This commit is contained in:
weiyunlong 2025-07-09 17:03:59 +08:00
parent b242e37fa2
commit 45645e3bdc
1 changed files with 71 additions and 56 deletions

View File

@ -378,7 +378,7 @@ public class SappzFormPlugin extends AbstractFormPlugin {
//汇率表
DynamicObject exrate = BusinessDataServiceHelper.loadSingle(BD_EXRATETABLE,
new QFilter[]{new QFilter("number", QCP.equals, "ERT-01")});
StringBuilder builder = new StringBuilder("失败原因:");
for (int selectRow : selectRows) {
String fkBillNum = (String) this.getModel().getValue("shjh_vouchernumber", selectRow);//凭证号
@ -386,15 +386,16 @@ public class SappzFormPlugin extends AbstractFormPlugin {
String companyNum = (String) this.getModel().getValue("shjh_orgnumber", selectRow);//公司编号
if (companyNum == null || companyNum.isEmpty()) {
handleError("同步失败,凭证号:" + fkBillNum + "的公司编号为空", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的公司编号为空");
return;
// this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的公司编号为空");
builder.append("同步失败,凭证号:" + fkBillNum + "的公司编号为空"+"\n");
continue;
}
QFilter Q1 = new QFilter("number", QCP.equals, companyNum);
DynamicObject org = BusinessDataServiceHelper.loadSingle(orgEntName, new QFilter[]{Q1});
if (null == org) {
handleError("同步失败,凭证号:" + fkBillNum + "的组织编码不存在", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的组织编码不存在");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的组织编码不存在"+"\n");
continue;
}
// 申请金额 , 汇率 , 申请金额折结算币别
@ -407,8 +408,8 @@ public class SappzFormPlugin extends AbstractFormPlugin {
} catch (NumberFormatException e) {
// 处理数字格式异常
handleError("同步失败,凭证号:" + fkBillNum + "的未清金额格式不正确", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的未清金额格式不正确");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的未清金额格式不正确"+"\n");
continue;
}
// 往来类型
@ -416,20 +417,20 @@ public class SappzFormPlugin extends AbstractFormPlugin {
// 检查往来类型是否为空或无效
if (asstacttype == null || asstacttype.isEmpty()) {
handleError("同步失败,凭证号:" + fkBillNum + "的往来类型为空", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的往来类型为空");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的往来类型为空"+"\n");
continue;
} else if (!asstactTypeMap.containsKey(asstacttype)) {
handleError("同步失败,凭证号:" + fkBillNum + "的往来类型不存在", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的往来类型不存在");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的往来类型不存在"+"\n");
continue;
}
// 往来户
String asstact = (String) this.getModel().getValue("shjh_payeebanknum", selectRow);//往来户名称
if (asstact == null || asstact.isEmpty()) {
handleError("同步失败,凭证号:" + fkBillNum + "的往来户为空", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的往来户为空");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的往来户为空"+"\n");
continue;
}
QFilter Q3 = new QFilter("number", QCP.equals, asstact);
DynamicObject party = "供应商".equals(asstacttype)
@ -438,8 +439,8 @@ public class SappzFormPlugin extends AbstractFormPlugin {
if (party == null) {
String errorMessage = "同步失败,凭证号:" + fkBillNum + "" + ("供应商".equals(asstacttype) ? "供应商" : "客户") + "不存在";
handleError(errorMessage, fkBillNum, apimenthod, null);
this.getView().showMessage(errorMessage);
return;
builder.append(errorMessage+"\n");
continue;
}
// 新增应付付款申请单
@ -459,8 +460,8 @@ public class SappzFormPlugin extends AbstractFormPlugin {
boolean shjhSapwhetherlocking = ap_payapplys.getBoolean("shjh_sapwhetherlocking");//SAP是否锁定
if (shjhSapwhetherlocking) {
handleError("同步失败,凭证号:" + fkBillNum + "已锁定", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "已锁定");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "已锁定"+"\n");
continue;
} else {
//存在且单据中SAP锁定状态为未锁定,更新数据
ap_payapply = ap_payapplys;
@ -476,8 +477,8 @@ public class SappzFormPlugin extends AbstractFormPlugin {
Date bizDate = (Date) this.getModel().getValue("shjh_bookkeepingdate", selectRow);//记账日期
if (null == bizDate) {
handleError("同步失败,凭证号:" + fkBillNum + "的记账日期为空", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的记账日期为空");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的记账日期为空"+"\n");
continue;
}
ap_payapply.set("applydate", bizDate);
@ -495,8 +496,8 @@ public class SappzFormPlugin extends AbstractFormPlugin {
DynamicObject accountview = BusinessDataServiceHelper.loadSingle(BD_ACCOUNTVIEW, Q8.toArray());
if (null == accountview) {
handleError("同步失败,凭证号:" + fkBillNum + "的会计科目不存在", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的会计科目不存在");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的会计科目不存在"+"\n");
continue;
}
ap_payapply.set("shjh_sapkjkm", accountview);
}
@ -517,8 +518,8 @@ public class SappzFormPlugin extends AbstractFormPlugin {
// 检查币别编号是否为空
if (currencyNumber == null || currencyNumber.trim().isEmpty()) {
handleError("同步失败,凭证号:" + fkBillNum + "" + currencyTypeName + "为空", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "" + currencyTypeName + "为空");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "" + currencyTypeName + "为空"+"\n");
continue;
}
if ("RMB".equals(currencyNumber)) {
currencyNumber = "CNY";
@ -528,8 +529,8 @@ public class SappzFormPlugin extends AbstractFormPlugin {
// 检查 currency 是否为空
if (currency == null) {
handleError("同步失败,凭证号:" + fkBillNum + "" + currencyTypeName + "不存在", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "" + currencyTypeName + "不存在");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "" + currencyTypeName + "不存在"+"\n");
continue;
}
ap_payapply.set(currencyType, currency);
}
@ -542,8 +543,8 @@ public class SappzFormPlugin extends AbstractFormPlugin {
} catch (NumberFormatException e) {
// 处理数字格式异常
handleError("同步失败,凭证号:" + fkBillNum + "的汇率格式不正确", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的汇率格式不正确");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的汇率格式不正确"+"\n");
continue;
}
//申请金额折结算币别
@ -554,8 +555,8 @@ public class SappzFormPlugin extends AbstractFormPlugin {
} catch (NumberFormatException e) {
// 处理数字格式异常
handleError("同步失败,凭证号:" + fkBillNum + "的申请金额折结算币别格式不正确", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的申请金额折结算币别格式不正确");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的申请金额折结算币别格式不正确"+"\n");
continue;
}
DynamicObjectCollection entry = ap_payapply.getDynamicObjectCollection("entry");//明细
@ -590,18 +591,18 @@ public class SappzFormPlugin extends AbstractFormPlugin {
// 检查银行账号,开户银行,账户名称是否为空
if (bankaccount == null || bankaccount.trim().isEmpty()) {
handleError("同步失败,凭证号:" + fkBillNum + "的银行账号为空(供应商)", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的银行账号为空(供应商)");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的银行账号为空(供应商)"+"\n");
continue;
}
if (null == bank) {
handleError("同步失败,凭证号:" + fkBillNum + "的开户银行为空(供应商)", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的开户银行为空(供应商)");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的开户银行为空(供应商)"+"\n");
continue;
}
if (accountname == null || accountname.trim().isEmpty()) {
handleError("同步失败,凭证号:" + fkBillNum + "的账户名称为空(供应商)", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的账户名称为空(供应商)");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的账户名称为空(供应商)"+"\n");
continue;
}
ap_payapply_entry.set("e_assacct", bankaccount);//银行账号
ap_payapply_entry.set("e_bebank", bank);//开户银行
@ -616,18 +617,18 @@ public class SappzFormPlugin extends AbstractFormPlugin {
// 检查银行账号,开户银行,账户名称是否为空
if (bankaccount == null || bankaccount.trim().isEmpty()) {
handleError("同步失败,凭证号:" + fkBillNum + "的银行账号为空(供应商)", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的银行账号为空(供应商)");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的银行账号为空(供应商)"+"\n");
continue;
}
if (null == bank) {
handleError("同步失败,凭证号:" + fkBillNum + "的开户银行为空(供应商)", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的开户银行为空(供应商)");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的开户银行为空(供应商)"+"\n");
continue;
}
if (accountname == null || accountname.trim().isEmpty()) {
handleError("同步失败,凭证号:" + fkBillNum + "的账户名称为空(供应商)", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的账户名称为空(供应商)");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的账户名称为空(供应商)"+"\n");
continue;
}
ap_payapply_entry.set("e_assacct", bankaccount);//银行账号
ap_payapply_entry.set("e_bebank", bank);//开户银行
@ -640,13 +641,13 @@ public class SappzFormPlugin extends AbstractFormPlugin {
if (!ispp) {
handleError("同步失败,凭证号:" + fkBillNum + "的合作银行类型无匹配数据(供应商)", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的合作银行类型无匹配数据(供应商)");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的合作银行类型无匹配数据(供应商)"+"\n");
continue;
}
}else {
handleError("同步失败,凭证号:" + fkBillNum + "的供应商不存在银行信息", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的供应商不存在银行信息");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的供应商不存在银行信息"+"\n");
continue;
}
}else {
//客户
@ -831,8 +832,8 @@ public class SappzFormPlugin extends AbstractFormPlugin {
DynamicObject cause = BusinessDataServiceHelper.loadSingle(GL_CASHFLOWITEM, new QFilter[]{Q11});
if (null == cause) {
handleError("同步失败,凭证号:" + fkBillNum + "的原因码不存在", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的原因码不存在");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的原因码不存在"+"\n");
continue;
}
ap_payapply.set("shjh_yym", cause);
}
@ -854,8 +855,8 @@ public class SappzFormPlugin extends AbstractFormPlugin {
DynamicObject vouchertypes = BusinessDataServiceHelper.loadSingle("gl_vouchertype", new QFilter[]{Q11});
if (null == vouchertypes) {
handleError("同步失败,凭证号:" + fkBillNum + "的凭证类型不存在", fkBillNum, apimenthod, null);
this.getView().showMessage("同步失败,凭证号:" + fkBillNum + "的凭证类型不存在");
return;
builder.append("同步失败,凭证号:" + fkBillNum + "的凭证类型不存在"+"\n");
continue;
}
ap_payapply.set("shjh_documenttype", vouchertypes);
}
@ -887,6 +888,8 @@ public class SappzFormPlugin extends AbstractFormPlugin {
OperateOption option = OperateOption.create();
option.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(false)); //不执行警告级别校验器
String fkBillNum;
Integer successCount = 0;
StringBuilder successStr = new StringBuilder("成功凭证号:");
for (DynamicObject ap_payapply : bills.values()) {
fkBillNum = ap_payapply.getString("shjh_vouchernum");
// 新增数据
@ -894,8 +897,8 @@ public class SappzFormPlugin extends AbstractFormPlugin {
if (!saveResult.isSuccess()) {
handleAndLogError(saveResult, "保存失败", apimenthod, fkBillNum, null);
String errorMessage = getFirstErrorMessage(saveResult);
this.getView().showErrorNotification(errorMessage);
return;
builder.append(errorMessage+"\n");
continue;
}
OperationResult submitResult = OperationServiceHelper.executeOperate("submit", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
if (!submitResult.isSuccess()) {
@ -903,20 +906,32 @@ public class SappzFormPlugin extends AbstractFormPlugin {
OperationServiceHelper.executeOperate("delete", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
handleAndLogError(submitResult, "提交失败", apimenthod, fkBillNum, null);
String errorMessage = getFirstErrorMessage(submitResult);
this.getView().showErrorNotification(errorMessage);
return;
builder.append(errorMessage+"\n");
continue;
}
OperationResult auditResult = OperationServiceHelper.executeOperate("audit", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
if (!auditResult.isSuccess()) {
handleAndLogError(auditResult, "审核失败", apimenthod, fkBillNum, null);
String errorMessage = getFirstErrorMessage(auditResult);
this.getView().showErrorNotification(errorMessage);
return;
builder.append(errorMessage+"\n");
continue;
}
log.info("审核成功,凭证号:" + fkBillNum);
JhzjUtils.saveLog(fkBillNum, apimenthod, ap_payapply.getString("shjh_sapuniquevalue"), "审核成功", true, "API");
successCount = successCount +1;
successStr.append(fkBillNum).append(",");
}
int length = selectRows.length;
int errorCount = length - successCount;
if (errorCount > 0) {
String error = "同步总数量:" + length + "\n" + "成功数量:" + successCount + "(" + successStr + ")" + "\n" +
"失败数量:" + errorCount + "\n" + builder.toString();
this.getView().showMessage(error);
JhzjUtils.saveLog(apimenthod, apimenthod, apimenthod, error, false, "API");
}else {
this.getView().showSuccessNotification("同步成功");
}
this.getView().showSuccessNotification("同步成功");
}
break;
default: