/*
 * 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.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.base.entity.RoleDept;
import com.tofly.base.service.RoleDeptService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

/**
 * 角色部门关系表
 *
 * @author admin
 * @date Thu Oct 10 00:00:00 CST 2019
 */
@RestController
@AllArgsConstructor
@RequestMapping("/roledept")
@Api(tags="角色部门关系表接口")
public class RoleDeptController {

    private final  RoleDeptService roleDeptService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param roleDept 角色部门关系表
    * @return
    */
    @GetMapping("/page" )
    //@ApiOperation(value = "分页查询")
    public ResultRespone getRoleDeptPage(Page page, @ModelAttribute RoleDept roleDept) {
      return ResultRespone.success(roleDeptService.page(page, Wrappers.query(roleDept)));
    }


    /**
     * 通过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(roleDeptService.getById(id));
    }

    /**
     * 新增角色部门关系表
     * @param roleDept 角色部门关系表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增角色部门关系表" )
    //@ApiOperation(value = "新增角色部门关系表")
    @PostMapping
    public ResultRespone save(@RequestBody RoleDept roleDept) {
      return ResultRespone.success(roleDeptService.save(roleDept));
    }

    /**
     * 修改角色部门关系表
     * @param roleDept 角色部门关系表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改角色部门关系表" )
    //@ApiOperation(value = "修改角色部门关系表")
    @PutMapping
    public ResultRespone updateById(@RequestBody RoleDept roleDept) {
      return ResultRespone.success(roleDeptService.updateById(roleDept));
    }

    /**
     * 通过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(roleDeptService.removeById(id));
    }
}
