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 javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -34,7 +31,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
*
* @author 小李
* @date 15:36 2024/12/15
**/
**/
@RestController
@RequestMapping("/admin-api/inspection/util")
public class InspectionUtilController {
@ -58,10 +55,10 @@ public class InspectionUtilController {
* @date 15:15 2024/12/15
**/
@GetMapping("/getRoleName")
public CommonResult<?> getRoleName(){
public CommonResult<?> getRoleName() {
String name = "未知岗位";
List<Long> roleIdsByUserId = permissionApi.getRoleIdsByUserId(SecurityFrameworkUtils.getLoginUserId());
if (CollUtil.isEmpty(roleIdsByUserId)){
if (CollUtil.isEmpty(roleIdsByUserId)) {
return success(name);
}
List<RoleReqDTO> roleList = roleApi.getRoleList();
@ -69,17 +66,17 @@ public class InspectionUtilController {
List<InspectionRoleCommon> roleCommons = Arrays.asList(InspectionRoleCommon.values());
List<String> codes = roleCommons.stream().map(InspectionRoleCommon::getCode).collect(Collectors.toList());
List<RoleReqDTO> inspectionRoles = roles.stream().filter(item -> codes.contains(item.getCode())).collect(Collectors.toList());
if (CollUtil.isEmpty(inspectionRoles)){
if (CollUtil.isEmpty(inspectionRoles)) {
return success(name);
}
Integer index = Integer.MAX_VALUE;
for (RoleReqDTO inspectionRole : inspectionRoles) {
InspectionRoleCommon inspectionRoleCommon = InspectionRoleCommon.valueOf(inspectionRole.getCode().toUpperCase());
if (ObjectUtil.isEmpty(inspectionRoleCommon)){
if (ObjectUtil.isEmpty(inspectionRoleCommon)) {
continue;
}
Integer weight = inspectionRoleCommon.getWeight();
if (weight < index){
if (weight < index) {
index = weight;
name = inspectionRole.getName();
}
@ -88,7 +85,7 @@ public class InspectionUtilController {
}
@GetMapping("/getTypeCount")
public CommonResult<?> getTypeCount(@RequestParam("partnerId")Long partnerId){
public CommonResult<?> getTypeCount(@RequestParam("partnerId") Long partnerId) {
Map<String, Long> map = new HashMap<>();
Long staffCount = roleApi.selectListByRoleId();
map.put("staff", staffCount);
@ -99,4 +96,44 @@ public class InspectionUtilController {
map.put("file", fileCount);
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;
})));
}
}