<?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.StaffManageMapper">
    
    <resultMap type="StaffManage" id="StaffManageResult">
        <result property="staffId"    column="staff_id"    />
        <result property="userId"    column="user_id"    />
        <result property="staffName"    column="staff_name"    />
        <result property="gender"    column="gender"    />
        <result property="staffCategory"    column="staff_category"    />
        <result property="maintenanceCategory"    column="maintenance_category"    />
        <result property="phoneNumber"    column="phone_number"    />
        <result property="avatarPhoto"    column="avatar_photo"    />
        <result property="idCard"    column="id_card"    />
        <result property="idCardFront"    column="id_card_front"    />
        <result property="idCardBack"    column="id_card_back"    />
        <result property="certificate"    column="certificate"    />
        <result property="status"    column="status"    />
        <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,user_id, staff_name, gender, staff_category, maintenance_category, phone_number, avatar_photo, id_card, id_card_front, id_card_back, certificate, status, 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="gender != null  and gender != ''"> and gender = #{gender}</if>
            <if test="staffCategory != null  and staffCategory != ''"> and staff_category = #{staffCategory}</if>
            <if test="maintenanceCategory != null  and maintenanceCategory != ''"> and maintenance_category = #{maintenanceCategory}</if>
            <if test="phoneNumber != null  and phoneNumber != ''"> and phone_number like concat('%', #{phoneNumber}, '%')</if>
            <if test="avatarPhoto != null  and avatarPhoto != ''"> and avatar_photo = #{avatarPhoto}</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="idCardFront != null  and idCardFront != ''"> and id_card_front = #{idCardFront}</if>
            <if test="idCardBack != null  and idCardBack != ''"> and id_card_back = #{idCardBack}</if>
            <if test="certificate != null  and certificate != ''"> and certificate = #{certificate}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectStaffManageByStaffId" parameterType="Long" resultMap="StaffManageResult">
        <include refid="selectStaffManageVo"/>
        where staff_id = #{staffId}
    </select>
    <select id="selectStaffManageByUserId" parameterType="Long" resultMap="StaffManageResult">
        <include refid="selectStaffManageVo"/>
        where user_id = #{userId}
    </select>

    <insert id="insertStaffManage" parameterType="StaffManage" useGeneratedKeys="true" keyProperty="staffId">
        insert into staff_manage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="staffName != null">staff_name,</if>
            <if test="gender != null">gender,</if>
            <if test="staffCategory != null">staff_category,</if>
            <if test="maintenanceCategory != null">maintenance_category,</if>
            <if test="phoneNumber != null">phone_number,</if>
            <if test="avatarPhoto != null">avatar_photo,</if>
            <if test="idCard != null">id_card,</if>
            <if test="idCardFront != null">id_card_front,</if>
            <if test="idCardBack != null">id_card_back,</if>
            <if test="certificate != null">certificate,</if>
            <if test="status != null">status,</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="userId != null">#{userId},</if>
            <if test="staffName != null">#{staffName},</if>
            <if test="gender != null">#{gender},</if>
            <if test="staffCategory != null">#{staffCategory},</if>
            <if test="maintenanceCategory != null">#{maintenanceCategory},</if>
            <if test="phoneNumber != null">#{phoneNumber},</if>
            <if test="avatarPhoto != null">#{avatarPhoto},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="idCardFront != null">#{idCardFront},</if>
            <if test="idCardBack != null">#{idCardBack},</if>
            <if test="certificate != null">#{certificate},</if>
            <if test="status != null">#{status},</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="userId != null">user_id = #{userId},</if>
            <if test="staffName != null">staff_name = #{staffName},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="staffCategory != null">staff_category = #{staffCategory},</if>
            <if test="maintenanceCategory != null">maintenance_category = #{maintenanceCategory},</if>
            <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
            <if test="avatarPhoto != null">avatar_photo = #{avatarPhoto},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="idCardFront != null">id_card_front = #{idCardFront},</if>
            <if test="idCardBack != null">id_card_back = #{idCardBack},</if>
            <if test="certificate != null">certificate = #{certificate},</if>
            <if test="status != null">status = #{status},</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>