package com.goldenwater.web.controller.system;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.domain.entity.SysMenu;
import com.goldenwater.common.utils.SecurityUtils;
import com.goldenwater.system.service.ISysMenuService;
import com.goldenwater.system.domain.vo.RouterVo;

/**
 * 前台菜单控制器
 */
@RestController
@RequestMapping("/system/front")
public class SysFrontMenuController
{
    @Autowired
    private ISysMenuService menuService;

    /**
     * 获取前台菜单路由
     */
    @GetMapping("/getRouters")
    public AjaxResult getFrontRouters()
    {
        Long userId = SecurityUtils.getUserId();
        List<SysMenu> menus = menuService.selectFrontMenuTreeByUserId(userId);
        List<RouterVo> routers = menuService.buildFrontMenus(menus);
        return AjaxResult.success(routers);
    }

    /**
     * 获取前台菜单列表
     */
    @GetMapping("/menuList")
    public AjaxResult getFrontMenuList()
    {
        Long userId = SecurityUtils.getUserId();
        List<SysMenu> menus = menuService.selectFrontMenuTreeByUserId(userId);
        return AjaxResult.success(menus);
    }
}