package com.moral.api.controller; import com.moral.api.service.*; 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.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.Date; import java.util.HashMap; import java.util.Map; /** * @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; @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("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(); } 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 headers = new HashMap(); //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105 headers.put("Authorization", "APPCODE " + appcode); Map querys = new HashMap(); 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(); } } }