package com.weather.controller;


import com.weather.common.AjaxResult;
import com.weather.common.BaseController;
import com.weather.entity.SysRole;
import com.weather.service.ISysRoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.security.SecureRandom;

/**
 * <p>
 * 角色信息表 前端控制器
 * </p>
 *
 * @author feng
 * @since 2023-09-01
 */
@RestController
@RequestMapping("/sys-role")
public class SysRoleController extends BaseController {

    @Autowired
    private ISysRoleService roleService;
    /**
     * 新增角色
     */
    @ApiOperation(value = "新增角色")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysRole role)
    {

        SecureRandom secureRandom = new SecureRandom();
        long randomInt = secureRandom.nextInt(100000000);
        role.setRoleId(randomInt);
        role.setDeptCheckStrictly(1);
        role.setMenuCheckStrictly(1);

        return toAjax(roleService.insertRole(role));


      /*  if (!roleService.checkRoleNameUnique(role))
        {
            return error("新增角色'" + role.getRoleName() + "'失败，角色名称已存在");
        }
        else if (!roleService.checkRoleKeyUnique(role))
        {
            return error("新增角色'" + role.getRoleName() + "'失败，角色权限已存在");
        }
        role.setCreateBy(SecurityUtils.getUsername());
        return toAjax(roleService.insertRole(role));*/


    }

}

