科目分类通用插件性能优化
This commit is contained in:
parent
c6ec93c2bf
commit
31b70ffe22
|
@ -22,9 +22,7 @@ import kd.bos.servicehelper.user.UserServiceHelper;
|
||||||
import kd.sdk.plugin.Plugin;
|
import kd.sdk.plugin.Plugin;
|
||||||
import zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils;
|
import zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.EventObject;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 1、费用报销单;2、差旅报销单;3、对公报销单;4、预付单
|
* 1、费用报销单;2、差旅报销单;3、对公报销单;4、预付单
|
||||||
|
@ -149,17 +147,12 @@ public class ReimbursementAccountTypePlugin extends AbstractBillPlugIn implement
|
||||||
//不是矿山不进入下面逻辑
|
//不是矿山不进入下面逻辑
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DynamicObject costDept = (DynamicObject) this.getModel().getValue("costdept");//费用承担部门
|
|
||||||
// long userid = Long.parseLong(RequestContext.get().getUserId());//当前用户id
|
|
||||||
// String userMainJob = UserServiceHelper.getUserMainJob(userid);//获取用户默认主职位
|
|
||||||
DynamicObject applier = (DynamicObject) this.getModel().getValue("applier");//申请人
|
|
||||||
long applierId = applier.getLong("id");//申请人id
|
|
||||||
String userMainJob = UserServiceHelper.getUserMainJob(applierId);//申请人默认主职位
|
|
||||||
ChangeData changeData = e.getChangeSet()[0];
|
ChangeData changeData = e.getChangeSet()[0];
|
||||||
int rowIndex = changeData.getRowIndex();//所选行
|
int rowIndex = changeData.getRowIndex();//所选行
|
||||||
DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("expenseentryentity");//分录
|
DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("expenseentryentity");//分录
|
||||||
if (entryEntityCollection != null) {
|
if (entryEntityCollection != null) {
|
||||||
DynamicObject expenseItem = entryEntityCollection.get(rowIndex).getDynamicObject("expenseitem");
|
DynamicObject expenseItem = entryEntityCollection.get(rowIndex).getDynamicObject("expenseitem");//费用项目
|
||||||
if (expenseItem == null) {
|
if (expenseItem == null) {
|
||||||
this.getModel().setValue("zcgj_accounttype", null, rowIndex);//科目属性
|
this.getModel().setValue("zcgj_accounttype", null, rowIndex);//科目属性
|
||||||
return;
|
return;
|
||||||
|
@ -174,10 +167,42 @@ public class ReimbursementAccountTypePlugin extends AbstractBillPlugIn implement
|
||||||
} else if ("er_prepaybill".equals(billFormId)) {
|
} else if ("er_prepaybill".equals(billFormId)) {
|
||||||
typeKey = "50"; //预付单
|
typeKey = "50"; //预付单
|
||||||
}
|
}
|
||||||
QFilter filter = new QFilter("zcgj_entryentity.zcgj_fee", QCP.equals, expenseItemId).and("zcgj_biztype", QCP.equals, typeKey);
|
|
||||||
DynamicObjectCollection AccountFeeCollection = QueryServiceHelper.query("zcgj_accountfee",
|
|
||||||
"zcgj_entryentity.zcgj_accounttype", new QFilter[]{filter});//费用与科目分类单
|
|
||||||
|
|
||||||
|
// 一次性缓存费用与科目分类关系数据
|
||||||
|
Map<Long, DynamicObjectCollection> accountFeeCache = new HashMap<>();
|
||||||
|
List<Long> expenseItemIds = new ArrayList<>();//费用项目id
|
||||||
|
for (DynamicObject entry : entryEntityCollection) {
|
||||||
|
DynamicObject item = entry.getDynamicObject("expenseitem");//费用项目
|
||||||
|
if (item != null) {
|
||||||
|
expenseItemIds.add(item.getLong("id"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Long> 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<Long, DynamicObjectCollection> orgTypeDefaultCache = new HashMap<>();
|
||||||
|
Set<Long> 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) {
|
if (AccountFeeCollection != null && AccountFeeCollection.size() == 1) {
|
||||||
//费用与科目分类中费用项目与科目分类为一对一的关系,直接获取科目分类赋值
|
//费用与科目分类中费用项目与科目分类为一对一的关系,直接获取科目分类赋值
|
||||||
long id = AccountFeeCollection.get(0).getLong("zcgj_entryentity.zcgj_accounttype");
|
long id = AccountFeeCollection.get(0).getLong("zcgj_entryentity.zcgj_accounttype");
|
||||||
|
@ -186,14 +211,12 @@ public class ReimbursementAccountTypePlugin extends AbstractBillPlugIn implement
|
||||||
} else if (AccountFeeCollection != null && AccountFeeCollection.size() > 1) {
|
} else if (AccountFeeCollection != null && AccountFeeCollection.size() > 1) {
|
||||||
//费用与科目分类中费用项目与科目分类为一对多的关系,先查询默认科目分类,存在默认科目分类数据时,如若通过费用承担公司与公司科目分类规则中查询到对应数据,便直接赋值
|
//费用与科目分类中费用项目与科目分类为一对多的关系,先查询默认科目分类,存在默认科目分类数据时,如若通过费用承担公司与公司科目分类规则中查询到对应数据,便直接赋值
|
||||||
//如若没有,则通过费用承担公司在组织分类中查询对应默认分类,再通过组织分类配置表确认默认科目分类,部门属性,职位,人员分别存在不同逻辑
|
//如若没有,则通过费用承担公司在组织分类中查询对应默认分类,再通过组织分类配置表确认默认科目分类,部门属性,职位,人员分别存在不同逻辑
|
||||||
QFilter filter1 = new QFilter("zcgj_entryexpense.zcgj_expenseitem", QCP.equals, expenseItemId);
|
DynamicObjectCollection orgTypeDefaultCollection = orgTypeDefaultCache.get(expenseItemId);
|
||||||
DynamicObjectCollection orgTypeDefaultCollection = QueryServiceHelper.query("zcgj_orgtypedefault",
|
|
||||||
"zcgj_entryexpense.zcgj_yanzhou,zcgj_entryexpense.zcgj_xian,zcgj_entryexpense.zcgj_nanjing,zcgj_entryexpense.zcgj_tianjin",
|
|
||||||
new QFilter[]{filter1});//默认科目分类单
|
|
||||||
|
|
||||||
if (orgTypeDefaultCollection != null && orgTypeDefaultCollection.size() == 1) {
|
if (orgTypeDefaultCollection != null && orgTypeDefaultCollection.size() == 1) {
|
||||||
//默认科目分类中存在单条的费用项目
|
//默认科目分类中存在单条的费用项目
|
||||||
DynamicObject companyRule = BusinessDataServiceHelper.loadSingle("zcgj_companyrule",
|
DynamicObject companyRule = BusinessDataServiceHelper.loadSingle("zcgj_companyrule",
|
||||||
|
"zcgj_entryrule,zcgj_entryrule.zcgj_expenseitem,zcgj_entryrule.zcgj_ruletype," +
|
||||||
|
"zcgj_entryrule.zcgj_companytype,zcgj_entryrule.zcgj_positiontype,zcgj_entryrule.zcgj_persontype",
|
||||||
new QFilter("zcgj_costcompany.id", QCP.equals, costCompanyId).toArray());//公司科目分类规则单
|
new QFilter("zcgj_costcompany.id", QCP.equals, costCompanyId).toArray());//公司科目分类规则单
|
||||||
if (companyRule != null) {
|
if (companyRule != null) {
|
||||||
//公司科目分类规则中存在对应公司的信息
|
//公司科目分类规则中存在对应公司的信息
|
||||||
|
@ -201,7 +224,9 @@ public class ReimbursementAccountTypePlugin extends AbstractBillPlugIn implement
|
||||||
for (DynamicObject entryRule : entryRuleCollection) {
|
for (DynamicObject entryRule : entryRuleCollection) {
|
||||||
DynamicObject entryRuleExpenseItem = entryRule.getDynamicObject("zcgj_expenseitem");//费用项目
|
DynamicObject entryRuleExpenseItem = entryRule.getDynamicObject("zcgj_expenseitem");//费用项目
|
||||||
String entryRuleRuleType = entryRule.getString("zcgj_ruletype");//分类规则
|
String entryRuleRuleType = entryRule.getString("zcgj_ruletype");//分类规则
|
||||||
if (entryRuleExpenseItem.getLong("id") == expenseItemId) {
|
if (entryRuleExpenseItem != null && entryRuleExpenseItem.getLong("id") == expenseItemId) {
|
||||||
|
DynamicObject applier = (DynamicObject) this.getModel().getValue("applier");//申请人
|
||||||
|
long applierId = applier.getLong("id");//申请人id
|
||||||
switch (entryRuleRuleType) {
|
switch (entryRuleRuleType) {
|
||||||
case "公司":
|
case "公司":
|
||||||
DynamicObject entryRuleCompanyType = entryRule.getDynamicObject("zcgj_companytype");//公司默认分类(科目分类)
|
DynamicObject entryRuleCompanyType = entryRule.getDynamicObject("zcgj_companytype");//公司默认分类(科目分类)
|
||||||
|
@ -209,7 +234,9 @@ public class ReimbursementAccountTypePlugin extends AbstractBillPlugIn implement
|
||||||
this.getModel().setValue("zcgj_accounttype", entryRuleCompanyType, rowIndex);
|
this.getModel().setValue("zcgj_accounttype", entryRuleCompanyType, rowIndex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case "部门属性":
|
case "部门属性":
|
||||||
|
DynamicObject costDept = (DynamicObject) this.getModel().getValue("costdept");//费用承担部门
|
||||||
DynamicObject dutyRelation = BusinessDataServiceHelper.loadSingle("bos_org_dutyrelation", "orgduty",
|
DynamicObject dutyRelation = BusinessDataServiceHelper.loadSingle("bos_org_dutyrelation", "orgduty",
|
||||||
new QFilter("org.id", QCP.equals, costDept.getLong("id")).toArray());//部门属性管理单
|
new QFilter("org.id", QCP.equals, costDept.getLong("id")).toArray());//部门属性管理单
|
||||||
if (dutyRelation != null) {
|
if (dutyRelation != null) {
|
||||||
|
@ -222,7 +249,9 @@ public class ReimbursementAccountTypePlugin extends AbstractBillPlugIn implement
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case "职位":
|
case "职位":
|
||||||
|
String userMainJob = UserServiceHelper.getUserMainJob(applierId);//申请人默认主职位
|
||||||
QFilter filter4 = new QFilter("zcgj_entryposition.zcgj_cusposition.name", QCP.equals, userMainJob);//职位
|
QFilter filter4 = new QFilter("zcgj_entryposition.zcgj_cusposition.name", QCP.equals, userMainJob);//职位
|
||||||
QFilter filter5 = new QFilter("zcgj_entryposition.zcgj_expenseitem", QCP.equals, expenseItemId);//费用项目
|
QFilter filter5 = new QFilter("zcgj_entryposition.zcgj_expenseitem", QCP.equals, expenseItemId);//费用项目
|
||||||
DynamicObjectCollection zcgj_positionrule = QueryServiceHelper.query("zcgj_positionrule",
|
DynamicObjectCollection zcgj_positionrule = QueryServiceHelper.query("zcgj_positionrule",
|
||||||
|
@ -274,6 +303,7 @@ public class ReimbursementAccountTypePlugin extends AbstractBillPlugIn implement
|
||||||
numbers.add(number);
|
numbers.add(number);
|
||||||
}
|
}
|
||||||
DynamicObject orgCateGoryConfig = BusinessDataServiceHelper.loadSingle("zcgj_orgcategoryconfig",
|
DynamicObject orgCateGoryConfig = BusinessDataServiceHelper.loadSingle("zcgj_orgcategoryconfig",
|
||||||
|
"zcgj_defaultsubjectcode",
|
||||||
new QFilter("number", QCP.in, numbers).toArray());//组织分类配置表单
|
new QFilter("number", QCP.in, numbers).toArray());//组织分类配置表单
|
||||||
|
|
||||||
String accountType = null;//默认科目分类中的科目分类
|
String accountType = null;//默认科目分类中的科目分类
|
||||||
|
@ -297,7 +327,7 @@ public class ReimbursementAccountTypePlugin extends AbstractBillPlugIn implement
|
||||||
accountType = "zcgj_yanzhou";
|
accountType = "zcgj_yanzhou";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (accountType != null){
|
if (accountType != null) {
|
||||||
long id = orgTypeDefaultCollection.get(0).getLong("zcgj_entryexpense." + accountType);
|
long id = orgTypeDefaultCollection.get(0).getLong("zcgj_entryexpense." + accountType);
|
||||||
this.getModel().setValue("zcgj_accounttype", id, rowIndex);//科目属性
|
this.getModel().setValue("zcgj_accounttype", id, rowIndex);//科目属性
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue