定时任务拉取sap应付凭证,接口改成分批获取
This commit is contained in:
		
							parent
							
								
									2ec1ac69a3
								
							
						
					
					
						commit
						60adcedbf0
					
				|  | @ -36,84 +36,96 @@ import static shjh.jhzj7.fi.fi.webapi.ApplyBillControler.*; | |||
|  * 定时调用SAP应付凭证接口生成付款申请单,过滤参数仅为临期 | ||||
|  */ | ||||
| public class QuerySapCreatePayApplyTask extends AbstractTask { | ||||
| 
 | ||||
|     public static final String apimenthod = "定时调用SAP应付凭证接口生成付款申请单(临期)";//bd_accountview | ||||
| 
 | ||||
|     private final static Log logger = LogFactory.getLog(QuerySapCreatePayApplyTask.class); | ||||
|     @Override | ||||
|     public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException { | ||||
|         // 获取临期天数并转换 | ||||
|         String lq1 = (String) map.get("临期_前"); | ||||
|         String lq = (String) map.get("临期_后"); | ||||
|         String lqBefore = (String) map.get("临期_前"); | ||||
|         String lqAfter = (String) map.get("临期_后"); | ||||
|         // 检查是否有有效的临期数据 | ||||
|         if (StringUtils.isEmpty(lq) && StringUtils.isEmpty(lq1)) { | ||||
|         if (StringUtils.isEmpty(lqBefore) || StringUtils.isEmpty(lqAfter)) { | ||||
|             return; | ||||
|         } | ||||
|         //获取当前日期 | ||||
|         LocalDate currentDate = LocalDate.now(); | ||||
|         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); | ||||
|         int daysBefore = Integer.parseInt(lq1);//临期_前 | ||||
|         int daysAfter = Integer.parseInt(lq);//临期_后 | ||||
|         int totalDays = daysBefore + daysAfter;//总天数,后面按照每30天调用一次接口 | ||||
|         int callInterval = 30; // 调用间隔天数 | ||||
|         // 计算调用次数(向上取整) | ||||
|         int daysBefore = Integer.parseInt(lqBefore);//临期_前 | ||||
|         int daysAfter = Integer.parseInt(lqAfter);//临期_后 | ||||
|         int totalDays = daysBefore + daysAfter;//总天数 | ||||
|         int callInterval = 20; // 调用间隔天数 | ||||
|         // 根据总天数和间隔天数计算调用次数(向上取整) | ||||
|         int callCount = (int) Math.ceil((double) totalDays / callInterval); | ||||
| 
 | ||||
|         // 计算开始日期(临期_前表示今天之前的天数) | ||||
|         LocalDate startDate = currentDate; | ||||
|         if (StringUtils.isNotEmpty(lq1)) { | ||||
|             startDate = currentDate.minusDays(daysBefore); | ||||
|         } | ||||
| 
 | ||||
|         LocalDate startDate = currentDate.minusDays(daysBefore); | ||||
|         // 计算结束日期(临期_后表示今天之后的天数) | ||||
|         LocalDate endDate = currentDate; | ||||
|         if (StringUtils.isNotEmpty(lq)) { | ||||
|             endDate = currentDate.plusDays(daysAfter); | ||||
|         } | ||||
| 
 | ||||
|         String formattedoldDate = startDate.format(formatter); // 开始日期 | ||||
|         String formattedNewDate = endDate.format(formatter); // 结束日期 | ||||
| 
 | ||||
|         JSONArray IT_LIST = new JSONArray(); | ||||
|         // 添加SAP应付凭到期日过滤条件 | ||||
|         addFilterCondition(IT_LIST, "FAEDT", formattedoldDate, formattedNewDate); | ||||
|         JSONObject result = vouchers_payable(IT_LIST,lq+ "临期:"+lq1); | ||||
|         if (null != result && result.containsKey("data")) { | ||||
|             // 处理查询结果 | ||||
|             JSONObject data = (JSONObject) result.get("data"); | ||||
|             if (null != data && data.containsKey("IT_ITEM")) { | ||||
|                 JSONArray IT_ITEMs = (JSONArray) data.get("IT_ITEM"); | ||||
|                 if (!IT_ITEMs.isEmpty()) { | ||||
|                     Map<String, DynamicObject> payapplys = getPayapply(IT_ITEMs); | ||||
|                     //若多条数据相同,则合并为一条数据处理 | ||||
|                     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; | ||||
|         LocalDate endDate = currentDate.plusDays(daysAfter); | ||||
|         JSONArray IT_LIST = new JSONArray(1); | ||||
|         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();//使用之前先清空 | ||||
|             // 添加SAP应付凭到期日过滤条件 | ||||
|             addFilterCondition(IT_LIST, "FAEDT", formatStartDate, formatEndDate); | ||||
|             record = formatStartDate+"临期第"+i+"次"+formatEndDate; | ||||
|             logger.info(record); | ||||
|             result = vouchers_payable(IT_LIST,record); | ||||
|             if (null != result && result.containsKey("data")) { | ||||
|                 // 处理查询结果 | ||||
|                 sapdata = (JSONObject) result.get("data"); | ||||
|                 if (null != sapdata && sapdata.containsKey("IT_ITEM")) { | ||||
|                     JSONArray IT_ITEMs = (JSONArray) sapdata.get("IT_ITEM"); | ||||
|                     if (!IT_ITEMs.isEmpty()) { | ||||
|                         payapplys = getPayapply(IT_ITEMs); | ||||
|                         //若多条数据相同,则合并为一条数据处理 | ||||
|                         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