/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.base.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.base.dto.RoleMenuDTO;
import com.tofly.base.entity.Role;
import com.tofly.base.entity.RoleMenu;
import com.tofly.base.service.RoleMenuService;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 角色菜单表
 *
 * @author admin
 * @date Thu Oct 10 00:00:00 CST 2019
 */
@RestController
@AllArgsConstructor
@RequestMapping("/rolemenu")
@Api(tags="角色菜单表接口")
public class RoleMenuController {

    private final  RoleMenuService roleMenuService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param roleMenu 角色菜单表
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getRoleMenuPage(Page page, @ModelAttribute RoleMenu roleMenu) {
      return ResultRespone.success(roleMenuService.page(page, Wrappers.query(roleMenu)));
    }


    /**
     * 通过id查询角色菜单表
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    //@ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id" ) Long id) {
      return ResultRespone.success(roleMenuService.getById(id));
    }

    /**
     * 新增角色菜单表
     * @param roleMenu 角色菜单表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增角色菜单表" )
    //@ApiOperation(value = "新增角色菜单表")
    @PostMapping("/save")
    public ResultRespone save(@RequestBody RoleMenu roleMenu) {
        return ResultRespone.success(roleMenuService.save(roleMenu));
    }

    /**
     * 修改角色菜单表
     * @param roleMenu 角色菜单表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改角色菜单表" )
    //@ApiOperation(value = "修改角色菜单表")
    @PutMapping
    public ResultRespone updateById(@RequestBody RoleMenu roleMenu) {
      return ResultRespone.success(roleMenuService.updateById(roleMenu));
    }

    /**
     * 通过id删除角色菜单表
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除角色菜单表" )
    //@ApiOperation(value = "通过ID删除角色菜单表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable Long id) {
      return ResultRespone.success(roleMenuService.removeById(id));
    }

//    @ToFlyAppLog(title="新增角色菜单表" )
//    @ApiOperation(tags = "角色管理", value = "新增角色菜单")
//    @PostMapping("/addBatch")
//    public ResultRespone addBatch(@RequestBody List<RoleMenu> roleMenu){
//        return ResultRespone.success(roleMenuService.saveBatch(roleMenu));
//    }

    @ToFlyAppLog(title="修改角色菜单" )
    @ApiOperation(tags = "角色管理", value = "修改角色菜单")
    @PutMapping("/updateBatch")
    public ResultRespone updateBatch(@RequestBody RoleMenu[] roleMenu){
        return ResultRespone.success(roleMenuService.updateBatch(roleMenu));
    }

    /**
     * 角色菜单绑定
     *
     */
    @ToFlyAppLog
    @ApiOperation(value = "角色菜单绑定")
    @PostMapping("/roleMenuBound")
    public ResultRespone roleMenuBound(@RequestBody RoleMenuDTO roleMenuDTO) {
        return ResultRespone.success(roleMenuService.roleMenuBound(roleMenuDTO));
    }
}
