mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 13:49:19 +08:00
remove: 移除统计相关后端代码
This commit is contained in:
@@ -23,8 +23,6 @@ mybatis-plus:
|
||||
# 开发环境可按需打开 SQL 日志
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
order-stat:
|
||||
nightly-rebuild-enabled: false
|
||||
|
||||
knife4j:
|
||||
enable: true
|
||||
|
||||
@@ -20,8 +20,6 @@ spring:
|
||||
jwt:
|
||||
secret: staging-jwt-secret-key-must-be-at-least-64-bytes-long-for-hs512-algorithm
|
||||
|
||||
order-stat:
|
||||
nightly-rebuild-enabled: false
|
||||
|
||||
knife4j:
|
||||
enable: true
|
||||
|
||||
@@ -21,8 +21,6 @@ spring:
|
||||
jwt:
|
||||
secret: prod-jwt-secret-key-must-be-at-least-64-bytes-long-for-hs512-algorithm-security
|
||||
|
||||
order-stat:
|
||||
nightly-rebuild-enabled: false
|
||||
|
||||
knife4j:
|
||||
enable: false
|
||||
|
||||
@@ -18,10 +18,6 @@ spring:
|
||||
jwt:
|
||||
secret: test-jwt-secret-key-must-be-at-least-64-bytes-long-for-hs512-algorithm
|
||||
|
||||
order-stat:
|
||||
nightly-rebuild-enabled: false
|
||||
refresh-worker:
|
||||
enabled: false
|
||||
|
||||
knife4j:
|
||||
enable: true
|
||||
|
||||
@@ -35,19 +35,6 @@ spring:
|
||||
max-wait: -1ms
|
||||
|
||||
# 订单统计读模型(汇总表已删,待重构前关闭写入与 miss 补算)
|
||||
order-stat:
|
||||
stat-source: daily
|
||||
auto-refresh-on-miss: false
|
||||
refresh-worker:
|
||||
enabled: false
|
||||
pool-size: 4
|
||||
poll-interval-ms: 2000
|
||||
cache:
|
||||
enabled: true
|
||||
ttl-history-seconds: 86400
|
||||
ttl-today-seconds: 900
|
||||
nightly-rebuild-cron: "0 30 2 * * ?"
|
||||
nightly-rebuild-enabled: false
|
||||
|
||||
# 导入任务 Redis Stream 队列(DB 为真相源,Redis 负责调度)
|
||||
import-task:
|
||||
|
||||
@@ -1,251 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderStatAggMapper">
|
||||
|
||||
<sql id="orderBaseFilter">
|
||||
o.company_id = #{companyId}
|
||||
<choose>
|
||||
<when test="shopIds != null and shopIds.size() > 0">
|
||||
AND o.shop_id IN
|
||||
<foreach collection="shopIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</when>
|
||||
<otherwise>AND 1 = 0</otherwise>
|
||||
</choose>
|
||||
AND o.order_time >= #{start}
|
||||
AND o.order_time <= #{end}
|
||||
</sql>
|
||||
|
||||
<sql id="orderFilter">
|
||||
<include refid="orderBaseFilter"/>
|
||||
<choose>
|
||||
<when test="unionStatusCodes != null and unionStatusCodes.size() > 0">
|
||||
AND o.status IN
|
||||
<foreach collection="unionStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</when>
|
||||
<otherwise>AND 1 = 0</otherwise>
|
||||
</choose>
|
||||
</sql>
|
||||
|
||||
<sql id="qty">IFNULL(NULLIF(i.quantity, 0), 1)</sql>
|
||||
|
||||
<sql id="lineSales">IFNULL(NULLIF(i.line_amount, 0), IFNULL(i.unit_price, 0) * <include refid="qty"/>)</sql>
|
||||
|
||||
<sql id="sumSales">
|
||||
SUM(CASE WHEN o.status IN
|
||||
<foreach collection="salesStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN <include refid="lineSales"/> ELSE 0 END)
|
||||
</sql>
|
||||
<sql id="sumOrderCount">
|
||||
COUNT(DISTINCT CASE WHEN o.status IN
|
||||
<foreach collection="salesStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN o.id END)
|
||||
</sql>
|
||||
<sql id="sumSalesQuantity">
|
||||
SUM(CASE WHEN o.status IN
|
||||
<foreach collection="salesStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN <include refid="qty"/> ELSE 0 END)
|
||||
</sql>
|
||||
<sql id="sumGmvQuantity">
|
||||
SUM(<include refid="qty"/>)
|
||||
</sql>
|
||||
<sql id="sumRefund">
|
||||
SUM(CASE WHEN o.status IN
|
||||
<foreach collection="refundStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN <include refid="lineSales"/> ELSE 0 END)
|
||||
</sql>
|
||||
<sql id="sumProductCost">
|
||||
SUM(CASE WHEN o.status IN
|
||||
<foreach collection="productCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.product_cost, 0) * <include refid="qty"/> ELSE 0 END)
|
||||
</sql>
|
||||
<sql id="sumFreightCost">
|
||||
SUM(CASE WHEN o.status IN
|
||||
<foreach collection="freightCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.shipping_cost, 0) * <include refid="qty"/> ELSE 0 END)
|
||||
</sql>
|
||||
<sql id="sumOtherCost">
|
||||
SUM(CASE WHEN o.status IN
|
||||
<foreach collection="otherCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.other_cost, 0) * <include refid="qty"/> ELSE 0 END)
|
||||
</sql>
|
||||
|
||||
<select id="aggregateByShopProduct"
|
||||
resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderStatAggMapper$ShopProductRow">
|
||||
SELECT o.shop_id AS shopId, s.platform_code AS platformCode,
|
||||
IFNULL(i.product_id, -1) AS productId, IFNULL(p.category_id, 0) AS categoryId,
|
||||
<include refid="sumSales"/> AS salesAmount,
|
||||
<include refid="sumOrderCount"/> AS orderCount,
|
||||
<include refid="sumSalesQuantity"/> AS salesQuantitySum,
|
||||
<include refid="sumRefund"/> AS refundAmount,
|
||||
<include refid="sumProductCost"/> AS productCost,
|
||||
<include refid="sumFreightCost"/> AS freightCost,
|
||||
<include refid="sumOtherCost"/> AS otherCost,
|
||||
SUM(<include refid="lineSales"/>) AS gmvAllStatus,
|
||||
COUNT(DISTINCT o.id) AS gmvOrderCount,
|
||||
<include refid="sumGmvQuantity"/> AS gmvQuantitySum
|
||||
FROM ec_order o
|
||||
INNER JOIN ec_order_item i ON i.order_id = o.id
|
||||
INNER JOIN ec_shop s ON s.id = o.shop_id
|
||||
LEFT JOIN ec_product p ON p.id = i.product_id
|
||||
WHERE <include refid="orderBaseFilter"/>
|
||||
GROUP BY o.shop_id, s.platform_code, i.product_id, p.category_id
|
||||
</select>
|
||||
|
||||
<select id="aggregateDaily"
|
||||
resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderStatAggMapper$DailyRow">
|
||||
SELECT DATE(o.order_time) AS statDate,
|
||||
<include refid="sumSales"/> AS salesAmount,
|
||||
<include refid="sumRefund"/> AS refundAmount,
|
||||
<include refid="sumProductCost"/> AS productCost,
|
||||
<include refid="sumFreightCost"/> AS freightCost,
|
||||
<include refid="sumOtherCost"/> AS otherCost
|
||||
FROM ec_order o
|
||||
INNER JOIN ec_order_item i ON i.order_id = o.id
|
||||
WHERE <include refid="orderFilter"/>
|
||||
GROUP BY DATE(o.order_time)
|
||||
ORDER BY statDate
|
||||
</select>
|
||||
|
||||
<select id="aggregatePeriodKpi"
|
||||
resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderStatAggMapper$PeriodKpiRow">
|
||||
SELECT
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{curStart} AND #{curEnd} AND o.status IN
|
||||
<foreach collection="salesStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
AND i.line_no = 1 THEN o.pay_amount ELSE 0 END) AS curSalesAmount,
|
||||
COUNT(DISTINCT CASE WHEN o.order_time BETWEEN #{curStart} AND #{curEnd} AND o.status IN
|
||||
<foreach collection="salesStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN o.id END) AS curOrderCount,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{curStart} AND #{curEnd} AND o.status IN
|
||||
<foreach collection="refundStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
AND i.line_no = 1 THEN o.pay_amount ELSE 0 END) AS curRefundAmount,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{curStart} AND #{curEnd} AND o.status IN
|
||||
<foreach collection="productCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.product_cost, 0) * <include refid="qty"/> ELSE 0 END) AS curProductCost,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{curStart} AND #{curEnd} AND o.status IN
|
||||
<foreach collection="freightCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.shipping_cost, 0) * <include refid="qty"/> ELSE 0 END) AS curFreightCost,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{curStart} AND #{curEnd} AND o.status IN
|
||||
<foreach collection="otherCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.other_cost, 0) * <include refid="qty"/> ELSE 0 END) AS curOtherCost,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{curStart} AND #{curEnd} AND i.line_no = 1 THEN o.pay_amount ELSE 0 END) AS curGmvAllStatus,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{prevStart} AND #{prevEnd} AND o.status IN
|
||||
<foreach collection="salesStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
AND i.line_no = 1 THEN o.pay_amount ELSE 0 END) AS prevSalesAmount,
|
||||
COUNT(DISTINCT CASE WHEN o.order_time BETWEEN #{prevStart} AND #{prevEnd} AND o.status IN
|
||||
<foreach collection="salesStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN o.id END) AS prevOrderCount,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{prevStart} AND #{prevEnd} AND o.status IN
|
||||
<foreach collection="refundStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
AND i.line_no = 1 THEN o.pay_amount ELSE 0 END) AS prevRefundAmount,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{prevStart} AND #{prevEnd} AND o.status IN
|
||||
<foreach collection="productCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.product_cost, 0) * <include refid="qty"/> ELSE 0 END) AS prevProductCost,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{prevStart} AND #{prevEnd} AND o.status IN
|
||||
<foreach collection="freightCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.shipping_cost, 0) * <include refid="qty"/> ELSE 0 END) AS prevFreightCost,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{prevStart} AND #{prevEnd} AND o.status IN
|
||||
<foreach collection="otherCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.other_cost, 0) * <include refid="qty"/> ELSE 0 END) AS prevOtherCost,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{prevStart} AND #{prevEnd} AND i.line_no = 1 THEN o.pay_amount ELSE 0 END) AS prevGmvAllStatus,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{yoyStart} AND #{yoyEnd} AND o.status IN
|
||||
<foreach collection="salesStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
AND i.line_no = 1 THEN o.pay_amount ELSE 0 END) AS yoySalesAmount,
|
||||
COUNT(DISTINCT CASE WHEN o.order_time BETWEEN #{yoyStart} AND #{yoyEnd} AND o.status IN
|
||||
<foreach collection="salesStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN o.id END) AS yoyOrderCount,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{yoyStart} AND #{yoyEnd} AND o.status IN
|
||||
<foreach collection="refundStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
AND i.line_no = 1 THEN o.pay_amount ELSE 0 END) AS yoyRefundAmount,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{yoyStart} AND #{yoyEnd} AND o.status IN
|
||||
<foreach collection="productCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.product_cost, 0) * <include refid="qty"/> ELSE 0 END) AS yoyProductCost,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{yoyStart} AND #{yoyEnd} AND o.status IN
|
||||
<foreach collection="freightCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.shipping_cost, 0) * <include refid="qty"/> ELSE 0 END) AS yoyFreightCost,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{yoyStart} AND #{yoyEnd} AND o.status IN
|
||||
<foreach collection="otherCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.other_cost, 0) * <include refid="qty"/> ELSE 0 END) AS yoyOtherCost,
|
||||
SUM(CASE WHEN o.order_time BETWEEN #{yoyStart} AND #{yoyEnd} AND i.line_no = 1 THEN o.pay_amount ELSE 0 END) AS yoyGmvAllStatus
|
||||
FROM ec_order o
|
||||
INNER JOIN ec_order_item i ON i.order_id = o.id
|
||||
WHERE o.company_id = #{companyId}
|
||||
<choose>
|
||||
<when test="shopIds != null and shopIds.size() > 0">
|
||||
AND o.shop_id IN <foreach collection="shopIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</when>
|
||||
<otherwise>AND 1 = 0</otherwise>
|
||||
</choose>
|
||||
AND o.order_time BETWEEN #{scanStart} AND #{scanEnd}
|
||||
<choose>
|
||||
<when test="unionStatusCodes != null and unionStatusCodes.size() > 0">
|
||||
AND o.status IN <foreach collection="unionStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</when>
|
||||
<otherwise>AND 1 = 0</otherwise>
|
||||
</choose>
|
||||
</select>
|
||||
|
||||
<select id="aggregatePromotionPeriodKpi"
|
||||
resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderStatAggMapper$FeeKpiRow">
|
||||
SELECT
|
||||
SUM(CASE WHEN f.fee_date BETWEEN #{curStart} AND #{curEnd} THEN IFNULL(f.fee_amount,0) ELSE 0 END) AS curAmount,
|
||||
SUM(CASE WHEN f.fee_date BETWEEN #{prevStart} AND #{prevEnd} THEN IFNULL(f.fee_amount,0) ELSE 0 END) AS prevAmount,
|
||||
SUM(CASE WHEN f.fee_date BETWEEN #{yoyStart} AND #{yoyEnd} THEN IFNULL(f.fee_amount,0) ELSE 0 END) AS yoyAmount
|
||||
FROM ec_promotion_fee f
|
||||
WHERE f.company_id = #{companyId}
|
||||
<choose>
|
||||
<when test="shopIds != null and shopIds.size() > 0">
|
||||
AND f.shop_id IN <foreach collection="shopIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</when>
|
||||
<otherwise>AND 1 = 0</otherwise>
|
||||
</choose>
|
||||
AND f.fee_date BETWEEN #{scanStart} AND #{scanEnd}
|
||||
</select>
|
||||
|
||||
<select id="aggregateBrushPeriodKpi"
|
||||
resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderStatAggMapper$FeeKpiRow">
|
||||
SELECT
|
||||
SUM(CASE WHEN b.brush_time BETWEEN #{curStart} AND #{curEnd} THEN IFNULL(b.brush_amount,0) ELSE 0 END) AS curAmount,
|
||||
SUM(CASE WHEN b.brush_time BETWEEN #{prevStart} AND #{prevEnd} THEN IFNULL(b.brush_amount,0) ELSE 0 END) AS prevAmount,
|
||||
SUM(CASE WHEN b.brush_time BETWEEN #{yoyStart} AND #{yoyEnd} THEN IFNULL(b.brush_amount,0) ELSE 0 END) AS yoyAmount
|
||||
FROM ec_brush_order b
|
||||
WHERE b.company_id = #{companyId}
|
||||
<choose>
|
||||
<when test="shopIds != null and shopIds.size() > 0">
|
||||
AND b.shop_id IN <foreach collection="shopIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</when>
|
||||
<otherwise>AND 1 = 0</otherwise>
|
||||
</choose>
|
||||
AND b.brush_time BETWEEN #{scanStart} AND #{scanEnd}
|
||||
</select>
|
||||
|
||||
<select id="aggregatePromotionFees"
|
||||
resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderStatAggMapper$PromotionRow">
|
||||
SELECT f.shop_id AS shopId, f.product_id AS productId, f.category_id AS categoryId,
|
||||
SUM(IFNULL(f.fee_amount, 0)) AS feeAmount
|
||||
FROM ec_promotion_fee f
|
||||
WHERE f.company_id = #{companyId}
|
||||
<choose>
|
||||
<when test="shopIds != null and shopIds.size() > 0">
|
||||
AND f.shop_id IN <foreach collection="shopIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</when>
|
||||
<otherwise>AND 1 = 0</otherwise>
|
||||
</choose>
|
||||
AND f.fee_date BETWEEN #{startDate} AND #{endDate}
|
||||
GROUP BY f.shop_id, f.product_id, f.category_id
|
||||
</select>
|
||||
|
||||
<select id="aggregateBrushFees"
|
||||
resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderStatAggMapper$BrushRow">
|
||||
SELECT b.shop_id AS shopId, SUM(IFNULL(b.brush_amount, 0)) AS brushAmount
|
||||
FROM ec_brush_order b
|
||||
WHERE b.company_id = #{companyId}
|
||||
<choose>
|
||||
<when test="shopIds != null and shopIds.size() > 0">
|
||||
AND b.shop_id IN <foreach collection="shopIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
</when>
|
||||
<otherwise>AND 1 = 0</otherwise>
|
||||
</choose>
|
||||
AND b.brush_time BETWEEN #{start} AND #{end}
|
||||
GROUP BY b.shop_id
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -1,94 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.mapper.FeeStatDailyMapper">
|
||||
|
||||
<delete id="deletePromotionDaily">
|
||||
DELETE FROM ec_promotion_fee_stat_daily
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId} AND stat_date = #{statDate}
|
||||
</delete>
|
||||
|
||||
<insert id="batchInsertPromotionDaily">
|
||||
INSERT INTO ec_promotion_fee_stat_daily (
|
||||
company_id, shop_id, product_id, category_id, stat_date, fee_amount
|
||||
) VALUES
|
||||
<foreach collection="list" item="r" separator=",">
|
||||
(#{r.companyId}, #{r.shopId}, #{r.productId}, #{r.categoryId}, #{r.statDate}, #{r.feeAmount})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<insert id="rollupPromotionMonthly">
|
||||
INSERT INTO ec_promotion_fee_stat_monthly (
|
||||
company_id, shop_id, product_id, category_id, stat_month, fee_amount
|
||||
)
|
||||
SELECT company_id, shop_id, product_id, category_id, #{statMonth}, SUM(fee_amount)
|
||||
FROM ec_promotion_fee_stat_daily
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId}
|
||||
AND stat_date >= #{statMonth}
|
||||
AND stat_date < DATE_ADD(#{statMonth}, INTERVAL 1 MONTH)
|
||||
GROUP BY company_id, shop_id, product_id, category_id
|
||||
ON DUPLICATE KEY UPDATE fee_amount = VALUES(fee_amount), update_time = CURRENT_TIMESTAMP
|
||||
</insert>
|
||||
|
||||
<insert id="rollupPromotionYearly">
|
||||
INSERT INTO ec_promotion_fee_stat_yearly (
|
||||
company_id, shop_id, product_id, category_id, stat_year, fee_amount
|
||||
)
|
||||
SELECT company_id, shop_id, product_id, category_id, #{statYear}, SUM(fee_amount)
|
||||
FROM ec_promotion_fee_stat_monthly
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId} AND YEAR(stat_month) = #{statYear}
|
||||
GROUP BY company_id, shop_id, product_id, category_id
|
||||
ON DUPLICATE KEY UPDATE fee_amount = VALUES(fee_amount), update_time = CURRENT_TIMESTAMP
|
||||
</insert>
|
||||
|
||||
<delete id="deleteBrushDaily">
|
||||
DELETE FROM ec_brush_fee_stat_daily
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId} AND stat_date = #{statDate}
|
||||
</delete>
|
||||
|
||||
<insert id="upsertBrushDaily">
|
||||
INSERT INTO ec_brush_fee_stat_daily (company_id, shop_id, stat_date, brush_amount)
|
||||
VALUES (#{companyId}, #{shopId}, #{statDate}, #{brushAmount})
|
||||
ON DUPLICATE KEY UPDATE brush_amount = VALUES(brush_amount), update_time = CURRENT_TIMESTAMP
|
||||
</insert>
|
||||
|
||||
<insert id="rollupBrushMonthly">
|
||||
INSERT INTO ec_brush_fee_stat_monthly (company_id, shop_id, stat_month, brush_amount)
|
||||
SELECT company_id, shop_id, #{statMonth}, SUM(brush_amount)
|
||||
FROM ec_brush_fee_stat_daily
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId}
|
||||
AND stat_date >= #{statMonth}
|
||||
AND stat_date < DATE_ADD(#{statMonth}, INTERVAL 1 MONTH)
|
||||
GROUP BY company_id, shop_id
|
||||
ON DUPLICATE KEY UPDATE brush_amount = VALUES(brush_amount), update_time = CURRENT_TIMESTAMP
|
||||
</insert>
|
||||
|
||||
<insert id="rollupBrushYearly">
|
||||
INSERT INTO ec_brush_fee_stat_yearly (company_id, shop_id, stat_year, brush_amount)
|
||||
SELECT company_id, shop_id, #{statYear}, SUM(brush_amount)
|
||||
FROM ec_brush_fee_stat_monthly
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId} AND YEAR(stat_month) = #{statYear}
|
||||
GROUP BY company_id, shop_id
|
||||
ON DUPLICATE KEY UPDATE brush_amount = VALUES(brush_amount), update_time = CURRENT_TIMESTAMP
|
||||
</insert>
|
||||
|
||||
<select id="aggregatePromotionByShopDay"
|
||||
resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.mapper.FeeStatDailyMapper$PromotionFeeAggRow">
|
||||
SELECT
|
||||
IFNULL(f.product_id, 0) AS productId,
|
||||
IFNULL(f.category_id, 0) AS categoryId,
|
||||
SUM(IFNULL(f.fee_amount, 0)) AS feeAmount
|
||||
FROM ec_promotion_fee f
|
||||
WHERE f.company_id = #{companyId}
|
||||
AND f.shop_id = #{shopId}
|
||||
AND f.fee_date = #{statDate}
|
||||
GROUP BY IFNULL(f.product_id, 0), IFNULL(f.category_id, 0)
|
||||
</select>
|
||||
|
||||
<select id="aggregateBrushByShopDay" resultType="java.math.BigDecimal">
|
||||
SELECT IFNULL(SUM(IFNULL(b.brush_amount, 0)), 0)
|
||||
FROM ec_brush_order b
|
||||
WHERE b.company_id = #{companyId}
|
||||
AND b.shop_id = #{shopId}
|
||||
AND DATE(b.brush_time) = #{statDate}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -1,272 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.mapper.OrderStatDailyMapper">
|
||||
|
||||
<insert id="upsertDailyShop">
|
||||
INSERT INTO ec_order_stat_daily_shop (
|
||||
company_id, shop_id, platform_code, stat_date,
|
||||
sales_amount, sales_order_count, sales_quantity_sum,
|
||||
gmv_amount, gmv_order_count, gmv_quantity_sum,
|
||||
refund_amount, product_cost, freight_cost, other_cost,
|
||||
stat_version
|
||||
) VALUES (
|
||||
#{companyId}, #{shopId}, #{platformCode}, #{statDate},
|
||||
#{salesAmount}, #{salesOrderCount}, #{salesQuantitySum},
|
||||
#{gmvAmount}, #{gmvOrderCount}, #{gmvQuantitySum},
|
||||
#{refundAmount}, #{productCost}, #{freightCost}, #{otherCost},
|
||||
#{statVersion}
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
platform_code = VALUES(platform_code),
|
||||
sales_amount = VALUES(sales_amount),
|
||||
sales_order_count = VALUES(sales_order_count),
|
||||
sales_quantity_sum = VALUES(sales_quantity_sum),
|
||||
gmv_amount = VALUES(gmv_amount),
|
||||
gmv_order_count = VALUES(gmv_order_count),
|
||||
gmv_quantity_sum = VALUES(gmv_quantity_sum),
|
||||
refund_amount = VALUES(refund_amount),
|
||||
product_cost = VALUES(product_cost),
|
||||
freight_cost = VALUES(freight_cost),
|
||||
other_cost = VALUES(other_cost),
|
||||
stat_version = VALUES(stat_version),
|
||||
update_time = CURRENT_TIMESTAMP
|
||||
</insert>
|
||||
|
||||
<delete id="deleteDailyProduct">
|
||||
DELETE FROM ec_order_stat_daily_product
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId} AND stat_date = #{statDate}
|
||||
</delete>
|
||||
|
||||
<insert id="batchInsertDailyProduct">
|
||||
INSERT INTO ec_order_stat_daily_product (
|
||||
company_id, shop_id, product_id, category_id, stat_date,
|
||||
sales_amount, sales_order_count, sales_quantity_sum,
|
||||
gmv_amount, gmv_order_count, gmv_quantity_sum,
|
||||
refund_amount, product_cost, freight_cost, other_cost, stat_version
|
||||
) VALUES
|
||||
<foreach collection="list" item="r" separator=",">
|
||||
(#{r.companyId}, #{r.shopId}, #{r.productId}, #{r.categoryId}, #{r.statDate},
|
||||
#{r.salesAmount}, #{r.salesOrderCount}, #{r.salesQuantitySum},
|
||||
#{r.gmvAmount}, #{r.gmvOrderCount}, #{r.gmvQuantitySum},
|
||||
#{r.refundAmount}, #{r.productCost}, #{r.freightCost}, #{r.otherCost}, #{r.statVersion})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<delete id="deleteDailySpec">
|
||||
DELETE FROM ec_order_stat_daily_spec
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId} AND stat_date = #{statDate}
|
||||
</delete>
|
||||
|
||||
<insert id="batchInsertDailySpec">
|
||||
INSERT INTO ec_order_stat_daily_spec (
|
||||
company_id, shop_id, product_id, product_sku_id, stat_date,
|
||||
sales_amount, sales_order_count, sales_quantity_sum,
|
||||
gmv_amount, gmv_order_count, gmv_quantity_sum,
|
||||
refund_amount, product_cost, freight_cost, other_cost, stat_version
|
||||
) VALUES
|
||||
<foreach collection="list" item="r" separator=",">
|
||||
(#{r.companyId}, #{r.shopId}, #{r.productId}, #{r.productSkuId}, #{r.statDate},
|
||||
#{r.salesAmount}, #{r.salesOrderCount}, #{r.salesQuantitySum},
|
||||
#{r.gmvAmount}, #{r.gmvOrderCount}, #{r.gmvQuantitySum},
|
||||
#{r.refundAmount}, #{r.productCost}, #{r.freightCost}, #{r.otherCost}, #{r.statVersion})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<!-- 月/年 rollup:从日表 SUM 写入对应粒度表 -->
|
||||
<insert id="rollupMonthlyShop">
|
||||
INSERT INTO ec_order_stat_monthly_shop (
|
||||
company_id, shop_id, platform_code, stat_month,
|
||||
sales_amount, sales_order_count, sales_quantity_sum,
|
||||
gmv_amount, gmv_order_count, gmv_quantity_sum,
|
||||
refund_amount, product_cost, freight_cost, other_cost, stat_version
|
||||
)
|
||||
SELECT company_id, shop_id, MAX(platform_code),
|
||||
#{statMonth},
|
||||
SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum),
|
||||
SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum),
|
||||
SUM(refund_amount), SUM(product_cost), SUM(freight_cost), SUM(other_cost),
|
||||
MAX(stat_version)
|
||||
FROM ec_order_stat_daily_shop
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId}
|
||||
AND stat_date >= #{statMonth}
|
||||
AND stat_date < DATE_ADD(#{statMonth}, INTERVAL 1 MONTH)
|
||||
GROUP BY company_id, shop_id
|
||||
ON DUPLICATE KEY UPDATE
|
||||
platform_code = VALUES(platform_code),
|
||||
sales_amount = VALUES(sales_amount),
|
||||
sales_order_count = VALUES(sales_order_count),
|
||||
sales_quantity_sum = VALUES(sales_quantity_sum),
|
||||
gmv_amount = VALUES(gmv_amount),
|
||||
gmv_order_count = VALUES(gmv_order_count),
|
||||
gmv_quantity_sum = VALUES(gmv_quantity_sum),
|
||||
refund_amount = VALUES(refund_amount),
|
||||
product_cost = VALUES(product_cost),
|
||||
freight_cost = VALUES(freight_cost),
|
||||
other_cost = VALUES(other_cost),
|
||||
stat_version = VALUES(stat_version),
|
||||
update_time = CURRENT_TIMESTAMP
|
||||
</insert>
|
||||
|
||||
<insert id="rollupYearlyShop">
|
||||
INSERT INTO ec_order_stat_yearly_shop (
|
||||
company_id, shop_id, platform_code, stat_year,
|
||||
sales_amount, sales_order_count, sales_quantity_sum,
|
||||
gmv_amount, gmv_order_count, gmv_quantity_sum,
|
||||
refund_amount, product_cost, freight_cost, other_cost, stat_version
|
||||
)
|
||||
SELECT company_id, shop_id, MAX(platform_code),
|
||||
#{statYear},
|
||||
SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum),
|
||||
SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum),
|
||||
SUM(refund_amount), SUM(product_cost), SUM(freight_cost), SUM(other_cost),
|
||||
MAX(stat_version)
|
||||
FROM ec_order_stat_monthly_shop
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId}
|
||||
AND YEAR(stat_month) = #{statYear}
|
||||
GROUP BY company_id, shop_id
|
||||
ON DUPLICATE KEY UPDATE
|
||||
platform_code = VALUES(platform_code),
|
||||
sales_amount = VALUES(sales_amount),
|
||||
sales_order_count = VALUES(sales_order_count),
|
||||
sales_quantity_sum = VALUES(sales_quantity_sum),
|
||||
gmv_amount = VALUES(gmv_amount),
|
||||
gmv_order_count = VALUES(gmv_order_count),
|
||||
gmv_quantity_sum = VALUES(gmv_quantity_sum),
|
||||
refund_amount = VALUES(refund_amount),
|
||||
product_cost = VALUES(product_cost),
|
||||
freight_cost = VALUES(freight_cost),
|
||||
other_cost = VALUES(other_cost),
|
||||
stat_version = VALUES(stat_version),
|
||||
update_time = CURRENT_TIMESTAMP
|
||||
</insert>
|
||||
|
||||
<insert id="rollupMonthlyProduct">
|
||||
INSERT INTO ec_order_stat_monthly_product (
|
||||
company_id, shop_id, product_id, category_id, stat_month,
|
||||
sales_amount, sales_order_count, sales_quantity_sum,
|
||||
gmv_amount, gmv_order_count, gmv_quantity_sum,
|
||||
refund_amount, product_cost, freight_cost, other_cost, stat_version
|
||||
)
|
||||
SELECT company_id, shop_id, product_id, category_id,
|
||||
#{statMonth},
|
||||
SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum),
|
||||
SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum),
|
||||
SUM(refund_amount), SUM(product_cost), SUM(freight_cost), SUM(other_cost),
|
||||
MAX(stat_version)
|
||||
FROM ec_order_stat_daily_product
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId}
|
||||
AND stat_date >= #{statMonth}
|
||||
AND stat_date < DATE_ADD(#{statMonth}, INTERVAL 1 MONTH)
|
||||
GROUP BY company_id, shop_id, product_id, category_id
|
||||
ON DUPLICATE KEY UPDATE
|
||||
sales_amount = VALUES(sales_amount),
|
||||
sales_order_count = VALUES(sales_order_count),
|
||||
sales_quantity_sum = VALUES(sales_quantity_sum),
|
||||
gmv_amount = VALUES(gmv_amount),
|
||||
gmv_order_count = VALUES(gmv_order_count),
|
||||
gmv_quantity_sum = VALUES(gmv_quantity_sum),
|
||||
refund_amount = VALUES(refund_amount),
|
||||
product_cost = VALUES(product_cost),
|
||||
freight_cost = VALUES(freight_cost),
|
||||
other_cost = VALUES(other_cost),
|
||||
stat_version = VALUES(stat_version),
|
||||
update_time = CURRENT_TIMESTAMP
|
||||
</insert>
|
||||
|
||||
<insert id="rollupYearlyProduct">
|
||||
INSERT INTO ec_order_stat_yearly_product (
|
||||
company_id, shop_id, product_id, category_id, stat_year,
|
||||
sales_amount, sales_order_count, sales_quantity_sum,
|
||||
gmv_amount, gmv_order_count, gmv_quantity_sum,
|
||||
refund_amount, product_cost, freight_cost, other_cost, stat_version
|
||||
)
|
||||
SELECT company_id, shop_id, product_id, category_id,
|
||||
#{statYear},
|
||||
SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum),
|
||||
SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum),
|
||||
SUM(refund_amount), SUM(product_cost), SUM(freight_cost), SUM(other_cost),
|
||||
MAX(stat_version)
|
||||
FROM ec_order_stat_monthly_product
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId}
|
||||
AND YEAR(stat_month) = #{statYear}
|
||||
GROUP BY company_id, shop_id, product_id, category_id
|
||||
ON DUPLICATE KEY UPDATE
|
||||
sales_amount = VALUES(sales_amount),
|
||||
sales_order_count = VALUES(sales_order_count),
|
||||
sales_quantity_sum = VALUES(sales_quantity_sum),
|
||||
gmv_amount = VALUES(gmv_amount),
|
||||
gmv_order_count = VALUES(gmv_order_count),
|
||||
gmv_quantity_sum = VALUES(gmv_quantity_sum),
|
||||
refund_amount = VALUES(refund_amount),
|
||||
product_cost = VALUES(product_cost),
|
||||
freight_cost = VALUES(freight_cost),
|
||||
other_cost = VALUES(other_cost),
|
||||
stat_version = VALUES(stat_version),
|
||||
update_time = CURRENT_TIMESTAMP
|
||||
</insert>
|
||||
|
||||
<insert id="rollupMonthlySpec">
|
||||
INSERT INTO ec_order_stat_monthly_spec (
|
||||
company_id, shop_id, product_id, product_sku_id, stat_month,
|
||||
sales_amount, sales_order_count, sales_quantity_sum,
|
||||
gmv_amount, gmv_order_count, gmv_quantity_sum,
|
||||
refund_amount, product_cost, freight_cost, other_cost, stat_version
|
||||
)
|
||||
SELECT company_id, shop_id, product_id, product_sku_id,
|
||||
#{statMonth},
|
||||
SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum),
|
||||
SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum),
|
||||
SUM(refund_amount), SUM(product_cost), SUM(freight_cost), SUM(other_cost),
|
||||
MAX(stat_version)
|
||||
FROM ec_order_stat_daily_spec
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId}
|
||||
AND stat_date >= #{statMonth}
|
||||
AND stat_date < DATE_ADD(#{statMonth}, INTERVAL 1 MONTH)
|
||||
GROUP BY company_id, shop_id, product_id, product_sku_id
|
||||
ON DUPLICATE KEY UPDATE
|
||||
sales_amount = VALUES(sales_amount),
|
||||
sales_order_count = VALUES(sales_order_count),
|
||||
sales_quantity_sum = VALUES(sales_quantity_sum),
|
||||
gmv_amount = VALUES(gmv_amount),
|
||||
gmv_order_count = VALUES(gmv_order_count),
|
||||
gmv_quantity_sum = VALUES(gmv_quantity_sum),
|
||||
refund_amount = VALUES(refund_amount),
|
||||
product_cost = VALUES(product_cost),
|
||||
freight_cost = VALUES(freight_cost),
|
||||
other_cost = VALUES(other_cost),
|
||||
stat_version = VALUES(stat_version),
|
||||
update_time = CURRENT_TIMESTAMP
|
||||
</insert>
|
||||
|
||||
<insert id="rollupYearlySpec">
|
||||
INSERT INTO ec_order_stat_yearly_spec (
|
||||
company_id, shop_id, product_id, product_sku_id, stat_year,
|
||||
sales_amount, sales_order_count, sales_quantity_sum,
|
||||
gmv_amount, gmv_order_count, gmv_quantity_sum,
|
||||
refund_amount, product_cost, freight_cost, other_cost, stat_version
|
||||
)
|
||||
SELECT company_id, shop_id, product_id, product_sku_id,
|
||||
#{statYear},
|
||||
SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum),
|
||||
SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum),
|
||||
SUM(refund_amount), SUM(product_cost), SUM(freight_cost), SUM(other_cost),
|
||||
MAX(stat_version)
|
||||
FROM ec_order_stat_monthly_spec
|
||||
WHERE company_id = #{companyId} AND shop_id = #{shopId}
|
||||
AND YEAR(stat_month) = #{statYear}
|
||||
GROUP BY company_id, shop_id, product_id, product_sku_id
|
||||
ON DUPLICATE KEY UPDATE
|
||||
sales_amount = VALUES(sales_amount),
|
||||
sales_order_count = VALUES(sales_order_count),
|
||||
sales_quantity_sum = VALUES(sales_quantity_sum),
|
||||
gmv_amount = VALUES(gmv_amount),
|
||||
gmv_order_count = VALUES(gmv_order_count),
|
||||
gmv_quantity_sum = VALUES(gmv_quantity_sum),
|
||||
refund_amount = VALUES(refund_amount),
|
||||
product_cost = VALUES(product_cost),
|
||||
freight_cost = VALUES(freight_cost),
|
||||
other_cost = VALUES(other_cost),
|
||||
stat_version = VALUES(stat_version),
|
||||
update_time = CURRENT_TIMESTAMP
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -1,245 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.mapper.OrderStatQueryMapper">
|
||||
|
||||
<sql id="shopFilter">
|
||||
company_id = #{companyId}
|
||||
AND shop_id IN
|
||||
<foreach collection="shopIds" item="sid" open="(" separator="," close=")">#{sid}</foreach>
|
||||
</sql>
|
||||
|
||||
<sql id="kpiSumShop">
|
||||
COALESCE(SUM(sales_amount), 0) AS salesAmount,
|
||||
COALESCE(SUM(refund_amount), 0) AS refundAmount,
|
||||
COALESCE(SUM(sales_order_count), 0) AS salesOrderCount,
|
||||
COALESCE(SUM(sales_quantity_sum), 0) AS salesQuantitySum,
|
||||
COALESCE(SUM(gmv_amount), 0) AS gmvAmount,
|
||||
COALESCE(SUM(gmv_order_count), 0) AS gmvOrderCount,
|
||||
COALESCE(SUM(gmv_quantity_sum), 0) AS gmvQuantitySum
|
||||
</sql>
|
||||
|
||||
<sql id="kpiSumProduct">
|
||||
COALESCE(SUM(sales_amount), 0) AS salesAmount,
|
||||
COALESCE(SUM(refund_amount), 0) AS refundAmount,
|
||||
COALESCE(SUM(sales_order_count), 0) AS salesOrderCount,
|
||||
COALESCE(SUM(sales_quantity_sum), 0) AS salesQuantitySum,
|
||||
COALESCE(SUM(gmv_amount), 0) AS gmvAmount,
|
||||
COALESCE(SUM(gmv_order_count), 0) AS gmvOrderCount,
|
||||
COALESCE(SUM(gmv_quantity_sum), 0) AS gmvQuantitySum,
|
||||
COALESCE(SUM(product_cost), 0) AS productCost,
|
||||
COALESCE(SUM(freight_cost), 0) AS freightCost,
|
||||
COALESCE(SUM(other_cost), 0) AS otherCost
|
||||
</sql>
|
||||
|
||||
<sql id="kpiSumSpec">
|
||||
COALESCE(SUM(sales_amount), 0) AS salesAmount,
|
||||
COALESCE(SUM(refund_amount), 0) AS refundAmount,
|
||||
COALESCE(SUM(sales_order_count), 0) AS salesOrderCount,
|
||||
COALESCE(SUM(sales_quantity_sum), 0) AS salesQuantitySum,
|
||||
COALESCE(SUM(gmv_amount), 0) AS gmvAmount,
|
||||
COALESCE(SUM(gmv_order_count), 0) AS gmvOrderCount,
|
||||
COALESCE(SUM(gmv_quantity_sum), 0) AS gmvQuantitySum,
|
||||
COALESCE(SUM(product_cost), 0) AS productCost,
|
||||
COALESCE(SUM(freight_cost), 0) AS freightCost,
|
||||
COALESCE(SUM(other_cost), 0) AS otherCost
|
||||
</sql>
|
||||
|
||||
<select id="sumDailyShop" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
<include refid="kpiSumShop"/>,
|
||||
COALESCE(SUM(product_cost), 0) AS productCost,
|
||||
COALESCE(SUM(freight_cost), 0) AS freightCost,
|
||||
COALESCE(SUM(other_cost), 0) AS otherCost
|
||||
FROM ec_order_stat_daily_shop
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND stat_date >= #{startDate}
|
||||
AND stat_date <= #{endDate}
|
||||
</select>
|
||||
|
||||
<select id="sumDailyShopByDay" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
stat_date AS statDate,
|
||||
<include refid="kpiSumShop"/>,
|
||||
COALESCE(SUM(product_cost), 0) AS productCost,
|
||||
COALESCE(SUM(freight_cost), 0) AS freightCost,
|
||||
COALESCE(SUM(other_cost), 0) AS otherCost
|
||||
FROM ec_order_stat_daily_shop
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND stat_date >= #{startDate}
|
||||
AND stat_date <= #{endDate}
|
||||
GROUP BY stat_date
|
||||
ORDER BY stat_date
|
||||
</select>
|
||||
|
||||
<select id="sumDailyShopByShop" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
shop_id AS shopId,
|
||||
MAX(platform_code) AS platformCode,
|
||||
<include refid="kpiSumShop"/>,
|
||||
COALESCE(SUM(product_cost), 0) AS productCost,
|
||||
COALESCE(SUM(freight_cost), 0) AS freightCost,
|
||||
COALESCE(SUM(other_cost), 0) AS otherCost
|
||||
FROM ec_order_stat_daily_shop
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND stat_date >= #{startDate}
|
||||
AND stat_date <= #{endDate}
|
||||
GROUP BY shop_id
|
||||
</select>
|
||||
|
||||
<select id="sumDailyProductByCategory" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
category_id AS categoryId,
|
||||
<include refid="kpiSumProduct"/>
|
||||
FROM ec_order_stat_daily_product
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND stat_date >= #{startDate}
|
||||
AND stat_date <= #{endDate}
|
||||
GROUP BY category_id
|
||||
</select>
|
||||
|
||||
<select id="sumDailyProductByProduct" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
product_id AS productId,
|
||||
MAX(category_id) AS categoryId,
|
||||
<include refid="kpiSumProduct"/>
|
||||
FROM ec_order_stat_daily_product
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND stat_date >= #{startDate}
|
||||
AND stat_date <= #{endDate}
|
||||
GROUP BY product_id
|
||||
</select>
|
||||
|
||||
<select id="sumDailyProductByShopProduct" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
shop_id AS shopId,
|
||||
product_id AS productId,
|
||||
MAX(category_id) AS categoryId,
|
||||
<include refid="kpiSumProduct"/>
|
||||
FROM ec_order_stat_daily_product
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND stat_date >= #{startDate}
|
||||
AND stat_date <= #{endDate}
|
||||
GROUP BY shop_id, product_id
|
||||
</select>
|
||||
|
||||
<select id="sumDailyProductForOneProduct" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
<include refid="kpiSumProduct"/>
|
||||
FROM ec_order_stat_daily_product
|
||||
WHERE company_id = #{companyId}
|
||||
AND product_id = #{productId}
|
||||
AND stat_date >= #{startDate}
|
||||
AND stat_date <= #{endDate}
|
||||
<if test="shopIds != null and shopIds.size() > 0">
|
||||
AND shop_id IN
|
||||
<foreach collection="shopIds" item="sid" open="(" separator="," close=")">#{sid}</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="sumDailyProductByDayForOneProduct" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
stat_date AS statDate,
|
||||
<include refid="kpiSumProduct"/>
|
||||
FROM ec_order_stat_daily_product
|
||||
WHERE company_id = #{companyId}
|
||||
AND product_id = #{productId}
|
||||
AND stat_date >= #{startDate}
|
||||
AND stat_date <= #{endDate}
|
||||
<if test="shopIds != null and shopIds.size() > 0">
|
||||
AND shop_id IN
|
||||
<foreach collection="shopIds" item="sid" open="(" separator="," close=")">#{sid}</foreach>
|
||||
</if>
|
||||
GROUP BY stat_date
|
||||
ORDER BY stat_date
|
||||
</select>
|
||||
|
||||
<select id="sumMonthlyProductByCategory" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
category_id AS categoryId,
|
||||
<include refid="kpiSumProduct"/>
|
||||
FROM ec_order_stat_monthly_product
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND stat_month >= #{startMonth}
|
||||
AND stat_month <= #{endMonth}
|
||||
GROUP BY category_id
|
||||
</select>
|
||||
|
||||
<select id="sumMonthlyProductByProduct" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
product_id AS productId,
|
||||
MAX(category_id) AS categoryId,
|
||||
<include refid="kpiSumProduct"/>
|
||||
FROM ec_order_stat_monthly_product
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND stat_month >= #{startMonth}
|
||||
AND stat_month <= #{endMonth}
|
||||
GROUP BY product_id
|
||||
</select>
|
||||
|
||||
<select id="sumYearlyProductByCategory" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
category_id AS categoryId,
|
||||
<include refid="kpiSumProduct"/>
|
||||
FROM ec_order_stat_yearly_product
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND stat_year >= #{startYear}
|
||||
AND stat_year <= #{endYear}
|
||||
GROUP BY category_id
|
||||
</select>
|
||||
|
||||
<select id="sumYearlyProductByProduct" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
product_id AS productId,
|
||||
MAX(category_id) AS categoryId,
|
||||
<include refid="kpiSumProduct"/>
|
||||
FROM ec_order_stat_yearly_product
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND stat_year >= #{startYear}
|
||||
AND stat_year <= #{endYear}
|
||||
GROUP BY product_id
|
||||
</select>
|
||||
|
||||
<select id="sumDailySpecBySpec" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
product_sku_id AS productSkuId,
|
||||
<include refid="kpiSumSpec"/>
|
||||
FROM ec_order_stat_daily_spec
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND product_id = #{productId}
|
||||
AND stat_date >= #{startDate}
|
||||
AND stat_date <= #{endDate}
|
||||
GROUP BY product_sku_id
|
||||
</select>
|
||||
|
||||
<select id="sumMonthlySpecBySpec" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
product_sku_id AS productSkuId,
|
||||
<include refid="kpiSumSpec"/>
|
||||
FROM ec_order_stat_monthly_spec
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND product_id = #{productId}
|
||||
AND stat_month >= #{startMonth}
|
||||
AND stat_month <= #{endMonth}
|
||||
GROUP BY product_sku_id
|
||||
</select>
|
||||
|
||||
<select id="sumYearlySpecBySpec" resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO">
|
||||
SELECT
|
||||
product_sku_id AS productSkuId,
|
||||
<include refid="kpiSumSpec"/>
|
||||
FROM ec_order_stat_yearly_spec
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND product_id = #{productId}
|
||||
AND stat_year >= #{startYear}
|
||||
AND stat_year <= #{endYear}
|
||||
GROUP BY product_sku_id
|
||||
</select>
|
||||
|
||||
<select id="countDailyShopRows" resultType="int">
|
||||
SELECT COUNT(*)
|
||||
FROM ec_order_stat_daily_shop
|
||||
WHERE <include refid="shopFilter"/>
|
||||
AND stat_date >= #{startDate}
|
||||
AND stat_date <= #{endDate}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -1,73 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.mapper.OrderStatRefreshMapper">
|
||||
|
||||
<sql id="qty">IFNULL(NULLIF(i.quantity, 0), 1)</sql>
|
||||
<sql id="lineSales">IFNULL(NULLIF(i.line_amount, 0), IFNULL(i.unit_price, 0) * <include refid="qty"/>)</sql>
|
||||
|
||||
<insert id="insertPendingIgnore">
|
||||
INSERT IGNORE INTO ec_order_stat_refresh_queue (
|
||||
company_id, shop_id, stat_date, source, status, retry_count
|
||||
) VALUES (
|
||||
#{companyId}, #{shopId}, #{statDate}, #{source}, 'pending', 0
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="markDone">
|
||||
UPDATE ec_order_stat_refresh_queue SET status = 'done', update_time = CURRENT_TIMESTAMP
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="markFailed">
|
||||
UPDATE ec_order_stat_refresh_queue
|
||||
SET status = 'failed', retry_count = #{retryCount}, update_time = CURRENT_TIMESTAMP
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="countGmvOrdersByShopDay" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*)
|
||||
FROM ec_order o
|
||||
WHERE o.company_id = #{companyId}
|
||||
AND o.shop_id = #{shopId}
|
||||
AND o.order_time >= #{start}
|
||||
AND o.order_time <= #{end}
|
||||
</select>
|
||||
|
||||
<select id="aggregateSpecByShopDay"
|
||||
resultType="top.xyquan.ecomdmbbackend.modules.ecom.order.stat.mapper.OrderStatRefreshMapper$SpecDayRow">
|
||||
SELECT
|
||||
IFNULL(i.product_id, 0) AS productId,
|
||||
IFNULL(i.product_sku_id, 0) AS productSkuId,
|
||||
SUM(CASE WHEN o.status IN
|
||||
<foreach collection="salesStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN <include refid="lineSales"/> ELSE 0 END) AS salesAmount,
|
||||
COUNT(DISTINCT CASE WHEN o.status IN
|
||||
<foreach collection="salesStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN o.id END) AS orderCount,
|
||||
SUM(CASE WHEN o.status IN
|
||||
<foreach collection="refundStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN <include refid="lineSales"/> ELSE 0 END) AS refundAmount,
|
||||
SUM(CASE WHEN o.status IN
|
||||
<foreach collection="salesStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN <include refid="qty"/> ELSE 0 END) AS salesQuantitySum,
|
||||
SUM(CASE WHEN i.line_no = 1 THEN o.pay_amount ELSE 0 END) AS gmvAmount,
|
||||
COUNT(DISTINCT o.id) AS gmvOrderCount,
|
||||
SUM(<include refid="qty"/>) AS gmvQuantitySum,
|
||||
SUM(CASE WHEN o.status IN
|
||||
<foreach collection="productCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.product_cost, 0) * <include refid="qty"/> ELSE 0 END) AS productCost,
|
||||
SUM(CASE WHEN o.status IN
|
||||
<foreach collection="freightCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.shipping_cost, 0) * <include refid="qty"/> ELSE 0 END) AS freightCost,
|
||||
SUM(CASE WHEN o.status IN
|
||||
<foreach collection="otherCostStatusCodes" item="id" open="(" separator="," close=")">#{id}</foreach>
|
||||
THEN IFNULL(i.other_cost, 0) * <include refid="qty"/> ELSE 0 END) AS otherCost
|
||||
FROM ec_order o
|
||||
INNER JOIN ec_order_item i ON i.order_id = o.id
|
||||
WHERE o.company_id = #{companyId}
|
||||
AND o.shop_id = #{shopId}
|
||||
AND o.order_time >= #{start}
|
||||
AND o.order_time <= #{end}
|
||||
GROUP BY IFNULL(i.product_sku_id, 0), IFNULL(i.product_id, 0)
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user