news 2026/3/6 8:27:38

java动态渲染列导出以及分页列表

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
java动态渲染列导出以及分页列表

1.查询方法

@Override public DishAppStallPersonnelPageBaseVo pageList(Page<DishAppStallPersonnelPageVo> page, DishAppStallPersonnelPageDto pageDto) { // 获取已绑定的收银门店集合 Map<String, MutablePair<String, StoreInfoListVO>> storeMap = getStoreIds(); List<BaseAttributesJsonVo> stallList = this.infoService.getAttributesList(List.of(), DishInfoTypeEnum.DISH_INFO_STALL.getCode()); // 校验是否有新增门店 this.checkStallPersonnelStore(stallList, storeMap); // 获取门店id集合 List<String> storeIds = StrUtil.isNotBlank(pageDto.getKeyword()) ? storeMap.entrySet().stream().filter(entry -> entry.getKey().contains(pageDto.getKeyword())).map(entry -> entry.getValue().getLeft()).collect(Collectors.toList()) : new ArrayList<>(storeMap.values().stream().map(MutablePair::getLeft).collect(Collectors.toList())); Page<DishAppStallPersonnelPageVo> pageList = baseMapper.getPageList(page, storeIds); if (CollUtil.isEmpty(pageList.getRecords())) { return DishAppStallPersonnelPageBaseVo.builder() .isStall(CollUtil.isEmpty(stallList) ? 0 : 1) .pageList(CultivatePage.coverPageList(page)) .build(); } // 设置档口人员列表 pageList.getRecords().forEach(pageListVo -> { pageListVo.setStallPersonnelList(JSON.parseArray(pageListVo.getStallPersonnelJson(), BaseAttributesJsonVo.class)); }); //处理每条数据的长度不一样,要处理成一样的,并且保证顺序一致 processStallPointData(stallList, pageList.getRecords(), storeMap); return DishAppStallPersonnelPageBaseVo.builder() .isStall(CollUtil.isEmpty(stallList) ? 0 : 1) .pageList(CultivatePage.coverPageList(pageList)) .build(); } public void export(HttpServletResponse response, DishAppStallPersonnelPageDto pageDto) { // 获取已绑定的收银门店集合 Map<String, MutablePair<String, StoreInfoListVO>> storeMap = getStoreIds(); // 获取获取系统最新档口数据集合(动态渲染列) List<BaseAttributesJsonVo> stallList = this.infoService.getAttributesList(List.of(), DishInfoTypeEnum.DISH_INFO_STALL.getCode()); // 校验是否有新增门店 this.checkStallPersonnelStore(stallList, storeMap); // 获取门店id集合 List<String> storeIds = StrUtil.isNotBlank(pageDto.getKeyword()) ? storeMap.entrySet().stream().filter(entry -> entry.getKey().contains(pageDto.getKeyword())).map(entry -> entry.getValue().getLeft()).collect(Collectors.toList()) : new ArrayList<>(storeMap.values().stream().map(MutablePair::getLeft).collect(Collectors.toList())); List<DishAppStallPersonnelPageVo> summaryVoList = this.baseMapper.getDataList(storeIds); if (CollUtil.isNotEmpty(summaryVoList)) { // 设置档口人员列表 summaryVoList.forEach(pageListVo -> { pageListVo.setStallPersonnelList(JSON.parseArray(pageListVo.getStallPersonnelJson(), BaseAttributesJsonVo.class)); }); } //处理每条数据的长度不一样,要处理成一样的,并且保证顺序一致 processStallPointData(stallList, summaryVoList, storeMap); //获取动态表头 List<List<String>> list = new ArrayList<>(); list.add(Collections.singletonList("门店名称")); List<List<String>> headers = EasyExcelUtil.getHeaders(stallList, list); //获取动态数据 List<List<Object>> dataList = EasyExcelUtil.getDataList(summaryVoList); EasyExcelUtil.rankingExportData(dataList, headers, "档口人员数据", "档口人员数据表", response); }

2.处理动态列数据

/** * 处理每条数据的长度不一样,要处理成一样的,并且保证顺序一致 * * @param attributesJsonVos 档口集合 * @param pageListVoList 待处理数据 * @param storeMap 门店集合 */ private void processStallPointData(List<BaseAttributesJsonVo> attributesJsonVos, List<DishAppStallPersonnelPageVo> pageListVoList, Map<String, MutablePair<String, StoreInfoListVO>> storeMap) { //获取所有技能点,并且按照sort字段排序 List<BaseAttributesJsonVo> sortedStallList = attributesJsonVos.stream().sorted(Comparator.comparing(BaseAttributesJsonVo::getSort)).collect(Collectors.toList()); LinkedHashMap<String, BaseAttributesJsonVo> skillCountVoMap = sortedStallList.stream().collect(Collectors.toMap(BaseAttributesJsonVo::getName, baseAttributesJsonVo -> baseAttributesJsonVo, (k1, k2) -> k1, LinkedHashMap::new)); Map<String, BaseAttributesJsonVo> skillCountMap; Map<String, StoreInfoListVO> storeInfoMap = storeMap.values().stream().collect(Collectors.toMap(MutablePair::getLeft, MutablePair::getRight)); for (DishAppStallPersonnelPageVo pageListVo : pageListVoList) { skillCountMap = pageListVo.getStallPersonnelList().stream().collect(Collectors.toMap(BaseAttributesJsonVo::getName, attributesJsonVo -> attributesJsonVo, (k1, k2) -> k1)); Map<String, BaseAttributesJsonVo> baseAttributesJsonVoMap = skillCountMap; List<BaseAttributesJsonVo> attributesJsonVoList = new LinkedList<>(); skillCountVoMap.forEach((name, skillCountVo) -> { if (baseAttributesJsonVoMap.containsKey(name)) { attributesJsonVoList.add(baseAttributesJsonVoMap.get(name)); } else { attributesJsonVoList.add(BaseAttributesJsonVo.builder() .id(skillCountVo.getId()) .sort(skillCountVo.getSort()) .name(skillCountVo.getName()) .value(null).build()); } }); pageListVo.setStallPersonnelList(attributesJsonVoList); pageListVo.setStoreName(storeInfoMap.get(pageListVo.getStoreId()).getName()); } }

3.导出工具类

package com.fantaibao.util; import cn.hutool.core.collection.CollUtil; import cn.hutool.http.Header; import cn.idev.excel.EasyExcel; import cn.idev.excel.util.ListUtils; import com.fantaibao.handler.CustomCellStyleHandler; import com.fantaibao.handler.CustomCellWriteHandler; import com.fantaibao.handler.CustomRowHeightHandler; import com.fantaibao.module.vo.appDish.BaseAttributesJsonVo; import com.fantaibao.module.vo.appDish.DishAppStallPersonnelPageVo; import org.apache.poi.ss.usermodel.*; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.InputStream; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.*; /** * easyExcel导入导出工具类 * @author yier */ public class EasyExcelUtil { /** * 获取动态表头 * @param stallList 数据集合 * @param list 已存在的动态表头 * @return 返回动态表头 */ public static List<List<String>> getHeaders(List<BaseAttributesJsonVo> stallList, List<List<String>> list) { if (CollUtil.isNotEmpty(stallList) && CollUtil.isNotEmpty(stallList)) { for (BaseAttributesJsonVo baseAttributesJsonVo : stallList) { List<String> head = new ArrayList<>(); head.add(baseAttributesJsonVo.getName()); list.add(head); } } return list; } /** * 获取表内容数据 * @param dataList 数据集合 * @return 表内容数据 */ public static List<List<Object>> getDataList(List<DishAppStallPersonnelPageVo> dataList) { List<List<Object>> list = ListUtils.newArrayList(); if (CollUtil.isNotEmpty(dataList)) { for (DishAppStallPersonnelPageVo rankingDTO : dataList) { List<Object> data = ListUtils.newArrayList(); data.add(rankingDTO.getStoreName()); if (CollUtil.isNotEmpty(rankingDTO.getStallPersonnelList())) { for (BaseAttributesJsonVo skillCountVo : rankingDTO.getStallPersonnelList()) { data.add(Objects.nonNull(skillCountVo.getValue()) ? skillCountVo.getValue() : ""); } } list.add(data); } } return list; } /** * 导出排行榜数据 * * @param list 导出数据 * @param headers 表头 * @param fileName 导出文件名称 * @param sheetName sheet名称 * @param response 响应对象 * @throws Exception 抛出异常 */ public static void rankingExportData(List<List<Object>> list, List<List<String>> headers, String fileName, String sheetName, HttpServletResponse response) throws Exception { EasyExcelUtil.export(response, fileName + ".xlsx", sheetName, list, headers); } /** * Excel导出功能(根据自定义表头) * * @param response 响应数据 * @param fileName 文件名 * @param sheetName sheet名 * @param list 数据列表 * @param headers 表头集合 */ public static void export(HttpServletResponse response, String fileName, String sheetName, List<List<Object>> list, List<List<String>> headers) throws Exception { ServletOutputStream outputStream = response.getOutputStream(); response.setCharacterEncoding("utf-8"); response.setHeader(Header.CONTENT_DISPOSITION.toString(), "attachment; filename=".concat(URLEncoder.encode(fileName, StandardCharsets.UTF_8))); response.setContentType("application/octet-stream"); EasyExcel.write(outputStream) .head(headers) .sheet(sheetName) .registerWriteHandler(new CustomRowHeightHandler()) .registerWriteHandler(new CustomCellStyleHandler()) .registerWriteHandler(new CustomCellWriteHandler()) .doWrite(list); } /** * 导入Excel,返回列表形式的数据 * * @param inputStream Excel文件流 * @return List<List < String>> 二维列表,第一行是表头,后续行是数据 */ public static List<List<String>> importExcel(InputStream inputStream) { List<List<String>> data = new ArrayList<>(); try { Workbook workbook = WorkbookFactory.create(inputStream); Sheet sheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = sheet.iterator(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); List<String> rowData = new ArrayList<>(); Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); rowData.add(getCellStringValue(cell)); } data.add(rowData); } workbook.close(); } catch (Exception e) { throw new RuntimeException("导入Excel失败: " + e.getMessage(), e); } return data; } /** * 获取单元格的字符串值 */ private static String getCellStringValue(Cell cell) { if (cell == null) { return ""; } switch (cell.getCellType()) { case STRING: return cell.getStringCellValue().trim(); case NUMERIC: double value = cell.getNumericCellValue(); if (value == (long) value) { return String.valueOf((long) value); } else { return String.valueOf(value); } case BOOLEAN: return String.valueOf(cell.getBooleanCellValue()); case FORMULA: try { return cell.getStringCellValue(); } catch (Exception e) { return String.valueOf(cell.getNumericCellValue()); } default: return ""; } } /** * 将Excel数据转换为Map列表格式 */ public static List<Map<String, String>> convertToMapList(List<List<String>> excelData) { if (excelData == null || excelData.isEmpty()) { return new ArrayList<>(); } List<Map<String, String>> result = new ArrayList<>(); // 第一行是表头 List<String> headers = excelData.get(0); for (int i = 1; i < excelData.size(); i++) { List<String> rowData = excelData.get(i); Map<String, String> rowMap = new HashMap<>(); for (int j = 0; j < headers.size(); j++) { String header = headers.get(j); String value = j < rowData.size() ? rowData.get(j) : ""; rowMap.put(header, value); } result.add(rowMap); } return result; } }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/3/3 17:21:09

vue2项目中WebUploader怎样实现局域网大文件分块上传?

一个大三学生的文件管理系统血泪史&#xff08;前端篇&#xff09; 各位看官&#xff0c;我是浙江某高校网络工程专业的大三学生&#xff0c;最近在搞一个"史诗级"项目——文件管理系统。为啥说是史诗级&#xff1f;因为光是需求就快把我整秃噜皮了&#xff01; 项…

作者头像 李华
网站建设 2026/3/3 23:27:09

金融系统开发中,KindEditor如何处理WORD报表截图粘贴?

前端老炮儿的CMS文档神器&#xff1a;KindEditor全能插件&#xff08;680元搞定&#xff01;&#xff09; 兄弟&#xff0c;作为刚接企业官网外包的前端程序员&#xff0c;我太懂你现在的处境了——客户要新闻发布模块支持Word/Excel/PPT/PDF导入Word粘贴&#xff0c;还要保留…

作者头像 李华
网站建设 2026/3/6 6:24:23

2026本科生必看8个降AI率工具测评榜单

2026本科生必看8个降AI率工具测评榜单 2026本科生必看的降AI率工具测评榜单 随着人工智能技术的快速发展&#xff0c;AIGC&#xff08;人工智能生成内容&#xff09;检测系统在学术领域的应用日益广泛。对于本科生而言&#xff0c;论文写作过程中若未能有效降低AI率&#xff0…

作者头像 李华
网站建设 2026/3/4 18:28:31

读懂别人搭建的复杂 FB 逻辑子块:核心方法 + 分步实操 + 避坑技巧

读懂别人搭建的复杂 FB 逻辑子块&#xff1a;核心方法 分步实操 避坑技巧 读懂拖拽式的复杂 Function Block 逻辑子块&#xff0c;核心不是 “逐块看细节”&#xff0c;而是先抓 “整体逻辑框架”&#xff0c;再拆 “子逻辑单元”&#xff0c;最后抠 “关键连接 / 参数”——…

作者头像 李华
网站建设 2026/3/6 6:26:52

SE11自定义域范围值的空值问题

前面的等号“”如何出现呢&#xff0c;方法如下在简短文字里随便输入几个字符&#xff0c;例如“空白"然后回车&#xff0c;前面的等号就自动出来了如果不需要”空白"字样&#xff0c;这个时候删除&#xff0c;在回车&#xff0c;等号仍然岿然不动然后保存激活

作者头像 李华
网站建设 2026/3/5 0:27:24

首本鸿蒙架构师培养手册《鸿蒙架构师修炼之道》简介

《鸿蒙架构师修炼之道》已于近日上市&#xff0c;该书由北京大学出版社出版。该书主要介绍如何培养鸿蒙架构师&#xff0c;内容涉及HarmonyOS架构设计思维/原理/模式、工具、编程语言、UI设计、线程模型设计、通信设计、持久化设计、安全性、测试、调优调测等多方面。 本文希望…

作者头像 李华