<?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="shop.alien.mapper.StorePlatformUserRoleMapper">

    <!-- 根据店铺ID查询子账号列表（连表查询） -->
    <select id="querySubAccounts" resultType="shop.alien.entity.store.vo.SubAccountVo">
        SELECT
            sur.id AS userId,
            spur.account_name AS accountName,
            sur.phone AS phone,
            spr.role_id AS roleId,
            spr.role_name AS roleName,
            spur.store_id AS storeId,
            0 AS permissionCount
        FROM store_platform_user_role spur
        INNER JOIN store_user sur ON spur.user_id = sur.id
        LEFT JOIN store_platform_role spr ON spur.role_id = spr.role_id
        WHERE spur.store_id = #{storeId}
          AND sur.delete_flag = 0
          AND spur.delete_flag = 0
        <if test="accountName != null and accountName != ''">
            AND (spur.account_name LIKE CONCAT('%', #{accountName}, '%') )
        </if>
        <if test="phone != null and phone != ''">
            AND sur.phone LIKE CONCAT('%', #{phone}, '%')
        </if>
        <if test="roleName != null and roleName != ''">
            AND spr.role_name LIKE CONCAT('%', #{roleName}, '%')
        </if>
        ORDER BY spur.created_time DESC
    </select>

</mapper>

