<?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.BdglLeaveOneMapper">

    <resultMap type="BdglLeaveOne" id="BdglLeaveOneResult">
        <result property="id"    column="id"    />
        <result property="peopleId"    column="people_id"    />
        <result property="unitId"    column="unit_id"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="leaveType"    column="leave_type"    />
        <result property="leaveReason"    column="leave_reason"    />
        <result property="departureTime"    column="departure_time"    />
        <result property="returnTime"    column="return_time"    />
        <result property="returnStatus"    column="return_status"    />
        <result property="isReturn"    column="is_return"    />
        <result property="updatetime"    column="updatetime"    />
        <result property="adminId"    column="admin_id"    />
        <result property="createtime"    column="createtime"    />
        <result property="peopleId1"    column="people_id1"    />
        <result property="postId"    column="post_id"    />
        <result property="peopleId2"    column="people_id2"    />
        <result property="peopleId3"    column="people_id3"    />
        <result property="peopleId4"    column="people_id4"    />
        <result property="status1"    column="status1"    />
        <result property="status2"    column="status2"    />
        <result property="status3"    column="status3"    />
        <result property="status4"    column="status4"    />
        <result property="contents"    column="contents"    />
        <result property="statusd"    column="statusd"    />
        <result property="rejoin"    column="rejoin"    />
        <result property="unitName"    column="unit_name"    />
        <result property="peopleName"    column="people_name"    />
        <result property="peopleName1"    column="people_name1"    />
        <result property="peopleName2"    column="people_name2"    />
        <result property="peopleName3"    column="people_name3"    />
        <result property="peopleName4"    column="people_name4"    />
        <result property="reasons"    column="reasons"    />
        <result property="specialApproval"    column="special_approval"    />
        <result property="actualreturntime"    column="actualreturntime"    />
        <result property="approvalDepartment"    column="approval_department"    />
        <result property="startTimeF"    column="startTime"    />
    </resultMap>

    <sql id="selectBdglLeaveOneVo">
        select id, people_id, unit_id, start_time, end_time, leave_type, leave_reason, departure_time, return_time, return_status, is_return, updatetime, admin_id, createtime, people_id1, post_id, people_id2, people_id3, people_id4, status1, status2, status3, status4, contents, statusd, rejoin, unit_name, people_name, people_name1, people_name2, people_name3, people_name4, reasons, special_approval, actualreturntime,approval_department from bdgl_leave_one
    </sql>

    <select id="selectBdglLeaveOneList" parameterType="BdglLeaveOne" resultMap="BdglLeaveOneResult">
        <include refid="selectBdglLeaveOneVo"/>
        <where>
            <if test="peopleId != null "> and people_id = #{peopleId}</if>
            <if test="unitId != null "> and unit_id = #{unitId}</if>
            <if test="startTimeF != null "> and start_time like concat('%', #{startTimeF}, '%')</if>
            <if test="startTime != null "> and start_time like concat('%', #{startTime}, '%')</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="leaveType != null  and leaveType != ''"> and leave_type = #{leaveType}</if>
            <if test="leaveReason != null  and leaveReason != ''"> and leave_reason = #{leaveReason}</if>
            <if test="departureTime != null  and departureTime != ''"> and departure_time like concat('%', #{departureTime}, '%')</if>
            <if test="returnTime != null  and returnTime != ''"> and return_time = #{returnTime}</if>
            <if test="returnStatus != null  and returnStatus != ''"> and return_status = #{returnStatus}</if>
            <if test="isReturn != null  and isReturn != ''"> and is_return = #{isReturn}</if>
            <if test="updatetime != null  and updatetime != ''"> and updatetime = #{updatetime}</if>
            <if test="adminId != null "> and admin_id = #{adminId}</if>
            <if test="createtime != null  and createtime != ''"> and createtime = #{createtime}</if>
            <if test="peopleId1 != null "> and people_id1 = #{peopleId1}</if>
            <if test="postId != null "> and post_id = #{postId}</if>
            <if test="peopleId2 != null "> and people_id2 = #{peopleId2}</if>
            <if test="peopleId3 != null "> and people_id3 = #{peopleId3}</if>
            <if test="peopleId4 != null "> and people_id4 = #{peopleId4}</if>
            <if test="status1 != null "> and status1 = #{status1}</if>
            <if test="status2 != null "> and status2 = #{status2}</if>
            <if test="status3 != null "> and status3 = #{status3}</if>
            <if test="status4 != null "> and status4 = #{status4}</if>
            <if test="contents != null  and contents != ''"> and contents = #{contents}</if>
            <if test="statusd != null "> and statusd = #{statusd}</if>
            <if test="rejoin != null "> and rejoin = #{rejoin}</if>
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="peopleName != null  and peopleName != ''"> and people_name like concat('%', #{peopleName}, '%')</if>
            <if test="peopleName1 != null  and peopleName1 != ''"> and people_name1 = #{peopleName1}</if>
            <if test="peopleName2 != null  and peopleName2 != ''"> and people_name2 = #{peopleName2}</if>
            <if test="peopleName3 != null  and peopleName3 != ''"> and people_name3 = #{peopleName3}</if>
            <if test="peopleName4 != null  and peopleName4 != ''"> and people_name4 = #{peopleName4}</if>
            <if test="reasons != null  and reasons != ''"> and reasons = #{reasons}</if>
            <if test="specialApproval != null  and specialApproval != ''"> and special_approval = #{specialApproval}</if>
            <if test="actualreturntime != null "> and actualreturntime = #{actualreturntime}</if>
            <if test="approvalDepartment != null "> and approval_department = #{approvalDepartment}</if>
            <if test="names != null "> and people_id in
                <foreach item="names" collection="names" open="(" separator="," close=")">
                    #{names}
                </foreach></if>
        </where>
        order by id desc
    </select>

    <select id="selectBdglLeaveOneById" parameterType="Long" resultMap="BdglLeaveOneResult">
        <include refid="selectBdglLeaveOneVo"/>
        where id = #{id}
    </select>

    <!-- to_days(start_time) = to_days(now())
        AND -->
    <select id="selectBdglLeaveOneListes" resultMap="BdglLeaveOneResult">
        <include refid="selectBdglLeaveOneVo"/>
        where departure_time is null
    </select>
    <select id="selectBdglLeaveOneLists" resultMap="BdglLeaveOneResult">
        <include refid="selectBdglLeaveOneVo"/>
        WHERE departure_time is not null
        AND return_time is null
    </select>

    <insert id="insertBdglLeaveOne" parameterType="BdglLeaveOne" useGeneratedKeys="true" keyProperty="id">
        insert into bdgl_leave_one
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="peopleId != null">people_id,</if>
            <if test="unitId != null">unit_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="leaveType != null">leave_type,</if>
            <if test="leaveReason != null">leave_reason,</if>
            <if test="departureTime != null">departure_time,</if>
            <if test="returnTime != null">return_time,</if>
            <if test="returnStatus != null">return_status,</if>
            <if test="isReturn != null">is_return,</if>
            <if test="updatetime != null">updatetime,</if>
            <if test="adminId != null">admin_id,</if>
            <if test="createtime != null">createtime,</if>
            <if test="peopleId1 != null">people_id1,</if>
            <if test="postId != null">post_id,</if>
            <if test="peopleId2 != null">people_id2,</if>
            <if test="peopleId3 != null">people_id3,</if>
            <if test="peopleId4 != null">people_id4,</if>
            <if test="status1 != null">status1,</if>
            <if test="status2 != null">status2,</if>
            <if test="status3 != null">status3,</if>
            <if test="status4 != null">status4,</if>
            <if test="contents != null">contents,</if>
            <if test="statusd != null">statusd,</if>
            <if test="rejoin != null">rejoin,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="peopleName != null">people_name,</if>
            <if test="peopleName1 != null">people_name1,</if>
            <if test="peopleName2 != null">people_name2,</if>
            <if test="peopleName3 != null">people_name3,</if>
            <if test="peopleName4 != null">people_name4,</if>
            <if test="reasons != null">reasons,</if>
            <if test="specialApproval != null">special_approval,</if>
            <if test="actualreturntime != null">actualreturntime,</if>
            <if test="approvalDepartment != null">approval_department,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="peopleId != null">#{peopleId},</if>
            <if test="unitId != null">#{unitId},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="leaveType != null">#{leaveType},</if>
            <if test="leaveReason != null">#{leaveReason},</if>
            <if test="departureTime != null">#{departureTime},</if>
            <if test="returnTime != null">#{returnTime},</if>
            <if test="returnStatus != null">#{returnStatus},</if>
            <if test="isReturn != null">#{isReturn},</if>
            <if test="updatetime != null">#{updatetime},</if>
            <if test="adminId != null">#{adminId},</if>
            <if test="createtime != null">#{createtime},</if>
            <if test="peopleId1 != null">#{peopleId1},</if>
            <if test="postId != null">#{postId},</if>
            <if test="peopleId2 != null">#{peopleId2},</if>
            <if test="peopleId3 != null">#{peopleId3},</if>
            <if test="peopleId4 != null">#{peopleId4},</if>
            <if test="status1 != null">#{status1},</if>
            <if test="status2 != null">#{status2},</if>
            <if test="status3 != null">#{status3},</if>
            <if test="status4 != null">#{status4},</if>
            <if test="contents != null">#{contents},</if>
            <if test="statusd != null">#{statusd},</if>
            <if test="rejoin != null">#{rejoin},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="peopleName != null">#{peopleName},</if>
            <if test="peopleName1 != null">#{peopleName1},</if>
            <if test="peopleName2 != null">#{peopleName2},</if>
            <if test="peopleName3 != null">#{peopleName3},</if>
            <if test="peopleName4 != null">#{peopleName4},</if>
            <if test="reasons != null">#{reasons},</if>
            <if test="specialApproval != null">#{specialApproval},</if>
            <if test="actualreturntime != null">#{actualreturntime},</if>
            <if test="approvalDepartment != null">#{approvalDepartment},</if>
         </trim>
    </insert>

    <update id="updateBdglLeaveOne" parameterType="BdglLeaveOne">
        update bdgl_leave_one
        <trim prefix="SET" suffixOverrides=",">
            <if test="peopleId != null">people_id = #{peopleId},</if>
            <if test="unitId != null">unit_id = #{unitId},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="leaveType != null">leave_type = #{leaveType},</if>
            <if test="leaveReason != null">leave_reason = #{leaveReason},</if>
            <if test="departureTime != null">departure_time = #{departureTime},</if>
            <if test="returnTime != null">return_time = #{returnTime},</if>
            <if test="returnStatus != null">return_status = #{returnStatus},</if>
            <if test="isReturn != null">is_return = #{isReturn},</if>
            <if test="updatetime != null">updatetime = #{updatetime},</if>
            <if test="adminId != null">admin_id = #{adminId},</if>
            <if test="createtime != null">createtime = #{createtime},</if>
            <if test="peopleId1 != null">people_id1 = #{peopleId1},</if>
            <if test="postId != null">post_id = #{postId},</if>
            <if test="peopleId2 != null">people_id2 = #{peopleId2},</if>
            <if test="peopleId3 != null">people_id3 = #{peopleId3},</if>
            <if test="peopleId4 != null">people_id4 = #{peopleId4},</if>
            <if test="status1 != null">status1 = #{status1},</if>
            <if test="status2 != null">status2 = #{status2},</if>
            <if test="status3 != null">status3 = #{status3},</if>
            <if test="status4 != null">status4 = #{status4},</if>
            <if test="contents != null">contents = #{contents},</if>
            <if test="statusd != null">statusd = #{statusd},</if>
            <if test="rejoin != null">rejoin = #{rejoin},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="peopleName != null">people_name = #{peopleName},</if>
            <if test="peopleName1 != null">people_name1 = #{peopleName1},</if>
            <if test="peopleName2 != null">people_name2 = #{peopleName2},</if>
            <if test="peopleName3 != null">people_name3 = #{peopleName3},</if>
            <if test="peopleName4 != null">people_name4 = #{peopleName4},</if>
            <if test="reasons != null">reasons = #{reasons},</if>
            <if test="specialApproval != null">special_approval = #{specialApproval},</if>
            <if test="actualreturntime != null">actualreturntime = #{actualreturntime},</if>
            <if test="approvalDepartment != null">approval_department = #{approvalDepartment},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBdglLeaveOneById" parameterType="Long">
        delete from bdgl_leave_one where id = #{id}
    </delete>

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