统计数据导出

This commit is contained in:
gong
2026-01-31 14:06:23 +08:00
parent f92a593ff8
commit 0d4b1ace60
19 changed files with 244 additions and 313 deletions

View File

@@ -8,10 +8,11 @@ import com.czg.account.vo.HandoverProductListVo;
import com.czg.account.vo.HandoverTotalVo;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.constants.SystemConstants;
import com.czg.excel.ExcelExportUtil;
import com.czg.log.annotation.OperationLog;
import com.czg.resp.CzgResult;
import com.mybatisflex.core.paginate.Page;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
@@ -62,12 +63,12 @@ public class HandoverRecordController {
*
* @param id 交班记录ID
*/
@ResponseExcel(name = "交班售出商品明细")
@GetMapping("/export/{id}")
@OperationLog("交班记录-导出")
@SaAdminCheckPermission(parentName = "交班记录", value = "handoverRecord:export", name = "交班记录-导出")
public List<HandoverProductListVo> export(@PathVariable Long id) {
return handoverRecordService.getHandoverProductListById(id);
public void export(@PathVariable Long id, HttpServletResponse response) {
List<HandoverProductListVo> list = handoverRecordService.getHandoverProductListById(id);
ExcelExportUtil.exportToResponse(list, HandoverProductListVo.class, "交班售出商品明细", response);
}
/**

View File

@@ -1,5 +1,6 @@
package com.czg.controller.admin;
import com.czg.excel.ExcelExportUtil;
import com.czg.log.annotation.OperationLog;
import com.czg.order.entity.ShopProdStatistic;
import com.czg.order.param.SaleSummaryCountParam;
@@ -7,8 +8,8 @@ import com.czg.order.service.ShopProdStatisticService;
import com.czg.order.vo.SaleSummaryCountVo;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
@@ -59,13 +60,12 @@ public class SaleSummaryController {
return CzgResult.success(list);
}
@ResponseExcel(name = "销售统计明细")
@GetMapping("/export")
public List<ShopProdStatistic> summaryExport(SaleSummaryCountParam param) {
public void summaryExport(SaleSummaryCountParam param, HttpServletResponse response) {
if (param.getShopId() == null) {
param.setShopId(StpKit.USER.getShopId());
}
return prodStatisticService.getArchiveTradeData(param);
ExcelExportUtil.exportToResponse(prodStatisticService.getArchiveTradeData(param), ShopProdStatistic.class, "销售统计明细", response);
}
}

View File

@@ -1,7 +1,6 @@
package com.czg.controller.admin;
import com.czg.handel.ExcelMergeHandler;
import com.czg.handel.TableRefundCellHandel;
import com.czg.excel.ExcelExportUtil;
import com.czg.log.annotation.OperationLog;
import com.czg.order.entity.ShopTableOrderStatistic;
import com.czg.order.param.DataSummaryTradeParam;
@@ -11,8 +10,8 @@ import com.czg.order.service.TableSummaryService;
import com.czg.order.vo.TableSummaryExportVo;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
@@ -54,15 +53,14 @@ public class TableSummaryController {
/**
* 导出
*/
@ResponseExcel(name = "台桌统计", writeHandler = {ExcelMergeHandler.class, TableRefundCellHandel.class})
@GetMapping("export")
@OperationLog("导出")
//@SaAdminCheckPermission("tableSummary:export")
public List<TableSummaryExportVo> summaryExport(TableSummaryParam param) {
public void summaryExport(TableSummaryParam param, HttpServletResponse response) {
if (param.getShopId() == null) {
param.setShopId(StpKit.USER.getShopId());
}
return tableSummaryService.summaryExportList(param);
tableSummaryService.summaryExportList(param, response);
}
}

View File

@@ -1,151 +0,0 @@
package com.czg.handel;
import cn.idev.excel.metadata.Head;
import cn.idev.excel.metadata.data.WriteCellData;
import cn.idev.excel.write.handler.CellWriteHandler;
import cn.idev.excel.write.metadata.holder.WriteSheetHolder;
import cn.idev.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import java.util.List;
/**
* @author tankaikai
* @since 2025-04-01 18:41
*/
public class ExcelMergeHandler implements CellWriteHandler {
// 要合并的列索引数组
private int[] mergeColumnIndex = {0, 1, 2, 3, 8, 9};
// 合并开始的行索引
private int mergeRowIndex = 1;
public ExcelMergeHandler() {
}
/**
* 构造函数
*
* @param mergeRowIndex 合并开始的行索引
* @param mergeColumnIndex 要合并的列索引数组
*/
public ExcelMergeHandler(int mergeRowIndex, int[] mergeColumnIndex) {
this.mergeRowIndex = mergeRowIndex;
this.mergeColumnIndex = mergeColumnIndex;
}
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
// 当前行索引
int curRowIndex = cell.getRowIndex();
// 当前列索引
int curColIndex = cell.getColumnIndex();
// 如果当前行大于合并开始行且当前列在需要合并的列中
if (curRowIndex > mergeRowIndex && isMergeColumn(curColIndex)) {
// 进行合并操作
mergeWithPrevRow(writeSheetHolder, cell, curRowIndex, curColIndex);
}
}
/**
* 检查当前列是否在需要合并的列中
*
* @param curColIndex 当前列索引
* @return 如果是需要合并的列返回true否则返回false
*/
private boolean isMergeColumn(int curColIndex) {
for (int columnIndex : mergeColumnIndex) {
if (curColIndex == columnIndex) {
return true;
}
}
return false;
}
/**
* 当前单元格向上合并
*
* @param writeSheetHolder 当前工作表持有者
* @param cell 当前单元格
* @param curRowIndex 当前行索引
* @param curColIndex 当前列索引
*/
private void mergeWithPrevRow(WriteSheetHolder writeSheetHolder, Cell cell, int curRowIndex, int curColIndex) {
// 获取当前单元格的数据
Object curData = getCellData(cell);
// 获取前一个单元格的数据
Cell preCell = cell.getSheet().getRow(curRowIndex - 1).getCell(curColIndex);
Object preData = getCellData(preCell);
// 判断当前单元格和前一个单元格的数据以及主键是否相同
if (curData.equals(preData) && isSamePrimaryKey(cell, curRowIndex)) {
// 获取工作表
Sheet sheet = writeSheetHolder.getSheet();
// 合并单元格
mergeCells(sheet, curRowIndex, curColIndex);
CellStyle style = preCell.getCellStyle();
// 设置水平居中
style.setAlignment(HorizontalAlignment.CENTER);
// 设置垂直居中
style.setVerticalAlignment(VerticalAlignment.CENTER);
preCell.setCellStyle(style);
}
}
/**
* 获取单元格的数据
*
* @param cell 单元格
* @return 单元格数据
*/
private Object getCellData(Cell cell) {
return cell.getCellType() == CellType.STRING ? cell.getStringCellValue() : cell.getNumericCellValue();
}
/**
* 判断当前单元格和前一个单元格的主键是否相同
*
* @param cell 当前单元格
* @param curRowIndex 当前行索引
* @return 如果主键相同返回true否则返回false
*/
private boolean isSamePrimaryKey(Cell cell, int curRowIndex) {
String currentPrimaryKey = cell.getRow().getCell(0).getStringCellValue();
String previousPrimaryKey = cell.getSheet().getRow(curRowIndex - 1).getCell(0).getStringCellValue();
return currentPrimaryKey.equals(previousPrimaryKey);
}
/**
* 合并单元格
*
* @param sheet 工作表
* @param curRowIndex 当前行索引
* @param curColIndex 当前列索引
*/
private void mergeCells(Sheet sheet, int curRowIndex, int curColIndex) {
// 获取已合并的区域
List<CellRangeAddress> mergeRegions = sheet.getMergedRegions();
boolean isMerged = false;
// 检查前一个单元格是否已经被合并
for (int i = 0; i < mergeRegions.size() && !isMerged; i++) {
CellRangeAddress cellRangeAddr = mergeRegions.get(i);
if (cellRangeAddr.isInRange(curRowIndex - 1, curColIndex)) {
sheet.removeMergedRegion(i);
cellRangeAddr.setLastRow(curRowIndex);
sheet.addMergedRegion(cellRangeAddr);
isMerged = true;
}
}
// 如果前一个单元格未被合并,则新增合并区域
if (!isMerged) {
CellRangeAddress cellRangeAddress = new CellRangeAddress(curRowIndex - 1, curRowIndex, curColIndex, curColIndex);
sheet.addMergedRegion(cellRangeAddress);
}
}
}

View File

@@ -1,55 +0,0 @@
package com.czg.handel;
import cn.hutool.core.util.ArrayUtil;
import cn.idev.excel.metadata.Head;
import cn.idev.excel.metadata.data.WriteCellData;
import cn.idev.excel.write.handler.CellWriteHandler;
import cn.idev.excel.write.metadata.holder.WriteSheetHolder;
import cn.idev.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.*;
import java.util.List;
/**
* 台桌统计退单单元格处理器
*
* @author tankaikai
* @since 2025-04-02 09:50
*/
public class TableRefundCellHandel implements CellWriteHandler {
// 要处理的列索引数组
private int[] yellowColumnIndex = {10, 11};
public TableRefundCellHandel() {
}
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
// 当前行索引
int curRowIndex = cell.getRowIndex();
// 当前列索引
int curColIndex = cell.getColumnIndex();
if (curRowIndex == 0) {
return;
}
// 如果是指定要处理的列,则要进行加黄操作
if (ArrayUtil.contains(yellowColumnIndex, curColIndex)) {
Cell preCell = cell.getSheet().getRow(curRowIndex - 1).getCell(curColIndex);
if (preCell.getCellType() == CellType.NUMERIC) {
if (preCell.getNumericCellValue() < 0) {
//System.out.println("设置黄色背景:" + curRowIndex + "行," + curColIndex + "列" + preCell.getNumericCellValue());
CellStyle style = preCell.getSheet().getWorkbook().createCellStyle();
style.cloneStyleFrom(preCell.getCellStyle());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
// 设置水平居中
style.setAlignment(HorizontalAlignment.CENTER);
// 设置垂直居中
style.setVerticalAlignment(VerticalAlignment.CENTER);
preCell.setCellStyle(style);
}
}
}
}
}

View File

@@ -52,10 +52,6 @@
<artifactId>cash-common-service</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.pig4cloud.excel</groupId>
<artifactId>excel-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<build>

View File

@@ -37,14 +37,19 @@ public class ShopProdCategoryController {
@Resource
private ShopSyncService shopSyncService;
/**
* 分页
*/
@GetMapping("page")
@OperationLog("商品分类-分页")
//@SaAdminCheckPermission("shopProdCategory:page")
public CzgResult<Page<ShopProdCategoryDTO>> getShopProdCategoryPage(ShopProdCategoryDTO param) {
Page<ShopProdCategoryDTO> data = shopProdCategoryService.getShopProdCategoryPage(param);
return CzgResult.success(data);
}
/**
* 列表
*/
@GetMapping("list")
@OperationLog("商品分类-列表")
//@SaAdminCheckPermission("shopProdCategory:list")
@@ -53,12 +58,18 @@ public class ShopProdCategoryController {
return CzgResult.success(data);
}
/**
* 导出
*/
@GetMapping("/export")
@OperationLog("商品分类-导出")
public void exportShopProdCategory(ShopProdCategoryDTO param, HttpServletResponse response) {
shopProdCategoryService.exportShopProdCategory(param, response);
}
/**
* 详情
*/
@GetMapping("{id}")
@OperationLog("商品分类-详情")
//@SaAdminCheckPermission("shopProdCategory:info")
@@ -68,6 +79,9 @@ public class ShopProdCategoryController {
return CzgResult.success(data);
}
/**
* 新增
*/
@PostMapping
@OperationLog("商品分类-新增")
//@SaAdminCheckPermission("shopProdCategory:add")
@@ -77,6 +91,9 @@ public class ShopProdCategoryController {
return CzgResult.success();
}
/**
* 修改
*/
@PutMapping
@OperationLog("商品分类-修改")
//@SaAdminCheckPermission("shopProdCategory:update")
@@ -86,6 +103,9 @@ public class ShopProdCategoryController {
return CzgResult.success();
}
/**
* 删除
*/
@DeleteMapping("{id}")
@OperationLog("商品分类-删除")
//@SaAdminCheckPermission("shopProdCategory:delete")
@@ -96,6 +116,9 @@ public class ShopProdCategoryController {
return CzgResult.success();
}
/**
* 禁用
*/
@PostMapping("disable/{id}")
@OperationLog("商品分类-禁用")
//@SaAdminCheckPermission("shopProdCategory:able")
@@ -107,6 +130,9 @@ public class ShopProdCategoryController {
return CzgResult.success();
}
/**
* 启用
*/
@PostMapping("enable/{id}")
@OperationLog("商品分类-启用")
//@SaAdminCheckPermission("shopProdCategory:able")

View File

@@ -22,7 +22,7 @@ import java.util.List;
/**
* 商品单位
* 管理端/商品单位
*
* @author Tankaikai tankaikai@aliyun.com
* @since 1.0 2025-02-10
@@ -37,7 +37,9 @@ public class ShopProdUnitController {
@Resource
private ShopSyncService shopSyncService;
/**
* 分页
*/
@GetMapping("page")
@OperationLog("商品单位-分页")
//@SaAdminCheckPermission("shopProdUnit:page")
@@ -46,6 +48,9 @@ public class ShopProdUnitController {
return CzgResult.success(data);
}
/**
* 列表
*/
@GetMapping("list")
@OperationLog("商品单位-列表")
//@SaAdminCheckPermission("shopProdUnit:list")
@@ -54,12 +59,18 @@ public class ShopProdUnitController {
return CzgResult.success(data);
}
/**
* 导出
*/
@GetMapping("/export")
@OperationLog("商品单位-导出")
public void exportProduct(ShopProdUnitDTO param, HttpServletResponse response) {
shopProdUnitService.exportShopProdUnit(param, response);
}
/**
* 详情
*/
@GetMapping("{id}")
@OperationLog("商品单位-详情")
//@SaAdminCheckPermission("shopProdUnit:info")
@@ -69,6 +80,9 @@ public class ShopProdUnitController {
return CzgResult.success(data);
}
/**
* 新增
*/
@PostMapping
@OperationLog("商品单位-新增")
//@SaAdminCheckPermission("shopProdUnit:add")
@@ -78,6 +92,9 @@ public class ShopProdUnitController {
return CzgResult.success();
}
/**
* 修改
*/
@PutMapping
@OperationLog("商品单位-修改")
//@SaAdminCheckPermission("shopProdUnit:update")
@@ -87,6 +104,9 @@ public class ShopProdUnitController {
return CzgResult.success();
}
/**
* 删除
*/
@DeleteMapping("{id}")
@OperationLog("商品单位-删除")
//@SaAdminCheckPermission("shopProdUnit:delete")
@@ -97,6 +117,9 @@ public class ShopProdUnitController {
return CzgResult.success();
}
/**
* 禁用
*/
@PostMapping("disable/{id}")
@OperationLog("商品单位-禁用")
//@SaAdminCheckPermission("shopProdUnit:able")
@@ -108,6 +131,9 @@ public class ShopProdUnitController {
return CzgResult.success();
}
/**
* 启用
*/
@PostMapping("enable/{id}")
@OperationLog("商品单位-启用")
//@SaAdminCheckPermission("shopProdUnit:able")