定时任务拉取sap应付凭证,接口改成分批获取
This commit is contained in:
parent
2ec1ac69a3
commit
60adcedbf0
|
|
@ -36,84 +36,96 @@ 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 formattedoldDate = startDate.format(formatter); // 开始日期
|
String formatEndDate; // 结束日期-文本
|
||||||
String formattedNewDate = endDate.format(formatter); // 结束日期
|
String record;//日期拼接记录
|
||||||
|
Map<String, DynamicObject> payapplys;//付款申请单处理结果集
|
||||||
JSONArray IT_LIST = new JSONArray();
|
//以调用次数开始循环
|
||||||
// 添加SAP应付凭到期日过滤条件
|
for (int i = 1; i <= callCount; i++) {
|
||||||
addFilterCondition(IT_LIST, "FAEDT", formattedoldDate, formattedNewDate);
|
formatStartDate = startDate.format(formatter);
|
||||||
JSONObject result = vouchers_payable(IT_LIST,lq+ "临期:"+lq1);
|
if(i == callCount){
|
||||||
if (null != result && result.containsKey("data")) {
|
//如果是最后一次循环,结束日期用endDate
|
||||||
// 处理查询结果
|
formatEndDate = endDate.format(formatter);
|
||||||
JSONObject data = (JSONObject) result.get("data");
|
}else{
|
||||||
if (null != data && data.containsKey("IT_ITEM")) {
|
//否则结束日期用开始日期加上间隔天数
|
||||||
JSONArray IT_ITEMs = (JSONArray) data.get("IT_ITEM");
|
formatEndDate = startDate.plusDays(callInterval).format(formatter);
|
||||||
if (!IT_ITEMs.isEmpty()) {
|
}
|
||||||
Map<String, DynamicObject> payapplys = getPayapply(IT_ITEMs);
|
IT_LIST.clear();//使用之前先清空
|
||||||
//若多条数据相同,则合并为一条数据处理
|
// 添加SAP应付凭到期日过滤条件
|
||||||
OperateOption option = OperateOption.create();
|
addFilterCondition(IT_LIST, "FAEDT", formatStartDate, formatEndDate);
|
||||||
option.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(false)); // 不执行警告级别校验器
|
record = formatStartDate+"临期第"+i+"次"+formatEndDate;
|
||||||
String fkBillNum;
|
logger.info(record);
|
||||||
String sapuniquevalue;
|
result = vouchers_payable(IT_LIST,record);
|
||||||
for (DynamicObject ap_payapply : payapplys.values()) {
|
if (null != result && result.containsKey("data")) {
|
||||||
fkBillNum = ap_payapply.getString("shjh_vouchernum");//凭证号
|
// 处理查询结果
|
||||||
sapuniquevalue = ap_payapply.getString("shjh_sapuniquevalue");//凭证唯一码
|
sapdata = (JSONObject) result.get("data");
|
||||||
// 新增数据
|
if (null != sapdata && sapdata.containsKey("IT_ITEM")) {
|
||||||
OperationResult saveResult = OperationServiceHelper.executeOperate("save", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
|
JSONArray IT_ITEMs = (JSONArray) sapdata.get("IT_ITEM");
|
||||||
if (!saveResult.isSuccess()) {
|
if (!IT_ITEMs.isEmpty()) {
|
||||||
handleAndLogError(saveResult, "保存失败", apimenthod, fkBillNum, sapuniquevalue);
|
payapplys = getPayapply(IT_ITEMs);
|
||||||
continue;
|
//若多条数据相同,则合并为一条数据处理
|
||||||
|
OperateOption option = OperateOption.create();
|
||||||
|
option.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(false)); // 不执行警告级别校验器
|
||||||
|
String fkBillNum;
|
||||||
|
String sapuniquevalue;
|
||||||
|
for (DynamicObject ap_payapply : payapplys.values()) {
|
||||||
|
fkBillNum = ap_payapply.getString("shjh_vouchernum");//凭证号
|
||||||
|
sapuniquevalue = ap_payapply.getString("shjh_sapuniquevalue");//凭证唯一码
|
||||||
|
// 新增数据
|
||||||
|
OperationResult saveResult = OperationServiceHelper.executeOperate("save", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
|
||||||
|
if (!saveResult.isSuccess()) {
|
||||||
|
handleAndLogError(saveResult, "保存失败", apimenthod, fkBillNum, sapuniquevalue);
|
||||||
|
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, sapuniquevalue);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
OperationResult auditResult = OperationServiceHelper.executeOperate("audit", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
|
||||||
|
if (!auditResult.isSuccess()) {
|
||||||
|
handleAndLogError(auditResult, "审核失败", apimenthod, fkBillNum, sapuniquevalue);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
logger.info("审核成功,凭证号:" + sapuniquevalue);
|
||||||
}
|
}
|
||||||
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, sapuniquevalue);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
OperationResult auditResult = OperationServiceHelper.executeOperate("audit", AP_PAYAPPLY, new DynamicObject[]{ap_payapply}, option);
|
|
||||||
if (!auditResult.isSuccess()) {
|
|
||||||
handleAndLogError(auditResult, "审核失败", apimenthod, fkBillNum, sapuniquevalue);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
logger.info("审核成功,凭证号:" + sapuniquevalue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//一次循环结束后,开始日期变为加上间隔天数+1后的日期
|
||||||
|
startDate = startDate.plusDays(callInterval+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue