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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class MenuService {

    @Autowired
    private 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);
        return ObjectUtil.listToTree(menus);
    }

    public List<MenuVO> getMyMenuTree() {
        String roleCode = AuthUtil.getCurrentUserRoleCode();
        log.info("当前用户角色为：" + roleCode);
        List<MenuVO> menus = menuMapper.getMyMenuTree(roleCode);
        log.info("当前用户菜单为：" + menus);
        List<MenuVO> menuVOS = ObjectUtil.listToTree(menus);
        log.info("当前用户菜单树为：" + menuVOS);
        return menuVOS;
    }
}
