<?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="cn.com.countrygarden.bi.main.dao.sys.SysUserMapper">
    <sql id="selectAll">
    <![CDATA[
        SELECT u.UserCode, u.UserName, u.LoginCode, u.PassWord, u.CommID, u.DepCode, u.Memo, u.OrganId
        FROM [HM_wygl_new_1853].[dbo].[Tb_Sys_User] AS u
        ]]>
    </sql>

    <!--
    获取已存在的用户的erp的id集合
    -->
    <select id="selectIdList" resultType="java.lang.String">
		SELECT erp_user_id FROM `sys_user`
	</select>
    <select id="findByNameAndCode" resultType="cn.com.countrygarden.bi.main.model.twerp.hm.TbSysUser">
        <![CDATA[
          SELECT u.UserCode, u.UserName, u.LoginCode,u.DepCode,d.DepName,u.MobileTel
          FROM [HM_wygl_new_1853].[dbo].[Tb_Sys_User] AS u
          INNER JOIN [HM_wygl_new_1853].[dbo].[Tb_Sys_Department] as d on d.DepCode = u.DepCode and (d.IsDelete is null OR d.IsDelete!='1')
          WHERE u.IsDelete = 0
        ]]>
        <if test="userQuery.excludeIds!=null  and userQuery.excludeIds.size()>0 ">
            <![CDATA[
              AND u.UserCode NOT IN
            ]]>
            <foreach item="item" index="index" collection="userQuery.excludeIds" open="("     separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="userQuery.employeeCodes!=null ">
            <![CDATA[
              AND u.LoginCode LIKE concat('%',#{userQuery.employeeCodes},'%')
            ]]>
        </if>
        <if test="userQuery.employeeNames!=null ">
            <![CDATA[
              AND u.UserName LIKE concat('%',#{userQuery.employeeNames},'%')
            ]]>
        </if>
        <if test="userQuery.depName!=null ">
            <![CDATA[
              AND d.DepName LIKE concat('%',#{userQuery.depName},'%')
            ]]>
        </if>
        <![CDATA[
          ORDER BY u.UserCode ASC
        ]]>
    </select>
    <select id="getUserName" resultType="java.lang.String" parameterType="list">
        SELECT  u.UserName,  u.OrganId
        FROM [HM_wygl_new_1853].[dbo].[Tb_Sys_User] AS u
        where u.UserCode in
        <foreach collection="userCodeList" index="index" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
    </select>
</mapper>