<?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.diagbot.mapper.SysUserUaaMapper">

    <resultMap id="userUaaMap" type="com.diagbot.entity.SysUserUaa">
        <id column="id" property="id"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="creator" property="creator"/>
        <result column="modifier" property="modifier"/>
        <result column="password" property="password"/>
        <result column="username" property="username"/>
        <result column="type" property="type" />
    </resultMap>

    <resultMap id="userUaaHospMap" type="com.diagbot.entity.SysUserUaa">
        <id column="id" property="id"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="creator" property="creator"/>
        <result column="modifier" property="modifier"/>
        <result column="password" property="password"/>
        <result column="username" property="username"/>
        <result column="type" property="type" />
        <result column="hospitalId" property="hospitalId" />
    </resultMap>

    <select id="getByUserName" parameterType="java.lang.String" resultMap="userUaaMap">
		select u.*
		from sys_user u
        where is_deleted = 'N' and u.status = 1 and u.username= #{username}
	</select>

    <select id="getHospByUserName" parameterType="java.lang.String" resultMap="userUaaHospMap">
        SELECT
            u.*, uh.hospital_id AS hospitalId
        FROM
            sys_user u,
            sys_user_hospital uh,
            bas_hospital_info h
        WHERE
            u.is_deleted = 'N'
        AND u.status = 1
        AND u.username = #{username}
        AND u.id = uh.user_id
        AND uh.is_deleted = 'N'
        AND h.id = uh.hospital_id
        AND h.is_deleted = 'N'
	</select>
</mapper>
