diff --git a/main/java/shkd/repc/resm/formplugin/ContractListDateFilterPlugin.java b/main/java/shkd/repc/resm/formplugin/ContractListDateFilterPlugin.java index a24289d..dcc1a5b 100644 --- a/main/java/shkd/repc/resm/formplugin/ContractListDateFilterPlugin.java +++ b/main/java/shkd/repc/resm/formplugin/ContractListDateFilterPlugin.java @@ -8,6 +8,8 @@ import kd.bos.dataentity.resource.ResManager; import kd.bos.dataentity.utils.StringUtils; import kd.bos.entity.EntityMetadataCache; import kd.bos.entity.datamodel.IDataModel; +import kd.bos.entity.datamodel.events.ChangeData; +import kd.bos.entity.datamodel.events.PropertyChangedArgs; import kd.bos.form.container.Tab; import kd.bos.form.control.Control; import kd.bos.orm.query.QCP; @@ -102,48 +104,80 @@ public class ContractListDateFilterPlugin extends AbstractBillPlugIn implements if (contractEntries.isEmpty()) { this.getView().showTipNotification(ResManager.loadKDString("没有符合条件的合同,请检查。", "EvalPlanEdit_13", "repc-resm-formplugin", new Object[0])); - Tab tabap = (Tab)this.getView().getControl("tabap"); + Tab tabap = (Tab) this.getView().getControl("tabap"); tabap.activeTab("tab_info"); - return; } + } + } - for (int i = 0; i < contractEntries.size(); i++) { - DynamicObject contractEntry = contractEntries.get(i); - DynamicObject eyContract = contractEntry.getDynamicObject("ey_contract"); - if (eyContract != null) { - DynamicObject contract = BusinessDataServiceHelper.loadSingle(eyContract.getPkValue(), "resm_contract_book", "id,sign_date,contract,ismaincontract,maincontract"); - Date signDate = contract.getDate("sign_date");// 签约日期 - Calendar calendar = Calendar.getInstance(); - calendar.setTime(signDate); - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - calendar.set(Calendar.MILLISECOND, 0); - signDate = calendar.getTime(); - model.setValue("qeug_sign_date", signDate, i); + @Override + public void propertyChanged(PropertyChangedArgs e) { + String name = e.getProperty().getName(); + if ("ey_contract".equals(name)) { + IDataModel model = this.getModel(); + ChangeData changeData = e.getChangeSet()[0]; + int rowIndex = changeData.getRowIndex(); + DynamicObject eyContract = (DynamicObject) model.getValue("ey_contract", rowIndex); - String evalTypeNum = contractEntry.getString("ey_eval_type.number");// 评估类型 - if (!"007".equals(evalTypeNum)) continue; + if (eyContract == null) { + model.setValue("qeug_sign_date", null, rowIndex); + model.setValue("qeug_bizdate", null, rowIndex); + } else { + DynamicObject contract = BusinessDataServiceHelper.loadSingle(eyContract.getPkValue(), "resm_contract_book", "id,sign_date,contract,ismaincontract,maincontract,bizstatus"); + Date signDate = contract.getDate("sign_date");// 签约日期 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(signDate); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + signDate = calendar.getTime(); + model.setValue("qeug_sign_date", signDate, rowIndex); - DynamicObject contractSettle; - boolean isMainContract = contract.getBoolean("ismaincontract"); - DynamicObject mainContract = contract.getDynamicObject("maincontract");// 关联主合同 - if (!isMainContract && mainContract != null) { - mainContract = BusinessDataServiceHelper.loadSingle(mainContract.getPkValue(), "resm_contract_book", "id,sign_date,contract"); - Long contractId = mainContract.getLong("contract"); - QFilter idQF = new QFilter("contractbill", QCP.equals, contractId); - contractSettle = BusinessDataServiceHelper.loadSingle("recon_consettlebill", "id,bizdate", idQF.toArray());// 合同结算 - } else { - Long contractId = contract.getLong("contract"); - QFilter idQF = new QFilter("contractbill", QCP.equals, contractId); - contractSettle = BusinessDataServiceHelper.loadSingle("recon_consettlebill", "id,bizdate", idQF.toArray());// 合同结算 - } - if (contractSettle != null) { - Date bizDate = contractSettle.getDate("bizdate");// 结算日期 - model.setValue("qeug_bizdate", bizDate, i); - } + String evalType = ""; + List evalTypeList = this.getEvalTypeByContract(contract); + if (!evalTypeList.isEmpty()) { + DynamicObject dynamicObject = evalTypeList.get(0); + if (dynamicObject != null) evalType = dynamicObject.getString("number"); + } + + if (!"007".equals(evalType)) return; + + DynamicObject contractSettle; + boolean isMainContract = contract.getBoolean("ismaincontract"); + DynamicObject mainContract = contract.getDynamicObject("maincontract");// 关联主合同 + if (!isMainContract && mainContract != null) { + mainContract = BusinessDataServiceHelper.loadSingle(mainContract.getPkValue(), "resm_contract_book", "id,sign_date,contract"); + Long contractId = mainContract.getLong("contract"); + QFilter idQF = new QFilter("contractbill", QCP.equals, contractId); + contractSettle = BusinessDataServiceHelper.loadSingle("recon_consettlebill", "id,bizdate", idQF.toArray());// 合同结算 + } else { + Long contractId = contract.getLong("contract"); + QFilter idQF = new QFilter("contractbill", QCP.equals, contractId); + contractSettle = BusinessDataServiceHelper.loadSingle("recon_consettlebill", "id,bizdate", idQF.toArray());// 合同结算 + } + if (contractSettle != null) { + Date bizDate = contractSettle.getDate("bizdate");// 结算日期 + model.setValue("qeug_bizdate", bizDate, rowIndex); } } } } + + protected List getEvalTypeByContract(DynamicObject contract) { + String bizStatus = contract.getString("bizstatus"); + QFilter qFilter = new QFilter("enable", "=", true); + qFilter.and("stage", "=", "2"); + DynamicObject[] evalTypeArr = BusinessDataServiceHelper.load("resm_evaltype", "stage,bizstatus", qFilter.toArray(), "number"); + List evalTypeList = (List)Arrays.stream(evalTypeArr).filter((item) -> { + return item.getString("bizstatus").contains(bizStatus); + }).collect(Collectors.toList()); + if (evalTypeList.isEmpty()) { + evalTypeList = (List)Arrays.stream(evalTypeArr).filter((item) -> { + return StringUtils.isEmpty(item.getString("bizstatus")); + }).collect(Collectors.toList()); + } + + return evalTypeList; + } } \ No newline at end of file