Commit 8e47d0f6 by HlQ

[chg]

1.定时任务添加至配置文件,可配置定时任务执行时间
2.修改打包时,jar包的名字
1 parent cf921cf7
......@@ -62,6 +62,7 @@
</dependencies>
<build>
<finalName>VVAS-DataCenter-Weather</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
......
......@@ -19,7 +19,7 @@ public class WeatherController {
@GetMapping("/getWeather")
public Object get() {
System.out.println("手动调用天气");
System.out.println("手动调用,获取今天的天气!");
try {
weatherService.getWeatherInfo();
} catch (IOException e) {
......
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();
}
......
......@@ -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("天气服务调用结束");
......
......@@ -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
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!