RRoleResourceController.java
1.3 KB
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.github.linpeilie.Converter;
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.List;
import java.util.stream.Collectors;
/**
* 角色资源关联
*/
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class RRoleResourceController {
private final IRRoleResourceService roleResourceService;
private final Converter converter;
@PostMapping("/rRoleRes")
@SaCheckPermission(value = "role:resource:edit", orRole = "admin")
public String saveOrUpdateRUserRole(@RequestBody List<RRoleResourceDTO> dto) {
List<Long> roleIdList = dto.stream().map(RRoleResourceDTO::getRoleId).collect(Collectors.toList());
roleResourceService.lambdaUpdate().in(RRoleResource::getRoleId, roleIdList).remove();
return roleResourceService.saveBatch(converter.convert(dto, RRoleResource.class)) ? "创建成功" : "创建失败";
}
}