package com.securitycontrol.system.controller;

import com.securitycontrol.common.core.web.controller.BaseController;
import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.common.log.annotation.Log;
import com.securitycontrol.common.log.enums.OperationType;
import com.securitycontrol.entity.system.dto.MenuDto;
import com.securitycontrol.entity.system.vo.MenuVo;
import com.securitycontrol.system.service.MenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 菜单管理层
 *
 * @author HeiZi
 */
@RestController
@RequestMapping("/sys/menu/")
public class MenuController extends BaseController {

    @Resource(name = "MenuService")
    private MenuService service;

    @ApiOperation(value = "获取菜单列表")
    @GetMapping("getMenuList")
    @Log(title = "系统管理", menu = "系统管理->菜单管理", grade = OperationType.QUERY_SYS, details = "查询菜单", type = "系统日志")
    public AjaxResult getMenuList(MenuDto dto) {
        return service.getMenuList(dto);
    }

    @ApiOperation(value = "新增菜单")
    @PostMapping("addMenu")
    @Log(title = "系统管理", menu = "系统管理->菜单管理", grade = OperationType.ADD_SYS, details = "新增菜单", type = "系统日志")
    public AjaxResult addMenu(@Valid @RequestBody MenuVo vo) {
        return service.addOrUpdateMenu(vo);
    }

    @ApiOperation(value = "修改菜单")
    @PostMapping("editMenu")
    @Log(title = "系统管理", menu = "系统管理->菜单管理", grade = OperationType.UPDATE_SYS, details = "修改菜单", type = "系统日志")
    public AjaxResult editMenu(@Valid @RequestBody MenuVo vo) {
        return service.addOrUpdateMenu(vo);
    }

    @ApiOperation(value = "菜单详情")
    @GetMapping("getMenuById")
    public AjaxResult getMenuById(MenuDto dto) {
        return service.getMenuById(dto);
    }

    @ApiOperation(value = "删除菜单")
    @PostMapping("delMenu")
    @Log(title = "系统管理", menu = "系统管理->菜单管理", grade = OperationType.DELETE_SYS, details = "删除菜单", type = "系统日志")
    public AjaxResult delMenu(MenuDto dto) {
        return service.delMenu(dto);
    }
}
