package com.xly.erp.module.usr.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xly.erp.module.usr.entity.UserPermission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserPermissionMapper extends BaseMapper<UserPermission> {

    @Delete("DELETE FROM tUserPermission WHERE iUserId = #{userId}")
    int deleteByUserId(@Param("userId") Integer userId);

    @Select("SELECT up.iCategoryId FROM tUserPermission up "
            + "INNER JOIN tPermissionCategory pc ON pc.iIncrement = up.iCategoryId "
            + "WHERE up.iUserId = #{userId} AND pc.bDeleted = 0 "
            + "ORDER BY up.iIncrement ASC")
    List<Integer> selectCategoryIdsByUserId(@Param("userId") Integer userId);
}
