<?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.njzscloud.dispose.sys.user.mapper.UserMapper">

    <resultMap id="pagingResultMap" autoMapping="true" type="com.njzscloud.dispose.sys.user.pojo.result.UserDetailResult">
        <id column="id" property="id"/>
        <association property="account" autoMapping="true" javaType="com.njzscloud.dispose.sys.user.pojo.result.UserAccountDetailResult">
            <id column="account_id" property="id"/>
            <result column="username" property="username"/>
            <result column="account_phone" property="phone"/>
        </association>
    </resultMap>

    <select id="paging" resultMap="pagingResultMap">
        SELECT a.id,
        a.nickname,
        a.avatar,
        a.phone,
        b.id account_id,
        b.username,
        b.phone account_phone,
        b.secret,
        b.wechat_openid,
        b.wechat_unionid,
        b.regdate,
        b.client_code,
        b.disabled
        FROM sys_user a
        INNER JOIN sys_user_account b ON b.user_id = a.id AND b.deleted = 0
        <if test="ew != null and ew.customSqlSegment != null and ew.customSqlSegment !=''">
            ${ew.customSqlSegment}
        </if>
    </select>
    <select id="selectUser" resultType="com.njzscloud.common.security.support.UserDetail">
        SELECT a.id      account_id,
               a.user_id,
               a.user_id id,
               a.secret,
               b.nickname,
               b.avatar,
               b.phone,
               a.disabled
        FROM sys_user_account a
                 INNER JOIN sys_user b ON a.user_id = b.id AND b.id = #{userId} AND b.deleted = 0
        WHERE a.deleted = 0
    </select>
    <select id="getRole" resultType="com.njzscloud.dispose.sys.role.pojo.entity.RoleEntity">
        SELECT *
        FROM sys_role
        WHERE role_code = #{roleCode}
    </select>
</mapper>
