diff --git a/main/java/shjh/jhzj7/fi/fi/plugin/operate/RecBillSubmitOperation.java b/main/java/shjh/jhzj7/fi/fi/plugin/operate/RecBillSubmitOperation.java index 11b0374..5349828 100644 --- a/main/java/shjh/jhzj7/fi/fi/plugin/operate/RecBillSubmitOperation.java +++ b/main/java/shjh/jhzj7/fi/fi/plugin/operate/RecBillSubmitOperation.java @@ -12,7 +12,7 @@ import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; import kd.sdk.plugin.Plugin; -import java.util.Date; +import java.util.*; /** * 单据操作插件 @@ -40,76 +40,224 @@ public class RecBillSubmitOperation extends AbstractOperationServicePlugIn imple private DynamicObject xdMembersubject(DynamicObject bill){ //收款单,系统自动根据配置表(shjh_pay_account)带出资金计划科目 + Date currentDate = new Date(); QFilter qFilter = new QFilter("shjh_biztype", QCP.equals,"B");//业务类型:收款 - //公司范围_多选基础资料 - DynamicObject openorg = bill.getDynamicObject("openorg"); - if (null != openorg) { - Long orgid = openorg.getLong("id"); - QFilter q1 = new QFilter("shjh_companys.fbasedataid", QCP.equals, orgid); - qFilter = qFilter.and(q1); - } - //业务大类 - DynamicObject shjhBizbig = bill.getDynamicObject("shjh_bizebig"); - if (null != shjhBizbig) { - Long shjhBizbigid = shjhBizbig.getLong("id"); - QFilter q2 = new QFilter("shjh_bizbig.fbasedataid", QCP.equals, shjhBizbigid); - qFilter = qFilter.and(q2); - } + qFilter.and(new QFilter("status",QCP.equals,"C"));//审核状态 + qFilter.and(new QFilter("shjh_begindate", QCP.less_equals, currentDate)); + qFilter.and(new QFilter("shjh_enddate", QCP.large_equals, currentDate)); + qFilter.and(new QFilter("number", QCP.equals, "test010")); + DynamicObject[] load = BusinessDataServiceHelper.load("shjh_pay_account", "id,shjh_priority,shjh_companys,shjh_bizbig,shjh_bizsmall,shjh_khzw", qFilter.toArray()); + if (load.length>0){ + List loadList = new ArrayList<>(Arrays.asList(load)); + Iterator iterator = loadList.iterator(); + while (iterator.hasNext()){ + DynamicObject dynamicObject = iterator.next(); + //公司范围 + DynamicObjectCollection companyCollection = dynamicObject.getDynamicObjectCollection("shjh_companys"); + if (companyCollection.size()!=0){ + //是否保留 + boolean isKeep=false; + DynamicObject openOrg = bill.getDynamicObject("openorg"); + for (DynamicObject object : companyCollection) { + if (openOrg!=null){ + Long orgId = openOrg.getLong("id"); + //匹配到就标记 + if (orgId.compareTo((Long) object.getPkValue())==0){ + isKeep=true; + break; + } + } + } + if (!isKeep){ + iterator.remove(); + continue; + } + } + //不包含公司 + DynamicObjectCollection notCompanyCollection = dynamicObject.getDynamicObjectCollection("shjh_bbhzz"); + if (notCompanyCollection.size()!=0){ + //是否保留 + boolean isKeep=true; + DynamicObject openOrg = bill.getDynamicObject("openorg"); + for (DynamicObject object : notCompanyCollection) { + if (openOrg!=null){ + Long orgId = openOrg.getLong("id"); + //匹配到就移除和包含相反 + if (orgId.compareTo((Long) object.getPkValue())==0){ + isKeep=false; + break; + } + } + } + if (!isKeep){ + iterator.remove(); + continue; + } + } - //业务小类 - DynamicObject shjhbizsmall = bill.getDynamicObject("shjh_bizsmall"); - if (null != shjhbizsmall) { - Long shjhbizsmallid = shjhbizsmall.getLong("id"); - QFilter q3 = new QFilter("shjh_bizsmall.fbasedataid", QCP.equals, shjhbizsmallid); - qFilter = qFilter.and(q3); - } - //成本中心 shjh_costcenter - DynamicObject shjhCostcenter = bill.getDynamicObject("shjh_costcenter"); - if (null != shjhCostcenter) { - Long costcenterid = shjhCostcenter.getLong("id"); - QFilter q4 = new QFilter("shjh_cc.fbasedataid", QCP.equals, costcenterid); - qFilter = qFilter.and(q4); - } - - //原因码 shjh_reasoncode - //会计科目 shjh_coaitemcode - DynamicObjectCollection entrys = bill.getDynamicObjectCollection("entry");//付款明细 - if (!entrys.isEmpty()) { - DynamicObject entry = entrys.get(0); - DynamicObject shjhYym = entry.getDynamicObject("shjh_yym"); - if (null != shjhYym) { - Long yymid = shjhYym.getLong("id"); - QFilter q5 = new QFilter("shjh_yym.fbasedataid", QCP.equals, yymid); - qFilter = qFilter.and(q5); + //业务大类 + DynamicObjectCollection bizBigCollection = dynamicObject.getDynamicObjectCollection("shjh_bizbig"); + if (bizBigCollection.size()!=0){ + boolean isKeep=false; + DynamicObject bizBig = bill.getDynamicObject("shjh_bizebig"); + for (DynamicObject object : bizBigCollection) { + if (bizBig!=null){ + Long bizBigId = bizBig.getLong("id"); + //匹配到就标记 + if (bizBigId.compareTo((Long) object.getPkValue())==0){ + isKeep=true; + break; + } + } + } + if (!isKeep){ + iterator.remove(); + continue; + } + } + //业务小类 + DynamicObjectCollection bizSmallCollection = dynamicObject.getDynamicObjectCollection("shjh_bizsmall"); + if (bizSmallCollection.size()!=0){ + boolean isKeep=false; + DynamicObject bizSmall = bill.getDynamicObject("shjh_bizsmall"); + for (DynamicObject object : bizSmallCollection) { + if (bizSmall!=null){ + Long bizBigId = bizSmall.getLong("id"); + //匹配到就标记 + if (bizBigId.compareTo((Long) object.getPkValue())==0){ + isKeep=true; + break; + } + } + } + if (!isKeep){ + iterator.remove(); + continue; + } + } } - - DynamicObject shjhSapkjkm = entry.getDynamicObject("shjh_accountsap"); - if (null != shjhSapkjkm) { - Long kjkmid = shjhSapkjkm.getLong("id"); - QFilter q6 = new QFilter("shjh_kjkm.fbasedataid", QCP.equals, kjkmid); - qFilter = qFilter.and(q6); - } - } + //TODO:对剩余数据做处理 - DynamicObject[] accounts = BusinessDataServiceHelper.load("shjh_pay_account", "id,shjh_membersubject", qFilter.toArray()); - if (accounts.length > 1) { - // 根据生效日期,失效日期区间,判断当前时间满足的数据 - Date currentDate = new Date(); - 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_pay_account", "id", newFilter.toArray()); - } - if (accounts.length > 0) { - // 处理找到符合条件的账户 - DynamicObject account = accounts[0]; - account = BusinessDataServiceHelper.loadSingle(account.getPkValue(), "shjh_pay_account"); - return account.getDynamicObject("shjh_membersubject"); - } else { - log.info("没有找到符合条件的资金计划科目"); - } + +// //公司范围_多选基础资料 +// DynamicObject openorg = bill.getDynamicObject("openorg"); +// if (null != openorg) { +// Long orgid = openorg.getLong("id"); +// QFilter q1 = new QFilter("shjh_companys.fbasedataid", QCP.equals, orgid); +// QFilter q2 = new QFilter("shjh_companys.fbasedataid", QCP.equals, null); +// 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)); +// }else { +// QFilter q2 = new QFilter("shjh_companys.fbasedataid", QCP.equals, null); +// qFilter = qFilter.and(q2); +// } +// BusinessDataServiceHelper.load("shjh_pay_account", "id,shjh_priority,shjh_khzw", qFilter.toArray()); +// //业务大类 +// DynamicObject shjhBizbig = bill.getDynamicObject("shjh_bizebig"); +// if (null != shjhBizbig) { +// Long shjhBizbigid = shjhBizbig.getLong("id"); +// QFilter q2 = new QFilter("shjh_bizbig.fbasedataid", QCP.equals, shjhBizbigid); +// QFilter q3 = new QFilter("shjh_bizbig.fbasedataid", QCP.equals, null); +// QFilter q4 = new QFilter("shjh_bbhywdl.fbasedataid", QCP.equals, shjhBizbigid); +// QFilter q5 = new QFilter("shjh_bbhywdl.fbasedataid", QCP.equals, null); +// qFilter = qFilter.and(q2.or(q3)).and(q4.or(q5)); +// } +// +// //业务小类 +// DynamicObject shjhbizsmall = bill.getDynamicObject("shjh_bizsmall"); +// 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)); +// } +// +// //成本中心 shjh_costcenter +// DynamicObject shjhCostcenter = bill.getDynamicObject("shjh_costcenter"); +// if (null != shjhCostcenter) { +// Long costcenterid = shjhCostcenter.getLong("id"); +// QFilter q4 = new QFilter("shjh_cc.fbasedataid", QCP.equals, costcenterid); +// qFilter = qFilter.and(q4); +// } +// +// //原因码 shjh_reasoncode +// //会计科目 shjh_coaitemcode +// DynamicObjectCollection entrys = bill.getDynamicObjectCollection("entry");//付款明细 +// if (!entrys.isEmpty()) { +// DynamicObject entry = entrys.get(0); +// DynamicObject shjhYym = entry.getDynamicObject("shjh_yym"); +// if (null != shjhYym) { +// Long yymid = shjhYym.getLong("id"); +// QFilter q5 = new QFilter("shjh_yym.fbasedataid", QCP.equals, yymid); +// qFilter = qFilter.and(q5); +// } +// +// DynamicObject shjhSapkjkm = entry.getDynamicObject("shjh_accountsap"); +// if (null != shjhSapkjkm) { +// Long kjkmid = shjhSapkjkm.getLong("id"); +// QFilter q6 = new QFilter("shjh_kjkm.fbasedataid", QCP.equals, kjkmid); +// qFilter = qFilter.and(q6); +// } +// +// } +// +// +// //付款人类型 +// String payerType = bill.getString("payertype"); +// if (null!=payerType){ +// long payerId = bill.getLong("payer"); +// if (payerId!=0L){ +// switch (payerType){ +// case "bd_customer": +// QFilter q1 = new QFilter("shjh_bhkh.fbasedataid", QCP.equals, payerId); +// QFilter q2 = new QFilter("shjh_bhkh.fbasedataid", QCP.equals, null); +// QFilter q3 = new QFilter("shjh_bbhkh.fbasedataid", QCP.equals, payerId); +// QFilter q4 = new QFilter("shjh_bbhkh.fbasedataid", QCP.equals, null); +// qFilter=qFilter.and(q1.or(q2)).and(q3.or(q4)); +// break; +// case "bd_supplier": +// QFilter q5 = new QFilter("shjh_bhgys.fbasedataid", QCP.equals, payerId); +// QFilter q6 = new QFilter("shjh_bhgys.fbasedataid", QCP.equals, null); +// QFilter q7 = new QFilter("shjh_bbhgys.fbasedataid", QCP.equals, payerId); +// QFilter q8 = new QFilter("shjh_bbhgys.fbasedataid", QCP.equals, null); +// qFilter=qFilter.and(q5.or(q6)).and(q7.or(q8)); +// break; +// default: +// break; +// } +// } +// } +// +// //不包含币种 +// DynamicObject currency = bill.getDynamicObject("currency"); +// if (currency!=null){ +// long currencyId = currency.getLong("id"); +// QFilter q1 = new QFilter("shjh_bbhbz.fbasedataid", QCP.equals, currencyId); +// QFilter q2 = new QFilter("shjh_bbhbz.fbasedataid", QCP.equals, null); +// qFilter=qFilter.and(q1.or(q2)); +// } +// +// DynamicObject[] accounts = BusinessDataServiceHelper.load("shjh_pay_account", "id,shjh_membersubject", qFilter.toArray()); +// if (accounts.length > 1) { +// // 根据生效日期,失效日期区间,判断当前时间满足的数据 +// Date currentDate = new Date(); +// 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_pay_account", "id,shjh_priority,shjh_khzw", newFilter.toArray()); +// } +// if (accounts.length > 0) { +// // 处理找到符合条件的账户 +// //按优先级排序,高中低取高,如果存在多条同一优先级级的数据,默认取第一条 +// DynamicObject account = accounts[0]; +// account = BusinessDataServiceHelper.loadSingle(account.getPkValue(), "shjh_pay_account"); +// return account.getDynamicObject("shjh_membersubject"); +// } else { +// log.info("没有找到符合条件的资金计划科目"); +// } return null; }