<?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.yiqi.app.mapper.AppCouponTypeMapper">

    <resultMap type="AppCouponType" id="AppCouponTypeResult">
        <result property="id" column="id"/>
        <result property="title" column="title"/>
        <result property="description" column="description"/>
        <result property="discountWay" column="discount_way"/>
        <result property="imgUrl" column="img_url"/>
        <result property="startDate" column="start_date"/>
        <result property="endDate" column="end_date"/>
        <result property="status" column="status"/>
        <result property="isUnique" column="is_unique"/>
        <result property="canManual" column="can_manual"/>
        <result property="minAmount" column="min_amount"/>
        <result property="deductAmount" column="deduct_amount"/>
        <result property="couponTypeThirdPartyId" column="coupon_type_third_party_id"/>
        <result property="canDeductRecharge" column="can_deduct_recharge"/>
        <result property="deductRechargeAmount" column="deduct_recharge_amount"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createById" column="create_by_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateById" column="update_by_id"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectAppCouponTypeVo">
        select *
        from app_coupon_type
    </sql>

    <select id="selectAppCouponTypeList" parameterType="AppCouponType" resultMap="AppCouponTypeResult">
        <include refid="selectAppCouponTypeVo"/>
        <where>
            and del_flag='0'
            <if test="title != null  and title != ''">
                and title = #{title}
            </if>
            <if test="startDate != null ">
                and start_date = #{startDate}
            </if>
            <if test="endDate != null ">
                and end_date = #{endDate}
            </if>
            <if test="discountWay != null ">
                and discount_way = #{discountWay}
            </if>
            <if test="couponTypeThirdPartyId != null ">
                and coupon_type_third_party_id = #{couponTypeThirdPartyId}
            </if>
        </where>
        order by id desc
    </select>

    <select id="selectAppCouponTypeById" parameterType="Long"
            resultMap="AppCouponTypeResult">
        <include refid="selectAppCouponTypeVo"/>
        where id = #{id}
        and del_flag='0'
    </select>

    <insert id="insertAppCouponType" parameterType="AppCouponType" useGeneratedKeys="true"
            keyProperty="id">
        insert into app_coupon_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,
            </if>
            <if test="description != null">description,
            </if>
            <if test="imgUrl != null">img_url,
            </if>
            <if test="startDate != null">start_date,
            </if>
            <if test="endDate != null">end_date,
            </if>
            <if test="status != null">status,
            </if>
            <if test="isUnique != null">is_unique,
            </if>
            <if test="canManual != null">can_manual,
            </if>
            <if test="minAmount != null">min_amount,
            </if>
            <if test="deductAmount != null">deduct_amount,
            </if>
            <if test="canDeductRecharge != null">can_deduct_recharge,
            </if>
            <if test="couponTypeThirdPartyId != null">coupon_type_third_party_id,
            </if>
            <if test="deductRechargeAmount != null">deduct_recharge_amount,
            </if>
            <if test="delFlag != null">del_flag,
            </if>
            <if test="createById != null">create_by_id,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateById != null">update_by_id,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
            <if test="remark != null">remark,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null">#{title},
            </if>
            <if test="description != null">#{description},
            </if>
            <if test="imgUrl != null">#{imgUrl},
            </if>
            <if test="startDate != null">#{startDate},
            </if>
            <if test="endDate != null">#{endDate},
            </if>
            <if test="status != null">#{status},
            </if>
            <if test="isUnique != null">#{isUnique},
            </if>
            <if test="canManual != null">#{canManual},
            </if>
            <if test="minAmount != null">#{minAmount},
            </if>
            <if test="deductAmount != null">#{deductAmount},
            </if>
            <if test="canDeductRecharge != null">#{canDeductRecharge},
            </if>
            <if test="couponTypeThirdPartyId != null">#{couponTypeThirdPartyId},
            </if>
            <if test="deductRechargeAmount != null">#{deductRechargeAmount},
            </if>
            <if test="delFlag != null">#{delFlag},
            </if>
            <if test="createById != null">#{createById},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateById != null">#{updateById},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
            <if test="remark != null">#{remark},
            </if>
        </trim>
    </insert>

    <update id="updateAppCouponType" parameterType="AppCouponType">
        update app_coupon_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title =
                #{title},
            </if>
            <if test="description != null">description =
                #{description},
            </if>
            <if test="discountWay != null">discount_way =
                #{discountWay},
            </if>
            <if test="imgUrl != null">img_url =
                #{imgUrl},
            </if>
            <if test="startDate != null">start_date =
                #{startDate},
            </if>
            <if test="endDate != null">end_date =
                #{endDate},
            </if>
            <if test="status != null">status =
                #{status},
            </if>
            <if test="couponTypeThirdPartyId != null and couponTypeThirdPartyId != ''" >coupon_type_third_party_id =
                #{couponTypeThirdPartyId},
            </if>
            <if test="couponTypeThirdPartyId == null" >coupon_type_third_party_id = NULL,
            </if>
            <if test="isUnique != null">is_unique =
                #{isUnique},
            </if>
            <if test="canManual != null">can_manual =
                #{canManual},
            </if>
            <if test="minAmount != null">min_amount =
                #{minAmount},
            </if>
            <if test="deductAmount != null">deduct_amount =
                #{deductAmount},
            </if>
            <if test="canDeductRecharge != null">can_deduct_recharge =
                #{canDeductRecharge},
            </if>
            <if test="deductRechargeAmount != null">deduct_recharge_amount =
                #{deductRechargeAmount},
            </if>
            <if test="delFlag != null">del_flag =
                #{delFlag},
            </if>
            <if test="createById != null">create_by_id =
                #{createById},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateById != null">update_by_id =
                #{updateById},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAppCouponTypeById" parameterType="Long">
            update app_coupon_type set del_flag='2' where id = #{id}
        </delete>

    <delete id="deleteAppCouponTypeByIds" parameterType="String">
        update app_coupon_type set del_flag='2' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>



</mapper>