package com.srs.web.controller.common;

import com.srs.common.core.domain.entity.SysRole;
import com.srs.system.domain.SysPost;
import com.srs.system.service.ISysPostService;
import com.srs.system.service.ISysRoleService;

import java.util.List;

/**
 * @author zhy
 * @date 2023-09-09 15:41
 * @description 判断权限
 */
public class RoleBool
{


    /**
     * 判断不是学生
     * @author zhy
     * @date 2024-05-31 15:28:40
     * @param uid
     * @param roleService
     * @return
     **/

    public static boolean notStu(Long uid, ISysRoleService roleService){
        if(uid == 1L){
            return true;
        }
        List<Long> roleIds = roleService.selectRoleListByUserId(uid);
        if(roleIds == null || roleIds.size() == 0){
            return false;
        }

        boolean notStu = true;

        for (Long id: roleIds) {
            SysRole sysRole = roleService.selectRoleById(id);
            if(sysRole.getRoleKey().equals("teststu")){
                notStu = false;
            }
        }

        return notStu;
    }

    /**
     * 判断是学生
     * @author zhy
     * @date 2024-05-31 15:28:40
     * @param uid
     * @param roleService
     * @return
     **/

    public static boolean isStu(Long uid, ISysRoleService roleService){
        if(uid == 1L){
            return true;
        }
        List<Long> roleIds = roleService.selectRoleListByUserId(uid);
        if(roleIds == null || roleIds.size() == 0){
            return false;
        }

        boolean notStu = false;

        for (Long id: roleIds) {
            SysRole sysRole = roleService.selectRoleById(id);
            if(sysRole.getRoleKey().equals("teststu")){
                notStu = true;
            }
        }

        return notStu;
    }


    /**
     * 判断是不是辅导员
     * @author zhy
     * @date 2023-09-09 15:41:54
     * @return
     **/
    public static boolean isFdy(Long uid,ISysPostService sysPostService){
        if(uid == 1L){
            return true;
        }
        List<Long> postIds=sysPostService.selectPostListByUserId(uid);//根据用户id获取岗位

        if(postIds == null || postIds.size() == 0){
            return false;
        }

        boolean isFdy = false;
        for (Long id:
             postIds) {
            SysPost sysPost = sysPostService.selectPostById(id);
            if(sysPost.getPostCode().equals("fdy")){
                isFdy = true;
                return isFdy;
            }
        }
        return isFdy;
    }

    /**
     * 判断是不是教务处 学工
     * @author zhy
     * @date 2023-09-09 15:47:53
     * @param uid
     * @return
     **/
    public static boolean isJwc(Long uid,ISysPostService sysPostService){
        if(uid == 1L){
            return true;
        }
        List<Long> postIds=sysPostService.selectPostListByUserId(uid);//根据用户id获取岗位
        if(postIds == null || postIds.size() == 0){
            return false;
        }
        boolean isFdy = false;
        for (Long id:
                postIds) {
            SysPost sysPost = sysPostService.selectPostById(id);
            if(sysPost.getPostCode().equals("jwcgl")){
                isFdy = true;
                return isFdy;
            }
        }
        return isFdy;
    }

    /**
     * 判断是不是学务
     * @author zhy
     * @date 2023-09-09 15:47:53
     * @param uid
     * @return
     **/
    public static boolean isXw(Long uid,ISysPostService sysPostService){
        if(uid == 1L){
            return true;
        }
        List<Long> postIds=sysPostService.selectPostListByUserId(uid);//根据用户id获取岗位
        if(postIds == null || postIds.size() == 0){
            return false;
        }
        boolean isFdy = false;
        for (Long id:
                postIds) {
            SysPost sysPost = sysPostService.selectPostById(id);
            String postCode = sysPost.getPostCode();
            boolean xwgs = postCode.equals("xwgs");
            if(xwgs){
                isFdy = true;
                return isFdy;
            }
        }
        return isFdy;
    }
    public static boolean isEjxysj(Long uid,ISysPostService sysPostService){
        if(uid == 1L){
            return true;
        }
        List<Long> postIds=sysPostService.selectPostListByUserId(uid);//根据用户id获取岗位
        if(postIds == null || postIds.size() == 0){
            return false;
        }
        boolean isEjxysj = false;
        for (Long id:
                postIds) {
            SysPost sysPost = sysPostService.selectPostById(id);
            if(sysPost.getPostCode().equals("ejxysj")){
                isEjxysj = true;
                return isEjxysj;
            }
        }
        return isEjxysj;
    }

    /**
     * 判断是不是 辅导员 、学务、教务处 学工的中的一项
     * @author zhy
     * @date 2023-09-25 09:29:55
     * @param uid
     * @param sysPostService
     * @return
     **/
    public static boolean isHigh(Long uid,ISysPostService sysPostService){
        if(uid == 1L){
            return true;
        }
        List<Long> postIds=sysPostService.selectPostListByUserId(uid);//根据用户id获取岗位
        if(postIds == null || postIds.size() == 0){
            return false;
        }
        boolean isFdy = false;
        for (Long id:
                postIds) {
            SysPost sysPost = sysPostService.selectPostById(id);
            if(sysPost.getPostCode().equals("xwgs")){
                isFdy = true;
                return isFdy;
            }

            if(sysPost.getPostCode().equals("jwcgl")){
                isFdy = true;
                return isFdy;
            }

            if(sysPost.getPostCode().equals("fdy")){
                isFdy = true;
                return isFdy;
            }
        }
        return isFdy;
    }






}
