jinpengyong
2021-12-23 3d593b39648ff583a255765f76760768d6ba5f55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.moral.api.task;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
 
import java.util.List;
import java.util.Map;
 
import com.moral.api.entity.CityAqi;
import com.moral.api.entity.CityWeather;
import com.moral.api.entity.HistoryAqi;
import com.moral.api.service.CityAqiService;
import com.moral.api.service.CityWeatherService;
import com.moral.api.service.HistoryAqiService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
 
/*
 * 从正式坏境数据库获取第三方接口数据,调用开发环境的manager接口,将数据传给manager,由manager存入数据库
 * 包括的表数据:
 * city_aqi 城市aqi数据
 * city_weather 城市气象数据
 * history_aqi 国控站aqi数据
 * */
@Component
public class DataReplicationTask {
 
    @Autowired
    private CityAqiService cityAqiService;
 
    @Autowired
    private CityWeatherService cityWeatherService;
 
    @Autowired
    private HistoryAqiService historyAqiService;
 
    @Autowired
    private RestTemplate restTemplate;
 
    //city_aqi数据复制
    @XxlJob("cityAqiReplication")
    public ReturnT cityAqiReplication() {
        try {
            List<CityAqi> cityAqi = cityAqiService.getCityAqi();
            HttpEntity<List<CityAqi>> requestEntity = new HttpEntity<>(cityAqi);
            restTemplate.exchange("http://47.99.64.149:8082/dataReplication/insertCityAqi", HttpMethod.POST, requestEntity, Map.class);
        } catch (Exception e) {
            XxlJobHelper.log(e.getMessage());
            return new ReturnT(ReturnT.FAIL_CODE, e.getMessage());
        }
        return ReturnT.SUCCESS;
    }
 
    //city_weather数据复制
    @XxlJob("cityWeatherReplication")
    public ReturnT cityWeatherReplication() {
        try {
            List<CityWeather> cityWeather = cityWeatherService.getCityWeather();
            HttpEntity<List<CityWeather>> requestEntity = new HttpEntity<>(cityWeather);
            restTemplate.exchange("http://47.99.64.149:8082/dataReplication/insertCityWeather", HttpMethod.POST, requestEntity, Map.class);
        } catch (Exception e) {
            XxlJobHelper.log(e.getMessage());
            return new ReturnT(ReturnT.FAIL_CODE, e.getMessage());
        }
        return ReturnT.SUCCESS;
    }
 
    //history_aqi数据复制
    @XxlJob("historyAqiReplication")
    public ReturnT historyAqiReplication() {
        try {
            List<HistoryAqi> historyAqi = historyAqiService.getHistoryAqi();
            HttpEntity<List<HistoryAqi>> requestEntity = new HttpEntity<>(historyAqi);
            restTemplate.exchange("http://47.99.64.149:8082/dataReplication/insertHistoryAqi", HttpMethod.POST, requestEntity, Map.class);
        } catch (Exception e) {
            XxlJobHelper.log(e.getMessage());
            return new ReturnT(ReturnT.FAIL_CODE, e.getMessage());
        }
        return ReturnT.SUCCESS;
    }
 
}