项目建立bug优化

This commit is contained in:
李贵强 2024-12-31 16:33:43 +08:00
parent a74b0e6876
commit 0f41c883f0
1 changed files with 170 additions and 137 deletions

View File

@ -1,22 +1,33 @@
package shkd.repc.repmd.formplugin;
import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.OperateOption;
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.RowDataEntity;
import kd.bos.entity.datamodel.events.AfterAddRowEventArgs;
import kd.bos.entity.datamodel.events.BeforeImportEntryEventArgs;
import kd.bos.entity.datamodel.events.ImportDataEventArgs;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.form.container.Tab;
import kd.bos.form.control.Control;
import kd.bos.form.control.EntryGrid;
import kd.bos.form.control.Label;
import kd.bos.form.control.Toolbar;
import kd.bos.form.control.events.BeforeItemClickEvent;
import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.form.control.events.RowClickEvent;
import kd.bos.form.control.events.RowClickEventListener;
import kd.bos.form.events.ClientCallBackEvent;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.form.plugin.importentry.resolving.ImportEntryData;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.OperationServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.sdk.plugin.Plugin;
import kd.tsc.tsrbs.business.domain.oprecord.service.helper.OprecordHelper;
@ -26,6 +37,7 @@ import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Map;
/**
* 位置:项目主数据-项目建立-表单插件
@ -40,25 +52,35 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
// 控件缓存
private Label publicAmountLabel;
private Label pubInsideAmountLabel;
//private Label pubInsideAmountLabel;
private Label watertightAmountLabel;
private Label hardcoverAmount;
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
this.addItemClickListeners("tbmain");
this.addItemClickListeners("advcontoolbarap");
this.addItemClickListeners("qeug_advcontoolbarap");
EntryGrid entryGrid = this.getControl(PRODUCT_ENTRY);
entryGrid.addRowClickListener(this);
// 缓存控件减少重复调用
publicAmountLabel = (Label) this.getControl("qeug_publicamount");
pubInsideAmountLabel = (Label) this.getControl("qeug_pubinsideamount");
//pubInsideAmountLabel = (Label) this.getControl("qeug_pubinsideamount");
watertightAmountLabel = (Label) this.getControl("qeug_watertightamount");
hardcoverAmount=(Label) this.getControl("qeug_hardcoveramount");
hardcoverAmount = (Label) this.getControl("qeug_hardcoveramount");
}
@Override
public void clientCallBack(ClientCallBackEvent e) {
super.clientCallBack(e);
String name = e.getName();
if ("auto_save".equals(name)) {
this.getView().invokeOperation("save");
}
}
@Override
public void entryRowClick(RowClickEvent evt) {
@ -66,7 +88,7 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
if (PRODUCT_ENTRY.equals(entryGrid.getKey())) {
// 业务逻辑
DynamicObjectCollection subEntryEntity = (DynamicObjectCollection) this.getModel().getValue(SUB_ENTRY);
if (subEntryEntity!=null){
if (subEntryEntity != null) {
onlyCalculateArea(subEntryEntity);
}
this.getView().updateView(SUB_ENTRY);
@ -78,82 +100,95 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
super.propertyChanged(e);
String fieldKey = e.getProperty().getName();
if (ENTRY_VALUE.equals(fieldKey)) {
DynamicObjectCollection productEntry = this.getModel().getEntryEntity(PRODUCT_ENTRY);
if (productEntry!=null){
// 缓存控件减少重复调用
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 collections = (DynamicObjectCollection) this.getModel().getValue(SUB_ENTRY);
DynamicObject parent = (DynamicObject) collections.get(0).getParent();
Long id = parent.getLong("id");
if (id != 0L) {
//更新指标信息数据
Object pkValue = this.getModel().getValue("id");
Long typeId = parent.getLong("productentry_producttype.id");
this.updateMetricInfo(collections, typeId, pkValue);
//更新产品构成数据不切换标签也能生效
DynamicObjectCollection productEntry = this.getModel().getEntryEntity(PRODUCT_ENTRY);
this.setProductEntryValue(productEntry,collections,id);
DynamicObjectCollection subEntryEntity = (DynamicObjectCollection) this.getModel().getValue(SUB_ENTRY);
if (subEntryEntity!=null){
//获取产品类型id
Long productTypeId = getProductTypeId(productEntry, subEntryEntity);
}
Object pkValue = this.getModel().getValue("id");
BigDecimal publicAndInside = calculateArea(subEntryEntity,productTypeId,pkValue);
//更新产品指标
setProductEntryValue(productEntry,subEntryEntity,publicAndInside);
}
this.getView().updateView(SUB_ENTRY);
} else if ("billname".equals(fieldKey)) {
String value = (String) this.getModel().getValue("billno");
if (value != null) {
this.getView().addClientCallBack("auto_save", 0);
}
}
}
private BigDecimal calculateArea(DynamicObjectCollection subEntryEntity,Long productTypeId,Object pkValue ) {
if (subEntryEntity == null || subEntryEntity.isEmpty()) {
return BigDecimal.ZERO; // 防止空集合
}
// 合计值
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;
@Override
public void afterBindData(EventObject e) {
super.afterBindData(e);
DynamicObjectCollection productEntry = this.getModel().getEntryEntity(PRODUCT_ENTRY);
if (null != productEntry && productEntry.size() != 0) {
//选中第一条数据
EntryGrid entryGrid = this.getControl("productentry");
entryGrid.selectRows(0);
//查询是否有未保存数据id==0L
boolean exitNoSaveData = false;
for (int i = 0; i < productEntry.size(); i++) {
Long id = productEntry.get(i).getLong("id");
if (id == 0L) {
exitNoSaveData = true;
break;
}
}
if (exitNoSaveData) {
DynamicObjectCollection subEntryEntity = (DynamicObjectCollection) this.getModel().getValue(SUB_ENTRY);
if (null != subEntryEntity && subEntryEntity.size() != 0) {
//获取产品构成分录父数据实体类型
DynamicObject parent = (DynamicObject) ((DynamicObject) subEntryEntity.getParent()).getParent();
DynamicObjectCollection productParent = parent.getDynamicObjectCollection(PRODUCT_ENTRY);
for (int i = 0; i < productParent.size(); i++) {
//获取产品构成分录相关联的面积数据分录
DynamicObjectCollection collections = productParent.get(i).getDynamicObjectCollection(SUB_ENTRY);
//先清空计入估算表数值再赋值触发保存
for (int j = 0; j < collections.size(); j++) {
this.getModel().setValue("qeug_jrgsbsz", BigDecimal.ZERO, j, i);
BigDecimal all = collections.get(j).getBigDecimal("qeug_hjs");
this.getModel().setValue("qeug_jrgsbsz", all, j, i);
}
}
this.getView().addClientCallBack("auto_save", 0);
}
}
}
}
// 更新控件显示
updateLabel(publicAmountLabel, publicArea);
updateLabel(pubInsideAmountLabel, publicAndInside);
updateLabel(watertightAmountLabel, watertight);
updateLabel(hardcoverAmount,hardcover);
updateMetricInfo(publicAndInside,hardcover,productTypeId,pkValue);
return publicAndInside;
@Override
public void itemClick(ItemClickEvent evt) {
super.itemClick(evt);
if (StringUtils.equals("qeug_advconbaritemap7", evt.getItemKey())) {
//表单id
Object pkValue = this.getModel().getValue("id");
DynamicObjectCollection productEntry = this.getModel().getEntryEntity(PRODUCT_ENTRY);
if (null != productEntry && productEntry.size() != 0) {
for (DynamicObject dynamicObject : productEntry) {
if (dynamicObject.getBigDecimal("productentry_buildingarea").compareTo(BigDecimal.ZERO) == 0) {
DynamicObjectCollection collections = dynamicObject.getDynamicObjectCollection(SUB_ENTRY);
//指标信息赋值
Long typeId = dynamicObject.getLong("productentry_producttype.id");
this.updateMetricInfo(collections, typeId, pkValue);
}
}
Tab tab = this.getView().getControl("tabap");
tab.activeTab("indexpage_tab");
}
} else if (StringUtils.equals("deleteproductentry", evt.getItemKey())) {
this.getView().addClientCallBack("auto_save", 0);
}
}
private void onlyCalculateArea(DynamicObjectCollection subEntryEntity) {
if (subEntryEntity == null || subEntryEntity.isEmpty()) {
return ; // 防止空集合
return; // 防止空集合
}
// 合计值
@ -189,9 +224,8 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
// 更新控件显示
updateLabel(publicAmountLabel, publicArea);
updateLabel(pubInsideAmountLabel, publicAndInside);
updateLabel(watertightAmountLabel, watertight);
updateLabel(hardcoverAmount,hardcover);
updateLabel(hardcoverAmount, hardcover);
}
@ -203,91 +237,90 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic
}
}
private void updateMetricInfo(BigDecimal publicAndInside,BigDecimal hardcover,Long productTypeId,Object pkValue ){
/**
* 更新指标信息
*
* @param collections 面积数据分录数据
* @param productTypeId 产品构成产品类型
* @param pkValue 表单id
*/
private void updateMetricInfo(DynamicObjectCollection collections, Long productTypeId, Object pkValue) {
// 获取地下面积汇总值
BigDecimal groundFloorSummary = collections.stream()
.map(collection -> {
// 获取两个 BigDecimal 如果为 null则使用 BigDecimal.ZERO
BigDecimal b1f = collection.getBigDecimal("qeug_b1f") != null ? collection.getBigDecimal("qeug_b1f") : BigDecimal.ZERO;
BigDecimal b2f = collection.getBigDecimal("qeug_b2f") != null ? collection.getBigDecimal("qeug_b2f") : BigDecimal.ZERO;
return b1f.add(b2f); // 返回 b1f b2f 的和
})
.reduce(BigDecimal.ZERO, BigDecimal::add); // 累加所有的和
// 获取地上面积汇总值
BigDecimal allArea = collections.stream()
.map(collection -> {
// 获取 BigDecimal 如果为 null则使用 BigDecimal.ZERO
BigDecimal hjs = collection.getBigDecimal("qeug_hjs") != null ? collection.getBigDecimal("qeug_hjs") : BigDecimal.ZERO;
return hjs;
})
.reduce(BigDecimal.ZERO, BigDecimal::add); // 累加所有的面积
// 获取地上面积 - 地下面积
BigDecimal groundSummary = allArea.subtract(groundFloorSummary);
// 获取精装面积汇总值
BigDecimal hardcoverSummary = collections.stream()
.filter(collection -> "套内".equals(collection.getString("qeug_fl"))) // 筛选 "套内" 类型
.map(collection -> {
// 获取 BigDecimal 如果为 null则使用 BigDecimal.ZERO
BigDecimal hjs = collection.getBigDecimal("qeug_hjs") != null ? collection.getBigDecimal("qeug_hjs") : BigDecimal.ZERO;
return hjs;
})
.reduce(BigDecimal.ZERO, BigDecimal::add); // 累加所有的 "套内" 面积
QFilter qFilter = new QFilter("mainprojectid", QCP.equals, pkValue);
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle( "repmd_index_products",qFilter.toArray());
if (null!=dynamicObject){
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("repmd_index_products", qFilter.toArray());
if (null != dynamicObject) {
DynamicObjectCollection buildingEntry = dynamicObject.getDynamicObjectCollection("buildingindexentry");
if (buildingEntry!=null&&buildingEntry.size()!=0){
if (buildingEntry != null && buildingEntry.size() != 0) {
for (DynamicObject entry : buildingEntry) {
Long typeId = entry.getLong("buildentry_producttype.id");
if (typeId.compareTo(productTypeId)==0){
entry.set("buildentry_allbuildarea",publicAndInside);
entry.set("buildentry_onbuildarea",publicAndInside);
entry.set("buildentry_downbuildarea",BigDecimal.ZERO);
entry.set("buildentry_finedecortarea",hardcover);
if (typeId.compareTo(productTypeId) == 0) {
entry.set("buildentry_allbuildarea", groundSummary.add(groundFloorSummary));
entry.set("buildentry_onbuildarea", groundSummary);
entry.set("buildentry_downbuildarea", groundFloorSummary);
entry.set("buildentry_finedecortarea", hardcoverSummary);
SaveServiceHelper.update(dynamicObject);
break;
}
}
}
}
SaveServiceHelper.update(dynamicObject);
}
private Long getProductTypeId(DynamicObjectCollection productEntry,DynamicObjectCollection subEntryEntity){
Long typeId = null;
DynamicObject dynamicObject = subEntryEntity.get(0);
DynamicObject parent = (DynamicObject) dynamicObject.getParent();
Long subEntryId = parent.getLong("id");
for (DynamicObject entry : productEntry) {
Long proEntryId = entry.getLong("id");
if (subEntryId.compareTo(proEntryId)==0){
typeId = entry.getLong("productentry_producttype.id");
break;
}
}
return typeId;
}
/**
* 产品构成分录赋值
* @param productEntry 产品构成分录
* @param subEntryEntity 面积数据分录
* @param publicAndInside 改建后面积
*
* @param productEntry 产品构成分录
* @param collections 面积数据分录
* @param id 产品构成分录id
*/
private void setProductEntryValue(DynamicObjectCollection productEntry,DynamicObjectCollection subEntryEntity,BigDecimal publicAndInside){
DynamicObject dynamicObject = subEntryEntity.get(0);
DynamicObject dynamicObject2 = (DynamicObject) dynamicObject.getParent();
Long pkValue = (Long) dynamicObject2.getPkValue();
private void setProductEntryValue(DynamicObjectCollection productEntry, DynamicObjectCollection collections, Long id) {
BigDecimal allArea = collections.stream()
.filter(collection -> !"防水".equals(collection.getString("qeug_fl"))) // 排除 "防水" 类型
.map(collection -> {
BigDecimal hjs = collection.getBigDecimal("qeug_hjs");
return hjs != null ? hjs : BigDecimal.ZERO;
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
for (int i = 0; i < productEntry.size(); i++) {
DynamicObject dynamicObject1 = productEntry.get(i);
Long id = (Long)dynamicObject1.getPkValue();
if (pkValue.compareTo(id)==0){
dynamicObject1.set("productentry_buildingarea",publicAndInside);
DynamicObject dynamicObject = productEntry.get(i);
Long id1 = dynamicObject.getLong("id");
if (id1.compareTo(id) == 0) {
dynamicObject.set("productentry_buildingarea", allArea);
this.getView().updateView("productentry_buildingarea",i);
break;
}
}
}
@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);
}
}
}
}