From a5089a619bcb9f66284d52e94de9dcc78d8ea7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=B4=B5=E5=BC=BA?= Date: Wed, 25 Dec 2024 17:51:09 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=BB=BA=E7=AB=8B=E9=9D=A2?= =?UTF-8?q?=E7=A7=AF=E6=95=B0=E6=8D=AE=E5=AF=BC=E5=85=A5=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E3=80=81=E5=90=88=E8=AE=A1=E3=80=81=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../formplugin/TotalAssignmentPlugin.java | 115 ++++++++++++++++-- 1 file changed, 104 insertions(+), 11 deletions(-) diff --git a/main/java/shkd/repc/repmd/formplugin/TotalAssignmentPlugin.java b/main/java/shkd/repc/repmd/formplugin/TotalAssignmentPlugin.java index eb3f007..4d5d0ed 100644 --- a/main/java/shkd/repc/repmd/formplugin/TotalAssignmentPlugin.java +++ b/main/java/shkd/repc/repmd/formplugin/TotalAssignmentPlugin.java @@ -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; } } @@ -170,7 +232,7 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic for (DynamicObject entry : productEntry) { Long proEntryId = entry.getLong("id"); if (subEntryId.compareTo(proEntryId)==0){ - typeId = entry.getLong("productentry_producttype.id"); + typeId = entry.getLong("productentry_producttype.id"); 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); + } + } + } }