RRoleResourceController.java 1.27 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.RRoleResourceDTO;
import vion.model.RRoleResource;
import vion.service.IRRoleResourceService;

import java.util.Arrays;

/**
 * 角色资源关联表
 */
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class RRoleResourceController {

    private final IRRoleResourceService roleResourceService;

    @PostMapping("/rRoleRes")
    @SaCheckPermission("role:resource:edit")
    public String saveOrUpdateRUserRole(@RequestBody RRoleResourceDTO dto) {
        roleResourceService.lambdaUpdate().eq(RRoleResource::getRoleId, dto.getRoleId()).remove();
        Arrays.stream(dto.getResourceIds()).map(resourceId -> {
            RRoleResource roleResource = new RRoleResource();
            roleResource.setRoleId(resourceId);
            roleResource.setResourceId(dto.getRoleId());
            return roleResource;
        }).forEach(roleResourceService::save);
        return "创建成功";
    }

}