<?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.cyksj.mapper.manage.coupon.CouponDistributePopularizeMapper">

    <insert id="batchInsert">
        insert into coupon_distribute_popularize(`coupon_id`,`distribute_id`,`ex_code`,`created_time`,`update_time`)
        values
        <foreach collection="list" item="item" separator=",">
            (#{item.couponId},#{item.distributeId},#{item.exCode},now(),now())
        </foreach>
    </insert>

    <select id="getCouponCodeByUid" resultType="java.lang.String">
        select group_concat(cp.ex_code)
        from (select id from user_distribute ud where user_id = #{userId} and deleted is true limit 1) s
        inner join coupon_distribute_popularize cp on cp.distribute_id = s.id
        and cp.deleted is true and cp.is_general is false
        <if test="couponId != null">
            and cp.coupon_id = #{couponId}
        </if>
    </select>
</mapper>