<?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.oa.mapper.CmcTransferMapper">
    
    <resultMap type="CmcTransfer" id="CmcTransferResult">
        <result property="transferId"    column="transfer_id"    />
        <result property="applier"    column="applier"    />
        <result property="applyDate"    column="apply_date"    />
        <result property="beforeDeptId"    column="before_dept_id"    />
        <result property="beforePostId"    column="before_post_id"    />
        <result property="afterDeptId"    column="after_dept_id"    />
        <result property="afterPostId"    column="after_post_id"    />
        <result property="beforeDeptComment"    column="before_dept_comment"    />
        <result property="beforeDeptLeader"    column="before_dept_leader"    />
        <result property="beforeDeptTime"    column="before_dept_time"    />
        <result property="afterDeptComment"    column="after_dept_comment"    />
        <result property="afterDeptTime"    column="after_dept_time"    />
        <result property="afterDeptLeader"    column="after_dept_leader"    />
        <result property="zhComment"    column="zh_comment"    />
        <result property="zhTime"    column="zh_time"    />
        <result property="zhUserId"    column="zh_user_id"    />
        <result property="managerComment"    column="manager_comment"    />
        <result property="managerTime"    column="manager_time"    />
        <result property="managerUserId"    column="manager_user_id"    />
        <result property="zjlComment"    column="zjl_comment"    />
        <result property="zjlTime"    column="zjl_time"    />
        <result property="zjlUserId"    column="zjl_user_id"    />
        <association property="applierUser"    javaType="SysUser"         resultMap="ApplierUserResult" />
        <association property="beforeDeptUser"    javaType="SysUser"         resultMap="BeforeDeptUserResult" />
        <association property="afterDeptUser"    javaType="SysUser"         resultMap="AfterDeptUserResult" />
        <association property="zhUser"    javaType="SysUser"         resultMap="ZhUserResult" />
        <association property="managerUser"    javaType="SysUser"         resultMap="ManagerUserResult" />
        <association property="zjlUser"    javaType="SysUser"         resultMap="ZjlUserResult" />
        <association property="beforePost"    javaType="SysPost"         resultMap="BeforePostResult" />
        <association property="afterPost"    javaType="SysPost"         resultMap="AfterPostResult" />
        <association property="beforeDept"    javaType="SysDept"         resultMap="BeforeDeptResult" />
        <association property="afterDept"    javaType="SysDept"         resultMap="AfterDeptResult" />
    </resultMap>

    <resultMap type="SysUser" id="ApplierUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="applier_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="BeforeDeptUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="before_dept_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="AfterDeptUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="after_dept_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="ZhUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="zh_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="ManagerUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="manager_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="ZjlUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="zjl_nick_name"    />
    </resultMap>

    <resultMap type="SysPost" id="BeforePostResult">
        <result property="postId"    column="post_id"    />
        <result property="postName"    column="before_post_name"    />
    </resultMap>

    <resultMap type="SysPost" id="AfterPostResult">
        <result property="postId"    column="post_id"    />
        <result property="postName"    column="after_post_name"    />
    </resultMap>

    <resultMap type="SysDept" id="BeforeDeptResult">
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="before_dept_name"    />
    </resultMap>

    <resultMap type="SysDept" id="AfterDeptResult">
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="after_dept_name"    />
    </resultMap>

    <sql id="selectCmcTransferVo">
        select t.transfer_id, t.applier, u.nick_name as applier_nick_name, t.apply_date, d.dept_name as before_dept_name, t.before_dept_id, p.post_name as before_post_name, t.before_post_id, d1.dept_name as after_dept_name, t.after_dept_id,
        p1.post_name as after_post_name, t.after_post_id, t.before_dept_comment, t.before_dept_leader, u1.nick_name as before_dept_nick_name, t.before_dept_time, t.after_dept_comment, t.after_dept_time, t.after_dept_leader,
        u2.nick_name as after_dept_nick_name, t.zh_comment, t.zh_time, t.zh_user_id, u3.nick_name as zh_nick_name, t.manager_comment, t.manager_time, t.manager_user_id, u4.nick_name as manager_nick_name,
        t.zjl_comment, t.zjl_time, t.zjl_user_id, u5.nick_name as zjl_nick_name from cmc_transfer as t
        left join sys_user as u on u.user_id = t.applier
        left join sys_user as u1 on u1.user_id = t.before_dept_leader
        left join sys_user as u2 on u2.user_id = t.after_dept_leader
        left join sys_user as u3 on u3.user_id = t.zh_user_id
        left join sys_user as u4 on u4.user_id = t.manager_user_id
        left join sys_user as u5 on u5.user_id = t.zjl_user_id
        left join sys_post as p on p.post_id = t.before_post_id
        left join sys_post as p1 on p1.post_id = t.after_post_id
        left join sys_dept as d on d.dept_id = t.before_dept_id
        left join sys_dept as d1 on d1.dept_id = t.after_dept_id
    </sql>

    <select id="selectCmcTransferList" parameterType="CmcTransfer" resultMap="CmcTransferResult">
        <include refid="selectCmcTransferVo"/>
        <where>  
            <if test="applier != null "> and t.applier = #{applier}</if>
            <if test="applyDate != null "> and t.apply_date = #{applyDate}</if>
            <if test="beforeDeptId != null "> and t.before_dept_id = #{beforeDeptId}</if>
            <if test="beforePostId != null "> and t.before_post_id = #{beforePostId}</if>
            <if test="afterDeptId != null "> and t.after_dept_id = #{afterDeptId}</if>
            <if test="afterPostId != null "> and t.after_post_id = #{afterPostId}</if>
            <if test="beforeDeptComment != null  and beforeDeptComment != ''"> and t.before_dept_comment = #{beforeDeptComment}</if>
            <if test="beforeDeptLeader != null "> and t.before_dept_leader = #{beforeDeptLeader}</if>
            <if test="beforeDeptTime != null "> and t.before_dept_time = #{beforeDeptTime}</if>
            <if test="afterDeptComment != null  and afterDeptComment != ''"> and t.after_dept_comment = #{afterDeptComment}</if>
            <if test="afterDeptTime != null "> and t.after_dept_time = #{afterDeptTime}</if>
            <if test="afterDeptLeader != null "> and t.after_dept_leader = #{afterDeptLeader}</if>
            <if test="zhComment != null  and zhComment != ''"> and t.zh_comment = #{zhComment}</if>
            <if test="zhTime != null "> and t.zh_time = #{zhTime}</if>
            <if test="zhUserId != null "> and t.zh_user_id = #{zhUserId}</if>
            <if test="managerComment != null  and managerComment != ''"> and t.manager_comment = #{managerComment}</if>
            <if test="managerTime != null "> and t.manager_time = #{managerTime}</if>
            <if test="managerUserId != null "> and t.manager_user_id = #{managerUserId}</if>
            <if test="zjlComment != null  and zjlComment != ''"> and t.zjl_comment = #{zjlComment}</if>
            <if test="zjlTime != null "> and t.zjl_time = #{zjlTime}</if>
            <if test="zjlUserId != null "> and t.zjl_user_id = #{zjlUserId}</if>
        </where>
    </select>
    
    <select id="selectCmcTransferByTransferId" parameterType="String" resultMap="CmcTransferResult">
        <include refid="selectCmcTransferVo"/>
        where transfer_id = #{transferId}
    </select>
        
    <insert id="insertCmcTransfer" parameterType="CmcTransfer">
        insert into cmc_transfer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="transferId != null">transfer_id,</if>
            <if test="applier != null">applier,</if>
            <if test="applyDate != null">apply_date,</if>
            <if test="beforeDeptId != null">before_dept_id,</if>
            <if test="beforePostId != null">before_post_id,</if>
            <if test="afterDeptId != null">after_dept_id,</if>
            <if test="afterPostId != null">after_post_id,</if>
            <if test="beforeDeptComment != null">before_dept_comment,</if>
            <if test="beforeDeptLeader != null">before_dept_leader,</if>
            <if test="beforeDeptTime != null">before_dept_time,</if>
            <if test="afterDeptComment != null">after_dept_comment,</if>
            <if test="afterDeptTime != null">after_dept_time,</if>
            <if test="afterDeptLeader != null">after_dept_leader,</if>
            <if test="zhComment != null">zh_comment,</if>
            <if test="zhTime != null">zh_time,</if>
            <if test="zhUserId != null">zh_user_id,</if>
            <if test="managerComment != null">manager_comment,</if>
            <if test="managerTime != null">manager_time,</if>
            <if test="managerUserId != null">manager_user_id,</if>
            <if test="zjlComment != null">zjl_comment,</if>
            <if test="zjlTime != null">zjl_time,</if>
            <if test="zjlUserId != null">zjl_user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="transferId != null">#{transferId},</if>
            <if test="applier != null">#{applier},</if>
            <if test="applyDate != null">#{applyDate},</if>
            <if test="beforeDeptId != null">#{beforeDeptId},</if>
            <if test="beforePostId != null">#{beforePostId},</if>
            <if test="afterDeptId != null">#{afterDeptId},</if>
            <if test="afterPostId != null">#{afterPostId},</if>
            <if test="beforeDeptComment != null">#{beforeDeptComment},</if>
            <if test="beforeDeptLeader != null">#{beforeDeptLeader},</if>
            <if test="beforeDeptTime != null">#{beforeDeptTime},</if>
            <if test="afterDeptComment != null">#{afterDeptComment},</if>
            <if test="afterDeptTime != null">#{afterDeptTime},</if>
            <if test="afterDeptLeader != null">#{afterDeptLeader},</if>
            <if test="zhComment != null">#{zhComment},</if>
            <if test="zhTime != null">#{zhTime},</if>
            <if test="zhUserId != null">#{zhUserId},</if>
            <if test="managerComment != null">#{managerComment},</if>
            <if test="managerTime != null">#{managerTime},</if>
            <if test="managerUserId != null">#{managerUserId},</if>
            <if test="zjlComment != null">#{zjlComment},</if>
            <if test="zjlTime != null">#{zjlTime},</if>
            <if test="zjlUserId != null">#{zjlUserId},</if>
         </trim>
    </insert>

    <update id="updateCmcTransfer" parameterType="CmcTransfer">
        update cmc_transfer
        <trim prefix="SET" suffixOverrides=",">
            <if test="applier != null">applier = #{applier},</if>
            <if test="applyDate != null">apply_date = #{applyDate},</if>
            <if test="beforeDeptId != null">before_dept_id = #{beforeDeptId},</if>
            <if test="beforePostId != null">before_post_id = #{beforePostId},</if>
            <if test="afterDeptId != null">after_dept_id = #{afterDeptId},</if>
            <if test="afterPostId != null">after_post_id = #{afterPostId},</if>
            <if test="beforeDeptComment != null">before_dept_comment = #{beforeDeptComment},</if>
            <if test="beforeDeptLeader != null">before_dept_leader = #{beforeDeptLeader},</if>
            <if test="beforeDeptTime != null">before_dept_time = #{beforeDeptTime},</if>
            <if test="afterDeptComment != null">after_dept_comment = #{afterDeptComment},</if>
            <if test="afterDeptTime != null">after_dept_time = #{afterDeptTime},</if>
            <if test="afterDeptLeader != null">after_dept_leader = #{afterDeptLeader},</if>
            <if test="zhComment != null">zh_comment = #{zhComment},</if>
            <if test="zhTime != null">zh_time = #{zhTime},</if>
            <if test="zhUserId != null">zh_user_id = #{zhUserId},</if>
            <if test="managerComment != null">manager_comment = #{managerComment},</if>
            <if test="managerTime != null">manager_time = #{managerTime},</if>
            <if test="managerUserId != null">manager_user_id = #{managerUserId},</if>
            <if test="zjlComment != null">zjl_comment = #{zjlComment},</if>
            <if test="zjlTime != null">zjl_time = #{zjlTime},</if>
            <if test="zjlUserId != null">zjl_user_id = #{zjlUserId},</if>
        </trim>
        where transfer_id = #{transferId}
    </update>

    <delete id="deleteCmcTransferByTransferId" parameterType="String">
        delete from cmc_transfer where transfer_id = #{transferId}
    </delete>

    <delete id="deleteCmcTransferByTransferIds" parameterType="String">
        delete from cmc_transfer where transfer_id in 
        <foreach item="transferId" collection="array" open="(" separator="," close=")">
            #{transferId}
        </foreach>
    </delete>
</mapper>