校验器优化
This commit is contained in:
parent
92059e36b1
commit
cec5ba8f03
|
@ -7,6 +7,7 @@ import kd.bos.entity.validate.AbstractValidator;
|
|||
import kd.bos.form.plugin.AbstractFormPlugin;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
import shkd.repc.repmd.formplugin.TotalAssignmentPlugin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
@ -22,29 +23,55 @@ public class ProjectBillSubmitValidator extends AbstractValidator {
|
|||
for (ExtendedDataEntity dataEntity : dataEntities) {
|
||||
if (dataEntity != null) {
|
||||
DynamicObject bill = dataEntity.getDataEntity();
|
||||
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle( bill.getLong("id"), "repmd_projectbill");
|
||||
if (null!=dynamicObject){
|
||||
//产品构成
|
||||
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(bill.getLong("id"), "repmd_projectbill");
|
||||
|
||||
if (dynamicObject != null) {
|
||||
// 产品构成
|
||||
DynamicObjectCollection productEntry = dynamicObject.getDynamicObjectCollection("productentry");
|
||||
if (null != productEntry && productEntry.size() != 0) {
|
||||
boolean hasBeenCalculated = true;
|
||||
if (productEntry != null && !productEntry.isEmpty()) {
|
||||
|
||||
StringBuilder errormessage = new StringBuilder();
|
||||
errormessage.append("有尚未计算的【面积数据】,请点击【面积汇总】按钮!\n");
|
||||
|
||||
for (int i = 0; i < productEntry.size(); i++) {
|
||||
//改建后建筑面积
|
||||
// 获取各面积字段
|
||||
BigDecimal buildingArea = productEntry.get(i).getBigDecimal("productentry_buildingarea");
|
||||
BigDecimal saleArea = productEntry.get(i).getBigDecimal("qeug_productentry_saleare");
|
||||
BigDecimal waterproofArea = productEntry.get(i).getBigDecimal("qeug_waterproofarea");
|
||||
BigDecimal actualArea = productEntry.get(i).getBigDecimal("qeug_actualarea");
|
||||
|
||||
// 获取子分录
|
||||
DynamicObjectCollection collections = productEntry.get(i).getDynamicObjectCollection("qeug_subentryentity");
|
||||
if (null != collections && collections.size() != 0) {
|
||||
BigDecimal total = collections.stream()
|
||||
.map(entry -> entry.getBigDecimal("qeug_jrgsbsz")) // 获取每个条目的 BigDecimal 值
|
||||
.filter(value -> value != null) // 过滤掉空值
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
if (buildingArea.compareTo(total)!=0){
|
||||
hasBeenCalculated = false;
|
||||
break;
|
||||
if (collections != null && !collections.isEmpty()) {
|
||||
|
||||
// 计算合计值
|
||||
BigDecimal totalBuilding = areaSummary(collections, "总面积");
|
||||
BigDecimal totalSale = areaSummary(collections, "可出租面积");
|
||||
BigDecimal totalWater = areaSummary(collections, "防水");
|
||||
BigDecimal publicArea = areaSummary(collections, "公区");
|
||||
BigDecimal insideArea = areaSummary(collections, "套内");
|
||||
BigDecimal totalActual = publicArea.add(insideArea);
|
||||
|
||||
// 校验并记录错误信息
|
||||
if (buildingArea.compareTo(totalBuilding) != 0) {
|
||||
errormessage.append(String.format("产品构成分录第 %d 行改建后建筑面积: %.2f 与合计值: %.2f 不相等!\n", i + 1, buildingArea, totalBuilding));
|
||||
}
|
||||
if (saleArea.compareTo(totalSale) != 0) {
|
||||
errormessage.append(String.format("产品构成分录第 %d 行可出租面积: %.2f 与合计值: %.2f 不相等!\n", i + 1, saleArea, totalSale));
|
||||
}
|
||||
if (waterproofArea.compareTo(totalWater) != 0) {
|
||||
errormessage.append(String.format("产品构成分录第 %d 行防水面积: %.2f 与合计值: %.2f 不相等!\n", i + 1, waterproofArea, totalWater));
|
||||
}
|
||||
if (actualArea.compareTo(totalActual) != 0) {
|
||||
errormessage.append(String.format("产品构成分录第 %d 行实际装修面积: %.2f 与合计值: %.2f 不相等!\n", i + 1, actualArea, totalActual));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hasBeenCalculated){
|
||||
this.addErrorMessage(dataEntity, "有尚未计算的【面积数据】,请点击【面积汇总】按钮!");
|
||||
|
||||
// 如果有错误信息,则添加错误提示
|
||||
if (errormessage.length() > "有尚未计算的【面积数据】,请点击【面积汇总】按钮!\n".length()) {
|
||||
this.addErrorMessage(dataEntity, errormessage.toString());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,4 +79,21 @@ public class ProjectBillSubmitValidator extends AbstractValidator {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 面积分类汇总
|
||||
* @param collections
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
private BigDecimal areaSummary(DynamicObjectCollection collections,String type){
|
||||
return collections.stream()
|
||||
.filter(collection -> type.equals(collection.getString("qeug_fl")))
|
||||
.map(collection -> {
|
||||
BigDecimal hjs = collection.getBigDecimal("qeug_hjs");
|
||||
BigDecimal tzz = collection.getBigDecimal("qeug_tzz");
|
||||
return hjs.add(tzz);
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue