package jj.tech.paolu.biz.webadmin.service;

import jj.tech.paolu.biz.webadmin.dao.TreeMapper;
import jj.tech.paolu.biz.webadmin.vo.MenuTree;
import jj.tech.paolu.repository.mybatis.dao.SysMenuMapper;
import jj.tech.paolu.repository.mybatis.dao.support.SysMenuDynamicSqlSupport;
import jj.tech.paolu.repository.mybatis.entity.SysMenu;
import jj.tech.paolu.utils.R;
import org.mybatis.dynamic.sql.render.RenderingStrategies;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import static org.mybatis.dynamic.sql.SqlBuilder.*;

@Service
public class MenuService {

    @Autowired OrgService orgService;
    @Autowired TreeMapper treeMapper;
    @Autowired SuperSysAdminComponent superSysAdminComponent;
    /**
     * 查询某个用户具有权限的菜单列表
     * @param userId
     * @return
     */
    List<SysMenu> getAllMenuByUserId(String userId){
        List<SysMenu> menuList = new ArrayList<>();
        if(userId.equals(superSysAdminComponent.id)) {//系统管理员拥有全部菜单权限
            var from = select(SysMenuMapper.selectList).from(SysMenuDynamicSqlSupport.sysMenu)
                    .orderBy(SysMenuDynamicSqlSupport.id,SysMenuDynamicSqlSupport.sort);
            SelectStatementProvider provider = from.build().render(RenderingStrategies.MYBATIS3);
            List<MenuTree> list = treeMapper.selectManyMenu(provider);
            menuList.addAll(list);
            return menuList;
        }
        else{
        	return null;
        }
    }

    /**
     * 获得“个人证书审核权限”的ID
     * @return
     */
    public String getPersonCheckMenuId() {

        return "226856895174934528";//现在的权限没有类似于COde一样的业务不变编码，只能用id来判断了。
    }
}
