销量记录导出
This commit is contained in:
@@ -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(80)
|
||||||
private String productName;
|
private String productName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 销售数量
|
* 销售数量
|
||||||
*/
|
*/
|
||||||
|
@ExcelProperty("销售数量")
|
||||||
|
@ColumnWidth(30)
|
||||||
private BigDecimal saleCount;
|
private BigDecimal saleCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 销售金额
|
* 销售金额
|
||||||
*/
|
*/
|
||||||
|
@ExcelProperty("销售金额")
|
||||||
|
@ColumnWidth(50)
|
||||||
private BigDecimal saleAmount;
|
private BigDecimal saleAmount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退单量
|
* 退单量
|
||||||
*/
|
*/
|
||||||
|
@ExcelProperty("退单量")
|
||||||
|
@ColumnWidth(30)
|
||||||
private BigDecimal refundCount;
|
private BigDecimal refundCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退单金额
|
* 退单金额
|
||||||
*/
|
*/
|
||||||
|
@ExcelProperty("退单金额")
|
||||||
|
@ColumnWidth(50)
|
||||||
private BigDecimal refundAmount;
|
private BigDecimal refundAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实际销售数量(过滤掉退单后的数量)
|
||||||
|
*/
|
||||||
|
@ExcelProperty("实际销售数量")
|
||||||
|
@ColumnWidth(30)
|
||||||
|
private BigDecimal validSaleCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实际销售金额(过滤掉退单后的金额)
|
||||||
|
*/
|
||||||
|
@ExcelProperty("实际销售金额")
|
||||||
|
@ColumnWidth(50)
|
||||||
|
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)
|
||||||
|
|||||||
@@ -108,23 +108,23 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
|
|||||||
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)) {
|
if (CollUtil.isNotEmpty(realTimeData)) {
|
||||||
// 过滤掉没有有效数据的记录
|
boolean exists = exists(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, day));
|
||||||
realTimeData = realTimeData.stream()
|
if (exists) {
|
||||||
.filter(ShopProdStatistic::isValid)
|
remove(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, day));
|
||||||
.toList();
|
|
||||||
if (CollUtil.isNotEmpty(realTimeData)) {
|
|
||||||
boolean exists = exists(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, day));
|
|
||||||
if (exists) {
|
|
||||||
remove(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, day));
|
|
||||||
}
|
|
||||||
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
|
||||||
|
|||||||
@@ -90,10 +90,10 @@
|
|||||||
</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 statistic
|
tb_shop_prod_statistic statistic
|
||||||
INNER JOIN tb_product prod ON tb_shop_prod_statistic.prod_id = prod.id
|
INNER JOIN tb_product prod ON tb_shop_prod_statistic.prod_id = prod.id
|
||||||
@@ -107,10 +107,10 @@
|
|||||||
|
|
||||||
<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 statistic
|
tb_shop_prod_statistic statistic
|
||||||
INNER JOIN tb_product prod ON statistic.prod_id = prod.id
|
INNER JOIN tb_product prod ON statistic.prod_id = prod.id
|
||||||
|
|||||||
Reference in New Issue
Block a user