<?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.kaohe.mapper.KhEmployeeMapper">
    
    <resultMap type="KhEmployee" id="KhEmployeeResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="empName"    column="emp_name"    />
        <result property="wordId"    column="word_id"    />
        <result property="position"    column="position"    />
        <result property="sex"    column="sex"    />
        <result property="age"    column="age"    />
        <result property="phone"    column="phone"    />
        <result property="idcard"    column="idcard"    />
        <result property="bankCardNumber"    column="bank_card_number"    />
        <result property="openingBank"    column="opening_bank"    />
        <result property="education"    column="education"    />
        <result property="docs"    column="docs"    />
        <result property="docDiscrip"    column="doc_discrip"    />
        <result property="address"    column="address"    />
        <result property="contact"    column="contact"    />
        <result property="contactPhone"    column="contact_phone"    />
        <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="selectKhEmployeeVo">
        select id, user_id, dept_id, dept_name, emp_name,word_id, `position`, sex, age, phone, idcard, bank_card_number, opening_bank, education,docs,doc_discrip, address, contact, contact_phone, create_by, create_time, update_by, update_time, remark from kh_employee
    </sql>

    <select id="selectKhEmployeeList" parameterType="KhEmployee" resultMap="KhEmployeeResult">
        <include refid="selectKhEmployeeVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</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="empName != null  and empName != ''"> and emp_name like concat('%', #{empName}, '%')</if>
            <if test="wordId != null  and wordId != ''"> and word_id = #{wordId}</if>
            <if test="position != null  and position != ''"> and `position` = #{position}</if>
            <if test="sex != null  and sex != ''"> and sex = #{sex}</if>
            <if test="age != null "> and age = #{age}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="idcard != null  and idcard != ''"> and idcard = #{idcard}</if>
            <if test="bankCardNumber != null  and bankCardNumber != ''"> and bank_card_number = #{bankCardNumber}</if>
            <if test="openingBank != null  and openingBank != ''"> and opening_bank = #{openingBank}</if>
            <if test="education != null  and education != ''"> and education = #{education}</if>
            <if test="docs != null  and docs != ''"> and docs = #{docs}</if>
            <if test="docDiscrip != null  and docDiscrip != ''"> and doc_discrip = #{docDiscrip}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="contact != null  and contact != ''"> and contact = #{contact}</if>
            <if test="contactPhone != null  and contactPhone != ''"> and contact_phone = #{contactPhone}</if>
            <if test="remark != null  and remark != ''"> and remark like concat('%', #{remark}, '%')</if>
        </where>
    </select>
    
    <select id="selectKhEmployeeById" parameterType="Long" resultMap="KhEmployeeResult">
        <include refid="selectKhEmployeeVo"/>
        where id = #{id}
    </select>

    <insert id="insertKhEmployee" parameterType="KhEmployee" useGeneratedKeys="true" keyProperty="id">
        insert into kh_employee
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="empName != null and empName != ''">emp_name,</if>
            <if test="wordId != null">word_id,</if>
            <if test="position != null">`position`,</if>
            <if test="sex != null">sex,</if>
            <if test="age != null">age,</if>
            <if test="phone != null">phone,</if>
            <if test="idcard != null">idcard,</if>
            <if test="bankCardNumber != null">bank_card_number,</if>
            <if test="openingBank != null">opening_bank,</if>
            <if test="education != null">education,</if>
            <if test="docs != null">docs,</if>
            <if test="docDiscrip != null">doc_discrip,</if>
            <if test="address != null">address,</if>
            <if test="contact != null">contact,</if>
            <if test="contactPhone != null">contact_phone,</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="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="empName != null and empName != ''">#{empName},</if>
            <if test="wordId != null">#{wordId},</if>
            <if test="position != null">#{position},</if>
            <if test="sex != null">#{sex},</if>
            <if test="age != null">#{age},</if>
            <if test="phone != null">#{phone},</if>
            <if test="idcard != null">#{idcard},</if>
            <if test="bankCardNumber != null">#{bankCardNumber},</if>
            <if test="openingBank != null">#{openingBank},</if>
            <if test="education != null">#{education},</if>
            <if test="docs != null">#{docs},</if>
            <if test="docDiscrip != null">#{docDiscrip},</if>
            <if test="address != null">#{address},</if>
            <if test="contact != null">#{contact},</if>
            <if test="contactPhone != null">#{contactPhone},</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="updateKhEmployee" parameterType="KhEmployee">
        update kh_employee
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="empName != null and empName != ''">emp_name = #{empName},</if>
            <if test="wordId != null">word_id = #{wordId},</if>
            <if test="position != null">`position` = #{position},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="age != null">age = #{age},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="idcard != null">idcard = #{idcard},</if>
            <if test="bankCardNumber != null">bank_card_number = #{bankCardNumber},</if>
            <if test="openingBank != null">opening_bank = #{openingBank},</if>
            <if test="education != null">education = #{education},</if>
            <if test="docs != null">docs = #{docs},</if>
            <if test="docDiscrip != null">doc_discrip = #{docDiscrip},</if>
            <if test="address != null">address = #{address},</if>
            <if test="contact != null">contact = #{contact},</if>
            <if test="contactPhone != null">contact_phone = #{contactPhone},</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="deleteKhEmployeeById" parameterType="Long">
        delete from kh_employee where id = #{id}
    </delete>

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