zhongdaoyi@wondertek.com.cn

审片间接口初始化3

... ... @@ -95,7 +95,11 @@
<artifactId>hibernate-validator-annotation-processor</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>
<!--常用库依赖-->
<dependency>
... ...
... ... @@ -59,5 +59,10 @@ public class LiveMonitorRoomController {
return liveMonitorRoomService.delete(id);
}
@GetMapping("taskDetail")
ResultBean taskDetail(@RequestParam(value = "id",required = true)Long id){
return liveMonitorRoomService.taskDetail(id);
}
}
... ...
... ... @@ -23,4 +23,7 @@ public interface LiveMonitorRoomService extends IService<LiveMonitorRoom> {
ResultBean delete(Long id);
ResultBean taskDetail(Long id);
}
... ...
package com.wondertek.service.impl;
import java.time.LocalDateTime;
import java.util.List;
import java.util.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
... ... @@ -13,10 +16,14 @@ import com.wondertek.entity.StreamTask;
import com.wondertek.mapper.LiveMonitorRoomMapper;
import com.wondertek.service.LiveMonitorRoomService;
import com.wondertek.service.StreamTaskService;
import com.wondertek.util.HttpClientUtils;
import com.wondertek.util.JSONUtils;
import com.wondertek.util.PageBean;
import com.wondertek.util.ResultBean;
import com.wondertek.vo.LMRoomListVo;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
... ... @@ -29,6 +36,10 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe
@Resource
private StreamTaskService monitorMarkService;
@Value("${transcode.getTaskDetail}")
private String getTaskDetail;
@Override
public PageBean queryPage(LMRoomDto lmRoomDto) {
Page<LMRoomListVo> page = new Page<>(lmRoomDto.getPage(), lmRoomDto.getSize());
... ... @@ -100,7 +111,6 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe
StreamTask streamTask = new StreamTask();
streamTask.setTaskId(crpDataVo.getTaskId());
streamTask.setChannelId(crpDataVo.getChannelId());
streamTask.setRoomId(roomId);
streamTask.setTaskType(crpDataVo.getTaskType());
streamTask.setCreatedBy("");
streamTask.setCreatedTime(LocalDateTime.now());
... ... @@ -153,4 +163,85 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe
return ResultBean.ok("删除成功");
}
@Override
public ResultBean taskDetail(Long id) {
LiveMonitorRoom monitorRoom = getById(id);
if(monitorRoom == null){
return ResultBean.error("房间不存在");
}
Map<String, Object> result = JSON.parseObject(JSON.toJSONString(monitorRoom), new TypeReference<Map<String, Object>>() {
});
List<Map<String, Object>> streamTaskMapList = new ArrayList<>();
List<StreamTask> taskList = monitorMarkService.list(new QueryWrapper<StreamTask>().eq("room_id", id));
if(!CollectionUtils.isEmpty(taskList)){
for (StreamTask streamTask : taskList) {
String taskId = streamTask.getTaskId();
String outputDirCheck = streamTask.getOutputDir();
Map<String, Object> streamTaskMap = JSON.parseObject(JSON.toJSONString(streamTask), new TypeReference<Map<String, Object>>() {
});
String reqUrl = getTaskDetail+"?taskId="+taskId;
String res = HttpClientUtils.executeByGET(reqUrl);
Map<Object,Object> output = new HashMap<>();
if(StringUtils.isNotBlank(res)){
Map<String, Object> resMap = JSON.parseObject(res, new TypeReference<Map<String, Object>>() {
});
Object returnMessage = resMap.get("returnMessage");
Object resultCode = resMap.get("resultCode");
if(Objects.equals("0",resultCode) && Objects.equals("成功",returnMessage)){
if(resMap.get("taskInfo")!=null){
Map<String, Object> taskInfo = (Map<String, Object>) resMap.get("taskInfo");
if(taskInfo.get("taskList")!=null){
List<Map<String, Object>> tasks = (List<Map<String, Object>>) taskInfo.get("taskList");
for (Map<String, Object> item : tasks) {
//输出地址
Object outGroupNo = item.get("outGroupNo");
List<Map<String, Object>> outputDirList= new ArrayList<>();
if(item.get("outPutList")!=null){
List<Map<String, Object>> outPutList = (List<Map<String, Object>>) item.get("outPutList");
for (Map<String, Object> opmap : outPutList) {
Object outputDir = opmap.get("outputDir");
Map<String, Object> outputDirMap = new HashMap<>();
outputDirMap.put("outputDir", outputDir);
outputDirMap.put("checked", false);
if(outputDir.equals(outputDirCheck)){
outputDirMap.put("checked", true);
}
outputDirList.add(outputDirMap);
}
}
output.put(outGroupNo,outputDirList);
}
}
}
}
}
streamTaskMap.put("output",output);
streamTaskMapList.add(streamTaskMap);
}
}
result.put("taskList",streamTaskMapList);
return ResultBean.ok(result);
}
}
... ...
package com.wondertek.util;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@SuppressWarnings("deprecation")
@Slf4j
public class HttpClientUtils {
private static HttpClient httpClient = null;
/**
* 生产HttpClient实例
* 公开,静态的工厂方法,需要使用时才去创建该单体
*
* @return
*/
public static HttpClient getHttpClient() {
if (httpClient == null) {
httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager());
}
return httpClient;
}
/**
* POST方式调用
*
* @param url
* @param obj 参数为实体类对象
* @return 响应字符串
* @throws java.io.UnsupportedEncodingException
*/
public static String executeByPOST(String url, Object obj) {
log.info("启动http请求,url:{},发送内容:{}", url, JSONUtil.toJsonStr(obj));
try {
HttpResponse execute = HttpRequest.post(url).body(JSONUtil.toJsonStr(obj)).timeout(10000).execute();
if (execute.isOk()) {
String body = execute.body();
log.info("完成执行http请求,url:{},出参:{}", url, body);
return body;
} else {
log.info("完成执行http请求,url:{},出参:{}", url, execute.body());
}
} catch (Exception e) {
log.error("完成执行http请求,url:{},异常:请求体:{},错误信息:{}", url, obj,e.getMessage());
}
return null;
}
/**
* POST方式调用
*
* @param url
* @param obj 参数为实体类对象
* @return 响应字符串
* @throws java.io.UnsupportedEncodingException
*/
public static String executeByPOST(String url, String obj) {
log.info("启动http请求,url:{},发送内容:{}", url, obj);
try {
HttpResponse execute = HttpRequest.post(url).body(obj).timeout(10000).execute();
if (execute.isOk()) {
String body = execute.body();
log.info("完成执行http请求,url:{},出参:{}", url, body);
return body;
} else {
log.info("完成执行http请求,url:{},出参:{}", url, execute.body());
}
} catch (Exception e) {
log.error("完成执行http请求,url:{},异常:请求体:{},错误信息:{}", url, obj,e.getMessage());
}
return null;
}
public static Map<String,String> executeByPOST(String info,String url, String obj) {
log.info(info+"===>启动http请求,url:{},发送内容:{}", url, obj);
Map<String,String> resMap= new HashMap<>();
try {
HttpResponse execute = HttpRequest.post(url).body(obj).timeout(10000).execute();
if (execute.isOk()) {
String body = execute.body();
log.info(info+"===>完成执行http请求,url:{},出参:{}", url, body);
resMap.put("data",body);
resMap.put("code","200");
} else {
log.info(info+"===>完成执行http请求,url:{},出参:{}", url, execute.body());
resMap.put("data",execute.body());
resMap.put("code","500");
}
} catch (Exception e) {
log.error("完成执行http请求,url:{},异常:请求体:{},错误信息:{}", url, obj,e.getMessage());
}
return null;
}
public static String executeByPUT(String url, String obj) {
log.info("启动http请求,url:{},发送内容:{}", url, obj);
try {
HttpResponse execute = HttpRequest.put(url).body(obj).timeout(10000).execute();
if (execute.isOk()) {
String body = execute.body();
log.info("完成执行http请求,url:{},出参:{}", url, body);
return body;
} else {
log.info("完成执行http请求,url:{},出参:{}", url, execute.body());
}
} catch (Exception e) {
log.error("完成执行http请求,url:{},异常:请求体:{},错误信息:{}", url, obj,e.getMessage());
}
return null;
}
public static String executeByDELETE(String url, String obj) {
log.info("启动http请求,url:{},发送内容:{}", url, obj);
try {
HttpResponse execute = HttpRequest.delete(url).body(obj).timeout(10000).execute();
if (execute.isOk()) {
String body = execute.body();
log.info("完成执行http请求,url:{},出参:{}", url, body);
return body;
} else {
log.info("完成执行http请求,url:{},出参:{}", url, execute.body());
}
} catch (Exception e) {
log.error("完成执行http请求,url:{},异常:请求体:{},错误信息:{}", url, obj,e.getMessage());
}
return null;
}
/**
* POST方式调用
*
* @param url
* @param params 参数为NameValuePair键值对对象
* @return 响应字符串
* @throws java.io.UnsupportedEncodingException
*/
public static String executeByPOST(String url, List<NameValuePair> params) {
HttpClient httpclient = getHttpClient();
HttpPost post = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30000).setSocketTimeout(180000).build();
post.setConfig(requestConfig);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseJson = null;
try {
if (params != null) {
post.setEntity(new UrlEncodedFormEntity(params));
}
responseJson = httpclient.execute(post, responseHandler);
log.info("HttpClient POST请求结果:" + responseJson);
} catch (Exception e) {
log.info("HttpClient POST请求异常:" + e.getMessage());
} finally {
httpclient.getConnectionManager().closeExpiredConnections();
httpclient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS);
}
return responseJson;
}
/**
* POST方式调用
*
* @param url
* @param xml 请求Json字符串
* @param headerMap 自定义头
* @return 响应字符串
* @throws java.io.UnsupportedEncodingException
*/
public static String executeByPOST(String url, String xml, Map<String,String> headerMap) {
log.info("启动http请求,url:{},发送内容:{},请求头:{}", url, xml, JSONUtil.toJsonStr(headerMap));
try {
HttpRequest request = HttpRequest.post(url);
if(null != headerMap) {
request.headerMap(headerMap, true);
}
HttpResponse execute = request.body(xml).timeout(10000).execute();
String body = execute.body();
log.info("完成执行http请求,url:{},出参:{}", url, body);
return body;
} catch (Exception e) {
log.error("完成执行http请求,url:{},异常:请求体:{},错误信息:{}", url, xml,e.getMessage());
throw e;
}
}
public static String executeByGET(String url, Object[] params) {
HttpClient httpclient = getHttpClient();
String messages = MessageFormat.format(url, params);
HttpGet get = new HttpGet(messages);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30000).setSocketTimeout(180000).build();
get.setConfig(requestConfig);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseJson = null;
try {
responseJson = httpclient.execute(get, responseHandler);
} catch (Exception e) {
log.info("HttpClient GET请求异常,url:{},error:{}", messages, e.getMessage());
} finally {
httpclient.getConnectionManager().closeExpiredConnections();
httpclient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS);
}
return responseJson;
}
public static String executeByGET(String url) {
String responseBody = null;
try {
log.info(">>>HTTP get请求,请求URL:" + url);
HttpRequest httpGet = HttpUtil.createGet(url);
httpGet.setConnectionTimeout(2000).setReadTimeout(5000);
HttpResponse response = httpGet.execute();
response.charset(Charset.defaultCharset());
if (response.isOk()) {
responseBody = response.body();
if (StringUtils.isNotBlank(responseBody)) {
log.info(">>>HTTP get请求,请求成功" + ",请求结果长度:" + responseBody.length());
}
}
} catch (Exception e) {
log.warn("HTTP get请求URL:" + url + ",请求异常:" + e.getMessage());
}
return responseBody;
/*
* HttpClient httpclient = getHttpClient();
*
* HttpParams params = httpClient.getParams();
* params.setParameter(ClientPNames.HANDLE_REDIRECTS, false);
*
* HttpGet get = new HttpGet(url);
* RequestConfig requestConfig =
* RequestConfig.custom().setConnectTimeout(2000).setSocketTimeout(5000).build()
* ;
* get.setConfig(requestConfig);
* ResponseHandler<String> responseHandler = new BasicResponseHandler();
* String responseJson = null;
* try {
* responseJson = httpclient.execute(get, responseHandler);
* log.info(">>>HttpClient请求URL:"+url+ ",请求结果长度:"+ responseJson.length());
* } catch (Exception e) {
* log.warn("HttpClient请求URL:"+url+",请求异常:" + e.getMessage());
* } finally {
* httpclient.getConnectionManager().closeExpiredConnections();
* httpclient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS);
* }
* return responseJson;
*/
}
/** 仅限用于get请求,传递媒资id列表,其他格式未必适合
* get请求传参,传入url和list数组
* 如:http://localhost:8920/oes-csas-manage/es-operate/sync5?assetIds=20210261500049,20210261500053
* @Param [url, assetIdList]
* @return java.lang.String
**/
public static String executeByGET(String url, List<Long> assetIdList) {
HttpClient httpclient = getHttpClient();
StringBuilder buffer = new StringBuilder();
for (Long assetId : assetIdList) {
buffer.append(assetId).append(",");
}
String substring = buffer.substring(0, buffer.length()-1);
// String messages = MessageFormat.format(url, substring);
String messages = url+substring;
log.info("get请求 messages = " + messages);
HttpGet get = new HttpGet(messages);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30000).setSocketTimeout(180000).build();
get.setConfig(requestConfig);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseJson = null;
try {
responseJson = httpclient.execute(get, responseHandler);
} catch (Exception e) {
log.info("HttpClient GET请求异常:" + e.getMessage());
} finally {
httpclient.getConnectionManager().closeExpiredConnections();
httpclient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS);
}
return responseJson;
}
/**
* 带cookie的get请求
*
* @param url 请求路径
* @param cookie cookie
* @return 请求结果
*/
public static String executeByGET(String url, String cookie) {
String responseBody = null;
try {
log.info(">>>带cookie的HTTP请求,请求URL:" + url);
HttpRequest httpGet = HttpUtil.createGet(url);
httpGet.cookie(cookie);
httpGet.setConnectionTimeout(2000).setReadTimeout(5000);
HttpResponse response = httpGet.execute();
response.charset(Charset.defaultCharset());
if (response.isOk()) {
responseBody = response.body();
if (StringUtils.isNotBlank(responseBody)) {
log.info(">>>带cookie的HTTP请求,请求成功" + ",请求结果长度:" + responseBody.length());
}
}
} catch (Exception e) {
log.warn("HttpClient请求URL:" + url + ",请求异常:" + e.getMessage());
}
return responseBody;
/*
* HttpClient httpclient = getHttpClient();
*
* HttpParams params = httpClient.getParams();
* params.setParameter(ClientPNames.HANDLE_REDIRECTS, false);
*
* HttpGet get = new HttpGet(url);
* RequestConfig requestConfig =
* RequestConfig.custom().setConnectTimeout(2000).setSocketTimeout(5000).build()
* ;
* get.setConfig(requestConfig);
* ResponseHandler<String> responseHandler = new BasicResponseHandler();
* String responseJson = null;
* try {
* get.setHeader("Cookie",cookie);
* responseJson = httpclient.execute(get, responseHandler);
* log.info(">>>HttpClient请求URL:"+url+ ",请求结果长度:"+ responseJson.length());
* } catch (Exception e) {
* log.warn("HttpClient请求URL:"+url+",请求异常:" + e.getMessage());
* } finally {
* httpclient.getConnectionManager().closeExpiredConnections();
* httpclient.getConnectionManager().closeIdleConnections(30, TimeUnit.SECONDS);
* }
* return responseJson;
*/
}
}
... ...
... ... @@ -61,6 +61,7 @@ mybatis-plus:
transcode:
delayTimeUrl: http://192.168.1.41:8080/transcode/delayTime # 延迟接口
getTaskDetail: http://192.168.1.237:9002/api/v1/getTaskDetail
crp:
log:
... ...
... ... @@ -15,7 +15,7 @@
`mix_output_url`,
`live_name`
FROM
crp_live_monitor_room`
`crp_live_monitor_room`
<where>
`del`=0
<if test="dto.name != null and dto.name != ''">
... ...