<?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.ruixuan.jinniu.mapper.KuaishouTransferAccountMapper">

    <resultMap type="com.ruixuan.jinniu.entity.KuaishouTransferAccount" id="KuaishouTransferAccountResult">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="accountId" column="account_id"/>
        <result property="projectId" column="project_id"/>
        <result property="transferor" column="transferor"/>
        <result property="assignee" column="assignee"/>
        <result property="transferorDate" column="transferor_date"/>
        <result property="assigneeDate" column="assignee_date"/>
        <result property="auditor" column="auditor"/>
        <result property="status" column="status"/>
        <result property="remarks" column="remarks"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectKuaishouTransferAccountVo">
        select id,
               user_id,
               account_id,
               project_id,
               transferor,
               assignee,
               transferor_date,
               assignee_date,
               auditor,
               status,
               remarks,
               create_time,
               update_time
        from kuaishou_transfer_account
    </sql>

    <select id="selectKuaishouTransferAccountList" resultType="com.alibaba.fastjson.JSONObject">
        select t1.id,
        t1.account_id as'accountId',
        t4.account_name as'accountName',
        t1.project_id as'projectId',
        t4.project_name as'projectName',
        t1.transferor as'transferorId',
        t3.nick_name as'transferorName',
        t1.assignee as'assigneeId',
        t2.nick_name as'assigneeName',
        t1.transferor_date as'transferorDate',
        t1.assignee_date as'assigneeDate',
        t1.auditor as'auditorId',
        t5.nick_name as'auditorName',
        t1.status,
        t1.remarks
        from kuaishou_transfer_account t1
        LEFT JOIN sys_user t2 on t1.assignee = t2.user_id
        LEFT JOIN sys_user t3 on t1.transferor = t3.user_id
        LEFT JOIN sys_user t5 on t1.auditor = t5.user_id
        LEFT JOIN kuaishou_account t4 ON t1.account_id = t4.account_id
        <where>
            <if test="userList != null ">and t1.transferor in
                <foreach collection="userList" item="userId" open="(" separator="," close=")">
                    #{userId}
                </foreach>
            </if>
            <if test="status != null ">and t1.status = #{status}</if>
            <if test="auditor != null  and auditor != ''">and t1.auditor = #{auditor}</if>
            <if test="assignee != null ">and t1.assignee = #{assignee}</if>
            <if test="transferor != null ">and t1.transferor = #{transferor}</if>
            <if test="accountId != null ">and t1.account_id = #{accountId}</if>
            <if test="accountName != null  and accountName != ''">
                and t4.account_name like concat('%', #{accountName}, '%')
            </if>
            <if test="projectName != null  and projectName != ''">
                and t4.project_name like concat('%', #{projectName}, '%')
            </if>
            <if test="projectId != null ">and t1.project_id = #{projectId}</if>
            <if test="transferorDate != null  and transferorDate != ''">and t1.transferor_date = #{transferorDate}</if>
            <if test="assigneeDate != null  and assigneeDate != ''">and t1.assignee_date = #{assigneeDate}</if>
        </where>

    </select>

    <select id="selectKuaishouTransferAccountById" parameterType="Long" resultMap="KuaishouTransferAccountResult">
        <include refid="selectKuaishouTransferAccountVo"/>
        where id = #{id}
    </select>

    <insert id="insertKuaishouTransferAccount" parameterType="com.ruixuan.jinniu.entity.KuaishouTransferAccount"
            useGeneratedKeys="true"
            keyProperty="id">
        insert into kuaishou_transfer_account
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="accountId != null">account_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="transferor != null">transferor,</if>
            <if test="assignee != null">assignee,</if>
            <if test="transferorDate != null">transferor_date,</if>
            <if test="assigneeDate != null">assignee_date,</if>
            <if test="auditor != null">auditor,</if>
            <if test="status != null">status,</if>
            <if test="remarks != null">remarks,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="accountId != null">#{accountId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="transferor != null">#{transferor},</if>
            <if test="assignee != null">#{assignee},</if>
            <if test="transferorDate != null">#{transferorDate},</if>
            <if test="assigneeDate != null">#{assigneeDate},</if>
            <if test="auditor != null">#{auditor},</if>
            <if test="status != null">#{status},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateKuaishouTransferAccount" parameterType="com.ruixuan.jinniu.entity.KuaishouTransferAccount">
        update kuaishou_transfer_account
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="accountId != null">account_id = #{accountId},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="transferor != null">transferor = #{transferor},</if>
            <if test="assignee != null">assignee = #{assignee},</if>
            <if test="transferorDate != null">transferor_date = #{transferorDate},</if>
            <if test="assigneeDate != null">assignee_date = #{assigneeDate},</if>
            <if test="auditor != null">auditor = #{auditor},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKuaishouTransferAccountById" parameterType="Long">
        delete
        from kuaishou_transfer_account
        where id = #{id}
    </delete>
</mapper>