Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
胡立强
/
VVAS-Weather
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 619e4fd3
authored
Nov 12, 2021
by
袁津
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[chg]优化日志打印:只有天气、aqi接口调用异常时,才打印日志
1 parent
ad71b23a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
42 deletions
src/main/java/com/viontech/service/impl/JsonService.java
src/main/java/com/viontech/service/impl/JsonService.java
View file @
619e4fd
...
...
@@ -38,27 +38,33 @@ public class JsonService {
// 调用weather接口
Callable
<
Boolean
>
weatherCallable
=
()
->
{
String
host
=
jsonclass
.
getHost1
();
String
path
=
jsonclass
.
getPath1
();
String
method
=
"POST"
;
String
appcode
=
jsonclass
.
getAppcode
();
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"Authorization"
,
"APPCODE "
+
appcode
);
headers
.
put
(
"Content-Type"
,
"application/x-www-form-urlencoded; charset=UTF-8"
);
Map
<
String
,
String
>
querys
=
new
HashMap
<>();
Map
<
String
,
String
>
bodys
=
new
HashMap
<>();
bodys
.
put
(
"cityId"
,
String
.
valueOf
(
cityId
));
HttpResponse
response
=
HttpUtils
.
doPost
(
host
,
path
,
method
,
headers
,
querys
,
bodys
);
String
json
=
EntityUtils
.
toString
(
response
.
getEntity
());
System
.
out
.
println
(
sdf
.
format
(
new
Date
())
+
"调用weather接口返回json:"
+
json
);
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
mapper
.
setDateFormat
(
new
SimpleDateFormat
(
"yyyy-MM-dd"
));
WeatherMessage
weatherMessage
=
mapper
.
readValue
(
json
,
WeatherMessage
.
class
);
if
(
null
!=
weatherMessage
)
{
dataMap
.
put
(
"WEATHER"
,
weatherMessage
);
return
true
;
String
json
=
""
;
try
{
String
host
=
jsonclass
.
getHost1
();
String
path
=
jsonclass
.
getPath1
();
String
method
=
"POST"
;
String
appcode
=
jsonclass
.
getAppcode
();
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"Authorization"
,
"APPCODE "
+
appcode
);
headers
.
put
(
"Content-Type"
,
"application/x-www-form-urlencoded; charset=UTF-8"
);
Map
<
String
,
String
>
querys
=
new
HashMap
<>();
Map
<
String
,
String
>
bodys
=
new
HashMap
<>();
bodys
.
put
(
"cityId"
,
String
.
valueOf
(
cityId
));
HttpResponse
response
=
HttpUtils
.
doPost
(
host
,
path
,
method
,
headers
,
querys
,
bodys
);
json
=
EntityUtils
.
toString
(
response
.
getEntity
());
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
mapper
.
setDateFormat
(
new
SimpleDateFormat
(
"yyyy-MM-dd"
));
WeatherMessage
weatherMessage
=
mapper
.
readValue
(
json
,
WeatherMessage
.
class
);
if
(
null
!=
weatherMessage
)
{
dataMap
.
put
(
"WEATHER"
,
weatherMessage
);
return
true
;
}
}
catch
(
Exception
e
)
{
// 接口调用发生异常时,打印接口返回信息
System
.
out
.
println
(
"调用weather接口发生异常,接口返回数据:"
+
json
);
throw
e
;
}
return
false
;
};
...
...
@@ -89,27 +95,34 @@ public class JsonService {
// 调用aqi接口
Callable
<
Boolean
>
aqiCallable
=
()
->
{
String
host
=
jsonclass
.
getHost2
();
String
path
=
jsonclass
.
getPath2
();
String
method
=
"POST"
;
String
appcode
=
jsonclass
.
getAppcode
();
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"Authorization"
,
"APPCODE "
+
appcode
);
headers
.
put
(
"Content-Type"
,
"application/x-www-form-urlencoded; charset=UTF-8"
);
Map
<
String
,
String
>
querys
=
new
HashMap
<>();
Map
<
String
,
String
>
bodys
=
new
HashMap
<>();
bodys
.
put
(
"cityId"
,
String
.
valueOf
(
cityId
));
HttpResponse
response
=
HttpUtils
.
doPost
(
host
,
path
,
method
,
headers
,
querys
,
bodys
);
String
json
=
EntityUtils
.
toString
(
response
.
getEntity
());
System
.
out
.
println
(
sdf
.
format
(
new
Date
())
+
"调用AQI接口返回json:"
+
json
);
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
mapper
.
setDateFormat
(
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
));
WeatherMessage
aqiMessage
=
mapper
.
readValue
(
json
,
WeatherMessage
.
class
);
if
(
null
!=
aqiMessage
)
{
dataMap
.
put
(
"AQI"
,
aqiMessage
);
return
true
;
String
json
=
""
;
try
{
String
host
=
jsonclass
.
getHost2
();
String
path
=
jsonclass
.
getPath2
();
String
method
=
"POST"
;
String
appcode
=
jsonclass
.
getAppcode
();
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
headers
.
put
(
"Authorization"
,
"APPCODE "
+
appcode
);
headers
.
put
(
"Content-Type"
,
"application/x-www-form-urlencoded; charset=UTF-8"
);
Map
<
String
,
String
>
querys
=
new
HashMap
<>();
Map
<
String
,
String
>
bodys
=
new
HashMap
<>();
bodys
.
put
(
"cityId"
,
String
.
valueOf
(
cityId
));
HttpResponse
response
=
HttpUtils
.
doPost
(
host
,
path
,
method
,
headers
,
querys
,
bodys
);
json
=
EntityUtils
.
toString
(
response
.
getEntity
());
System
.
out
.
println
(
sdf
.
format
(
new
Date
())
+
"调用AQI接口返回json:"
+
json
);
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
);
mapper
.
setDateFormat
(
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
));
WeatherMessage
aqiMessage
=
mapper
.
readValue
(
json
,
WeatherMessage
.
class
);
if
(
null
!=
aqiMessage
)
{
dataMap
.
put
(
"AQI"
,
aqiMessage
);
return
true
;
}
}
catch
(
Exception
e
)
{
// 接口调用发生异常时,打印接口返回信息
System
.
out
.
println
(
"调用AQI接口发生异常,接口返回数据:"
+
json
);
throw
e
;
}
return
false
;
};
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment