<?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.ycwl.basic.mapper.CouponMapper">
    <update id="updateStatus">
        UPDATE coupon
        SET status = IF(status = 1, 0, 1)
        WHERE id = #{id}
    </update>
    <select id="selectByQuery" resultType="com.ycwl.basic.model.pc.coupon.resp.CouponRespVO">
        SELECT
        c.id, scenic_id AS scenicId, s.name as scenicName,
        c.name AS name,
        config_ids AS configIds, discount_price AS discountPrice,
        type, discount_type AS discountType,
        c.status, c.create_at
        FROM coupon c
        LEFT JOIN scenic s ON c.scenic_id = s.id
        <where>
            <if test="scenicId != null">AND scenic_id = #{scenicId}</if>
            <if test="name != null and name != ''">AND c.name = concat('%',#{name},'%')</if>
            <if test="type != null">AND type = #{type}</if>
            <if test="discountType != null">AND discount_type = #{discountType}</if>
            <if test="status != null">AND c.status = #{status}</if>
            <if test="createAtStart != null">AND create_time >= #{createAtStart}</if>
            <if test="createAtEnd != null">AND create_time &lt;= #{createAtEnd}
            </if>
        </where>
        ORDER BY create_time DESC
    </select>
    <select id="getById" resultType="com.ycwl.basic.model.pc.coupon.entity.CouponEntity">
        select * from coupon where id = #{id}
    </select>
</mapper>