From ebaaa34038ebda73630c9ab82465c5f76692b5c2 Mon Sep 17 00:00:00 2001 From: jiazx0107@163.com <jiazx0107@163.com> Date: 星期二, 05 十二月 2023 00:01:48 +0800 Subject: [PATCH] 提交粮情协议2,完成 --- /dev/null | 37 --------- src/main/java/com/fzzy/protocol/fzzy/server/SessionListener.java | 4 src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisService.java | 2 src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java | 154 +++++++++++++++++++++++++++++++++++++- src/main/java/com/fzzy/protocol/fzzy/server/MsgConsumer.java | 14 +- src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisSystem.java | 2 6 files changed, 158 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncGrainImpl.java b/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncGrainImpl.java deleted file mode 100644 index 100dce2..0000000 --- a/src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncGrainImpl.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.fzzy.gateway.hx2023.service; - -import com.fzzy.api.data.GatewayDeviceProtocol; -import com.fzzy.gateway.api.GatewaySyncGranService; -import com.fzzy.gateway.data.BaseResp; -import com.fzzy.gateway.data.BaseReqData; -import com.fzzy.gateway.entity.GatewayDevice; -import com.fzzy.gateway.hx2023.data.*; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; -import org.springframework.stereotype.Service; - -/** - * 缃戝叧涓庣伯鎯呭垎鏈洪�氳鍜岃В鏋� - */ -@Slf4j -@Data -@Service -public class HxGatewaySyncGrainImpl implements GatewaySyncGranService { - - - @Override - public String getGrainProtocol() { - return GatewayDeviceProtocol.DEVICE_TEST.getCode(); - } - - - @Override - public BaseResp syncGrain(BaseReqData reqData) { - - return new BaseResp(); - } - - -} - diff --git a/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java index 6e02d70..017002e 100644 --- a/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java +++ b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisGrain.java @@ -2,7 +2,17 @@ import com.alibaba.fastjson.JSONObject; import com.fzzy.api.data.ApiCommonDevice; +import com.fzzy.api.data.GatewayDeviceType; +import com.fzzy.api.utils.NumberUtil; +import com.fzzy.gateway.GatewayUtils; +import com.fzzy.gateway.api.GatewayDeviceReportService; +import com.fzzy.gateway.api.GatewayRemoteManager; import com.fzzy.gateway.data.BaseReqData; +import com.fzzy.gateway.data.BaseResp; +import com.fzzy.gateway.data.WeatherWebDto; +import com.fzzy.gateway.entity.GatewayDevice; +import com.fzzy.gateway.hx2023.ScConstant; +import com.fzzy.gateway.hx2023.data.*; import com.fzzy.protocol.fzzy.builder.SimpleCommandBuilder; import com.fzzy.protocol.fzzy.cmd.BaseRemoteImpl; import com.fzzy.protocol.fzzy.data.ReMessage; @@ -10,7 +20,12 @@ import com.fzzy.protocol.fzzy.resp.Response2102; import com.fzzy.protocol.fzzy.server.ServerUtils; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; /** * 绮儏瑙f瀽 @@ -20,6 +35,9 @@ @Slf4j @Component(AnalysisGrain.BEAN_ID) public class AnalysisGrain extends BaseRemoteImpl { + + @Resource + private GatewayRemoteManager gatewayRemoteManager; public static final String BEAN_ID = "fzzy.analysisGrain"; @@ -48,14 +66,16 @@ Response2102 response = JSONObject.parseObject(reMessage.getContent(), Response2102.class); - String depotId = response.getHouseId(); - - //鑾峰彇璇锋眰淇℃伅 - BaseReqData reqData = ServerUtils.getSyncReq(depotId); - //绮儏瑙f瀽 - log.info("鎺у埗鏌�--->骞冲彴绮儏淇℃伅--{}", response); + log.info("鎺у埗鏌�--->骞冲彴锛屾帹鍔ㄧ殑绮儏淇℃伅--{}", response); + + //绮儏灏佽鍜屽鐞� + if (StringUtils.isEmpty(response.getLayerPerCircle())) { + buildBizInfo1(response); + } else { + buildBizInfo2(response); + } } catch (Exception e) { @@ -65,6 +85,128 @@ } } + private void buildBizInfo2(Response2102 response) { + //TODO 绛掍粨鐨勫皝瑁呰В鏋愬緟澶勭悊 + } + + //淇℃伅璋冩暣灏佽 + private void buildBizInfo1(Response2102 response) { + String depotId = response.getHouseId(); + + //鑾峰彇璇锋眰淇℃伅 + BaseReqData reqData = ServerUtils.getSyncReq(depotId); + + if (null == reqData) { + log.error("--绮儏灏佽瑙f瀽锛屾湭鑾峰彇鍒拌姹傜浉鍏冲弬鏁�----"); + return; + } + + + int cableZ = Integer.valueOf(response.getLay()); + int cableY = Integer.valueOf(response.getRow()); + int cableX = Integer.valueOf(response.getCol()); + + GatewayDevice device = reqData.getDevice(); + + //鏁版嵁灏佽 + GrainData grain = new GrainData(); + grain.setMessageId(ScConstant.getMessageId()); + grain.setDeviceId(device.getDeviceId()); + grain.setTimestamp(System.currentTimeMillis() + ""); + + ClientHeaders headers = new ClientHeaders(); + headers.setDeviceName(device.getDeviceName()); + headers.setProductId(device.getProductId()); + headers.setOrgId(device.getOrgId()); + headers.setMsgId(reqData.getMessageId()); + grain.setHeaders(headers); + + GrainOutPut outPut = new GrainOutPut(); + + outPut.setAvgTemperature(response.getTAvg() + ""); + outPut.setMinTemperature(response.getTMin() + ""); + outPut.setMaxTemperature(response.getTMax() + ""); + + + List<GrainTemp> temperature = new ArrayList<>(); + //鏍瑰彿 + int cableNum = 1, position = 0; + + double curTemp = response.getTMin(); + String[] attr = response.getPoints().split(","); + int x = 0, y = 0, z = 0; + for (int i = 0; i < attr.length; i++) { + curTemp = Double.valueOf(attr[i]); + + if (curTemp < -900) { + curTemp = ERROR_CHECK_TAG; + } + + //鏁版嵁浼樺寲 + if (curTemp > 35) { + curTemp = response.getTAvg(); + } + + position = i; + z = i % cableZ + 1; + x = i / (cableZ * cableY); + y = x * (cableZ * cableY); + y = (i - y) / cableZ; + //鏍瑰彿 + cableNum = (i / cableZ) + 1; + + temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + "")); + } + + outPut.setTemperature(temperature); + + grain.setOutput(com.alibaba.fastjson2.JSONObject.toJSONString(outPut)); + + + GatewayDevice gatewayDeviceWeather = GatewayUtils.getCacheByDeviceTypeOne(GatewayDeviceType.TYPE_09.getCode()); + + + //绯荤粺姘旇薄绔欎俊鎭� + WeatherWebDto weather = WeatherWebDto.contextMap.get("default"); + + //姘旇薄淇℃伅 + GrainWeather weatherStation = new GrainWeather(); + weatherStation.setMessageId(ScConstant.getMessageId()); + weatherStation.setMessgeId(weatherStation.getMessageId()); + + if (null != gatewayDeviceWeather) { + weatherStation.setId(gatewayDeviceWeather.getDeviceId()); + } else { + weatherStation.setId(device.getDeviceId()); + } + weatherStation.setAirPressure(weather.getPressure()); + weatherStation.setHumidity(weather.getHumidity()); + weatherStation.setPm(weather.getAir_pm25()); + weatherStation.setRadiation("0"); + weatherStation.setRainfallAmount(weather.getWea()); + weatherStation.setTemperature(weather.getTem()); + weatherStation.setWindDirection(weather.getWin()); + weatherStation.setWindPower(weather.getWin_meter()); + weatherStation.setWindSpeed(weather.getWin_speed()); + grain.setWeatherStation(JSONObject.toJSONString(weatherStation)); + + + //灏佽濂界殑鏁版嵁 + log.info("---绮儏鏈烘灏佽瀹屾垚----寮�濮嬫墽琛屾帹閫�"); + + reqData.setData(JSONObject.toJSONString(grain)); + doPushGrain(reqData); + } + + private void doPushGrain(BaseReqData reqData) { + + GatewayDeviceReportService reportService = gatewayRemoteManager.getDeviceReportService(reqData.getDevice().getPushProtocol()); + if (null == reportService) { + log.error("------------绮儏鎺ㄩ�佸け璐ワ紝绯荤粺涓嶅瓨鍦ㄥ綋鍓嶅崗璁墽琛岀被----{}", reqData.getDevice().getDeviceName()); + } + reportService.reportGrainData(reqData); + } + private void returnMsg(ApiCommonDevice ser) { //鍏堝洖澶嶆帶鍒舵煖 SimpleCommandBuilder commandBuilder = SimpleCommandBuilder.getInstance(); diff --git a/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisService.java index e270adf..30fe028 100644 --- a/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisService.java +++ b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisService.java @@ -46,14 +46,12 @@ return; } - //鎵ц鐨勫垎鏈轰俊鎭� ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getSn()); if (null == commonDevice) { log.warn("鎺у埗鏌�------>>>骞冲彴锛氬綋鍓嶇粍缁囩紪鐮�={}锛屽垎鏈篒D={}锛岀郴缁熸病鏈夎幏鍙栧埌鍒嗘満淇℃伅锛屾姤鏂囨棤娉曡繘琛岃В鏋�", message.getCompanyId(), message.getIedId()); return; } - //鏍规嵁鎺ュ彛缂栧彿杩涜瑙f瀽璺敱 switch (message.getFunctionId()) { diff --git a/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisSystem.java b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisSystem.java index 91db1bd..3a5a27f 100644 --- a/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisSystem.java +++ b/src/main/java/com/fzzy/protocol/fzzy/analysis/AnalysisSystem.java @@ -49,7 +49,7 @@ SendMessage message = commandBuilder.buildMessage(reMessage, ServerUtils.FUNCTION_1001, response); send(message); - log.info("鎺у埗鏌�----->>>骞冲彴锛氭帶鍒舵煖涓婄嚎鐧婚檰鎴愬姛-IP={},PORT={}", reMessage.getIp(), reMessage.getPort()); + log.info("鎺у埗鏌�----->>>骞冲彴锛屾帶鍒舵煖鐧婚檰瑙f瀽瀹屾垚-鎶ユ枃-{}", reMessage); } public void analysis1003(ReMessage reMessage, ApiCommonDevice ser) { diff --git a/src/main/java/com/fzzy/protocol/fzzy/server/MsgConsumer.java b/src/main/java/com/fzzy/protocol/fzzy/server/MsgConsumer.java index 7da3623..037dfee 100644 --- a/src/main/java/com/fzzy/protocol/fzzy/server/MsgConsumer.java +++ b/src/main/java/com/fzzy/protocol/fzzy/server/MsgConsumer.java @@ -43,19 +43,19 @@ reMessage.setStrMsg(message); session.setCompanyId("0000"); - log.info("鎺у埗鏌�------>>>>骞冲彴锛欼P={}锛孭ORT={}锛宮essage={}", reMessage.getIp(), reMessage.getPort(), message); + log.debug("鎺у埗鏌滃埌---->>>>骞冲彴锛屾湭瑙f瀽淇℃伅锛欼P={}锛孭ORT={}锛宮essage={}", reMessage.getIp(), reMessage.getPort(), message); + + //璋冪敤瑙f瀽鎺ュ彛寮�濮嬭В鏋� + if (null == analysisService) { + analysisService = (AnalysisService) SpringUtil.getBean(AnalysisService.BEAN_ID); + } + analysisService.analysis(reMessage); } catch (Exception e) { log.error("鎺у埗鏌�------>>>>骞冲彴锛氭敹鍒版姤鏂囪В鏋愬紓甯革細{}", e.getMessage()); e.printStackTrace(); } - //璋冪敤瑙f瀽鎺ュ彛寮�濮嬭В鏋� - if (null == analysisService) { - analysisService = (AnalysisService) SpringUtil.getBean(AnalysisService.BEAN_ID); - } - - analysisService.analysis(reMessage); } } diff --git a/src/main/java/com/fzzy/protocol/fzzy/server/SessionListener.java b/src/main/java/com/fzzy/protocol/fzzy/server/SessionListener.java index 7c30842..0c0f766 100644 --- a/src/main/java/com/fzzy/protocol/fzzy/server/SessionListener.java +++ b/src/main/java/com/fzzy/protocol/fzzy/server/SessionListener.java @@ -10,7 +10,7 @@ @Override public void onCreate(IoSession session) { - log.info("++++FZZY-鎺у埗鏌滀笂绾�++++-IP={}锛孭ORT={}", session.getAddress(), session.getPort()); + log.info("++++FZZY-鎺у埗涓崗璁湁鏂拌澶囪繛鎺�++++-IP={}锛孭ORT={}", session.getAddress(), session.getPort()); // 娣诲姞鑷畾涔変笟鍔D session.setBusinessKey(ServerUtils.getServerKey(session.getAddress(), session.getPort())); @@ -19,6 +19,6 @@ @Override public void onDestroy(IoSession session) { - log.info("----FZZY-鎺у埗鏌滅绾�-----IP={}锛孭ORT={}", session.getAddress(), session.getPort()); + log.info("----FZZY-鎺у埗涓崗璁湁璁惧绂荤嚎-----IP={}锛孭ORT={}", session.getAddress(), session.getPort()); } } -- Gitblit v1.9.3