Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
aroad_aqsc
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
许言琪
aroad_aqsc
Commits
808952c9
提交
808952c9
authored
5月 30, 2019
作者:
Phyday
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
路网监测-综合监测新增天气功能
上级
67c2cb3e
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
370 行增加
和
0 行删除
+370
-0
RestTemplateConfig.java
...ant/framework/galaxy/aroad/config/RestTemplateConfig.java
+24
-0
GlgzcxSstqController.java
...module/roadcondition/controller/GlgzcxSstqController.java
+117
-0
CastInfo.java
...ework/galaxy/aroad/module/roadcondition/dto/CastInfo.java
+60
-0
WeatherDto.java
...ork/galaxy/aroad/module/roadcondition/dto/WeatherDto.java
+45
-0
WeatherForecastDto.java
...xy/aroad/module/roadcondition/dto/WeatherForecastDto.java
+42
-0
WeatherLivesDto.java
...alaxy/aroad/module/roadcondition/dto/WeatherLivesDto.java
+58
-0
WxMappingJackson2HttpMessageConverter.java
.../aroad/support/WxMappingJackson2HttpMessageConverter.java
+24
-0
没有找到文件。
src/main/java/com/elephant/framework/galaxy/aroad/config/RestTemplateConfig.java
0 → 100644
浏览文件 @
808952c9
package
com
.
elephant
.
framework
.
galaxy
.
aroad
.
config
;
import
com.elephant.framework.galaxy.aroad.support.WxMappingJackson2HttpMessageConverter
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.client.RestTemplate
;
/**
* @program: RestTemplate 配置类
* @description: 用于访问 Web Api
* @author: songwenjie
* @create: 2019-03-27 13:57
**/
@Configuration
public
class
RestTemplateConfig
{
@Bean
public
RestTemplate
restTemplate
(
RestTemplateBuilder
restTemplateBuilder
){
RestTemplate
restTemplate
=
restTemplateBuilder
.
build
();
restTemplate
.
getMessageConverters
().
add
(
new
WxMappingJackson2HttpMessageConverter
());
return
restTemplate
;
}
}
src/main/java/com/elephant/framework/galaxy/aroad/module/roadcondition/controller/GlgzcxSstqController.java
0 → 100644
浏览文件 @
808952c9
package
com
.
elephant
.
framework
.
galaxy
.
aroad
.
module
.
roadcondition
.
controller
;
import
com.elephant.framework.galaxy.aroad.module.roadcondition.dto.WeatherDto
;
import
com.elephant.framework.galaxy.aroad.module.roadcondition.dto.WeatherLivesDto
;
import
com.elephant.framework.galaxy.aroad.module.common.controller.BaseController
;
import
com.elephant.framework.galaxy.aroad.response.R
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
java.net.URI
;
import
java.util.*
;
/**
* <p>
* 高德实时天气
* </p>
* @author xuzhitu
* @since 2019-04-23
*/
@RestController
@RequestMapping
(
"/qxfw"
)
public
class
GlgzcxSstqController
extends
BaseController
{
@Autowired
private
RedisTemplate
redisTemplate
;
@Autowired
private
RestTemplate
restTemplate
;
@RequestMapping
(
"/cxqx"
)
public
R
getWeatherLivesOfShandong
(){
//获取山东17地市的实时天气数据并写入缓存
List
<
WeatherLivesDto
>
weatherLives
=
new
ArrayList
<>();
weatherLives
=
(
List
)
redisTemplate
.
opsForValue
().
get
(
"weatherLives"
);
if
(
weatherLives
==
null
||
weatherLives
.
size
()
<=
0
)
{
System
.
out
.
println
(
"111"
);
weatherLives
=
getWeatherLives
();
redisTemplate
.
opsForValue
().
set
(
"weatherLives"
,
weatherLives
);
// 实时天气Redis缓存时间设为1小时
redisTemplate
.
expire
(
"weatherLives"
,
3600
l
,
java
.
util
.
concurrent
.
TimeUnit
.
SECONDS
);
}
return
new
R
<>(
weatherLives
);
}
private
static
Iterable
<
Object
[]>
getCityCodes
()
{
return
Arrays
.
asList
(
new
Object
[][]{
//山东17地市
{
370100
,
"济南市"
,
"base"
},
{
370200
,
"青岛市"
,
"base"
},
{
370300
,
"淄博市"
,
"base"
},
{
370400
,
"枣庄市"
,
"base"
},
{
370500
,
"东营市"
,
"base"
},
{
370600
,
"烟台市"
,
"base"
},
{
370700
,
"潍坊市"
,
"base"
},
{
370800
,
"济宁市"
,
"base"
},
{
370900
,
"泰安市"
,
"base"
},
{
371000
,
"威海市"
,
"base"
},
{
371100
,
"日照市"
,
"base"
},
{
371300
,
"临沂市"
,
"base"
},
{
371400
,
"德州市"
,
"base"
},
{
371500
,
"聊城市"
,
"base"
},
{
371600
,
"滨州市"
,
"base"
},
{
371700
,
"菏泽市"
,
"base"
},
});
}
/**
* 获取实时天气
*/
private
List
<
WeatherLivesDto
>
getWeatherLives
()
{
List
<
WeatherLivesDto
>
weatherLives
=
new
ArrayList
<>();
// RestTemplate restTemplate = new RestTemplate();
Map
<
String
,
Object
>
map
=
new
HashMap
();
map
.
put
(
"key"
,
"88036e8e6a7f0d69cf8d38e84da278f5"
);
Iterable
<
Object
[]>
params
=
getCityCodes
();
params
.
forEach
(
p
->{
map
.
put
(
"city"
,
p
[
0
]);
map
.
put
(
"extensions"
,
p
[
2
]);
URI
uri
=
UriComponentsBuilder
.
fromUriString
(
"https://restapi.amap.com/v3/weather/weatherInfo?"
+
"city={city}&key={key}&extensions={extensions}"
)
.
build
(
map
);
WeatherDto
weatherResponse
=
restTemplate
.
getForObject
(
uri
,
WeatherDto
.
class
);
if
(
weatherResponse
.
getStatus
()
!=
1
)
{
return
;
}
//组装批量操作数据
weatherResponse
.
getLives
().
forEach
(
m
->{
weatherLives
.
add
(
WeatherLivesDto
.
builder
()
.
province
(
m
.
getProvince
())
.
city
(
m
.
getCity
())
.
adcode
(
m
.
getAdcode
())
.
weather
(
m
.
getWeather
())
.
temperature
(
m
.
getTemperature
())
.
winddirection
(
m
.
getWinddirection
())
.
windpower
(
m
.
getWindpower
())
.
humidity
(
m
.
getHumidity
())
.
reporttime
(
m
.
getReporttime
())
.
build
()
);
});
});
return
weatherLives
;
}
}
src/main/java/com/elephant/framework/galaxy/aroad/module/roadcondition/dto/CastInfo.java
0 → 100644
浏览文件 @
808952c9
package
com
.
elephant
.
framework
.
galaxy
.
aroad
.
module
.
roadcondition
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
/**
* @program:
* @description:
* @author: xuzhitu
* @create: 2019-04-24 09:26
**/
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
CastInfo
implements
Serializable
{
/**
* 日期
*/
private
String
date
;
/**
* 星期几
*/
private
String
week
;
/**
* 白天天气现象
*/
private
String
dayweather
;
/**
* 晚上天气现象
*/
private
String
nightweather
;
/**
* 白天温度
*/
private
String
daytemp
;
/**
* 晚上温度
*/
private
String
nighttemp
;
/**
* 白天风向
*/
private
String
daywind
;
/**
* 晚上风向
*/
private
String
nightwind
;
/**
* 白天风力
*/
private
String
daypower
;
/**
* 晚上风力
*/
private
String
nightpower
;
}
src/main/java/com/elephant/framework/galaxy/aroad/module/roadcondition/dto/WeatherDto.java
0 → 100644
浏览文件 @
808952c9
package
com
.
elephant
.
framework
.
galaxy
.
aroad
.
module
.
roadcondition
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* @program:
* @description:
* @author: xuzhitu
* @create: 2019-04-24 09:26
**/
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
WeatherDto
implements
Serializable
{
/**
* 返回状态
*/
private
Integer
status
;
/**
* 返回结果总数目
*/
private
Integer
count
;
/**
* 返回的状态信息
*/
private
String
info
;
/**
* 返回状态说明,10000代表正确
*/
private
Integer
infocode
;
/**
* 实况天气数据信息
*/
private
List
<
WeatherLivesDto
>
lives
;
/**
* 预报天气信息数据
*/
private
List
<
WeatherForecastDto
>
forecast
;
}
src/main/java/com/elephant/framework/galaxy/aroad/module/roadcondition/dto/WeatherForecastDto.java
0 → 100644
浏览文件 @
808952c9
package
com
.
elephant
.
framework
.
galaxy
.
aroad
.
module
.
roadcondition
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* @program:
* @description:
* @author: xuzhitu
* @create: 2019-04-24 09:26
**/
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
WeatherForecastDto
implements
Serializable
{
/**
* 城市名称
*/
private
String
city
;
/**
* 城市编码
*/
private
Integer
adcode
;
/**
*
* 省份名称
*/
private
String
province
;
/**
* 预报发布时间
*/
private
String
reporttime
;
/**
* 预报数据list结构,元素cast,按顺序为当天、第二天、第三天的预报数据
*/
private
List
<
CastInfo
>
casts
;
}
src/main/java/com/elephant/framework/galaxy/aroad/module/roadcondition/dto/WeatherLivesDto.java
0 → 100644
浏览文件 @
808952c9
package
com
.
elephant
.
framework
.
galaxy
.
aroad
.
module
.
roadcondition
.
dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
/**
* @program:
* @description:
* @author: xuzhitu
* @create: 2019-04-24 09:26
**/
@Data@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
WeatherLivesDto
implements
Serializable
{
/**
* 省份名称
*/
private
String
province
;
/**
* 城市名称
*/
private
String
city
;
/**
* 区域编码
*/
private
Integer
adcode
;
/**
* 天气现象(汉字描述)
*/
private
String
weather
;
/**
* 实时气温,单位:摄氏度
*/
private
String
temperature
;
/**
* 风向描述
*/
private
String
winddirection
;
/**
* 风力级别,单位:级
*/
private
String
windpower
;
/**
* 空气湿度
*/
private
String
humidity
;
/**
* 预报发布时间
*/
private
String
reporttime
;
}
src/main/java/com/elephant/framework/galaxy/aroad/support/WxMappingJackson2HttpMessageConverter.java
0 → 100644
浏览文件 @
808952c9
package
com
.
elephant
.
framework
.
galaxy
.
aroad
.
support
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @program:
* @description: restTemplate 媒体类型支持类
* @author: songwenjie
* @create: 2019-03-27 15:28
**/
public
class
WxMappingJackson2HttpMessageConverter
extends
MappingJackson2HttpMessageConverter
{
public
WxMappingJackson2HttpMessageConverter
(){
List
<
MediaType
>
mediaTypes
=
new
ArrayList
<>();
// mediaTypes.add(MediaType.TEXT_PLAIN);
// mediaTypes.add(MediaType.TEXT_HTML); //加入text/html类型的支持
mediaTypes
.
add
(
MediaType
.
ALL
);
setSupportedMediaTypes
(
mediaTypes
);
// tag6
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论