<?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="vip.xiaonuo.disk.mapper.StorageMapper">


    <select id="getUserStorageList" resultType="vip.xiaonuo.disk.vo.storage.StorageBeanVO">
        select us.ID as userId, us.ACCOUNT as userName, us.NAME as nickName, st.TOTAL_STORAGE_SIZE as totalStorageSize  from STORAGE as st left join SYS_USER as us on st.USER_ID = us.ID
        <where>
                us.DELETE_FLAG = 'NOT_DELETE'
            <if test="getUserStorageDTO.usernameOrNickname != null and getUserStorageDTO.usernameOrNickname != ''">
                and (us.NAME LIKE CONCAT('%', #{getUserStorageDTO.usernameOrNickname}, '%') OR us.ACCOUNT LIKE CONCAT('%', #{getUserStorageDTO.usernameOrNickname}, '%'))
            </if>
            <if test="getUserStorageDTO.roleId != null">
                and us.ID in (select re.OBJECT_ID from SYS_RELATION as re where re.CATEGORY = 'SYS_USER_HAS_ROLE' and re.TARGET_ID = #{getUserStorageDTO.roleId})
            </if>
        </where>
    </select>

    <select id="getUserRoleNameListById" resultType="java.lang.String">
        select ro.NAME from SYS_ROLE as ro left join  SYS_RELATION as re on ro.ID = re.TARGET_ID where re.OBJECT_ID = #{userId}
    </select>


</mapper>
