<?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.frequency.klkwithdrawalrecord.mapper.KlkWithdrawalRecordMapper">

    <resultMap type="com.ruoyi.frequency.klkwithdrawalrecord.entity.KlkWithdrawalRecord" id="KlkWithdrawalRecordResult">
        <result property="id"    column="id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="userId"    column="user_id"    />
        <result property="totalAmt"    column="total_amt"    />
        <result property="balanceSplitStatus"    column="balance_split_status"    />
        <result property="balanceSplitRemark"    column="balance_split_remark"    />
        <result property="acctNo"    column="acct_no"    />
        <result property="withdrawalStatus"    column="withdrawal_status"    />
        <result property="withdrawalRemark"    column="withdrawal_remark"    />
        <result property="acctOpenBankName"    column="acct_open_bank_name"    />
        <result property="acctName"    column="acct_name"    />
        <result property="transferFinishTime"    column="transfer_finish_time"    />
        <result property="withdrawalRecordId"    column="withdrawal_record_id"    />
        <association property="userInfo"    column="user_id" javaType="com.ruoyi.vo.UserInfo" resultMap="userInfo" />
    </resultMap>

    <resultMap id="userInfo" type="com.ruoyi.vo.UserInfo">
        <id     property="userId"    column="user_id"     />
        <result property="userType"  column="user_type"   />
        <result property="idNo"  column="id_no"   />
        <result property="nickname"  column="nickname"   />
        <result property="avatar" column="avatar"   />
        <result property="mobile" column="mobile"   />
    </resultMap>
    
    
    <sql id="selectKlkWithdrawalRecordVo">
        select
            t.id ,
            t.del_flag ,
            t.create_by ,
            t.create_time ,
            t.update_by ,
            t.update_time ,
            t.user_id ,
            t.total_amt ,
            t.balance_split_status ,
            t.balance_split_remark ,
            t.acct_no ,
            t.withdrawal_status ,
            t.withdrawal_remark ,
            t.acct_open_bank_name ,
            t.acct_name ,
            t.transfer_finish_time ,
            t.withdrawal_record_id ,
            u.user_type,
            u.id_no,
            u.mobile,
            u.avatar,
            u.nickname
        from t_klk_withdrawal_record AS t
                LEFT JOIN t_user AS u ON t.user_id = u.id
    </sql>

    <select id="selectKlkWithdrawalRecordList" parameterType="com.ruoyi.frequency.klkwithdrawalrecord.entity.KlkWithdrawalRecord" resultMap="KlkWithdrawalRecordResult">
        <include refid="selectKlkWithdrawalRecordVo"/>
        <where> AND t.del_flag != 2
            <if test="userId != null "> and t.user_id = #{userId}</if>
            <if test="totalAmt != null  and totalAmt != ''"> and t.total_amt = #{totalAmt}</if>
            <if test="balanceSplitStatus != null "> and t.balance_split_status = #{balanceSplitStatus}</if>
            <if test="balanceSplitRemark != null  and balanceSplitRemark != ''"> and t.balance_split_remark = #{balanceSplitRemark}</if>
            <if test="acctNo != null  and acctNo != ''"> and t.acct_no = #{acctNo}</if>
            <if test="withdrawalStatus != null "> and t.withdrawal_status = #{withdrawalStatus}</if>
            <if test="withdrawalRemark != null  and withdrawalRemark != ''"> and t.withdrawal_remark = #{withdrawalRemark}</if>
            <if test="acctOpenBankName != null  and acctOpenBankName != ''"> and t.acct_open_bank_name like concat('%', #{acctOpenBankName}, '%')</if>
            <if test="acctName != null  and acctName != ''"> and t.acct_name like concat('%', #{acctName}, '%')</if>
            <if test="transferFinishTime != null "> and t.transfer_finish_time = #{transferFinishTime}</if>
            <if test="withdrawalRecordId != null "> and t.withdrawal_record_id = #{withdrawalRecordId}</if>
            <if test="delFlag != null and delFlag != ''"> and t.del_flag = #{delFlag}</if>
        </where>
        order by t.create_time desc
    </select>

    <select id="selectKlkWithdrawalRecordById" parameterType="Long" resultMap="KlkWithdrawalRecordResult">
        <include refid="selectKlkWithdrawalRecordVo"/>
        where t.id = #{id}
    </select>

    <insert id="insertKlkWithdrawalRecord" parameterType="com.ruoyi.frequency.klkwithdrawalrecord.entity.KlkWithdrawalRecord">
        insert into t_klk_withdrawal_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="userId != null">user_id,</if>
            <if test="totalAmt != null">total_amt,</if>
            <if test="balanceSplitStatus != null">balance_split_status,</if>
            <if test="balanceSplitRemark != null">balance_split_remark,</if>
            <if test="acctNo != null">acct_no,</if>
            <if test="withdrawalStatus != null">withdrawal_status,</if>
            <if test="withdrawalRemark != null">withdrawal_remark,</if>
            <if test="acctOpenBankName != null">acct_open_bank_name,</if>
            <if test="acctName != null">acct_name,</if>
            <if test="transferFinishTime != null">transfer_finish_time,</if>
            <if test="withdrawalRecordId != null">withdrawal_record_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="userId != null">#{userId},</if>
            <if test="totalAmt != null">#{totalAmt},</if>
            <if test="balanceSplitStatus != null">#{balanceSplitStatus},</if>
            <if test="balanceSplitRemark != null">#{balanceSplitRemark},</if>
            <if test="acctNo != null">#{acctNo},</if>
            <if test="withdrawalStatus != null">#{withdrawalStatus},</if>
            <if test="withdrawalRemark != null">#{withdrawalRemark},</if>
            <if test="acctOpenBankName != null">#{acctOpenBankName},</if>
            <if test="acctName != null">#{acctName},</if>
            <if test="transferFinishTime != null">#{transferFinishTime},</if>
            <if test="withdrawalRecordId != null">#{withdrawalRecordId},</if>
        </trim>
    </insert>

    <update id="updateKlkWithdrawalRecord" parameterType="com.ruoyi.frequency.klkwithdrawalrecord.entity.KlkWithdrawalRecord">
        update t_klk_withdrawal_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="totalAmt != null">total_amt = #{totalAmt},</if>
            <if test="balanceSplitStatus != null">balance_split_status = #{balanceSplitStatus},</if>
            <if test="balanceSplitRemark != null">balance_split_remark = #{balanceSplitRemark},</if>
            <if test="acctNo != null">acct_no = #{acctNo},</if>
            <if test="withdrawalStatus != null">withdrawal_status = #{withdrawalStatus},</if>
            <if test="withdrawalRemark != null">withdrawal_remark = #{withdrawalRemark},</if>
            <if test="acctOpenBankName != null">acct_open_bank_name = #{acctOpenBankName},</if>
            <if test="acctName != null">acct_name = #{acctName},</if>
            <if test="transferFinishTime != null">transfer_finish_time = #{transferFinishTime},</if>
            <if test="withdrawalRecordId != null">withdrawal_record_id = #{withdrawalRecordId},</if>
        </trim>
        where id = #{id}
    </update>
                                                                                                                        </mapper>