package com.ibeetl.admin.core.service;

import cn.hutool.core.lang.Assert;
import com.ibeetl.admin.core.dao.CoreRoleDao;
import com.ibeetl.admin.core.entity.CoreRole;
import java.util.List;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.beetl.sql.core.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 描述: 字典 service，包含常规字典和级联字典的操作。
 *
 * @author : xiandafu
 */
@Slf4j
@Service
@Transactional
public class CoreRoleService extends CoreBaseService<CoreRole> {

  @Autowired
  private CoreRoleDao roleDao;

  /**
   * @param type
   *     ： R0 操作角色；R1 是工作流角色
   * @author 一日看尽长安花
   */
  public List<CoreRole> getAllRoles(String type) {

    return roleDao
        .getSQLManager()
        .lambdaQuery(CoreRole.class)
        .andEq(CoreRole::getType, Query.filterEmpty(type))
        .select();
  }
  public List<CoreRole> getRoles(Long userId) {

    Assert.notNull(userId,"用户角色不能为空");
    return roleDao.geRoles(userId);
  }
}
