package com.cpop.system.business.controller.backstage;

import com.cpop.core.annontation.OperationLog;
import com.cpop.core.base.R;
import com.cpop.core.base.enums.OperationLogEnum;
import com.cpop.system.business.bo.MenuBo;
import com.cpop.system.business.bo.MenuListBo;
import com.cpop.system.business.service.MenuService;
import com.cpop.system.business.vo.MenuVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统菜单表 控制层。
 *
 * @author DB
 * @since 2023-10-19
 */
@RestController
@Api(tags = "通用系统菜单表接口")
@RequestMapping("/backstage/menu")
public class BackstageMenuController {

    @Autowired
    private MenuService menuService;

    /**
     * @descriptions 获取系统菜单树列表
     * @author DB
     * @date 2023/09/07 15:48
     * @param bo 请求参数
     * @return com.jambox.core.base.R<java.util.List<OamMenuVo>>
     */
    @PreAuthorize("@aps.hasPermission('system:menu:list')")
    @ApiOperation("获取系统菜单树列表")
    @GetMapping("/getSysMenuTreeList")
    public R<List<MenuVo>> getSysMenuTreeList(MenuListBo bo) {
        List<MenuVo> list = menuService.getSysMenuTreeList(bo);
        return R.ok(list);
    }

    /**
     * @descriptions 获取目录与菜单树
     * @author DB
     * @date 2023/09/07 17:41
     * @return com.jambox.core.base.R<java.util.List<com.jambox.oam.business.vo.OamMenuVo>>
     */
    @ApiOperation("获取目录与菜单树")
    @GetMapping("/getDirectoryAndMenuTreeList")
    public R<List<MenuVo>> getDirectoryAndMenuTreeList() {
        List<MenuVo> list = menuService.getDirectoryAndMenuTreeList();
        return R.ok(list);
    }

    /**
     * @descriptions 新增系统菜单
     * @author DB
     * @date 2023/09/07 17:45
     * @param bo 请求参数
     * @return com.jambox.core.base.R<java.lang.Void>
     */
    @PreAuthorize("@aps.hasPermission('system:menu:insert')")
    @ApiOperation("新增系统菜单")
    @PostMapping("/insertSysMenu")
    public R<Void> insertSysMenu(@RequestBody @Validated MenuBo bo) {
        menuService.insertSysMenu(bo);
        return R.ok();
    }

    /**
     * @Description: 修改系统菜单表
     * @param bo 请求参数
     * @Author: DB
     * @Date: 2023/5/10 16:01
     **/
    @PreAuthorize("@aps.hasPermission('system:menu:update')")
    @ApiOperation("修改系统菜单")
    @PutMapping("/updateSysMenu")
    public R<Void> updateSysMenu(@RequestBody @Validated MenuBo bo) {
        menuService.updateSysMenu(bo);
        return R.ok();
    }

    /**
     * @Description: 删除系统菜单表
     * @param id 主键id
     * @Author: DB
     * @Date: 2023/5/10 16:01
     **/
    @PreAuthorize("@aps.hasPermission('system:menu:remove')")
    @ApiOperation("删除系统菜单")
    @DeleteMapping("/removeSysMenu/{id}")
    public R<Void> removeSysMenu(@PathVariable String id) {
        menuService.removeSysMenu(id);
        return R.ok();
    }

}
