|
|
@@ -0,0 +1,126 @@
|
|
|
+package com.xunmei.iot.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
+import com.xunmei.common.core.thread.ThreadPoolConfig;
|
|
|
+import com.xunmei.iot.mapper.IotBoardMapper;
|
|
|
+import com.xunmei.iot.service.IotBoardService;
|
|
|
+import com.xunmei.iot.vo.board.IotBoardOverviewItemVo;
|
|
|
+import com.xunmei.iot.vo.board.IotBoardOverviewVo;
|
|
|
+import com.xunmei.system.api.RemoteOrgService;
|
|
|
+import com.xunmei.system.api.domain.SysOrg;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.TimeoutException;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class IotBoardServiceImpl implements IotBoardService {
|
|
|
+ @Autowired
|
|
|
+ RemoteOrgService remoteOrgService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IotBoardMapper iotBoardMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Qualifier(ThreadPoolConfig.SOC_EXECUTOR)
|
|
|
+ private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
+
|
|
|
+ private final Long TIMEOUT = 3L;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IotBoardOverviewVo overview(Long orgId) throws ExecutionException, InterruptedException, TimeoutException {
|
|
|
+ IotBoardOverviewVo vo = new IotBoardOverviewVo();
|
|
|
+ SysOrg org = remoteOrgService.selectOrgById(orgId, SecurityConstants.INNER);
|
|
|
+ CompletableFuture<IotBoardOverviewItemVo> hostFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
+ IotBoardOverviewItemVo result = iotBoardMapper.device(org.getPath());
|
|
|
+ if (ObjectUtil.isNull(result)) {
|
|
|
+ result = new IotBoardOverviewItemVo();
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ , threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ CompletableFuture<IotBoardOverviewItemVo> subsystemFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
+ IotBoardOverviewItemVo result = iotBoardMapper.subsystem(org.getPath());
|
|
|
+ if (ObjectUtil.isNull(result)) {
|
|
|
+ result = new IotBoardOverviewItemVo();
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ , threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ CompletableFuture<IotBoardOverviewItemVo> sensorFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
+ IotBoardOverviewItemVo result = iotBoardMapper.sensor(org.getPath());
|
|
|
+ if (ObjectUtil.isNull(result)) {
|
|
|
+ result = new IotBoardOverviewItemVo();
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ , threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ CompletableFuture<IotBoardOverviewItemVo> videoInterityFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
+ IotBoardOverviewItemVo result = iotBoardMapper.videoInterity(org.getPath());
|
|
|
+ if (ObjectUtil.isNull(result)) {
|
|
|
+ result = new IotBoardOverviewItemVo();
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ , threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ CompletableFuture<IotBoardOverviewItemVo> videoDaysFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
+ IotBoardOverviewItemVo result = iotBoardMapper.videoDays(org.getPath());
|
|
|
+ if (ObjectUtil.isNull(result)) {
|
|
|
+ result = new IotBoardOverviewItemVo();
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ , threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ CompletableFuture<IotBoardOverviewItemVo> videoQualityFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
+ IotBoardOverviewItemVo result = iotBoardMapper.videoQuality(org.getPath());
|
|
|
+ if (ObjectUtil.isNull(result)) {
|
|
|
+ result = new IotBoardOverviewItemVo();
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ , threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ CompletableFuture<IotBoardOverviewItemVo> dvrDiskFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
+ IotBoardOverviewItemVo result = iotBoardMapper.dvrDisk(org.getPath());
|
|
|
+ if (ObjectUtil.isNull(result)) {
|
|
|
+ result = new IotBoardOverviewItemVo();
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ , threadPoolTaskExecutor
|
|
|
+ );
|
|
|
+
|
|
|
+ CompletableFuture<Void> allQueries = CompletableFuture.allOf(
|
|
|
+ hostFuture, subsystemFuture, sensorFuture,
|
|
|
+ videoDaysFuture, videoInterityFuture, videoQualityFuture, dvrDiskFuture
|
|
|
+ );
|
|
|
+
|
|
|
+ allQueries.get(TIMEOUT, TimeUnit.SECONDS);
|
|
|
+ vo.setHost(hostFuture.get());
|
|
|
+ vo.setSubsystem(subsystemFuture.get());
|
|
|
+ vo.setSensor(sensorFuture.get());
|
|
|
+ vo.setDvrDisk(dvrDiskFuture.get());
|
|
|
+ vo.setVideoDays(videoDaysFuture.get());
|
|
|
+ vo.setVideoInterity(videoInterityFuture.get());
|
|
|
+ vo.setVideoQuality(videoQualityFuture.get());
|
|
|
+
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+}
|