金额填充

This commit is contained in:
2025-11-26 10:44:21 +08:00
parent 8b7d6b9f98
commit 16237210df
5 changed files with 62 additions and 24 deletions

View File

@@ -17,7 +17,7 @@ import java.util.List;
*/ */
public class ExcelMergeHandler implements CellWriteHandler { public class ExcelMergeHandler implements CellWriteHandler {
// 要合并的列索引数组 // 要合并的列索引数组
private int[] mergeColumnIndex = {0, 1, 2, 9, 10}; private int[] mergeColumnIndex = {0, 1, 2, 8, 9};
// 合并开始的行索引 // 合并开始的行索引
private int mergeRowIndex = 1; private int mergeRowIndex = 1;

View File

@@ -18,7 +18,7 @@ import java.util.List;
*/ */
public class TableRefundCellHandel implements CellWriteHandler { public class TableRefundCellHandel implements CellWriteHandler {
// 要处理的列索引数组 // 要处理的列索引数组
private int[] yellowColumnIndex = {11, 12}; private int[] yellowColumnIndex = {10, 11};
public TableRefundCellHandel() { public TableRefundCellHandel() {

View File

@@ -12,8 +12,7 @@ import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
* 台桌统计明细 * 台桌统计明细 *
*
* @author tankaikai * @author tankaikai
* @since 2025-03-07 16:22 * @since 2025-03-07 16:22
*/ */
@@ -31,10 +30,12 @@ public class TableSummaryExportVo implements Serializable {
@JSONField(serialize = false) @JSONField(serialize = false)
private Long lineNum; private Long lineNum;
/** /**
* 台桌+日期 * 台桌Code_日期
*/ */
@ExcelIgnore @ExcelIgnore
private String tableConcatDate; private String tableConcatDate;
@ExcelIgnore
private String tableCode;
/** /**
* 台桌 * 台桌
*/ */
@@ -53,6 +54,8 @@ public class TableSummaryExportVo implements Serializable {
@ExcelProperty("商品分类") @ExcelProperty("商品分类")
@ColumnWidth(15) @ColumnWidth(15)
private String categoryName; private String categoryName;
@ExcelIgnore
private Long productId;
/** /**
* 商品名称 * 商品名称
*/ */
@@ -80,26 +83,26 @@ public class TableSummaryExportVo implements Serializable {
/** /**
* 单价 * 单价
*/ */
@ExcelProperty("单价") // @ExcelProperty("单价")
@ColumnWidth(10) // @ColumnWidth(10)
private BigDecimal unitPrice; // private BigDecimal unitPrice;
/** /**
* 金额 * 金额
*/ */
@ExcelProperty("") @ExcelProperty("销售")
@ColumnWidth(10) @ColumnWidth(10)
private BigDecimal amount; private BigDecimal amount;
/** /**
* 销售额 * 销售额
*/ */
@ExcelProperty("销售额") @ExcelProperty("销售额")
@ColumnWidth(10) @ColumnWidth(12)
private BigDecimal salesAmount; private BigDecimal salesAmount;
/** /**
* 总销售额 * 总销售额
*/ */
@ExcelProperty("总销售额") @ExcelProperty("当日总销售额")
@ColumnWidth(15) @ColumnWidth(16)
private BigDecimal totalSalesAmount; private BigDecimal totalSalesAmount;
/** /**
* 退单量 * 退单量

View File

@@ -11,7 +11,6 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -51,7 +50,41 @@ public class TableSummaryServiceImpl implements TableSummaryService {
if (CollUtil.isEmpty(list)) { if (CollUtil.isEmpty(list)) {
return List.of(); return List.of();
} }
record TableSummary(String tableKey, BigDecimal totalSales, Map<Long, BigDecimal> productSales) {}
Map<String, TableSummary> summaryMap = list.stream()
.collect(Collectors.groupingBy(
vo -> vo.getTableCode() + "_" + vo.getCreateDate(),
Collectors.collectingAndThen(
Collectors.toList(),
vos -> {
String tableKey = vos.getFirst().getTableCode() + "_" + vos.getFirst().getCreateDate();
BigDecimal totalSales = vos.stream()
.map(TableSummaryExportVo::getAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add);
Map<Long, BigDecimal> productSales = vos.stream()
.collect(Collectors.groupingBy(
TableSummaryExportVo::getProductId,
Collectors.reducing(
BigDecimal.ZERO,
TableSummaryExportVo::getAmount,
BigDecimal::add
)
));
return new TableSummary(tableKey, totalSales, productSales);
}
)
));
list.forEach(vo -> {
TableSummary summary = summaryMap.get(vo.getTableConcatDate());
if (summary != null) {
vo.setTotalSalesAmount(summary.totalSales());
vo.setSalesAmount(summary.productSales().getOrDefault(vo.getProductId(), BigDecimal.ZERO));
}
});
// 追加个空行用于处理表格样式 // 追加个空行用于处理表格样式
TableSummaryExportVo nullVo = new TableSummaryExportVo(); TableSummaryExportVo nullVo = new TableSummaryExportVo();
list.add(nullVo); list.add(nullVo);

View File

@@ -6,17 +6,19 @@
<select id="findSummaryExportList" resultType="com.czg.order.vo.TableSummaryExportVo"> <select id="findSummaryExportList" resultType="com.czg.order.vo.TableSummaryExportVo">
SELECT `order`.table_code, SELECT `order`.table_code,
`order`.trade_day as create_date, `order`.trade_day as create_date,
concat(`order`.table_code, '_', `order`.trade_day) as tableConcatDate,
IF(`order`.table_code IS NULL OR `order`.table_code = '' OR `table`.NAME IS NULL, '吧台', IF(`order`.table_code IS NULL OR `order`.table_code = '' OR `table`.NAME IS NULL, '吧台',
`table`.NAME) AS table_name, `table`.NAME) AS table_name,
category.`name` AS category_name, category.`name` AS category_name,
product.`name` AS product_name, product.`name` AS product_name,
unit.`name` AS unit_name, product.`id` AS product_id,
unit.`name` AS unit_name,
detail.sku_name, detail.sku_name,
sum(detail.num - detail.return_num) AS num, sum(detail.num - detail.return_num) AS num,
sum(detail.pay_amount) AS salesAmount, sum(detail.pay_amount) AS amount,
sum(detail.refund_num) AS refund_num, sum(detail.refund_num) AS refund_num,
sum(detail.return_amount) AS refund_amount sum(detail.return_amount) AS refund_amount
FROM tb_order_info `order` FROM tb_order_info `order`
INNER JOIN tb_order_detail detail ON detail.order_id = `order`.id INNER JOIN tb_order_detail detail ON detail.order_id = `order`.id
AND detail.is_temporary = 0 AND detail.is_temporary = 0
@@ -31,6 +33,6 @@
AND `order`.pay_mode != 'no-table' AND `order`.pay_mode != 'no-table'
AND `order`.trade_day >= #{beginDate} AND `order`.trade_day >= #{beginDate}
AND `order`.trade_day &lt;= #{endDate} AND `order`.trade_day &lt;= #{endDate}
group by `order`.trade_day, `order`.table_code, detail.product_id group by `order`.trade_day, `order`.table_code, detail.product_id, detail.sku_id
</select> </select>
</mapper> </mapper>