<?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.PersonnelManagementMapper">
    
    <resultMap type="PersonnelManagement" id="PersonnelManagementResult">
        <result property="personneId"    column="personne_id"    />
        <result property="personneName"    column="personne_name"    />
        <result property="personnePhone"    column="personne_phone"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="humanFaceData"    column="human_face_data"    />
        <result property="guard"    column="guard"    />

        <result property="isEnable"    column="is_enable"    />

        <result property="createDept"    column="create_dept"    />
        <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="selectPersonnelManagementVo">
        select personne_id, personne_name, personne_phone, dept_id, dept_name, human_face_data, guard,is_enable, create_dept, create_by, create_time, update_by, update_time, remark from personnel_management
    </sql>

    <select id="selectPersonnelManagementList" parameterType="PersonnelManagement" resultMap="PersonnelManagementResult">
        <include refid="selectPersonnelManagementVo"/>
        <where>  
            <if test="personneName != null  and personneName != ''"> and personne_name like concat('%', #{personneName}, '%')</if>
            <if test="personnePhone != null  and personnePhone != ''"> and personne_phone = #{personnePhone}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="humanFaceData != null  and humanFaceData != ''"> and human_face_data = #{humanFaceData}</if>
            <if test="guard != null  and guard != ''"> and guard = #{guard}</if>
            <if test="isEnable != null  and isEnable != ''"> and is_enable = #{isEnable}</if>
            <if test="createDept != null "> and create_dept = #{createDept}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectPersonnelManagementByPersonneId" parameterType="Long" resultMap="PersonnelManagementResult">
        <include refid="selectPersonnelManagementVo"/>
        where personne_id = #{personneId}
    </select>
        
    <insert id="insertPersonnelManagement" parameterType="PersonnelManagement" useGeneratedKeys="true" keyProperty="personneId">
        insert into personnel_management
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="personneName != null">personne_name,</if>
            <if test="personnePhone != null">personne_phone,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="humanFaceData != null">human_face_data,</if>
            <if test="guard != null">guard,</if>
            <if test="isEnable != null "> is_enable ,</if>
            <if test="createDept != null">create_dept,</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="personneName != null">#{personneName},</if>
            <if test="personnePhone != null">#{personnePhone},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="humanFaceData != null">#{humanFaceData},</if>
            <if test="guard != null">#{guard},</if>
            <if test="isEnable != null "> #{isEnable},</if>
            <if test="createDept != null">#{createDept},</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="updatePersonnelManagement" parameterType="PersonnelManagement">
        update personnel_management
        <trim prefix="SET" suffixOverrides=",">
            <if test="personneName != null">personne_name = #{personneName},</if>
            <if test="personnePhone != null">personne_phone = #{personnePhone},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="humanFaceData != null">human_face_data = #{humanFaceData},</if>
            <if test="guard != null">guard = #{guard},</if>
            <if test="isEnable != null "> is_enable = #{isEnable},</if>
            <if test="createDept != null">create_dept = #{createDept},</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 personne_id = #{personneId}
    </update>

    <delete id="deletePersonnelManagementByPersonneId" parameterType="Long">
        delete from personnel_management where personne_id = #{personneId}
    </delete>

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