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

This commit is contained in:
zhangzhiguo 2025-08-07 16:38:23 +08:00
commit 9971000218
3 changed files with 138 additions and 5 deletions

View File

@ -11,7 +11,10 @@ import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import java.math.BigDecimal;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Map;
/*
* 使用插件注册位置支出合同结算表单插件
@ -57,11 +60,12 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
newProcessAllocEntity.set("zcgj_amountnotax", listEntry.get("thisamount"));//不含税金额-本期计量金额
newProcessAllocEntity.set("zcgj_rateval", listEntry.get("entrytaxrate"));//税率%-税率%
newProcessAllocEntity.set("zcgj_taxamt", listEntry.get("thistax"));//税额-本期税额
newProcessAllocEntity.set("zcgj_pa_remark", listEntry.get("desc"));//费用说明-说明
processAllocEntityCollection.add(newProcessAllocEntity);
}
}
}
// 添加合并逻辑按工序和税率组合合并相同项
mergeProcessAllocEntriesByProcessAndRate(processAllocEntityCollection);
}
this.getView().updateView("zcgj_processallocatentity");//工序分摊
} else {
@ -124,14 +128,87 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
newProcessAllocEntity.set("zcgj_amountnotax", listEntry.get("thisamount"));//不含税金额-本期计量金额
newProcessAllocEntity.set("zcgj_rateval", listEntry.get("entrytaxrate"));//税率%-税率%
newProcessAllocEntity.set("zcgj_taxamt", listEntry.get("thistax"));//税额-本期税额
newProcessAllocEntity.set("zcgj_pa_remark", listEntry.get("desc"));//费用说明-说明
processAllocEntityCollection.add(newProcessAllocEntity);
}
}
}
}
}
// 添加合并逻辑按工序和税率组合合并相同项
mergeProcessAllocEntriesByProcessAndRate(processAllocEntityCollection);
this.getView().updateView("zcgj_processallocatentity");//工序分摊
}
}
/**
* 按工序和税率组合合并工序分摊条目
*
* @param processAllocEntityCollection 工序分摊集合
*/
private void mergeProcessAllocEntriesByProcessAndRate(DynamicObjectCollection processAllocEntityCollection) {
// 使用Map来存储已存在的工序+税率组合避免嵌套循环
Map<String, DynamicObject> processRateMap = new HashMap<>();
for (int i = 0; i < processAllocEntityCollection.size(); i++) {
DynamicObject currentEntry = processAllocEntityCollection.get(i);
Object currentProcess = currentEntry.get("zcgj_pa_process"); // 工序
Object currentRate = currentEntry.get("zcgj_rateval"); // 税率
// 创建唯一键值工序ID + 税率值
String key = (currentProcess != null ? currentProcess.toString() : "null") +
"_" +
(currentRate != null ? currentRate.toString() : "null");
if (processRateMap.containsKey(key)) {
// 如果已存在相同组合则合并数值
DynamicObject existingEntry = processRateMap.get(key);
// 合并价税合计
BigDecimal currentAmount = toBigDecimal(existingEntry.get("zcgj_pa_amount"));
BigDecimal nextAmount = toBigDecimal(currentEntry.get("zcgj_pa_amount"));
existingEntry.set("zcgj_pa_amount", currentAmount.add(nextAmount));
// 合并不含税金额
BigDecimal currentAmountNoTax = toBigDecimal(existingEntry.get("zcgj_amountnotax"));
BigDecimal nextAmountNoTax = toBigDecimal(currentEntry.get("zcgj_amountnotax"));
existingEntry.set("zcgj_amountnotax", currentAmountNoTax.add(nextAmountNoTax));
// 合并税额
BigDecimal currentTaxAmt = toBigDecimal(existingEntry.get("zcgj_taxamt"));
BigDecimal nextTaxAmt = toBigDecimal(currentEntry.get("zcgj_taxamt"));
existingEntry.set("zcgj_taxamt", currentTaxAmt.add(nextTaxAmt));
// 移除当前条目
processAllocEntityCollection.remove(i);
i--; // 调整索引
} else {
// 如果不存在相同组合则添加到Map中
processRateMap.put(key, currentEntry);
}
}
}
/**
* 将对象转换为BigDecimal类型
*
* @param obj 待转换对象
* @return BigDecimal值
*/
private BigDecimal toBigDecimal(Object obj) {
if (obj == null) {
return BigDecimal.ZERO;
}
if (obj instanceof BigDecimal) {
return (BigDecimal) obj;
} else if (obj instanceof Number) {
return new BigDecimal(obj.toString());
} else {
try {
return new BigDecimal(obj.toString());
} catch (NumberFormatException e) {
return BigDecimal.ZERO;
}
}
}
}

View File

@ -1,4 +1,4 @@
package zcgj.zcdev.zcdev.pr.plugin;
package zcgj.zcdev.zcdev.pr.plugin.operate;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.ExtendedDataEntity;
@ -12,7 +12,7 @@ import kd.bos.servicehelper.BusinessDataServiceHelper;
import java.math.BigDecimal;
//工序成本预算单保存提交操作插件验证项目和年份的组合是否已经存在且只有一个
public class AimcostcbsBllSubmitOp extends AbstractOperationServicePlugIn {
public class AimCostCbsBllSaveOrSubOp extends AbstractOperationServicePlugIn {
@Override
public void onPreparePropertys(PreparePropertysEventArgs e) {
@ -25,7 +25,7 @@ public class AimcostcbsBllSubmitOp extends AbstractOperationServicePlugIn {
@Override
public void onAddValidators(AddValidatorsEventArgs e) {
super.onAddValidators(e);
e.getValidators().add(new ValidatorExt());
e.getValidators().add(new AimCostCbsBllSaveOrSubOp.ValidatorExt());
}
class ValidatorExt extends AbstractValidator {

View File

@ -0,0 +1,56 @@
package zcgj.zcdev.zcdev.pr.plugin.operate;
import kd.bos.dataentity.entity.DynamicObject;
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.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import java.math.BigDecimal;
/**
* 工序期间成本预算保存提交操作插件;
* 说明校验项目加期间加版本的组合是否存在存在便提示不可重复创建
*/
public class PeriodCostBSaveOrSubOp extends AbstractOperationServicePlugIn {
@Override
public void onPreparePropertys(PreparePropertysEventArgs e) {
super.onPreparePropertys(e);
e.getFieldKeys().add("period");//期间
e.getFieldKeys().add("project");//项目
e.getFieldKeys().add("versionno");//版本号
}
@Override
public void onAddValidators(AddValidatorsEventArgs e) {
super.onAddValidators(e);
e.getValidators().add(new PeriodCostBSaveOrSubOp.ValidatorExt());
}
class ValidatorExt extends AbstractValidator {
@Override
public void validate() {
ExtendedDataEntity[] extendedDataEntities = this.getDataEntities();
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
DynamicObject extendedData = extendedDataEntity.getDataEntity();
DynamicObject project = extendedData.getDynamicObject("project");//项目
DynamicObject period = extendedData.getDynamicObject("period");//期间
BigDecimal versionNo = extendedData.getBigDecimal("versionno");//版本号
QFilter filter = new QFilter("project", "=", project.getPkValue());
filter.and(new QFilter("period", "=", period.getPkValue()));
filter.and(new QFilter("versionno", "=", versionNo));
DynamicObject ecco_periodcostbillcbs = BusinessDataServiceHelper.loadSingle("ecco_periodcostbillcbs", "id", new QFilter[]{filter});
if (ecco_periodcostbillcbs != null) {
if (extendedData.getPkValue().equals(ecco_periodcostbillcbs.getPkValue())){
continue;
}
this.addFatalErrorMessage(extendedDataEntity, "该期间的项目已编制预算,请勿重复创建!");
}
}
}
}
}