去费用标准配置表中获取费用标准、标准单位-龚宇杰

This commit is contained in:
ggxl 2025-04-09 15:55:46 +08:00
parent e1d2af0dcb
commit 4f41697623
1 changed files with 143 additions and 0 deletions

View File

@ -1,11 +1,154 @@
package zf47.jdgz1.fi.em.plugin.form;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
import java.util.*;
import java.util.stream.Collectors;
/**
* 单据界面插件
*/
public class GetExpenseStandardPlugin extends AbstractBillPlugIn implements Plugin {
/*
* 费用报销单-根据报账类型费用项目以及一些特殊字段去费用标准配置表中获取费用标准标准单位
* */
private static final Log log = LogFactory.getLog(GetExpenseStandardPlugin.class);
@Override
public void propertyChanged(PropertyChangedArgs e) {
IDataModel model = this.getModel();
DynamicObject bill = model.getDataEntity();
String reimburseType = bill.getString("reimburseType");
if (reimburseType == null || reimburseType.isEmpty()) return;
DynamicObjectCollection expenseEntries = bill.getDynamicObjectCollection("expenseentryentity");// 费用明细分录
if (expenseEntries == null || expenseEntries.isEmpty()) return;
//获取 监听值变更单据头字段集合
QFilter headParamQF = new QFilter("number", QCP.equals, "ExpenseListeningHeadFields");
DynamicObject headParam = BusinessDataServiceHelper.loadSingle("zf47_system_params", "zf47_val", headParamQF.toArray());
if (headParam == null) {
log.warn("GetExpenseStandardPluginExpenseListeningHeadFields参数未配置");
return;
}
String headVal = headParam.getString("zf47_val");
ArrayList<String> headFields;
if (headVal.contains(",")) {
String[] splits = headVal.split(",");
headFields = new ArrayList<>(Arrays.asList(splits));
} else {
headFields = new ArrayList<>(Collections.singletonList(headVal));
}
//获取 监听值变更分录字段集合
QFilter entryParamQF = new QFilter("number", QCP.equals, "ExpenseListeningEntryFields");
DynamicObject entryParam = BusinessDataServiceHelper.loadSingle("zf47_system_params", "zf47_val", entryParamQF.toArray());
if (entryParam == null) {
log.warn("GetExpenseStandardPluginExpenseListeningEntryFields参数未配置");
return;
}
String entryVal = entryParam.getString("zf47_val");
ArrayList<String> entryFields;
if (entryVal.contains(",")) {
String[] splits = entryVal.split(",");
entryFields = new ArrayList<>(Arrays.asList(splits));
} else {
entryFields = new ArrayList<>(Collections.singletonList(entryVal));
}
String changeName = e.getProperty().getName();
if (headFields.contains(changeName)) {//值更新字段在单据头
for (int i = 0; i < expenseEntries.size(); i++) {
DynamicObject expenseEntry = expenseEntries.get(i);
DynamicObject expenseItem = expenseEntry.getDynamicObject("expenseitem");
if (expenseItem != null) {
HashMap<String, Object> result = getExpenseStandard(entryFields, reimburseType, expenseItem.getString("number"), expenseEntry);
if (result != null) {
for (String field : result.keySet()) {
model.setValue(field, result.get(field), i);
}
}
}
}
} else if (entryFields.contains(changeName)) {//值更新字段在费用明细分录
int rowIndex = e.getChangeSet()[0].getRowIndex();
DynamicObject expenseEntry = expenseEntries.get(rowIndex);
DynamicObject expenseItem = expenseEntry.getDynamicObject("expenseitem");
if (expenseItem != null) {
HashMap<String, Object> result = getExpenseStandard(entryFields, reimburseType, expenseItem.getString("number"), expenseEntry);
if (result != null) {
for (String field : result.keySet()) {
model.setValue(field, result.get(field), rowIndex);
}
}
}
}
}
/**
* 根据报账类型费用项目编码组成的过滤条件从费用标准配置表中取值并一一与分录对象进行比较最终获取到对应的费用标准和标准单位组成HashMap集合并返回
* @param entryFields 费用明细分录字段标识集合
* @param reimburseType 报账类型
* @param expenseItem 费用项目编码
* @param expenseEntry 费用明细分录对象
*/
private HashMap<String, Object> getExpenseStandard(ArrayList<String> entryFields, String reimburseType, String expenseItem, DynamicObject expenseEntry) {
HashMap<String, Object> result = new HashMap<>();
QFilter filter = new QFilter("zf47_reimburse_type", QCP.equals, reimburseType)
.and(new QFilter("zf47_expense_item.number", QCP.equals, expenseItem));
DynamicObject[] standardConfigIds = BusinessDataServiceHelper.load("zf47_exp_standard_conf","id", filter.toArray());
if (standardConfigIds == null || standardConfigIds.length == 0) {
log.info("GetExpenseStandardPlugin根据reimburseType"+reimburseType+"、expenseItem"+expenseItem+",没有获取到费用标准");
return null;
}
List<Long> ids = Arrays.stream(standardConfigIds).map(x -> x.getLong("id")).collect(Collectors.toList());
for (Long id : ids) {
DynamicObject standardConfig = BusinessDataServiceHelper.loadSingle(id, "zf47_exp_standard_conf");
if (isAccordWithExpenseStandards(entryFields, expenseEntry, standardConfig)) {
result.put("zf47_expense_standards", standardConfig.getBigDecimal("zf47_expense_standards"));
result.put("zf47_standard_unit", standardConfig.getString("zf47_standard_unit"));
}
}
return result;
}
/**
* 遍历费用明细分录字段标识集合从两个对象中取值判断是否相等都相等则符合该标准返回true
* @param entryFields 费用明细分录字段标识集合
* @param expenseEntry 费用明细分录对象
* @param standardConfig 费用标准配置对象
*/
private boolean isAccordWithExpenseStandards(ArrayList<String> entryFields, DynamicObject expenseEntry, DynamicObject standardConfig) {
int num = 0;
for (String entryField : entryFields) {
if ("zf47_expense_item".equals(entryField)) continue;
Object object1 = expenseEntry.get(entryField);
Object object2 = standardConfig.get(entryField);
if (object1 == null && object2 == null) {
num++;
continue;
}
if (object1 != null && object1.equals(object2)) num++;
}
return num == entryFields.size() - 1;
}
}