| | |
| | | package com.fzzy.gateway; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.fzzy.api.data.ApiParam; |
| | | import com.fzzy.api.entity.ApiConfs; |
| | | import com.fzzy.api.service.*; |
| | | import com.fzzy.api.utils.ContextUtil; |
| | | import com.fzzy.api.utils.RedisUtil; |
| | | import com.fzzy.gateway.api.GatewayRemoteManager; |
| | | import com.fzzy.gateway.data.WeatherWebDto; |
| | | import com.fzzy.gateway.entity.GatewayConf; |
| | | import com.fzzy.gateway.service.GatewayConfService; |
| | | import com.fzzy.gateway.util.GatewayHttpUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.commons.lang.time.DateUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | |
| | | @Slf4j |
| | | @Component(GatewayTimerScheduled.BEAN_ID) |
| | | public class GatewayTimerScheduled { |
| | | |
| | | public static String DEFAULT_URL = "https://v0.yiketianqi.com/api?unescape=1&version=v61&appid={appId}&appsecret={appsecret}&cityid={cityid}"; |
| | | public static String DEFAULT_APP_ID = "49421971"; |
| | | public static String DEFAULT_APP_SECRET = "JmJE48Fv"; |
| | | public static String DEFAULT_CITYID = "101270101";//成都 |
| | | |
| | | |
| | | public static final String BEAN_ID = "gateway.timerScheduled"; |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 每间隔30分钟执行一次 |
| | | */ |
| | | @Scheduled(cron = "0 0/30 * * * ?") |
| | | public void scheduled30() { |
| | | |
| | | //定时获取气象信息 |
| | | doWeatherExe(); |
| | | } |
| | | |
| | | public void doWeatherExe() { |
| | | |
| | | try { |
| | | String url = DEFAULT_URL; |
| | | url = url.replace("{appId}", DEFAULT_APP_ID).replace("{appsecret}", DEFAULT_APP_SECRET).replace("{cityid}", DEFAULT_CITYID); |
| | | |
| | | String result = GatewayHttpUtil.doGet(url, null); |
| | | |
| | | if (null == result) { |
| | | log.error("当前外网获取气象信息失败……"); |
| | | return; |
| | | } |
| | | WeatherWebDto dto = JSON.parseObject(result, WeatherWebDto.class); |
| | | if (StringUtils.isNotEmpty(dto.getErrcode())) { |
| | | log.error("当前外网获取气象信息异常:{}", dto.getErrmsg()); |
| | | return; |
| | | } |
| | | |
| | | WeatherWebDto.contextMap.put("default", dto); |
| | | |
| | | |
| | | log.info("===========================系统定时获获取气象信息===={}==================",dto); |
| | | |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 执行网关心跳 |
| | |
| | | gatewayRemoteManager.getRemoteService(conf.getPushProtocol()).heartbeat(conf); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |