生成的评估清单里的合同增加根据评估期间过滤

This commit is contained in:
ggxl 2024-11-15 11:21:50 +08:00
parent 7ff7e30065
commit 6625d3699a
1 changed files with 149 additions and 0 deletions

View File

@ -0,0 +1,149 @@
package shkd.repc.resm.formplugin;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DataEntityBase;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
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.form.container.Tab;
import kd.bos.form.control.Control;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.repc.common.util.resm.eval.EvalUtils;
import kd.sdk.plugin.Plugin;
import java.util.*;
import java.util.stream.Collectors;
/**
* 单据界面插件
*/
public class ContractListDateFilterPlugin extends AbstractBillPlugIn implements Plugin {
/*
* 评估计划-生成的评估清单里的合同增加根据评估期间过滤
* 合同执行中合同签约日期 <= 评估结束日期
* 合同已结算评估开始日期 <= 合同结算日期 <= 评估结束日期
* */
@Override
public void registerListener(EventObject e) {
this.addClickListeners("btn_contractlist");
}
@Override
public void click(EventObject evt) {
super.click(evt);
IDataModel model = this.getModel();
Date startTime = (Date) model.getValue("interval_starttime");// 评估开始日期
Date endTime = (Date) model.getValue("interval_endtime");// 评估结束日期
DynamicObjectCollection contractEntries = model.getEntryEntity("contract_entry");
if (contractEntries != null && !contractEntries.isEmpty()) {
if (endTime != null) {
ArrayList<DynamicObject> deleteEntries = new ArrayList<>();
for (DynamicObject contractEntry : contractEntries) {
DynamicObject eyContract = contractEntry.getDynamicObject("ey_contract");
String evalTypeNum = contractEntry.getString("ey_eval_type.number");// 评估类型
if (eyContract != null) {
DynamicObject contract = BusinessDataServiceHelper.loadSingle(eyContract.getPkValue(), "resm_contract_book", "id,sign_date,contract,ismaincontract,maincontract");
if ("008".equals(evalTypeNum)) {// 执行中
Date signDate = contract.getDate("sign_date");// 签约日期
if (signDate != null) {
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();
if (!signDate.before(endTime))
deleteEntries.add(contractEntry);
}
} else if ("007".equals(evalTypeNum) && startTime != null) {// 已结算
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");// 结算日期
if (bizDate != null) {
if (bizDate.before(startTime) || bizDate.after(endTime))
deleteEntries.add(contractEntry);
}
}
}
}
}
if (!deleteEntries.isEmpty()) {
for (DynamicObject deleteEntry : deleteEntries) {
contractEntries.remove(deleteEntry);
}
this.getView().updateView("contract_entry");
}
}
if (contractEntries.isEmpty()) {
this.getView().showTipNotification(ResManager.loadKDString("没有符合条件的合同,请检查。", "EvalPlanEdit_13", "repc-resm-formplugin", new Object[0]));
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);
String evalTypeNum = contractEntry.getString("ey_eval_type.number");// 评估类型
if (!"007".equals(evalTypeNum)) continue;
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);
}
}
}
}
}
}