Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
traffic-front
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangxiaoming
traffic-front
Commits
5a51fcff
Commit
5a51fcff
authored
Dec 07, 2018
by
sherlock
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unchange
parent
d22b8055
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
36 deletions
+12
-36
HttpFileService.java
...n/java/pwc/taxtech/atms/service/impl/HttpFileService.java
+7
-33
TemplateGroupServiceImpl.java
...c/taxtech/atms/service/impl/TemplateGroupServiceImpl.java
+5
-3
No files found.
atms-api/src/main/java/pwc/taxtech/atms/service/impl/HttpFileService.java
View file @
5a51fcff
...
@@ -26,7 +26,8 @@ import pwc.taxtech.atms.common.config.FileServiceConfig;
...
@@ -26,7 +26,8 @@ import pwc.taxtech.atms.common.config.FileServiceConfig;
import
pwc.taxtech.atms.dto.ApiResultDto
;
import
pwc.taxtech.atms.dto.ApiResultDto
;
import
pwc.taxtech.atms.exception.ServiceException
;
import
pwc.taxtech.atms.exception.ServiceException
;
import
java.io.*
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -42,32 +43,24 @@ public class HttpFileService extends BaseService {
...
@@ -42,32 +43,24 @@ public class HttpFileService extends BaseService {
* 上传模板
* 上传模板
*
*
* @param fileName 文件名
* @param fileName 文件名
* @param file
Bytes 文件字节
* @param file
MultipartFile
* @return Boolean
* @return Boolean
*/
*/
public
String
uploadTemplate
WithBytes
(
String
fileName
,
byte
[]
fileBytes
)
throws
ServiceException
{
public
String
uploadTemplate
(
String
fileName
,
MultipartFile
file
)
throws
ServiceException
{
if
(
StringUtils
.
isBlank
(
fileName
)
||
null
==
file
Bytes
)
{
if
(
StringUtils
.
isBlank
(
fileName
)
||
null
==
file
)
{
throw
new
IllegalArgumentException
(
"上传参数为空"
);
throw
new
IllegalArgumentException
(
"上传参数为空"
);
}
}
CloseableHttpClient
httpClient
=
null
;
CloseableHttpClient
httpClient
=
null
;
String
fullPath
=
USER_TEMPLATE_PATH
+
fileName
;
String
fullPath
=
USER_TEMPLATE_PATH
+
fileName
;
try
{
try
{
httpClient
=
HttpClients
.
createDefault
();
httpClient
=
HttpClients
.
createDefault
();
HttpPost
httpPost
=
new
HttpPost
(
config
.
getServerUrl
()
+
config
.
getUploadUrl
());
HttpPost
httpPost
=
new
HttpPost
(
config
.
getServerUrl
()
+
config
.
getUploadUrl
());
httpPost
.
addHeader
(
HttpHeaders
.
CONTENT_TYPE
,
ContentType
.
APPLICATION_JSON
.
getMimeType
());
httpPost
.
addHeader
(
HttpHeaders
.
CONTENT_TYPE
,
ContentType
.
APPLICATION_JSON
.
getMimeType
());
FileOutputStream
out
=
new
FileOutputStream
(
fullPath
);
out
.
write
(
fileBytes
);
FileInputStream
fis
=
new
FileInputStream
(
fullPath
);
byte
[]
byt
=
new
byte
[
fis
.
available
()];
fis
.
read
(
byt
);
JSONObject
param
=
new
JSONObject
();
JSONObject
param
=
new
JSONObject
();
param
.
put
(
"path"
,
fullPath
);
param
.
put
(
"path"
,
fullPath
);
param
.
put
(
"file"
,
byt
);
param
.
put
(
"file"
,
file
.
getBytes
());
fis
.
close
();
out
.
close
();
HttpEntity
httpEntity
=
new
StringEntity
(
param
.
toJSONString
(),
ContentType
.
APPLICATION_JSON
);
HttpEntity
httpEntity
=
new
StringEntity
(
param
.
toJSONString
(),
ContentType
.
APPLICATION_JSON
);
httpPost
.
setEntity
(
httpEntity
);
httpPost
.
setEntity
(
httpEntity
);
...
@@ -90,25 +83,6 @@ public class HttpFileService extends BaseService {
...
@@ -90,25 +83,6 @@ public class HttpFileService extends BaseService {
throw
new
ServiceException
(
"uploadTemplate error."
);
throw
new
ServiceException
(
"uploadTemplate error."
);
}
}
/**
* 上传模板
*
* @param fileName 文件名
* @param file MultipartFile
* @return Boolean
*/
public
String
uploadTemplate
(
String
fileName
,
MultipartFile
file
)
throws
ServiceException
{
if
(
StringUtils
.
isBlank
(
fileName
)
||
null
==
file
)
{
throw
new
IllegalArgumentException
(
"上传参数为空"
);
}
try
{
return
uploadTemplateWithBytes
(
fileName
,
file
.
getBytes
());
}
catch
(
IOException
e
)
{
logger
.
error
(
"close httpClient error."
,
e
);
}
throw
new
ServiceException
(
"uploadTemplate error."
);
}
/**
/**
* 下载模板
* 下载模板
*
*
...
...
atms-api/src/main/java/pwc/taxtech/atms/service/impl/TemplateGroupServiceImpl.java
View file @
5a51fcff
...
@@ -41,7 +41,9 @@ import pwc.taxtech.atms.vat.dao.PeriodDataSourceMapper;
...
@@ -41,7 +41,9 @@ import pwc.taxtech.atms.vat.dao.PeriodDataSourceMapper;
import
pwc.taxtech.atms.vat.entity.PeriodCellData
;
import
pwc.taxtech.atms.vat.entity.PeriodCellData
;
import
pwc.taxtech.atms.vat.entity.PeriodDataSource
;
import
pwc.taxtech.atms.vat.entity.PeriodDataSource
;
import
java.io.*
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -221,7 +223,7 @@ public class TemplateGroupServiceImpl extends AbstractService {
...
@@ -221,7 +223,7 @@ public class TemplateGroupServiceImpl extends AbstractService {
}
}
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
optional
.
get
().
write
(
bos
);
optional
.
get
().
write
(
bos
);
String
tmpPath
=
httpFileService
.
uploadTemplate
WithBytes
(
newName
,
bos
.
toByteArray
()
);
String
tmpPath
=
httpFileService
.
uploadTemplate
(
newName
,
file
);
String
[]
arr
=
sheetName
.
split
(
"_"
);
String
[]
arr
=
sheetName
.
split
(
"_"
);
String
name
=
arr
.
length
>=
2
?
arr
[
1
]
:
arr
[
0
];
String
name
=
arr
.
length
>=
2
?
arr
[
1
]
:
arr
[
0
];
Template
template
=
new
Template
();
Template
template
=
new
Template
();
...
@@ -368,7 +370,7 @@ public class TemplateGroupServiceImpl extends AbstractService {
...
@@ -368,7 +370,7 @@ public class TemplateGroupServiceImpl extends AbstractService {
}
}
}
}
wtemp
.
write
(
bos
);
wtemp
.
write
(
bos
);
String
tmpPath
=
httpFileService
.
uploadTemplate
WithBytes
(
newName
,
bos
.
toByteArray
()
);
String
tmpPath
=
httpFileService
.
uploadTemplate
(
newName
,
file
);
String
[]
arr
=
sheetName
.
split
(
"_"
);
String
[]
arr
=
sheetName
.
split
(
"_"
);
String
name
=
arr
.
length
>=
2
?
arr
[
1
]
:
arr
[
0
];
String
name
=
arr
.
length
>=
2
?
arr
[
1
]
:
arr
[
0
];
Template
template
=
new
Template
();
Template
template
=
new
Template
();
...
...
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