Commit 385fc38a authored by yzm's avatar yzm

修复ftpbug

parent 1cbd9743
......@@ -217,11 +217,14 @@ public class ExtController {
@PathVariable("photonum") Integer photonum) {
//根据videoID查询 rtsp 值
List<Sbtdspsr> sbtdspsrlist=sbtdspsrService.selectByRtsp(videoid);
logger.info("sbtdspsrlist:{}",JSONObject.toJSON(sbtdspsrlist));
if (sbtdspsrlist.size() == 0) {
logger.info(videoid+"设备不存在");
return ResultUtil.success();
}
Sbtdspsr sbtdspsr = sbtdspsrlist.get(0);
logger.info("sbtdspsr:{}",JSONObject.toJSON(sbtdspsr));
//尝试抽取第一张图片
List<String> imgUrls = new ArrayList<>();
HttpHeaders headers = new HttpHeaders();
......@@ -233,11 +236,15 @@ public class ExtController {
}
maps.put("rtspvalue", sbtdspsr.getSqurllj());
maps.put("refresh", 1);
logger.info("getRTSP/1:{}",videoid);
logger.info("rtspurl:{}",rtspurl);
logger.info("maps:{}",JSONObject.toJSON(maps));
HttpEntity<String> formEntity = new HttpEntity<>(null, headers);
try {
ResponseEntity<String> exchange = restTemplate.exchange(rtspurl + "?url={rtspvalue}&refresh={refresh}",
HttpMethod.GET, formEntity, String.class, maps);
String body = exchange.getBody();
logger.info("getRTSP/1->body:",body);
if(null==body|| "".equals(body)){
JSONObject json = JSONObject.parseObject(exchange.getBody());
//rtsp地址可能改变,重新获取
......@@ -263,6 +270,8 @@ public class ExtController {
try{
if(imgUrls.size()==0){
logger.info("no picture data ");
return ResultUtil.success();
}
//根据rtsp 进行图片获取及存储
......@@ -331,10 +340,11 @@ public String getnewRtspVlue(String devicecode ){
map.put("deviceCode", devicecode);
ResponseEntity<String> responseEntity = restTemplate.getForEntity(getrtspbyurl+"?deviceCode={deviceCode}", String.class, map);
JSONObject json = JSONObject.parseObject(responseEntity.getBody());
if (null != json.getString("code") && json.getString("code").equals("0")) {
if (null != json.getString("errorCode") && json.getString("errorCode").equals("0")) {
//返回rtsp 地址
if (null != json.get("obj") && !"".equals(json.get("obj"))) {
rtspnewvalue = String.valueOf(json.get("obj"));
json = JSONObject.parseObject(json.getString("data"));
if (null != json.get("rtspUri") && !"".equals(json.get("rtspUri"))) {
rtspnewvalue = String.valueOf(json.get("rtspUri"));
if(rtspnewvalue.contains("rtsp")) {
//更新sbtdspsr 地址
int result = sbtdspsrService.updateRecogByRtsp(rtspnewvalue, devicecode);
......
......@@ -10,6 +10,7 @@ import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
......@@ -34,6 +35,8 @@ public class IndexController {
@Autowired
private RestTemplate restTemplate;
@Value("${ftppath}")
private String ftppath;
@Autowired
TraffPictureService traffPictureService;
......@@ -173,6 +176,7 @@ public class IndexController {
@GetMapping("/fielagent")
@ResponseBody
protected void fielagent(@RequestParam("ftpPath") String ftpPath, HttpServletRequest request, HttpServletResponse response) {
long startTime = System.currentTimeMillis();
FileInputStream hFile = null;
OutputStream toClient = null;
......@@ -255,4 +259,89 @@ public class IndexController {
}
}
@GetMapping("/api/alg/files")
protected void files(@RequestParam("location") String location, HttpServletRequest request, HttpServletResponse response) {
long startTime = System.currentTimeMillis();
//ftp://reader:reader@33.50.1.22:21/
//ftp.host=33.65.250.179:21:hzjt:1qaz2wsx
String ftpPath="ftp://"+ftppath+"/"+location;
FileInputStream hFile = null;
OutputStream toClient = null;
InputStream inputStream = null;
BufferedInputStream bis = null;
try {
response.reset();
response.setHeader("Expires", "Sat, 10 May 2059 12:00:00 GMT");
response.setHeader("Cache-Control", "max-age=315360000");
if (StringUtils.isNotBlank(ftpPath)) {
if (ftpPath.endsWith(".jpg") || ftpPath.endsWith(".JPG") || ftpPath.endsWith(".png") || ftpPath.endsWith(".PNG") || ftpPath.endsWith(".gif") || ftpPath.endsWith(".GIF")) {
response.setContentType("image/" + ftpPath.substring(ftpPath.lastIndexOf(".") + 1) + "; charset=utf-8");
} else if (ftpPath.endsWith(".mp4") || ftpPath.endsWith(".MP4")) {
response.setContentType("video/mpeg4; charset=utf-8");
String mp4file = ftpPath.substring(ftpPath.lastIndexOf("/") + 1);
response.setHeader("Content-Disposition", "attachment;fileName=" + mp4file);
}
String destUrl = ftpPath;
destUrl = new String(destUrl.getBytes("ISO8859-1"), "GBK");
String[] arr = destUrl.split(";");
FtpURLConnection ftpUrl = null;
HttpURLConnection httpUrl = null;
for (int i = 0; i < arr.length; i++) {
try {
URL url = new URL(arr[i]);
if (arr[i].toUpperCase().indexOf("FTP") != -1) { // ftp
ftpUrl = (FtpURLConnection) url.openConnection();
ftpUrl.setConnectTimeout(30000);
ftpUrl.setReadTimeout(30000);
bis = new BufferedInputStream(ftpUrl.getInputStream());
response.setContentLength(ftpUrl.getContentLength());
} else { // http
httpUrl = (HttpURLConnection) url.openConnection();
httpUrl.setConnectTimeout(30000);
httpUrl.setReadTimeout(30000);
bis = new BufferedInputStream(httpUrl.getInputStream());
response.setContentLength(httpUrl.getContentLength());
}
toClient = response.getOutputStream();
IOUtils.copy(bis, toClient);
} catch (Exception e) {
response.setContentType("text/html;charset=GBK");
response.setCharacterEncoding("GBK");
PrintWriter out = response.getWriter();
out.write("无法打开图片!");
out.flush();
logger.info("ftpagent error:{} ",ftpUrl+e.toString());
} finally {
if (bis != null) {
bis.close();
}
if (bis != null) {
bis.close();
}
if (httpUrl != null) {
httpUrl.disconnect();
}
if (ftpUrl != null) {
ftpUrl.close();
}
if (toClient != null) {
toClient.close();
}
}
}
return;
}
} catch (Exception e) {
} finally {
IOUtils.closeQuietly(bis);
IOUtils.closeQuietly(toClient);
IOUtils.closeQuietly(hFile);
IOUtils.closeQuietly(inputStream);
}
}
}
\ No newline at end of file
......@@ -44,6 +44,11 @@ public class QuartzController {
@Value("${file.rtspurl}")
private String rtspurl;
@Value("${ftppath}")
private String ftppath;
@Autowired
private SbtdspsrService sbtdspsrService;
......@@ -199,9 +204,10 @@ public class QuartzController {
map.put("deviceCode", rtspValue);
ResponseEntity<String> responseEntity = restTemplate.getForEntity(getrtspbyurl + "?deviceCode={deviceCode}", String.class, map);
JSONObject json = JSONObject.parseObject(responseEntity.getBody());
if (null != json.getString("code") && json.getString("code").equals("0")) {
if (null != json.getString("errorCode") && json.getString("errorCode").equals("0")) {
//返回rtsp 地址,更新 sbtdspsr 地址
rtspValue = String.valueOf(json.get("obj"));
json = JSONObject.parseObject(json.getString("data"));
rtspValue = String.valueOf(json.get("rtspUri"));
}
}
......@@ -213,15 +219,21 @@ public class QuartzController {
ResponseEntity<String> result = restTemplate.exchange(rtspurl + "?url={rtspvalue}&refresh={refresh}",
HttpMethod.GET, null, String.class, maps);
JSONObject jsonresult = JSONObject.parseObject(result.getBody());
logger.info("getRtsp:{}",jsonresult);
if (null != jsonresult.getString("ret") && jsonresult.getString("ret").equals("0") && !"".equals(jsonresult.getString("url"))) {
//获得图片地址,存放到ftp上面
//将图片存储到ftp 上去,jsonresult.getString("url")
Ftp ftp = ftpService.reloadFtp();
String ftpfilepath=FileTransferManager.urlTransToFtp(jsonresult.getString("url"),ftp,"gstraff/picturedemo/");
return ResultUtil.success(ResultEnum.SUCCESS.getCode(), jsonresult.getString("url")+ "," + rtspValue);
logger.info("ftppath"+ftpfilepath);
ftpfilepath=ftpfilepath.replace("ftp://"+ftppath+"/","");
// return ResultUtil.success(ResultEnum.SUCCESS.getCode(), jsonresult.getString("url")+ "," + rtspValue);
return ResultUtil.success(ResultEnum.SUCCESS.getCode(), ftpfilepath+ "," + rtspValue);
}
return ResultUtil.fail();
} catch (Exception ex) {
logger.info(ex.toString());
return ResultUtil.fail();
}
}
......
......@@ -11,7 +11,7 @@ file.alarmurl=http://www.zjwwzf.cn/xzzfSpv/ext/alarm/camera
file.rtspurl=http://172.16.24.29:8081/getrealcamerasnapshot.php
file.recogurl=http://172.16.24.29:9098/images/recog
redis.cachekey.ftplist=gs:traff:global:cache:ftplist
file.getrtspbyurl=http://212.129.142.17:8281/gh/device/test
file.getrtspbyurl=http://212.129.142.17:8888/heschome_api/api/hesc/open/getRtsp
countryside.url=http://countryside.51iwifi.com/gw/hesc-mq/hesc/mq/receive/cameraalarm
eventwrite.timeout=5000
eventwrite.token=countrysidetoken
......@@ -21,4 +21,5 @@ countryside.appid=05744e80b2c211ebe32a8e271066b19e
countryside.appsecret=a55a8870b2e911ebe32a8e271066b19e
countryside.tokenurl=http://countryside.51iwifi.com/gw/getAccessToken
file.publicpictureurl=http://zjh189.ncpoi.cc:10001
ftppath=jiuling:9ling.cn@172.16.24.29:21
......@@ -12,9 +12,10 @@
<select id="selectByRtsp" parameterType="java.lang.String" resultType="com.cx.cn.cxquartz.vo.Sbtdspsr">
select a.* from sbtdspsr a,
select distinct a.* from sbtdspsr a,
quartz_task_informations b
WHERE (a.sbbh=b.videoid or a.squrllj=b.videoid) and b.taskno=#{rtsp}
WHERE (a.sbbh=b.videoid or a.squrllj=b.videoid) and
(a.sbbh=#{rtsp} or a.squrllj=#{rtsp})
</select>
<select id="selectRecogByRtsp" parameterType="java.lang.String" resultType="java.util.HashMap">
......@@ -30,7 +31,7 @@
FROM
quartz_task_informations b
WHERE
taskno=#{rtsp}
(videoid=#{rtsp} or executeparamter=#{rtsp})
</select>
<update id="updateRecogByRtsp" parameterType="java.util.HashMap" >
......
......@@ -575,7 +575,7 @@
$("#rtsp").val(result.message.split(",")[1]);
$("#imgsrc").val( result.message.split(",")[0]);
draw.src = result.message.split(",")[0];
draw.setImageBackground(result.message.split(",")[0]);
draw.setImageBackground("/api/alg/files?location="+result.message.split(",")[0]);
//draw.init();
}
}
......
......@@ -214,7 +214,7 @@
<div class="form-group"><label
class="col-sm-2 control-label text-right">执行参数:</label>
<div class="col-sm-10"><input readonly type="text" name="executeparamter"
<div class="col-sm-10"><input type="text" name="executeparamter"
th:value="${taskInformation.executeparamter}"
id="executeparamter"
class="form-control">
......@@ -669,7 +669,7 @@
$("#rtsp").val(result.message.split(",")[1]);
$("#imgsrc").val( result.message.split(",")[0]);
draw.src = result.message.split(",")[0];
draw.setImageBackground(result.message.split(",")[0]);
draw.setImageBackground("/api/alg/files?location="+result.message.split(",")[0]);
//draw.init();
}
}
......
//package com.quartz.cn.com.cx.cn.cxquartz;
//
//import com.cx.cn.cxquartz.service.quartz.impl.SbtdspsrImpl;
//import com.cx.cn.cxquartz.vo.Sbtdspsr;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.test.context.junit4.SpringRunner;
//import sun.misc.BASE64Decoder;
//
//import java.util.List;
//
//@RunWith(SpringRunner.class)
//@SpringBootTest
// public class CXQuartzApplicationTests {
//
// @Test
// public void contextLoads() {
// RedisProperties.Jedis jedis = new Jedis("192.168.10.1");
// jedis.auth("ldd");
// jedis.set("age", "1");
// System.out.println(jedis.get("age"));
// }
//
//}
//
package com.quartz.cn.com.cx.cn.cxquartz;
import com.alibaba.fastjson.JSONObject;
import com.cx.cn.cxquartz.service.quartz.impl.SbtdspsrImpl;
import com.cx.cn.cxquartz.vo.Sbtdspsr;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest
public class CXQuartzApplicationTests {
@Test
public void contextLoads() {
String body = "{\"errorCode\":\"0\",\"errorMsg\":\"success\",\"data\":{\"rtspUri\":\"rtsp://60.188.134.18:30030/streamDelivery_JX04_136/1_0_52268/3d10d70b9e7012bd2f85f35fa3d5f8d3\",\"rtpUri\":\"rtp://60.188.134.18:11348/304\",\"rtmpUri\":\"rtmp://60.188.134.18:30031/streamDelivery_JX04_136/1_0_52268/3d10d70b9e7012bd2f85f35fa3d5f8d3\",\"hlsUri\":\"http://60.188.134.18:30120/streamDelivery_JX04_136/1_0_52268/3d10d70b9e7012bd2f85f35fa3d5f8d3.m3u8\",\"received\":true}}";
JSONObject json = JSONObject.parseObject(body);
if (null != json.getString("errorCode") && json.getString("errorCode").equals("0")) {
json = JSONObject.parseObject(json.getString("data"));
//返回rtsp 地址
if (null != json.get("rtspUri") && !"".equals(json.get("rtspUri"))) {
String rtspnewvalue = String.valueOf(json.get("rtspUri"));
if (rtspnewvalue.contains("rtsp")) {
//更新sbtdspsr 地址
//int result = sbtdspsrService.updateRecogByRtsp(rtspnewvalue, devicecode);
}
}
}
}
@Test
public void testfilepath(){
String ftpfilepath="ftp://jiuling:9ling.cn@172.16.24.29:21/gstraff/picturedemo/20210625.jpg";
String ftppath="jiuling:9ling.cn@172.16.24.29:21";
ftpfilepath=ftpfilepath.replace("ftp://"+ftppath+"/","");
System.out.println(ftpfilepath);
String ftpPath="ftp://"+ftppath+"/"+ftpfilepath;
System.out.println(ftpPath);
}
}
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