From 5bb3ad3944ff229baff1d8bb92caf55d816ee68b Mon Sep 17 00:00:00 2001 From: jiazx0107@163.com <jiazx0107@163.com> Date: 星期六, 02 十二月 2023 18:34:45 +0800 Subject: [PATCH] 提交粮情协议1 --- src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java b/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java index 379583d..8daf788 100644 --- a/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java +++ b/src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java @@ -2,13 +2,16 @@ import com.alibaba.fastjson.JSON; import com.fzzy.api.data.ApiParam; +import com.fzzy.api.data.GatewayDeviceProtocol; 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.BaseReqData; import com.fzzy.gateway.data.WeatherWebDto; import com.fzzy.gateway.entity.GatewayConf; +import com.fzzy.gateway.entity.GatewayDevice; import com.fzzy.gateway.service.GatewayConfService; import com.fzzy.gateway.util.GatewayHttpUtil; import lombok.extern.slf4j.Slf4j; @@ -19,6 +22,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; +import java.util.Collection; import java.util.Date; import java.util.List; @@ -29,7 +33,7 @@ @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_URL = "https://v1.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";//鎴愰兘 @@ -39,7 +43,6 @@ @Resource private GatewayConfService confService; - @Resource private GatewayRemoteManager gatewayRemoteManager; @@ -48,13 +51,25 @@ * <p> * 鍥哄畾鏃堕棿锛氭瘡闂撮殧10鍒嗛挓鎵ц涓�娆� */ - @Scheduled(cron = "0 0/10 * * * ? ") + @Scheduled(cron = "0 0/10 * * * ?") public void scheduled() { //缃戝叧鐨勫績璺虫墽琛� doHeartbeat(); } + + /** + * <p> + * 姣忛棿闅�3绉掓墽琛屼竴娆′簨浠� + */ + @Scheduled(cron = "0/3 * * * * ?") + public void scheduled3() { + + //鎵цHTTP鍦扮璇锋眰 + exeHttpWeightReq(); + } + /** * 姣忛棿闅�30鍒嗛挓鎵ц涓�娆� @@ -73,7 +88,7 @@ url = url.replace("{appId}", DEFAULT_APP_ID).replace("{appsecret}", DEFAULT_APP_SECRET).replace("{cityid}", DEFAULT_CITYID); - log.debug("------姘旇薄URL---{}",url); + log.debug("------姘旇薄URL---{}", url); String result = GatewayHttpUtil.doGet(url, null); if (null == result) { @@ -89,7 +104,7 @@ WeatherWebDto.contextMap.put("default", dto); - log.info("===========================绯荤粺瀹氭椂鑾疯幏鍙栨皵璞′俊鎭�===={}==================",dto); + log.info("===========================绯荤粺瀹氭椂鑾疯幏鍙栨皵璞′俊鎭�===={}==================", dto); } catch (Exception e) { @@ -114,4 +129,30 @@ } } + + /** + * 鎵ц鍦扮HTTP璇锋眰鍗忚 + */ + private void exeHttpWeightReq() { + //鑾峰彇璁惧 + Collection<GatewayDevice> list = GatewayUtils.listDeviceWeight(); + + if (null == list || list.isEmpty()) return; + + BaseReqData reqData; + for (GatewayDevice device : list) { + + if (!GatewayDeviceProtocol.DEVICE_WEIGHT_HTTP.getCode().equals(device.getSyncProtocol())) { + continue; + } + + reqData = new BaseReqData(); + reqData.setDevice(device); + reqData.setDeviceName(device.getDeviceName()); + reqData.setProductId(device.getProductId()); + reqData.setDeviceId(device.getDeviceId()); + + gatewayRemoteManager.getSyncWeightService(device.getSyncProtocol()).syncWeightInfo(reqData); + } + } } -- Gitblit v1.9.3