<?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.manage.mapper.StaffManageMapper">
    
    <resultMap type="StaffManage" id="StaffManageResult">
        <result property="staffId"    column="staff_id"    />
        <result property="staffName"    column="staff_name"    />
        <result property="staffPhone"    column="staff_phone"    />
        <result property="emergencyContact"    column="emergency_contact"    />
        <result property="emergencyContactPhone"    column="emergency_contact_phone"    />
        <result property="staffImage"    column="staff_image"    />
        <result property="delFlag"    column="del_flag"    />
        <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="selectStaffManageVo">
        select staff_id, staff_name, staff_phone, emergency_contact, emergency_contact_phone, staff_image, del_flag, create_by, create_time, update_by, update_time, remark from staff_manage
    </sql>

    <select id="selectStaffManageList" parameterType="StaffManage" resultMap="StaffManageResult">
        <include refid="selectStaffManageVo"/>
        <where>  
            <if test="staffName != null  and staffName != ''"> and staff_name like concat('%', #{staffName}, '%')</if>
            <if test="staffPhone != null  and staffPhone != ''"> and staff_phone = #{staffPhone}</if>
            <if test="emergencyContact != null  and emergencyContact != ''"> and emergency_contact = #{emergencyContact}</if>
            <if test="emergencyContactPhone != null  and emergencyContactPhone != ''"> and emergency_contact_phone = #{emergencyContactPhone}</if>
            <if test="staffImage != null  and staffImage != ''"> and staff_image = #{staffImage}</if>
        </where>
    </select>
    
    <select id="selectStaffManageByStaffId" parameterType="Long" resultMap="StaffManageResult">
        <include refid="selectStaffManageVo"/>
        where staff_id = #{staffId}
    </select>

    <insert id="insertStaffManage" parameterType="StaffManage" useGeneratedKeys="true" keyProperty="staffId">
        insert into staff_manage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="staffName != null">staff_name,</if>
            <if test="staffPhone != null">staff_phone,</if>
            <if test="emergencyContact != null">emergency_contact,</if>
            <if test="emergencyContactPhone != null">emergency_contact_phone,</if>
            <if test="staffImage != null">staff_image,</if>
            <if test="delFlag != null">del_flag,</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="staffName != null">#{staffName},</if>
            <if test="staffPhone != null">#{staffPhone},</if>
            <if test="emergencyContact != null">#{emergencyContact},</if>
            <if test="emergencyContactPhone != null">#{emergencyContactPhone},</if>
            <if test="staffImage != null">#{staffImage},</if>
            <if test="delFlag != null">#{delFlag},</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="updateStaffManage" parameterType="StaffManage">
        update staff_manage
        <trim prefix="SET" suffixOverrides=",">
            <if test="staffName != null">staff_name = #{staffName},</if>
            <if test="staffPhone != null">staff_phone = #{staffPhone},</if>
            <if test="emergencyContact != null">emergency_contact = #{emergencyContact},</if>
            <if test="emergencyContactPhone != null">emergency_contact_phone = #{emergencyContactPhone},</if>
            <if test="staffImage != null">staff_image = #{staffImage},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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 staff_id = #{staffId}
    </update>

    <delete id="deleteStaffManageByStaffId" parameterType="Long">
        delete from staff_manage where staff_id = #{staffId}
    </delete>

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