<?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.system.mapper.KeyPeopleInfoMapper">
    
    <resultMap type="KeyPeopleInfo" id="KeyPeopleInfoResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="idCard"    column="id_card"    />
        <result property="phoneNum"    column="phone_num"    />
        <result property="deptId"    column="dept_id"    />
        <result property="jobStyle"    column="job_style"    />
        <result property="focusCrowdStyle"    column="focus_crowd_style"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectKeyPeopleInfoVo">
        select id, name, id_card, phone_num, dept_id,job_style,focus_crowd_style, create_by, create_time, update_by, update_time, remark from key_people_info
    </sql>

    <select id="selectKeyPeopleInfoList" parameterType="KeyPeopleInfo" resultMap="KeyPeopleInfoResult">
        <include refid="selectKeyPeopleInfoVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="phoneNum != null  and phoneNum != ''"> and phone_num = #{phoneNum}</if>
            <if test="deptId != null  and deptId != ''"> and dept_id = #{deptId}</if>
            <if test="deptIdList!= null and deptIdList.size()>0" >
            and dept_id in
            <foreach item="deptId" collection="deptIdList" open="(" separator="," close=")">
                #{deptId}
            </foreach>
            </if>
        </where>
    </select>
    
    <select id="selectKeyPeopleInfoById" parameterType="Long" resultMap="KeyPeopleInfoResult">
        <include refid="selectKeyPeopleInfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertKeyPeopleInfo" parameterType="KeyPeopleInfo" useGeneratedKeys="true" keyProperty="id">
        insert into key_people_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="idCard != null">id_card,</if>
            <if test="phoneNum != null">phone_num,</if>
            <if test="deptId != null">dept_id,</if>

            <if test="jobStyle != null">job_style,</if>
            <if test="focusCrowdStyle != null">focus_crowd_style,</if>

            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="phoneNum != null">#{phoneNum},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="jobStyle != null">#{jobStyle},</if>
            <if test="focusCrowdStyle != null">#{focusCrowdStyle},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateKeyPeopleInfo" parameterType="KeyPeopleInfo">
        update key_people_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="phoneNum != null">phone_num = #{phoneNum},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>

            <if test="jobStyle != null">job_style = #{jobStyle},</if>
            <if test="focusCrowdStyle != null">focus_crowd_style = #{focusCrowdStyle},</if>

            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKeyPeopleInfoById" parameterType="Long">
        delete from key_people_info where id = #{id}
    </delete>

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