Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
customer-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QG
customer-service
Commits
4b1b833f
Commit
4b1b833f
authored
Mar 03, 2022
by
yexiong.wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
注释fastDfs
parent
fb5a0b6b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
256 additions
and
256 deletions
+256
-256
IFastDFSService.java
.../java/cn/quantgroup/customer/service/IFastDFSService.java
+74
-74
FastDFSServiceImpl.java
.../quantgroup/customer/service/impl/FastDFSServiceImpl.java
+179
-179
VccServiceImpl.java
...a/cn/quantgroup/customer/service/impl/VccServiceImpl.java
+3
-3
No files found.
src/main/java/cn/quantgroup/customer/service/IFastDFSService.java
View file @
4b1b833f
package
cn
.
quantgroup
.
customer
.
service
;
//
package cn.quantgroup.customer.service;
//
import
java.io.IOException
;
//
import java.io.IOException;
import
java.io.InputStream
;
//
import java.io.InputStream;
//
/**
/
//
**
* fastDFS 接入 http://confluence.quantgroup.cn/x/bMU5AQ
//
* fastDFS 接入 http://confluence.quantgroup.cn/x/bMU5AQ
*
//
*
* @author jingfeng.guo
//
* @author jingfeng.guo
* @since 2019-08-24 17:04
//
* @since 2019-08-24 17:04
*/
//
*/
//
public
interface
IFastDFSService
{
//
public interface IFastDFSService {
//
/**
//
/**
* 上传文件
//
* 上传文件
*
//
*
* @param fileInput
//
* @param fileInput
* @param fileSize
//
* @param fileSize
* @param fileExtName 扩展名
//
* @param fileExtName 扩展名
* @return
//
* @return
* @throws IOException
//
* @throws IOException
*/
//
*/
String
uploadFile
(
InputStream
fileInput
,
Long
fileSize
,
String
fileExtName
)
throws
IOException
;
//
String uploadFile(InputStream fileInput, Long fileSize, String fileExtName) throws IOException;
//
/**
//
/**
* 上传文件
//
* 上传文件
*
//
*
* @param bytes
//
* @param bytes
* @param fileExtName
//
* @param fileExtName
* @return
//
* @return
* @throws IOException
//
* @throws IOException
*/
//
*/
String
uploadFile
(
byte
[]
bytes
,
String
fileExtName
)
throws
IOException
;
//
String uploadFile(byte[] bytes, String fileExtName) throws IOException;
//
/**
//
/**
* 文件上传, 下载url 再传
//
* 文件上传, 下载url 再传
*
//
*
* @param url
//
* @param url
* @param fileExtName
//
* @param fileExtName
* @return
//
* @return
* @throws IOException
//
* @throws IOException
*/
//
*/
String
uploadFile
(
String
url
,
String
fileExtName
)
throws
IOException
;
//
String uploadFile(String url, String fileExtName) throws IOException;
//
//
/**
//
/**
* 上传文件 base64
//
* 上传文件 base64
*
//
*
* @param base64String
//
* @param base64String
* @param fileExtName
//
* @param fileExtName
* @return
//
* @return
* @throws IOException
//
* @throws IOException
*/
//
*/
String
uploadFileOfBase64String
(
String
base64String
,
String
fileExtName
)
throws
IOException
;
//
String uploadFileOfBase64String(String base64String, String fileExtName) throws IOException;
//
/**
//
/**
* 下载文件
//
* 下载文件
*
//
*
* @param path
//
* @param path
* @return
//
* @return
* @throws IOException
//
* @throws IOException
*/
//
*/
byte
[]
downloadFile
(
String
path
)
throws
IOException
;
//
byte[] downloadFile(String path) throws IOException;
//
/**
//
/**
* 转成一个临时可用的url
//
* 转成一个临时可用的url
*
//
*
* @param path
//
* @param path
* @return
//
* @return
* @throws IOException
//
* @throws IOException
*/
//
*/
String
toUrl
(
String
path
)
throws
IOException
;
//
String toUrl(String path) throws IOException;
}
//
}
src/main/java/cn/quantgroup/customer/service/impl/FastDFSServiceImpl.java
View file @
4b1b833f
package
cn
.
quantgroup
.
customer
.
service
.
impl
;
//
package cn.quantgroup.customer.service.impl;
//
//
import
cn.quantgroup.customer.service.IFastDFSService
;
//
import cn.quantgroup.customer.service.IFastDFSService;
import
cn.quantgroup.customer.util.ProtoCommon
;
//
import cn.quantgroup.customer.util.ProtoCommon;
import
com.github.tobato.fastdfs.domain.StorePath
;
//
import com.github.tobato.fastdfs.domain.StorePath;
import
com.github.tobato.fastdfs.proto.storage.DownloadByteArray
;
//
import com.github.tobato.fastdfs.proto.storage.DownloadByteArray;
import
com.github.tobato.fastdfs.service.FastFileStorageClient
;
//
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import
lombok.extern.slf4j.Slf4j
;
//
import lombok.extern.slf4j.Slf4j;
import
org.apache.commons.codec.binary.Base64
;
//
import org.apache.commons.codec.binary.Base64;
import
org.apache.commons.lang3.StringUtils
;
//
import org.apache.commons.lang3.StringUtils;
import
org.springframework.beans.factory.annotation.Value
;
//
import org.springframework.beans.factory.annotation.Value;
import
org.springframework.stereotype.Service
;
//
import org.springframework.stereotype.Service;
//
import
javax.annotation.Resource
;
//
import javax.annotation.Resource;
import
java.io.ByteArrayInputStream
;
//
import java.io.ByteArrayInputStream;
import
java.io.IOException
;
//
import java.io.IOException;
import
java.io.InputStream
;
//
import java.io.InputStream;
import
java.net.HttpURLConnection
;
//
import java.net.HttpURLConnection;
import
java.net.URL
;
//
import java.net.URL;
//
/**
/
//
**
* @author xing.yuan
//
* @author xing.yuan
*/
//
*/
@Service
//
@Service
@Slf4j
//
@Slf4j
public
class
FastDFSServiceImpl
implements
IFastDFSService
{
//
public class FastDFSServiceImpl implements IFastDFSService {
//
@Resource
//
@Resource
private
FastFileStorageClient
storageClient
;
//
private FastFileStorageClient storageClient;
//
@Value
(
"${fdfs.secret_key}"
)
//
@Value("${fdfs.secret_key}")
private
String
secretKey
;
//
private String secretKey;
//
@Value
(
"${fdfs.domain}"
)
//
@Value("${fdfs.domain}")
private
String
fastDfsHttp
;
//
private String fastDfsHttp;
//
/**
//
/**
* 文件上传
//
* 文件上传
*
//
*
* @param fileInput
//
* @param fileInput
* @param fileSize
//
* @param fileSize
* @param fileExtName 扩展名
//
* @param fileExtName 扩展名
* @return
//
* @return
*/
//
*/
@Override
//
@Override
public
String
uploadFile
(
InputStream
fileInput
,
Long
fileSize
,
String
fileExtName
)
throws
IOException
{
//
public String uploadFile(InputStream fileInput, Long fileSize, String fileExtName) throws IOException {
StorePath
storePath
=
null
;
//
StorePath storePath = null;
try
{
//
try {
storePath
=
storageClient
.
uploadFile
(
fileInput
,
fileSize
,
fileExtName
,
null
);
//
storePath = storageClient.uploadFile(fileInput, fileSize, fileExtName, null);
}
finally
{
//
} finally {
if
(
fileInput
!=
null
)
{
//
if (fileInput != null) {
try
{
//
try {
fileInput
.
close
();
//
fileInput.close();
}
catch
(
IOException
e
)
{
//
} catch (IOException e) {
}
//
}
}
//
}
}
//
}
if
(
storePath
!=
null
&&
StringUtils
.
isNotBlank
(
storePath
.
getFullPath
()))
{
//
if (storePath != null && StringUtils.isNotBlank(storePath.getFullPath())) {
return
storePath
.
getFullPath
();
//
return storePath.getFullPath();
}
else
{
//
} else {
throw
new
IOException
(
"文件上传失败"
);
//
throw new IOException("文件上传失败");
}
//
}
}
//
}
//
/**
//
/**
* 文件上传
//
* 文件上传
*
//
*
* @param bytes
//
* @param bytes
* @param fileExtName 扩展名
//
* @param fileExtName 扩展名
* @return
//
* @return
*/
//
*/
@Override
//
@Override
public
String
uploadFile
(
byte
[]
bytes
,
String
fileExtName
)
throws
IOException
{
//
public String uploadFile(byte[] bytes, String fileExtName) throws IOException {
return
uploadFile
(
new
ByteArrayInputStream
(
bytes
),
(
long
)
bytes
.
length
,
fileExtName
);
//
return uploadFile(new ByteArrayInputStream(bytes), (long) bytes.length, fileExtName);
}
//
}
//
//
/**
//
/**
* 文件上传, 下载url 再传
//
* 文件上传, 下载url 再传
*
//
*
* @param url
//
* @param url
* @param fileExtName
//
* @param fileExtName
* @return
//
* @return
* @throws IOException
//
* @throws IOException
*/
//
*/
@Override
//
@Override
public
String
uploadFile
(
String
url
,
String
fileExtName
)
throws
IOException
{
//
public String uploadFile(String url, String fileExtName) throws IOException {
InputStream
in
=
null
;
//
InputStream in = null;
long
size
=
0
;
//
long size = 0;
HttpURLConnection
conn
=
null
;
//
HttpURLConnection conn = null;
try
{
//
try {
URL
httpUrl
=
new
URL
(
url
);
//
URL httpUrl = new URL(url);
conn
=
(
HttpURLConnection
)
httpUrl
.
openConnection
();
//
conn = (HttpURLConnection) httpUrl.openConnection();
//设置超时间为3秒
//
//设置超时间为3秒
conn
.
setConnectTimeout
(
3
*
1000
);
//
conn.setConnectTimeout(3 * 1000);
conn
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"
);
//
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
in
=
conn
.
getInputStream
();
//
in = conn.getInputStream();
size
=
in
.
available
();
//
size = in.available();
}
catch
(
IOException
e
)
{
//
} catch (IOException e) {
log
.
warn
(
"下载文件异常,url={},"
,
url
,
e
);
//
log.warn("下载文件异常,url={},", url, e);
throw
e
;
//
throw e;
}
//
}
log
.
info
(
"准备上传文件; url={}, "
,
url
);
//
log.info("准备上传文件; url={}, ", url);
try
{
//
try {
String
path
=
uploadFile
(
in
,
size
,
fileExtName
);
//
String path = uploadFile(in, size, fileExtName);
return
path
;
//
return path;
}
finally
{
//
} finally {
if
(
conn
!=
null
)
{
//
if (conn != null) {
try
{
//
try {
conn
.
disconnect
();
//
conn.disconnect();
}
catch
(
Exception
e
)
{
//
} catch (Exception e) {
}
//
}
}
//
}
}
//
}
}
//
}
//
//
/**
//
/**
* 上传文件 base64
//
* 上传文件 base64
*
//
*
* @param base64String
//
* @param base64String
* @param fileExtName
//
* @param fileExtName
* @return
//
* @return
* @throws IOException
//
* @throws IOException
*/
//
*/
@Override
//
@Override
public
String
uploadFileOfBase64String
(
String
base64String
,
String
fileExtName
)
throws
IOException
{
//
public String uploadFileOfBase64String(String base64String, String fileExtName) throws IOException {
byte
[]
bytes
=
Base64
.
decodeBase64
(
base64String
);
//
byte[] bytes = Base64.decodeBase64(base64String);
return
uploadFile
(
bytes
,
fileExtName
);
//
return uploadFile(bytes, fileExtName);
}
//
}
//
/**
//
/**
* 下载文件
//
* 下载文件
*
//
*
* @param path
//
* @param path
* @return
//
* @return
*/
//
*/
@Override
//
@Override
public
byte
[]
downloadFile
(
String
path
)
throws
IOException
{
//
public byte[] downloadFile(String path) throws IOException {
if
(
StringUtils
.
isBlank
(
path
))
{
//
if (StringUtils.isBlank(path)) {
return
null
;
//
return null;
}
//
}
String
[]
split
=
StringUtils
.
split
(
path
,
"/"
,
2
);
//
String[] split = StringUtils.split(path, "/", 2);
if
(
split
.
length
<
2
)
{
//
if (split.length < 2) {
throw
new
IOException
(
"路径不对"
);
//
throw new IOException("路径不对");
}
//
}
byte
[]
bytes
=
storageClient
.
downloadFile
(
split
[
0
],
split
[
1
],
new
DownloadByteArray
()
{
//
byte[] bytes = storageClient.downloadFile(split[0], split[1], new DownloadByteArray() {
});
//
});
return
bytes
;
//
return bytes;
}
//
}
//
/**
//
/**
* 转成一个临时可用的url
//
* 转成一个临时可用的url
* @param path
//
* @param path
* @return
//
* @return
* @throws IOException
//
* @throws IOException
*/
//
*/
@Override
//
@Override
public
String
toUrl
(
String
path
)
throws
IOException
{
//
public String toUrl(String path) throws IOException {
if
(
StringUtils
.
isBlank
(
path
))
{
//
if (StringUtils.isBlank(path)) {
return
null
;
//
return null;
}
//
}
String
fileName
=
path
;
//
String fileName = path;
if
(
fileName
.
indexOf
(
"/M"
)
>
0
)
{
//
if (fileName.indexOf("/M") > 0) {
fileName
=
fileName
.
substring
(
fileName
.
indexOf
(
"/M"
)
+
1
);
//
fileName = fileName.substring(fileName.indexOf("/M") + 1);
}
//
}
int
lts
=
(
int
)
(
System
.
currentTimeMillis
()
/
1000
);
//
int lts = (int) (System.currentTimeMillis() / 1000);
// 初始化secret_key
//
// 初始化secret_key
try
{
//
try {
String
token
=
ProtoCommon
.
getToken
(
fileName
,
lts
,
secretKey
);
//
String token = ProtoCommon.getToken(fileName, lts, secretKey);
return
fastDfsHttp
+
"/"
+
path
+
"?token="
+
token
+
"&ts="
+
lts
;
//
return fastDfsHttp + "/" + path + "?token=" + token + "&ts=" + lts;
}
catch
(
Exception
e
)
{
//
} catch (Exception e) {
log
.
warn
(
"生成FastDFS下载链接失败:path:{},"
,
path
,
e
);
//
log.warn("生成FastDFS下载链接失败:path:{},", path, e);
throw
new
IOException
(
"生成下载链接失败"
);
//
throw new IOException("生成下载链接失败");
}
//
}
}
//
}
//
}
//
}
src/main/java/cn/quantgroup/customer/service/impl/VccServiceImpl.java
View file @
4b1b833f
...
@@ -14,7 +14,7 @@ import cn.quantgroup.customer.rest.param.vcc.UserPreRepayInfoQuery;
...
@@ -14,7 +14,7 @@ import cn.quantgroup.customer.rest.param.vcc.UserPreRepayInfoQuery;
import
cn.quantgroup.customer.rest.vo.JsonResult
;
import
cn.quantgroup.customer.rest.vo.JsonResult
;
import
cn.quantgroup.customer.rest.vo.vcc.QueryPreOfflineRepayVo
;
import
cn.quantgroup.customer.rest.vo.vcc.QueryPreOfflineRepayVo
;
import
cn.quantgroup.customer.rest.vo.vcc.QuerySubmitRecordVo
;
import
cn.quantgroup.customer.rest.vo.vcc.QuerySubmitRecordVo
;
import
cn.quantgroup.customer.service.IFastDFSService
;
//
import cn.quantgroup.customer.service.IFastDFSService;
import
cn.quantgroup.customer.service.IOpSystemService
;
import
cn.quantgroup.customer.service.IOpSystemService
;
import
cn.quantgroup.customer.service.IVccService
;
import
cn.quantgroup.customer.service.IVccService
;
import
cn.quantgroup.customer.service.ftp.IFtpService
;
import
cn.quantgroup.customer.service.ftp.IFtpService
;
...
@@ -62,8 +62,8 @@ public class VccServiceImpl implements IVccService {
...
@@ -62,8 +62,8 @@ public class VccServiceImpl implements IVccService {
private
OfflineRepayOperateRecordRepo
offlineRepayOperateRecordRepo
;
private
OfflineRepayOperateRecordRepo
offlineRepayOperateRecordRepo
;
@Autowired
@Autowired
private
IOpSystemService
IOpSystemService
;
private
IOpSystemService
IOpSystemService
;
@Autowired
//
@Autowired
private
IFastDFSService
fastDfsService
;
//
private IFastDFSService fastDfsService;
@Autowired
@Autowired
private
IFtpService
ftpService
;
private
IFtpService
ftpService
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment