diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/PublicreimbursebillContractPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/PublicreimbursebillContractPlugin.java index f451a28..6aad1bb 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/PublicreimbursebillContractPlugin.java +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/form/PublicreimbursebillContractPlugin.java @@ -1,20 +1,32 @@ package zcgj.zcdev.zcdev.fs.plugin.form; import kd.bos.bill.AbstractBillPlugIn; +import kd.bos.bill.BillShowParameter; +import kd.bos.bill.OperationStatus; import kd.bos.context.RequestContext; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.utils.StringUtils; +import kd.bos.entity.datamodel.events.ChangeData; +import kd.bos.entity.datamodel.events.PropertyChangedArgs; import kd.bos.entity.operate.Submit; +import kd.bos.entity.property.ItemClassProp; import kd.bos.form.events.BeforeDoOperationEventArgs; +import kd.bos.form.field.ItemClassEdit; import kd.bos.logging.Log; import kd.bos.logging.LogFactory; +import kd.bos.mvc.bill.BillView; +import kd.bos.orm.query.QCP; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.QueryServiceHelper; import kd.bos.servicehelper.user.UserServiceHelper; import kd.sdk.plugin.Plugin; import zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils; import java.time.LocalDate; import java.time.ZoneId; -import java.util.Date; +import java.util.*; /** * 对公报销单去年合同提醒插件 @@ -28,6 +40,41 @@ public class PublicreimbursebillContractPlugin extends AbstractBillPlugIn implem //预付单的关联合同标识 private final static String CONTRACT_ENTRY_ENTITY = "contractentry"; + @Override + public void afterBindData(EventObject e) { + super.afterBindData(e); + Object company = this.getModel().getValue("costcompany");//核算组织(费用承担公司) + if (company != null) { + DynamicObject companyObj = (DynamicObject) company; + Long companyId = companyObj.getLong("id"); + if (OrgCheckUtils.isKS(companyId)) { + String ecpaytype = (String)this.getModel().getValue("zcgj_ecpaytype"); + BillShowParameter bsp=(BillShowParameter)this.getView().getFormShowParameter(); + if(bsp.getStatus()== OperationStatus.ADDNEW ){ + if(ecpaytype.equals("DG")){ + //设置字段必填 必录 + ItemClassEdit textEdit = this.getView().getControl("billpayerid"); + textEdit.setMustInput(true); + ItemClassProp textProp = (ItemClassProp) textEdit.getProperty(); + textProp.setMustInput(true); + } + }else{ + //设置字段必填 必录 + ItemClassEdit textEdit = this.getView().getControl("billpayerid"); + textEdit.setMustInput(false); + ItemClassProp textProp = (ItemClassProp) textEdit.getProperty(); + textProp.setMustInput(false); + } + }else{ + //设置字段必填 必录 + ItemClassEdit textEdit = this.getView().getControl("billpayerid"); + textEdit.setMustInput(false); + ItemClassProp textProp = (ItemClassProp) textEdit.getProperty(); + textProp.setMustInput(false); + } + } + } + @Override public void beforeDoOperation(BeforeDoOperationEventArgs args) { Long currentUserId = UserServiceHelper.getCurrentUserId(); @@ -76,4 +123,280 @@ public class PublicreimbursebillContractPlugin extends AbstractBillPlugIn implem .toLocalDate(); } + + public void propertyChanged(PropertyChangedArgs e) { + String name = e.getProperty().getName(); + if (StringUtils.equals(name, "expenseitem")) { + //费用项目 + String billFormId = ((BillView) this.getView()).getFormId();//单据标识 + DynamicObject costCompany = (DynamicObject) this.getModel().getValue("costcompany");//费用承担公司 + if (costCompany == null) { + return; + } + long costCompanyId = costCompany.getLong("id");//费用承担公司id + if (!OrgCheckUtils.isKS(costCompanyId)) { + //不是矿山不进入下面逻辑 + return; + } + + ChangeData changeData = e.getChangeSet()[0]; + int rowIndex = changeData.getRowIndex();//所选行 + DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("expenseentryentity");//分录 + if (entryEntityCollection.size() > 0) { + DynamicObject expenseItem = entryEntityCollection.get(rowIndex).getDynamicObject("expenseitem");//费用项目 + if (expenseItem == null) { + this.getModel().setValue("zcgj_accounttype", null, rowIndex);//科目属性 + return; + } + long expenseItemId = expenseItem.getLong("id");//费用项目id + + String typeKey = ""; + if ("er_dailyreimbursebill".equals(billFormId)) { + typeKey = "30";//费用报销单 + } else if ("er_publicreimbursebill".equals(billFormId)) { + typeKey = "40"; //对公报销单 + } else if ("er_prepaybill".equals(billFormId)) { + typeKey = "50"; //预付单 + } + + // 一次性缓存费用与科目分类关系数据 + Map accountFeeCache = new HashMap<>(); + List expenseItemIds = new ArrayList<>();//费用项目id + for (DynamicObject entry : entryEntityCollection) { + DynamicObject item = entry.getDynamicObject("expenseitem");//费用项目 + if (item != null) { + expenseItemIds.add(item.getLong("id")); + } + } + + Set uniqueExpenseItemIds = new HashSet<>(expenseItemIds); + if (!uniqueExpenseItemIds.isEmpty()) { + for (Long id : uniqueExpenseItemIds) { + QFilter filter = new QFilter("zcgj_entryentity.zcgj_fee", QCP.equals, id) + .and("zcgj_biztype", QCP.equals, typeKey); + DynamicObjectCollection result = QueryServiceHelper.query("zcgj_accountfee", + "zcgj_entryentity.zcgj_accounttype", new QFilter[]{filter});//费用与科目分类单 + accountFeeCache.put(id, result); + } + } + + // 一次性缓存默认科目分类配置 + Map orgTypeDefaultCache = new HashMap<>(); + Set uniqueExpenseItemIdsForDefault = new HashSet<>(expenseItemIds); + if (!uniqueExpenseItemIdsForDefault.isEmpty()) { + for (Long id : uniqueExpenseItemIdsForDefault) { + QFilter filter1 = new QFilter("zcgj_entryexpense.zcgj_expenseitem", QCP.equals, id); + DynamicObjectCollection result = QueryServiceHelper.query("zcgj_orgtypedefault", + "zcgj_entryexpense.zcgj_yanzhou,zcgj_entryexpense.zcgj_xian,zcgj_entryexpense.zcgj_nanjing,zcgj_entryexpense.zcgj_tianjin", + new QFilter[]{filter1});//默认科目分类单 + orgTypeDefaultCache.put(id, result); + } + } + + DynamicObjectCollection AccountFeeCollection = accountFeeCache.get(expenseItemId); + if (AccountFeeCollection != null && AccountFeeCollection.size() == 1) { + //费用与科目分类中费用项目与科目分类为一对一的关系,直接获取科目分类赋值 + long id = AccountFeeCollection.get(0).getLong("zcgj_entryentity.zcgj_accounttype"); + this.getModel().setValue("zcgj_accounttype", id, rowIndex);//科目属性 + + } else if (AccountFeeCollection != null && AccountFeeCollection.size() > 1) { + //费用与科目分类中费用项目与科目分类为一对多的关系,先查询默认科目分类,存在默认科目分类数据时,如若通过费用承担公司与公司科目分类规则中查询到对应数据,便直接赋值 + //如若没有,则通过费用承担公司在组织分类中查询对应默认分类,再通过组织分类配置表确认默认科目分类,部门属性,职位,人员分别存在不同逻辑 + DynamicObjectCollection orgTypeDefaultCollection = orgTypeDefaultCache.get(expenseItemId); + if (orgTypeDefaultCollection != null && orgTypeDefaultCollection.size() == 1) { + //默认科目分类中存在单条的费用项目 + DynamicObject companyRule = BusinessDataServiceHelper.loadSingle("zcgj_companyrule", + new QFilter("zcgj_costcompany.id", QCP.equals, costCompanyId).toArray());//公司科目分类规则单 + if (companyRule != null) { + //公司科目分类规则中存在对应公司的信息 + DynamicObjectCollection entryRuleCollection = companyRule.getDynamicObjectCollection("zcgj_entryrule");//公司费用分类规则分录 + for (DynamicObject entryRule : entryRuleCollection) { + DynamicObject entryRuleExpenseItem = entryRule.getDynamicObject("zcgj_expenseitem");//费用项目 + String entryRuleRuleType = entryRule.getString("zcgj_ruletype");//分类规则 + if (entryRuleExpenseItem != null && entryRuleExpenseItem.getLong("id") == expenseItemId) { + DynamicObject applier = (DynamicObject) this.getModel().getValue("applier");//申请人 + long applierId = applier.getLong("id");//申请人id + switch (entryRuleRuleType) { + case "公司": + DynamicObject entryRuleCompanyType = entryRule.getDynamicObject("zcgj_companytype");//公司默认分类(科目分类) + if (entryRuleCompanyType != null) { + this.getModel().setValue("zcgj_accounttype", entryRuleCompanyType, rowIndex); + return; + } + break; + case "部门属性": + DynamicObject costDept = (DynamicObject) this.getModel().getValue("costdept");//费用承担部门 + DynamicObject dutyRelation = BusinessDataServiceHelper.loadSingle("bos_org_dutyrelation", "orgduty", + new QFilter("org.id", QCP.equals, costDept.getLong("id")).toArray());//部门属性管理单 + if (dutyRelation != null) { + DynamicObject orgDuty = dutyRelation.getDynamicObject("orgduty");//业务属性 + long id = orgDuty.getLong("id"); + DynamicObject accountType = BusinessDataServiceHelper.loadSingle("zcgj_accounttype", "id", + new QFilter("zcgj_orgtype.fbasedataid", QCP.in, id).toArray());//科目分类单 + if (accountType != null) { + this.getModel().setValue("zcgj_accounttype", accountType, rowIndex); + return; + } + } + break; + case "职位": + String userMainJob = UserServiceHelper.getUserMainJob(applierId);//申请人默认主职位 + QFilter filter4 = new QFilter("zcgj_entryposition.zcgj_cusposition.name", QCP.equals, userMainJob);//职位 + QFilter filter5 = new QFilter("zcgj_entryposition.zcgj_expenseitem", QCP.equals, expenseItemId);//费用项目 + DynamicObjectCollection zcgj_positionrule = QueryServiceHelper.query("zcgj_positionrule", + "zcgj_entryposition.zcgj_accounttype", new QFilter[]{filter4, filter5});//职位科目分类单 + if (zcgj_positionrule != null && zcgj_positionrule.size() == 1) { + long zcgj_accounttype = zcgj_positionrule.get(0).getLong("zcgj_entryposition.zcgj_accounttype"); + if (zcgj_accounttype != 0) { + this.getModel().setValue("zcgj_accounttype", zcgj_accounttype, rowIndex);//科目属性 + return; + } + } + DynamicObject zcgj_positiontype = entryRule.getDynamicObject("zcgj_positiontype");//职位默认分类 + if (zcgj_positiontype != null) { + this.getModel().setValue("zcgj_accounttype", zcgj_positiontype, rowIndex);//科目属性 + return; + } + break; + case "人员": + QFilter filter6 = new QFilter("zcgj_entryperson.zcgj_person.id", QCP.equals, applierId);//申请人 + QFilter filter7 = new QFilter("zcgj_entryperson.zcgj_expenseitem", QCP.equals, expenseItemId);//费用项目 + DynamicObjectCollection zcgj_personrule = QueryServiceHelper.query("zcgj_personrule", + "zcgj_entryperson.zcgj_accounttype", new QFilter[]{filter6, filter7});//人员科目分类单 + if (zcgj_personrule != null && zcgj_personrule.size() == 1) { + long zcgj_accounttype = zcgj_personrule.get(0).getLong("zcgj_entryperson.zcgj_accounttype"); + if (zcgj_accounttype != 0) { + this.getModel().setValue("zcgj_accounttype", zcgj_accounttype, rowIndex);//科目属性 + return; + } + } + DynamicObject zcgj_persontype = entryRule.getDynamicObject("zcgj_persontype");//人员默认分类 + if (zcgj_persontype != null) { + this.getModel().setValue("zcgj_accounttype", zcgj_persontype, rowIndex);//科目属性 + return; + } + break; + } + } + } + } + + QFilter filter3 = new QFilter("entryentity.orgid", QCP.equals, costCompanyId); + DynamicObjectCollection wf_orgTypCollection = QueryServiceHelper.query("wf_orgtype", + "number", new QFilter[]{filter3});//组织分类单 + + if (wf_orgTypCollection != null && wf_orgTypCollection.size() > 0) { + List numbers = new ArrayList<>(); + for (DynamicObject wf_orgTyp : wf_orgTypCollection) { + String number = wf_orgTyp.getString("number"); + numbers.add(number); + } + DynamicObject orgCateGoryConfig = BusinessDataServiceHelper.loadSingle("zcgj_orgcategoryconfig", + "zcgj_defaultsubjectcode", + new QFilter("number", QCP.in, numbers).toArray());//组织分类配置表单 + + String accountType = null;//默认科目分类中的科目分类 + if (orgCateGoryConfig != null) { + String defaultSubjectCode = orgCateGoryConfig.getString("zcgj_defaultsubjectcode");//默认科目分类编码 + switch (defaultSubjectCode) { + case "ZCKS_NJXMBM": + //南京项目 + accountType = "zcgj_nanjing"; + break; + case "ZCKS_TJXMBM": + //天津项目 + accountType = "zcgj_tianjin"; + break; + case "ZCKS_XAXMBM": + //西安项目 + accountType = "zcgj_xian"; + break; + case "ZCKS_YZ_XMBM": + //兖州项目 + accountType = "zcgj_yanzhou"; + break; + } + if (accountType != null) { + long id = orgTypeDefaultCollection.get(0).getLong("zcgj_entryexpense." + accountType); + this.getModel().setValue("zcgj_accounttype", id, rowIndex);//科目属性 + } + } else { + //组织分类配置表中未查询到对应数据,说明组织分类中编码有所改变,需维护对应的组织分类配置表 + this.getModel().setValue("zcgj_accounttype", null, rowIndex);//科目属性 +// this.getView().showErrorNotification("组织分类中编码有所改变,请维护对应的组织分类配置表!"); + } + } else { + this.getModel().setValue("zcgj_accounttype", null, rowIndex);//科目属性 + } + } else { + this.getModel().setValue("zcgj_accounttype", null, rowIndex);//科目属性 + } + } else { + this.getModel().setValue("zcgj_accounttype", null, rowIndex);//科目属性 + } + } + }else + if(name.equals("zcgj_ecpaytype")){ + //所属组织 + Object company = this.getModel().getValue("costcompany");//核算组织(费用承担公司) + if (company != null) { + //String yzCompanyNumber ="10006475"; //兖州中材建设有限公司 + DynamicObject companyObj = (DynamicObject) company; + Long companyId = companyObj.getLong("id"); + if (OrgCheckUtils.isKS(companyId)) { + ChangeData[] changeSet = e.getChangeSet(); + ChangeData changeData = changeSet[0]; + String newValue = (String) changeData.getNewValue();//新值 + if("DG".equals(newValue)){ + //设置字段必填 必录 + ItemClassEdit textEdit = this.getView().getControl("billpayerid"); + textEdit.setMustInput(true); + ItemClassProp textProp = (ItemClassProp) textEdit.getProperty(); + textProp.setMustInput(true); + }else{ + //设置字段必填 必录 + ItemClassEdit textEdit = this.getView().getControl("billpayerid"); + textEdit.setMustInput(false); + ItemClassProp textProp = (ItemClassProp) textEdit.getProperty(); + textProp.setMustInput(false); + } + }else{ + //设置字段必填 必录 + ItemClassEdit textEdit = this.getView().getControl("billpayerid"); + textEdit.setMustInput(false); + ItemClassProp textProp = (ItemClassProp) textEdit.getProperty(); + textProp.setMustInput(false); + } + } + + }else if(name.equals("costcompany")){ + ChangeData[] changeSet = e.getChangeSet(); + ChangeData changeData = changeSet[0]; + DynamicObject newValue = (DynamicObject) changeData.getNewValue();//新值 + String ecpaytype = (String)this.getModel().getValue("zcgj_ecpaytype");//核算组织(费用承担公司) + long companyId = newValue.getLong("id"); + if (OrgCheckUtils.isKS(companyId)) { + if("DG".equals(ecpaytype)){ + //设置字段必填 必录 + ItemClassEdit textEdit = this.getView().getControl("billpayerid"); + textEdit.setMustInput(true); + ItemClassProp textProp = (ItemClassProp) textEdit.getProperty(); + textProp.setMustInput(true); + }else{ + //设置字段必填 必录 + ItemClassEdit textEdit = this.getView().getControl("billpayerid"); + textEdit.setMustInput(false); + ItemClassProp textProp = (ItemClassProp) textEdit.getProperty(); + textProp.setMustInput(false); + } + }else{ + //设置字段必填 必录 + ItemClassEdit textEdit = this.getView().getControl("billpayerid"); + textEdit.setMustInput(false); + ItemClassProp textProp = (ItemClassProp) textEdit.getProperty(); + textProp.setMustInput(false); + } + } + } + }