<?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.staffing.custom.mapper.StEmployeeMapper">
    
    <resultMap type="StEmployee" id="StEmployeeResult">
        <result property="id"    column="id"    />
        <result property="realName"    column="real_name"    />
        <result property="phone"    column="phone"    />
        <result property="idCard"    column="id_card"    />
        <result property="sex"    column="sex"    />
        <result property="nation"    column="nation"    />
        <result property="age"    column="age"    />
        <result property="useUnit"    column="use_unit"    />
        <result property="interviewDate"    column="interview_date"    />
        <result property="entryDate"    column="entry_date"    />
        <result property="supplier"    column="supplier"    />
        <result property="employeePrice"    column="employee_price"    />
        <result property="supplierPrice"    column="supplier_price"    />
        <result property="employeeType"    column="employee_type"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="openId"    column="open_id"    />
    </resultMap>

    <sql id="selectStEmployeeVo">
        select id, real_name, phone, id_card, sex, nation, age, use_unit, interview_date, entry_date, supplier, employee_price, supplier_price, employee_type, update_time,create_time,open_id from st_employee
    </sql>

    <select id="selectStEmployeeList" parameterType="StEmployee" resultMap="StEmployeeResult">
        <include refid="selectStEmployeeVo"/>
        <where>  
            <if test="realName != null  and realName != ''"> and real_name like concat('%', #{realName}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
            <if test="idCard != null  and idCard != ''"> and id_card like concat('%', #{idCard}, '%')</if>
            <if test="employeeType != null "> and employee_type = #{employeeType}</if>

            <if test="keyWord != null  and keyWord != ''"> and (real_name like concat('%', #{keyWord}, '%') or phone like concat('%', #{keyWord}, '%'))</if>
        </where>
        order by create_time desc , update_time desc
    </select>
    
    <select id="selectStEmployeeById" parameterType="Long" resultMap="StEmployeeResult">
        <include refid="selectStEmployeeVo"/>
        where id = #{id}
    </select>

    <select id="selectStEmployeeByIds" resultMap="StEmployeeResult">
        <include refid="selectStEmployeeVo"/>
        <where>
            <if test="uids != null ">
                and id in
                <foreach collection="uids" index="index" item="item" open="(" separator="," close=")">
                    (#{item})
                </foreach>
            </if>
        </where>

    </select>

    <select id="selectStEmployeeByPhone" parameterType="String" resultMap="StEmployeeResult">
        <include refid="selectStEmployeeVo"/>
        where phone = #{phone}
    </select>


    <insert id="insertStEmployee" parameterType="StEmployee" useGeneratedKeys="true" keyProperty="id">
        insert into st_employee
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="realName != null and realName != ''">real_name,</if>
            <if test="phone != null and phone != ''">phone,</if>
            <if test="idCard != null and idCard != ''">id_card,</if>
            <if test="sex != null">sex,</if>
            <if test="nation != null">nation,</if>
            <if test="age != null">age,</if>
            <if test="useUnit != null">use_unit,</if>
            <if test="interviewDate != null">interview_date,</if>
            <if test="entryDate != null">entry_date,</if>
            <if test="supplier != null">supplier,</if>
            <if test="employeePrice != null">employee_price,</if>
            <if test="supplierPrice != null">supplier_price,</if>
            <if test="employeeType != null">employee_type,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="openId != null">open_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="realName != null and realName != ''">#{realName},</if>
            <if test="phone != null and phone != ''">#{phone},</if>
            <if test="idCard != null and idCard != ''">#{idCard},</if>
            <if test="sex != null">#{sex},</if>
            <if test="nation != null">#{nation},</if>
            <if test="age != null">#{age},</if>
            <if test="useUnit != null">#{useUnit},</if>
            <if test="interviewDate != null">#{interviewDate},</if>
            <if test="entryDate != null">#{entryDate},</if>
            <if test="supplier != null">#{supplier},</if>
            <if test="employeePrice != null">#{employeePrice},</if>
            <if test="supplierPrice != null">#{supplierPrice},</if>
            <if test="employeeType != null">#{employeeType},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="openId != null">#{openId},</if>
         </trim>
    </insert>

    <insert id="save" parameterType="StEmployee" useGeneratedKeys="true" keyProperty="id">
        insert into st_employee
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="realName != null and realName != ''">real_name,</if>
            <if test="phone != null and phone != ''">phone,</if>
            <if test="idCard != null and idCard != ''">id_card,</if>
            <if test="sex != null">sex,</if>
            <if test="nation != null">nation,</if>
            <if test="age != null">age,</if>
            <if test="useUnit != null">use_unit,</if>
            <if test="interviewDate != null">interview_date,</if>
            <if test="entryDate != null">entry_date,</if>
            <if test="supplier != null">supplier,</if>
            <if test="employeePrice != null">employee_price,</if>
            <if test="supplierPrice != null">supplier_price,</if>
            <if test="employeeType != null">employee_type,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="openId != null">open_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="realName != null and realName != ''">#{realName},</if>
            <if test="phone != null and phone != ''">#{phone},</if>
            <if test="idCard != null and idCard != ''">#{idCard},</if>
            <if test="sex != null">#{sex},</if>
            <if test="nation != null">#{nation},</if>
            <if test="age != null">#{age},</if>
            <if test="useUnit != null">#{useUnit},</if>
            <if test="interviewDate != null">#{interviewDate},</if>
            <if test="entryDate != null">#{entryDate},</if>
            <if test="supplier != null">#{supplier},</if>
            <if test="employeePrice != null">#{employeePrice},</if>
            <if test="supplierPrice != null">#{supplierPrice},</if>
            <if test="employeeType != null">#{employeeType},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="openId != null">#{openId},</if>
        </trim>
        ON DUPLICATE KEY UPDATE
        <trim prefix="" suffixOverrides=",">
            <if test="realName != null and realName != ''">real_name = #{realName},</if>
            <if test="idCard != null and idCard != ''">id_card = #{idCard},</if>
            <if test="sex != null">sex = #{sex},</if>
            nation = #{nation},
            age = #{age},
            interview_date = #{interviewDate},
            entry_date = #{entryDate},
            use_unit = #{useUnit},
            supplier = #{supplier},
            employee_price = #{employeePrice},
            supplier_price = #{supplierPrice},
            <if test="employeeType != null">employee_type = #{employeeType},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>

    </insert>

    <update id="updateStEmployeeOrNull" parameterType="StEmployee">
        update st_employee
        <trim prefix="SET" suffixOverrides=",">
            <if test="realName != null and realName != ''">real_name = #{realName},</if>
            <if test="phone != null and phone != ''">phone = #{phone},</if>
            <if test="idCard != null and idCard != ''">id_card = #{idCard},</if>
            <if test="sex != null">sex = #{sex},</if>

            nation = #{nation},
            age = #{age},
            interview_date = #{interviewDate},
            entry_date = #{entryDate},
            use_unit = #{useUnit},
            supplier = #{supplier},
            employee_price = #{employeePrice},
            supplier_price = #{supplierPrice},
            <if test="employeeType != null">employee_type = #{employeeType},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateStEmployee" parameterType="StEmployee">
        update st_employee
        <trim prefix="SET" suffixOverrides=",">
            <if test="realName != null and realName != ''">real_name = #{realName},</if>
            <if test="phone != null and phone != ''">phone = #{phone},</if>
            <if test="idCard != null and idCard != ''">id_card = #{idCard},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="nation != null">nation = #{nation},</if>
            <if test="age != null">age = #{age},</if>
            <if test="useUnit != null">use_unit = #{useUnit},</if>
            <if test="interviewDate != null">interview_date = #{interviewDate},</if>
            <if test="entryDate != null">entry_date = #{entryDate},</if>
            <if test="supplier != null">supplier = #{supplier},</if>
            <if test="employeePrice != null">employee_price = #{employeePrice},</if>
            <if test="supplierPrice != null">supplier_price = #{supplierPrice},</if>
            <if test="employeeType != null">employee_type = #{employeeType},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="openId != null">open_id = #{openId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteStEmployeeById" parameterType="Long">
        delete from st_employee where id = #{id}
    </delete>

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