项目建立面积数据导入保存、合计、刷新

This commit is contained in:
李贵强 2024-12-25 17:51:09 +08:00
parent c089cf1237
commit a5089a619b
1 changed files with 104 additions and 11 deletions

View File

@ -4,6 +4,8 @@ import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.datamodel.events.BeforeImportEntryEventArgs;
import kd.bos.entity.datamodel.events.ImportDataEventArgs;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.control.Control;
import kd.bos.form.control.EntryGrid;
@ -21,7 +23,9 @@ import kd.tsc.tsrbs.business.domain.oprecord.service.helper.OprecordHelper;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.EventObject;
import java.util.HashMap;
/**
* 位置:项目主数据-项目建立-表单插件
@ -39,15 +43,20 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
private Label pubInsideAmountLabel;
private Label watertightAmountLabel;
private Label hardcoverAmount;
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
this.addItemClickListeners("tbmain");
EntryGrid entryGrid = this.getControl(PRODUCT_ENTRY);
entryGrid.addRowClickListener(this);
// 缓存控件减少重复调用
publicAmountLabel = (Label) this.getControl("qeug_publicamount");
pubInsideAmountLabel = (Label) this.getControl("qeug_pubinsideamount");
watertightAmountLabel = (Label) this.getControl("qeug_watertightamount");
hardcoverAmount=(Label) this.getControl("qeug_hardcoveramount");
}
@ -58,7 +67,7 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
// 业务逻辑
DynamicObjectCollection subEntryEntity = (DynamicObjectCollection) this.getModel().getValue(SUB_ENTRY);
if (subEntryEntity!=null){
calculateArea(subEntryEntity);
onlyCalculateArea(subEntryEntity);
}
this.getView().updateView(SUB_ENTRY);
}
@ -75,24 +84,27 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
publicAmountLabel = (Label) this.getControl("qeug_publicamount");
pubInsideAmountLabel = (Label) this.getControl("qeug_pubinsideamount");
watertightAmountLabel = (Label) this.getControl("qeug_watertightamount");
hardcoverAmount=(Label) this.getControl("qeug_hardcoveramount");
DynamicObjectCollection subEntryEntity = (DynamicObjectCollection) this.getModel().getValue(SUB_ENTRY);
if (subEntryEntity!=null){
Object pkValue = this.getModel().getValue("id");
BigDecimal publicAndInside = calculateArea(subEntryEntity);
//更新产品指标
setProductEntryValue(productEntry,subEntryEntity,publicAndInside);
//获取产品类型id
Long productTypeId = getProductTypeId(productEntry, subEntryEntity);
//更新指标信息
updateMetricInfo(publicAndInside,productTypeId,pkValue);
calculateArea(subEntryEntity);
Object pkValue = this.getModel().getValue("id");
BigDecimal publicAndInside = calculateArea(subEntryEntity,productTypeId,pkValue);
//更新产品指标
setProductEntryValue(productEntry,subEntryEntity,publicAndInside);
}
this.getView().updateView(SUB_ENTRY);
}
}
}
private BigDecimal calculateArea(DynamicObjectCollection subEntryEntity) {
private BigDecimal calculateArea(DynamicObjectCollection subEntryEntity,Long productTypeId,Object pkValue ) {
if (subEntryEntity == null || subEntryEntity.isEmpty()) {
return BigDecimal.ZERO; // 防止空集合
}
@ -101,6 +113,7 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
BigDecimal publicArea = BigDecimal.ZERO;
BigDecimal publicAndInside = BigDecimal.ZERO;
BigDecimal watertight = BigDecimal.ZERO;
BigDecimal hardcover = BigDecimal.ZERO;
// 分类处理
for (DynamicObject entry : subEntryEntity) {
@ -115,6 +128,7 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
break;
case "套内":
publicAndInside = publicAndInside.add(value);
hardcover = hardcover.add(value);
break;
case "防水":
watertight = watertight.add(value);
@ -130,10 +144,57 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
updateLabel(publicAmountLabel, publicArea);
updateLabel(pubInsideAmountLabel, publicAndInside);
updateLabel(watertightAmountLabel, watertight);
updateLabel(hardcoverAmount,hardcover);
updateMetricInfo(publicAndInside,hardcover,productTypeId,pkValue);
return publicAndInside;
}
private void onlyCalculateArea(DynamicObjectCollection subEntryEntity) {
if (subEntryEntity == null || subEntryEntity.isEmpty()) {
return ; // 防止空集合
}
// 合计值
BigDecimal publicArea = BigDecimal.ZERO;
BigDecimal publicAndInside = BigDecimal.ZERO;
BigDecimal watertight = BigDecimal.ZERO;
BigDecimal hardcover = BigDecimal.ZERO;
// 分类处理
for (DynamicObject entry : subEntryEntity) {
String type = entry.getString("qeug_fl");
BigDecimal value = entry.getBigDecimal(ENTRY_VALUE);
if (StringUtils.isNotEmpty(type)) {
switch (type) {
case "公区":
publicArea = publicArea.add(value);
publicAndInside = publicAndInside.add(value);
break;
case "套内":
publicAndInside = publicAndInside.add(value);
hardcover = hardcover.add(value);
break;
case "防水":
watertight = watertight.add(value);
break;
default:
this.getView().showMessage("无效的分类: " + type + ", 请重新选择!");
break;
}
}
}
// 更新控件显示
updateLabel(publicAmountLabel, publicArea);
updateLabel(pubInsideAmountLabel, publicAndInside);
updateLabel(watertightAmountLabel, watertight);
updateLabel(hardcoverAmount,hardcover);
}
private void updateLabel(Label label, BigDecimal value) {
// 设置值并确保格式化保留两位小数
@ -142,7 +203,7 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
}
}
private void updateMetricInfo(BigDecimal publicAndInside,Long productTypeId,Object pkValue){
private void updateMetricInfo(BigDecimal publicAndInside,BigDecimal hardcover,Long productTypeId,Object pkValue ){
QFilter qFilter = new QFilter("mainprojectid", QCP.equals, pkValue);
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle( "repmd_index_products",qFilter.toArray());
if (null!=dynamicObject){
@ -154,6 +215,7 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
entry.set("buildentry_allbuildarea",publicAndInside);
entry.set("buildentry_onbuildarea",publicAndInside);
entry.set("buildentry_downbuildarea",BigDecimal.ZERO);
entry.set("buildentry_finedecortarea",hardcover);
break;
}
}
@ -197,4 +259,35 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
}
}
}
@Override
public void afterBindData(EventObject e) {
super.afterBindData(e);
EntryGrid entryGrid = this.getControl("productentry");
DynamicObjectCollection productEntry = this.getModel().getEntryEntity(PRODUCT_ENTRY);
if (productEntry!=null) {
//选中最新的导入数据
entryGrid.selectRows(productEntry.size() - 1);
//先清空计入估算表数值再赋值触发保存
DynamicObjectCollection subEntryEntity = (DynamicObjectCollection) this.getModel().getValue(SUB_ENTRY);
if (subEntryEntity!=null&& subEntryEntity.size()!=0) {
for (int i = 0; i < subEntryEntity.size(); i++) {
this.getModel().setValue("qeug_jrgsbsz", BigDecimal.ZERO, i);
DynamicObject entry = subEntryEntity.get(i);
BigDecimal all = entry.getBigDecimal("qeug_hjs");
this.getModel().setValue("qeug_jrgsbsz", all, i);
}
//反写产品构成和指标信息
//获取产品类型id
Long productTypeId = getProductTypeId(productEntry, subEntryEntity);
Object pkValue = this.getModel().getValue("id");
BigDecimal publicAndInside = calculateArea(subEntryEntity,productTypeId,pkValue);
//更新产品指标
setProductEntryValue(productEntry,subEntryEntity,publicAndInside);
}
}
}
}