定时任务拉取sap应付凭证,接口改成分批获取

This commit is contained in:
yuxueliang0813 2025-07-05 16:14:55 +08:00
parent 2ec1ac69a3
commit 60adcedbf0
1 changed files with 70 additions and 58 deletions

View File

@ -36,54 +36,63 @@ import static shjh.jhzj7.fi.fi.webapi.ApplyBillControler.*;
* 定时调用SAP应付凭证接口生成付款申请单过滤参数仅为临期 * 定时调用SAP应付凭证接口生成付款申请单过滤参数仅为临期
*/ */
public class QuerySapCreatePayApplyTask extends AbstractTask { public class QuerySapCreatePayApplyTask extends AbstractTask {
public static final String apimenthod = "定时调用SAP应付凭证接口生成付款申请单(临期)";//bd_accountview public static final String apimenthod = "定时调用SAP应付凭证接口生成付款申请单(临期)";//bd_accountview
private final static Log logger = LogFactory.getLog(QuerySapCreatePayApplyTask.class); private final static Log logger = LogFactory.getLog(QuerySapCreatePayApplyTask.class);
@Override @Override
public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException { public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
// 获取临期天数并转换 // 获取临期天数并转换
String lq1 = (String) map.get("临期_前"); String lqBefore = (String) map.get("临期_前");
String lq = (String) map.get("临期_后"); String lqAfter = (String) map.get("临期_后");
// 检查是否有有效的临期数据 // 检查是否有有效的临期数据
if (StringUtils.isEmpty(lq) && StringUtils.isEmpty(lq1)) { if (StringUtils.isEmpty(lqBefore) || StringUtils.isEmpty(lqAfter)) {
return; return;
} }
//获取当前日期 //获取当前日期
LocalDate currentDate = LocalDate.now(); LocalDate currentDate = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
int daysBefore = Integer.parseInt(lq1);//临期_前 int daysBefore = Integer.parseInt(lqBefore);//临期_前
int daysAfter = Integer.parseInt(lq);//临期_后 int daysAfter = Integer.parseInt(lqAfter);//临期_后
int totalDays = daysBefore + daysAfter;//总天数后面按照每30天调用一次接口 int totalDays = daysBefore + daysAfter;//总天数
int callInterval = 30; // 调用间隔天数 int callInterval = 20; // 调用间隔天数
// 计算调用次数向上取整 // 根据总天数和间隔天数计算调用次数向上取整
int callCount = (int) Math.ceil((double) totalDays / callInterval); int callCount = (int) Math.ceil((double) totalDays / callInterval);
// 计算开始日期临期_前表示今天之前的天数 // 计算开始日期临期_前表示今天之前的天数
LocalDate startDate = currentDate; LocalDate startDate = currentDate.minusDays(daysBefore);
if (StringUtils.isNotEmpty(lq1)) {
startDate = currentDate.minusDays(daysBefore);
}
// 计算结束日期临期_后表示今天之后的天数 // 计算结束日期临期_后表示今天之后的天数
LocalDate endDate = currentDate; LocalDate endDate = currentDate.plusDays(daysAfter);
if (StringUtils.isNotEmpty(lq)) { JSONArray IT_LIST = new JSONArray(1);
endDate = currentDate.plusDays(daysAfter); JSONObject result;//sap应付凭证接口返回值
JSONObject sapdata;//sap应付凭证接口返回值data
String formatStartDate; // 开始日期-文本
String formatEndDate; // 结束日期-文本
String record;//日期拼接记录
Map<String, DynamicObject> payapplys;//付款申请单处理结果集
//以调用次数开始循环
for (int i = 1; i <= callCount; i++) {
formatStartDate = startDate.format(formatter);
if(i == callCount){
//如果是最后一次循环结束日期用endDate
formatEndDate = endDate.format(formatter);
}else{
//否则结束日期用开始日期加上间隔天数
formatEndDate = startDate.plusDays(callInterval).format(formatter);
} }
IT_LIST.clear();//使用之前先清空
String formattedoldDate = startDate.format(formatter); // 开始日期
String formattedNewDate = endDate.format(formatter); // 结束日期
JSONArray IT_LIST = new JSONArray();
// 添加SAP应付凭到期日过滤条件 // 添加SAP应付凭到期日过滤条件
addFilterCondition(IT_LIST, "FAEDT", formattedoldDate, formattedNewDate); addFilterCondition(IT_LIST, "FAEDT", formatStartDate, formatEndDate);
JSONObject result = vouchers_payable(IT_LIST,lq+ "临期:"+lq1); record = formatStartDate+"临期第"+i+""+formatEndDate;
logger.info(record);
result = vouchers_payable(IT_LIST,record);
if (null != result && result.containsKey("data")) { if (null != result && result.containsKey("data")) {
// 处理查询结果 // 处理查询结果
JSONObject data = (JSONObject) result.get("data"); sapdata = (JSONObject) result.get("data");
if (null != data && data.containsKey("IT_ITEM")) { if (null != sapdata && sapdata.containsKey("IT_ITEM")) {
JSONArray IT_ITEMs = (JSONArray) data.get("IT_ITEM"); JSONArray IT_ITEMs = (JSONArray) sapdata.get("IT_ITEM");
if (!IT_ITEMs.isEmpty()) { if (!IT_ITEMs.isEmpty()) {
Map<String, DynamicObject> payapplys = getPayapply(IT_ITEMs); payapplys = getPayapply(IT_ITEMs);
//若多条数据相同,则合并为一条数据处理 //若多条数据相同,则合并为一条数据处理
OperateOption option = OperateOption.create(); OperateOption option = OperateOption.create();
option.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(false)); // 不执行警告级别校验器 option.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(false)); // 不执行警告级别校验器
@ -115,6 +124,9 @@ public class QuerySapCreatePayApplyTask extends AbstractTask {
} }
} }
} }
//一次循环结束后开始日期变为加上间隔天数+1后的日期
startDate = startDate.plusDays(callInterval+1);
}
} }
/** /**