| | |
| | | |
| | | @Value("${igds.img-path}") |
| | | private String imgPath; |
| | | |
| | | @Value("${igds.weather-url}") |
| | | private String weatherUrl; |
| | | } |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | private GatewayConfService confService; |
| | | @Resource |
| | | private GatewayRemoteManager gatewayRemoteManager; |
| | | @Resource |
| | | private ConfigData configData; |
| | | |
| | | |
| | | /** |
| | |
| | | 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("当前外网获取气象信息失败……"); |
| | |
| | | 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; |
| | | |
| | |
| | | */ |
| | | @Slf4j |
| | | public class GatewayHttpUtil { |
| | | |
| | | private static final int TIMEOUT_IN_MILLIONS = 5000; |
| | | |
| | | /** |
| | | * 执行GET请求 |
| | |
| | | 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; |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | //粮情解析 |
| | | log.info("控制柜--->平台,推动的粮情信息--{}", response); |
| | | log.info("控制柜--->平台,控制柜返回粮情检测结果--{}", response); |
| | | |
| | | //粮情封装和处理 |
| | | if (StringUtils.isEmpty(response.getLayerPerCircle())) { |
| | |
| | | |
| | | //信息调整封装 |
| | | 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("--粮情封装解析,未获取到请求相关参数----"); |
| | |
| | | //根号 |
| | | 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++) { |
| | |
| | | } |
| | | |
| | | 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; |
| | |
| | | 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) { |
| | |
| | | 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; |
| | |
| | | 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} |