package org.dromara.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.dromara.system.domain.SysUserTenant;
import org.dromara.system.domain.vo.SysUserTenantVO;

import java.util.List;

@Mapper
public interface SysUserTenantMapper extends BaseMapper<SysUserTenant> {

    @Select("SELECT " +
        "     sut.user_id, " +
        "     sut.tenant_id, " +
        "     st.store_name tenantName  " +
        "FROM " +
        "     sys_user_tenant sut " +
        "     LEFT JOIN sys_tenant st ON sut.tenant_id = st.tenant_id  " +
        "WHERE " +
        "     sut.user_id = #{userId}  " +
        "     AND st.type = #{type}  " +
        "     AND st.del_flag = 0  " +
        "     AND st.`status` = 0")
    List<SysUserTenantVO> getUserTenantList(@Param("userId") Long userId, @Param("type") int type);
}
