<?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.zsc.edu.gateway.modules.system.repo.UserRepository">
    <resultMap id="BaseResultMap" type="com.zsc.edu.gateway.modules.system.entity.User">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="username" jdbcType="VARCHAR" property="username"/>
        <result column="password" jdbcType="VARCHAR" property="password"/>
        <result column="role_id" jdbcType="BIGINT" property="roleId"/>
        <result column="dept_id" jdbcType="BIGINT" property="deptId"/>
        <result column="email" jdbcType="VARCHAR" property="email"/>
        <result column="phone" jdbcType="VARCHAR" property="phone"/>
        <result column="name" jdbcType="INTEGER" property="name"/>
        <result column="avatar" jdbcType="VARCHAR" property="avatar"/>
        <result column="address" jdbcType="VARCHAR" property="address"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="enable_state" jdbcType="BIT" property="enableState"/>
        <collection property="role" ofType="com.zsc.edu.gateway.modules.system.entity.Role">
            <id column="id" jdbcType="BIGINT" property="id"/>
            <result column="name" jdbcType="VARCHAR" property="name"/>
        </collection>
    </resultMap>

    <resultMap id="BaseResultMap1" type="com.zsc.edu.gateway.modules.system.vo.UserVo">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="username" jdbcType="VARCHAR" property="username"/>
        <result column="role_id" jdbcType="BIGINT" property="roleId"/>
        <result column="dept_id" jdbcType="BIGINT" property="deptId"/>
        <result column="email" jdbcType="VARCHAR" property="email"/>
        <result column="phone" jdbcType="VARCHAR" property="phone"/>
        <result column="name" jdbcType="INTEGER" property="name"/>
        <result column="avatar" jdbcType="VARCHAR" property="avatar"/>
        <result column="address" jdbcType="VARCHAR" property="address"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
    </resultMap>
    <sql id="Base_Column_List">
        id, username, password, email, phone, create_time
    </sql>

    <select id="selectByUsername" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
            *
        from sys_user su
                 left join sys_role sr on su.role_id = sr.id
        where su.username = #{username,jdbcType=VARCHAR}
    </select>

    <select id="page" resultType="com.zsc.edu.gateway.modules.system.vo.UserVo" resultMap="BaseResultMap1">
        select
            *
        from sys_user
        ${ew.customSqlSegment}
    </select>
    <select id="detail" resultType="com.zsc.edu.gateway.modules.system.vo.UserVo" resultMap="BaseResultMap1">
        select
            *
        from sys_user
        where id = #{id}
    </select>

</mapper>
