单据类型关联约束付款事项代码提交01

This commit is contained in:
zengweihai 2024-06-13 11:04:02 +08:00
parent c1a2339806
commit 1f6eb6a331
1 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,100 @@
package shkd.fi.er.plugin.formplugin;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.form.field.BasedataEdit;
import kd.bos.form.field.events.BeforeF7SelectEvent;
import kd.bos.form.field.events.BeforeF7SelectListener;
import kd.bos.list.ListShowParameter;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import shkd.cosmic.cxkg.task.HrmDepartmentTaskImpl;
import java.util.ArrayList;
import java.util.EventObject;
/**
* 单据界面插件
*/
public class CommonBillOsPaymentBillFormPlugin extends AbstractBillPlugIn implements BeforeF7SelectListener,Plugin {
private static Logger logger = LoggerFactory.getLogger(HrmDepartmentTaskImpl.class);
String entityName;
@Override
public void initialize() {
super.initialize();
entityName = this.getModel().getDataEntityType().getDisplayName().getLocaleValue();
logger.info("此单据类型为:"+entityName);
}
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
if (entityName.equals("员工借款单") || entityName.equals("员工还款单")){
BasedataEdit edit = this.getView().getControl("shkd_paymentitem");
if (edit != null){
edit.addBeforeF7SelectListener(this);
}
logger.info("此单据类型为员工借款单或员工还款单");
}else {
BasedataEdit edit = this.getView().getControl("shkd_payment");
if (edit != null){
edit.addBeforeF7SelectListener(this);
}
logger.info("此单据类型不为员工借款单、员工还款单");
}
}
@Override
public void beforeF7Select(BeforeF7SelectEvent beforeF7SelectEvent) {
String name = beforeF7SelectEvent.getProperty().getName();
if (name.equals("shkd_payment") || name.equals("shkd_paymentitem")){
String billType = "";
//赋值单据类型
if (entityName.equals("对公报销单")){
DynamicObject shkd_billtype = (DynamicObject) this.getModel().getValue("shkd_billtypefield");
billType = shkd_billtype.getString("name");
logger.info("此单据为对公报销单,额外需取单据类型值,单据类型字段编码为shkd_billtypefield___"+billType);
} else if (entityName.equals("预付单")) {
DynamicObject shkd_billtype = (DynamicObject) this.getModel().getValue("stdbilltype");
billType = shkd_billtype.getString("name");
logger.info("此单据为预付单,额外需取单据类型值,单据类型字段编码为stdbilltype___"+billType);
}else {
billType = entityName;
logger.info("单据类型就是单据名称");
}
//设置付款事项约束
if (billType.length() > 0){//当单据类型字段不为空时
QFilter QF = new QFilter("shkd_typename", QCP.equals, billType);
DynamicObject org = (DynamicObject) this.getModel().getValue("org");
String orgName = org.getString("name");
QF.and("shkd_org.name",QCP.equals,orgName);
logger.info("过滤条件单据类型为"+billType+",组织名称为:"+orgName);
ArrayList<Object> paymentNumbers = new ArrayList<>();
DynamicObject[] loads = BusinessDataServiceHelper.load("shkd_paymatter", "id,shkd_paymatterinfonumber", QF.toArray());
for (DynamicObject load : loads) {
String paymentNumber = load.getString("shkd_paymatterinfonumber");
paymentNumbers.add(paymentNumber);
}
if (!paymentNumbers.isEmpty()){
logger.info("付款事项编码集合为"+paymentNumbers.toString());
QFilter qF = new QFilter("number", QCP.in,paymentNumbers);
ListShowParameter formShowParameter = (ListShowParameter) beforeF7SelectEvent.getFormShowParameter();
formShowParameter.getListFilterParameter().setFilter(qF);
}else {
beforeF7SelectEvent.setCancel(true);
this.getView().showTipNotification("此类型单据无关联付款事项");
}
}
}
}
}