Commit 54a6ef26 authored by wangjinjing's avatar wangjinjing

建金ftp连接方式修改。待验证

parent bab327c3
Pipeline #21 failed with stages
...@@ -167,7 +167,16 @@ ...@@ -167,7 +167,16 @@
<artifactId>poi</artifactId> <artifactId>poi</artifactId>
<version>3.8-beta5</version> <version>3.8-beta5</version>
</dependency> </dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies> </dependencies>
<repositories> <repositories>
......
...@@ -17,8 +17,8 @@ public class RestTemplateConfig { ...@@ -17,8 +17,8 @@ public class RestTemplateConfig {
@Bean @Bean
public ClientHttpRequestFactory simpleClientHttpRequestFactory(){ public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setConnectTimeout(15000); factory.setConnectTimeout(30000);
factory.setReadTimeout(5000); factory.setReadTimeout(30000);
return factory; return factory;
} }
......
package im.zhaojun.common.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.util.IOUtils;
@Slf4j(topic="文件上传/下载===ftp服务器:")
public class FtpUtil {
private static FTPClient mFTPClient = new FTPClient();
private static FtpUtil ftp = new FtpUtil();
public FtpUtil() {
// 在控制台打印操作过程
mFTPClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
}
/**
* 上传文件到ftp服务器
*/
public static boolean ftpUpload(String fileName, String ftpUrl, int ftpPort,
String ftpUsername, String ftpPassword, String ftpLocalDir, String ftpRemotePath) {
boolean result = false;
try {
boolean isConnection = ftp.openConnection(ftpUrl, ftpPort, ftpUsername, ftpPassword);
if (isConnection) {
boolean isSuccess = ftp.upload(ftpRemotePath, ftpLocalDir + "/" + fileName);
if (isSuccess) {
log.info("文件上传成功!");
result = true;
} else {
log.info("文件上传失败!");
result = false;
}
ftp.logout();
} else {
log.info("链接ftp服务器失败,请检查配置信息是否正确!");
result = false;
}
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
/**
* 从ftp服务器下载文件到本地
*/
public static boolean ftpDownload( String ftpUrl,OutputStream os) {
boolean result = false;
try {
Map ftpresult=getFtpInfoMapByFullPath(ftpUrl);
int ftpPort=ftpresult.get("ftpPort")==null?21:Integer.parseInt(String.valueOf(ftpresult.get("ftpPort")));
String ftpUsername=String.valueOf(ftpresult.get("ftpUser"));
String ftpPassword=String.valueOf(ftpresult.get("ftpPassword"));
boolean isConnection = ftp.openConnection(ftpUrl, ftpPort, ftpUsername, ftpPassword);
if (isConnection) {
boolean isDownloadOk = ftp.downLoad(ftpUrl,os);
//boolean isCreateOk = ftp.createDirectory(ftpRemotePath, ftp.mFTPClient);
if (isDownloadOk) {
log.info("文件下载成功!");
result = true;
} else {
log.info("文件下载失败!");
result = false;
}
ftp.logout();
} else {
log.info("链接ftp服务器失败,请检查配置信息是否正确!");
result = false;
}
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
/**
* 连接ftp服务器
*
* @param host
* ip地址
* @param port
* 端口号
* @param account
* 账号
* @param pwd
* 密码
* @return 是否连接成功
* @throws SocketException
* @throws IOException
*/
private boolean openConnection(String host, int port, String account, String pwd)
throws SocketException, IOException {
mFTPClient.setControlEncoding("UTF-8");
mFTPClient.connect(host, port);
if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
mFTPClient.login(account, pwd);
if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
System.err.println(mFTPClient.getSystemType());
FTPClientConfig config = new FTPClientConfig(mFTPClient.getSystemType().split(" ")[0]);
config.setServerLanguageCode("zh");
mFTPClient.configure(config);
return true;
}
}
disConnection();
return false;
}
/**
* 登出并断开连接
*/
public void logout() {
System.err.println("logout");
if (mFTPClient.isConnected()) {
System.err.println("logout");
try {
mFTPClient.logout();
disConnection();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 断开连接
*/
private void disConnection() {
if (mFTPClient.isConnected()) {
try {
mFTPClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/***
*
* @param remotePath
* 远程地址
* @param fos
* 输出流
* @return
* @throws IOException
*/
public boolean downLoad(String remotePath,OutputStream fos ) throws IOException {
// 进入被动模式
mFTPClient.enterLocalPassiveMode();
// 以二进制进行传输数据
mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
FTPFile[] ftpFiles = mFTPClient.listFiles(remotePath);
if (ftpFiles == null || ftpFiles.length == 0) {
log.info("远程文件不存在");
return false;
} else if (ftpFiles.length > 1) {
log.info("远程文件是文件夹");
return false;
}
// // 本地文件的地址
// File localFileDir = new File(localDir);
// if (!localFileDir.exists()) {
// localFileDir.mkdirs();
// }
// File localFile = new File(localFileDir, ftpFiles[0].getName());
// long localSize = 0;
//
// if (localFile.exists()) {
// if (localFile.length() == lRemoteSize) {
// System.err.println("已经下载完毕");
// return true;
// } else if (localFile.length() < lRemoteSize) {
// // 要下载的文件存在,进行断点续传
// localSize = localFile.length();
// mFTPClient.setRestartOffset(localSize);
// fos = new FileOutputStream(localFile, true);
// }
// }
// if (fos == null) {
// fos = new FileOutputStream(localFile);
// }
InputStream is = mFTPClient.retrieveFileStream(remotePath);
// byte[] buffers = new byte[1024];
// int len = -1;
// while ((len = is.read(buffers)) != -1) {
// fos.write(buffers, 0, len);
// }
// fos.close();
IOUtils.copy(is, fos);
is.close();
boolean isDo = mFTPClient.completePendingCommand();
if (isDo) {
log.info("读取成功");
} else {
log.info("读取失败");
}
return isDo;
}
/**
* 创建远程目录
*
* @param remote
* 远程目录
* @param ftpClient
* ftp客户端
* @return 是否创建成功
* @throws IOException
*/
public boolean createDirectory(String remote, FTPClient ftpClient) throws IOException {
String dirctory = remote.substring(0, remote.lastIndexOf("/") + 1);
if (!dirctory.equalsIgnoreCase("/") && !ftpClient.changeWorkingDirectory(dirctory)) {
int start = 0;
int end = 0;
if (dirctory.startsWith("/")) {
start = 1;
}
end = dirctory.indexOf("/", start);
while (true) {
String subDirctory = remote.substring(start, end);
if (!ftpClient.changeWorkingDirectory(subDirctory)) {
if (ftpClient.makeDirectory(subDirctory)) {
ftpClient.changeWorkingDirectory(subDirctory);
} else {
System.err.println("创建目录失败");
return false;
}
}
start = end + 1;
end = dirctory.indexOf("/", start);
if (end <= start) {
break;
}
}
}
return true;
}
/**
* 上传的文件
*
* @param remotePath
* 上传文件的路径地址(文件夹地址)
* @param localPath
* 本地文件的地址
* @throws IOException
* 异常
*/
public boolean upload(String remotePath, String localPath) throws IOException {
// 进入被动模式
mFTPClient.enterLocalPassiveMode();
// 以二进制进行传输数据
mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
File localFile = new File(localPath);
if (!localFile.exists()) {
System.err.println("本地文件不存在");
return false;
}
String fileName = localFile.getName();
if (remotePath.contains("/")) {
boolean isCreateOk = createDirectory(remotePath, mFTPClient);
if (!isCreateOk) {
System.err.println("文件夹创建失败");
return false;
}
}
// 列出ftp服务器上的文件
FTPFile[] ftpFiles = mFTPClient.listFiles(remotePath);
long remoteSize = 0l;
String remoteFilePath = remotePath + "/" + fileName;
if (ftpFiles.length > 0) {
FTPFile mFtpFile = null;
for (FTPFile ftpFile : ftpFiles) {
if (ftpFile.getName().endsWith(fileName)) {
mFtpFile = ftpFile;
break;
}
}
if (mFtpFile != null) {
remoteSize = mFtpFile.getSize();
if (remoteSize == localFile.length()) {
System.err.println("文件已经上传成功");
return true;
}
if (remoteSize > localFile.length()) {
if (!mFTPClient.deleteFile(remoteFilePath)) {
System.err.println("服务端文件操作失败");
} else {
boolean isUpload = uploadFile(remoteFilePath, localFile, 0);
System.err.println("是否上传成功:" + isUpload);
}
return true;
}
if (!uploadFile(remoteFilePath, localFile, remoteSize)) {
System.err.println("文件上传成功");
return true;
} else {
// 断点续传失败删除文件,重新上传
if (!mFTPClient.deleteFile(remoteFilePath)) {
System.err.println("服务端文件操作失败");
} else {
boolean isUpload = uploadFile(remoteFilePath, localFile, 0);
System.err.println("是否上传成功:" + isUpload);
}
return true;
}
}
}
boolean isUpload = uploadFile(remoteFilePath, localFile, remoteSize);
System.err.println("是否上传成功:" + isUpload);
return isUpload;
}
/**
* 上传文件
*
* @param remoteFile
* 包含文件名的地址
* @param localFile
* 本地文件
* @param remoteSize
* 服务端已经存在的文件大小
* @return 是否上传成功
* @throws IOException
*/
private boolean uploadFile(String remoteFile, File localFile, long remoteSize) throws IOException {
long step = localFile.length() / 10;
long process = 0;
long readByteSize = 0;
RandomAccessFile randomAccessFile = new RandomAccessFile(localFile, "r");
OutputStream os = mFTPClient.appendFileStream(remoteFile);
if (remoteSize > 0) {
// 已经上传一部分的时候就要进行断点续传
process = remoteSize / step;
readByteSize = remoteSize;
randomAccessFile.seek(remoteSize);
mFTPClient.setRestartOffset(remoteSize);
}
byte[] buffers = new byte[1024];
int len = -1;
while ((len = randomAccessFile.read(buffers)) != -1) {
os.write(buffers, 0, len);
readByteSize += len;
long newProcess = readByteSize / step;
if (newProcess > process) {
process = newProcess;
System.err.println("当前上传进度为:" + process);
}
}
os.flush();
randomAccessFile.close();
os.close();
boolean result = mFTPClient.completePendingCommand();
return result;
}
public static String changeUrlCharater(String tempUrl) {
tempUrl = tempUrl.replaceAll("%", "%25").replaceAll("#", "%23").replaceAll("\\+", "%2B").replaceAll("&", "%26");
tempUrl = tempUrl.replaceAll("=", "%3D").replaceAll("\\?", "%3F");
return tempUrl;
}
private static Map<String, String> getFtpInfoMapByFullPath(String ftpUrlStr){
Map<String, String> resultMap = new HashMap<String, String>();
if (null == ftpUrlStr || "".equals(ftpUrlStr.trim())) {
return resultMap;
}
ftpUrlStr = ftpUrlStr.replaceAll("\\\\", "/");
ftpUrlStr = changeUrlCharater(ftpUrlStr);
String array[] = ftpUrlStr.split("/");
if(array.length<2){
return resultMap;
}
String[] ftpUserPasswordAndIpPort = array[2].split("@");
String[] ftpUserAndPassword = ftpUserPasswordAndIpPort[0].split(":");
String[] ftpIpAndPort = ftpUserPasswordAndIpPort[1].split(":");
String ftpUser = ftpUserAndPassword[0];
String ftpPassword = ftpUserAndPassword[1];
String ftpIp = ftpIpAndPort[0];
String ftpPort = ftpIpAndPort.length > 1 ? ftpIpAndPort[1] : "";
String fileName = array[array.length - 1];
resultMap.put("ftpUser", ftpUser);
resultMap.put("ftpPassword", ftpPassword);
resultMap.put("ftpIp", ftpIp);
resultMap.put("ftpPort", ftpPort);
resultMap.put("fileName", fileName);
String path = "";
for (int i = 3; i < array.length - 1; i++) {
if (i != array.length - 2) {
path += array[i] + "/";
} else {
path += array[i];
}
}
resultMap.put("path", path);
return resultMap;
}
}
\ No newline at end of file
package im.zhaojun.common.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexUtils {
/**
* 验证Email
* @param email email地址,格式:zhangsan@zuidaima.com,zhangsan@xxx.com.cn,xxx代表邮件服务商
* @return 验证成功返回true,验证失败返回false
*/
public static boolean checkEmail(String email) {
String regex = "\\w+@\\w+\\.[a-z]+(\\.[a-z]+)?";
return Pattern.matches(regex, email);
}
/**
* 验证身份证号码
* @param idCard 居民身份证号码15位或18位,最后一位可能是数字或字母
* @return 验证成功返回true,验证失败返回false
*/
public static boolean checkIdCard(String idCard) {
String regex = "[1-9]\\d{13,16}[a-zA-Z0-9]{1}";
return Pattern.matches(regex,idCard);
}
/**
* 验证手机号码(支持国际格式,+86135xxxx...(中国内地),+00852137xxxx...(中国香港))
* @param mobile 移动、联通、电信运营商的号码段
*<p>移动的号段:134(0-8)、135、136、137、138、139、147(预计用于TD上网卡)
*、150、151、152、157(TD专用)、158、159、187(未启用)、188(TD专用)</p>
*<p>联通的号段:130、131、132、155、156(世界风专用)、185(未启用)、186(3g)</p>
*<p>电信的号段:133、153、180(未启用)、189</p>
* @return 验证成功返回true,验证失败返回false
*/
public static boolean checkMobile(String mobile) {
String regex = "(\\+\\d+)?1[34578]\\d{9}$";
return Pattern.matches(regex,mobile);
}
/**
* 验证固定电话号码
* @param phone 电话号码,格式:国家(地区)电话代码 + 区号(城市代码) + 电话号码,如:+8602085588447
* <p><b>国家(地区) 代码 :</b>标识电话号码的国家(地区)的标准国家(地区)代码。它包含从 0 到 9 的一位或多位数字,
* 数字之后是空格分隔的国家(地区)代码。</p>
* <p><b>区号(城市代码):</b>这可能包含一个或多个从 0 到 9 的数字,地区或城市代码放在圆括号——
* 对不使用地区或城市代码的国家(地区),则省略该组件。</p>
* <p><b>电话号码:</b>这包含从 0 到 9 的一个或多个数字 </p>
* @return 验证成功返回true,验证失败返回false
*/
public static boolean checkPhone(String phone) {
String regex = "(\\+\\d+)?(\\d{3,4}\\-?)?\\d{7,8}$";
return Pattern.matches(regex, phone);
}
/**
* 验证整数(正整数和负整数)
* @param digit 一位或多位0-9之间的整数
* @return 验证成功返回true,验证失败返回false
*/
public static boolean checkDigit(String digit) {
String regex = "\\-?[1-9]\\d+";
return Pattern.matches(regex,digit);
}
/**
* 验证整数和浮点数(正负整数和正负浮点数)
* @param decimals 一位或多位0-9之间的浮点数,如:1.23,233.30
* @return 验证成功返回true,验证失败返回false
*/
public static boolean checkDecimals(String decimals) {
String regex = "\\-?[1-9]\\d+(\\.\\d+)?";
return Pattern.matches(regex,decimals);
}
/**
* 验证空白字符
* @param blankSpace 空白字符,包括:空格、\t、\n、\r、\f、\x0B
* @return 验证成功返回true,验证失败返回false
*/
public static boolean checkBlankSpace(String blankSpace) {
String regex = "\\s+";
return Pattern.matches(regex,blankSpace);
}
/**
* 验证中文
* @param chinese 中文字符
* @return 验证成功返回true,验证失败返回false
*/
public static boolean checkChinese(String chinese) {
String regex = "^[\u4E00-\u9FA5]+$";
return Pattern.matches(regex,chinese);
}
/**
* 验证日期(年月日)
* @param birthday 日期,格式:1992-09-03,或1992.09.03
* @return 验证成功返回true,验证失败返回false
*/
public static boolean checkBirthday(String birthday) {
String regex = "[1-9]{4}([-./])\\d{1,2}\\1\\d{1,2}";
return Pattern.matches(regex,birthday);
}
/**
* 验证URL地址
* @param url 格式:http://blog.csdn.net:80/xyang81/article/details/7705960? 或 http://www.csdn.net:80
* @return 验证成功返回true,验证失败返回false
*/
public static boolean checkURL(String url) {
String regex = "(https?://(w{3}\\.)?)?\\w+\\.\\w+(\\.[a-zA-Z]+)*(:\\d{1,5})?(/\\w*)*(\\??(.+=.*)?(&.+=.*)?)?";
return Pattern.matches(regex, url);
}
/**
* <pre>
* 获取网址 URL 的一级域
* </pre>
*
* @param url
* @return
*/
public static String getDomain(String url) {
Pattern p = Pattern.compile("(?<=http://|\\.)[^.]*?\\.(com|cn|net|org|biz|info|cc|tv)", Pattern.CASE_INSENSITIVE);
// 获取完整的域名
// Pattern p=Pattern.compile("[^//]*?\\.(com|cn|net|org|biz|info|cc|tv)", Pattern.CASE_INSENSITIVE);
Matcher matcher = p.matcher(url);
matcher.find();
return matcher.group();
}
/**
* 匹配中国邮政编码
* @param postcode 邮政编码
* @return 验证成功返回true,验证失败返回false
*/
public static boolean checkPostcode(String postcode) {
String regex = "[1-9]\\d{5}";
return Pattern.matches(regex, postcode);
}
/**
* 匹配IP地址(简单匹配,格式,如:192.168.1.1,127.0.0.1,没有匹配IP段的大小)
* @param ipAddress IPv4标准地址
* @return 验证成功返回true,验证失败返回false
*/
public static boolean checkIpAddress(String ipAddress) {
String regex = "[1-9](\\d{1,2})?\\.(0|([1-9](\\d{1,2})?))\\.(0|([1-9](\\d{1,2})?))\\.(0|([1-9](\\d{1,2})?))";
return Pattern.matches(regex, ipAddress);
}
/**
* 匹配IP地址(简单匹配,格式,如:192.168.1.1,127.0.0.1,没有匹配IP段的大小)
* @param ipAddress IPv4标准地址
* @return 验证成功返回true,验证失败返回false
*/
public static boolean checkFtp(String ipAddress) {
String regex = "(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]";
return Pattern.matches(regex, ipAddress);
}
}
...@@ -21,13 +21,11 @@ import sun.net.www.protocol.ftp.FtpURLConnection; ...@@ -21,13 +21,11 @@ import sun.net.www.protocol.ftp.FtpURLConnection;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.websocket.server.PathParam;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
@Controller @Controller
...@@ -512,86 +510,87 @@ public class TrafficStatisticsController { ...@@ -512,86 +510,87 @@ public class TrafficStatisticsController {
} }
@GetMapping("/fielagent") // @GetMapping("/fielagent")
protected void fielagent(@RequestParam("ftpPath") String ftpPath, HttpServletRequest request, HttpServletResponse response) { // protected void fielagent(@RequestParam("ftpPath") String ftpPath, HttpServletRequest request, HttpServletResponse response) {
long startTime = System.currentTimeMillis(); // long startTime = System.currentTimeMillis();
FileInputStream hFile = null; // FileInputStream hFile = null;
OutputStream toClient = null; // OutputStream toClient = null;
InputStream inputStream = null; // InputStream inputStream = null;
BufferedInputStream bis = null; // BufferedInputStream bis = null;
try { // try {
response.reset(); // response.reset();
response.setHeader("Expires", "Sat, 10 May 2059 12:00:00 GMT"); // response.setHeader("Expires", "Sat, 10 May 2059 12:00:00 GMT");
response.setHeader("Cache-Control", "max-age=315360000"); // response.setHeader("Cache-Control", "max-age=315360000");
//
if (StringUtils.isNotBlank(ftpPath)) { // if (StringUtils.isNotBlank(ftpPath)) {
if (ftpPath.endsWith(".jpg") || ftpPath.endsWith(".JPG") || ftpPath.endsWith(".png") || ftpPath.endsWith(".PNG") || ftpPath.endsWith(".gif") || ftpPath.endsWith(".GIF")) { // 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"); // response.setContentType("image/" + ftpPath.substring(ftpPath.lastIndexOf(".") + 1) + "; charset=utf-8");
} else if (ftpPath.endsWith(".mp4") || ftpPath.endsWith(".MP4")) { // } else if (ftpPath.endsWith(".mp4") || ftpPath.endsWith(".MP4")) {
response.setContentType("video/mpeg4; charset=utf-8"); // response.setContentType("video/mpeg4; charset=utf-8");
String mp4file = ftpPath.substring(ftpPath.lastIndexOf("/") + 1); // String mp4file = ftpPath.substring(ftpPath.lastIndexOf("/") + 1);
response.setHeader("Content-Disposition", "attachment;fileName=" + mp4file); // response.setHeader("Content-Disposition", "attachment;fileName=" + mp4file);
} // }
//
String destUrl = ftpPath; // String destUrl = ftpPath;
destUrl = new String(destUrl.getBytes("ISO8859-1"), "GBK"); // destUrl = new String(destUrl.getBytes("ISO8859-1"), "GBK");
String[] arr = destUrl.split(";"); // String[] arr = destUrl.split(";");
FtpURLConnection ftpUrl = null; // FtpURLConnection ftpUrl = null;
HttpURLConnection httpUrl = null; // HttpURLConnection httpUrl = null;
for (int i = 0; i < arr.length; i++) { // for (int i = 0; i < arr.length; i++) {
try { // try {
URL url = new URL(arr[i]); // URL url = new URL(arr[i]);
if (arr[i].toUpperCase().indexOf("FTP") != -1) { // ftp // if (arr[i].toUpperCase().indexOf("FTP") != -1) { // ftp
ftpUrl = (FtpURLConnection) url.openConnection(); // ftpUrl = (FtpURLConnection) url.openConnection();
ftpUrl.setConnectTimeout(5000); // ftpUrl.setConnectTimeout(30000);
ftpUrl.setReadTimeout(5000); // ftpUrl.setReadTimeout(30000);
bis = new BufferedInputStream(ftpUrl.getInputStream()); // bis = new BufferedInputStream(ftpUrl.getInputStream());
response.setContentLength(ftpUrl.getContentLength()); // response.setContentLength(ftpUrl.getContentLength());
} else { // http // } else { // http
httpUrl = (HttpURLConnection) url.openConnection(); // httpUrl = (HttpURLConnection) url.openConnection();
httpUrl.setConnectTimeout(5000); // httpUrl.setConnectTimeout(30000);
httpUrl.setReadTimeout(5000); // httpUrl.setReadTimeout(30000);
bis = new BufferedInputStream(httpUrl.getInputStream()); // bis = new BufferedInputStream(httpUrl.getInputStream());
response.setContentLength(httpUrl.getContentLength()); // response.setContentLength(httpUrl.getContentLength());
} // }
toClient = response.getOutputStream(); // toClient = response.getOutputStream();
IOUtils.copy(bis, toClient); // IOUtils.copy(bis, toClient);
} catch (Exception e) { // } catch (Exception e) {
response.setContentType("text/html;charset=GBK"); // response.setContentType("text/html;charset=GBK");
response.setCharacterEncoding("GBK"); // response.setCharacterEncoding("GBK");
PrintWriter out = response.getWriter(); // PrintWriter out = response.getWriter();
out.write("无法打开图片!"); // out.write("无法打开图片!");
out.flush(); // out.flush();
} finally { // log.info("ftpagent error "+ftpUrl+e.toString());
if (bis != null) { // } finally {
bis.close(); // if (bis != null) {
} // bis.close();
if (bis != null) { // }
bis.close(); // if (bis != null) {
} // bis.close();
if (httpUrl != null) { // }
httpUrl.disconnect(); // if (httpUrl != null) {
} // httpUrl.disconnect();
if (ftpUrl != null) { // }
ftpUrl.close(); // if (ftpUrl != null) {
} // ftpUrl.close();
if (toClient != null) { // }
toClient.close(); // if (toClient != null) {
} // toClient.close();
} // }
} // }
return; // }
} // return;
// }
} catch (Exception e) { //
} finally { // } catch (Exception e) {
IOUtils.closeQuietly(bis); // } finally {
IOUtils.closeQuietly(toClient); // IOUtils.closeQuietly(bis);
IOUtils.closeQuietly(hFile); // IOUtils.closeQuietly(toClient);
IOUtils.closeQuietly(inputStream); // IOUtils.closeQuietly(hFile);
} // IOUtils.closeQuietly(inputStream);
// }
} //
// }
@OperationLog("查询今天所有车流量,同比环比按照上个月和上周时间") @OperationLog("查询今天所有车流量,同比环比按照上个月和上周时间")
@GetMapping("/list/todayvehiclesByVideoId") @GetMapping("/list/todayvehiclesByVideoId")
...@@ -853,6 +852,48 @@ public class TrafficStatisticsController { ...@@ -853,6 +852,48 @@ public class TrafficStatisticsController {
} }
@GetMapping("/fielagent")
protected void fielagent(@RequestParam("ftpPath") String ftpPath, HttpServletRequest request, HttpServletResponse response) {
OutputStream toClient = 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(";");
// ftp://username:password@yourdomain.com/path
for (int i = 0; i < arr.length; i++) {
log.info("ftpagent data "+arr[i]);
if (arr[i].toUpperCase().indexOf("FTP") != -1) { // ftp
String tempUrl = arr[i];
tempUrl = tempUrl.replaceAll("\\\\", "/");
toClient=response.getOutputStream();
boolean isdao= FtpUtil.ftpDownload(tempUrl,toClient);
}
if(null==toClient){
response.setContentType("text/html;charset=GBK");
response.setCharacterEncoding("GBK");
PrintWriter out = response.getWriter();
out.write("无法打开图片!");
out.flush();
log.info("ftpagent error ");
}
}
return;
}
} catch (Exception e) {
log.info("ftpagent e "+e);
}
}
} }
package im.zhaojun.system.model;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Ftp {
private String ftpIp;
private Integer ftpPort;
private String ftpUsername;
private String ftpPassword;
@Override
public String toString() {
return "Ftp{" +
"ftpIp='" + ftpIp + '\'' +
", ftpPort=" + ftpPort +
", ftpUsername='" + ftpUsername + '\'' +
", ftpPassword='" + ftpPassword + '\'' +
'}';
}
}
...@@ -2,12 +2,12 @@ spring.profiles.active=dev ...@@ -2,12 +2,12 @@ spring.profiles.active=dev
server.port=8082 server.port=8082
#spring.datasource.username=hzjt spring.datasource.username=hzjt
#spring.datasource.password=hzjt spring.datasource.password=hzjt
#spring.datasource.url=jdbc:oracle:thin:@33.65.250.179:1521:helowin spring.datasource.url=jdbc:oracle:thin:@33.65.250.179:1521:helowin
spring.datasource.username=test #spring.datasource.username=test
spring.datasource.password=test #spring.datasource.password=test
spring.datasource.url=jdbc:oracle:thin:@192.168.168.212:1523:helowin #spring.datasource.url=jdbc:oracle:thin:@192.168.168.212:1523:helowin
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
# ��ʼ����С����С����� # ��ʼ����С����С�����
...@@ -29,8 +29,8 @@ spring.datasource.useGlobalDataSourceStat=true ...@@ -29,8 +29,8 @@ spring.datasource.useGlobalDataSourceStat=true
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8 spring.jackson.time-zone=GMT+8
# #
spring.redis.host=localhost #spring.redis.host=localhost
#spring.redis.host=33.65.250.179 spring.redis.host=33.65.250.179
spring.redis.port=6379 spring.redis.port=6379
spring.cache.type=redis spring.cache.type=redis
spring.cache.redis.time-to-live=600000 spring.cache.redis.time-to-live=600000
...@@ -50,7 +50,7 @@ spring.thymeleaf.cache=false ...@@ -50,7 +50,7 @@ spring.thymeleaf.cache=false
shiro-action.log.operation = false shiro-action.log.operation = false
shiro-action.log.login = false shiro-action.log.login = false
shiro-action.session-timeout=259200 shiro-action.session-timeout=518400
shiro-action.perms-cache-timeout=518400 shiro-action.perms-cache-timeout=518400
shiro-action.super-admin-username=admin shiro-action.super-admin-username=admin
...@@ -80,6 +80,5 @@ qingzhi.eventwrite.timeout=5000 ...@@ -80,6 +80,5 @@ qingzhi.eventwrite.timeout=5000
eventsend.url=http://33.65.250.179:8089/sendEvents eventsend.url=http://33.65.250.179:8089/sendEvents
pushrecordurl=33.65.250.179:8089/sendtouser pushrecordurl=33.65.250.179:8089/sendtouser
ipstrs=33.55.1.85,33.55.1.86,33.55.1.87,33.55.1.88,33.55.1.89,33.55.1.90,33.55.1.91,33.55.1.92,33.55.1.93,33.55.1.94,33.55.1.95,33.55.1.96,33.51.6.97,33.60.1.7,33.54.3.240,33.53.1.171,33.52.1.222,33.61.1.23,33.57.1.22 ipstrs=33.55.1.85,33.55.1.86,33.55.1.87,33.55.1.88,33.55.1.89,33.55.1.90,33.55.1.91,33.55.1.92,33.55.1.93,33.55.1.94,33.55.1.95,33.55.1.96,33.51.6.97,33.60.1.7,33.54.3.240,33.53.1.171,33.52.1.222,33.61.1.23,33.57.1.22
ipurl=:8001/api/traffic-incident/restartAutoRule ipurl=:8001/api/traffic-incident/restartAutoRule
\ No newline at end of file
...@@ -736,7 +736,12 @@ wss.onmessage = function (evt) { ...@@ -736,7 +736,12 @@ wss.onmessage = function (evt) {
sjdj = item.alarmlevel; sjdj = item.alarmlevel;
} }
}); });
vue_sjcx.data_sjlxs1.forEach((item, index)=> {
if ( item.id.toLowerCase() == data.data.incident_type.toLowerCase()) {
bjlx = item.name;
sjdj = item.alarmlevel;
}
});
//监控名称 //监控名称
let jkmc = ''; let jkmc = '';
vue_sjcx.jk_arr.forEach((item, index)=> { vue_sjcx.jk_arr.forEach((item, index)=> {
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<option value="2">重复事件</option> <option value="2">重复事件</option>
</select> </select>
<span class="pub-span" style="margin-left: 10px;">自动刷新 <span class="pub-span" style="margin-left: 10px;">自动刷新
<input type="checkbox" id="push" @click="zdsx" style="width: 17px;height: 17px;margin-top: 16px;"/> <input type="checkbox" id="push" @click="zdsx" style="width: 17px;height: 17px;margin-top: 16px;" checked />
</span> </span>
<span class="glyphicon glyphicon-th-list table-class" <span class="glyphicon glyphicon-th-list table-class"
......
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