From 768308ab47041062d9e97745099784acf297286b Mon Sep 17 00:00:00 2001 From: jiazx0107@163.com <jiazx0107@163.com> Date: 星期三, 08 十一月 2023 17:45:37 +0800 Subject: [PATCH] 提交粮情测试协议和流程 --- src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 49 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java b/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java index b26ff83..4bb2a3e 100644 --- a/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java +++ b/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java @@ -1,14 +1,18 @@ 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; @@ -24,6 +28,12 @@ @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"; @@ -46,6 +56,44 @@ } + /** + * 姣忛棿闅�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) { + + } + } + /** * 鎵ц缃戝叧蹇冭烦 @@ -63,5 +111,5 @@ gatewayRemoteManager.getRemoteService(conf.getPushProtocol()).heartbeat(conf); } } - + } -- Gitblit v1.9.3