<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.EmployeeInfoDAO">
    <resultMap id="EmployeeInfoMap" type="com.jpsoft.shinestar.modules.base.entity.EmployeeInfo">
        <id property="id" column="id_"/>
        <result property="name" column="name_"/>
        <result property="companyId" column="company_id"/>
        <result property="companyName" column="company_name"/>
        <result property="photo" column="photo_"/>
        <result property="no" column="no_"/>
        <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="delFlag" column="del_flag"/>
        <result property="sortNo" column="sort_no"/>
        <result property="openId" column="open_id"/>
        <result property="exportStatus" column="export_status"/>
        <result property="phone" column="phone_"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.EmployeeInfo">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_employee_info
	    (name_,company_id,photo_,no_,create_by,create_time,
	    update_by,update_time,del_flag,sort_no,open_id,export_status,phone_)
		values
		(
			#{name,jdbcType=VARCHAR}
			,#{companyId,jdbcType=VARCHAR}
			,#{photo,jdbcType=VARCHAR}
			,#{no,jdbcType=VARCHAR}
			,#{createBy,jdbcType=VARCHAR}
			,#{createTime,jdbcType= TIMESTAMP }
			,#{updateBy,jdbcType=VARCHAR}
			,#{updateTime,jdbcType= TIMESTAMP }
			,#{delFlag,jdbcType= NUMERIC }
			,#{sortNo,jdbcType= NUMERIC }
			,#{openId,jdbcType=VARCHAR}
			,#{exportStatus,jdbcType=NUMERIC}
			,#{phone,jdbcType=VARCHAR}
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_employee_info where id_=#{id,jdbcType=NUMERIC}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.EmployeeInfo">
        update base_employee_info
        <set>
            <if test="name!=null">
                name_=#{name,jdbcType=VARCHAR},
            </if>
            <if test="companyId!=null">
                company_id=#{companyId,jdbcType=VARCHAR},
            </if>
            <if test="photo!=null">
                photo_=#{photo,jdbcType=VARCHAR},
            </if>
            <if test="no!=null">
                no_=#{no,jdbcType=VARCHAR},
            </if>
            <if test="createBy!=null">
                create_by=#{createBy,jdbcType=VARCHAR},
            </if>
            <if test="createTime!=null">
                create_time=#{createTime,jdbcType= TIMESTAMP },
            </if>
            <if test="updateBy!=null">
                update_by=#{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime!=null">
                update_time=#{updateTime,jdbcType= TIMESTAMP },
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="sortNo!=null">
                sort_no=#{sortNo,jdbcType= NUMERIC },
            </if>
            <if test="openId!=null">
                open_id=#{openId,jdbcType= VARCHAR },
            </if>
            <if test="exportStatus!=null">
                export_status=#{exportStatus,jdbcType= NUMERIC },
            </if>
            <if test="phone!=null">
                phone_=#{phone,jdbcType= VARCHAR },
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="long" resultMap="EmployeeInfoMap">
        select e.*,c.name_ as 'company_name'
        from base_employee_info e,base_company_info c
        where e.id_=#{0} and e.company_id = c.id_
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_employee_info where id_=#{0}
    </select>
    <select id="list" resultMap="EmployeeInfoMap">
        select * from base_employee_info
    </select>
    <select id="search" parameterType="hashmap" resultMap="EmployeeInfoMap">
        <![CDATA[
			select e.*,c.name_ as 'company_name'
			from base_employee_info e,base_company_info c
		]]>
        <where>
            e.company_id = c.id_ and e.del_flag=0
            <if test="searchParams.employeeName != null">
                and e.name_ like #{searchParams.employeeName}
            </if>
            <if test="searchParams.companyId != null">
                and e.company_id = #{searchParams.companyId}
            </if>
            <if test="searchParams.exportStatus != null">
                and e.export_status = #{searchParams.exportStatus}
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
    <select id="findByArray" resultMap="EmployeeInfoMap">
        select e.*,c.name_ as 'company_name'
        from base_employee_info e,base_company_info c
        where e.company_id = c.id_
        and e.id_ in
        <foreach item="item" collection="array" open="(" separator="," close=")">
            ${item}
        </foreach>
    </select>
    <select id="findByOpenId" resultMap="EmployeeInfoMap" parameterType="string">
        select e.*,c.name_ as 'company_name'
        from base_employee_info e,base_company_info c
        where e.company_id = c.id_
        and e.open_id=#{openId}
    </select>
</mapper>