This commit is contained in:
xiaofajia 2024-12-17 17:18:30 +08:00
parent 2fbbcb0daa
commit a94700e4f6

View File

@ -21,10 +21,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Arrays; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -99,4 +96,44 @@ public class InspectionUtilController {
map.put("file", fileCount); map.put("file", fileCount);
return success(map); return success(map);
} }
@GetMapping("/getRoleNameByIds")
public CommonResult<?> getRoleNameByIds(@RequestParam("ids") List<Long> ids) {
Map<Long, List<Long>> idToRoleIds = ids.stream().collect(Collectors.toMap(id -> id, id -> permissionApi.getRoleIdsByUserId(id)));
if (CollUtil.isEmpty(idToRoleIds)){
return null;
}
List<RoleReqDTO> roleList = roleApi.getRoleList();
List<InspectionRoleCommon> roleCommons = Arrays.asList(InspectionRoleCommon.values());
List<String> codes = roleCommons.stream().map(InspectionRoleCommon::getCode).collect(Collectors.toList());
return success(idToRoleIds.entrySet().stream().collect(Collectors.toMap(
Map.Entry::getKey,
item -> {
String name = "未知岗位";
if (CollUtil.isEmpty(item.getValue())){
return name;
}
List<RoleReqDTO> roles = roleList.stream().filter(i -> item.getValue().contains(i.getId())).collect(Collectors.toList());
if (CollUtil.isEmpty(roles)) {
return name;
}
List<RoleReqDTO> inspectionRoles = roles.stream().filter(i -> codes.contains(i.getCode())).collect(Collectors.toList());
if (CollUtil.isEmpty(inspectionRoles)){
return name;
}
Integer index = Integer.MAX_VALUE;
for (RoleReqDTO inspectionRole : inspectionRoles) {
InspectionRoleCommon inspectionRoleCommon = InspectionRoleCommon.valueOf(inspectionRole.getCode().toUpperCase());
if (ObjectUtil.isEmpty(inspectionRoleCommon)) {
continue;
}
Integer weight = inspectionRoleCommon.getWeight();
if (weight < index) {
index = weight;
name = inspectionRole.getName();
}
}
return name;
})));
}
} }