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

/**
 * 用户许可表
 *
 * @author admin
 * @date Thu Oct 10 00:00:00 CST 2019
 */
@RestController
@AllArgsConstructor
@RequestMapping("/userpermission")
@Api(tags="用户许可表接口")
public class UserpermissionController {

    private final  UserpermissionService userpermissionService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param userpermission 用户许可表
    * @return
    */
    @GetMapping("/page" )
    //@ApiOperation(value = "分页查询")
    public ResultRespone getUserpermissionPage(Page page, @ModelAttribute Userpermission userpermission) {
      return ResultRespone.success(userpermissionService.page(page, Wrappers.query(userpermission)));
    }


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

    /**
     * 新增用户许可表
     * @param userpermission 用户许可表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增用户许可表" )
    //@ApiOperation(value = "新增用户许可表")
    @PostMapping
    public ResultRespone save(@RequestBody Userpermission userpermission) {
      return ResultRespone.success(userpermissionService.save(userpermission));
    }

    /**
     * 修改用户许可表
     * @param userpermission 用户许可表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改用户许可表" )
    //@ApiOperation(value = "修改用户许可表")
    @PutMapping
    public ResultRespone updateById(@RequestBody Userpermission userpermission) {
      return ResultRespone.success(userpermissionService.updateById(userpermission));
    }

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