金额填充
This commit is contained in:
@@ -11,7 +11,6 @@ import org.springframework.stereotype.Service;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -51,7 +50,41 @@ public class TableSummaryServiceImpl implements TableSummaryService {
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
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();
|
||||
list.add(nullVo);
|
||||
|
||||
@@ -6,17 +6,19 @@
|
||||
|
||||
<select id="findSummaryExportList" resultType="com.czg.order.vo.TableSummaryExportVo">
|
||||
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, '吧台',
|
||||
`table`.NAME) AS table_name,
|
||||
category.`name` AS category_name,
|
||||
product.`name` AS product_name,
|
||||
unit.`name` AS unit_name,
|
||||
`table`.NAME) AS table_name,
|
||||
category.`name` AS category_name,
|
||||
product.`name` AS product_name,
|
||||
product.`id` AS product_id,
|
||||
unit.`name` AS unit_name,
|
||||
detail.sku_name,
|
||||
sum(detail.num - detail.return_num) AS num,
|
||||
sum(detail.pay_amount) AS salesAmount,
|
||||
sum(detail.refund_num) AS refund_num,
|
||||
sum(detail.return_amount) AS refund_amount
|
||||
sum(detail.num - detail.return_num) AS num,
|
||||
sum(detail.pay_amount) AS amount,
|
||||
sum(detail.refund_num) AS refund_num,
|
||||
sum(detail.return_amount) AS refund_amount
|
||||
FROM tb_order_info `order`
|
||||
INNER JOIN tb_order_detail detail ON detail.order_id = `order`.id
|
||||
AND detail.is_temporary = 0
|
||||
@@ -31,6 +33,6 @@
|
||||
AND `order`.pay_mode != 'no-table'
|
||||
AND `order`.trade_day >= #{beginDate}
|
||||
AND `order`.trade_day <= #{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>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user