Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
zhangzhiguo 2025-11-24 17:22:52 +08:00
commit 3f76f9b4dd
2 changed files with 157 additions and 10 deletions

View File

@ -5,6 +5,8 @@ import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType; import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
import kd.bos.dataentity.resource.ResManager; import kd.bos.dataentity.resource.ResManager;
import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.events.BeforeDoOperationEventArgs; import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.operate.FormOperate; import kd.bos.form.operate.FormOperate;
import kd.bos.orm.query.QCP; import kd.bos.orm.query.QCP;
@ -18,6 +20,8 @@ import java.util.*;
/** /**
* 企业成本核算表单插件 * 企业成本核算表单插件
* 说明1点击自动取数按钮获取核算余额表 * 说明1点击自动取数按钮获取核算余额表
* 2子分录成本分解结构跟随父分录成本分解结构赋值
* 工序即为成本分解结构
*/ */
public class EntCostSplitBillPlugin extends AbstractBillPlugIn { public class EntCostSplitBillPlugin extends AbstractBillPlugIn {
@Override @Override
@ -25,6 +29,24 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn {
super.registerListener(e); super.registerListener(e);
} }
@Override
public void propertyChanged(PropertyChangedArgs e) {
super.propertyChanged(e);
String key = e.getProperty().getName();
if ("cbs".equals(key)) {
//企业费用成本分摊明细分录-成本分解结构
//子分录跟随父分录字段赋值逻辑
ChangeData changeData = e.getChangeSet()[0];
DynamicObject dataEntity = changeData.getDataEntity();
DynamicObject cbs = (DynamicObject) changeData.getNewValue();//成本分解结构新值
DynamicObjectCollection subEntryEntityCollection = dataEntity.getDynamicObjectCollection("zcgj_subentryentity");//成本核算维度明细
for (DynamicObject subEntryEntity : subEntryEntityCollection) {
subEntryEntity.set("zcgj_cbs", cbs);//成本核算维度明细-成本分解结构
}
this.getView().updateView("zcgj_subentryentity");//刷新成本核算维度明细
}
}
public void beforeDoOperation(BeforeDoOperationEventArgs args) { public void beforeDoOperation(BeforeDoOperationEventArgs args) {
super.beforeDoOperation(args); super.beforeDoOperation(args);
FormOperate formOperate = (FormOperate) args.getSource(); FormOperate formOperate = (FormOperate) args.getSource();
@ -105,10 +127,8 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn {
Object costType = zcgj_accountcost != null ? zcgj_accountcost.get("zcgj_acccostentry.zcgj_costtype") : null; // 成本项 Object costType = zcgj_accountcost != null ? zcgj_accountcost.get("zcgj_acccostentry.zcgj_costtype") : null; // 成本项
Object secType = zcgj_accountcost != null ? zcgj_accountcost.get("zcgj_acccostentry.zcgj_sectype") : null; // 二级分类 Object secType = zcgj_accountcost != null ? zcgj_accountcost.get("zcgj_acccostentry.zcgj_sectype") : null; // 二级分类
/* // 替换原有的单一条件检查代码使用以下代码块
String secTypeName = ""; String secTypeName = "";
String costTypeName = ""; String costTypeName = "";
if (secType != null) { if (secType != null) {
if (secType instanceof DynamicObject) { if (secType instanceof DynamicObject) {
DynamicObject secTypeObj = (DynamicObject) secType; DynamicObject secTypeObj = (DynamicObject) secType;
@ -117,7 +137,6 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn {
secTypeName = secType.toString(); secTypeName = secType.toString();
} }
} }
if (costType != null) { if (costType != null) {
if (costType instanceof DynamicObject) { if (costType instanceof DynamicObject) {
DynamicObject costTypeObj = (DynamicObject) costType; DynamicObject costTypeObj = (DynamicObject) costType;
@ -127,19 +146,45 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn {
} }
} }
// 如果二级分类为"70.55"且成本项为"70"跳过该条记录 // 如果二级分类为"70.55"且成本项为"70"对该行的成本金额进行扣减
if ("70.55".equals(secTypeName) && "70.".equals(costTypeName)) { if ("70.55".equals(secTypeName) && "70.".equals(costTypeName)) {
QFilter filter5 = new QFilter("billstatus", QCP.equals, "C");//单据状态
filter5.and(new QFilter("zcgj_entryentity.zcgj_assperiod", QCP.equals, period1.getPkValue()));//折旧期间
filter5.and(new QFilter("zcgj_entryentity.zcgj_headusedept", QCP.equals, org1.getPkValue()));//使用部门
DynamicObject eceq_equipinfo = QueryServiceHelper.queryOne("eceq_equipinfo",
"id,zcgj_entryentity.zcgj_shareamount",
new QFilter[]{filter5});//"设备详情"
if (eceq_equipinfo != null) {
BigDecimal zcgj_shareamount = eceq_equipinfo.getBigDecimal("zcgj_entryentity.zcgj_shareamount");//设备详情的成本金额
// 扣减成本金额
Object currentAmount = rptAssistBalanceGx.get("zcgj_debitlocal");
BigDecimal newAmount = new BigDecimal(currentAmount != null ? currentAmount.toString() : "0")
.subtract(zcgj_shareamount != null ? zcgj_shareamount : BigDecimal.ZERO);
// 确保不会出现负数
if (newAmount.compareTo(BigDecimal.ZERO) < 0) {
newAmount = BigDecimal.ZERO;
}
// 更新rptAssistBalanceGx中的金额
rptAssistBalanceGx.set("zcgj_debitlocal", newAmount);
}
}
// 如果成本项为null则跳过该行
if (costType == null) {
continue; continue;
}*/ }
String uniqueKey = ""; String uniqueKey = "";
if (processName != null && !processName.isEmpty()) { if (processName != null && !processName.isEmpty()) {
// 存在工序时按照工序+成本项+二级分类去重 // 存在工序时按照工序+成本项+二级分类去重
uniqueKey = "PROCESS_" + processName + "_" + (costType != null ? costType.toString() : "") + "_" + (secType != null ? secType.toString() : ""); uniqueKey = "PROCESS_" + processName + "_" + costType.toString() + "_" + (secType != null ? secType.toString() : "");
} else { } else {
// 如果没有工序则按照成本项+二级分类去重 // 如果没有工序则按照成本项+二级分类去重
uniqueKey = "NONE_" + (costType != null ? costType.toString() : "") + "_" + (secType != null ? secType.toString() : ""); uniqueKey = "NONE_" + costType.toString() + "_" + (secType != null ? secType.toString() : "");
} }
DynamicObject existingEntry = summaryMap.get(uniqueKey); DynamicObject existingEntry = summaryMap.get(uniqueKey);
@ -214,10 +259,10 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn {
Object costType1 = entry1.get("costtype"); Object costType1 = entry1.get("costtype");
Object costType2 = entry2.get("costtype"); Object costType2 = entry2.get("costtype");
// 处理null值情况 - 将null值放在最后 // 处理null值情况 - 将null值放在前面
if (costType1 == null && costType2 == null) return 0; if (costType1 == null && costType2 == null) return 0;
if (costType1 == null) return 1; // null值排在 if (costType1 == null) return -1; // null值排在
if (costType2 == null) return -1; // null值排在后 if (costType2 == null) return 1; // null值排在前
// 提取数值部分进行比较 // 提取数值部分进行比较
String value1 = costType1.toString().replaceAll("[^0-9]", ""); String value1 = costType1.toString().replaceAll("[^0-9]", "");

View File

@ -0,0 +1,102 @@
package zcgj.zcdev.zcdev.pr.plugin.operate;
import ec.ecco.opplugin.ContractCostMustInputOP;
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.ExtendedDataEntity;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.AddValidatorsEventArgs;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.validate.AbstractValidator;
import kd.ec.basedata.common.enums.CostControlModelEnum;
import kd.ec.basedata.common.utils.EcProjectHelper;
import java.util.Iterator;
import java.util.List;
/**
* 二开系统插件-企业成本核算提交操作插件
*/
public class ContractCostMustInputOPExt extends AbstractOperationServicePlugIn {
public void onPreparePropertys(PreparePropertysEventArgs e) {
super.onPreparePropertys(e);
e.getFieldKeys().add("costaccount");
e.getFieldKeys().add("cbs");
e.getFieldKeys().add("boq");
e.getFieldKeys().add("resource");
e.getFieldKeys().add("unitproject");
}
public void onAddValidators(AddValidatorsEventArgs e) {
super.onAddValidators(e);
e.getValidators().add(new OtestValidator());
}
private class OtestValidator extends AbstractValidator {
private OtestValidator() {
}
public void validate() {
String key = this.getOperateKey();
if (StringUtils.equals(key, "submit")) {
ExtendedDataEntity[] dataEntities = this.getDataEntities();
ExtendedDataEntity[] var3 = dataEntities;
int var4 = dataEntities.length;
for (int var5 = 0; var5 < var4; ++var5) {
ExtendedDataEntity extendedDataEntity = var3[var5];
DynamicObject dynamicObject = extendedDataEntity.getDataEntity();
DynamicObjectCollection collection = dynamicObject.getDynamicObjectCollection("entryentity");
if (collection != null) {
for (int i = 0; i < collection.size(); ++i) {
DynamicObject entry = (DynamicObject) collection.get(i);
DynamicObject project = entry.getDynamicObject("project");
if (project != null) {
Long projectId = project.getLong("id");
List<String> modelList = EcProjectHelper.getCostControlModelList(projectId);
Iterator var14 = modelList.iterator();
while (var14.hasNext()) {
String string = (String) var14.next();
DynamicObject rs;
if (StringUtils.equals(string, CostControlModelEnum.CBS.getValue())) {
/* rs = entry.getDynamicObject("cbs");
if (rs == null) {
this.addErrorMessage(extendedDataEntity, String.format(ResManager.loadKDString("分录第[%1$s]行的项目勾选了%2$s核算维度请填写%3$s字段", "ContractCostMustInputOP_0", "ec-ecco-opplugin", new Object[0]), i + 1, "CBS", "“CBS”"));
}*/
} else if (StringUtils.equals(string, CostControlModelEnum.CA.getValue())) {
rs = entry.getDynamicObject("costaccount");
if (rs == null) {
this.addErrorMessage(extendedDataEntity, String.format(ResManager.loadKDString("分录第[%1$s]行的项目勾选了%2$s核算维度请填写%3$s字段", "ContractCostMustInputOP_0", "ec-ecco-opplugin", new Object[0]), i + 1, "CA", "“CA”"));
}
} else if (StringUtils.equals(string, CostControlModelEnum.BOQ.getValue())) {
rs = entry.getDynamicObject("boq");
if (rs == null) {
this.addErrorMessage(extendedDataEntity, String.format(ResManager.loadKDString("分录第[%1$s]行的项目勾选了%2$s核算维度请填写%3$s字段", "ContractCostMustInputOP_0", "ec-ecco-opplugin", new Object[0]), i + 1, "BOQ", "“BOQ”"));
}
} else if (StringUtils.equals(string, CostControlModelEnum.RS.getValue())) {
rs = entry.getDynamicObject("resource");
if (rs == null) {
this.addErrorMessage(extendedDataEntity, String.format(ResManager.loadKDString("分录第[%1$s]行的项目勾选了%2$s核算维度请填写%3$s字段", "ContractCostMustInputOP_0", "ec-ecco-opplugin", new Object[0]), i + 1, "RS", ResManager.loadKDString("“资源名称”", "ContractCostMustInputOP_1", "ec-ecco-opplugin", new Object[0])));
}
}
}
String boqMode = project.getString("boqmode");
if (boqMode != null && "unitproject".equals(boqMode)) {
DynamicObject unitProject = entry.getDynamicObject("unitproject");
if (unitProject == null) {
this.addErrorMessage(extendedDataEntity, String.format(ResManager.loadKDString("分录第[%1$s]行的项目的业务核算模式为按单位工程/标段核算,请填写%2$s字段", "ContractCostMustInputOP_2", "ec-ecco-opplugin", new Object[0]), i + 1, ResManager.loadKDString("“单位工程/标段”", "ContractCostMustInputOP_3", "ec-ecco-opplugin", new Object[0])));
}
}
}
}
}
}
}
}
}
}