上划下拨单定时推送任务
This commit is contained in:
		
							parent
							
								
									c1e3493939
								
							
						
					
					
						commit
						6c0960b41f
					
				|  | @ -0,0 +1,124 @@ | ||||||
|  | package shjh.jhzj7.fi.fi.plugin.task; | ||||||
|  | 
 | ||||||
|  | import kd.bos.context.RequestContext; | ||||||
|  | import kd.bos.dataentity.OperateOption; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObject; | ||||||
|  | import kd.bos.entity.operate.OperateOptionConst; | ||||||
|  | import kd.bos.entity.operate.result.OperationResult; | ||||||
|  | import kd.bos.exception.KDException; | ||||||
|  | import kd.bos.logging.Log; | ||||||
|  | import kd.bos.logging.LogFactory; | ||||||
|  | import kd.bos.orm.query.QCP; | ||||||
|  | import kd.bos.orm.query.QFilter; | ||||||
|  | import kd.bos.schedule.executor.AbstractTask; | ||||||
|  | import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||||
|  | import kd.bos.servicehelper.botp.BFTrackerServiceHelper; | ||||||
|  | import kd.bos.servicehelper.operation.OperationServiceHelper; | ||||||
|  | import kd.sdk.plugin.Plugin; | ||||||
|  | 
 | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.Date; | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Map; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * 后台任务插件 | ||||||
|  |  * 上划、下拨单定时推送SAP | ||||||
|  |  */ | ||||||
|  | public class UpAndDownBillTask extends AbstractTask implements Plugin { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     private final static Log logger = LogFactory.getLog(UpAndDownBillTask.class); | ||||||
|  | 
 | ||||||
|  |     //上划单标识 | ||||||
|  |     private final static String UP_KEY="fca_transupbill"; | ||||||
|  | 
 | ||||||
|  |     //下拨单标识 | ||||||
|  |     private final static String DOWN_KEY="fca_transdownbill"; | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException { | ||||||
|  |         //1.单据状态=已付款 | ||||||
|  |         //2.推送SAP=false && SAP凭证号=null | ||||||
|  |         //3.关联凭证已审核 | ||||||
|  |         QFilter qFilter = new QFilter("billstatus", QCP.equals, "D"); | ||||||
|  |         qFilter.and(new QFilter("shjh_sendsap",QCP.equals,false)); | ||||||
|  |         qFilter.and(new QFilter("isvoucher",QCP.equals,true)); | ||||||
|  |         String[] billno=new String[]{"SHZJ202506300007","SHZJ202506250007"}; | ||||||
|  |         qFilter.and(new QFilter("billno",QCP.in,billno)); | ||||||
|  |         this.queryBills(qFilter,UP_KEY); | ||||||
|  |         this.queryBills(qFilter,DOWN_KEY); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 查询符合条件的单据 | ||||||
|  |      * @param qFilter | ||||||
|  |      * @param upKey | ||||||
|  |      */ | ||||||
|  |     private void queryBills(QFilter qFilter, String upKey) { | ||||||
|  |         DynamicObject[] objects = BusinessDataServiceHelper.load(upKey, "id", qFilter.toArray()); | ||||||
|  |         if (objects.length!=0){ | ||||||
|  |             ArrayList<Long> idList = new ArrayList<>(); | ||||||
|  |             for (DynamicObject object : objects) { | ||||||
|  |                 //联查凭证状态-已审核 | ||||||
|  |                 Boolean exitAuditVoucher = this.QueryVoucherStatus(object.getPkValue()); | ||||||
|  |                 if (exitAuditVoucher){ | ||||||
|  |                     idList.add((Long) object.getPkValue()); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             if (idList.size()!=0){ | ||||||
|  |                 Map<Object, DynamicObject> billMap = BusinessDataServiceHelper.loadFromCache(idList.toArray(), upKey); | ||||||
|  |                 // 配置操作选项(共用) | ||||||
|  |                 OperateOption operateOption = createStrictOperateOption(); | ||||||
|  |                 List<DynamicObject> billList = new ArrayList<>(billMap.values()); | ||||||
|  |                 pushBills(billList,"sendvoucher",operateOption,upKey); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * 查询关联凭证是否已审核 | ||||||
|  |      * @param pkValue 源单id | ||||||
|  |      * @return 布尔值 | ||||||
|  |      */ | ||||||
|  |     private Boolean QueryVoucherStatus(Object pkValue) { | ||||||
|  |         boolean exitAuditVoucher = false; | ||||||
|  |         QFilter voucherFilters = new QFilter("sourcebill", QCP.equals, pkValue); | ||||||
|  |         DynamicObject gl_voucher = BusinessDataServiceHelper.loadSingle("gl_voucher", voucherFilters.toArray()); | ||||||
|  |         if (gl_voucher != null) { | ||||||
|  |             String billStatus = gl_voucher.getString("billstatus"); | ||||||
|  |             if ("C".equals(billStatus)){ | ||||||
|  |                 exitAuditVoucher=true; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return exitAuditVoucher; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private OperateOption createStrictOperateOption() { | ||||||
|  |         OperateOption option = OperateOption.create(); | ||||||
|  |         option.setVariableValue(OperateOptionConst.IGNOREWARN, "true");//不执行警告级别校验器 | ||||||
|  |         option.setVariableValue(OperateOptionConst.IGNOREINTERACTION, "true");//不显示交互提示,自动执行到底 | ||||||
|  |         option.setVariableValue(OperateOptionConst.STRICTVALIDATION, "true");//全部校验通过才保存 | ||||||
|  |         option.setVariableValue(OperateOptionConst.MUTEX_ISSTRICT, "true");//同一个用户在多个界面操作同一张,也不允许操作 | ||||||
|  |         return option; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void pushBills(List<DynamicObject> bills, String operationKey, OperateOption option,String billKey){ | ||||||
|  |         if (bills.isEmpty()){ | ||||||
|  |             logger.info(billKey+"无数据处理"); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         try { | ||||||
|  |             DynamicObject[] billArray = bills.toArray(new DynamicObject[0]); | ||||||
|  |             OperationResult result = OperationServiceHelper.executeOperate(operationKey, billKey, billArray, option); | ||||||
|  | 
 | ||||||
|  |             if (result.isSuccess()) { | ||||||
|  |                 logger.info(String.format("【%s】批量处理成功:%d 张单据", operationKey, bills.size())); | ||||||
|  |             } else { | ||||||
|  |                 logger.error(String.format("【%s】处理失败:%s", operationKey, result.getMessage())); | ||||||
|  |             } | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             logger.error(String.format("【%s】执行异常:", operationKey), e); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue