package com.talentcard.server.mapper;
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.talentcard.server.entity.MerchantCouponManagement;
|
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Update;
|
|
import java.time.LocalDate;
|
import java.util.List;
|
import java.util.Map;
|
|
@Mapper
|
public interface MerchantCouponManagementMapper extends BaseMapper<MerchantCouponManagement> {
|
@Select("""
|
<script>
|
select c.*, m.merchant_name as merchantName,
|
(select count(*) from merchant_coupon_claim cc where cc.coupon_id = c.id and cc.deleted = 0) as claimRecordCount,
|
(select count(*) from merchant_coupon_claim cc where cc.coupon_id = c.id and cc.deleted = 0 and cc.claim_status = 1 and cc.use_status = 0) as unusedCount,
|
(select count(*) from merchant_coupon_claim cc where cc.coupon_id = c.id and cc.deleted = 0 and cc.use_status = 1) as usedCount,
|
(select count(*) from merchant_coupon_claim cc where cc.coupon_id = c.id and cc.deleted = 0 and cc.use_status = 2) as expiredCount,
|
(select count(*) from merchant_coupon_claim cc where cc.coupon_id = c.id and cc.deleted = 0 and cc.use_status = 3) as invalidCount
|
from merchant_coupon c
|
join merchant m on m.id = c.merchant_id and m.deleted = 0
|
where c.deleted = 0
|
<if test="merchantId != null">and c.merchant_id = #{merchantId}</if>
|
<if test="couponType != null and couponType != ''">and c.coupon_type = #{couponType}</if>
|
<if test="batchNo != null and batchNo != ''">and c.batch_no = #{batchNo}</if>
|
<if test="status != null">and c.status = #{status}</if>
|
<if test="keyword != null and keyword != ''">and (c.coupon_name like concat('%', #{keyword}, '%') or m.merchant_name like concat('%', #{keyword}, '%'))</if>
|
<if test="validOn != null">and (c.valid_start is null or c.valid_start <= #{validOn}) and (c.valid_end is null or c.valid_end >= #{validOn})</if>
|
order by c.created_at desc, c.id desc
|
limit #{size} offset #{offset}
|
</script>
|
""")
|
List<Map<String, Object>> selectManagementPage(@Param("merchantId") Long merchantId,
|
@Param("couponType") String couponType,
|
@Param("batchNo") String batchNo,
|
@Param("status") Integer status,
|
@Param("keyword") String keyword,
|
@Param("validOn") LocalDate validOn,
|
@Param("size") int size,
|
@Param("offset") int offset);
|
|
@Select("""
|
<script>
|
select count(*) from merchant_coupon c
|
join merchant m on m.id = c.merchant_id and m.deleted = 0
|
where c.deleted = 0
|
<if test="merchantId != null">and c.merchant_id = #{merchantId}</if>
|
<if test="couponType != null and couponType != ''">and c.coupon_type = #{couponType}</if>
|
<if test="batchNo != null and batchNo != ''">and c.batch_no = #{batchNo}</if>
|
<if test="status != null">and c.status = #{status}</if>
|
<if test="keyword != null and keyword != ''">and (c.coupon_name like concat('%', #{keyword}, '%') or m.merchant_name like concat('%', #{keyword}, '%'))</if>
|
<if test="validOn != null">and (c.valid_start is null or c.valid_start <= #{validOn}) and (c.valid_end is null or c.valid_end >= #{validOn})</if>
|
</script>
|
""")
|
Long countManagementPage(@Param("merchantId") Long merchantId,
|
@Param("couponType") String couponType,
|
@Param("batchNo") String batchNo,
|
@Param("status") Integer status,
|
@Param("keyword") String keyword,
|
@Param("validOn") LocalDate validOn);
|
|
@Select("select count(*) from merchant where id = #{merchantId} and deleted = 0")
|
Long countMerchant(@Param("merchantId") Long merchantId);
|
|
@Update("""
|
update merchant_coupon
|
set claimed_quantity = claimed_quantity + 1
|
where id = #{couponId} and deleted = 0 and status = 1
|
and (total_quantity = -1 or claimed_quantity < total_quantity)
|
""")
|
int reserveOne(@Param("couponId") Long couponId);
|
|
@Update("update merchant_coupon set claimed_quantity = greatest(claimed_quantity - 1, 0) where id = #{couponId} and deleted = 0")
|
int releaseOne(@Param("couponId") Long couponId);
|
|
@Select("select count(*) from talent_user where id = #{talentId} and deleted = 0")
|
Long countTalent(@Param("talentId") Long talentId);
|
|
@Select("select count(*) from talent_card where id = #{cardId} and talent_id = #{talentId} and deleted = 0")
|
Long countTalentCard(@Param("cardId") Long cardId, @Param("talentId") Long talentId);}
|