package com.usoftchina.bi.server.dao.dashboard;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * @Author chenwei
 * @Date 2019-05-31
 */
@Mapper
@Repository
public interface DefaultDashboardMapper {

    @Select("SELECT DASHBOARD_ID AS \"id\", BD_NAME AS \"name\" FROM BI_DASHBOARDS_USER LEFT JOIN BI_DASHBOARDS ON ID = DASHBOARD_ID WHERE USER_ID = #{userId}")
    Map<String, String> selectDashboardIdByUserId(@Param("userId") int userId);

    @Insert("INSERT INTO BI_DASHBOARDS_USER(USER_ID,DASHBOARD_ID) VALUES(#{userId,jdbcType=INTEGER},#{dashboardId,jdbcType=INTEGER})")
    void save(@Param("userId") int userId, @Param("dashboardId") int dashboardId);

    @Delete("DELETE FROM BI_DASHBOARDS_USER WHERE DASHBOARD_ID = #{dashboardId,jdbcType=INTEGER}")
    void delete(@Param("dashboardId") int dashboardId);

    @Delete("DELETE FROM BI_DASHBOARDS_USER WHERE USER_ID = #{userId,jdbcType=INTEGER}")
    void deleteByUserId(@Param("userId") int userId);
}
