<?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="cn.iocoder.yudao.module.shop.mapper.ShopCouponTemplateMapper">

    <resultMap type="cn.iocoder.yudao.module.shop.entity.ShopCouponTemplate" id="ShopCouponTemplateResult">
        <result property="id"    column="id"    />
        <result property="couponType"    column="coupon_type"    />
        <result property="allPlatform"    column="all_platform"    />
        <result property="partnerId"    column="partner_id"    />
        <result property="title"    column="title"    />
        <result property="bindMoudle"    column="bind_moudle"    />
        <result property="bindGoodsIds"    column="bind_goods_ids"    />
        <result property="bindPartnerId"    column="bind_partner_id"    />
        <result property="discount"    column="discount"    />
        <result property="effectiveDay"    column="effective_day"    />
        <result property="startTime"    column="start_time"    />
        <result property="expirationTime"    column="expiration_time"    />
        <result property="eventsStartTime"    column="events_start_time"    />
        <result property="eventsEndTime"    column="events_end_time"    />
        <result property="roleKey"    column="role_key"    />
        <result property="creator"    column="creator"    />
        <result property="createTime"    column="create_time"    />
        <result property="updater"    column="updater"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectShopCouponTemplateVo">
        select id, coupon_type, all_platform, partner_id, title, bind_moudle, bind_goods_ids, bind_partner_id, discount, effective_day, start_time, expiration_time, events_start_time, events_end_time, role_key, creator, create_time, updater, update_time from shop_coupon_template
    </sql>

    <select id="selectShopCouponTemplateList" parameterType="cn.iocoder.yudao.module.shop.entity.ShopCouponTemplate" resultMap="ShopCouponTemplateResult">
        <include refid="selectShopCouponTemplateVo"/>
        <where>
            <if test="vo.title != null  and title != ''"> and title = #{vo.title}</if>
            <if test="vo.discount != null "> and discount = #{vo.discount}</if>
            <if test="vo.effectiveDay != null "> and effective_day = #{vo.effectiveDay}</if>
            <if test="vo.startTime != null "> and start_time = #{vo.startTime}</if>
            <if test="vo.expirationTime != null "> and expiration_time = #{vo.expirationTime}</if>
            <if test="vo.eventsStartTime != null "> and events_start_time = #{vo.eventsStartTime}</if>
            <if test="vo.eventsEndTime != null "> and events_end_time = #{vo.eventsEndTime}</if>
        </where>
    </select>

    <select id="selectShopCouponTemplateById" parameterType="Long" resultMap="ShopCouponTemplateResult">
        <include refid="selectShopCouponTemplateVo"/>
        where id = #{id}
    </select>
    <select id="listCoupon" resultType="cn.iocoder.yudao.module.shop.entity.ShopCouponTemplate">
        select  template.*,goods.title as bindGoodsName  from shop_coupon_template template
        left join shop_inspection_goods goods on goods.id = template.bind_goods_ids
        where template.partner_id = #{partnerId} and bind_moudle = '检测项目现金券'
        <if test="searchValue!=null and searchValue!=''">
            and title like concat('%',#{searchValue},'%')
        </if>
        order by create_time desc
    </select>

    <insert id="insertShopCouponTemplate" parameterType="cn.iocoder.yudao.module.shop.entity.ShopCouponTemplate">
        insert into shop_coupon_template
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="couponType != null">coupon_type,</if>
            <if test="allPlatform != null">all_platform,</if>
            <if test="partnerId != null">partner_id,</if>
            <if test="title != null">title,</if>
            <if test="bindMoudle != null">bind_moudle,</if>
            <if test="bindGoodsIds != null">bind_goods_ids,</if>
            <if test="bindPartnerId != null">bind_partner_id,</if>
            <if test="discount != null">discount,</if>
            <if test="effectiveDay != null">effective_day,</if>
            <if test="startTime != null">start_time,</if>
            <if test="expirationTime != null">expiration_time,</if>
            <if test="eventsStartTime != null">events_start_time,</if>
            <if test="eventsEndTime != null">events_end_time,</if>
            <if test="roleKey != null">role_key,</if>
            <if test="creator != null">creator,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updater != null">updater,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="couponType != null">#{couponType},</if>
            <if test="allPlatform != null">#{allPlatform},</if>
            <if test="partnerId != null">#{partnerId},</if>
            <if test="title != null">#{title},</if>
            <if test="bindMoudle != null">#{bindMoudle},</if>
            <if test="bindGoodsIds != null">#{bindGoodsIds},</if>
            <if test="bindPartnerId != null">#{bindPartnerId},</if>
            <if test="discount != null">#{discount},</if>
            <if test="effectiveDay != null">#{effectiveDay},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="expirationTime != null">#{expirationTime},</if>
            <if test="eventsStartTime != null">#{eventsStartTime},</if>
            <if test="eventsEndTime != null">#{eventsEndTime},</if>
            <if test="roleKey != null">#{roleKey},</if>
            <if test="creator != null">#{creator},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updater != null">#{updater},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateShopCouponTemplate" parameterType="cn.iocoder.yudao.module.shop.entity.ShopCouponTemplate">
        update shop_coupon_template
        <trim prefix="SET" suffixOverrides=",">
            <if test="couponType != null">coupon_type = #{couponType},</if>
            <if test="allPlatform != null">all_platform = #{allPlatform},</if>
            <if test="partnerId != null">partner_id = #{partnerId},</if>
            <if test="title != null">title = #{title},</if>
            <if test="bindMoudle != null">bind_moudle = #{bindMoudle},</if>
            <if test="bindGoodsIds != null">bind_goods_ids = #{bindGoodsIds},</if>
            <if test="bindPartnerId != null">bind_partner_id = #{bindPartnerId},</if>
            <if test="discount != null">discount = #{discount},</if>
            <if test="effectiveDay != null">effective_day = #{effectiveDay},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="expirationTime != null">expiration_time = #{expirationTime},</if>
            <if test="eventsStartTime != null">events_start_time = #{eventsStartTime},</if>
            <if test="eventsEndTime != null">events_end_time = #{eventsEndTime},</if>
            <if test="roleKey != null">role_key = #{roleKey},</if>
            <if test="creator != null">creator = #{creator},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updater != null">updater = #{updater},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteShopCouponTemplateById" parameterType="Long">
        delete from shop_coupon_template where id = #{id}
    </delete>

    <delete id="deleteShopCouponTemplateByIds" parameterType="String">
        delete from shop_coupon_template where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
