package org.jeecg.modules.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.system.entity.SysUserRole;
import org.jeecg.modules.system.mapper.SysUserRoleMapper;
import org.jeecg.modules.system.service.ISysUserRoleService;
import org.springframework.stereotype.Service;

/**
 * 用户角色表 服务实现类 @Author scott
 *
 * @since 2018-12-21
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole>
    implements ISysUserRoleService {

  @Resource private SysUserRoleMapper sysUserRoleMapper;

  @Override
  public boolean isDeveloper() {
    LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    String username = sysUser.getUsername();
    List<String> adminRoleIdList = new ArrayList<>(); // 管理员角色id列表
    adminRoleIdList.add("admin");
    List<String> roles = sysUserRoleMapper.getRoleByUserName(username);
    for (String role : roles) {
      if (adminRoleIdList.contains(role)) {
        return true;
      }
    }
    return false;
  }
  @Override
  public boolean isAdmin() {
    LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    String username = sysUser.getUsername();
    List<String> adminRoleIdList = new ArrayList<>(); // 管理员角色id列表
    adminRoleIdList.add("admin");
    adminRoleIdList.add("adweb_admin");
    adminRoleIdList.add("seo_admin");
    adminRoleIdList.add("adweb_site_manager");
    adminRoleIdList.add("adweb_seo_manager");
    List<String> roles = sysUserRoleMapper.getRoleByUserName(username);
    for (String role : roles) {
      if (adminRoleIdList.contains(role)) {
        return true;
      }
    }
    return false;
  }

}
