|
|
@@ -29,12 +29,17 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.TimeoutException;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class PanelServiceImpl implements PanelService {
|
|
|
|
|
|
+ public static final int TIMEOUT = 3;
|
|
|
@Autowired
|
|
|
private ResumptionService resumptionService;
|
|
|
|
|
|
@@ -54,124 +59,95 @@ public class PanelServiceImpl implements PanelService {
|
|
|
private IProtectionService protectionService;
|
|
|
|
|
|
@Override
|
|
|
- public List<PanelResultVo> selectPage() {
|
|
|
+ public List<PanelResultVo> selectPage() throws ExecutionException, InterruptedException, TimeoutException {
|
|
|
|
|
|
List<Long> roles = RemoteCallHandlerExecutor.executeRemoteCall(
|
|
|
() -> roleService.getUserRoleId(SecurityUtils.getUserId(), SecurityConstants.FROM_SOURCE),
|
|
|
ErrorMsgConstants.QUERY_USER_ROLE_ERROR);
|
|
|
|
|
|
PanelListDto panelListDto = PanelAdapter.getMapperSelectParam(SecurityUtils.getLoginUser().getOrgId(),
|
|
|
- roles,SecurityUtils.getUserId());
|
|
|
+ roles, SecurityUtils.getUserId());
|
|
|
|
|
|
- List<PanelListVo> resultList = Collections.synchronizedList(new ArrayList<>(6));
|
|
|
|
|
|
//履职任务
|
|
|
- CompletableFuture<List<PanelListVo>> resumptionTaskFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
- return resumptionService.selectCurUserTaskList(panelListDto);
|
|
|
- }).whenComplete((resumptionTaskList, throwable) -> {
|
|
|
- if (ObjectUtil.isNotEmpty(resumptionTaskList)) {
|
|
|
- resumptionTaskList.forEach(vo->vo.setType(PanelTypeEnums.RESUMPTION.getCode()));
|
|
|
- resultList.addAll(resumptionTaskList);
|
|
|
- }
|
|
|
- if (throwable != null) {
|
|
|
- log.error("resumptionTaskFuture Exception error.", throwable);
|
|
|
- }
|
|
|
- });
|
|
|
+ CompletableFuture<List<PanelListVo>> resumptionTaskFuture = CompletableFuture.supplyAsync(() ->
|
|
|
+ resumptionService.selectCurUserTaskList(panelListDto)
|
|
|
+ );
|
|
|
|
|
|
//布撤防
|
|
|
- CompletableFuture<List<PanelListVo>> protectionTaskFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
- return protectionService.selectCurUserTaskList(panelListDto);
|
|
|
- }).whenComplete((protectionTaskList, throwable) -> {
|
|
|
- if (ObjectUtil.isNotEmpty(protectionTaskList)) {
|
|
|
- protectionTaskList.forEach(vo->vo.setType(PanelTypeEnums.PROTECTION.getCode()));
|
|
|
- resultList.addAll(protectionTaskList);
|
|
|
- }
|
|
|
- if (throwable != null) {
|
|
|
- log.error("protectionTaskFuture Exception error.", throwable);
|
|
|
- }
|
|
|
- });
|
|
|
+ CompletableFuture<List<PanelListVo>> protectionTaskFuture = CompletableFuture.supplyAsync(() ->
|
|
|
+ protectionService.selectCurUserTaskList(panelListDto)
|
|
|
+ );
|
|
|
|
|
|
//监控调阅任务
|
|
|
- CompletableFuture<List<PanelListVo>> monitorTaskFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
- return coreMonitoringRetrievalTaskService.selectCurUserTaskList(panelListDto);
|
|
|
- }).whenComplete((monitorTaskList, throwable) -> {
|
|
|
- if (ObjectUtil.isNotEmpty(monitorTaskList)) {
|
|
|
- monitorTaskList.forEach(vo->vo.setType(PanelTypeEnums.MONITORING_RETRIEVAL.getCode()));
|
|
|
- resultList.addAll(monitorTaskList);
|
|
|
- }
|
|
|
- if (throwable != null) {
|
|
|
- log.error("monitorTaskFuture Exception error.", throwable);
|
|
|
- }
|
|
|
- });
|
|
|
+ CompletableFuture<List<PanelListVo>> monitorTaskFuture = CompletableFuture.supplyAsync(() ->
|
|
|
+ coreMonitoringRetrievalTaskService.selectCurUserTaskList(panelListDto)
|
|
|
+ );
|
|
|
|
|
|
//安全检查任务
|
|
|
- CompletableFuture<List<PanelListVo>> safetyTaskFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
- return safetyTaskService.selectCurUserTaskList(panelListDto);
|
|
|
- }).whenComplete((safetyTaskList, throwable) -> {
|
|
|
- if (ObjectUtil.isNotEmpty(safetyTaskList)) {
|
|
|
- safetyTaskList.forEach(vo->vo.setType(PanelTypeEnums.SAFETY_CHECK.getCode()));
|
|
|
- resultList.addAll(safetyTaskList);
|
|
|
- }
|
|
|
- if (throwable != null) {
|
|
|
- log.error("safetyTaskFuture Exception error.", throwable);
|
|
|
- }
|
|
|
- });
|
|
|
+ CompletableFuture<List<PanelListVo>> safetyTaskFuture = CompletableFuture.supplyAsync(() ->
|
|
|
+ safetyTaskService.selectCurUserTaskList(panelListDto)
|
|
|
+ );
|
|
|
|
|
|
|
|
|
//预案演练任务
|
|
|
- CompletableFuture<List<PanelListVo>> drillTaskFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
- return drillTaskService.selectCurUserTaskList(panelListDto);
|
|
|
- }).whenComplete((drillTaskList, throwable) -> {
|
|
|
- if (ObjectUtil.isNotEmpty(drillTaskList)) {
|
|
|
- drillTaskList.forEach(vo->vo.setType(PanelTypeEnums.DRILL.getCode()));
|
|
|
- resultList.addAll(drillTaskList);
|
|
|
- }
|
|
|
- if (throwable != null) {
|
|
|
- log.error("drillTaskFuture Exception error.", throwable);
|
|
|
- }
|
|
|
- });
|
|
|
+ CompletableFuture<List<PanelListVo>> drillTaskFuture = CompletableFuture.supplyAsync(() ->
|
|
|
+ drillTaskService.selectCurUserTaskList(panelListDto)
|
|
|
+ );
|
|
|
|
|
|
//教育培训任务
|
|
|
- CompletableFuture<List<PanelListVo>> eduTrainingTaskFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
- return eduTrainingTaskService.selectCurUserTaskList(panelListDto);
|
|
|
- }).whenComplete((eduTrainingTaskList, throwable) -> {
|
|
|
- if (ObjectUtil.isNotEmpty(eduTrainingTaskList)) {
|
|
|
- eduTrainingTaskList.forEach(vo->vo.setType(PanelTypeEnums.EDU_TRAINING.getCode()));
|
|
|
- resultList.addAll(eduTrainingTaskList);
|
|
|
- }
|
|
|
- if (throwable != null) {
|
|
|
- log.error("eduTrainingTaskFuture Exception error.", throwable);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- List<CompletableFuture<List<PanelListVo>>> futureList = ListUtil.list(true,
|
|
|
- resumptionTaskFuture,
|
|
|
- protectionTaskFuture,
|
|
|
- monitorTaskFuture,
|
|
|
- safetyTaskFuture,
|
|
|
- drillTaskFuture,
|
|
|
- eduTrainingTaskFuture);
|
|
|
-
|
|
|
-
|
|
|
- try {
|
|
|
- // 多个任务
|
|
|
- CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0])).join();
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("CompletableFuture.allOf Exception error.", e);
|
|
|
- }
|
|
|
-
|
|
|
+ CompletableFuture<List<PanelListVo>> eduTrainingTaskFuture = CompletableFuture.supplyAsync(() ->
|
|
|
+ eduTrainingTaskService.selectCurUserTaskList(panelListDto)
|
|
|
+ );
|
|
|
+ /* List<PanelListVo> resumptionTaskResult = resumptionTaskFuture.get(TIMEOUT, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ List<PanelListVo> protectionTaskResult = protectionTaskFuture.get(TIMEOUT, TimeUnit.SECONDS);
|
|
|
+ List<PanelListVo> monitorTaskResult = monitorTaskFuture.get(TIMEOUT, TimeUnit.SECONDS);
|
|
|
+ List<PanelListVo> safetyTaskResult = safetyTaskFuture.get(TIMEOUT, TimeUnit.SECONDS);
|
|
|
+ List<PanelListVo> drillTaskResult = drillTaskFuture.get(TIMEOUT, TimeUnit.SECONDS);
|
|
|
+ List<PanelListVo> eduTrainingTaskResult = eduTrainingTaskFuture.get(TIMEOUT, TimeUnit.SECONDS);
|
|
|
+ dealResult(resumptionTaskResult,protectionTaskResult,monitorTaskResult,safetyTaskResult,drillTaskResult,eduTrainingTaskResult);
|
|
|
+ List<PanelListVo> resultList = Stream.of(resumptionTaskResult, protectionTaskResult, monitorTaskResult, safetyTaskResult, drillTaskResult, eduTrainingTaskResult)
|
|
|
+ .flatMap(Collection::stream)
|
|
|
+ .collect(Collectors.toList());*/
|
|
|
+
|
|
|
+ CompletableFuture<Void> allQueries = CompletableFuture.allOf(
|
|
|
+ resumptionTaskFuture, protectionTaskFuture, monitorTaskFuture,
|
|
|
+ safetyTaskFuture, drillTaskFuture, eduTrainingTaskFuture
|
|
|
+ );
|
|
|
+
|
|
|
+ allQueries.get(TIMEOUT, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ List<PanelListVo> resultList = Stream.of(
|
|
|
+ resumptionTaskFuture.join(), protectionTaskFuture.join(), monitorTaskFuture.join(),
|
|
|
+ safetyTaskFuture.join(), drillTaskFuture.join(), eduTrainingTaskFuture.join()
|
|
|
+ )
|
|
|
+ .flatMap(Collection::stream)
|
|
|
+ .collect(Collectors.toList());
|
|
|
//将resultList根据type字段分组,并排序
|
|
|
Map<Integer, List<PanelListVo>> listMap = resultList.stream().sorted(Comparator.comparing(PanelListVo::getType)).collect(Collectors.groupingBy(PanelListVo::getType));
|
|
|
List<PanelResultVo> list = new ArrayList<PanelResultVo>();
|
|
|
for (Integer type : listMap.keySet()) {
|
|
|
PanelResultVo vo = new PanelResultVo();
|
|
|
vo.setTaskType(type);
|
|
|
+ List<PanelListVo> data = listMap.get(type);
|
|
|
+ vo.setNums(data.size());
|
|
|
vo.setTaskTypeText(PanelTypeEnums.getName(type));
|
|
|
- vo.setDataList(listMap.get(type));
|
|
|
+ vo.setDataList(data);
|
|
|
list.add(vo);
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private void dealResult(List<PanelListVo> resumptionTaskResult, List<PanelListVo> protectionTaskResult, List<PanelListVo> monitorTaskResult, List<PanelListVo> safetyTaskResult, List<PanelListVo> drillTaskResult, List<PanelListVo> eduTrainingTaskResult) {
|
|
|
+ resumptionTaskResult.forEach(item->{item.setType(PanelTypeEnums.RESUMPTION.getCode());});
|
|
|
+ protectionTaskResult.forEach(item->{item.setType(PanelTypeEnums.PROTECTION.getCode());});
|
|
|
+ monitorTaskResult.forEach(item->{item.setType(PanelTypeEnums.MONITORING_RETRIEVAL.getCode());});
|
|
|
+ safetyTaskResult.forEach(item->{item.setType(PanelTypeEnums.SAFETY_CHECK.getCode());});
|
|
|
+ drillTaskResult.forEach(item->{item.setType(PanelTypeEnums.DRILL.getCode());});
|
|
|
+ eduTrainingTaskResult.forEach(item->{item.setType(PanelTypeEnums.EDU_TRAINING.getCode());});
|
|
|
+
|
|
|
+ }
|
|
|
}
|