李学松 2 жил өмнө
parent
commit
07986aa397

+ 16 - 16
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmDeptTaskTypeConfigController.java

@@ -30,6 +30,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
 
 /**
  * 部门任务类型配置控制层
@@ -94,26 +95,25 @@ public class WmDeptTaskTypeConfigController {
 			});
 		}
 		// 查询上级的deptId
-		List<SysDeptRelation> relationList = sysDeptRelationService.list(Wrappers.<SysDeptRelation>lambdaQuery()
+		List<SysDeptRelation> ancestorDeptRelations = sysDeptRelationService.list(Wrappers.<SysDeptRelation>lambdaQuery()
 				.eq(SysDeptRelation::getDescendant, deptId)
 				.ne(SysDeptRelation::getAncestor, deptId)
 				.ne(SysDeptRelation::getAncestor, 1));
 		// 上级dept对应任务类型配置
-		if (CollUtil.isNotEmpty(relationList)) {
-			relationList.forEach(relation ->  {
-				WmDeptTaskTypeConfig ancestorDeptTaskTypeConfig = wmDeptTaskTypeConfigService.getOne(Wrappers.<WmDeptTaskTypeConfig>lambdaQuery()
-						.eq(WmDeptTaskTypeConfig::getDeptId, relation.getAncestor()));
-				if (ancestorDeptTaskTypeConfig != null) {
-					List<WmDeptTaskTypeConfigJsonDTO> ancestorConfigJsonDTOList =
-							JSON.parseArray(ancestorDeptTaskTypeConfig.getTaskTypeJson(), WmDeptTaskTypeConfigJsonDTO.class);
-					ancestorConfigJsonDTOList
-							.forEach(configJsonDTO -> {
-								if (configJsonDTO.getQualifiedTask() && configJsonDTO.getAssociateLower()) {
-									configed.set(true);
-								}
-							});
-				}
-			});
+		if (CollUtil.isNotEmpty(ancestorDeptRelations)) {
+			List<Integer> ancestorIds = ancestorDeptRelations.stream().mapToInt(SysDeptRelation::getAncestor).boxed().collect(Collectors.toList());
+			List<WmDeptTaskTypeConfig> ancestorDeptTaskTypeConfigs = wmDeptTaskTypeConfigService.list(Wrappers.<WmDeptTaskTypeConfig>lambdaQuery().eq(WmDeptTaskTypeConfig::getDeptId, ancestorIds));
+			if (CollUtil.isNotEmpty(ancestorDeptTaskTypeConfigs)) {
+				List<WmDeptTaskTypeConfigJsonDTO> ancestorConfigJsonDTOList =
+						ancestorDeptTaskTypeConfigs.stream()
+								.flatMap(config -> JSON.parseArray(config.getTaskTypeJson(), WmDeptTaskTypeConfigJsonDTO.class).stream()).collect(Collectors.toList());
+
+				ancestorConfigJsonDTOList.forEach(configJsonDTO -> {
+					if (configJsonDTO.getQualifiedTask() && configJsonDTO.getAssociateLower()) {
+						configed.set(true);
+					}
+				});
+			}
 		}
 		resultMap.put("config", configed.get());
 		return R.ok(resultMap);