package com.lutao.cloud.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lutao.cloud.admin.api.entity.SysPosition;
import com.lutao.cloud.admin.service.SysPositionService;
import com.lutao.cloud.common.core.util.MessageInfo;
import com.lutao.cloud.common.log.annotation.SysLog;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 
 *
 * @author guoyc
 * @date 2022-05-30 10:50:38
 */
@RestController
@AllArgsConstructor
@RequestMapping("/sys/position" )
@Api(value = "sys/position", tags = "职位管理")
public class SysPositionController{

    private final SysPositionService sysPositionService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param sysPosition 
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('admin_sysposition_view')" )
    public MessageInfo<IPage<SysPosition>> getSysPositionPage(Page page, SysPosition sysPosition){
        return MessageInfo.ok(sysPositionService.page(page, Wrappers.query(sysPosition)));
    }


    /**
     * 通过id查询
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('admin_sysposition_view')" )
    public MessageInfo<SysPosition> getById(@PathVariable("id" ) Integer id){
        return MessageInfo.ok(sysPositionService.getById(id));
    }

    /**
     * 新增
     * @param sysPosition 
     * @return R
     */
    @ApiOperation(value = "新增", notes = "新增")
    @SysLog("新增" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('admin_sysposition_add')" )
    public MessageInfo<Boolean> save(@RequestBody SysPosition sysPosition){
        return MessageInfo.ok(sysPositionService.save(sysPosition));
    }

    /**
     * 修改
     * @param sysPosition 
     * @return R
     */
    @ApiOperation(value = "修改", notes = "修改")
    @SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('admin_sysposition_edit')" )
    public MessageInfo<Boolean> updateById(@RequestBody SysPosition sysPosition){
        return MessageInfo.ok(sysPositionService.updateById(sysPosition));
    }

    /**
     * 通过id删除
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    @SysLog("通过id删除" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('admin_sysposition_del')" )
    public MessageInfo<Boolean> removeById(@PathVariable Integer id){
        return MessageInfo.ok(sysPositionService.removeById(id));
    }

}
