package com.gz.controller.system;

import cn.hutool.core.lang.tree.Tree;
import com.gz.core.annotation.TraceLog;
import com.gz.dto.system.MenuDTO;
import com.gz.service.system.MenuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author LiuchangLan
 * @date 2020/9/4 16:00
 */
@RestController
@RequestMapping("system/menu")
public class MenuController {

    @Resource
    private MenuService menuService;

    /**
     * @description 增
     * @author LiuChangLan
     * @since 2020/9/4 14:46
     */
    @PostMapping("insert")
    @TraceLog(module = "菜单管理",business = "新增菜单")
    public Integer insert(@RequestBody MenuDTO menuDTO){
        return menuService.insert(menuDTO);
    }

    /**
     * @description 删
     * @author LiuChangLan
     * @since 2020/9/4 14:46
     */
    @DeleteMapping("delete")
    @TraceLog(module = "菜单管理",business = "删除菜单")
    public Integer delete(Integer id){
        return menuService.delete(id);
    }

    /**
     * @description 改
     * @author LiuChangLan
     * @since 2020/9/4 14:46
     */
    @PostMapping("update")
    @TraceLog(module = "菜单管理",business = "修改菜单")
    public Integer update(@RequestBody MenuDTO menuDTO){
        return menuService.update(menuDTO);
    }

    /**
     * @description 查(给分页参数查分页 没给查全部)
     * @author LiuChangLan
     * @since 2020/9/4 14:46
     */
    @GetMapping("select")
    @TraceLog(module = "菜单管理",business = "查询所有菜单")
    public List<MenuDTO> select(){
        return menuService.select();
    }

    /**
     * @description 根据主键查询
     * @author LiuChangLan
     * @since 2020/9/4 16:36
     */
    @GetMapping("selectByPrimaryKey")
    @TraceLog(module = "菜单管理",business = "查询菜单详细信息")
    public MenuDTO selectByPrimaryKey(Integer id){
        return menuService.selectByPrimaryKey(id);
    }

    /**
     * @description 查询菜单按照排序
     * @author LiuChangLan
     * @since 2020/9/7 16:47
     */
    @GetMapping("selectByOrder")
    @TraceLog(module = "菜单管理",business = "根据排序查询菜单")
    public List<MenuDTO> selectByOrder(){
        return menuService.selectByOrder();
    }

    /**
     * @description 查询菜单树
     * @author LiuChangLan
     * @since 2020/9/7 16:49
     */
    @GetMapping("getMenuTree")
    @TraceLog(module = "菜单管理",business = "查询菜单树")
    List<Tree<String>> getMenuTree(){
        return menuService.getMenuTree();
    }
}
