Commit fa1f3566 authored by 高飞's avatar 高飞

根据videoid 查询对应的flv 地址

parent db5b0ce3
package com.hzjt.controller; package com.hzjt.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.util.concurrent.RateLimiter; import com.google.common.util.concurrent.RateLimiter;
import com.hzjt.domain.*; import com.hzjt.domain.*;
import com.hzjt.handler.WebSocket; import com.hzjt.handler.WebSocket;
...@@ -8,12 +10,14 @@ import com.hzjt.service.ImportService; ...@@ -8,12 +10,14 @@ import com.hzjt.service.ImportService;
import com.hzjt.service.TraffFlowService; import com.hzjt.service.TraffFlowService;
import com.hzjt.util.DateUtils; import com.hzjt.util.DateUtils;
import com.hzjt.util.JsonUtil; import com.hzjt.util.JsonUtil;
import com.hzjt.util.RedisEnum;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -39,6 +43,12 @@ public class TraffController { ...@@ -39,6 +43,12 @@ public class TraffController {
@Autowired @Autowired
TraffFlowService traffFlowService; TraffFlowService traffFlowService;
@Value("${flv.resisvalue}")
private String resisvalue;
@Autowired
private StringRedisTemplate stringRedisTemplate;
...@@ -184,6 +194,36 @@ public class TraffController { ...@@ -184,6 +194,36 @@ public class TraffController {
webSocket.AppointSending(rules.getVideo_id(),JsonUtil.beanToString(map)); webSocket.AppointSending(rules.getVideo_id(),JsonUtil.beanToString(map));
return ResultObj.ok(); return ResultObj.ok();
} }
//获取flv地址
@GetMapping("/getflv/{videoid}")
public String getflv(@PathVariable("videoid") String videoid) {
//根据id查询对应的rtsp
String rtsp= traffFlowService.selectSbtddspsrRtspByVideoid(videoid);
//huode resid 中值、
if(null!=rtsp && null!=stringRedisTemplate.opsForValue().get(resisvalue)) {
JSONArray jsonArr = JSONObject.parseArray(stringRedisTemplate.opsForValue().get(resisvalue));
log.info("jsonArr" + jsonArr.size());
for (int i = 0; i < jsonArr.size(); i++) {
JSONObject jsonObject = jsonArr.getJSONObject(i);
if (jsonObject.getString("source").equalsIgnoreCase(rtsp)) {
if (null != jsonObject.getJSONArray("play_uris") && jsonObject.getJSONArray("play_uris").size() > 3) {
return String.valueOf(jsonObject.getJSONArray("play_uris").get(2));
}
}
}
}
return null;
}
//获取自动规则 //获取自动规则
@GetMapping("/test") @GetMapping("/test")
......
package com.hzjt.listener; package com.hzjt.listener;
import com.hzjt.service.CacheLoadService; import com.hzjt.service.CacheLoadService;
import com.hzjt.service.FLVCacheService;
import com.hzjt.service.FtpService; import com.hzjt.service.FtpService;
import com.hzjt.service.QingZhiLoginCacheService; import com.hzjt.service.QingZhiLoginCacheService;
import com.hzjt.util.ThreadPoolUtil; import com.hzjt.util.ThreadPoolUtil;
...@@ -38,7 +39,7 @@ public class MyApplicationStartingEventListener implements ApplicationListener<S ...@@ -38,7 +39,7 @@ public class MyApplicationStartingEventListener implements ApplicationListener<S
ThreadPoolUtil.getSchedulePool().scheduleWithFixedDelay(() -> { ThreadPoolUtil.getSchedulePool().scheduleWithFixedDelay(() -> {
CacheLoadService cacheLoadService = applicationContext.getBean(CacheLoadService.class); CacheLoadService cacheLoadService = applicationContext.getBean(CacheLoadService.class);
cacheLoadService.loadFtpCache(); cacheLoadService.loadFtpCache();
}, 200, 60000, TimeUnit.MILLISECONDS); }, 200, 60, TimeUnit.SECONDS);
//判断第三方登录是否有效 //判断第三方登录是否有效
ThreadPoolUtil.getSchedulePool().scheduleWithFixedDelay(() -> { ThreadPoolUtil.getSchedulePool().scheduleWithFixedDelay(() -> {
...@@ -46,6 +47,12 @@ public class MyApplicationStartingEventListener implements ApplicationListener<S ...@@ -46,6 +47,12 @@ public class MyApplicationStartingEventListener implements ApplicationListener<S
qingZhiLoginCacheService.keepAlive(); qingZhiLoginCacheService.keepAlive();
}, 3, 60, TimeUnit.SECONDS); }, 3, 60, TimeUnit.SECONDS);
//查询flv值
ThreadPoolUtil.getSchedulePool().scheduleWithFixedDelay(() -> {
FLVCacheService flvservice = applicationContext.getBean(FLVCacheService.class);
flvservice.getvalue();
}, 3, 300, TimeUnit.SECONDS);
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -21,4 +21,5 @@ public interface TraffFlowMapper { ...@@ -21,4 +21,5 @@ public interface TraffFlowMapper {
Integer deleteBeforeTwoMonthVehiclesDetails(String startime); Integer deleteBeforeTwoMonthVehiclesDetails(String startime);
Integer deleteVehiclesByDay(); Integer deleteVehiclesByDay();
Integer insertOrUpdatevehicleTodaystatistic(); Integer insertOrUpdatevehicleTodaystatistic();
String selectSbtddspsrRtspByVideoid(String videoid);
} }
package com.hzjt.service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.concurrent.TimeUnit;
@Service
@Slf4j
public class FLVCacheService {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Value("${flv.resisvalue}")
private String resisvalue;
@Value("${flv.url}")
private String url;
public void getvalue() {
try {
HttpHeaders headers = getHttpHeaders();
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
RestTemplate client = new RestTemplate();
ResponseEntity<String> request = client.exchange((url), HttpMethod.GET, requestEntity, String.class);
//解析返回结果
if (request.getBody() != null) {
log.info("flv response success" );
stringRedisTemplate.opsForValue().set(resisvalue,request.getBody(), 2, TimeUnit.MINUTES);
} else {
log.error("flv response " + "empty...");
}
} catch (Exception e) {
System.out.println(e.toString());
log.error(e.getMessage());
}
}
private HttpHeaders getHttpHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
return headers;
}
}
...@@ -48,7 +48,13 @@ public class TraffFlowService { ...@@ -48,7 +48,13 @@ public class TraffFlowService {
return traffFlowMapper.insertOrUpdatevehicleTodaystatistic(); return traffFlowMapper.insertOrUpdatevehicleTodaystatistic();
} }
public String selectSbtddspsrRtspByVideoid(String videoid){
return traffFlowMapper.selectSbtddspsrRtspByVideoid(videoid);
}
......
...@@ -160,4 +160,9 @@ ...@@ -160,4 +160,9 @@
) )
</insert> </insert>
<select id="selectSbtddspsrRtspByVideoid" resultType="string">
select squrllj from sbtdspsr where sbbh||'_'||tdbh =#{videoid} and rownum=1
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment