Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
张松
2025-11-26 09:32:57 +08:00
7 changed files with 125 additions and 108 deletions

View File

@@ -7,6 +7,7 @@ import com.czg.order.service.ShopProdStatisticService;
import com.czg.order.vo.SaleSummaryCountVo; import com.czg.order.vo.SaleSummaryCountVo;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -62,4 +63,15 @@ public class SaleSummaryController {
return CzgResult.success(list); return CzgResult.success(list);
} }
@ResponseExcel(name = "销售统计明细")
@GetMapping("/export")
public List<ShopProdStatistic> summaryExport(SaleSummaryCountParam param) {
Long shopId = StpKit.USER.getShopId();
if (param.getShopId() == null) {
param.setShopId(shopId);
}
return prodStatisticService.getArchiveTradeData(
param.getShopId(),param.getProductName(), param.getRangeType(), param.getBeginDate(), param.getEndDate());
}
} }

View File

@@ -1,5 +1,8 @@
package com.czg.order.entity; package com.czg.order.entity;
import cn.idev.excel.annotation.ExcelIgnore;
import cn.idev.excel.annotation.ExcelProperty;
import cn.idev.excel.annotation.write.style.ColumnWidth;
import com.mybatisflex.annotation.Column; import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType; import com.mybatisflex.annotation.KeyType;
@@ -20,7 +23,6 @@ import java.util.Date;
* @since 2025-03-07 * @since 2025-03-07
*/ */
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Table("tb_shop_prod_statistic") @Table("tb_shop_prod_statistic")
@@ -30,48 +32,83 @@ public class ShopProdStatistic implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto) @Id(keyType = KeyType.Auto)
@ExcelIgnore
private Long id; private Long id;
/** /**
* 商品id * 商品id
*/ */
@ExcelIgnore
private Long prodId; private Long prodId;
/** /**
* 商品名称 * 商品名称
*/ */
@Column(ignore = true) @Column(ignore = true)
@ExcelProperty("商品名称")
@ColumnWidth(30)
private String productName; private String productName;
/** /**
* 销售数量 * 销售数量
*/ */
@ExcelProperty("销量")
@ColumnWidth(5)
private BigDecimal saleCount; private BigDecimal saleCount;
/** /**
* 销售金额 * 销售金额
*/ */
@ExcelProperty("销售金额")
@ColumnWidth(7)
private BigDecimal saleAmount; private BigDecimal saleAmount;
/** /**
* 退单量 * 退单量
*/ */
@ExcelProperty("退单量")
@ColumnWidth(5)
private BigDecimal refundCount; private BigDecimal refundCount;
/** /**
* 退单金额 * 退单金额
*/ */
@ExcelProperty("退款金额")
@ColumnWidth(7)
private BigDecimal refundAmount; private BigDecimal refundAmount;
/**
* 实际销售数量(过滤掉退单后的数量)
*/
@ExcelProperty("实际销量")
@ColumnWidth(5)
private BigDecimal validSaleCount;
/**
* 实际销售金额(过滤掉退单后的金额)
*/
@ExcelProperty("实际销售额")
@ColumnWidth(7)
private BigDecimal validSaleAmount;
/** /**
* 店铺id * 店铺id
*/ */
@ExcelIgnore
private Long shopId; private Long shopId;
/** /**
* 创建时间 * 创建时间
*/ */
@ExcelIgnore
private Date createDay; private Date createDay;
public void initValidData() {
// 初始化实际销售数量和金额(过滤退单数据)
this.validSaleCount = this.saleCount.subtract(this.refundCount);
this.validSaleAmount = this.saleAmount.subtract(this.refundAmount);
}
// 在 ShopProdStatistic.java 中添加以下方法 // 在 ShopProdStatistic.java 中添加以下方法
/** /**
* 判断当前统计数据是否有效销售数量、金额退单数量、金额均有值且大于0 * 判断当前统计数据是否有效销售数量、金额退单数量、金额均有值且大于0

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

@@ -107,11 +107,6 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
@Override @Override
public void statisticAndInsert(Long shopId, LocalDate day) { public void statisticAndInsert(Long shopId, LocalDate day) {
List<ShopProdStatistic> realTimeData = getRealTimeDataByDay(shopId, day, null); List<ShopProdStatistic> realTimeData = getRealTimeDataByDay(shopId, day, null);
if (CollUtil.isNotEmpty(realTimeData)) {
// 过滤掉没有有效数据的记录
realTimeData = realTimeData.stream()
.filter(ShopProdStatistic::isValid)
.toList();
if (CollUtil.isNotEmpty(realTimeData)) { if (CollUtil.isNotEmpty(realTimeData)) {
boolean exists = exists(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, day)); boolean exists = exists(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, day));
if (exists) { if (exists) {
@@ -120,11 +115,16 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
saveBatch(realTimeData); saveBatch(realTimeData);
} }
} }
}
@Override @Override
public List<ShopProdStatistic> getRealTimeDataByDay(Long shopId, LocalDate day, String productName) { public List<ShopProdStatistic> getRealTimeDataByDay(Long shopId, LocalDate day, String productName) {
return mapper.selectProStatByDay(shopId, day, productName); List<ShopProdStatistic> shopProdStatistics = mapper.selectProStatByDay(shopId, day, productName);
// 过滤掉没有有效数据的记录
shopProdStatistics = shopProdStatistics.stream()
.filter(ShopProdStatistic::isValid)
.peek(ShopProdStatistic::initValidData)
.toList();
return shopProdStatistics;
} }
@Override @Override

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

@@ -23,7 +23,7 @@
AND `order`.trade_day = #{day} AND `order`.trade_day = #{day}
AND `order`.paid_time IS NOT NULL AND `order`.paid_time IS NOT NULL
<if test="productName != null and productName != ''"> <if test="productName != null and productName != ''">
AND detail.name LIKE CONCAT('%',#{productName},'%') AND detail.product_name LIKE CONCAT('%',#{productName},'%')
</if> </if>
GROUP BY prodId GROUP BY prodId
</select> </select>
@@ -85,20 +85,21 @@
AND `order`.trade_day = #{day} AND `order`.trade_day = #{day}
AND `order`.paid_time IS NOT NULL AND `order`.paid_time IS NOT NULL
<if test="productName != null and productName != ''"> <if test="productName != null and productName != ''">
AND detail.name LIKE CONCAT('%',#{productName},'%') AND detail.product_name LIKE CONCAT('%',#{productName},'%')
</if> </if>
</select> </select>
<select id="summaryCountSingleDate" resultType="com.czg.order.vo.SaleSummaryCountVo"> <select id="summaryCountSingleDate" resultType="com.czg.order.vo.SaleSummaryCountVo">
SELECT SELECT
sum(tb_shop_prod_statistic.sale_count) AS saleCount, sum(statistic.sale_count) AS saleCount,
sum(tb_shop_prod_statistic.sale_amount) AS saleAmount, sum(statistic.sale_amount) AS saleAmount,
sum(tb_shop_prod_statistic.refund_count) AS refundCount, sum(statistic.refund_count) AS refundCount,
sum(tb_shop_prod_statistic.refund_amount) AS refundAmount sum(statistic.refund_amount) AS refundAmount
FROM FROM
tb_shop_prod_statistic tb_shop_prod_statistic statistic
INNER JOIN tb_product prod ON tb_shop_prod_statistic.prod_id = prod.id
WHERE WHERE
tb_shop_prod_statistic.shop_id = #{shopId} statistic.shop_id = #{shopId}
AND tb_shop_prod_statistic.create_day = #{day} AND statistic.create_day = #{day}
<if test="productName != null and productName != ''"> <if test="productName != null and productName != ''">
AND prod.name LIKE CONCAT('%',#{productName},'%') AND prod.name LIKE CONCAT('%',#{productName},'%')
</if> </if>
@@ -106,16 +107,17 @@
<select id="summaryCountDateRange" resultType="com.czg.order.vo.SaleSummaryCountVo"> <select id="summaryCountDateRange" resultType="com.czg.order.vo.SaleSummaryCountVo">
SELECT SELECT
sum(tb_shop_prod_statistic.sale_count) AS saleCount, sum(statistic.sale_count) AS saleCount,
sum(tb_shop_prod_statistic.sale_amount) AS totalAmount, sum(statistic.sale_amount) AS totalAmount,
sum(tb_shop_prod_statistic.refund_count) AS refundCount, sum(statistic.refund_count) AS refundCount,
sum(tb_shop_prod_statistic.refund_amount) AS refundAmount sum(statistic.refund_amount) AS refundAmount
FROM FROM
tb_shop_prod_statistic tb_shop_prod_statistic statistic
INNER JOIN tb_product prod ON statistic.prod_id = prod.id
WHERE WHERE
tb_shop_prod_statistic.shop_id = #{shopId} statistic.shop_id = #{shopId}
AND tb_shop_prod_statistic.create_day &gt;= #{start} AND statistic.create_day &gt;= #{start}
AND tb_shop_prod_statistic.create_day &lt;= #{end} AND statistic.create_day &lt;= #{end}
<if test="productName != null and productName != ''"> <if test="productName != null and productName != ''">
AND prod.name LIKE CONCAT('%',#{productName},'%') AND prod.name LIKE CONCAT('%',#{productName},'%')
</if> </if>

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>