RUserRoleController.java 1.06 KB
package vion.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import vion.dto.RUserRoleDTO;
import vion.model.RUserRole;
import vion.service.IRUserRoleService;

import java.util.List;
import java.util.stream.Collectors;

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

    private final IRUserRoleService rUserRoleService;
    private final Converter converter;

    @PostMapping("/rUserRole")
    @SaCheckPermission(value = "user:role:edit", orRole = "admin")
    public String saveOrUpdateRUserRole(@RequestBody List<RUserRoleDTO> dto) {
        List<Long> userIdList = dto.stream().map(RUserRoleDTO::getUserId).collect(Collectors.toList());
        rUserRoleService.lambdaUpdate().in(RUserRole::getUserId, userIdList).remove();
        return rUserRoleService.saveBatch(converter.convert(dto, RUserRole.class)) ? "创建成功" : "创建失败";
    }
}