package com.heketai.website.web;


import com.heketai.website.common.result.BaseResult;
import com.heketai.website.service.ISysUserRoleService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户角色关联表 前端控制器
 * </p>
 *
 * @author xjl
 * @since 2019-11-14
 */
@RestController
@RequestMapping("/sysUserRole")
public class SysUserRoleController {
    @Autowired
    private ISysUserRoleService userRoleService;

    @Autowired
    private RedisTemplate redisTemplate;
    private String fKey = "4BAF93F9-FE61-8F5E7435-501C2D5011C2";


    @RequestMapping("/distributionRole")
    @ApiOperation(value = "给用户分配角色", notes = "给用户分配角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "roleIds", value = "角色ids", required = true, paramType = "query")
    })
    public BaseResult distributionRole(@RequestParam Integer userId, @RequestParam String roleIds) {
        userRoleService.distributionRole(userId, roleIds);
        redisTemplate.delete(fKey);
        return BaseResult.success();
    }
}
