package com.ssm.controller;


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

import com.github.pagehelper.PageInfo;
import com.ssm.manage.entity.RlRolePower;
import com.ssm.manage.dto.RlRolePowerDto;
import com.ssm.manage.response.GenericResponse;
import com.ssm.manage.response.PageResponse;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.RlRolePowerService;
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;

/**
 * 新登录（门店角色关联菜单）(RlRolePower)表控制层
 *
 * @author makejava
 * @since 2023-12-13 15:34:03
 */
@RestController
@RequestMapping("rlRolePower")
@Slf4j
@Api(tags = "新登录（门店角色关联菜单）")
public class RlRolePowerController {
    /**
     * 服务对象
     */
    @Autowired
    private RlRolePowerService rlRolePowerService;

/**
 * 通过主键查询单条数据
 *
 * @param id 主键
 * @return
 @GetMapping("{id}")
 @ApiOperation("通过主键查询单条数据")
 //@RequiresPermissions("system:rlRolePower:query")
 public ResultVo get(@PathVariable Serializable id) {
 return this.rlRolePowerService.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:rlRolePower:query")
    public PageResponse<RlRolePower> listPage(RlRolePowerDto dto) {
        PageResponse<RlRolePower> pageResponse = new PageResponse<>();
        PageInfo<RlRolePower> pageInfo = new PageInfo<>();
        try {
            pageInfo = this.rlRolePowerService.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 rlRolePower
     * @return
     */
    @PostMapping
    @ApiOperation("新增新登录（门店角色关联菜单）")
//@RequiresPermissions("system:rlRolePower:add")
    public GenericResponse add(@RequestBody RlRolePower rlRolePower) {
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        try {
            i = this.rlRolePowerService.save(rlRolePower);
        } 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 rlRolePower
     * @return
     */
    @PutMapping
    @ApiOperation("编辑新登录（门店角色关联菜单）")
//@RequiresPermissions("system:rlRolePower:edit")
    public GenericResponse edit(@RequestBody RlRolePower rlRolePower) {
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        try {
            i = this.rlRolePowerService.updateByPrimaryKey(rlRolePower);
        } 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:rlRolePower:delete")
    public GenericResponse delete(@PathVariable Long id) {
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        try {
            RlRolePower rlRolePower = new RlRolePower();
            i = this.rlRolePowerService.delete(rlRolePower);
        } 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;
    }

}
