diff --git a/main/java/shkd/repc/repmd/formplugin/TotalAssignmentPlugin.java b/main/java/shkd/repc/repmd/formplugin/TotalAssignmentPlugin.java index 5592a06..558fb5e 100644 --- a/main/java/shkd/repc/repmd/formplugin/TotalAssignmentPlugin.java +++ b/main/java/shkd/repc/repmd/formplugin/TotalAssignmentPlugin.java @@ -38,6 +38,7 @@ import kd.tsc.tsrbs.business.domain.oprecord.service.helper.OprecordHelper; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; +import java.util.stream.Collectors; /** * 位置:【项目主数据】-【项目建立】-表单插件 @@ -93,12 +94,28 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic public void entryRowClick(RowClickEvent evt) { EntryGrid entryGrid = (EntryGrid) evt.getSource(); if (PRODUCT_ENTRY.equals(entryGrid.getKey())) { - // 业务逻辑 - DynamicObjectCollection subEntryEntity = (DynamicObjectCollection) this.getModel().getValue(SUB_ENTRY); - if (subEntryEntity != null) { - onlyCalculateArea(subEntryEntity); + //选中行 + int[] selectRows = entryGrid.getSelectRows(); + if (selectRows != null && selectRows.length > 0) { + //产品构成 + DynamicObjectCollection productEntity = this.getModel().getEntryEntity(PRODUCT_ENTRY); + if (null !=productEntity && productEntity.size()!=0){ + DynamicObjectCollection areaEntry = new DynamicObjectCollection(); + for (int selectRow : selectRows) { + DynamicObject productObj = productEntity.get(selectRow); + if (null!=productObj){ + DynamicObjectCollection collection = productObj.getDynamicObjectCollection(SUB_ENTRY); + if (null!=collection&&collection.size()!=0){ + areaEntry.addAll(collection); + } + } + } + if (areaEntry.size()!=0) { + onlyCalculateArea(areaEntry); + } + this.getView().updateView(SUB_ENTRY); + } } - this.getView().updateView(SUB_ENTRY); } } @@ -111,17 +128,23 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic String fieldKey = e.getProperty().getName(); switch (fieldKey){ case ENTRY_VALUE: + int index = this.getModel().getEntryCurrentRowIndex(PRODUCT_ENTRY); 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); + if (null!=collections&&collections.size()!=0){ + 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); + } + //依旧选择该行数据 + EntryGrid entryGrid = this.getControl("productentry"); + entryGrid.selectRows(index); } break; case BILL_NAME: @@ -151,27 +174,50 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic 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; + //进入页面 + boolean isImport = productEntry.stream() + .allMatch(d -> d.getLong("id") != 0L); + //防止页面打开触发该方法 + if (!isImport){ + //选中第一条数据 + EntryGrid entryGrid = this.getControl("productentry"); + entryGrid.selectRows(0); + //已保存数据的产品id + Set savedProductTypeIds = productEntry.stream() + .filter(d -> d.getLong("id")!=0L) + .map(d -> d.getLong("productentry_producttype.id")) + .collect(Collectors.toSet()); + //相同产品数据 + boolean exitSameProduct = false; + // 2. 倒序循环检查未保存数据(id == 0L) + for (int i = productEntry.size() - 1; i >= 0; i--) { + DynamicObject dynamicObject = productEntry.get(i); + long id = dynamicObject.getLong("id"); + if (id == 0L) { // 未保存数据 + long productTypeId = dynamicObject.getLong("productentry_producttype.id"); + if (savedProductTypeIds.contains(productTypeId)) { + // 获取未保存数据的 transferredEntry + DynamicObjectCollection transferredEntry = dynamicObject.getDynamicObjectCollection(SUB_ENTRY); + if (transferredEntry != null && !transferredEntry.isEmpty()) { + // 3. 查找对应的已保存数据 + for (DynamicObject savedObject : productEntry) { + if (savedObject.getLong("id") != 0L && savedObject.getLong("productentry_producttype.id")==productTypeId) { + // 4. 替换已保存数据的 SUB_ENTRY + savedObject.set(SUB_ENTRY, transferredEntry); + // 5. 移除未保存的数据 + productEntry.remove(i); + exitSameProduct=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++) { + if (exitSameProduct){ + for (int i = 0; i < productEntry.size(); i++) { //获取产品构成分录相关联的面积数据分录 - DynamicObjectCollection collections = productParent.get(i).getDynamicObjectCollection(SUB_ENTRY); + DynamicObjectCollection collections = productEntry.get(i).getDynamicObjectCollection(SUB_ENTRY); //先清空计入估算表数值再赋值,触发保存 for (int j = 0; j < collections.size(); j++) { if (collections.get(j).getString("qeug_fl").equals("非标")){ @@ -185,8 +231,31 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic } } } - this.getView().addClientCallBack("auto_save", 0); + }else { + 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++) { + if (collections.get(j).getString("qeug_fl").equals("非标")){ + this.getModel().setValue("qeug_jrgsbsz", BigDecimal.ONE, j, i); + this.getModel().setValue("qeug_jrgsbsz", BigDecimal.ZERO, j, i); + }else { + this.getModel().setValue("qeug_jrgsbsz", BigDecimal.ZERO, j, i); + BigDecimal hjs = collections.get(j).getBigDecimal("qeug_hjs"); + BigDecimal tzz = collections.get(j).getBigDecimal("qeug_tzz"); + this.getModel().setValue("qeug_jrgsbsz", hjs.add(tzz), j, i); + } + } + } + } } + this.getView().addClientCallBack("auto_save", 0); } } } @@ -200,14 +269,14 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic DynamicObjectCollection productEntry = this.getModel().getEntryEntity(PRODUCT_ENTRY); if (null != productEntry && productEntry.size() != 0) { for (int i = 0; i < productEntry.size(); i++) { - if (productEntry.get(i).getBigDecimal("productentry_buildingarea").compareTo(BigDecimal.ZERO) == 0) { - DynamicObjectCollection collections = productEntry.get(i).getDynamicObjectCollection(SUB_ENTRY); + DynamicObjectCollection collections = productEntry.get(i).getDynamicObjectCollection(SUB_ENTRY); + if (null!=collections){ this.setProductEntryValue(productEntry,collections,productEntry.get(i).getLong("id")); //指标信息赋值 Long typeId = productEntry.get(i).getLong("productentry_producttype.id"); this.updateMetricInfo(collections, typeId, pkValue); - } + } Tab tab = this.getView().getControl("tabap"); tab.activeTab("indexpage_tab"); @@ -313,9 +382,9 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic indexVsMsgMap.put(rowNum, "第" + (i + 1) + "行:产品类型编码不能为空或空字符串"); } // 校验物料编码是否已经存在于当前页面的表格中 - if (existCodes.contains(number)) { - indexVsMsgMap.put(rowNum, "第" + (i + 1) + "行:产品类型编码已存在表单分录,不能重复导入"); - } +// if (existCodes.contains(number)) { +// indexVsMsgMap.put(rowNum, "第" + (i + 1) + "行:产品类型编码已存在表单分录,不能重复导入"); +// } } return indexVsMsgMap; } @@ -430,15 +499,23 @@ public class TotalAssignmentPlugin extends AbstractFormPlugin implements RowClic */ private void setProductEntryValue(DynamicObjectCollection productEntry, DynamicObjectCollection collections, Long id) { //公区面积汇总 - BigDecimal publicArea = areaSummary(collections,"公区"); - //套内面积汇总 - BigDecimal hardcoverArea = areaSummary(collections,"套内"); - //防水面积汇总 - BigDecimal waterproofArea = areaSummary(collections,"防水"); - //可出租面积 - BigDecimal hireArea = areaSummary(collections,"可出租面积"); - //总面积 - BigDecimal allArea = areaSummary(collections,"总面积"); + BigDecimal publicArea=BigDecimal.ZERO; + BigDecimal hardcoverArea=BigDecimal.ZERO; + BigDecimal waterproofArea=BigDecimal.ZERO; + BigDecimal hireArea=BigDecimal.ZERO; + BigDecimal allArea=BigDecimal.ZERO; + if (collections.size()!=0){ + //公区面积汇总 + publicArea = areaSummary(collections,"公区"); + //套内面积汇总 + hardcoverArea = areaSummary(collections,"套内"); + //防水面积汇总 + waterproofArea = areaSummary(collections,"防水"); + //可出租面积 + hireArea = areaSummary(collections,"可出租面积"); + //总面积 + allArea = areaSummary(collections,"总面积"); + } for (int i = 0; i < productEntry.size(); i++) { DynamicObject dynamicObject = productEntry.get(i); diff --git a/main/java/shkd/repc/repmd/template/AreaDataExportPlugin.java b/main/java/shkd/repc/repmd/template/AreaDataExportPlugin.java new file mode 100644 index 0000000..8526a38 --- /dev/null +++ b/main/java/shkd/repc/repmd/template/AreaDataExportPlugin.java @@ -0,0 +1,261 @@ +package shkd.repc.repmd.template; + +import kd.bos.context.RequestContext; +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.utils.StringUtils; +import kd.bos.entity.ExtendedDataEntity; +import kd.bos.entity.plugin.AbstractOperationServicePlugIn; +import kd.bos.entity.plugin.AddValidatorsEventArgs; +import kd.bos.entity.plugin.args.AfterOperationArgs; +import kd.bos.entity.validate.AbstractValidator; +import kd.bos.form.*; +import kd.bos.form.control.Control; +import kd.bos.form.control.EntryGrid; +import kd.bos.form.control.events.ItemClickEvent; +import kd.bos.form.events.MessageBoxClosedEvent; +import kd.bos.form.plugin.AbstractFormPlugin; +import kd.bos.orm.query.QCP; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.sdk.plugin.Plugin; +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import shkd.repc.repmd.template.util.ExportTemplateUtil; +import shkd.repc.repmd.template.util.Template; + +import java.math.BigDecimal; +import java.util.*; + +/** + * 面积数据导出-二开插件 + */ +public class AreaDataExportPlugin extends AbstractFormPlugin implements Plugin { + + + @Override + public void registerListener(EventObject e) { + super.registerListener(e); + this.addItemClickListeners("qeug_advcontoolbarap"); + } + + @Override + public void itemClick(ItemClickEvent evt) { + super.itemClick(evt); + if (StringUtils.equals("qeug_areadataexport", evt.getItemKey())) { + DynamicObjectCollection productEntry = this.getModel().getEntryEntity("productentry"); + if (null==productEntry||productEntry.size()==0){ + this.getView().showMessage("暂无可导出数据!"); + return; + } + EntryGrid entryGrid = this.getControl("productentry"); + int[] selectRows = entryGrid.getSelectRows(); + String top="导出确认提示"; + String body; + //默认导出 + if (selectRows.length==0){ + body = "默认导出所有【产品构成】数据?"; + this.showExportMessage(top,body,"default"); + }else { + body = "导出 " + selectRows.length + " 行【产品构成】数据?"; + this.showExportMessage(top,body,"select"); + } + } + } + + @Override + public void confirmCallBack(MessageBoxClosedEvent evt) { + super.confirmCallBack(evt); + String callBackId = evt.getCallBackId(); + StringBuilder tipsBuffer = new StringBuilder(); + + if (StringUtils.equalsIgnoreCase("export_area", callBackId) && evt.getResult().getValue() == 6) { + String customValue = evt.getCustomVaule(); + boolean isDefaultExport = "default".equals(customValue); + + // 获取模板 + DynamicObject templateObj = getTemplate(); + if (templateObj == null) { + return; + } + + // 读取系统模板 + Control productView = this.getView().getControl("productentry"); + Control areaView = this.getView().getControl("qeug_subentryentity"); + List