多线程提高获取预览url的速度
This commit is contained in:
parent
aede9d3701
commit
b763bec632
@ -2,25 +2,29 @@ package com.zhgd.xmgl.async;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.zhgd.jeecg.common.mybatis.EntityMap;
|
||||
import com.zhgd.mqtt.bean.PushPayload;
|
||||
import com.zhgd.mqtt.server.IMqttSender;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.CompanyConfig;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
|
||||
import com.zhgd.xmgl.modules.basicdata.mapper.SystemUserMapper;
|
||||
import com.zhgd.xmgl.modules.basicdata.service.ICompanyConfigService;
|
||||
import com.zhgd.xmgl.modules.project.entity.ProjectVideoConfig;
|
||||
import com.zhgd.xmgl.modules.project.service.IProjectService;
|
||||
import com.zhgd.xmgl.push.service.UniPushService;
|
||||
import com.zhgd.xmgl.util.HikVideoUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.AsyncResult;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -334,4 +338,23 @@ public class AsyncCommon {
|
||||
String kdTopic = scope + userId;
|
||||
mqttPushClient.sendToMqtt(kdTopic, pushMessage.toString());
|
||||
}
|
||||
|
||||
@Async("asyncExecutor")
|
||||
public Future<HashMap<String, Object>> getPlayUrlAsync(ProjectVideoConfig videoConfig, EntityMap entityMap) {
|
||||
String serialNumber = MapUtils.getString(entityMap, "serialNumber");
|
||||
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||
String url = HikVideoUtil.callPostApiGetPreviewURL(serialNumber, "hls", null, videoConfig.getAccount(),
|
||||
videoConfig.getPassword(), videoConfig.getAppId(), videoConfig.getAppSecret());
|
||||
if (StringUtils.isNotEmpty(url)) {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("url", url);
|
||||
map.putAll(entityMap);
|
||||
Future<HashMap<String, Object>> future = new AsyncResult<>(map);
|
||||
return future;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
|
||||
/**
|
||||
@ -281,7 +282,7 @@ public class VideoItemController {
|
||||
@ApiOperation(value = "根据项目sn查询监控点预览取流URL列表(海康)", httpMethod = "GET")
|
||||
@ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "query", required = true, dataType = "String")
|
||||
@GetMapping("/getPlayUrlFromHikvision")
|
||||
public Result<Map<String, Object>> getPlayUrlFromHikvision(String projectSn) {
|
||||
public Result<Map<String, Object>> getPlayUrlFromHikvision(String projectSn) throws ExecutionException, InterruptedException {
|
||||
return Result.success(videoItemService.getPlayUrlFromHikvision(projectSn));
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import com.zhgd.xmgl.modules.video.entity.VideoItem;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* @Description: 视频设备列表
|
||||
@ -66,5 +67,5 @@ public interface IVideoItemService extends IService<VideoItem> {
|
||||
|
||||
List<VideoItem> viListAndTenAlarm(String projectSn);
|
||||
|
||||
Map<String, Object> getPlayUrlFromHikvision(String projectSn);
|
||||
Map<String, Object> getPlayUrlFromHikvision(String projectSn) throws ExecutionException, InterruptedException;
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zhgd.jeecg.common.execption.OpenAlertException;
|
||||
import com.zhgd.jeecg.common.mybatis.EntityMap;
|
||||
import com.zhgd.xmgl.async.AsyncCommon;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.DictionariesRecord;
|
||||
import com.zhgd.xmgl.modules.basicdata.mapper.DictionariesRecordMapper;
|
||||
import com.zhgd.xmgl.modules.basicdata.service.ICompanyService;
|
||||
@ -29,6 +30,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* @Description: 视频设备列表
|
||||
@ -40,6 +43,8 @@ import java.util.*;
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Slf4j
|
||||
public class VideoItemServiceImpl extends ServiceImpl<VideoItemMapper, VideoItem> implements IVideoItemService {
|
||||
@Autowired
|
||||
private AsyncCommon asyncCommon;
|
||||
@Autowired
|
||||
private VideoItemMapper videoItemMapper;
|
||||
@Autowired
|
||||
@ -534,7 +539,7 @@ public class VideoItemServiceImpl extends ServiceImpl<VideoItemMapper, VideoItem
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getPlayUrlFromHikvision(String projectSn) {
|
||||
public Map<String, Object> getPlayUrlFromHikvision(String projectSn) throws ExecutionException, InterruptedException {
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("projectSn", projectSn);
|
||||
ProjectVideoConfig videoConfig = getEnableProjectVideoConfigByProjectSn(paramMap);
|
||||
@ -542,19 +547,17 @@ public class VideoItemServiceImpl extends ServiceImpl<VideoItemMapper, VideoItem
|
||||
Map<String, Object> rsMap = new HashMap<>();
|
||||
List<Map<String, Object>> urlMaps = new ArrayList<>();
|
||||
rsMap.put("urlMaps", urlMaps);
|
||||
List<Future<HashMap<String, Object>>> futures = new ArrayList<>();
|
||||
for (EntityMap entityMap : videoList) {
|
||||
String serialNumber = MapUtils.getString(entityMap, "serialNumber");
|
||||
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||
String url = HikVideoUtil.callPostApiGetPreviewURL(serialNumber, "hls", null, videoConfig.getAccount(),
|
||||
videoConfig.getPassword(), videoConfig.getAppId(), videoConfig.getAppSecret());
|
||||
if (StringUtils.isNotEmpty(url)) {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("url", url);
|
||||
map.putAll(entityMap);
|
||||
urlMaps.add(map);
|
||||
}
|
||||
futures.add(asyncCommon.getPlayUrlAsync(videoConfig, entityMap));
|
||||
}
|
||||
for (Future<HashMap<String, Object>> future : futures) {
|
||||
HashMap<String, Object> map = future.get();
|
||||
if (map != null) {
|
||||
urlMaps.add(map);
|
||||
}
|
||||
}
|
||||
return rsMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user