<?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.business.mapper.BusGridPersonInfoMapper">
    
    <resultMap type="BusGridPersonInfo" id="BusGridPersonInfoResult">
        <result property="gridPersonId"    column="grid_person_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="personName"    column="person_name"    />
        <result property="personSex"    column="person_sex"    />
        <result property="personPhone"    column="person_phone"    />
        <result property="personIdcard"    column="person_idcard"    />
        <result property="postId"    column="post_id"    />
        <result property="wordTime"    column="word_time"    />
        <result property="postName"    column="post_name"    />
        <result property="deptName"    column="dept_name"    />
    </resultMap>

    <sql id="selectBusGridPersonInfoVo">
        select grid_person_id, dept_id, person_name, person_sex, person_phone, person_idcard, post_id, word_time from bus_grid_person_info
    </sql>

    <select id="selectBusGridPersonInfoList" parameterType="BusGridPersonInfo" resultMap="BusGridPersonInfoResult">
        <include refid="selectBusGridPersonInfoVo"/>
        <where>  
            and dept_id = #{deptId}
            <if test="personName != null  and personName != ''"> and person_name like concat('%', #{personName}, '%')</if>
            <if test="personSex != null "> and person_sex = #{personSex}</if>
            <if test="personPhone != null  and personPhone != ''"> and person_phone = #{personPhone}</if>
            <if test="personIdcard != null  and personIdcard != ''"> and person_idcard = #{personIdcard}</if>
            <if test="postId != null "> and post_id = #{postId}</if>
            <if test="wordTime != null "> and word_time = #{wordTime}</if>
        </where>
    </select>
    
    <select id="selectBusGridPersonInfoById" parameterType="Long" resultMap="BusGridPersonInfoResult">
        select b.grid_person_id,b.dept_id,b.person_idcard,b.person_name,b.person_phone,b.person_sex,b.post_id,b.word_time,s.dept_name,p.post_name
        from bus_grid_person_info b
          LEFT JOIN sys_dept s on b.dept_id=s.dept_id
          LEFT JOIN sys_post p on b.post_id=p.post_id
        where b.grid_person_id=#{gridPersonId}
    </select>

    <insert id="insertBusGridPersonInfo" parameterType="BusGridPersonInfo" useGeneratedKeys="true" keyProperty="gridPersonId">
        insert into bus_grid_person_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="personName != null">person_name,</if>
            <if test="personSex != null">person_sex,</if>
            <if test="personPhone != null">person_phone,</if>
            <if test="personIdcard != null">person_idcard,</if>
            <if test="postId != null">post_id,</if>
            <if test="wordTime != null">word_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deptId != null">#{deptId},</if>
            <if test="personName != null">#{personName},</if>
            <if test="personSex != null">#{personSex},</if>
            <if test="personPhone != null">#{personPhone},</if>
            <if test="personIdcard != null">#{personIdcard},</if>
            <if test="postId != null">#{postId},</if>
            <if test="wordTime != null">#{wordTime},</if>
         </trim>
    </insert>

    <update id="updateBusGridPersonInfo" parameterType="BusGridPersonInfo">
        update bus_grid_person_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="personName != null">person_name = #{personName},</if>
            <if test="personSex != null">person_sex = #{personSex},</if>
            <if test="personPhone != null">person_phone = #{personPhone},</if>
            <if test="personIdcard != null">person_idcard = #{personIdcard},</if>
            <if test="postId != null">post_id = #{postId},</if>
            <if test="wordTime != null">word_time = #{wordTime},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="postId != null">post_id = #{postId},</if>
        </trim>
        where grid_person_id = #{gridPersonId}
    </update>

    <delete id="deleteBusGridPersonInfoById" parameterType="Long">
        delete from bus_grid_person_info where grid_person_id = #{gridPersonId}
    </delete>

    <delete id="deleteBusGridPersonInfoByIds" parameterType="String">
        delete from bus_grid_person_info where grid_person_id in 
        <foreach item="gridPersonId" collection="array" open="(" separator="," close=")">
            #{gridPersonId}
        </foreach>
    </delete>

</mapper>