台桌统计

This commit is contained in:
2025-11-25 18:24:51 +08:00
parent c366862327
commit 881f33ff2b
3 changed files with 45 additions and 79 deletions

View File

@@ -33,8 +33,8 @@ public class TableSummaryExportVo implements Serializable {
/** /**
* 台桌+日期 * 台桌+日期
*/ */
@ExcelIgnore // @ExcelIgnore
private String tableConcatDate; // private String tableConcatDate;
/** /**
* 台桌 * 台桌
*/ */
@@ -80,27 +80,27 @@ 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(10)
private BigDecimal salesAmount; private BigDecimal salesAmount;
/** // /**
* 总销售额 // * 总销售额
*/ // */
@ExcelProperty("总销售额") // @ExcelProperty("总销售额")
@ColumnWidth(15) // @ColumnWidth(15)
private BigDecimal totalSalesAmount; // private BigDecimal totalSalesAmount;
/** /**
* 退单量 * 退单量
*/ */

View File

@@ -11,6 +11,7 @@ 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,24 +52,6 @@ public class TableSummaryServiceImpl implements TableSummaryService {
if (CollUtil.isEmpty(list)) { if (CollUtil.isEmpty(list)) {
return List.of(); return List.of();
} }
Map<String, BigDecimal> totalSalesAmountMap = list.stream().collect(
Collectors.groupingBy(
TableSummaryExportVo::getTableName, Collectors.reducing(BigDecimal.ZERO,
TableSummaryExportVo::getAmount,
BigDecimal::add)
)
);
Map<String, BigDecimal> salesAmountMap = list.stream().collect(
Collectors.groupingBy(
TableSummaryExportVo::getTableConcatDate, Collectors.reducing(BigDecimal.ZERO,
TableSummaryExportVo::getAmount,
BigDecimal::add)
)
);
list.parallelStream().forEach(data -> {
data.setSalesAmount(salesAmountMap.get(data.getTableConcatDate()));
data.setTotalSalesAmount(totalSalesAmountMap.get(data.getTableName()));
});
// 追加个空行用于处理表格样式 // 追加个空行用于处理表格样式
TableSummaryExportVo nullVo = new TableSummaryExportVo(); TableSummaryExportVo nullVo = new TableSummaryExportVo();
list.add(nullVo); list.add(nullVo);

View File

@@ -5,49 +5,32 @@
<mapper namespace="com.czg.service.order.mapper.ShopTableOrderStatisticMapper"> <mapper namespace="com.czg.service.order.mapper.ShopTableOrderStatisticMapper">
<select id="findSummaryExportList" resultType="com.czg.order.vo.TableSummaryExportVo"> <select id="findSummaryExportList" resultType="com.czg.order.vo.TableSummaryExportVo">
SELECT SELECT `order`.table_code,
t.product_name, `order`.trade_day as create_date,
date_format(t.create_time, '%Y-%m-%d') as create_date, IF(`order`.table_code IS NULL OR `order`.table_code = '' OR `table`.NAME IS NULL, '吧台',
if(t.table_name = 'NONE','银收客',t.table_name) as table_name, `table`.NAME) AS table_name,
concat(if(t.table_name = 'NONE','银收客',t.table_name),'-',date_format(t.create_time, '%Y-%m-%d')) as tableConcatDate, category.`name` AS category_name,
t.category_name, product.`name` AS product_name,
t.unit_name, unit.`name` AS unit_name,
group_concat(distinct t.sku_name SEPARATOR ';') as sku_name, detail.sku_name,
sum(t.num) as num, sum(detail.num - detail.return_num) AS num,
avg(t.unit_price) as unit_price, sum(detail.pay_amount) AS salesAmount,
sum(t.num*t.unit_price) as amount, sum(detail.refund_num) AS refund_num,
sum(-t.refund_num) as refund_num, sum(detail.return_amount) AS refund_amount
sum(-t.refund_num*t.unit_price) as refund_amount FROM tb_order_info `order`
FROM INNER JOIN tb_order_detail detail ON detail.order_id = `order`.id
( AND detail.is_temporary = 0
SELECT LEFT JOIN tb_product product ON detail.product_id = product.id
t1.product_id, LEFT JOIN tb_shop_prod_category category ON product.category_id = category.id
t2.table_code, LEFT JOIN tb_shop_prod_unit unit ON product.unit_id = unit.id
IF(t2.table_code is null or t2.table_code = '' or t6.NAME is null, 'NONE', t6.NAME) AS table_name, LEFT JOIN tb_shop_table `table`
t1.create_time, ON `order`.table_code = `table`.table_code AND `order`.shop_id = `table`.shop_id
t4.NAME AS category_name, AND `table`.table_code != '' AND `table`.table_code IS NOT NULL
t3.name as product_name, WHERE `order`.shop_id = #{shopId}
t5.NAME AS unit_name, AND `order`.paid_time IS NOT NULL
t1.sku_name, AND `order`.pay_mode != 'no-table'
t1.num, AND `order`.trade_day >= #{beginDate}
t1.unit_price, AND `order`.trade_day &lt;= #{endDate}
t1.refund_num as refund_num group by `order`.trade_day, `order`.table_code, detail.product_id
FROM
tb_order_detail t1
LEFT JOIN tb_order_info t2 ON t1.order_id = t2.id
LEFT JOIN tb_product t3 ON t1.product_id = t3.id
LEFT JOIN tb_shop_prod_category t4 ON t3.category_id = t4.id
LEFT JOIN tb_shop_prod_unit t5 ON t3.unit_id = t5.id
LEFT JOIN tb_shop_table t6 ON t2.table_code = t6.table_code AND t1.shop_id = t6.shop_id and t6.table_code != '' and t6.table_code is not null
WHERE t1.shop_id = #{shopId}
<if test="beginDate != null and beginDate != ''">
AND t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
</if>
<if test="endDate != null and endDate != ''">
and t1.create_time &lt;= str_to_date(#{endDate}, '%Y-%m-%d %H:%i:%s')
</if>
) t
group by t.product_id,date_format(t.create_time, '%Y-%m-%d'),t.table_name
order by t.table_name,t.table_code,date_format(t.create_time, '%Y-%m-%d'),t.category_name,t.product_id
</select> </select>
</mapper> </mapper>