package com.yanzhu.jh.bigscreen.web.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.SysRoleEnum;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/bgscreen/dept")
public class DeptController extends BaseController {
    @Autowired
    private ISysDeptService deptService;

    @Autowired
    private ISysDeptService sysDeptService;
    @GetMapping("/list")
    public AjaxResult  list(){
        long roleId=SecurityUtils.getRoleId();
        if(roleId<4){
            return  getDeptTypeA();
        }
        return  getDeptTypeC();
    }

    /**
     * c.子公司用户只能查看自己子公司相关的项目
     * @return
     */
    private AjaxResult getDeptTypeC() {
        Long deptId= sysDeptService.getZGSDeptId(getDeptId());
        SysDept dept=new SysDept();
        dept.setComFlag("1");
        dept.setDeptId(deptId);
        List list=deptService.selectAllDeptList(dept);
        return  AjaxResult.success(list);
    }

    /**
     * 集团公司用户和集团子公司的用户可以看到所有菜单
     * 1,2,3
     * @return
     */
    private AjaxResult getDeptTypeA(){
        SysDept dept=new SysDept();
        dept.setComFlag("1");
        List list=deptService.selectAllDeptList(dept);
        return  AjaxResult.success(list);
    }
}
