<?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="io.dataease.base.mapper.ext.ExtUserMapper">

    <resultMap id="BaseResultMap" type="io.dataease.base.domain.User">
        <id column="id" jdbcType="VARCHAR" property="id"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="email" jdbcType="VARCHAR" property="email"/>
        <result column="password" jdbcType="VARCHAR" property="password"/>
        <result column="status" jdbcType="VARCHAR" property="status"/>
        <result column="create_time" jdbcType="BIGINT" property="createTime"/>
        <result column="update_time" jdbcType="BIGINT" property="updateTime"/>
        <result column="language" jdbcType="VARCHAR" property="language"/>
        <result column="last_workspace_id" jdbcType="VARCHAR" property="lastWorkspaceId"/>
        <result column="last_organization_id" jdbcType="VARCHAR" property="lastOrganizationId"/>
        <result column="phone" jdbcType="VARCHAR" property="phone"/>
    </resultMap>

    <select id="getUserList" resultMap="BaseResultMap">
        select u.id, u.name, u.email, u.phone, u.language, u.status, u.source,
        u.last_organization_id, u.last_workspace_id, u.language, u.create_time, u.update_time
        from `user` u
        <where>
            <if test="userRequest.id != null">
                AND u.id like CONCAT('%', #{userRequest.id},'%')
            </if>
            <if test="userRequest.name != null">
                AND u.name like CONCAT('%', #{userRequest.name},'%')
            </if>
            <if test="userRequest.email != null">
                AND u.email like CONCAT('%', #{userRequest.email},'%')
            </if>
        </where>
        order by u.update_time desc
    </select>
    <!--修改密码-->
    <update id="updatePassword" parameterType="io.dataease.base.domain.User">
    update user
    set
       password=#{password,jdbcType=VARCHAR},
       update_time = #{updateTime,jdbcType=BIGINT}
    where  id=#{id,jdbcType=VARCHAR}
   </update>
    <select id="getDefaultLanguage" parameterType="java.lang.String" resultType="java.lang.String">
    select param_value from system_parameter
    where param_key=#{paramKey,jdbcType=VARCHAR}
   </select>

    <select id="searchUser" parameterType="java.lang.String" resultType="io.dataease.base.domain.User">
        select id, name, email, last_organization_id, last_workspace_id from `user` where id like CONCAT('%', #{condition},'%') or email like CONCAT('%', #{condition},'%') limit 100;
    </select>

    <select id="queryNameByIds" resultType="io.dataease.base.domain.User">
        select id, name
        from `user`
        WHERE id IN
        <foreach collection="list" item="id" index="index"
                 open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>

</mapper>
