1.新增-导入相同产品更新面积数据功能
2.优化-选中产品构成更改面积数据后刷新页面不丢失选中行 3.优化-多选产品构成后面积合计数据可汇总显示 4.新增-二开引出,根据勾选的产品构成引出分录数据(携带产品名称),可多选; 标准引出按钮(隐藏)
This commit is contained in:
parent
7296f5be49
commit
a2bece6b4d
|
@ -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<Long> 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);
|
||||
|
|
|
@ -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<Template> templateList = ExportTemplateUtil.readSysTemplate(templateObj, productView, areaView, tipsBuffer);
|
||||
if (templateList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建 Excel
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = createExcelSheet(workbook, templateList, areaView);
|
||||
|
||||
// 获取表头信息(第三行)
|
||||
List<String> columnHeaders = getColumnHeaders(sheet);
|
||||
|
||||
// 获取数据
|
||||
DynamicObjectCollection productEntry = this.getModel().getEntryEntity("productentry");
|
||||
List<DynamicObject> exportData = isDefaultExport ? new ArrayList<>(productEntry) : getSelectedData(productEntry);
|
||||
|
||||
// 填充数据
|
||||
fillExcelData(sheet, exportData, columnHeaders);
|
||||
|
||||
// 上传文件并提供下载链接
|
||||
exportAndDownload(workbook, customValue);
|
||||
|
||||
tipsBuffer.append("导出成功");
|
||||
this.getView().showSuccessNotification(tipsBuffer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板对象
|
||||
*/
|
||||
private DynamicObject getTemplate() {
|
||||
QFilter numberFilter = new QFilter("number", QCP.equals, "repmd_projectbill_IMPT_ENTRY");
|
||||
return BusinessDataServiceHelper.loadSingle("bos_importentry_template", numberFilter.toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 Excel Sheet 并填充标题、描述、表头等
|
||||
*/
|
||||
private XSSFSheet createExcelSheet(XSSFWorkbook workbook, List<Template> templateList, Control areaView) {
|
||||
XSSFSheet sheet = workbook.createSheet("产品构成 # productentry");
|
||||
ExportTemplateUtil.createTitleRow(sheet, workbook);
|
||||
ExportTemplateUtil.createDescriptionRow(sheet, workbook);
|
||||
ExportTemplateUtil.createTemplateHeaders(sheet, workbook, templateList);
|
||||
ExportTemplateUtil.otherStyleSet(sheet, areaView);
|
||||
return sheet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取第三行的表头信息
|
||||
*/
|
||||
private List<String> getColumnHeaders(XSSFSheet sheet) {
|
||||
List<String> columnHeaders = new ArrayList<>();
|
||||
XSSFRow thirdRow = sheet.getRow(2);
|
||||
if (thirdRow != null) {
|
||||
for (int cellIndex = 0; cellIndex < thirdRow.getLastCellNum(); cellIndex++) {
|
||||
XSSFCell cell = thirdRow.getCell(cellIndex);
|
||||
columnHeaders.add(cell != null ? cell.getStringCellValue().trim() : ""); // 避免 null
|
||||
}
|
||||
}
|
||||
return columnHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取选中的数据
|
||||
*/
|
||||
private List<DynamicObject> getSelectedData(DynamicObjectCollection productEntry) {
|
||||
List<DynamicObject> selectedData = new ArrayList<>();
|
||||
EntryGrid entryGrid = this.getControl("productentry");
|
||||
int[] selectedRows = entryGrid.getSelectRows();
|
||||
for (int row : selectedRows) {
|
||||
selectedData.add(productEntry.get(row));
|
||||
}
|
||||
return selectedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充 Excel 数据
|
||||
*/
|
||||
private void fillExcelData(XSSFSheet sheet, List<DynamicObject> productEntries, List<String> columnHeaders) {
|
||||
int rowIndex = 4; // 从 Excel 第 5 行开始填充
|
||||
for (DynamicObject productObj : productEntries) {
|
||||
if (productObj == null) continue;
|
||||
|
||||
String productTypeNumber = productObj.getString("productentry_producttype.number");
|
||||
String productTypeName = productObj.getString("productentry_producttype.name");
|
||||
DynamicObjectCollection areaEntries = productObj.getDynamicObjectCollection("qeug_subentryentity");
|
||||
|
||||
if (areaEntries != null && !areaEntries.isEmpty()) {
|
||||
for (DynamicObject areaObj : areaEntries) {
|
||||
XSSFRow dataRow = sheet.createRow(rowIndex);
|
||||
int cellIndex = 0;
|
||||
|
||||
for (String header : columnHeaders) {
|
||||
XSSFCell cell = dataRow.createCell(cellIndex);
|
||||
|
||||
if ("productentry_producttype.number".equals(header)) {
|
||||
cell.setCellValue(productTypeNumber);
|
||||
} else if ("productentry_producttype.name".equals(header)) {
|
||||
cell.setCellValue(productTypeName);
|
||||
} else {
|
||||
Object value = areaObj.get(header);
|
||||
setCellValue(cell, value);
|
||||
}
|
||||
cellIndex++;
|
||||
}
|
||||
rowIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 Excel 单元格值
|
||||
*/
|
||||
private void setCellValue(XSSFCell cell, Object value) {
|
||||
if (value instanceof String) {
|
||||
cell.setCellValue((String) value);
|
||||
} else if (value instanceof BigDecimal) {
|
||||
cell.setCellValue(((BigDecimal) value).doubleValue());
|
||||
} else if (value instanceof Integer) {
|
||||
cell.setCellValue((Integer) value);
|
||||
} else if (value instanceof Double) {
|
||||
cell.setCellValue((Double) value);
|
||||
} else if (value != null) {
|
||||
cell.setCellValue(value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出 Excel 并提供下载链接
|
||||
*/
|
||||
private void exportAndDownload(XSSFWorkbook workbook, String fileName) {
|
||||
String uploadedFilePath = ExportTemplateUtil.uploadExcel(workbook, fileName);
|
||||
String url = RequestContext.get().getClientFullContextPath() + "/attachment/download.do?path=" + uploadedFilePath;
|
||||
this.getView().openUrl(url);
|
||||
}
|
||||
|
||||
private void showExportMessage(String top,String body,String customValue){
|
||||
// 基本信息
|
||||
// 备注: \r\n 可换行
|
||||
//String msg = "消息头\r\n message header...";
|
||||
// 详细消息
|
||||
//String detail = "消息体\r\nmessage body...";
|
||||
// 消息框按钮类型
|
||||
// None:不启用 Toast:简短提示,几秒后消失
|
||||
MessageBoxOptions options = MessageBoxOptions.OKCancel;
|
||||
// 确认提示类型
|
||||
// Default:默认提示 Save:保存提交类提示 Delete:删除类提示 Wait:等待类提示 Fail:失败类提示
|
||||
ConfirmTypes confirmTypes = ConfirmTypes.Default;
|
||||
// 确认框回调
|
||||
ConfirmCallBackListener callBack = new ConfirmCallBackListener("export_area", this);
|
||||
// 按钮名称
|
||||
// 注意: 按钮名称参数Map的key值必须和 options 参数相对应, 否则按钮名称修改不生效!
|
||||
// 例: options 使用 MessageBoxOptions.OKCancel, 则 按钮名称参数Map的key必须为2 or 6
|
||||
// options 使用 MessageBoxOptions.AbortRetryIgnore, 则 按钮名称参数Map的key必须为3 or 4 or 5
|
||||
// none-0; ok-1; cancel-2; abort-3; retry-4; ignore-5; yes-6; no-7; custom-8
|
||||
// -----------------------------------------------------------------
|
||||
// options | btnNameMaps的key的取值
|
||||
// MessageBoxOptions.None | 2
|
||||
// MessageBoxOptions.OK | 2
|
||||
// MessageBoxOptions.OKCancel | 2 & 6
|
||||
// MessageBoxOptions.AbortRetryIgnore | 3 & 4 & 5
|
||||
// MessageBoxOptions.YesNoCancel | 6 & 7 & 2
|
||||
// MessageBoxOptions.YesNo | 6 & 7
|
||||
// MessageBoxOptions.RetryCancel | 4 & 2
|
||||
// MessageBoxOptions.Toast | 2
|
||||
// -----------------------------------------------------------------
|
||||
Map<Integer, String> btnNameMaps = new HashMap<>();
|
||||
btnNameMaps.put(2, "取消");
|
||||
btnNameMaps.put(6, "确认");
|
||||
// 用户自定义参数,前端会在afterConfirm中返回
|
||||
//String customValue = "allowExport";
|
||||
this.getView().showConfirm(top, body, options, confirmTypes, callBack, btnNameMaps,customValue);
|
||||
}
|
||||
}
|
|
@ -63,7 +63,7 @@ public class ExportTemplateUtil {
|
|||
createDescriptionRow(sheet, workbook);
|
||||
createTemplateHeaders(sheet, workbook, templateList);
|
||||
//其它设置
|
||||
otherStyleSet(sheet,workbook,areaView);
|
||||
otherStyleSet(sheet,areaView);
|
||||
// 上传Excel文件并获取下载路径
|
||||
String uploadedFilePath = uploadExcel(workbook, templateName);
|
||||
return RequestContext.get().getClientFullContextPath() + "/attachment/download.do?path=" + uploadedFilePath;
|
||||
|
@ -109,7 +109,7 @@ public class ExportTemplateUtil {
|
|||
createDescriptionRow(sheet, workbook);
|
||||
createTemplateHeaders(sheet, workbook, templateList);
|
||||
//其它设置
|
||||
otherStyleSet(sheet,workbook,areaView);
|
||||
otherStyleSet(sheet,areaView);
|
||||
|
||||
// 填充自定义模板数据
|
||||
fillCustomTemplateData(sheet, workbook, collections, templateList, message);
|
||||
|
@ -125,7 +125,7 @@ public class ExportTemplateUtil {
|
|||
}
|
||||
}
|
||||
|
||||
private static void otherStyleSet(XSSFSheet sheet,XSSFWorkbook workbook, Control areaView) {
|
||||
public static void otherStyleSet(XSSFSheet sheet, Control areaView) {
|
||||
int numColumns = sheet.getRow(3).getPhysicalNumberOfCells(); // 获取总列数
|
||||
|
||||
// 遍历第四行,检查是否为“分类”或“*分类”
|
||||
|
@ -163,7 +163,7 @@ public class ExportTemplateUtil {
|
|||
/**
|
||||
* 创建标题行
|
||||
*/
|
||||
private static void createTitleRow(XSSFSheet sheet, XSSFWorkbook workbook) {
|
||||
public static void createTitleRow(XSSFSheet sheet, XSSFWorkbook workbook) {
|
||||
XSSFRow row1 = sheet.createRow(0);
|
||||
XSSFCell cell1 = row1.createCell(0);
|
||||
cell1.setCellValue("产品构成 # productentry");
|
||||
|
@ -186,7 +186,7 @@ public class ExportTemplateUtil {
|
|||
/**
|
||||
* 创建说明行
|
||||
*/
|
||||
private static void createDescriptionRow(XSSFSheet sheet, XSSFWorkbook workbook) {
|
||||
public static void createDescriptionRow(XSSFSheet sheet, XSSFWorkbook workbook) {
|
||||
XSSFRow row2 = sheet.createRow(1);
|
||||
XSSFCell cell3 = row2.createCell(0);
|
||||
cell3.setCellValue("1、请将鼠标移到灰色标题行查看字段录入要求。2、红色带星号(*)的字段为必录字段。");
|
||||
|
@ -209,7 +209,7 @@ public class ExportTemplateUtil {
|
|||
/**
|
||||
* 创建模板头部行
|
||||
*/
|
||||
private static void createTemplateHeaders(XSSFSheet sheet, XSSFWorkbook workbook, List<Template> templateList) {
|
||||
public static void createTemplateHeaders(XSSFSheet sheet, XSSFWorkbook workbook, List<Template> templateList) {
|
||||
XSSFRow row3 = sheet.createRow(2);
|
||||
for (int i = 0; i < templateList.size(); i++) {
|
||||
Template template = templateList.get(i);
|
||||
|
@ -266,6 +266,7 @@ public class ExportTemplateUtil {
|
|||
for (int i = 0; i < collections.size(); i++) {
|
||||
DynamicObject dynamicObject = collections.get(i);
|
||||
String productNumber = dynamicObject.getString("qeug_productentry.number");
|
||||
String productName = dynamicObject.getString("qeug_productentry.name");
|
||||
String name = dynamicObject.getString("qeug_kmname");
|
||||
String type = dynamicObject.getString("qeug_fl");
|
||||
|
||||
|
@ -275,11 +276,13 @@ public class ExportTemplateUtil {
|
|||
try {
|
||||
// 获取列索引
|
||||
int productNumberColumnIndex = findColumnIndex(sheet, "productentry_producttype.number");
|
||||
int productNameColumnIndex = findColumnIndex(sheet, "productentry_producttype.name");
|
||||
int nameColumnIndex = findColumnIndex(sheet, "qeug_kmname");
|
||||
int typeColumnIndex = findColumnIndex(sheet, "qeug_fl");
|
||||
|
||||
// 填充数据
|
||||
createCell(dataRow, productNumberColumnIndex, productNumber, workbook);
|
||||
createCell(dataRow, productNameColumnIndex, productName, workbook);
|
||||
createCell(dataRow, nameColumnIndex, name, workbook);
|
||||
createCell(dataRow, typeColumnIndex, type, workbook);
|
||||
|
||||
|
@ -333,7 +336,7 @@ public class ExportTemplateUtil {
|
|||
/**
|
||||
* 上传Excel文件并返回路径
|
||||
*/
|
||||
private static String uploadExcel(XSSFWorkbook workbook, String templateName) {
|
||||
public static String uploadExcel(XSSFWorkbook workbook, String templateName) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
|
||||
String fileName = templateName + sdf.format(new Date()) + ".xlsx";
|
||||
String pathName = "/offices/" + fileName;
|
||||
|
@ -405,6 +408,21 @@ public class ExportTemplateUtil {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
// **固定插入第二行 (索引 1) 一个 Template**
|
||||
Template productNameTemplate = new Template();
|
||||
productNameTemplate.setName("产品名称");
|
||||
productNameTemplate.setNumber("productentry_producttype.name");
|
||||
productNameTemplate.setMustInput(false);
|
||||
productNameTemplate.setImport(true);
|
||||
productNameTemplate.setImportProp("");
|
||||
|
||||
// **插入到第二行,如果列表长度 < 1,则直接添加**
|
||||
if (templateList.size() > 1) {
|
||||
templateList.add(1, productNameTemplate);
|
||||
} else {
|
||||
templateList.add(productNameTemplate);
|
||||
}
|
||||
} else {
|
||||
message.append("模板中的 treeentryentity 为空或不存在\n");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue