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
f4425203
Commit
f4425203
authored
Feb 28, 2022
by
yexiong.wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fastDfs改文件服务器
parent
bdf8b38f
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
516 additions
and
9 deletions
+516
-9
pom.xml
pom.xml
+7
-0
FileInfo.java
src/main/java/cn/quantgroup/customer/model/ftp/FileInfo.java
+21
-0
ServerInfo.java
...ain/java/cn/quantgroup/customer/model/ftp/ServerInfo.java
+22
-0
AbstractFtpService.java
...n/quantgroup/customer/service/ftp/AbstractFtpService.java
+269
-0
CustomerSftpServiceImpl.java
...ntgroup/customer/service/ftp/CustomerSftpServiceImpl.java
+96
-0
IFtpService.java
.../java/cn/quantgroup/customer/service/ftp/IFtpService.java
+71
-0
VccServiceImpl.java
...a/cn/quantgroup/customer/service/impl/VccServiceImpl.java
+30
-9
No files found.
pom.xml
View file @
f4425203
...
...
@@ -304,6 +304,13 @@
</exclusions>
</dependency>
<!-- fastdfs end -->
<!-- sftp -->
<dependency>
<groupId>
com.jcraft
</groupId>
<artifactId>
jsch
</artifactId>
<version>
0.1.54
</version>
</dependency>
</dependencies>
</project>
src/main/java/cn/quantgroup/customer/model/ftp/FileInfo.java
0 → 100644
View file @
f4425203
package
cn
.
quantgroup
.
customer
.
model
.
ftp
;
import
lombok.Data
;
/**
* @author yexiong.wang
* @date 2022/02/27
*/
@Data
public
class
FileInfo
{
private
String
fileName
;
private
byte
[]
fileBytes
;
private
String
filePath
;
public
FileInfo
(
String
fileName
,
byte
[]
fileBytes
,
String
filePath
)
{
this
.
fileName
=
fileName
;
this
.
fileBytes
=
fileBytes
;
this
.
filePath
=
filePath
;
}
}
src/main/java/cn/quantgroup/customer/model/ftp/ServerInfo.java
0 → 100644
View file @
f4425203
package
cn
.
quantgroup
.
customer
.
model
.
ftp
;
import
lombok.Builder
;
import
lombok.Data
;
/**
* @author yexiong.wang
* @date 2022/02/27
*/
@Data
@Builder
public
class
ServerInfo
{
private
String
username
;
private
String
password
;
private
String
host
;
private
String
directory
;
private
int
port
;
}
src/main/java/cn/quantgroup/customer/service/ftp/AbstractFtpService.java
0 → 100644
View file @
f4425203
This diff is collapsed.
Click to expand it.
src/main/java/cn/quantgroup/customer/service/ftp/CustomerSftpServiceImpl.java
0 → 100644
View file @
f4425203
package
cn
.
quantgroup
.
customer
.
service
.
ftp
;
import
cn.quantgroup.customer.model.ftp.FileInfo
;
import
cn.quantgroup.customer.model.ftp.ServerInfo
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.exception.ExceptionUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.io.IOException
;
import
java.util.Map
;
/**
* @author yexiong.wang
* @date 2022/02/27
*/
@Slf4j
@Service
(
"CustomerSftpServiceImpl"
)
public
class
CustomerSftpServiceImpl
extends
AbstractFtpService
implements
IFtpService
{
@Value
(
"${customer.sftp.user}"
)
private
String
username
;
@Value
(
"${customer.sftp.password}"
)
private
String
password
;
@Value
(
"${customer.sftp.host}"
)
private
String
host
;
@Value
(
"${customer.sftp.directory}"
)
private
String
directory
;
@Value
(
"${customer.sftp.port}"
)
private
int
port
;
/**
* @param request 请求参数对象
* @param retryTime 上传失败重试次数
* @return ture:上传成功,false:上传失败
* @throws Exception
*/
@Override
public
Boolean
send
(
Object
request
,
int
retryTime
)
throws
Exception
{
String
fileName
=
""
;
String
path
=
""
;
byte
[]
fileBytes
=
null
;
if
(
request
instanceof
Map
)
{
fileName
=
(
String
)
((
Map
)
request
).
get
(
"fileName"
);
fileBytes
=
(
byte
[])
((
Map
)
request
).
get
(
"fileBytes"
);
path
=
(
String
)
((
Map
)
request
).
get
(
"filePath"
);
}
if
(
StringUtils
.
isBlank
(
fileName
))
{
throw
new
RuntimeException
(
"文件名不能为空"
);
}
if
(
fileBytes
==
null
)
{
throw
new
RuntimeException
(
"文件内容不能为空"
);
}
log
.
info
(
"客服系统上传sftp, fileName:{}, path:{}"
,
fileName
,
path
);
FileInfo
fileInfo
=
new
FileInfo
(
fileName
,
fileBytes
,
path
);
ServerInfo
serverInfo
=
ServerInfo
.
builder
()
.
username
(
username
)
.
directory
(
directory
)
.
host
(
host
)
.
password
(
password
)
.
port
(
port
)
.
build
();
send
(
fileInfo
,
serverInfo
,
3
);
return
null
;
}
@Override
public
byte
[]
down
(
String
fileName
)
throws
IOException
{
ServerInfo
serverInfo
=
ServerInfo
.
builder
()
.
username
(
username
).
directory
(
directory
)
.
host
(
host
).
password
(
password
)
.
port
(
port
)
.
build
();
byte
[]
result
;
try
{
fileName
=
directory
.
concat
(
fileName
);
result
=
down
(
fileName
,
serverInfo
,
1
);
}
catch
(
IOException
ioEx
)
{
log
.
warn
(
"客服系统下载文件,出现异常,fileName:{}, ex:{}"
,
fileName
,
ExceptionUtils
.
getStackTrace
(
ioEx
));
throw
ioEx
;
}
catch
(
Exception
e
)
{
log
.
warn
(
"客服系统下载文件,出现异常,fileName:{}, ex:{}"
,
fileName
,
ExceptionUtils
.
getStackTrace
(
e
));
throw
new
IOException
(
"下载未知异常"
);
}
if
(
result
==
null
)
{
throw
new
IOException
(
"文件为空"
);
}
return
result
;
}
}
src/main/java/cn/quantgroup/customer/service/ftp/IFtpService.java
0 → 100644
View file @
f4425203
package
cn
.
quantgroup
.
customer
.
service
.
ftp
;
import
cn.quantgroup.customer.model.ftp.FileInfo
;
import
cn.quantgroup.customer.model.ftp.ServerInfo
;
import
org.apache.commons.lang3.NotImplementedException
;
import
java.io.IOException
;
import
java.util.List
;
public
interface
IFtpService
{
Object
send
(
Object
request
);
/**
* @param request 请求参数对象
* @param retryTime 上传失败重试次数
* @return ture:上传成功,false:上传失败
* @throws Exception
*/
default
Boolean
send
(
Object
request
,
int
retryTime
)
throws
Exception
{
throw
new
NotImplementedException
(
"send(Object request,int retryTime)方法没有实现!"
);
}
/**
* 文件下载
*
* @param fileName
* @return
* @throws IOException
*/
default
byte
[]
down
(
String
fileName
)
throws
IOException
{
throw
new
NotImplementedException
(
"文件下载没有实现!"
);
}
/**
* SFTP 方式文件上传
*
* @param fileInfo 文件信息
* @param serverInfo SFTP服务器信息
* @param retryTime 重试次数
* @return
* @throws Exception
*/
default
boolean
send
(
FileInfo
fileInfo
,
ServerInfo
serverInfo
,
int
retryTime
)
throws
Exception
{
throw
new
NotImplementedException
(
"send没有实现!"
);
}
/**
* 文件下载
*
* @param fullName 路径文件名称
* @param serverInfo 服务器信息
* @param retryTime 重试次数
* @return
* @throws Exception
*/
default
byte
[]
down
(
String
fullName
,
ServerInfo
serverInfo
,
int
retryTime
)
throws
Exception
{
throw
new
NotImplementedException
(
"文件下载没有实现!"
);
}
/**
* 获取文件名列表
*
* @param serverInfo
* @return
* @throws Exception
*/
default
List
<
String
>
listDirectory
(
ServerInfo
serverInfo
)
throws
Exception
{
throw
new
NotImplementedException
(
"查看目录下的所有文件没有实现!"
);
}
}
src/main/java/cn/quantgroup/customer/service/impl/VccServiceImpl.java
View file @
f4425203
...
...
@@ -17,6 +17,7 @@ import cn.quantgroup.customer.rest.vo.vcc.QuerySubmitRecordVo;
import
cn.quantgroup.customer.service.IFastDFSService
;
import
cn.quantgroup.customer.service.IOpSystemService
;
import
cn.quantgroup.customer.service.IVccService
;
import
cn.quantgroup.customer.service.ftp.IFtpService
;
import
cn.quantgroup.customer.service.http.IHttpService
;
import
cn.quantgroup.customer.util.IdUtil
;
import
cn.quantgroup.user.retbean.XUser
;
...
...
@@ -35,12 +36,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
javax.transaction.Transactional
;
import
java.time.LocalDate
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
import
java.util.List
;
...
...
@@ -60,6 +64,8 @@ public class VccServiceImpl implements IVccService {
private
IOpSystemService
IOpSystemService
;
@Autowired
private
IFastDFSService
fastDfsService
;
@Autowired
private
IFtpService
ftpService
;
@Autowired
private
UserSdkImpl
userSdk
;
...
...
@@ -201,8 +207,10 @@ public class VccServiceImpl implements IVccService {
List
<
String
>
list
=
Arrays
.
asList
(
split
);
List
<
String
>
addressList
=
new
ArrayList
<>();
for
(
String
baseUrl:
list
){
String
viewUrl
=
fastDfsService
.
toUrl
(
baseUrl
);
addressList
.
add
(
viewUrl
);
// String viewUrl = fastDfsService.toUrl(baseUrl);
// addressList.add(viewUrl);
byte
[]
down
=
ftpService
.
down
(
baseUrl
);
addressList
.
add
(
Base64
.
getEncoder
().
encodeToString
(
down
));
}
param
.
setCredentialsAddress
(
addressList
);
return
param
;
...
...
@@ -270,14 +278,27 @@ public class VccServiceImpl implements IVccService {
@Override
public
Map
<
String
,
String
>
fileUpload
(
MultipartFile
file
)
throws
Exception
{
String
name
=
file
.
getOriginalFilename
();
log
.
info
(
"fileUpload | filename={}"
,
name
);
String
substring
=
name
.
substring
(
name
.
lastIndexOf
(
"."
)
+
1
);
String
baseUrl
=
fastDfsService
.
uploadFile
(
file
.
getBytes
(),
substring
);
String
viewUrl
=
fastDfsService
.
toUrl
(
baseUrl
);
// String name = file.getOriginalFilename();
// log.info("fileUpload | filename={}",name);
// String substring = name.substring(name.lastIndexOf(".") + 1);
// String baseUrl = fastDfsService.uploadFile(file.getBytes(), substring);
// String viewUrl = fastDfsService.toUrl(baseUrl);
// Map<String,String> map = new HashMap<>();
// map.put("baseUrl",baseUrl);
// map.put("viewUrl",viewUrl);
// return map;
String
fileName
=
file
.
getOriginalFilename
();
byte
[]
bytes
=
file
.
getBytes
();
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>(
8
);
paramMap
.
put
(
"fileName"
,
fileName
);
paramMap
.
put
(
"fileBytes"
,
bytes
);
String
filePath
=
LocalDate
.
now
().
format
(
DateTimeFormatter
.
ofPattern
(
"yyyyMMdd"
))
+
"/"
;
paramMap
.
put
(
"filePath"
,
filePath
);
ftpService
.
send
(
paramMap
,
3
);
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"base
Url"
,
baseUrl
);
map
.
put
(
"
viewUrl"
,
viewUrl
);
map
.
put
(
"base
64"
,
Base64
.
getEncoder
().
encodeToString
(
bytes
)
);
map
.
put
(
"
url"
,
filePath
+
fileName
);
return
map
;
}
...
...
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