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 8e47d0f6
authored
Nov 02, 2021
by
HlQ
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[chg]
1.定时任务添加至配置文件,可配置定时任务执行时间 2.修改打包时,jar包的名字
1 parent
cf921cf7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
12 additions
and
9 deletions
pom.xml
src/main/java/com/viontech/controller/WeatherController.java
src/main/java/com/viontech/job/SchedulerTask.java
src/main/java/com/viontech/service/impl/WeatherService.java
src/main/resources/application.yml
pom.xml
View file @
8e47d0f
...
...
@@ -62,6 +62,7 @@
</dependencies>
<build>
<finalName>
VVAS-DataCenter-Weather
</finalName>
<plugins>
<plugin>
<artifactId>
maven-compiler-plugin
</artifactId>
...
...
src/main/java/com/viontech/controller/WeatherController.java
View file @
8e47d0f
...
...
@@ -19,7 +19,7 @@ public class WeatherController {
@GetMapping
(
"/getWeather"
)
public
Object
get
()
{
System
.
out
.
println
(
"手动调用
天气
"
);
System
.
out
.
println
(
"手动调用
,获取今天的天气!
"
);
try
{
weatherService
.
getWeatherInfo
();
}
catch
(
IOException
e
)
{
...
...
src/main/java/com/viontech/job/SchedulerTask.java
View file @
8e47d0f
package
com
.
viontech
.
job
;
import
java.io.IOException
;
import
com.viontech.service.impl.WeatherService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
/**
* @author zhaibolin
*/
...
...
@@ -16,7 +16,7 @@ public class SchedulerTask {
@Autowired
private
WeatherService
weatherService
;
@Scheduled
(
cron
=
"${schedules}"
)
@Scheduled
(
cron
=
"${schedules
:0 0 8 * * ?
}"
)
private
void
process
()
throws
IOException
{
weatherService
.
getWeatherInfo
();
}
...
...
src/main/java/com/viontech/service/impl/WeatherService.java
View file @
8e47d0f
...
...
@@ -6,10 +6,8 @@ import com.viontech.model.SimpleWeather;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.io.IOException
;
import
java.sql.Timestamp
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
...
...
@@ -34,7 +32,9 @@ public class WeatherService {
private
CityService
cityService
;
public
void
getWeatherInfo
()
throws
IOException
{
Date
date
=
java
.
sql
.
Date
.
valueOf
(
LocalDate
.
now
());
// 摆子哥之前为啥这样写?
// Date date = java.sql.Date.valueOf(LocalDate.now());
Date
date
=
Date
.
from
(
LocalDate
.
now
().
atStartOfDay
(
ZoneId
.
systemDefault
()).
toInstant
());
System
.
out
.
println
(
LocalDateTime
.
now
()
+
"天气服务调用开始"
);
List
<
Mall
>
mallList
=
cityService
.
selectMallList
();
List
<
City
>
cityList
=
cityService
.
selectCityList
(
mallList
);
...
...
@@ -57,6 +57,7 @@ public class WeatherService {
SimpleWeather
simpleWeather
=
jsonService
.
getWeatherInfo
(
weatherCode
);
if
(
simpleWeather
==
null
)
{
System
.
out
.
println
(
weatherCode
);
continue
;
}
jdbcTemplate
.
update
(
...
...
@@ -70,7 +71,7 @@ public class WeatherService {
Integer
.
parseInt
(
simpleWeather
.
getAqi
()),
Integer
.
parseInt
(
simpleWeather
.
getFengli
().
substring
(
0
,
1
))
);
System
.
out
.
println
(
""
+
bcity
.
getCityName
()
+
"天气插入成功"
);
System
.
out
.
println
(
bcity
.
getCityName
()
+
"天气插入成功"
);
}
}
System
.
out
.
println
(
"天气服务调用结束"
);
...
...
src/main/resources/application.yml
View file @
8e47d0f
...
...
@@ -30,6 +30,7 @@ spring:
jackson
:
date-format
:
yyyy-MM-dd HH:mm:ss
time-zone
:
GMT+8
## 自定义配置项 ##
# 天气服务调用的定时任务,默认每天早上8点
schedules
:
0 0 8 * * ?
\ No newline at end of file
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