<?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.supervision.peopleChuRu.mapper.BdglPeopleBorrowMapper">
    
    <resultMap type="BdglPeopleBorrow" id="BdglPeopleBorrowResult">
        <result property="id"    column="id"    />
        <result property="transferPeople"    column="transfer_people"    />
        <result property="transferPeopleId"    column="transfer_people_id"    />
        <result property="unitName"    column="unit_name"    />
        <result property="unitId"    column="unit_id"    />
        <result property="transferUnitName"    column="transfer_unit_name"    />
        <result property="transferUnitId"    column="transfer_unit_id"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="transferReason"    column="transfer_reason"    />
        <result property="jobTitle"    column="job_title"    />
        <result property="rankId"    column="rank_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="creatName"    column="creat_name"    />
        <result property="state"    column="state"    />
        <result property="userId"    column="user_id"    />
    </resultMap>

    <sql id="selectBdglPeopleBorrowVo">
        select id, transfer_people, transfer_people_id, unit_name, unit_id, transfer_unit_name, transfer_unit_id, start_time, end_time, transfer_reason, job_title, rank_id, create_time, creat_name,state,user_id from bdgl_people_borrow
    </sql>

    <select id="selectBdglPeopleBorrowList" parameterType="BdglPeopleBorrow" resultMap="BdglPeopleBorrowResult">
        <include refid="selectBdglPeopleBorrowVo"/>
        <where>  
            <if test="transferPeople != null  and transferPeople != ''"> and transfer_people = #{transferPeople}</if>
            <if test="transferPeopleId != null "> and transfer_people_id = #{transferPeopleId}</if>
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="unitId != null "> and unit_id = #{unitId}</if>
            <if test="transferUnitName != null  and transferUnitName != ''"> and transfer_unit_name like concat('%', #{transferUnitName}, '%')</if>
            <if test="transferUnitId != null "> and transfer_unit_id = #{transferUnitId}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="transferReason != null  and transferReason != ''"> and transfer_reason = #{transferReason}</if>
            <if test="jobTitle != null  and jobTitle != ''"> and job_title = #{jobTitle}</if>
            <if test="rankId != null  and rankId != ''"> and rank_id = #{rankId}</if>
            <if test="creatName != null  and creatName != ''"> and creat_name like concat('%', #{creatName}, '%')</if>
            <if test="state != null  and state != ''"> and state = #{state}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectBdglPeopleBorrowById" parameterType="Long" resultMap="BdglPeopleBorrowResult">
        <include refid="selectBdglPeopleBorrowVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBdglPeopleBorrow" parameterType="BdglPeopleBorrow">
        insert into bdgl_people_borrow
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="transferPeople != null">transfer_people,</if>
            <if test="transferPeopleId != null">transfer_people_id,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="unitId != null">unit_id,</if>
            <if test="transferUnitName != null">transfer_unit_name,</if>
            <if test="transferUnitId != null">transfer_unit_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="transferReason != null">transfer_reason,</if>
            <if test="jobTitle != null">job_title,</if>
            <if test="rankId != null">rank_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="creatName != null">creat_name,</if>
            <if test="state != null">state,</if>
            <if test="userId != null">user_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="transferPeople != null">#{transferPeople},</if>
            <if test="transferPeopleId != null">#{transferPeopleId},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="unitId != null">#{unitId},</if>
            <if test="transferUnitName != null">#{transferUnitName},</if>
            <if test="transferUnitId != null">#{transferUnitId},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="transferReason != null">#{transferReason},</if>
            <if test="jobTitle != null">#{jobTitle},</if>
            <if test="rankId != null">#{rankId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="creatName != null">#{creatName},</if>
            <if test="state != null">#{state},</if>
            <if test="userId != null">#{user_id},</if>
         </trim>
    </insert>

    <update id="updateBdglPeopleBorrow" parameterType="BdglPeopleBorrow">
        update bdgl_people_borrow
        <trim prefix="SET" suffixOverrides=",">
            <if test="transferPeople != null">transfer_people = #{transferPeople},</if>
            <if test="transferPeopleId != null">transfer_people_id = #{transferPeopleId},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="unitId != null">unit_id = #{unitId},</if>
            <if test="transferUnitName != null">transfer_unit_name = #{transferUnitName},</if>
            <if test="transferUnitId != null">transfer_unit_id = #{transferUnitId},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="transferReason != null">transfer_reason = #{transferReason},</if>
            <if test="jobTitle != null">job_title = #{jobTitle},</if>
            <if test="rankId != null">rank_id = #{rankId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="creatName != null">creat_name = #{creatName},</if>
            <if test="state != null">state = #{state},</if>
            <if test="userId !=null">user_id=#{userId}</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBdglPeopleBorrowById" parameterType="Long">
        delete from bdgl_people_borrow where id = #{id}
    </delete>

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