From 69e8acc5dd1f760eb60e914472c151bfa8126a52 Mon Sep 17 00:00:00 2001 From: vince <757871790@qq.com> Date: 星期三, 03 七月 2024 17:08:20 +0800 Subject: [PATCH] 修改测温 --- src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java | 99 +++++++++++++++++++++---------------------------- 1 files changed, 42 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java b/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java index 6caca77..5be2c2d 100644 --- a/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java +++ b/src/main/java/com/fzzy/protocol/bhzn/v0/analysis/AnalysisService.java @@ -3,12 +3,12 @@ import com.alibaba.fastjson.JSONObject; import com.fzzy.api.Constant; import com.fzzy.api.data.ApiCommonDevice; +import com.fzzy.api.data.DepotType; import com.fzzy.api.data.GatewayDeviceType; import com.fzzy.api.utils.BytesUtil; import com.fzzy.api.utils.NumberUtil; import com.fzzy.api.utils.RedisConst; import com.fzzy.api.utils.RedisUtil; -import com.fzzy.async.fzzy40.entity.Fz40Grain; import com.fzzy.data.ConfigData; import com.fzzy.gateway.GatewayUtils; import com.fzzy.gateway.api.GatewayDeviceReportService; @@ -24,9 +24,8 @@ import com.fzzy.protocol.bhzn.v0.data.IoMessage; import com.fzzy.protocol.bhzn.v0.server.BhznGrainV0ServerEngine; import com.fzzy.protocol.bhzn.v0.server.BhznGrainV0ServerUtils; -import com.fzzy.protocol.data.GrainCableData; +import com.fzzy.gateway.data.GrainCableData; import com.fzzy.protocol.data.THDto; -import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; @@ -109,19 +108,19 @@ private void analysisGrain(IoMessage message) { try { //鏍规嵁鍒嗘満SN鑾峰彇璁惧閰嶇疆淇℃伅 - GatewayDevice gatewayDevice = GatewayUtils.getCacheByDeviceSn(message.getAddr()); + GatewayDevice gatewayDevice = BhznGrainV0ServerUtils.contextOrder; if (null == gatewayDevice) { replayGrain(message); log.error("涓绘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺璁惧閰嶇疆淇℃伅锛�" + message.getAddr()); return; } //鏍规嵁鍒嗘満鍦板潃鑾峰彇鍒嗘満淇℃伅 - ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getIp()); - if (commonDevice == null) { - replayGrain(message); - log.error("涓绘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺绮儏涓绘満閰嶇疆锛�" + message.getAddr()); - return; - } +// ApiCommonDevice commonDevice = Constant.getCommonDeviceCache(message.getIp()); +// if (commonDevice == null) { +// replayGrain(message); +// log.error("涓绘満-------->>骞冲彴锛岃В鏋愮伯鎯呭け璐ワ紝鏈幏鍙栧埌绯荤粺绮儏涓绘満閰嶇疆锛�" + message.getAddr()); +// return; +// } //鑾峰彇璇锋眰淇℃伅 BaseReqData reqData = ProtocolUtils.getSyncReq(gatewayDevice.getDepotIdSys()); @@ -132,7 +131,7 @@ } // 鍒ゆ柇鏁版嵁鏈夋病鏈夋敹鍙栧畬鏁� - GrainCableData cableData = this.getCableData(gatewayDevice); + GrainCableData cableData = GatewayUtils.getCableData(gatewayDevice); //鑾峰彇褰撳墠绮儏娓╁害鎶ユ枃 String grainHex = message.getContent().substring(16); @@ -179,39 +178,6 @@ } } - private GrainCableData getCableData(GatewayDevice gatewayDevice) { - String cableRule = gatewayDevice.getCableRule(); - String cableCir = gatewayDevice.getCableCir(); - - GrainCableData result = new GrainCableData(); - - int cableY, cableX; - String[] attCable = cableRule.split("-"); - int cableZ = Integer.valueOf(attCable[0]); - if (StringUtils.isEmpty(cableCir)) { - cableY = Integer.valueOf(attCable[1]); - cableX = Integer.valueOf(attCable[2]); - } else { - String[] attCir = cableCir.split("-"); - cableZ = Integer.valueOf(attCir[0]); - cableY = 1; - cableX = 0; - //閽堝澶氬湀璁$畻 - for (int i = 0; i < cableCir.length(); i++) { - cableX += Integer.valueOf(attCir[i]); - } - - result.setCir(true); - } - - result.setCableY(cableY); - result.setCableZ(cableZ); - result.setCableX(cableX); - result.setSumNum(cableZ * cableY * cableX); - - return result; - } - /** * 杩斿洖绮儏鏀跺埌鎶ユ枃淇℃伅锛岄渶瑕佹敞鎰忥細濡傛灉瀛樺湪鍒嗗寘鎯呭喌涓嬶紝闇�瑕佺瓑鎵�鏈夊寘鏀跺埌鍚庤繑鍥� * @@ -222,7 +188,7 @@ String hexStr = CommandBuild.getMsgGrainReply(message.getAddr()); log.info("骞冲彴--------->>>涓绘満锛岃繑鍥炵伯鎯呮姤鏂囨敹鍒颁俊鎭紝鎶ユ枃={}", hexStr); - BhznGrainV0ServerEngine.push(message.getIp(), message.getPort(), BytesUtil.hexStrToBytes(hexStr)); + BhznGrainV0ServerEngine.pushByMin(hexStr); } /** @@ -274,22 +240,39 @@ contextMapGrain.put(key, null); - if (cableData.isCir()) { + + if(DepotType.TYPE_03.getCode().equals(device.getDepotType())){ //绛掍粨 + analysisAndPush3(temps, reqData, thDto, cableData); + }else if(DepotType.TYPE_02.getCode().equals(device.getDepotType())){ analysisAndPush2(temps, reqData, thDto, cableData); - } else { + }else if(DepotType.TYPE_04.getCode().equals(device.getDepotType())){ + analysisAndPush2(temps, reqData, thDto, cableData); + }else { //骞虫埧浠� analysisAndPush1(temps, reqData, thDto, cableData); } } /** - * 绛掍粨瑙f瀽锛岃В鏋愮浜屾锛岃В鏋愬埌鍧愭爣鏁版嵁 + * 绛掍粨锛岃В鏋愮浜屾锛岃В鏋愬埌鍧愭爣鏁版嵁 + * @param temps + * @param reqData + * @param thDto + * @param cableData + */ + private void analysisAndPush2(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) { + //TODO + log.info("-------------------------鏆傛湭瀹炵幇----------------"); + } + + /** + * 娌圭綈浠擄紝瑙f瀽绗簩姝ワ紝瑙f瀽鍒板潗鏍囨暟鎹� * * @param temps * @throws Exception */ - private void analysisAndPush2(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) { + private void analysisAndPush3(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) { GatewayDevice device = reqData.getDevice(); @@ -370,21 +353,21 @@ JSONObject properties = new JSONObject(); - properties.put("data", JSONObject.toJSONString(outPut)); + properties.put("data", outPut); properties.put("timestamp", grain.getTimestamp()); String height = this.getCacheHeight(device); if (StringUtils.isEmpty(height)) height = "0.0"; properties.put("liquidHeight", height); - grain.setProperties(properties.toJSONString()); + grain.setProperties(properties); //灏佽濂界殑鏁版嵁 log.info("---娴呭渾浠撳皝瑁呭畬鎴�----寮�濮嬫墽琛屾帹閫�"); reqData.setData(JSONObject.toJSONString(grain)); - doPushGrain(reqData); + doPushGrain(reqData,grain); } /** @@ -482,7 +465,7 @@ outPut.setTemperature(temperature); outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + ""); outPut.setMinTemperature(min + ""); - outPut.setMaxTemperature(min + ""); + outPut.setMaxTemperature(max + ""); List<GrainTH> ths = new ArrayList<>(); ths.add(new GrainTH(thDto.getTempIn() != null ? thDto.getTempIn() + "" : "", thDto.getHumidityIn() != null ? thDto.getHumidityIn() + "" : "", "1")); @@ -505,7 +488,7 @@ weatherStation.setId(device.getDeviceId()); } weatherStation.setAirPressure(weather.getPressure()); - weatherStation.setHumidity(weather.getHumidity()); + weatherStation.setHumidity(weather.getHumidity().replaceAll("%","")); weatherStation.setPm(weather.getAir_pm25()); weatherStation.setRadiation("0"); weatherStation.setRainfallAmount(weather.getWea()); @@ -521,10 +504,10 @@ reqData.setData(JSONObject.toJSONString(grain)); - doPushGrain(reqData); + doPushGrain(reqData,grain); } - private void doPushGrain(BaseReqData reqData) { + private void doPushGrain(BaseReqData reqData,GrainData grainData) { GatewayDeviceReportService reportService = gatewayRemoteManager.getDeviceReportService(reqData.getDevice().getPushProtocol()); if (null == reportService) { @@ -532,6 +515,8 @@ return; } reportService.reportGrainData(reqData); + reqData.setData(reportService.grainData2GatewayApiInfoKafka(grainData,reqData.getDevice()).getData()); + reportService.reportGrainDataByKafka(reqData); } @@ -579,7 +564,7 @@ } finally { String hexStr = CommandBuild.getMsgTHReply(message.getAddr()); log.info("骞冲彴--------->>>涓绘満锛岃繑鍥炰粨娓╀粨婀挎敹鍒颁俊鎭紝鎶ユ枃={}", hexStr); - BhznGrainV0ServerEngine.push(message.getIp(), message.getPort(), BytesUtil.hexStrToBytes(hexStr)); + BhznGrainV0ServerEngine.pushByMin(hexStr); } } -- Gitblit v1.9.3