package com.cloud.retrieve.service.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.cloud.common.utils.RestTemplateUtil;
|
import com.cloud.model.common.Result;
|
import com.cloud.retrieve.dao.CulOrDevDao;
|
import com.cloud.retrieve.service.AnalyDevService;
|
import com.cloud.retrieve.service.DeviceService;
|
import com.cloud.retrieve.utils.EnumStr;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.MediaType;
|
import org.springframework.stereotype.Service;
|
|
import java.io.UnsupportedEncodingException;
|
import java.util.Map;
|
|
@Service
|
@Slf4j
|
public class AnalyDevServiceImpl implements AnalyDevService {
|
|
@Autowired
|
private EnumStr enumStr;
|
@Autowired
|
private RestTemplateUtil restTemplateUtil;
|
@Autowired
|
private CulOrDevDao culOrDevDao;
|
@Autowired
|
private DeviceService deviceService;
|
@Override
|
public JSONObject getVideo(String videoNum, String picDate, String videoIp, String indeviceid,String imgKey) {
|
|
String reqIp = null;
|
Integer videoPort = 80;
|
String videoPublicIp = "";
|
// nodeIp, videoPublicPort
|
if (StringUtils.isNotEmpty(videoNum)) {
|
// Map<String, Object> byIndeviceId = culOrDevDao.findByIndeviceId(indeviceid);
|
|
JSONObject nodeJson = getNodeByVideoNum(videoNum);
|
if(nodeJson !=null){
|
reqIp = nodeJson.getString("nodeIp");
|
videoPort = nodeJson.getInteger("videoPort");
|
videoPublicIp = nodeJson.getString("videoPublicIp");
|
}
|
} else {
|
reqIp = videoIp;
|
}
|
if (imgKey == null) {
|
imgKey = "";
|
} // 兼容旧数据
|
String bsUrl = "http://" + reqIp + ":" + enumStr.getCServerPort();
|
String esBaseUrl = enumStr.getCServerGetVideoUrl();
|
String reqJson = "{\"videoNum\": \"" + videoNum +
|
"\",\"picDate\": \"" + picDate + "\",\"imgKey\": \"" + imgKey + "\"}";
|
JSONObject dataBaseParams = JSONObject.parseObject(reqJson);
|
String respData = restTemplateUtil.post(bsUrl + esBaseUrl,
|
dataBaseParams, MediaType.APPLICATION_JSON_UTF8, String.class, false);
|
JSONObject cResult = new JSONObject();
|
if (respData != null) {
|
try {
|
respData = new String(respData.getBytes("ISO-8859-1"), "utf-8");
|
} catch (UnsupportedEncodingException e) {
|
e.printStackTrace();
|
}
|
cResult = JSONObject.parseObject(respData);
|
if (StringUtils.isNotEmpty(videoPublicIp) && cResult.getString("file_path") != null) {
|
cResult.put("filepath", "http://" + videoPublicIp + ":" + videoPort + "/videosource" + cResult.getString("file_path").split("/cut")[1]);
|
}
|
}
|
return cResult;
|
}
|
|
@Override
|
public JSONObject getBigPic(String videoNum, String picDate, String videoIp, String indeviceid, String imgKey) {
|
|
// 获取 服务ip
|
String reqIp = null;
|
Integer videoPort = 80;
|
// publicIp, videoPublicPort
|
if (StringUtils.isNotEmpty(videoNum)) {
|
// Map<String, Object> byIndeviceId = culOrDevDao.findByIndeviceId(indeviceid);
|
JSONObject nodeJson = getNodeByVideoNum(videoNum);
|
if(nodeJson !=null){
|
reqIp = nodeJson.getString("nodeIp");
|
videoPort = nodeJson.getInteger("videoPort");
|
}
|
// log.info("数据库查询nodeIp:" + reqIp + "videoPort:" + videoPort);
|
if (videoPort == null) videoPort = 80;
|
} else {
|
reqIp = videoIp;
|
}
|
if (imgKey == null) {
|
imgKey = "";
|
} // 兼容旧数据
|
log.info("reqIp:" + reqIp);
|
String bsUrl = "http://" + reqIp + ":" + enumStr.getCServerPort();
|
String esBaseUrl = enumStr.getCServerGetBigPicUrl();
|
String reqJson = "{\"videoNum\": \"" + videoNum +
|
"\",\"picDate\": \"" + picDate + "\",\"imgKey\": \"" + imgKey + "\"}";
|
JSONObject dataBaseParams = JSONObject.parseObject(reqJson);
|
// log.info("查看大图:reqJson:" + dataBaseParams + ",请求地址:" + bsUrl + esBaseUrl);
|
String respData = restTemplateUtil.post(bsUrl + esBaseUrl,
|
dataBaseParams, MediaType.APPLICATION_JSON_UTF8, String.class, false);
|
JSONObject cResult = new JSONObject();
|
if (respData != null) {
|
// log.info("查看大图c返回:" + respData);
|
cResult = JSONObject.parseObject(respData);
|
}
|
return cResult;
|
}
|
|
/**
|
* 根据摄像机编号获取节点信息
|
* @param videoNum
|
* @return
|
*/
|
private JSONObject getNodeByVideoNum(String videoNum){
|
JSONObject jsonResult = null;
|
Result result = deviceService.getNodeByDeviceId(videoNum);
|
if (result.isSuccess()) {
|
JSONObject data = (JSONObject) result.getData();
|
JSONObject node = data.getJSONObject("node");
|
if (node == null) {
|
throw new RuntimeException("设备(摄像机)查找不到所在节点信息。");
|
}
|
jsonResult = new JSONObject();
|
jsonResult.put("nodeIp",node.getString("nodeIp"));
|
jsonResult.put("videoPort", node.getInteger("videoPublicPort"));
|
jsonResult.put("videoPublicIp",node.getString("publicIp"));
|
}
|
return jsonResult;
|
}
|
|
@Override
|
public Result getDevSnapshot(String devId) {
|
return deviceService.getDevSnapshot(devId);
|
}
|
|
public Map<String, Object> findByIndeviceId(String devId) {
|
return deviceService.getNodeByDevId(devId);
|
}
|
|
}
|