jinpengyong
2024-06-19 f05383c46370ec8c4f4b8b8165ffab3769dd06a2
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package com.moral.api.controller;
 
import com.moral.api.service.*;
import com.moral.api.util.DeviceExcelDTO;
import com.moral.api.util.EmailSpringUtil;
import com.moral.api.util.ExcelUtil;
import com.moral.api.util.HttpUtils;
import com.moral.constant.ResultMessage;
import com.moral.util.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.mail.MessagingException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.*;
 
/**
 * @ClassName UserController
 * @Description 用户管理
 * @Author 陈凯裕
 * @Date 2021/3/22 13:52
 * @Version TODO
 **/
@Slf4j
@Api(tags = {"公共功能"})
@RestController
@RequestMapping("/pub")
public class PubController {
    @Autowired
    private HistoryDailyService historyDailyService;
    @Autowired
    private HistoryFiveMinutelyService historyFiveMinutelyService;
 
    @Autowired
    private CityWeatherService cityWeatherService;
    @Autowired
    private ForecastService forecastService;
 
    @Autowired
    private HistoryAqiService historyAqiService;
    @Autowired
    private HistoryHourlyService historyHourlyService;
    @Autowired
    private HistoryMonthlyService historyMonthlyService;
    @Autowired
    private DeviceService deviceService;
 
    @Autowired
    private ManageCoordinateDetailService manageCoordinateDetailService;
 
    private final EmailSpringUtil emailSpringUtil;
    private final CityWeatherForecastService cityWeatherForecastService;
 
    public PubController(EmailSpringUtil emailSpringUtil, CityWeatherForecastService cityWeatherForecastService) {
        this.emailSpringUtil = emailSpringUtil;
        this.cityWeatherForecastService = cityWeatherForecastService;
    }
 
    @GetMapping("insertHistoryDaily")
    @ApiOperation(value = "天数据补录", notes = "天数据补录")
    public ResultMessage insertHistoryDaily(String time) {
        Date d = DateUtils.getDate(time,"yyyy-MM-dd");
        historyDailyService.insertHistoryDaily(time);
        int i = 0;
        return new ResultMessage();
    }
 
    @GetMapping("insertHistoryFiveMinutely")
    @ApiOperation(value = "5分钟数据", notes = "5分钟数据")
    public ResultMessage insertHistoryFiveMinutely() {
        String format = DateUtils.yyyy_MM_dd_HH_mm_EN;
        historyFiveMinutelyService.insertHistoryFiveMinutely();
        String s ="2023-10-13 03:35";
        String s1 ="2023-10-13 03:40";
        Date start = DateUtils.getDate(s,format);
        Date end = DateUtils.getDate(s1,format);
        return new ResultMessage();
    }
 
    @GetMapping("dateInsertHistoryHourlyJKAvg")
    @ApiOperation(value = "疾控中心小时数据", notes = "疾控中心小时数据")
    public ResultMessage dateInsertHistoryHourlyJKAvg(String start,String end) {
        Date ks = DateUtils.getDate(start,"yyyy-MM-dd HH:mm:ss");
        Date js = DateUtils.getDate("2024-01-23 13:00:00","yyyy-MM-dd HH:mm:ss");
        Date ends = DateUtils.getDate(end,"yyyy-MM-dd HH:mm:ss");
        while (DateUtils.isTimeBefor(js,ks)){
            String dateString = DateUtils.dateToDateString(ks);
            String dateString1 = DateUtils.dateToDateString(ends);
//            historyHourlyService.dateInsertHistoryHourlyJKAvg(start, end);
            historyHourlyService.dateInsertHistoryHourlyJKAvg(dateString, dateString1);
            ks = DateUtils.getDateAddHour(ks,1);
            ends = DateUtils.getDateAddHour(ends,1);
        }
//        String format = DateUtils.yyyy_MM_dd_HH_mm_EN;
//        String start ="2023-11-19 09:00"
//        String end ="2023-11-19 10:00";
//        Date start1 = DateUtils.getDate(start,format);
//        Date end1 = DateUtils.getDate(end,format);
 
        return new ResultMessage();
    }
 
    @GetMapping("FiveMinutelyTest")
    @ApiOperation(value = "5分钟数据1", notes = "5分钟数据1")
    public ResultMessage FiveMinutelyTest(String yz,String mac) {
        historyFiveMinutelyService.insertHistoryFiveMinutely(yz,mac);
        return new ResultMessage();
    }
 
    @GetMapping("insertHistoryAqi")
    @ApiOperation(value = "过控制战补偿", notes = "过控制战补偿")
    public ResultMessage insertHistoryAqi(String time) {
        historyAqiService.insertHistoryAqi(time);
        return new ResultMessage();
    }
 
    @GetMapping("insertHCHistoryAqi")
    @ApiOperation(value = "海城省控", notes = "海城省控")
    public ResultMessage insertHCHistoryAqi() {
        historyAqiService.insertHCHistoryAqi();
        return new ResultMessage();
    }
    @GetMapping("dateToChangShu")
    @ApiOperation(value = "常熟小时数据", notes = "常熟小时数据")
    public ResultMessage dateToChangShu() {
        historyHourlyService.dateToChangShu(null);
        return new ResultMessage();
    }
 
    @GetMapping("forecastO3")
    @ApiOperation(value = "O3预测接口调试", notes = "O3")
    public ResultMessage forecastO3() {
        forecastService.forecastO3();
        return new ResultMessage();
    }
    @GetMapping("insertCityWeather")
    @ApiOperation(value = "获取天气小时数据", notes = "获取天气小时数据")
    public ResultMessage insertCityWeather() {
        cityWeatherService.insertCityWeather();
        return new ResultMessage();
    }
 
    @GetMapping("insertCityWeatherForecast")
    @ApiOperation(value = "城市每日天气预测", notes = "城市每日天气预测")
    public ResultMessage insertCityWeatherForecast() {
        cityWeatherForecastService.insertCityWeatherForecast();
        return new ResultMessage();
    }
 
    @GetMapping("insertHistoryMonthly")
    @ApiOperation(value = "月数据", notes = "月数据")
    public ResultMessage insertHistoryMonthly() {
        historyMonthlyService.insertHistoryMonthly();
        return new ResultMessage();
    }
 
    @GetMapping("insertCoordinateDetail")
    @ApiOperation(value = "路段录入", notes = "路段录入")
    public ResultMessage insertCoordinateDetail() {
        String startTime ="2024-06-06 00:07:01";
        String endTime ="2024-06-06 23:07:01";
        manageCoordinateDetailService.insertCoordinateDetail(startTime,endTime);
        return new ResultMessage();
    }
 
 
    public static void main(String[] args) {
        String host = "https://pair.market.alicloudapi.com";
        String path = "/api/v1/pair/station_list";
        String method = "GET";
        String appcode = "31b6ea8f804a4472be3b633cfee44849";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("province", "辽宁省");
 
 
        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            System.out.println(response.toString());
            //获取response的body
            System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    @GetMapping("excelDevice")
    @ApiOperation(value = "excle", notes = "excle")
    public void  excelDevice() throws IOException {
        String startTime = DateUtils.dateToDateString(DateUtils.addDays(new Date(),-1),DateUtils.yyyy_MM_dd_EN);
        List<DeviceExcelDTO> list = deviceService.ListDeviceExcel(startTime,null,72);
       // String path = this.getClass().getClassLoader().getResource("/data/file").getPath();
        String path = System.getProperty("user.dir")+"/";
        String fileName = String.format("%s疾控中心数据-%s.xlsx",path,startTime);
        ByteArrayOutputStream out = null;
        try {
            // 生成excel文件
            out = ExcelUtil.generateExcel(list, DeviceExcelDTO.class);
            // 发送邮件
            String content = startTime+"疾控中心设备统计数据";
            String toMail = "ad@7drlb.com";
            emailSpringUtil.sendEmail("设备分钟数据",content,false,"909710561@qq.com",
                    toMail,"909710561@qq.com",null, fileName, new ByteArrayResource(out.toByteArray()));
        } catch (IOException e) {
            log.error(String.format("生成excel失败,原因:%s",e));
            e.printStackTrace();
        } catch (MessagingException e) {
            log.error(String.format("邮件发送失败,原因:%s",e));
            e.printStackTrace();
        }finally {
            if(out != null){
                out.close();
            }
        }
    }
}