收付款单全量更新资金计划科目优化为update语句
This commit is contained in:
		
							parent
							
								
									14f19b4f52
								
							
						
					
					
						commit
						26213d6473
					
				|  | @ -3,6 +3,8 @@ package shjh.jhzj7.fi.fi.plugin.task; | |||
| import kd.bos.context.RequestContext; | ||||
| import kd.bos.dataentity.entity.DynamicObject; | ||||
| import kd.bos.dataentity.entity.DynamicObjectCollection; | ||||
| import kd.bos.db.DB; | ||||
| import kd.bos.db.DBRoute; | ||||
| import kd.bos.exception.KDException; | ||||
| import kd.bos.logging.Log; | ||||
| import kd.bos.logging.LogFactory; | ||||
|  | @ -10,7 +12,6 @@ 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.operation.SaveServiceHelper; | ||||
| import kd.sdk.plugin.Plugin; | ||||
| 
 | ||||
| import java.util.*; | ||||
|  | @ -20,6 +21,9 @@ public class RecBillZjjhTask extends AbstractTask implements Plugin { | |||
| 
 | ||||
|     private static final String recbillName = "cas_recbill";//收款单 T_CAS_ReceivingBill | ||||
| 
 | ||||
|     private static final String updateZero = "update T_CAS_ReceivingBill set fk_shjh_planclass=0 where fid=?";//更新资金计划科目为0 | ||||
|     private static final String updateKM = "update T_CAS_ReceivingBill set fk_shjh_planclass=? where fid=?";//更新资金计划科目为指定科目 | ||||
| 
 | ||||
|     @Override | ||||
|     public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException { | ||||
| 
 | ||||
|  | @ -34,13 +38,15 @@ public class RecBillZjjhTask extends AbstractTask implements Plugin { | |||
|         for (DynamicObject recbill : recBillMap.values()) { | ||||
|             //根据配置表携带资金计划科目 | ||||
|             zjaccount = xdMembersubject(recbill); | ||||
|             recbill.set("shjh_planclass", zjaccount); | ||||
| //            recbill.set("shjh_planclass", zjaccount); | ||||
| //            SaveServiceHelper.save(new DynamicObject[]{recbill}); | ||||
|             if(zjaccount == null){ | ||||
|                 logger.info(recbill.getString("billno")+"对应资金计划科目为空"); | ||||
|                 DB.update(DBRoute.of("fi"), updateZero, new Object[]{recbill.getPkValue()}); | ||||
|             }else{ | ||||
|                 logger.info(recbill.getString("billno")+"对应资金计划科目为"+zjaccount.getLong("id")); | ||||
|                 DB.update(DBRoute.of("fi"), updateKM, new Object[]{zjaccount.getPkValue(), recbill.getPkValue()}); | ||||
|             } | ||||
|             SaveServiceHelper.save(new DynamicObject[]{recbill}); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,10 +1,10 @@ | |||
| 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.dataentity.entity.DynamicObjectCollection; | ||||
| import kd.bos.db.DB; | ||||
| import kd.bos.db.DBRoute; | ||||
| import kd.bos.exception.KDException; | ||||
| import kd.bos.logging.Log; | ||||
| import kd.bos.logging.LogFactory; | ||||
|  | @ -12,67 +12,320 @@ 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.operation.OperationServiceHelper; | ||||
| import kd.bos.servicehelper.operation.SaveServiceHelper; | ||||
| import kd.bos.util.StringUtils; | ||||
| import kd.sdk.plugin.Plugin; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.Map; | ||||
| import java.util.*; | ||||
| 
 | ||||
| import static shjh.jhzj7.fi.fi.plugin.operate.PayBillSaveOperation.xdMembersubject; | ||||
| 
 | ||||
| public class ZjjhTask extends AbstractTask implements Plugin { | ||||
| 
 | ||||
|     private final static Log logger = LogFactory.getLog(ZjjhTask.class); | ||||
|     private static final Log logger = LogFactory.getLog(ZjjhTask.class); | ||||
| 
 | ||||
|     private static final String paybillName = "cas_paybill";//付款单 T_CAS_PaymentBill | ||||
| 
 | ||||
|     private static final String payapplyName = "ap_payapply";//付款申请单 | ||||
| 
 | ||||
|     private static final String updateZero = "update T_CAS_PaymentBill set fk_shjh_membersubject=0 where fid=?";//更新资金计划科目为0 | ||||
|     private static final String updateKM = "update T_CAS_PaymentBill set fk_shjh_membersubject=? where fid=?";//更新资金计划科目为指定科目 | ||||
| 
 | ||||
|     @Override | ||||
|     public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException { | ||||
| 
 | ||||
|         QFilter q1 = new QFilter("paymentidentify.number", QCP.equals, "FKBS02");//付款标识为被动付款 | ||||
|         QFilter q2 = new QFilter("paymentidentify.number", QCP.equals, "FKBS01");//付款标识为主动付款 | ||||
|         QFilter q3 = new QFilter("shjh_sourcesystem", QCP.equals, "A");//来源系统,A_sap,B_fk | ||||
|         QFilter q4 = new QFilter("shjh_sourcesystem", QCP.equals, "B");//来源系统,A_sap,B_fk | ||||
|         QFilter filter = q1.or(q2.and(q3.or(q4)));//filter条件为被动付款 或者 主动付款(且来源系统为sap或费控) | ||||
|         DynamicObject[] paybills = BusinessDataServiceHelper.load("cas_paybill", "id", filter.toArray()); | ||||
|         if (paybills.length!=0){ | ||||
|         DynamicObject[] paybills = BusinessDataServiceHelper.load(paybillName, "id", filter.toArray()); | ||||
|         if (paybills.length != 0){ | ||||
|             ArrayList<Long> ids = new ArrayList<>(); | ||||
|             for (DynamicObject dynamicObject : paybills) { | ||||
|                 ids.add(dynamicObject.getLong("id")); | ||||
|             } | ||||
|             Map<Object, DynamicObject> recBillMap = BusinessDataServiceHelper.loadFromCache(ids.toArray(), "cas_paybill"); | ||||
|             OperateOption operateOption = OperateOption.create(); | ||||
|             // 不执行警告级别校验器 | ||||
|             operateOption.setVariableValue(OperateOptionConst.IGNOREWARN, String.valueOf(true)); | ||||
|             // 不显示交互提示,自动执行到底 | ||||
|             operateOption.setVariableValue(OperateOptionConst.IGNOREINTERACTION, String.valueOf(true)); | ||||
|             // 全部校验通过才保存 | ||||
|             operateOption.setVariableValue(OperateOptionConst.STRICTVALIDATION, String.valueOf(true)); | ||||
|             //同一个用户在多个界面操作同一张,也不允许操作 | ||||
|             operateOption.setVariableValue(OperateOptionConst.MUTEX_ISSTRICT, String.valueOf(true)); | ||||
|             Map<Object, DynamicObject> recBillMap = BusinessDataServiceHelper.loadFromCache(ids.toArray(), paybillName); | ||||
|             String paymentidentify; | ||||
|             DynamicObject payapply; | ||||
|             DynamicObject zjjhkm; | ||||
|             for (DynamicObject cas_paybill : recBillMap.values()) { | ||||
|                 String string = cas_paybill.getString("paymentidentify.number"); | ||||
|                 //被动  如果是被动付款,则将现有付款单保存操作后,获取资金计划科目的代码直接复制拷贝至此; | ||||
|                 if ("FKBS02".equals(string)) { | ||||
|                     cas_paybill.set("shjh_membersubject", xdMembersubject(cas_paybill)); | ||||
|                     SaveServiceHelper.save(new DynamicObject[]{cas_paybill}); | ||||
|                 } | ||||
|                 //主动 如果是主动付款,根据付款单查找到上游某一个付款申请单即可,再根据付款申请单对象,将现有付款申请单保存操作后获取资金计划科目的代码直接复制拷贝至此; | ||||
|                 if ("FKBS01".equals(string)) { | ||||
|                     long sourcebillid = cas_paybill.getLong("sourcebillid"); | ||||
|                 paymentidentify = cas_paybill.getString("paymentidentify.number"); | ||||
|                 //被动 如果是被动付款,则将现有付款单保存操作后,获取资金计划科目的代码直接复制拷贝至此; | ||||
|                 if ("FKBS02".equals(paymentidentify)) { | ||||
|                     zjjhkm = xdMembersubject(cas_paybill); | ||||
|                     if(zjjhkm == null){ | ||||
|                         //科目为空,将单子上的字段值置为0 | ||||
|                         logger.info(cas_paybill.getString("billno")+"对应资金计划科目为空"); | ||||
|                         DB.update(DBRoute.of("fi"), updateZero, new Object[]{cas_paybill.getPkValue()}); | ||||
|                     }else{ | ||||
|                         //将科目id更新到表字段上 | ||||
|                         logger.info(cas_paybill.getString("billno")+"对应资金计划科目为"+zjjhkm.getLong("id")); | ||||
|                         DB.update(DBRoute.of("fi"), updateKM, new Object[]{zjjhkm.getPkValue(), cas_paybill.getPkValue()}); | ||||
|                     } | ||||
| //                    cas_paybill.set("shjh_membersubject", ); | ||||
| //                    SaveServiceHelper.save(new DynamicObject[]{cas_paybill}); | ||||
|                 }else if ("FKBS01".equals(paymentidentify)) { | ||||
|                     //主动 如果是主动付款,根据付款单查找到上游某一个付款申请单即可,再根据付款申请单对象,将现有付款申请单保存操作后获取资金计划科目的代码直接复制拷贝至此; | ||||
|                     //根据付款单查找到上游某一个付款申请单即可 | ||||
|                     DynamicObject payapply = BusinessDataServiceHelper.loadSingle(sourcebillid, "ap_payapply"); | ||||
|                     payapply = BusinessDataServiceHelper.loadSingle(cas_paybill.getLong("sourcebillid"), payapplyName); | ||||
|                     if (null != payapply) { | ||||
|                         DynamicObject xdMembersubject = xdMembersubject(payapply); | ||||
|                         payapply.set("shjh_membersubject",xdMembersubject); | ||||
|                         SaveServiceHelper.save(new DynamicObject[]{payapply}); | ||||
|                         //将现有付款申请单保存操作后获取资金计划科目的代码直接复制拷贝至此 | ||||
|                         cas_paybill.set("shjh_membersubject", xdMembersubject); | ||||
|                         SaveServiceHelper.save(new DynamicObject[]{cas_paybill}); | ||||
| //                        DynamicObject xdMembersubject = xdMembersubject(payapply); | ||||
| //                        payapply.set("shjh_membersubject",xdMembersubject); | ||||
| //                        SaveServiceHelper.save(new DynamicObject[]{payapply});//此代码是更新付款申请单的,先不更新 | ||||
|                         //将现有付款申请单保存操作后获取资金计划科目的代码直接复制拷贝至此,更新付款单上的资金计划科目 | ||||
|                         zjjhkm = getzjkmbyapply(payapply); | ||||
|                         if(zjjhkm == null){ | ||||
|                             //科目为空,将单子上的字段值置为0 | ||||
|                             logger.info(cas_paybill.getString("billno")+"对应资金计划科目为空"); | ||||
|                             DB.update(DBRoute.of("fi"), updateZero, new Object[]{cas_paybill.getPkValue()}); | ||||
|                         }else{ | ||||
|                             //将科目id更新到表字段上 | ||||
|                             logger.info(cas_paybill.getString("billno")+"对应资金计划科目为"+zjjhkm.getLong("id")); | ||||
|                             DB.update(DBRoute.of("fi"), updateKM, new Object[]{zjjhkm.getPkValue(), cas_paybill.getPkValue()}); | ||||
|                         } | ||||
| //                        cas_paybill.set("shjh_membersubject", xdMembersubject); | ||||
| //                        SaveServiceHelper.save(new DynamicObject[]{cas_paybill}); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public DynamicObject getzjkmbyapply(DynamicObject bill){ | ||||
|         //SAP应付凭证生成付款申请单后,系统自动根据配置表(shjh_request_account)带出资金计划科目 | ||||
|         QFilter qFilter = new QFilter("shjh_biztype", QCP.equals,"A");//业务类型:付款 | ||||
|         qFilter.and(new QFilter("enable", QCP.equals, "1"));//启用 | ||||
|         qFilter.and(new QFilter("status", QCP.equals, "C"));//审核 | ||||
|         //公司范围_多选基础资料 && 不包含公司 | ||||
|         DynamicObject applyorg = bill.getDynamicObject("applyorg"); | ||||
|         if (null != applyorg) { | ||||
|             Long orgid = applyorg.getLong("id"); | ||||
|             QFilter q1 = new QFilter("shjh_companys.fbasedataid", QCP.equals, orgid); | ||||
|             QFilter q2 = new QFilter("shjh_companys.fbasedataid", QCP.equals, null);//in 或者配置表公司为空 | ||||
|             QFilter q3 = new QFilter("shjh_bbhzz.fbasedataid", QCP.equals, orgid); | ||||
|             QFilter q4 = new QFilter("shjh_bbhzz.fbasedataid", QCP.equals, null);//不包含不包含公司 | ||||
|             qFilter = qFilter.and(q1.or(q2)).and(q3.or(q4)); | ||||
|         } | ||||
| 
 | ||||
|         //业务大类 && 不包含业务大类 | ||||
|         DynamicObject shjhBizbig = bill.getDynamicObject("shjh_bizbig"); | ||||
|         if (null != shjhBizbig) { | ||||
|             Long shjhBizbigid = shjhBizbig.getLong("id"); | ||||
|             QFilter q1 = new QFilter("shjh_bizbig.fbasedataid", QCP.equals, shjhBizbigid);//包含业务大类 | ||||
|             QFilter q2 = new QFilter("shjh_bizbig.fbasedataid", QCP.equals, null); | ||||
|             QFilter q3 = new QFilter("shjh_bbhywdl.fbasedataid", QCP.not_equals, shjhBizbigid);//不包含业务大类 | ||||
|             QFilter q4 = new QFilter("shjh_bbhywdl.fbasedataid", QCP.equals, null); | ||||
|             qFilter = qFilter.and(q1.or(q2)).and(q3.or(q4)); | ||||
|         }else { | ||||
|             QFilter q2 = new QFilter("shjh_bizbig.fbasedataid", QCP.equals, null); | ||||
|             qFilter = qFilter.and(q2); | ||||
|         } | ||||
|         //业务小类 | ||||
|         DynamicObject shjhbizsmall = bill.getDynamicObject("shjh_basedatafield"); | ||||
|         if (null != shjhbizsmall) { | ||||
|             Long shjhbizsmallid = shjhbizsmall.getLong("id"); | ||||
|             QFilter q1 = new QFilter("shjh_bizsmall.fbasedataid", QCP.equals, shjhbizsmallid); | ||||
|             QFilter q2 = new QFilter("shjh_bizsmall.fbasedataid", QCP.equals, null); | ||||
|             qFilter = qFilter.and(q1.or(q2)); | ||||
|         }else { | ||||
|             QFilter q2 = new QFilter("shjh_bizsmall.fbasedataid", QCP.equals, null); | ||||
|             qFilter = qFilter.and(q2); | ||||
|         } | ||||
|         //原因码_多选基础资料 | ||||
|         DynamicObject shjhYym = bill.getDynamicObject("shjh_yym"); | ||||
|         if (null != shjhYym) { | ||||
|             Long yymid = shjhYym.getLong("id"); | ||||
|             QFilter q1 = new QFilter("shjh_yym.fbasedataid", QCP.equals, yymid); | ||||
|             QFilter q2 = new QFilter("shjh_yym.fbasedataid", QCP.equals, null); | ||||
|             qFilter = qFilter.and(q1.or(q2)); | ||||
|         }else { | ||||
|             QFilter q2 = new QFilter("shjh_yym.fbasedataid", QCP.equals, null); | ||||
|             qFilter = qFilter.and(q2); | ||||
|         } | ||||
|         //单子为true 对应配置表是/否  为false 对应配置表否 | ||||
|         //是否充值类 | ||||
|         boolean shjhWhetherrechargecateg = bill.getBoolean("shjh_whetherrechargecateg"); | ||||
|         if (!shjhWhetherrechargecateg) { | ||||
|             QFilter q2 = new QFilter("shjh_czl", QCP.equals, false); | ||||
|             qFilter = qFilter.and(q2); | ||||
|         } | ||||
|         //是否自行采购 | ||||
|         boolean shjhZxcg = bill.getBoolean("shjh_zxcg"); | ||||
|         if (!shjhZxcg) { | ||||
|             QFilter q3 = new QFilter("shjh_zxcg", QCP.equals, false); | ||||
|             qFilter = qFilter.and(q3); | ||||
|         } | ||||
|         //事业部_多选基础资料,通过申请单的二级部门去映射表查询(shjh_ejbm_syb) | ||||
|         DynamicObject shjhSecondarydept = bill.getDynamicObject("shjh_secondarydept"); | ||||
|         if (null != shjhSecondarydept) { | ||||
|             Long deptid = shjhSecondarydept.getLong("id"); | ||||
|             QFilter q5 = new QFilter("shjh_orgdept.id", QCP.equals, deptid); | ||||
|             DynamicObject ejbm_syb = BusinessDataServiceHelper.loadSingle("shjh_ejbm_syb", | ||||
|                     "shjh_orgdept,shjh_division", q5.toArray()); | ||||
|             if (null != ejbm_syb) { | ||||
|                 DynamicObject shjhDivision = ejbm_syb.getDynamicObject("shjh_division"); | ||||
|                 if (null != shjhDivision) { | ||||
|                     Long divisionid = shjhDivision.getLong("id"); | ||||
|                     QFilter q6 = new QFilter("shjh_division.fbasedataid", QCP.equals, divisionid); | ||||
|                     QFilter q7 = new QFilter("shjh_division.fbasedataid", QCP.equals, null); | ||||
|                     qFilter = qFilter.and(q6.or(q7)); | ||||
|                 }else { | ||||
|                     QFilter q7 = new QFilter("shjh_division.fbasedataid", QCP.equals, null); | ||||
|                     qFilter = qFilter.and(q7); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         //会计科目_多选基础资料 | ||||
|         DynamicObject shjhSapkjkm = bill.getDynamicObject("shjh_sapkjkm"); | ||||
|         if (null != shjhSapkjkm) { | ||||
| //            Long kjkmid = shjhSapkjkm.getLong("id"); | ||||
|             QFilter q6 = new QFilter("shjh_kjkm.fbasedataid.number", QCP.equals, shjhSapkjkm.getString("number")); | ||||
|             QFilter q7 = new QFilter("shjh_kjkm.fbasedataid.number", QCP.equals, null); | ||||
|             qFilter = qFilter.and(q6.or(q7)); | ||||
|         }else { | ||||
|             QFilter q7 = new QFilter("shjh_kjkm.fbasedataid.number", QCP.equals, null); | ||||
|             qFilter = qFilter.and(q7); | ||||
|         } | ||||
|         //供应商_多选基础资料  分录 | ||||
|         DynamicObjectCollection entrys = bill.getDynamicObjectCollection("entry"); | ||||
|         if (!entrys.isEmpty()) { | ||||
|             DynamicObject entry = entrys.get(0); | ||||
|             String eAsstacttype = entry.getString("e_asstacttype"); | ||||
|             if ("bd_supplier".equals(eAsstacttype)) { | ||||
|                 //供应商 && 不包含供应商 | ||||
|                 DynamicObject eAsstact = entry.getDynamicObject("e_asstact");//往来户 | ||||
|                 if (null != eAsstact) { | ||||
|                     Long eAsstactid = eAsstact.getLong("id"); | ||||
|                     QFilter q11 = new QFilter("shjh_supplier.fbasedataid", QCP.equals, eAsstactid);//包含供应商 | ||||
|                     QFilter q22 = new QFilter("shjh_supplier.fbasedataid", QCP.equals, null); | ||||
|                     QFilter q33 = new QFilter("shjh_bbhgys.fbasedataid", QCP.equals, eAsstactid);//不包含供应商 | ||||
|                     QFilter q44 = new QFilter("shjh_bbhgys.fbasedataid", QCP.equals, null); | ||||
|                     qFilter = qFilter.and(q11.or(q22)).and(q33.or(q44)); | ||||
|                 }else { | ||||
|                     QFilter q22 = new QFilter("shjh_supplier.fbasedataid", QCP.equals, null); | ||||
|                     qFilter = qFilter.and(q22); | ||||
|                 } | ||||
|             } | ||||
|             //客户(bd_customer)||供应商(bd_supplier) | ||||
|             if ("bd_customer".equals(eAsstacttype)) { | ||||
|                 //客户 && 不包含客户 | ||||
|                 DynamicObject eAsstact = entry.getDynamicObject("e_asstact");//往来户 | ||||
|                 if (null != eAsstact) { | ||||
|                     Long eAsstactid = eAsstact.getLong("id"); | ||||
|                     QFilter q11 = new QFilter("shjh_kh.fbasedataid", QCP.equals, eAsstactid);//包含客户 | ||||
|                     QFilter q22 = new QFilter("shjh_kh.fbasedataid", QCP.equals, null); | ||||
|                     QFilter q33 = new QFilter("shjh_bbhkh.fbasedataid", QCP.equals, eAsstactid);//不包含客户 | ||||
|                     QFilter q44 = new QFilter("shjh_bbhkh.fbasedataid", QCP.equals, null); | ||||
|                     qFilter = qFilter.and(q11.or(q22)).and(q33.or(q44)); | ||||
|                 }else { | ||||
|                     QFilter q22 = new QFilter("shjh_kh.fbasedataid", QCP.equals, null); | ||||
|                     qFilter = qFilter.and(q22); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         //不包含币种 currency | ||||
|         DynamicObject currency = bill.getDynamicObject("paycurrency"); | ||||
|         if (null != currency) { | ||||
|             Long currencyid = currency.getLong("id"); | ||||
|             QFilter q11 = new QFilter("shjh_bbhbz.fbasedataid", QCP.equals, currencyid);//不包含币种 | ||||
|             QFilter q22 = new QFilter("shjh_bbhbz.fbasedataid", QCP.equals, null); | ||||
|             qFilter = qFilter.and(q11.or(q22)); | ||||
|         } | ||||
|         //提单人所属部门(付款单申请) && 提单人不属于部门(付款单申请) | ||||
|         DynamicObject secondarydept = bill.getDynamicObject("shjh_secondarydept"); | ||||
|         if (null != secondarydept) { | ||||
|             Long secondarydeptid = secondarydept.getLong("id"); | ||||
|             QFilter q1 = new QFilter("shjh_tdrssbm.fbasedataid", QCP.equals, secondarydeptid);//提单人所属部门(付款单申请) | ||||
|             QFilter q2 = new QFilter("shjh_tdrssbm.fbasedataid", QCP.equals, null); | ||||
|             QFilter q3 = new QFilter("shjh_tdrbsybm.fbasedataid", QCP.equals, secondarydeptid);//提单人不属于部门(付款单申请) | ||||
|             QFilter q4 = new QFilter("shjh_tdrbsybm.fbasedataid", QCP.equals, null); | ||||
|             qFilter = qFilter.and(q1.or(q2)).and(q3.or(q4)); | ||||
|         }else { | ||||
|             QFilter q2 = new QFilter("shjh_tdrssbm.fbasedataid", QCP.equals, null); | ||||
|             qFilter = qFilter.and(q2); | ||||
|         } | ||||
| 
 | ||||
|         DynamicObject[] accounts = BusinessDataServiceHelper.load("shjh_request_account", "id," + | ||||
|                 "shjh_membersubject,shjh_cgz,shjh_bbhcgz,shjh_billtype,shjh_bbhdjlx", qFilter.toArray()); | ||||
| 
 | ||||
|         if (accounts.length > 1) { | ||||
|             // 根据生效日期,失效日期区间,判断当前时间满足的数据 | ||||
|             Date currentDate = bill.getDate("applydate");//申请日期 | ||||
|             QFilter startDateFilter = new QFilter("shjh_begindate", QCP.less_equals, currentDate); | ||||
|             QFilter endDateFilter = new QFilter("shjh_enddate", QCP.large_equals, currentDate); | ||||
|             QFilter newFilter = qFilter.and(startDateFilter).and(endDateFilter); | ||||
|             //优先级为高的 | ||||
|             accounts = BusinessDataServiceHelper.load("shjh_request_account", "id,shjh_cgz,shjh_bbhcgz", newFilter.toArray(),"shjh_priority"); | ||||
|         } | ||||
|         // 转换为 List 以便支持 remove 操作 | ||||
|         List<DynamicObject> configList = new ArrayList<>(Arrays.asList(accounts)); | ||||
| 
 | ||||
|         // 采购组shjh_procurementteam && 不包含采购组 | ||||
|         String shjhBhcgz = bill.getString("shjh_procurementteam"); | ||||
|         QFilter filter = new QFilter("number", QCP.equals, shjhBhcgz); | ||||
|         DynamicObject shjh_cgz = BusinessDataServiceHelper.loadSingle("shjh_cgz", filter.toArray()); | ||||
| 
 | ||||
|         if (shjh_cgz != null) { | ||||
|             long cgzid = shjh_cgz.getLong("id"); | ||||
|             Iterator<DynamicObject> iterator = configList.iterator(); | ||||
|             while (iterator.hasNext()) { | ||||
|                 DynamicObject account = iterator.next(); | ||||
|                 // 检查采购组 | ||||
|                 boolean isbh = false; | ||||
|                 DynamicObjectCollection shjh_cgzs = account.getDynamicObjectCollection("shjh_cgz"); | ||||
|                 for (DynamicObject shjhCgz : shjh_cgzs) { | ||||
|                     DynamicObject fbasedataid = shjhCgz.getDynamicObject("fbasedataid"); | ||||
|                     if (fbasedataid != null && fbasedataid.getLong("id") == cgzid) { | ||||
|                         isbh = true; | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|                 if (!isbh && !shjh_cgzs.isEmpty()) { | ||||
|                     iterator.remove(); | ||||
|                     continue; | ||||
|                 } | ||||
| 
 | ||||
|                 // 检查不包含采购组 | ||||
|                 DynamicObjectCollection shjh_bbhcgzs = account.getDynamicObjectCollection("shjh_bbhcgz"); | ||||
|                 for (DynamicObject shjhBbhcgz : shjh_bbhcgzs) { | ||||
|                     DynamicObject fbasedataid = shjhBbhcgz.getDynamicObject("fbasedataid"); | ||||
|                     if (fbasedataid != null && fbasedataid.getLong("id") == cgzid) { | ||||
|                         iterator.remove(); | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         // 外部系统单据类型_多选下拉 && 不包含单据类型 | ||||
|         String shjhExternalsystemdocume = bill.getString("shjh_externalsystemdocume"); | ||||
|         // 使用迭代器遍历以安全删除元素 | ||||
|         Iterator<DynamicObject> iterator = configList.iterator(); | ||||
|         while (iterator.hasNext()) { | ||||
|             DynamicObject account = iterator.next(); | ||||
|             account = BusinessDataServiceHelper.loadSingle(account.getPkValue(), "shjh_request_account"); | ||||
|             String bhdjlx = account.getString("shjh_billtype"); | ||||
|             // 外部系统单据类型_不包含剔除 | ||||
|             if (!bhdjlx.contains(shjhExternalsystemdocume) && StringUtils.isNotEmpty(bhdjlx)) { | ||||
|                 iterator.remove(); | ||||
|                 continue; | ||||
|             } | ||||
| 
 | ||||
|             String bbhdjlx = account.getString("shjh_bbhdjlx"); | ||||
|             // 不包含单据类型_包含剔除 | ||||
|             if (bbhdjlx.contains(shjhExternalsystemdocume)&& StringUtils.isNotEmpty(shjhExternalsystemdocume)) { | ||||
|                 iterator.remove(); | ||||
|             } | ||||
|         } | ||||
|         if (!configList.isEmpty()) { | ||||
|             // 处理找到符合条件的账户 | ||||
|             DynamicObject account = configList.get(0); | ||||
|             account = BusinessDataServiceHelper.loadSingle(account.getPkValue(), "shjh_request_account"); | ||||
|             return account.getDynamicObject("shjh_membersubject"); | ||||
|         } else { | ||||
|             logger.info("付款单全量更新任务没有找到符合条件的资金计划科目"); | ||||
|         } | ||||
| 
 | ||||
|         return null; | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue