82 lines
4.1 KiB
XML
82 lines
4.1 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="com.imyeyu.api.modules.gao.mapper.GaoPointRedemptionMapper">
|
|
<select id="selectByStoreIdAndRequestNo" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemption">
|
|
SELECT * FROM `gao_point_redemption`
|
|
WHERE `store_id` = #{storeId} AND `request_no` = #{requestNo} AND `deleted_at` IS NULL
|
|
LIMIT 1
|
|
</select>
|
|
<select id="selectByStoreIdAndId" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemption">
|
|
SELECT * FROM `gao_point_redemption`
|
|
WHERE `store_id` = #{storeId} AND `id` = #{id} AND `deleted_at` IS NULL
|
|
LIMIT 1
|
|
</select>
|
|
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemption">
|
|
SELECT * FROM `gao_point_redemption`
|
|
WHERE `id` = #{id} AND `deleted_at` IS NULL
|
|
LIMIT 1
|
|
FOR UPDATE
|
|
</select>
|
|
<sql id="queryWhere">
|
|
`r`.`deleted_at` IS NULL
|
|
<if test="storeId != null and storeId != ''">AND `r`.`store_id` = #{storeId}</if>
|
|
<if test="customerId != null and customerId != ''">AND `r`.`customer_id` = #{customerId}</if>
|
|
<if test="redeemSkuId != null and redeemSkuId != ''">AND `r`.`redeem_sku_id_snapshot` = #{redeemSkuId}</if>
|
|
<if test="skuIdSnapshot != null and skuIdSnapshot != ''">AND `r`.`sku_id_snapshot` = #{skuIdSnapshot}</if>
|
|
<if test="status != null">AND `r`.`status` = #{status}</if>
|
|
<if test="keyword != null and keyword.trim() != ''">
|
|
AND (`r`.`product_name_snapshot` LIKE CONCAT('%', #{keyword}, '%')
|
|
OR `r`.`sku_code_snapshot` LIKE CONCAT('%', #{keyword}, '%')
|
|
OR `r`.`sku_name_snapshot` LIKE CONCAT('%', #{keyword}, '%')
|
|
OR `c`.`code` LIKE CONCAT('%', #{keyword}, '%')
|
|
OR `c`.`name` LIKE CONCAT('%', #{keyword}, '%')
|
|
OR `c`.`telephone` LIKE CONCAT('%', #{keyword}, '%')
|
|
OR `c`.`name_pinyin_full` LIKE CONCAT(#{keyword}, '%')
|
|
OR `c`.`name_pinyin_initial` LIKE CONCAT(#{keyword}, '%')
|
|
OR `c`.`name_pinyin_mixed` LIKE CONCAT(#{keyword}, '%'))
|
|
</if>
|
|
<if test="beginAt != null">AND `r`.`redeemed_at` >= #{beginAt}</if>
|
|
<if test="endAt != null">AND `r`.`redeemed_at` <= #{endAt}</if>
|
|
</sql>
|
|
<select id="countByQuery" resultType="long">
|
|
SELECT COUNT(1)
|
|
FROM `gao_point_redemption` `r`
|
|
LEFT JOIN `gao_customer` `c` ON `c`.`id` = `r`.`customer_id`
|
|
WHERE <include refid="queryWhere"/>
|
|
</select>
|
|
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemption">
|
|
SELECT `r`.*
|
|
FROM `gao_point_redemption` `r`
|
|
LEFT JOIN `gao_customer` `c` ON `c`.`id` = `r`.`customer_id`
|
|
WHERE <include refid="queryWhere"/>
|
|
ORDER BY `r`.`redeemed_at` DESC, `r`.`created_at` DESC, `r`.`id` DESC
|
|
LIMIT #{offset}, #{limit}
|
|
</select>
|
|
<select id="sumValidQuantity" resultType="java.math.BigDecimal">
|
|
SELECT COALESCE(SUM(`quantity` - `returned_quantity`), 0)
|
|
FROM `gao_point_redemption`
|
|
WHERE `store_id` = #{storeId}
|
|
AND `customer_id` = #{customerId}
|
|
AND `sku_id_snapshot` = #{skuId}
|
|
AND `status` IN ('COMPLETED', 'PARTIALLY_RETURNED')
|
|
AND `deleted_at` IS NULL
|
|
<if test="beginAt != null">AND `redeemed_at` >= #{beginAt}</if>
|
|
<if test="endAt != null">AND `redeemed_at` <= #{endAt}</if>
|
|
</select>
|
|
<select id="selectSkuSummaryByStoreIdAndSkuId" resultType="com.imyeyu.api.modules.gao.vo.GaoPointRedeemSkuPageResult">
|
|
SELECT COALESCE(SUM(`r`.`base_quantity`), 0) AS `redeemed_base_quantity_total`,
|
|
COALESCE(SUM(`return_summary`.`base_quantity_total`), 0) AS `returned_base_quantity_total`,
|
|
COALESCE(SUM(`r`.`base_quantity` - COALESCE(`return_summary`.`base_quantity_total`, 0)), 0) AS `net_redeemed_base_quantity_total`
|
|
FROM `gao_point_redemption` `r`
|
|
LEFT JOIN (
|
|
SELECT `redemption_id`, SUM(`base_quantity`) AS `base_quantity_total`
|
|
FROM `gao_point_redemption_return`
|
|
WHERE `deleted_at` IS NULL
|
|
GROUP BY `redemption_id`
|
|
) `return_summary` ON `return_summary`.`redemption_id` = `r`.`id`
|
|
WHERE `r`.`deleted_at` IS NULL
|
|
AND `r`.`sku_id_snapshot` = #{skuId}
|
|
<if test="storeId != null and storeId != ''">AND `r`.`store_id` = #{storeId}</if>
|
|
</select>
|
|
</mapper>
|