package com.bonus.sgzb.app.controller;

import com.bonus.sgzb.app.domain.AppMenu;
import com.bonus.sgzb.app.service.AppMenuService;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.utils.SecurityUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author c liu
 * @date 2024/1/17
 */
@RestController
@RequestMapping("/base/appMenu")
public class AppMenuController extends BaseController {
    @Autowired
    private AppMenuService service;

    @ApiOperation(value = "查询所有菜单")
    @Log(title = "查询所有菜单", businessType = BusinessType.QUERY)
    @GetMapping("/getAllMenu")
    public AjaxResult getAllMenu()
    {
        List<AppMenu> list = service.getAllMenu();
        return AjaxResult.success("操作成功",list);
    }
    @ApiOperation(value = "查询个人菜单")
    @Log(title = "查询个人菜单", businessType = BusinessType.QUERY)
    @GetMapping("/getMenuById")
    public AjaxResult getMenuById(@RequestParam Long userId)
    {
        List<AppMenu> list = service.getMenuById(userId);
        return AjaxResult.success("操作成功",list);
    }

    @ApiOperation(value = "新增个人菜单")
    @Log(title = "新增个人菜单", businessType = BusinessType.INSERT)
    @PostMapping("/addMenuById")
    public AjaxResult addMenuById(@RequestBody AppMenu bean)
    {
        Long userId = SecurityUtils.getLoginUser().getUserid();
        return toAjax(service.addMenuById(bean.getMenuId(), userId));
    }

    @ApiOperation(value = "删除个人菜单")
    @Log(title = "删除个人菜单", businessType = BusinessType.INSERT)
    @DeleteMapping("/delMenuById")
    public AjaxResult delMenuById(@RequestBody AppMenu bean)
    {
        Long userId = SecurityUtils.getLoginUser().getUserid();
        return toAjax(service.delMenuById(bean.getMenuId(),userId));
    }
}
