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
0416601a
Commit
0416601a
authored
Jul 09, 2018
by
neo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DEV] get template json api you hua
parent
ba76c7eb
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
104 additions
and
34 deletions
+104
-34
MyAsserts.java
...src/main/java/pwc/taxtech/atms/common/util/MyAsserts.java
+23
-0
AtmsExceptionHandler.java
...ava/pwc/taxtech/atms/controller/AtmsExceptionHandler.java
+3
-0
TemplateController.java
.../java/pwc/taxtech/atms/controller/TemplateController.java
+25
-34
ApiException.java
...rc/main/java/pwc/taxtech/atms/exception/ApiException.java
+23
-0
BadParameterException.java
...ava/pwc/taxtech/atms/exception/BadParameterException.java
+10
-0
BadParameterWithMsgException.java
.../taxtech/atms/exception/BadParameterWithMsgException.java
+10
-0
NotFoundException.java
...in/java/pwc/taxtech/atms/exception/NotFoundException.java
+10
-0
No files found.
atms-api/src/main/java/pwc/taxtech/atms/common/util/MyAsserts.java
View file @
0416601a
package
pwc
.
taxtech
.
atms
.
common
.
util
;
import
pwc.taxtech.atms.exception.ApiException
;
import
pwc.taxtech.atms.exception.FormulaException
;
import
java.util.Collection
;
public
class
MyAsserts
{
public
static
void
assertNotNull
(
Object
obj
,
FormulaException
exception
)
{
if
(
obj
==
null
)
throw
exception
;
}
public
static
void
assertNotNull
(
Object
obj
,
ApiException
exception
)
{
if
(
obj
==
null
)
throw
exception
;
}
public
static
void
assertTrue
(
boolean
obj
,
ApiException
exception
)
{
if
(!
obj
)
throw
exception
;
}
public
static
void
assertFalse
(
boolean
obj
,
ApiException
exception
)
{
if
(
obj
)
throw
exception
;
}
public
static
void
assertNotEmpty
(
String
obj
,
ApiException
exception
)
{
if
(
obj
==
null
||
obj
.
isEmpty
())
throw
exception
;
}
public
static
void
assertNotEmpty
(
Collection
obj
,
ApiException
exception
)
{
if
(
obj
==
null
||
obj
.
isEmpty
())
throw
exception
;
}
}
atms-api/src/main/java/pwc/taxtech/atms/controller/AtmsExceptionHandler.java
View file @
0416601a
...
...
@@ -5,6 +5,7 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
;
import
pwc.taxtech.atms.exception.ApiException
;
import
pwc.taxtech.atms.exception.ApplicationException
;
import
pwc.taxtech.atms.exception.ServiceException
;
...
...
@@ -21,6 +22,8 @@ public class AtmsExceptionHandler extends ResponseEntityExceptionHandler {
return
handleApplicationException
((
ApplicationException
)
ex
);
}
else
if
(
ex
instanceof
ServiceException
)
{
return
handleServiceException
((
ServiceException
)
ex
);
}
else
if
(
ex
instanceof
ApiException
)
{
return
((
ApiException
)
ex
).
handle
();
}
else
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
build
();
}
...
...
atms-api/src/main/java/pwc/taxtech/atms/controller/TemplateController.java
View file @
0416601a
...
...
@@ -6,12 +6,21 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
pwc.taxtech.atms.dto.vatdto.TemplateByGroupDto
;
import
pwc.taxtech.atms.common.util.MyAsserts
;
import
pwc.taxtech.atms.exception.ApplicationException
;
import
pwc.taxtech.atms.common.ftp.FTPClientPool
;
import
pwc.taxtech.atms.dto.*
;
import
pwc.taxtech.atms.entitiy.Template
;
import
pwc.taxtech.atms.exception.BadParameterException
;
import
pwc.taxtech.atms.exception.NotFoundException
;
import
pwc.taxtech.atms.service.TemplateService
;
import
javax.servlet.http.HttpServletResponse
;
...
...
@@ -48,40 +57,26 @@ public class TemplateController extends BaseController {
@RequestMapping
(
value
=
"getTemplateJson"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
)
public
@ResponseBody
void
getTemplateBlob
(
@RequestParam
Long
templateID
,
HttpServletResponse
response
)
throws
URISyntaxException
{
if
(!
isParamValid
(
templateID
))
{
return
;
}
String
filePath
;
File
templateFile
;
InputStream
inputStream
=
null
;
void
getTemplateBlob
(
@RequestParam
Long
templateID
,
HttpServletResponse
response
)
{
MyAsserts
.
assertTrue
(
isParamValid
(
templateID
),
new
BadParameterException
());
Template
template
=
templateService
.
getTemplateByID
(
templateID
);
String
templatePath
=
templateService
.
getTemplatePath
(
templateID
);
MyAsserts
.
assertNotEmpty
(
templatePath
,
new
NotFoundException
());
if
(
StringUtils
.
isBlank
(
templatePath
))
{
return
;
}
filePath
=
this
.
getClass
().
getResource
(
""
).
toURI
().
getPath
();
String
tempPath
=
filePath
.
substring
(
0
,
filePath
.
indexOf
(
"classes"
)
+
"\\classes"
.
length
());
templateFile
=
new
File
(
tempPath
+
templatePath
);
try
{
//如果是系统报表就取本地文件夹,如果不是就取FTP
if
(
template
.
getIsSystemType
())
{
inputStream
=
new
BufferedInputStream
(
new
FileInputStream
(
templateFile
));
}
else
{
inputStream
=
ftpClientPool
.
download
(
templatePath
);
}
try
(
InputStream
inputStream
=
template
.
getIsSystemType
()
?
new
BufferedInputStream
(
new
FileInputStream
(
getTempFile
(
templatePath
)))
:
ftpClientPool
.
download
(
templatePath
);
OutputStream
out
=
response
.
getOutputStream
();)
{
//客户端保存的文件名
String
customFileName
=
"template_"
+
DateTime
.
now
().
toString
(
"yyyyMMddHHmmss"
)
+
".xlsx"
;
response
.
setHeader
(
"Content-Disposition"
,
String
.
format
(
"inline; filename=\""
+
customFileName
+
"\""
));
response
.
setContentType
(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
);
int
len
=
0
;
byte
[]
buffer
=
new
byte
[
1024
];
OutputStream
out
=
response
.
getOutputStream
();
while
((
len
=
inputStream
.
read
(
buffer
))
>
0
)
{
out
.
write
(
buffer
,
0
,
len
);
}
out
.
flush
();
//FileCopyUtils.copy(inputStream, response.getOutputStream());
}
catch
(
FileNotFoundException
e
)
{
...
...
@@ -89,20 +84,16 @@ public class TemplateController extends BaseController {
}
catch
(
Exception
e
)
{
logger
.
error
(
"Error downloading template file template.xlsx"
,
e
);
throw
new
ApplicationException
(
"Error downloading template file template.xlsx"
,
e
);
}
finally
{
try
{
templateFile
=
null
;
if
(
inputStream
!=
null
)
{
inputStream
.
close
();
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"Error closing inputStream. "
,
e
);
}
finally
{
inputStream
=
null
;
}
}
}
private
File
getTempFile
(
String
templatePath
)
throws
URISyntaxException
{
String
filePath
=
this
.
getClass
().
getResource
(
""
).
toURI
().
getPath
();
String
tempPath
=
filePath
.
substring
(
0
,
filePath
.
indexOf
(
"classes"
)
+
"\\classes"
.
length
());
return
new
File
(
tempPath
+
templatePath
);
}
@RequestMapping
(
value
=
"getTemplateUniqList"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
public
@ResponseBody
List
<
TemplateUniqDto
>
getTemplateUniqList
(
String
serviceTypeID
,
Integer
payTaxType
,
Integer
reportType
,
String
industryIDs
)
{
...
...
atms-api/src/main/java/pwc/taxtech/atms/exception/ApiException.java
0 → 100644
View file @
0416601a
package
pwc
.
taxtech
.
atms
.
exception
;
import
org.springframework.http.ResponseEntity
;
public
abstract
class
ApiException
extends
RuntimeException
{
public
ApiException
()
{
super
();
}
public
ApiException
(
String
message
)
{
super
(
message
);
}
public
ApiException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
public
ApiException
(
Throwable
cause
)
{
super
(
cause
);
}
public
abstract
<
Object
>
ResponseEntity
handle
();
}
atms-api/src/main/java/pwc/taxtech/atms/exception/BadParameterException.java
0 → 100644
View file @
0416601a
package
pwc
.
taxtech
.
atms
.
exception
;
import
org.springframework.http.ResponseEntity
;
public
class
BadParameterException
extends
ApiException
{
@Override
public
<
Object
>
ResponseEntity
handle
()
{
return
ResponseEntity
.
badRequest
().
build
();
}
}
atms-api/src/main/java/pwc/taxtech/atms/exception/BadParameterWithMsgException.java
0 → 100644
View file @
0416601a
package
pwc
.
taxtech
.
atms
.
exception
;
import
org.springframework.http.ResponseEntity
;
public
class
BadParameterWithMsgException
extends
ApiException
{
@Override
public
<
Object
>
ResponseEntity
handle
()
{
return
ResponseEntity
.
badRequest
().
body
(
getMessage
());
}
}
atms-api/src/main/java/pwc/taxtech/atms/exception/NotFoundException.java
0 → 100644
View file @
0416601a
package
pwc
.
taxtech
.
atms
.
exception
;
import
org.springframework.http.ResponseEntity
;
public
class
NotFoundException
extends
ApiException
{
@Override
public
<
Object
>
ResponseEntity
handle
()
{
return
ResponseEntity
.
notFound
().
build
();
}
}
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