Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jiwei-api
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
马天浩
jiwei-api
Commits
81c5a1ab
Commit
81c5a1ab
authored
Dec 16, 2020
by
汪昱
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
金安易-临安区村级小微权力数据接口增加文档下载和添加日志
parent
8704ffa1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
9 deletions
+87
-9
JAYSmartController.java
.../com/mth/requestsecret/controller/JAYSmartController.java
+87
-9
No files found.
src/main/java/com/mth/requestsecret/controller/JAYSmartController.java
View file @
81c5a1ab
package
com
.
mth
.
requestsecret
.
controller
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.
http.HttpEntity
;
import
org.springframework.
http.HttpHeaders
;
import
org.springframework.http.
HttpMethod
;
import
org.springframework.
http.ResponseEntity
;
import
org.springframework.
boot.web.client.RestTemplateBuilder
;
import
org.springframework.
core.io.Resource
;
import
org.springframework.http.
*
;
import
org.springframework.
web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.client.RestTemplate
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
import
java.net.URLEncoder
;
import
java.nio.charset.Charset
;
import
java.util.HashMap
;
/**
...
...
@@ -18,14 +24,22 @@ import java.util.HashMap;
* @date 2020/12/11 16:42
*/
@RestController
@Slf4j
public
class
JAYSmartController
{
@Autowired
private
RestTemplate
restTemplate
;
@Autowired
private
RestTemplateBuilder
restTemplateBuilder
;
private
final
String
host
=
"http://www.laxwql.com:8768"
;
private
final
String
authCode
=
"nXprocFLHaGa9LzRqGA3u"
;
private
final
String
downAddr
=
"http://www.laxwql.com:8767/picture"
;
private
final
String
username
=
"临安区"
;
private
final
String
password
=
"1QAZ2wsx"
;
/**
* 获取单位列表
* @return
...
...
@@ -36,6 +50,7 @@ public class JAYSmartController {
.
append
(
"/queryUnitList.json?authCode="
)
.
append
(
authCode
)
.
append
(
"&apiName=onlyOrganize"
).
toString
();
log
.
info
(
"访问临安区村级小微权力平台数据接口/获取单位列表 -->"
+
url
);
HttpHeaders
headers
=
new
HttpHeaders
();
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
headers
);
return
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
request
,
String
.
class
);
...
...
@@ -56,7 +71,7 @@ public class JAYSmartController {
.
append
(
"&unitCode="
).
append
(
unitCode
)
.
append
(
"&year="
).
append
(
null
==
year
?
""
:
year
)
.
append
(
"&apiName=onlyOrganize"
).
toString
();
log
.
info
(
"访问临安区村级小微权力平台数据接口/获取公开表数据 -->"
+
url
);
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
new
HttpHeaders
());
return
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
request
,
String
.
class
);
}
...
...
@@ -72,13 +87,13 @@ public class JAYSmartController {
.
append
(
"/villageEngineeringMaster.json?authCode="
)
.
append
(
authCode
)
.
append
(
"&unitCode="
).
append
(
unitCode
).
toString
();
log
.
info
(
"访问临安区村级小微权力平台数据接口/获取村级工程 -->"
+
url
);
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
new
HttpHeaders
());
return
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
request
,
String
.
class
);
}
/**
* 根据单位代码获取 村级工程
付款情况
表数据
* 根据单位代码获取 村级工程
付款情况
表数据
* @param unitCode 单位代码
* @return
*/
...
...
@@ -88,7 +103,7 @@ public class JAYSmartController {
.
append
(
"/villageEngineeringDetail.json?authCode="
)
.
append
(
authCode
)
.
append
(
"&unitCode="
).
append
(
unitCode
).
toString
();
log
.
info
(
"访问临安区村级小微权力平台数据接口/获取村级工程付款情况表数据 -->"
+
url
);
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
new
HttpHeaders
());
return
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
request
,
String
.
class
);
}
...
...
@@ -104,9 +119,72 @@ public class JAYSmartController {
.
append
(
"/queryAssetsResourcesList.json?authCode="
)
.
append
(
authCode
)
.
append
(
"&unitCode="
).
append
(
unitCode
).
toString
();
log
.
info
(
"访问临安区村级小微权力平台数据接口/获取资产资源处置表数据 -->"
+
url
);
HttpEntity
<
HashMap
<
String
,
Object
>>
request
=
new
HttpEntity
<>(
null
,
new
HttpHeaders
());
return
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
request
,
String
.
class
);
}
@GetMapping
(
"/downloadContract"
)
public
ResponseEntity
downloadContract
(
HttpServletResponse
response
,
HttpServletRequest
request
,
String
contractAddr
){
String
url
=
new
StringBuffer
(
downAddr
).
append
(
contractAddr
).
toString
();
RestTemplate
template
=
restTemplateBuilder
.
basicAuthentication
(
username
,
password
,
Charset
.
forName
(
"UTF-8"
)).
build
();
ResponseEntity
<
Resource
>
entity
=
template
.
postForEntity
(
url
,
null
,
Resource
.
class
);
InputStream
bis
=
null
;
OutputStream
outputStream
=
null
;
try
{
bis
=
entity
.
getBody
().
getInputStream
();
outputStream
=
response
.
getOutputStream
();
// DataInputStream dataInputStream = new DataInputStream(bis);
String
filename
=
contractAddr
.
substring
(
contractAddr
.
lastIndexOf
(
"/"
)
+
1
);
// 解决文件名乱码问题,获取浏览器类型,转换对应文件名编码格式,IE要求文件名必须是utf-8, firefo要求是iso-8859-1编码
String
agent
=
request
.
getHeader
(
"user-agent"
);
if
(
agent
.
contains
(
"FireFox"
))
{
filename
=
new
String
(
filename
.
getBytes
(
"UTF-8"
),
"iso-8859-1"
);
}
else
{
filename
=
URLEncoder
.
encode
(
filename
,
"UTF-8"
);
}
log
.
info
(
"访问临安区村级小微权力平台数据接口/下载合同文书 -->"
+
url
+
";文件 -->"
+
filename
);
// String path = "D:/wangy/test/" + file;
// FileOutputStream fileOutputStream = new FileOutputStream(new File(path));
// 设置下载文件的mineType,告诉浏览器下载文件类型
String
mineType
=
request
.
getServletContext
().
getMimeType
(
filename
);
response
.
setContentType
(
mineType
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
filename
);
byte
[]
buffer
=
new
byte
[
1024
];
int
length
;
while
((
length
=
bis
.
read
(
buffer
))
>
0
)
{
outputStream
.
write
(
buffer
,
0
,
length
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
log
.
info
(
"访问临安区村级小微权力平台数据接口,下载合同文书异常"
);
}
finally
{
if
(
outputStream
!=
null
)
{
try
{
outputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
if
(
bis
!=
null
)
{
try
{
bis
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
ResponseEntity
.
ok
(
"下载成功!"
);
}
}
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