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
ac8131d4
Commit
ac8131d4
authored
Mar 02, 2022
by
吴琼
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
导出修改
parent
2aa71ad1
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
213 additions
and
52 deletions
+213
-52
TransactionReceiptRecordServiceImpl.java
...mer/service/impl/TransactionReceiptRecordServiceImpl.java
+89
-27
SFTPUtil.java
src/main/java/cn/quantgroup/customer/util/SFTPUtil.java
+124
-25
No files found.
src/main/java/cn/quantgroup/customer/service/impl/TransactionReceiptRecordServiceImpl.java
View file @
ac8131d4
...
...
@@ -73,7 +73,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
@Value
(
"${kdsp-operation}"
)
private
String
kdspOperationUrl
;
//@Value("${customer.contract
.http}")
@Value
(
"${pdf.quantgroup.cn
.http}"
)
private
String
contractUrl
;
@Value
(
"${passportapi2.tjzimu.http}"
)
...
...
@@ -89,6 +89,13 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
private
String
password
;
@Value
(
"${customer.transaction.basePath}"
)
private
String
basePath
;
@Value
(
"${customer.transaction.local.file.uploadPath}"
)
private
String
uploadLocalPath
;
@Value
(
"${customer.transaction.local.file.downloadPath}"
)
private
String
downloadLocalPath
;
@Value
(
"${customer.transaction.local.file.downloadZipPath}"
)
private
String
downloadZipLocalPath
;
@Override
public
JsonResult
<
Page
<
TransactionReceiptRecordVO
>>
findRecordsByQuery
(
TransactionReceiptRecordQuery
query
)
{
...
...
@@ -262,7 +269,10 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
return
JsonResult
.
buildErrorStateResult
(
"没有可以导出得数据"
);
}
List
<
Map
<
String
,
Object
>>
filePathList
=
new
ArrayList
<>();
log
.
info
(
"[TransactionReceiptRecordServiceImpl.kdspOperationUrl 调用kdsp-op 接口begin]"
);
log
.
info
(
"[TransactionReceiptRecordServiceImpl.kdspOperationUrl 调用kdsp-op 接口begin]"
,
System
.
currentTimeMillis
());
SFTPUtil
sftpUtil
=
new
SFTPUtil
(
username
,
password
,
host
,
port
);
sftpUtil
.
login
();
log
.
info
(
"uploadFile | 成功连接ftp"
);
for
(
TransactionReceiptRecord
record
:
transactionReceiptRecordList
){
Integer
userId
=
record
.
getUserId
();
String
orderNo
=
record
.
getOrderNo
();
...
...
@@ -311,24 +321,17 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
continue
;
}
//生成pdf
basePath
=
"D:/交易凭证"
;
//String basicPath="D:\\交易凭证0225";
String
directory
=
"/"
+
record
.
getBatchNo
()+
record
.
getUserName
()+
"/"
;
FileToZip
.
mkdir
(
basePath
+
directory
);
String
directory
=
record
.
getBatchNo
()+
record
.
getUserName
();
String
pdfFileName
=
record
.
getOrderNo
()+
".pdf"
;
generatePDF
(
transactionReceiptVOList
.
get
(
0
),
basePath
+
directory
+
pdfFileName
);
//保存到文件服务器上
/*SFTPUtil sftpUtil = new SFTPUtil(username,password,host,port);
sftpUtil.login();
log.info("uploadFile | 成功连接ftp");
File file = new File(pdfFileName);
InputStream is = new FileInputStream(file);
sftpUtil.upload(basePath,directory,pdfFileName,is);
sftpUtil.logout();*/
FileToZip
.
mkdir
(
uploadLocalPath
+
directory
);
generatePDF
(
transactionReceiptVOList
.
get
(
0
),
uploadLocalPath
+
"/"
+
directory
+
"/"
+
pdfFileName
);
File
file1
=
new
File
(
uploadLocalPath
+
"/"
+
directory
+
"/"
+
pdfFileName
);
InputStream
inputStream
=
new
FileInputStream
(
file1
);
sftpUtil
.
upload
(
basePath
,
directory
,
pdfFileName
,
inputStream
);
//将文件路径和useId放入list,进行签章
Map
<
String
,
Object
>
map
=
Maps
.
newHashMap
();
map
.
put
(
"userId"
,
record
.
getUserId
());
map
.
put
(
"fileAddress"
,
basePath
+
directory
+
pdfFileName
);
map
.
put
(
"fileAddress"
,
basePath
+
directory
+
"/"
+
pdfFileName
);
filePathList
.
add
(
map
);
}
}
catch
(
Exception
e
)
{
...
...
@@ -336,9 +339,11 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
return
JsonResult
.
buildErrorStateResult
(
e
.
getMessage
());
}
}
log
.
info
(
"[TransactionReceiptRecordServiceImpl.kdspOperationUrl 调用kdsp-op 接口end]"
);
sftpUtil
.
logout
();
log
.
info
(
"[TransactionReceiptRecordServiceImpl.kdspOperationUrl 调用kdsp-op 接口end]"
,
System
.
currentTimeMillis
());
//上传文件
//调用签章接口
/*
String url = contractUrl + "/contract/batch/sign";
/*
String url = contractUrl + "/contract/batch/sign";
Map<String, String> header = Maps.newHashMap();
header.put("Content-type", "application/json");
Map param = Maps.newHashMap();
...
...
@@ -349,24 +354,81 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
JSONObject json = JSONObject.parseObject(contractResult);
String jsonResult = json.getString("data");
String businessCode = json.getString("businessCode");*/
//下载签章文件
/* SFTPUtil sftpUtil = new SFTPUtil(username,password,host,port);
sftpUtil.login();
log
.
info
(
"downloadFile | 成功连接ftp"
);
sftpUtil.download("","");*/
//转换成zip包
File
file
=
ZipUtil
.
zip
(
basePath
,
basePath
+
".zip"
);
//zip 包保存路径
//sftpUtil.logout();
for
(
Map
<
String
,
Object
>
map
:
filePathList
){
SFTPUtil
sftpUtil1
=
new
SFTPUtil
(
username
,
password
,
host
,
port
);
sftpUtil1
.
login
();
String
filepath
=
(
String
)
map
.
get
(
"fileAddress"
);
int
totallength
=
filepath
.
length
();
//byte[] bytes = sftpUtil1.download("/lzshopkf/transaction/交易凭证/1张三/","1498571250795298816.pdf");
//getFile(bytes,downloadLocalPath+"交易凭证/1张三","1498571250795298816.pdf");//downloadLocalPath=D:/tmp1/
int
length
=
filepath
.
lastIndexOf
(
"/"
);
String
fileName
=
filepath
.
substring
(
length
+
1
,
totallength
);
filepath
=
filepath
.
substring
(
0
,
length
+
1
);
byte
[]
bytes
=
sftpUtil1
.
download
(
filepath
,
fileName
);
String
subPath
=
filepath
.
substring
(
0
,
filepath
.
length
()-
1
);
int
length2
=
subPath
.
lastIndexOf
(
"/"
);
String
directory
=
subPath
.
substring
(
length2
+
1
,
subPath
.
length
());
FileToZip
.
mkdir
(
downloadLocalPath
+
"/"
+
directory
);
getFile
(
bytes
,
downloadLocalPath
+
"/"
+
directory
,
fileName
);
sftpUtil1
.
logout
();
}
//byte[] bytes = sftpUtil.download("/lzshopkf/transaction/交易凭证/1张三","",username,password,host,port);
//getFile(bytes,"D:/0301/交易凭证/1张三","1498571250795298816.pdf");
//转换成zip包
//FileToZip.mkdir("D:/0301/交易凭证");
//File file = ZipUtil.zip("D:/0301/交易凭证", "D:/0301/交易凭证"+".zip");//zip 包保存路径
//FileToZip.mkdir(downloadLocalPath);
File
file
=
ZipUtil
.
zip
(
downloadLocalPath
,
downloadLocalPath
+
".zip"
);
//zip 包保存路径
FileInputStream
is
=
new
FileInputStream
(
file
);
byte
[]
fileData
=
IOUtils
.
readNBytes
(
is
,
is
.
available
());
//FileOutputStream fos1 = new FileOutputStream(new File("D:/交易凭证.zip"));
//FileToZip.toZip(basicPath, fos1,true);
//返回给前端
return
this
.
outputFile
(
response
,
"交易凭证.zip"
,
fileData
,
100
,
20
);
}
/**
*将字节数组转换为file
*/
/**
* 根据byte数组,生成文件
*/
public
void
getFile
(
byte
[]
bfile
,
String
filePath
,
String
fileName
)
{
BufferedOutputStream
bos
=
null
;
FileOutputStream
fos
=
null
;
File
file
=
null
;
try
{
File
dir
=
new
File
(
filePath
);
if
(!
dir
.
exists
()&&
dir
.
isDirectory
()){
//判断文件目录是否存在
dir
.
mkdirs
();
}
FileToZip
.
mkdir
(
filePath
);
file
=
new
File
(
filePath
+
"/"
+
fileName
);
fos
=
new
FileOutputStream
(
file
);
bos
=
new
BufferedOutputStream
(
fos
);
bos
.
write
(
bfile
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
bos
!=
null
)
{
try
{
bos
.
close
();
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
if
(
fos
!=
null
)
{
try
{
fos
.
close
();
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
}
}
public
JsonResult
outputFile
(
HttpServletResponse
response
,
String
fileName
,
byte
[]
file
,
Integer
successCount
,
Integer
failCount
){
if
(
ArrayUtils
.
isEmpty
(
file
))
{
...
...
src/main/java/cn/quantgroup/customer/util/SFTPUtil.java
View file @
ac8131d4
This diff is collapsed.
Click to expand it.
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