|
|
@ -3,36 +3,25 @@ package com.kms.yg.df.service; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.kms.yg.df.domain.BsSgcDfSwtz; |
|
|
|
import com.kms.yg.df.mapper.BsSgcDfSwtzMapper; |
|
|
|
import com.alibaba.fastjson.annotation.JSONField; |
|
|
|
import com.kms.yxgh.df.dto.DfSpPlayDto; |
|
|
|
import com.kms.yxgh.df.dto.DfSpPlayQueDto; |
|
|
|
import com.kms.yxgh.df.dto.ReservoirListDto; |
|
|
|
import com.kms.yxgh.df.dto.ReservoirListQueDto; |
|
|
|
import com.kms.yxgh.util.DataCenterRestTemplateUtils; |
|
|
|
import com.kms.yxgh.util.RestTemplateUtil; |
|
|
|
import com.shuili.common.core.service.BaseService; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.Data; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.http.HttpEntity; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.http.*; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@ -41,44 +30,61 @@ import java.util.Objects; |
|
|
|
* @author kms |
|
|
|
* @date 2024-01-16 |
|
|
|
*/ |
|
|
|
@AllArgsConstructor |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
public class BsSgcDfSpPlayService { |
|
|
|
|
|
|
|
@Value("${dataSync.url:}") |
|
|
|
private String dataSyncUrl; |
|
|
|
@Value("#{${dataSync.paths:{}}}") |
|
|
|
private Map<String, String> paths = new HashMap<>(); |
|
|
|
|
|
|
|
@Value("${video.url:}") |
|
|
|
private String videoUrl; |
|
|
|
@Value("${video.phone:}") |
|
|
|
private String videoPhone; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private DataCenterRestTemplateUtils dataCenterRestTemplateUtils; |
|
|
|
static final String BELONG_URL ="http://19.25.35.205:31190/ZHSL_ZY/dws_rel_wmst_res"; |
|
|
|
static final String BELONG_URL = "dws_rel_wmst_res"; |
|
|
|
|
|
|
|
static final String OAUTH_TOKEN ="http://19.15.67.125:80/vsap-opp-service/resourceSharing/oauth/token"; |
|
|
|
static final String OAUTH_TOKEN = "/vsap-opp-service/resourceSharing/oauth/token"; |
|
|
|
|
|
|
|
static final String SP_PLAY_URL ="http://19.15.67.125:80/vsap-opp-service/resourceSharing/startTransform"; |
|
|
|
static final String SP_PLAY_URL = "/vsap-opp-service/resourceSharing/startTransform"; |
|
|
|
|
|
|
|
public ReservoirListDto reservoirList (ReservoirListDto dto) { |
|
|
|
ReservoirListDto listDto=new ReservoirListDto(); |
|
|
|
public ReservoirListDto reservoirList(ReservoirListDto dto) { |
|
|
|
ReservoirListDto listDto = new ReservoirListDto(); |
|
|
|
// 1. 获取水库信息
|
|
|
|
String belongReservoirUrlJson = dataCenterRestTemplateUtils.doPostRequest(BELONG_URL, dto); |
|
|
|
log.info("belongReservoirUrl-请求接口响应报文: {}", belongReservoirUrlJson); |
|
|
|
|
|
|
|
JSONObject belongReservoirJson = parseJson(belongReservoirUrlJson); |
|
|
|
if (belongReservoirJson == null || !isSuccess(belongReservoirJson)) { |
|
|
|
log.warn("获取水库信息失败,响应: {}", belongReservoirUrlJson); |
|
|
|
return listDto; |
|
|
|
String uri = paths.get(BELONG_URL); |
|
|
|
if (StringUtils.isEmpty(uri) || StringUtils.isEmpty(dataSyncUrl)) { |
|
|
|
return new ReservoirListDto(); |
|
|
|
} |
|
|
|
JSONArray reservoirData = parseJsonArray(belongReservoirJson.get("data")); |
|
|
|
if (reservoirData == null || reservoirData.isEmpty()) { |
|
|
|
log.warn("水库信息数据为空:{}",reservoirData.toString()); |
|
|
|
return listDto; |
|
|
|
String belongReservoirUrlJson = dataCenterRestTemplateUtils.doPostRequest(dataSyncUrl + uri, dto); |
|
|
|
|
|
|
|
DataResponse response = JSON.parseObject(belongReservoirUrlJson, DataResponse.class); |
|
|
|
ReservoirListDto result = new ReservoirListDto(); |
|
|
|
if (response.isSuccess()) { |
|
|
|
result.setCameraIds(response.getData().stream().map(Item::getWmstCode).collect(Collectors.toList())); |
|
|
|
} |
|
|
|
List<String> list=new ArrayList<String>(); |
|
|
|
for (int i = 0; i < reservoirData.size(); i++) { |
|
|
|
Map<String,String> map = (Map) reservoirData.get(0); |
|
|
|
list.add(map.get("RES_CODE").toString()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Data |
|
|
|
public static class DataResponse { |
|
|
|
private String msg; |
|
|
|
private String code; |
|
|
|
private List<Item> data = new ArrayList<>(); |
|
|
|
|
|
|
|
public Boolean isSuccess() { |
|
|
|
return "0".equals(getCode()); |
|
|
|
} |
|
|
|
listDto.setCameraIds(list); |
|
|
|
return listDto; |
|
|
|
} |
|
|
|
|
|
|
|
@Data |
|
|
|
public static class Item { |
|
|
|
@JSONField(name = "WMST_CODE") |
|
|
|
private String wmstCode; |
|
|
|
} |
|
|
|
|
|
|
|
public DfSpPlayDto play(DfSpPlayQueDto dto) { |
|
|
|
DfSpPlayDto rest = new DfSpPlayDto(); |
|
|
@ -98,32 +104,39 @@ public class BsSgcDfSpPlayService { |
|
|
|
dto.setToken(token); |
|
|
|
// 3. 调用第三方接口获取播放地址
|
|
|
|
String playOauthTokenUrlJson = getSpPlayUrls(dto); |
|
|
|
log.info("spPlayUrl-请求接口响应报文: {}", playOauthTokenUrlJson); |
|
|
|
|
|
|
|
JSONObject playJson = parseJson(playOauthTokenUrlJson); |
|
|
|
if (playJson == null || !isSuccess(playJson)) { |
|
|
|
log.warn("获取播放地址失败,响应: {}", playOauthTokenUrlJson); |
|
|
|
return rest; |
|
|
|
} |
|
|
|
|
|
|
|
JSONObject playDataJson = playJson.getJSONObject("data"); |
|
|
|
if (playDataJson == null) { |
|
|
|
log.warn("播放地址数据为空"); |
|
|
|
return rest; |
|
|
|
} |
|
|
|
|
|
|
|
JSONObject urls = playDataJson.getJSONObject("urls"); |
|
|
|
if (urls != null) { |
|
|
|
rest.setUrlsMap((Map) urls); |
|
|
|
VideoInfo videoInfo = JSON.parseObject(playOauthTokenUrlJson, VideoInfo.class); |
|
|
|
if (videoInfo.isSuccess()) { |
|
|
|
rest.setUrlsMap(videoInfo.getData().getUrls()); |
|
|
|
} |
|
|
|
return rest; |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("请求接口异常: {}", e.getMessage(), e); |
|
|
|
} |
|
|
|
return rest; |
|
|
|
} |
|
|
|
|
|
|
|
@Data |
|
|
|
public static class VideoInfo { |
|
|
|
private String status; |
|
|
|
private VideoData data; |
|
|
|
|
|
|
|
public Boolean isSuccess() { |
|
|
|
return "0".equals(status); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Data |
|
|
|
public static class VideoData { |
|
|
|
private Url urls; |
|
|
|
} |
|
|
|
|
|
|
|
@Data |
|
|
|
public static class Url { |
|
|
|
private String rtspPlayUrl; |
|
|
|
private String flvPlayUrl; |
|
|
|
private String rtmpPlayUrl; |
|
|
|
private String hlsPlayUrl; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 解析 JSON 字符串为 JSONObject |
|
|
@ -152,17 +165,17 @@ public class BsSgcDfSpPlayService { |
|
|
|
return json != null && Objects.equals(200, json.getIntValue("code")); |
|
|
|
} |
|
|
|
|
|
|
|
public String getSpPlayUrls (DfSpPlayQueDto dto) { |
|
|
|
public String getSpPlayUrls(DfSpPlayQueDto dto) { |
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
Map<String, String> uriVariables = new HashMap<>(); |
|
|
|
MultiValueMap<String, String> headValues = new LinkedMultiValueMap<>(); |
|
|
|
headValues.put("token", Collections.singletonList(dto.getToken())); |
|
|
|
Map<String,String>paramMap=new HashMap<>(); |
|
|
|
paramMap.put("cameraId",dto.getCameraId()); |
|
|
|
Map<String, String> paramMap = new HashMap<>(); |
|
|
|
paramMap.put("cameraId", dto.getCameraId()); |
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON); |
|
|
|
String seqResult2 = null; |
|
|
|
try { |
|
|
|
seqResult2 = RestTemplateUtil.postForObjectWithHead(paramMap, headValues,SP_PLAY_URL , String.class, uriVariables); |
|
|
|
seqResult2 = RestTemplateUtil.postForObjectWithHead(paramMap, headValues, videoUrl + SP_PLAY_URL, String.class, uriVariables); |
|
|
|
log.info("获取播放地址响应SP_PLAY_URL: {}", seqResult2); |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("请求接口SP_PLAY_URL返回异常: {}", e.getMessage()); |
|
|
@ -170,21 +183,19 @@ public class BsSgcDfSpPlayService { |
|
|
|
return seqResult2; |
|
|
|
} |
|
|
|
|
|
|
|
public String getToken (DfSpPlayQueDto dto) { |
|
|
|
RestTemplate restTemplate=new RestTemplate(); |
|
|
|
String token =null; |
|
|
|
public String getToken(DfSpPlayQueDto dto) { |
|
|
|
dto.setMobile(videoPhone); |
|
|
|
RestTemplate restTemplate = new RestTemplate(); |
|
|
|
String token = null; |
|
|
|
String requestStr = JSONObject.toJSONString(dto); |
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON); |
|
|
|
HttpEntity<String> httpEntity = new HttpEntity<>(requestStr, headers); |
|
|
|
String seqResult = ""; |
|
|
|
try { |
|
|
|
ResponseEntity<String> responseEntity = restTemplate.exchange(OAUTH_TOKEN, HttpMethod.POST, httpEntity, String.class); |
|
|
|
ResponseEntity<String> responseEntity = restTemplate.exchange(videoUrl + OAUTH_TOKEN, HttpMethod.POST, httpEntity, String.class); |
|
|
|
seqResult = responseEntity.getBody(); |
|
|
|
log.info("获取播放地址响应SP_PLAY_URL: {}", seqResult); |
|
|
|
JSONObject tokenJson = JSONObject.parseObject(seqResult); |
|
|
|
JSONObject tokenData = tokenJson.getJSONObject("data"); |
|
|
|
token= String.valueOf(tokenData.get("token")); |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("请求接口OAUTH_TOKEN返回异常: {}", e.getMessage()); |
|
|
|
} |
|
|
|