package com.ssm.controller;


import javax.persistence.Column;
import javax.persistence.Id;

import com.github.pagehelper.PageInfo;
import com.ssm.manage.entity.RlRoleStaff;
import com.ssm.manage.dto.RlRoleStaffDto;
import com.ssm.manage.response.GenericResponse;
import com.ssm.manage.response.PageResponse;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.RlRoleStaffService;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

import java.io.Serializable;

import lombok.extern.slf4j.Slf4j;
import com.ssm.core.utils.SnowflakeUtil;

import java.util.Random;

/**
 * 角色(RlRoleStaff)表控制层
 *
 * @author makejava
 * @since 2023-12-13 15:34:06
 */
@RestController
@RequestMapping("rlRoleStaff")
@Slf4j
@Api(tags = "角色")
public class RlRoleStaffController {
    /**
     * 服务对象
     */
    @Autowired
    private RlRoleStaffService rlRoleStaffService;

/**
 * 通过主键查询单条数据
 *
 * @param id 主键
 * @return
 @GetMapping("{id}")
 @ApiOperation("通过主键查询单条数据")
 //@RequiresPermissions("system:rlRoleStaff:query")
 public ResultVo get(@PathVariable Serializable id) {
 return this.rlRoleStaffService.queryById(id);
 }
 */


    /**
     * 分页查询角色
     *
     * @param dto
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "10", required = true)
    })
//@RequiresPermissions("system:rlRoleStaff:query")
    public PageResponse<RlRoleStaff> listPage(RlRoleStaffDto dto) {
        PageResponse<RlRoleStaff> pageResponse = new PageResponse<>();
        PageInfo<RlRoleStaff> pageInfo = new PageInfo<>();
        try {
            pageInfo = this.rlRoleStaffService.selectPage(dto);
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.selectPage", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setPageInfo(pageInfo);
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        return pageResponse;
    }

    /**
     * 新增角色
     *
     * @param rlRoleStaff
     * @return
     */
    @PostMapping
    @ApiOperation("新增角色")
//@RequiresPermissions("system:rlRoleStaff:add")
    public GenericResponse add(@RequestBody RlRoleStaff rlRoleStaff) {
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        try {
            i = this.rlRoleStaffService.save(rlRoleStaff);
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.add:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        } else {
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }

    /**
     * 编辑角色
     *
     * @param rlRoleStaff
     * @return
     */
    @PutMapping
    @ApiOperation("编辑角色")
//@RequiresPermissions("system:rlRoleStaff:edit")
    public GenericResponse edit(@RequestBody RlRoleStaff rlRoleStaff) {
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        try {
            i = this.rlRoleStaffService.updateByPrimaryKey(rlRoleStaff);
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.add:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        } else {
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }

    /**
     * 根据主键删除角色
     *
     * @param id 主键
     * @return
     */
    @DeleteMapping("{id}")
    @ApiOperation("根据主键删除角色")
//@RequiresPermissions("system:rlRoleStaff:delete")
    public GenericResponse delete(@PathVariable Long id) {
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        try {
            RlRoleStaff rlRoleStaff = new RlRoleStaff();
            i = this.rlRoleStaffService.delete(rlRoleStaff);
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.add:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        } else {
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }

}
