package cn.qinys.platform.upms.api.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.qinys.platform.entity.upms.UpmsUserRole;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * 用户角色关系表(UpmsUserRole)表数据库访问层
 *
 * @author makejava
 * @since 2024-02-27 17:18:51
 */
@Repository
@Mapper
public interface UpmsUserRoleMapper extends BaseMapper<UpmsUserRole> {

    /**
     * 用户的角色id
     *
     * @param userId
     * @return
     */
    @Select("SELECT role_id FROM upms_user_role WHERE user_id = #{userId}")
    List<String> selectRoleIds(@Param("userId") String userId);

    @Select("SELECT r.role_cn_name FROM upms_role r INNER JOIN upms_user_role ur ON r.id = ur.role_id WHERE ur.user_id = #{userId}")
    List<String> selectRoleNames(@Param("userId") String userId);

    /**
     * 修改
     *
     * @param userId
     */
    @Update("UPDATE upms_user_role SET active = 0 WHERE user_id = #{userId}")
    void setUserUnActive(@Param("userId") String userId);

    /**
     * 修改
     *
     * @param userId
     */
    @Update("UPDATE upms_user_role SET active = 1 WHERE user_id = #{userId} AND role_id = #{roleId}")
    void setUserActive(@Param("userId") String userId, @Param("roleId") String roleId);


    /**
     * 删除用户角色
     * @param userId
     */
    @Delete("DELETE FROM upms_user_role WHERE user_id = #{userId}")
    void deleteUserRole(@Param("userId") String userId);
}

