package com.css.simulation.resource.server.app.service;

import api.common.pojo.vo.system.MenuVO;
import api.common.util.ObjectUtil;
import com.css.simulation.resource.server.infra.util.AuthUtil;
import com.css.simulation.resource.server.infra.db.mysql.mapper.MenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuService {

    @Autowired
    MenuMapper menuMapper;

    public List<MenuVO> getMenuTree() {
        List<MenuVO> menus = menuMapper.getMenuTree();
        //List<MenuVO> treeList = ObjectUtil.listToTree(menus, "0", MenuVO::getId, MenuVO::getParentId, MenuVO::getChildren, MenuVO::setChildren);
        List<MenuVO> menuVOS = ObjectUtil.listToTree(menus);//注解方式转tree
        return menuVOS;
    }

    public List<MenuVO> getMyMenuTree() {
        String roleCode = AuthUtil.getCurrentUserRoleCode();
        List<MenuVO> menus = menuMapper.getMyMenuTree(roleCode);
        List<MenuVO> menuVOS = ObjectUtil.listToTree(menus);//注解方式转tree
        return menuVOS;
    }
}
