台桌统计报表
This commit is contained in:
parent
6df79916bd
commit
d748680ee3
|
|
@ -1,8 +1,11 @@
|
|||
package com.czg.controller.admin;
|
||||
|
||||
import com.czg.handel.ExcelMergeHandler;
|
||||
import com.czg.handel.TableRefundCellHandel;
|
||||
import com.czg.log.annotation.OperationLog;
|
||||
import com.czg.order.param.TableSummaryParam;
|
||||
import com.czg.order.service.TableSummaryService;
|
||||
import com.czg.order.vo.TableSummaryExportVo;
|
||||
import com.czg.order.vo.TableSummaryInfoVo;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
|
|
@ -42,14 +45,14 @@ public class TableSummaryController {
|
|||
/**
|
||||
* 导出
|
||||
*/
|
||||
@ResponseExcel(name = "台桌统计")
|
||||
@ResponseExcel(name = "台桌统计", writeHandler = {ExcelMergeHandler.class, TableRefundCellHandel.class})
|
||||
@GetMapping("export")
|
||||
@OperationLog("导出")
|
||||
//@SaAdminCheckPermission("tableSummary:export")
|
||||
public List<TableSummaryInfoVo> summaryExport(TableSummaryParam param) {
|
||||
public List<TableSummaryExportVo> summaryExport(TableSummaryParam param) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
param.setShopId(shopId);
|
||||
return tableSummaryService.summaryList(param);
|
||||
return tableSummaryService.summaryExportList(param);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.czg.order.service;
|
||||
|
||||
import com.czg.order.param.TableSummaryParam;
|
||||
import com.czg.order.vo.TableSummaryExportVo;
|
||||
import com.czg.order.vo.TableSummaryInfoVo;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -15,5 +16,7 @@ public interface TableSummaryService {
|
|||
|
||||
List<TableSummaryInfoVo> summaryList(TableSummaryParam param);
|
||||
|
||||
List<TableSummaryExportVo> summaryExportList(TableSummaryParam param);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import java.math.BigDecimal;
|
|||
* @since 2025-03-07 16:22
|
||||
*/
|
||||
@Data
|
||||
@ColumnWidth(30)
|
||||
public class TableSummaryExportVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
|
|
@ -31,70 +30,88 @@ public class TableSummaryExportVo implements Serializable {
|
|||
@ExcelIgnore
|
||||
@JSONField(serialize = false)
|
||||
private Long lineNum;
|
||||
/**
|
||||
* 台桌+日期
|
||||
*/
|
||||
@ExcelIgnore
|
||||
private String tableConcatDate;
|
||||
/**
|
||||
* 台桌
|
||||
*/
|
||||
@ExcelProperty("台桌")
|
||||
@ColumnWidth(10)
|
||||
private String tableName;
|
||||
/**
|
||||
* 日期
|
||||
*/
|
||||
@ExcelProperty("日期")
|
||||
private String date;
|
||||
@ColumnWidth(10)
|
||||
private String createDate;
|
||||
/**
|
||||
* 商品分类
|
||||
*/
|
||||
@ExcelProperty("商品分类")
|
||||
@ColumnWidth(15)
|
||||
private String categoryName;
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
@ExcelProperty("商品名称")
|
||||
@ColumnWidth(30)
|
||||
private String productName;
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
@ExcelProperty("单位")
|
||||
@ColumnWidth(8)
|
||||
private String unitName;
|
||||
/**
|
||||
* 商品规格
|
||||
*/
|
||||
@ExcelProperty("商品规格")
|
||||
private String specName;
|
||||
@ColumnWidth(20)
|
||||
private String skuName;
|
||||
/**
|
||||
* 销量
|
||||
*/
|
||||
@ExcelProperty("销量")
|
||||
private BigDecimal salesNum;
|
||||
@ColumnWidth(10)
|
||||
private BigDecimal num;
|
||||
/**
|
||||
* 单价
|
||||
*/
|
||||
@ExcelProperty("单价")
|
||||
private BigDecimal price;
|
||||
@ColumnWidth(10)
|
||||
private BigDecimal unitPrice;
|
||||
/**
|
||||
* 金额
|
||||
*/
|
||||
@ExcelProperty("金额")
|
||||
@ColumnWidth(10)
|
||||
private BigDecimal amount;
|
||||
/**
|
||||
* 销售额
|
||||
*/
|
||||
@ExcelProperty("销售额")
|
||||
@ColumnWidth(10)
|
||||
private BigDecimal salesAmount;
|
||||
/**
|
||||
* 总销售额
|
||||
*/
|
||||
@ExcelProperty("总销售额")
|
||||
@ColumnWidth(15)
|
||||
private BigDecimal totalSalesAmount;
|
||||
/**
|
||||
* 退单量
|
||||
*/
|
||||
@ExcelProperty("退单量")
|
||||
private Integer refundNum;
|
||||
@ColumnWidth(10)
|
||||
private BigDecimal refundNum;
|
||||
/**
|
||||
* 退单额
|
||||
*/
|
||||
@ExcelProperty("退单额")
|
||||
@ColumnWidth(10)
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.czg.service.order.mapper;
|
|||
|
||||
import com.czg.order.entity.ShopTableOrderStatistic;
|
||||
import com.czg.order.param.TableSummaryParam;
|
||||
import com.czg.order.vo.TableSummaryExportVo;
|
||||
import com.czg.order.vo.TableSummaryInfoVo;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
|
||||
|
|
@ -23,4 +24,6 @@ public interface ShopTableOrderStatisticMapper extends BaseMapper<ShopTableOrder
|
|||
List<TableSummaryInfoVo> findSummaryList(TableSummaryParam param);
|
||||
|
||||
List<TableSummaryInfoVo> findSummaryList2(TableSummaryParam param);
|
||||
|
||||
List<TableSummaryExportVo> findSummaryExportList(TableSummaryParam param);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,20 @@
|
|||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.czg.order.param.TableSummaryParam;
|
||||
import com.czg.order.service.TableSummaryService;
|
||||
import com.czg.order.vo.TableSummaryExportVo;
|
||||
import com.czg.order.vo.TableSummaryInfoVo;
|
||||
import com.czg.service.order.mapper.ShopTableOrderStatisticMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 台桌统计Service实现类
|
||||
|
|
@ -26,4 +33,50 @@ public class TableSummaryServiceImpl implements TableSummaryService {
|
|||
return shopTableOrderStatisticMapper.findSummaryList2(param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableSummaryExportVo> summaryExportList(TableSummaryParam param) {
|
||||
if (param.getBeginDate() == null && param.getEndDate() == null) {
|
||||
// 获取当前日期
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
// 计算 30 天前的日期
|
||||
LocalDate startDate = currentDate.minusDays(30);
|
||||
|
||||
// 定义日期格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
// 格式化日期
|
||||
String formattedStartDate = startDate.format(formatter);
|
||||
String formattedEndDate = currentDate.format(formatter);
|
||||
|
||||
param.setBeginDate(formattedStartDate + " 00:00:00");
|
||||
param.setEndDate(formattedEndDate + " 23:59:59");
|
||||
}
|
||||
List<TableSummaryExportVo> list = shopTableOrderStatisticMapper.findSummaryExportList(param);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
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();
|
||||
list.add(nullVo);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,8 @@
|
|||
LEFT JOIN tb_shop_table_area t3 ON t2.area_id = t3.id
|
||||
where t1.shop_id = #{shopId}
|
||||
and t1.table_code is not null
|
||||
and t2.table_code is not null
|
||||
and t2.table_code != ''
|
||||
and t2.name is not null
|
||||
and t1.paid_time is not null
|
||||
<if test="beginDate != null and beginDate != ''">
|
||||
|
|
@ -74,4 +76,50 @@
|
|||
GROUP BY t1.table_code
|
||||
order by count( t1.id ) desc,sum( t1.pay_amount ) desc
|
||||
</select>
|
||||
<select id="findSummaryExportList" resultType="com.czg.order.vo.TableSummaryExportVo">
|
||||
SELECT
|
||||
t.product_name,
|
||||
date_format(t.create_time, '%Y-%m-%d') as create_date,
|
||||
if(t.table_name = '11111111','银收客',t.table_name) as table_name,
|
||||
concat(if(t.table_name = '11111111','银收客',t.table_name),'-',date_format(t.create_time, '%Y-%m-%d')) as tableConcatDate,
|
||||
t.category_name,
|
||||
t.unit_name,
|
||||
group_concat(distinct t.sku_name SEPARATOR ';') as sku_name,
|
||||
sum(t.num) as num,
|
||||
avg(t.unit_price) as unit_price,
|
||||
sum(t.num*t.unit_price) as amount,
|
||||
sum(-t.refund_num) as refund_num,
|
||||
sum(-t.refund_num*t.unit_price) as refund_amount
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
t1.product_id,
|
||||
t2.table_code,
|
||||
IF(t2.table_code is null or t2.table_code = '' or t6.NAME is null, '11111111', t6.NAME) AS table_name,
|
||||
t1.create_time,
|
||||
t4.NAME AS category_name,
|
||||
t3.name as product_name,
|
||||
t5.NAME AS unit_name,
|
||||
t1.sku_name,
|
||||
t1.num,
|
||||
t1.unit_price,
|
||||
t1.refund_num as refund_num
|
||||
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 <= 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>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue