| | |
| | | * @author ruoyi |
| | | */ |
| | | public class ExcelUtil<T> { |
| | | |
| | | public static final String FORMULA_REGEX_STR = "=|-|\\+|@"; |
| | | public static final String[] FORMULA_STR = {"=", "-", "+", "@"}; |
| | | /** |
| | |
| | | * 标题 |
| | | */ |
| | | private String title; |
| | | /** |
| | | * 搜索时间 |
| | | */ |
| | | private String timeDesc; |
| | | /** |
| | | * 制表人 |
| | | */ |
| | | private String createUser; |
| | | /** |
| | | * 制表时间 |
| | | */ |
| | | private Date createTime; |
| | | |
| | | /** |
| | | * 最大高度 |
| | | */ |
| | |
| | | createSubHead(); |
| | | } |
| | | |
| | | public void init(List<T> list, String sheetName, String title, Type type, String timeDesc, String createUser, Date createTime) { |
| | | if (list == null) { |
| | | list = new ArrayList<T>(); |
| | | } |
| | | this.list = list; |
| | | this.sheetName = sheetName; |
| | | this.type = type; |
| | | this.title = title; |
| | | this.timeDesc = timeDesc; |
| | | this.createUser = createUser; |
| | | this.createTime = createTime; |
| | | createExcelField(); |
| | | createWorkbook(); |
| | | createTitle(); |
| | | createSecondHead(); |
| | | createSubHead(); |
| | | } |
| | | |
| | | /** |
| | | * 创建excel第一行标题 |
| | | */ |
| | |
| | | sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(), titleLastCol)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建第二行自定义内容 |
| | | * |
| | | * @author sgj |
| | | * @since 2026/03/09 |
| | | */ |
| | | public void createSecondHead() { |
| | | if (StringUtils.isNotBlank(timeDesc) && StringUtils.isNotBlank(createUser) && createTime != null) { |
| | | subMergedFirstRowNum++; |
| | | subMergedLastRowNum++; |
| | | //第二行,添加搜索时间,创建人, 创建时间信息 |
| | | Row secondRow = sheet.createRow(rownum); |
| | | secondRow.setHeightInPoints(30); |
| | | int titleLastCol = this.fields.size() - 1; |
| | | if (isSubList()) { |
| | | titleLastCol = titleLastCol + subFields.size() - 1; |
| | | } |
| | | |
| | | // 创建三个单元格,分别用于搜索时间、创建人、创建时间 |
| | | // 第一列:搜索时间 |
| | | Cell timeDescCell = secondRow.createCell(0); |
| | | timeDescCell.setCellValue("查询时间:"+timeDesc); |
| | | timeDescCell.setCellStyle(styles.get("secTitle")); |
| | | |
| | | // 中间列:创建人 |
| | | int createUserCol = (titleLastCol + 1) / 2; |
| | | Cell createUserCell = secondRow.createCell(createUserCol); |
| | | createUserCell.setCellValue("制表人:"+createUser); |
| | | createUserCell.setCellStyle(styles.get("secTitle")); |
| | | |
| | | // 最后一列:创建时间 |
| | | Cell createTimeCell = secondRow.createCell(titleLastCol - 1); |
| | | createTimeCell.setCellValue("制表时间:"+parseDateToStr("yyyy-MM-dd HH:mm:ss", createTime)); |
| | | createTimeCell.setCellStyle(styles.get("secTitle")); |
| | | |
| | | // 合并单元格 |
| | | sheet.addMergedRegion(new CellRangeAddress(secondRow.getRowNum(), secondRow.getRowNum(), 0, 1)); |
| | | sheet.addMergedRegion(new CellRangeAddress(secondRow.getRowNum(), secondRow.getRowNum(), createUserCol, createUserCol + 1)); |
| | | sheet.addMergedRegion(new CellRangeAddress(secondRow.getRowNum(), secondRow.getRowNum(), titleLastCol - 1, titleLastCol)); |
| | | |
| | | rownum++; |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 创建对象的子列表名称 |
| | |
| | | this.init(list, sheetName, title, Type.EXPORT); |
| | | return exportExcel(); |
| | | } |
| | | |
| | | /** |
| | | * 对list数据源将其里面的数据导入到excel表单 |
| | | * |
| | | * @param list 导出数据集合 |
| | | * @param sheetName 工作表的名称 |
| | | * @param title 标题 |
| | | * @param timeDesc 查询时间 |
| | | * @param createUser 制表人 |
| | | * @param createTime 制表时间 |
| | | * @return 结果 |
| | | */ |
| | | public AjaxResult exportExcel(List<T> list, String sheetName, String title, String timeDesc, String createUser, Date createTime) { |
| | | if (StringUtils.isBlank(timeDesc) || StringUtils.isBlank(createUser) || createTime == null) { |
| | | this.init(list, sheetName, title, Type.EXPORT); |
| | | } else { |
| | | this.init(list, sheetName, title, Type.EXPORT, timeDesc, createUser, createTime); |
| | | } |
| | | return exportExcel(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 对list数据源将其里面的数据导入到excel表单 |
| | |
| | | style.setFont(dataFont); |
| | | styles.put("data", style); |
| | | |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | Font dataFontTwo = wb.createFont(); |
| | | dataFontTwo.setFontName("Arial"); |
| | | dataFontTwo.setFontHeightInPoints((short) 10); |
| | | style.setFont(dataFontTwo); |
| | | styles.put("secTitle", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | |
| | | "depotId":data.get("depotId"),
 |
| | | "foodVariety":data.get("foodVariety"),
 |
| | | "start":data.get("start"),
 |
| | | "end":data.get("end")
 |
| | | "end":data.get("end"),
 |
| | | "timeDesc":data.get("timeDesc"),
 |
| | | "createUser":data.get("createUser"),
 |
| | | "createTime":data.get("createTime")
 |
| | | }
 |
| | | window.parent.$.table.exportExcelDorado("./export/inout-excel", "入库数据", param);</ClientEvent> |
| | | <Property name="caption">导出EXCEL</Property> |
| | |
| | | "deptId":data.get("deptId"),
 |
| | | "companyId":data.get("companyId"),
 |
| | | "start":data.get("start"),
 |
| | | "end":data.get("end")
 |
| | | "end":data.get("end"),
 |
| | | "timeDesc":data.get("timeDesc"),
 |
| | | "createUser":data.get("createUser"),
 |
| | | "createTime":data.get("createTime")
 |
| | | }
 |
| | | window.parent.$.table.exportExcelDorado("./export/inout-excel", "入库数据", param);</ClientEvent> |
| | | <Property name="caption">导出EXCEL</Property> |
| | |
| | | "depotId":data.get("depotId"),
 |
| | | "foodVariety":data.get("foodVariety"),
 |
| | | "start":data.get("start"),
 |
| | | "end":data.get("end")
 |
| | | "end":data.get("end"),
 |
| | | "timeDesc":data.get("timeDesc"),
 |
| | | "createUser":data.get("createUser"),
 |
| | | "createTime":data.get("createTime")
 |
| | | }
 |
| | | window.parent.$.table.exportExcelDorado("./export/inout-excel", "出库数据", param);</ClientEvent> |
| | | <Property name="caption">导出EXCEL</Property> |
| | |
| | | "deptId":data.get("deptId"),
 |
| | | "companyId":data.get("companyId"),
 |
| | | "start":data.get("start"),
 |
| | | "end":data.get("end")
 |
| | | "end":data.get("end"),
 |
| | | "timeDesc":data.get("timeDesc"),
 |
| | | "createUser":data.get("createUser"),
 |
| | | "createTime":data.get("createTime")
 |
| | | }
 |
| | | window.parent.$.table.exportExcelDorado("./export/inout-excel", "出库数据", param);</ClientEvent> |
| | | <Property name="caption">导出EXCEL</Property> |
| | |
| | | <Property></Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="createUser"> |
| | | <Property name="label">创建人</Property> |
| | | <Property name="label">制表人</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="createTime"> |
| | | <Property name="dataType">DateTime</Property> |
| | |
| | | "deptId":data.get("deptId"),
 |
| | | "customerId":data.get("customerId"),
 |
| | | "start":data.get("start"),
 |
| | | "end":data.get("end")
 |
| | | "end":data.get("end"),
 |
| | | "timeDesc":data.get("timeDesc"),
 |
| | | "createUser":data.get("createUser"),
 |
| | | "createTime":data.get("createTime")
 |
| | | }
 |
| | | window.parent.$.table.exportExcelDorado("./export/storage-excel", "库存数据", param);</ClientEvent> |
| | | <Property name="caption">导出EXCEL</Property> |
| | |
| | | package com.fzzy.common; |
| | | |
| | | import com.fzzy.common.manager.ExportManager; |
| | | import com.fzzy.igds.*; |
| | | import com.fzzy.igds.CompanyPR; |
| | | import com.fzzy.igds.DepotPR; |
| | | import com.fzzy.igds.DeptPR; |
| | | import com.fzzy.igds.ReportInoutPR; |
| | | import com.fzzy.igds.constant.FoodVariety; |
| | | import com.fzzy.igds.data.*; |
| | | import com.fzzy.igds.domain.Company; |
| | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.text.DecimalFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | /** |
| | | * 出入库报表导出 |
| | | * |
| | | * @return |
| | | */ |
| | | @RequestMapping("/inout-excel") |
| | |
| | | if (null != subDept) { |
| | | deptName = subDept.getDeptName(); |
| | | } |
| | | String exportTimeDesc = ""; |
| | | String exportCreateUser = ""; |
| | | Date exportCreateTime = new Date(); |
| | | if (StringUtils.isNotEmpty(param.getTimeDesc())) { |
| | | exportTimeDesc = param.getTimeDesc(); |
| | | } |
| | | if (StringUtils.isNotEmpty(param.getCreateUser())) { |
| | | exportCreateUser = param.getCreateUser(); |
| | | } |
| | | if (param.getCreateTime() != null) { |
| | | exportCreateTime = param.getCreateTime(); |
| | | } |
| | | |
| | | //创建收储公司ID到名称的映射 |
| | | Map<String, String> companyMap = Optional.ofNullable(companyPR.getData()) |
| | | .orElse(new ArrayList<>()) |
| | |
| | | exportList.add(export); |
| | | } |
| | | ExcelUtil<InoutRecordInExport> util = new ExcelUtil<InoutRecordInExport>(InoutRecordInExport.class); |
| | | return util.exportExcel(exportList, sheetName, deptName); |
| | | return util.exportExcel(exportList, sheetName, deptName, exportTimeDesc, exportCreateUser, exportCreateTime); |
| | | } |
| | | |
| | | if (StringUtils.isNotEmpty(param.getType()) && "OUT".equals(param.getType())) { |
| | |
| | | exportList.add(export); |
| | | } |
| | | ExcelUtil<InoutRecordOutExport> util = new ExcelUtil<InoutRecordOutExport>(InoutRecordOutExport.class); |
| | | return util.exportExcel(exportList, sheetName, deptName); |
| | | return util.exportExcel(exportList, sheetName, deptName, exportTimeDesc, exportCreateUser, exportCreateTime); |
| | | } |
| | | |
| | | if (StringUtils.isNotEmpty(param.getType()) && "IN_DETAIL".equals(param.getType())) { |
| | |
| | | exportList.add(export); |
| | | } |
| | | ExcelUtil<InoutRecordDetailInExport> util = new ExcelUtil<InoutRecordDetailInExport>(InoutRecordDetailInExport.class); |
| | | return util.exportExcel(exportList, sheetName, deptName); |
| | | return util.exportExcel(exportList, sheetName, deptName, exportTimeDesc, exportCreateUser, exportCreateTime); |
| | | } |
| | | |
| | | if (StringUtils.isNotEmpty(param.getType()) && "OUT_DETAIL".equals(param.getType())) { |
| | |
| | | exportList.add(export); |
| | | } |
| | | ExcelUtil<InoutRecordDetailOutExport> util = new ExcelUtil<InoutRecordDetailOutExport>(InoutRecordDetailOutExport.class); |
| | | return util.exportExcel(exportList, sheetName, deptName); |
| | | return util.exportExcel(exportList, sheetName, deptName, exportTimeDesc, exportCreateUser, exportCreateTime); |
| | | } |
| | | return AjaxResult.error("参数错误"); |
| | | } |
| | | |
| | | /** |
| | | * 库存报表导出 |
| | | * |
| | | * @return |
| | | */ |
| | | @RequestMapping("/storage-excel") |
| | |
| | | SysDept subDept = sysDeptService.getCacheDept(null, ContextUtil.subDeptId(null)); |
| | | if (null != subDept) { |
| | | deptName = subDept.getDeptName(); |
| | | } |
| | | String exportTimeDesc = ""; |
| | | String exportCreateUser = ""; |
| | | Date exportCreateTime = new Date(); |
| | | if (StringUtils.isNotEmpty(param.getTimeDesc())) { |
| | | exportTimeDesc = param.getTimeDesc(); |
| | | } |
| | | if (StringUtils.isNotEmpty(param.getCreateUser())) { |
| | | exportCreateUser = param.getCreateUser(); |
| | | } |
| | | if (param.getCreateTime() != null) { |
| | | exportCreateTime = param.getCreateTime(); |
| | | } |
| | | List<SuperInventoryReportExport> exportList = new ArrayList<>(); |
| | | DecimalFormat df = new DecimalFormat("0.00"); |
| | |
| | | |
| | | //导出 |
| | | ExcelUtil<SuperInventoryReportExport> util = new ExcelUtil<SuperInventoryReportExport>(SuperInventoryReportExport.class); |
| | | return util.exportExcel(exportList, sheetName, deptName); |
| | | return util.exportExcel(exportList, sheetName, deptName, exportTimeDesc, exportCreateUser, exportCreateTime); |
| | | } |
| | | |
| | | } |