|
@@ -3,14 +3,12 @@ package com.ozs.web.controller.common;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.ozs.common.core.domain.AjaxResult;
|
|
import com.ozs.common.core.domain.AjaxResult;
|
|
import com.ozs.common.utils.ApiTokenUtils;
|
|
import com.ozs.common.utils.ApiTokenUtils;
|
|
-import com.ozs.common.utils.DateUtils;
|
|
|
|
import com.ozs.common.utils.MinioUtils;
|
|
import com.ozs.common.utils.MinioUtils;
|
|
import com.ozs.common.utils.uuid.IdUtils;
|
|
import com.ozs.common.utils.uuid.IdUtils;
|
|
import com.ozs.service.entity.BaseCameraManagement;
|
|
import com.ozs.service.entity.BaseCameraManagement;
|
|
import com.ozs.service.entity.MsgAlarm;
|
|
import com.ozs.service.entity.MsgAlarm;
|
|
import com.ozs.service.service.BaseCameraManagementService;
|
|
import com.ozs.service.service.BaseCameraManagementService;
|
|
import com.ozs.service.service.MsgAlarmService;
|
|
import com.ozs.service.service.MsgAlarmService;
|
|
-import com.ozs.service.utils.HttpGetUtil;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.util.ObjectUtils;
|
|
@@ -19,7 +17,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.io.BufferedInputStream;
|
|
|
|
+import java.io.BufferedOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.net.HttpURLConnection;
|
|
import java.net.MalformedURLException;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -39,6 +41,8 @@ public class PictureController {
|
|
BaseCameraManagementService baseCameraManagementService;
|
|
BaseCameraManagementService baseCameraManagementService;
|
|
@Resource
|
|
@Resource
|
|
MsgAlarmService msgAlarmService;
|
|
MsgAlarmService msgAlarmService;
|
|
|
|
+ @Resource
|
|
|
|
+ MinioUtils minioUtils;
|
|
public final long timeout = 10000;
|
|
public final long timeout = 10000;
|
|
/**
|
|
/**
|
|
* 获取图片
|
|
* 获取图片
|
|
@@ -62,7 +66,7 @@ public class PictureController {
|
|
URL url = new URL("http://124.70.58.209:18891/api/snap?stream="+l.getCameraCode()+"/"+l.getChannel()+"&timeout="+timeout);
|
|
URL url = new URL("http://124.70.58.209:18891/api/snap?stream="+l.getCameraCode()+"/"+l.getChannel()+"&timeout="+timeout);
|
|
String fileName = "cameraPicture/"+l.getCameraCode()+"_"+uuid +".jpg";
|
|
String fileName = "cameraPicture/"+l.getCameraCode()+"_"+uuid +".jpg";
|
|
log.info("fileName="+fileName);
|
|
log.info("fileName="+fileName);
|
|
- HttpGetUtil.getPicture(url, fileName);
|
|
|
|
|
|
+ getCapture(url, fileName);
|
|
} catch (MalformedURLException e) {
|
|
} catch (MalformedURLException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
@@ -72,4 +76,64 @@ public class PictureController {
|
|
});
|
|
});
|
|
return AjaxResult.success(list);
|
|
return AjaxResult.success(list);
|
|
}
|
|
}
|
|
|
|
+ public void getCapture(URL url,String fileName) throws IOException {
|
|
|
|
+ HttpURLConnection connection = null;
|
|
|
|
+ BufferedInputStream bis = null;
|
|
|
|
+ BufferedOutputStream bos = null;
|
|
|
|
+ try {
|
|
|
|
+ connection = (HttpURLConnection) url.openConnection();
|
|
|
|
+ // http正文内,因此需要设为true
|
|
|
|
+ connection.setDoOutput(true);
|
|
|
|
+ connection.setDoInput(true);
|
|
|
|
+ // Post 请求不能使用缓存
|
|
|
|
+ connection.setUseCaches(false);
|
|
|
|
+ //设置本次连接是否自动重定向
|
|
|
|
+ connection.setInstanceFollowRedirects(true);
|
|
|
|
+
|
|
|
|
+ connection.setRequestMethod("GET");
|
|
|
|
+ connection.setRequestProperty("Accept-Language", "zh,zh-CN;q=0.9");
|
|
|
|
+ connection.setRequestProperty("connection", "keep-alive");
|
|
|
|
+ //设置参数类型是json格式
|
|
|
|
+ connection.setRequestProperty("Content-Type", "application/json;charset=utf-8");
|
|
|
|
+ connection.setRequestProperty("Accept","application/json");
|
|
|
|
+ //connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
|
|
+ connection.setRequestProperty("Charsert", "UTF-8");
|
|
|
|
+ //设置读取时间为30秒
|
|
|
|
+ connection.setConnectTimeout(30 * 1000);
|
|
|
|
+ connection.setReadTimeout(30 * 1000);
|
|
|
|
+ connection.connect();
|
|
|
|
+
|
|
|
|
+ // 返回流
|
|
|
|
+ System.out.println("responseCode=" + connection.getResponseCode());
|
|
|
|
+ log.info("responseCode="+connection.getResponseCode());
|
|
|
|
+ if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
+ InputStream input = connection.getInputStream();
|
|
|
|
+ bis = new BufferedInputStream(input);
|
|
|
|
+ minioUtils.minIoClientUpload(input, fileName);
|
|
|
|
+// FileOutputStream output = new FileOutputStream(fileName);
|
|
|
|
+// bos = new BufferedOutputStream(output);
|
|
|
|
+// byte[] buffer = new byte[1024];
|
|
|
|
+// int size = 0;
|
|
|
|
+// while ((size = bis.read(buffer, 0, 1024)) != -1) {
|
|
|
|
+// bos.write(buffer, 0, size);
|
|
|
|
+// }
|
|
|
|
+// bos.flush();
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ //先关闭外层的缓冲流,再关闭内层的流,但是在关闭外层流的同时,
|
|
|
|
+ //内层流也会自动的进行关闭,关于内层流的关闭,可以省略
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ if (bis != null) {
|
|
|
|
+ bis.close();
|
|
|
|
+ }
|
|
|
|
+// if (bos != null) {
|
|
|
|
+// bos.close();
|
|
|
|
+// }
|
|
|
|
+ if (connection != null) {
|
|
|
|
+ connection.disconnect();
|
|
|
|
+ }
|
|
|
|
+// os.close();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|