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
7093cc1d
Commit
7093cc1d
authored
Jun 19, 2018
by
neo.wang
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev_neo2' into 'dev'
[dev] upload balance sheet impl See merge request root/atms!24
parents
009c7b6b
9fb3e7e3
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
202 additions
and
8 deletions
+202
-8
Constant.java
...api/src/main/java/pwc/taxtech/atms/constant/Constant.java
+6
-0
EnumModule.java
...main/java/pwc/taxtech/atms/constant/enums/EnumModule.java
+19
-0
FileUploadController.java
...ava/pwc/taxtech/atms/controller/FileUploadController.java
+33
-0
FileUploadAdapter.java
.../pwc/taxtech/atms/vat/service/impl/FileUploadAdapter.java
+124
-0
conf.properties
atms-api/src/main/resources/conf/conf.properties
+5
-2
conf_profile_dev.properties
atms-api/src/main/resources/conf/conf_profile_dev.properties
+5
-2
conf_profile_pub.properties
atms-api/src/main/resources/conf/conf_profile_pub.properties
+5
-2
conf_profile_staging.properties
...i/src/main/resources/conf/conf_profile_staging.properties
+5
-2
No files found.
atms-api/src/main/java/pwc/taxtech/atms/constant/Constant.java
View file @
7093cc1d
package
pwc
.
taxtech
.
atms
.
constant
;
import
java.io.File
;
import
java.util.UUID
;
public
final
class
Constant
{
public
static
final
String
Comma
=
","
;
...
...
@@ -19,4 +20,8 @@ public final class Constant {
public
static
final
boolean
ACTIVE
=
true
;
public
static
final
String
DEFAULT_INDUSTRY_ID
=
"0"
;
public
static
final
UUID
USER_ID_FOR_UPLOAD
=
UUID
.
fromString
(
"64D39CF7-467E-4414-B334-AA4B55A4E2B3"
);
public
static
final
String
UPLOAD_FOLDER_NAME
=
"Upload"
;
}
\ No newline at end of file
atms-api/src/main/java/pwc/taxtech/atms/constant/enums/EnumModule.java
0 → 100644
View file @
7093cc1d
package
pwc
.
taxtech
.
atms
.
constant
.
enums
;
public
enum
EnumModule
{
EnterpriseMaterial
(
0
),
TrailBalance
(
1
),
Evidence
(
2
),
Voucher
(
3
),
Invoice
(
4
);
private
Integer
code
;
private
EnumModule
(
Integer
code
)
{
this
.
code
=
code
;
}
public
int
getCode
()
{
return
code
;
}
}
atms-api/src/main/java/pwc/taxtech/atms/controller/FileUploadController.java
0 → 100644
View file @
7093cc1d
package
pwc
.
taxtech
.
atms
.
controller
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
pwc.taxtech.atms.constant.enums.EnumModule
;
import
pwc.taxtech.atms.dto.PagingResultDto
;
import
pwc.taxtech.atms.dto.vatdto.InputVATInvoiceDto
;
import
pwc.taxtech.atms.vat.service.impl.FileUploadAdapter
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.ws.rs.core.Response
;
import
static
pwc
.
taxtech
.
atms
.
constant
.
Constant
.
USER_ID_FOR_UPLOAD
;
@RestController
@RequestMapping
(
"/api/v1/FileUpload"
)
public
class
FileUploadController
{
@Autowired
private
FileUploadAdapter
fileUploadAdapter
;
@RequestMapping
(
value
=
"NewFile"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
MULTIPART_FORM_DATA_VALUE
)
public
ResponseEntity
getInputInvoiceTreeViewData
(
MultipartHttpServletRequest
request
)
{
return
fileUploadAdapter
.
upload
(
request
,
EnumModule
.
TrailBalance
,
USER_ID_FOR_UPLOAD
);
}
}
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/FileUploadAdapter.java
0 → 100644
View file @
7093cc1d
package
pwc
.
taxtech
.
atms
.
vat
.
service
.
impl
;
import
org.apache.xmlbeans.impl.store.Path
;
import
org.reflections.util.Utils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
pwc.taxtech.atms.constant.enums.EnumModule
;
import
java.io.File
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.UUID
;
import
static
pwc
.
taxtech
.
atms
.
constant
.
Constant
.
UPLOAD_FOLDER_NAME
;
@Service
public
class
FileUploadAdapter
{
private
final
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
FileUploadAdapter
.
class
);
@Value
(
"${max_file_length}"
)
private
String
maxFileSize
;
static
final
String
FILE_NAME
=
"filename"
;
public
static
final
String
TEMP_FILE_NAME
=
"tempFileName"
;
public
static
final
String
CHUNK_NUMBER
=
"_chunkNumber"
;
public
static
final
String
CHUNK_SIZE
=
"_chunkSize"
;
public
static
final
String
TOTAL_SIZE
=
"_totalSize"
;
private
boolean
containsSubFolder
=
true
;
//TODO this should not use val should use parameter(neo)
static
class
FileParamBean
{
String
fileName
;
String
tempFileName
;
long
chunkNumber
;
long
chunkSize
;
long
totalSize
;
boolean
isCanle
;
boolean
result
;
boolean
isLastChunk
;
boolean
isFirsChunk
;
}
public
ResponseEntity
upload
(
MultipartHttpServletRequest
request
,
EnumModule
trailBalance
,
UUID
userIdForUpload
)
{
if
(
request
.
getFileMap
().
size
()
<=
0
)
return
ResponseEntity
.
badRequest
().
body
(
"NoFile"
);
FileParamBean
paramBean
=
getQueryStringParameters
(
request
);
if
(!
paramBean
.
result
)
return
ResponseEntity
.
badRequest
().
body
(
"ParametersInvalid"
);
if
(
paramBean
.
totalSize
>
Long
.
valueOf
(
maxFileSize
))
return
ResponseEntity
.
badRequest
().
body
(
"InvalidFileSize"
);
String
baseFolder
=
prepareFolder
();
if
(!
Utils
.
isEmpty
(
baseFolder
))
return
ResponseEntity
.
badRequest
().
body
(
"PrepareFolderError"
);
String
tempPath
=
String
.
format
(
"%s"
+
File
.
separator
+
"%s"
,
baseFolder
,
paramBean
.
tempFileName
);
String
completePath
=
String
.
format
(
"%s"
+
File
.
separator
+
"%s"
,
baseFolder
,
paramBean
.
tempFileName
);
if
(!
paramBean
.
isCanle
)
{
if
(
paramBean
.
isFirsChunk
)
{
LOGGER
.
debug
(
"First chunk arrived at webservice"
);
File
tempFile
=
new
File
(
tempPath
);
File
completeFile
=
new
File
(
completePath
);
if
(
tempFile
.
exists
())
tempFile
.
delete
();
if
(
completeFile
.
exists
())
completeFile
.
delete
();
}
if
(
paramBean
.
isLastChunk
){
LOGGER
.
debug
(
"Last chunk arrived"
);
File
completeFile
=
new
File
(
completePath
);
File
tempFile
=
new
File
(
tempPath
);
tempFile
.
renameTo
(
completeFile
);
LOGGER
.
info
(
"{} upload to temp folder sucess"
,
paramBean
.
fileName
);
}
}
else
{
File
tempFile
=
new
File
(
tempPath
);
File
completeFile
=
new
File
(
completePath
);
if
(
tempFile
.
exists
())
tempFile
.
delete
();
if
(
completeFile
.
exists
())
completeFile
.
delete
();
}
return
null
;
}
private
FileParamBean
getQueryStringParameters
(
MultipartHttpServletRequest
request
)
{
FileParamBean
param
=
new
FileParamBean
();
param
.
fileName
=
request
.
getParameter
(
FILE_NAME
);
param
.
tempFileName
=
request
.
getParameter
(
TEMP_FILE_NAME
);
param
.
chunkNumber
=
Utils
.
isEmpty
(
request
.
getParameter
(
CHUNK_NUMBER
))
?
-
1
:
Long
.
parseLong
(
request
.
getParameter
(
CHUNK_NUMBER
));
param
.
chunkSize
=
Utils
.
isEmpty
(
request
.
getParameter
(
CHUNK_SIZE
))
?
-
1
:
Long
.
parseLong
(
request
.
getParameter
(
CHUNK_SIZE
));
param
.
totalSize
=
Utils
.
isEmpty
(
request
.
getParameter
(
TOTAL_SIZE
))
?
-
1
:
Long
.
parseLong
(
request
.
getParameter
(
TOTAL_SIZE
));
param
.
result
=
(
param
.
chunkNumber
!=
-
1L
)
&&
(
param
.
chunkSize
!=
-
1L
)
||
(
param
.
totalSize
!=
-
1L
);
if
(!
param
.
result
)
return
param
;
param
.
isLastChunk
=
(
param
.
chunkNumber
+
1
)
*
param
.
chunkSize
>=
param
.
totalSize
;
param
.
isFirsChunk
=
param
.
chunkNumber
==
0
;
param
.
result
=
true
;
return
param
;
}
private
String
prepareFolder
()
{
String
uploadFolder
=
String
.
format
(
"~/%s"
,
UPLOAD_FOLDER_NAME
);
if
(
containsSubFolder
)
{
Calendar
now
=
Calendar
.
getInstance
();
now
.
setTime
(
new
Date
());
String
subUploadFolder
=
String
.
format
(
"%s"
+
File
.
separator
+
"%s"
,
now
.
get
(
Calendar
.
MONTH
),
now
.
get
(
Calendar
.
DATE
));
uploadFolder
=
String
.
format
(
"%s"
+
File
.
separator
+
"%s"
,
uploadFolder
,
subUploadFolder
);
File
file
=
new
File
(
uploadFolder
);
if
(!
file
.
exists
())
file
.
mkdirs
();
}
return
uploadFolder
;
}
}
atms-api/src/main/resources/conf/conf.properties
View file @
7093cc1d
...
...
@@ -18,4 +18,7 @@ jwt.powerToken=${jwt.powerToken}
ftp.host
=
${ftp.host}
ftp.port
=
${ftp.port}
ftp.user
=
${ftp.user}
ftp.pwd
=
${ftp.pwd}
\ No newline at end of file
ftp.pwd
=
${ftp.pwd}
#upload
max_file_length
=
${max_file_length}
\ No newline at end of file
atms-api/src/main/resources/conf/conf_profile_dev.properties
View file @
7093cc1d
...
...
@@ -17,4 +17,7 @@ jwt.powerToken=xxxx
ftp.host
=
cnshaappulv004.asia.pwcinternal.com
ftp.port
=
21
ftp.user
=
ftpuser
ftp.pwd
=
12345678
\ No newline at end of file
ftp.pwd
=
12345678
#upload
max_file_length
=
104857600
\ No newline at end of file
atms-api/src/main/resources/conf/conf_profile_pub.properties
View file @
7093cc1d
...
...
@@ -17,4 +17,7 @@ jwt.powerToken=
ftp.host
=
cnshaappulv004.asia.pwcinternal.com
ftp.port
=
21
ftp.user
=
ftpuser
ftp.pwd
=
12345678
\ No newline at end of file
ftp.pwd
=
12345678
#upload
max_file_length
=
104857600
\ No newline at end of file
atms-api/src/main/resources/conf/conf_profile_staging.properties
View file @
7093cc1d
...
...
@@ -17,4 +17,7 @@ jwt.powerToken=xxxx
ftp.host
=
cnshaappulv004.asia.pwcinternal.com
ftp.port
=
21
ftp.user
=
ftpuser
ftp.pwd
=
12345678
\ No newline at end of file
ftp.pwd
=
12345678
#upload
max_file_length
=
104857600
\ No newline at end of file
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