Files
ecom-dmb/ecom-dmb-backend/src/main/resources/mapper/order/stat/FeeStatDailyMapper.xml
T

95 lines
4.4 KiB
XML

<?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 &gt;= #{statMonth}
AND stat_date &lt; 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 &gt;= #{statMonth}
AND stat_date &lt; 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>