<?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.ruoyi.ss.userWithdraw.mapper.UserWithdrawMapper">

    <resultMap type="UserWithdrawVO" id="RlUserWithdrawResult" autoMapping="true" >
        <result property="withdrawHandlingCharge" column="withdraw_handling_charge" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
    </resultMap>

    <sql id="selectRlUserWithdrawVo">
        select
           uw.user_channel_id,
           uw.user_id,
           u.user_name,
           uw.channel_id,
           uw.name,
           uw.handling_charge_type,
           uw.withdraw_handling_charge,
           uw.min_amount,
           uw.max_amount,
           uw.create_time,
           uw.is_open,
           uw.picture,
           uw.collection_code,
           uw.is_need_code,
           uw.type,
           uw.is_auto
        from ss_user_withdraw uw
        left join ss_user u on u.user_id = uw.user_id
    </sql>

    <select id="selectRlUserWithdrawList" parameterType="UserWithdrawQuery" resultMap="RlUserWithdrawResult">
        <include refid="selectRlUserWithdrawVo"/>
        <where>
            <if test="userId != null "> and uw.user_id = #{userId}</if>
            <if test="channelId != null "> and uw.channel_id = #{channelId}</if>
            <if test="name != null  and name != ''"> and uw.name like concat('%', #{name}, '%')</if>
            <if test="userName != null  and userName != ''"> and u.user_name like concat('%', #{userName}, '%')</if>
            <if test="handlingChargeType != null  and handlingChargeType != ''"> and uw.handling_charge_type = #{handlingChargeType}</if>
            <if test="withdrawHandlingCharge != null "> and uw.withdraw_handling_charge = #{withdrawHandlingCharge}</if>
            <if test="minAmount != null "> and uw.min_amount = #{minAmount}</if>
            <if test="maxAmount != null "> and uw.max_amount = #{maxAmount}</if>
            <if test="isOpen != null  and isOpen != ''"> and uw.is_open = #{isOpen}</if>
            <if test="isAuto != null  and isAuto != ''"> and uw.is_auto = #{isAuto}</if>
            <if test="isNeedCode != null  and isNeedCode != ''"> and uw.is_need_code = #{isNeedCode}</if>
            <if test="type != null  and type != ''"> and uw.type = #{type}</if>
        </where>
    </select>

    <select id="selectRlUserWithdrawByUserChannelId" parameterType="Long" resultMap="RlUserWithdrawResult">
        <include refid="selectRlUserWithdrawVo"/>
        where uw.user_channel_id = #{userChannelId}
    </select>

    <select id="selectRlUserWithdrawListByUserId" parameterType="Long" resultMap="RlUserWithdrawResult">
        <include refid="selectRlUserWithdrawVo"/>
        where uw.user_id = #{userId}
        and uw.is_open = true
    </select>

    <insert id="insertRlUserWithdraw" parameterType="UserWithdraw">
        insert into ss_user_withdraw
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userChannelId != null">user_channel_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="channelId != null">channel_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="handlingChargeType != null">handling_charge_type,</if>
            <if test="withdrawHandlingCharge != null">withdraw_handling_charge,</if>
            <if test="minAmount != null">min_amount,</if>
            <if test="maxAmount != null">max_amount,</if>
            <if test="createTime != null">create_time,</if>
            <if test="isOpen != null">is_open,</if>
            <if test="picture != null">picture,</if>
            <if test="collectionCode != null">collection_code,</if>
            <if test="isNeedCode != null">is_need_code,</if>
            <if test="type != null">type,</if>
            <if test="isAuto != null">is_auto,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userChannelId != null">#{userChannelId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="channelId != null">#{channelId},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="handlingChargeType != null">#{handlingChargeType},</if>
            <if test="withdrawHandlingCharge != null">#{withdrawHandlingCharge},</if>
            <if test="minAmount != null">#{minAmount},</if>
            <if test="maxAmount != null">#{maxAmount},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="isOpen != null">#{isOpen},</if>
            <if test="picture != null">#{picture},</if>
            <if test="collectionCode != null">#{collectionCode},</if>
            <if test="isNeedCode != null">#{isNeedCode},</if>
            <if test="type != null">#{type},</if>
            <if test="isAuto != null">#{isAuto},</if>
         </trim>
    </insert>

    <update id="updateRlUserWithdraw" parameterType="UserWithdraw">
        update ss_user_withdraw
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="channelId != null">channel_id = #{channelId},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="handlingChargeType != null">handling_charge_type = #{handlingChargeType},</if>
            <if test="withdrawHandlingCharge != null">withdraw_handling_charge = #{withdrawHandlingCharge},</if>
            <if test="minAmount != null">min_amount = #{minAmount},</if>
            <if test="maxAmount != null">max_amount = #{maxAmount},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="isOpen != null">is_open = #{isOpen},</if>
            <if test="picture != null">picture = #{picture},</if>
            <if test="collectionCode != null">collection_code = #{collectionCode},</if>
            <if test="isNeedCode != null">is_need_code = #{isNeedCode},</if>
            <if test="type != null">type = #{type},</if>
            <if test="isAuto != null">is_auto = #{isAuto},</if>
        </trim>
        where user_channel_id = #{userChannelId}
    </update>

    <delete id="deleteRlUserWithdrawByUserChannelId" parameterType="Long">
        delete from ss_user_withdraw where user_channel_id = #{userChannelId}
    </delete>

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