src/main/java/com/fzzy/data/ConfigData.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/gateway/util/GatewayHttpUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/protocol/fzzy/cmd/BaseRemoteImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/protocol/fzzy/server/MsgConsumer.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/fzzy/protocol/fzzy/service/FzzyGatewayGrainService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/application.yml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/fzzy/data/ConfigData.java
@@ -23,4 +23,7 @@ @Value("${igds.img-path}") private String imgPath; @Value("${igds.weather-url}") private String weatherUrl; } src/main/java/com/fzzy/gateway/GatewayTimerScheduled.java
@@ -7,6 +7,7 @@ import com.fzzy.api.service.*; import com.fzzy.api.utils.ContextUtil; import com.fzzy.api.utils.RedisUtil; import com.fzzy.data.ConfigData; import com.fzzy.gateway.api.GatewayRemoteManager; import com.fzzy.gateway.data.BaseReqData; import com.fzzy.gateway.data.WeatherWebDto; @@ -14,6 +15,7 @@ import com.fzzy.gateway.entity.GatewayDevice; import com.fzzy.gateway.service.GatewayConfService; import com.fzzy.gateway.util.GatewayHttpUtil; import jdk.nashorn.internal.runtime.regexp.joni.Config; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateUtils; @@ -33,7 +35,7 @@ @Component(GatewayTimerScheduled.BEAN_ID) public class GatewayTimerScheduled { public static String DEFAULT_URL = "https://v1.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";//成都 @@ -45,6 +47,8 @@ private GatewayConfService confService; @Resource private GatewayRemoteManager gatewayRemoteManager; @Resource private ConfigData configData; /** @@ -84,12 +88,13 @@ public void doWeatherExe() { try { String url = DEFAULT_URL; String url = configData.getWeatherUrl(); url = url.replace("{appId}", DEFAULT_APP_ID).replace("{appsecret}", DEFAULT_APP_SECRET).replace("{cityid}", DEFAULT_CITYID); log.debug("------气象URL---{}", url); String result = GatewayHttpUtil.doGet(url, null); log.debug("------气象请求信息URL---{}", url); String result = GatewayHttpUtil.doGet(url); if (null == result) { log.error("当前外网获取气象信息失败……"); src/main/java/com/fzzy/gateway/util/GatewayHttpUtil.java
@@ -9,6 +9,11 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.Map; @@ -17,6 +22,8 @@ */ @Slf4j public class GatewayHttpUtil { private static final int TIMEOUT_IN_MILLIONS = 5000; /** * 执行GET请求 @@ -62,4 +69,54 @@ return responseText; } public static String doGet(String urlStr) { URL url = null; HttpURLConnection conn = null; InputStream is = null; ByteArrayOutputStream baos = null; try { url = new URL(urlStr); conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(TIMEOUT_IN_MILLIONS); conn.setConnectTimeout(TIMEOUT_IN_MILLIONS); conn.setRequestMethod("GET"); conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("Content-Type", "application/json"); if (conn.getResponseCode() == 200) { is = conn.getInputStream(); baos = new ByteArrayOutputStream(); int len = -1; byte[] buf = new byte[128]; while ((len = is.read(buf)) != -1) { baos.write(buf, 0, len); } baos.flush(); return baos.toString(); } else { throw new RuntimeException(" responseCode is not 200 ... "); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (is != null) is.close(); } catch (IOException e) { } try { if (baos != null) baos.close(); } catch (IOException e) { } conn.disconnect(); } return null; } } src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java
@@ -68,7 +68,7 @@ //粮情解析 log.info("控制柜--->平台,推动的粮情信息--{}", response); log.info("控制柜--->平台,控制柜返回粮情检测结果--{}", response); //粮情封装和处理 if (StringUtils.isEmpty(response.getLayerPerCircle())) { @@ -91,10 +91,9 @@ //信息调整封装 private void buildBizInfo1(Response2102 response) { String depotId = response.getHouseId(); //获取请求信息 BaseReqData reqData = ServerUtils.getSyncReq(depotId); BaseReqData reqData = ServerUtils.getSyncReq(response.getHouseId()); if (null == reqData) { log.error("--粮情封装解析,未获取到请求相关参数----"); @@ -132,7 +131,7 @@ //根号 int cableNum = 1, position = 0; double curTemp = response.getTMin(); double curTemp; String[] attr = response.getPoints().split(","); int x = 0, y = 0, z = 0; for (int i = 0; i < attr.length; i++) { src/main/java/com/fzzy/protocol/fzzy/cmd/BaseRemoteImpl.java
@@ -41,7 +41,7 @@ } public InvokeResult send(SendMessage message) { log.debug("平台发送报文---->>控制柜--{}", message.toString()); // log.debug("平台发送报文---->>控制柜--{}", message.toString()); IoSessionQuery sessionFactory = FzzyServerEngine.ioServer.getSessionQuery(); List<IoSession> sessions = sessionFactory.getAllSession(); IoSession session = null; src/main/java/com/fzzy/protocol/fzzy/server/MsgConsumer.java
@@ -43,7 +43,7 @@ reMessage.setStrMsg(message); session.setCompanyId("0000"); log.debug("控制柜到---->>>>平台,未解析信息:IP={},PORT={},message={}", reMessage.getIp(), reMessage.getPort(), message); log.debug("控制柜到---->>>>平台,暂未解析信息:IP={},PORT={},message={}", reMessage.getIp(), reMessage.getPort(), message); //调用解析接口开始解析 if (null == analysisService) { src/main/java/com/fzzy/protocol/fzzy/service/FzzyGatewayGrainService.java
@@ -60,26 +60,26 @@ try { //Step 请求信息放入内存 ServerUtils.addSyncReq2Map(device.getDepotId(), reqData); ServerUtils.addSyncReq2Map(device.getDepotIdSys(), reqData); // Step1 生成粮情信息 SendMessage message = GrainCommandBuilder.getInstance().buildMessage(device,apiCommonDevice); // 发送命令 InvokeResult result = send(device.getIp(), device.getPort(), message.getByteMsg()); log.error("平台------>>>>控制柜:粮情检测-{}", message); log.error("平台------>>>>控制柜:发送粮情检测命令-{}", message); // 封装返回信息 if (!InvokeResult.SUCCESS.getCode().equals(result.getCode())) { log.error("平台------>>>>控制柜:粮情检测-失败{}", result.getMessage()); log.error("平台------>>>>控制柜:发送粮情检测命令-失败{}", result.getMessage()); resp.setCode(500); resp.setMsg("平台------>>>>控制柜:粮情检测-失败:" + result.getMessage()); resp.setMsg("平台------>>>>控制柜:发送粮情检测命令-失败:" + result.getMessage()); } } catch (Exception e) { log.error("粮情检测异常:{}", e); resp.setCode(500); resp.setMsg("粮情检测异常:" + e.getMessage()); resp.setMsg("平台------>>>>控制柜:发送粮情检测命令:" + e.getMessage()); return resp; } return resp; src/main/resources/application.yml
@@ -42,3 +42,4 @@ companyId: 5326 file-path: C:/app/igds-api img-path: D:/IGDS/FILE/ weather-url: https://v1.yiketianqi.com/api?unescape=1&version=v61&appid={appId}&appsecret={appsecret}&cityid={cityid}