package com.yunfeiyun.agmp.pts.controller;

import com.yunfeiyun.agmp.pts.domain.PtsLink;
import com.yunfeiyun.agmp.pts.service.IPtsLinkService;
import com.yunfeiyun.agmp.pts.service.IPtsMenuService;
import com.yunfeiyun.agmp.common.constant.ErrorCode;
import com.yunfeiyun.agmp.common.core.controller.BaseController;
import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
import com.yunfeiyun.agmp.common.core.domain.model.IBaseMenu;
import com.yunfeiyun.agmp.common.core.domain.vo.RouterVo;
import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
import com.yunfeiyun.agmp.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 默认Controller
 *
 * @author 杨晓辉
 * @date 2023-05-23
 */
@RestController
@RequestMapping("/pts/console")
public class PtsConsoleController extends BaseController
{
    @Autowired
    private IPtsMenuService ptsMenuService;

    @Autowired
    private IPtsLinkService ptsLinkService;

    /**
     * 查询链接列表
     */
    @GetMapping("/getSysLinks")
    public TableDataInfo getSysLinks()
    {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(ErrorCode.SUCCESS.getCode());
        rspData.setMsg(ErrorCode.SUCCESS.getMessage());
        List<PtsLink> list = ptsLinkService.selectPtsLinkList(null,1);
        rspData.setData(list);
        rspData.setTotal(list.size());
        return rspData;
    }

    /**
     * 首页的菜单链接
     */
    @GetMapping("/getRouters")
    public AjaxResult getRouters()
    {
        String userId = SecurityUtils.getUserId();
        List<IBaseMenu> menus = ptsMenuService.selectMenuTreeByUserId(userId);
        List<RouterVo> routersVo = ptsMenuService.buildMenus(menus);
        return AjaxResult.success(ptsMenuService.buildConsoleMenus( routersVo ));
    }

}
