RUserRoleController.java 1.19 KB
package vion.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
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 vion.dto.RUserRoleDTO;
import vion.model.RUserRole;
import vion.service.IRUserRoleService;

import java.util.Arrays;

/**
 * 用户角色表
 */
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class RUserRoleController {

    private final IRUserRoleService rUserRoleService;

    @PostMapping("/rUserRole")
    @SaCheckPermission("user:role:edit")
    public String saveOrUpdateRUserRole(@RequestBody RUserRoleDTO dto) {
        rUserRoleService.lambdaUpdate().eq(RUserRole::getUserId, dto.getUserId()).remove();
        Arrays.stream(dto.getRoleIds()).map(roleId -> {
            RUserRole rUserRole = new RUserRole();
            rUserRole.setUserId(dto.getUserId());
            rUserRole.setRoleId(roleId);
            return rUserRole;
        }).forEach(rUserRoleService::save);
        return "创建成功";
    }
}