| | |
| | | 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; |
| | |
| | | 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()); |
| | |
| | | String hexStr = CommandBuild.getMsgGrainReply(message.getAddr()); |
| | | log.info("平台--------->>>主机,返回粮情报文收到信息,报文={}", hexStr); |
| | | |
| | | BhznGrainV0ServerEngine.push(message.getIp(), message.getPort(), BytesUtil.hexStrToBytes(hexStr)); |
| | | BhznGrainV0ServerEngine.pushByMin(hexStr); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 筒仓解析,解析第二步,解析到坐标数据 |
| | | * 筒仓,解析第二步,解析到坐标数据 |
| | | * @param temps |
| | | * @param reqData |
| | | * @param thDto |
| | | * @param cableData |
| | | */ |
| | | private void analysisAndPush2(List<Double> temps, BaseReqData reqData, THDto thDto, GrainCableData cableData) { |
| | | //TODO |
| | | log.info("-------------------------暂未实现----------------"); |
| | | } |
| | | |
| | | /** |
| | | * 油罐仓,解析第二步,解析到坐标数据 |
| | | * |
| | | * @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(); |
| | | |
| | |
| | | int cableY = cableData.getCableY(); |
| | | int cableX = cableData.getCableX(); |
| | | |
| | | int sumNum = temps.size(); |
| | | int sumNum = 0; |
| | | |
| | | //数据封装 |
| | | GrainData grain = new GrainData(); |
| | |
| | | |
| | | double curTemp; |
| | | int x = 0, y = 0, z = 0; |
| | | for (int i = 0; i < sumNum; i++) { |
| | | for (int i = 0; i < temps.size(); i++) { |
| | | curTemp = temps.get(i); |
| | | position = i; |
| | | |
| | |
| | | temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + "")); |
| | | |
| | | //求最大最小值 |
| | | if (curTemp < -900) { |
| | | sumNum--; |
| | | } else { |
| | | // if (curTemp < -900) { |
| | | // sumNum--; |
| | | // } else { |
| | | // sumT += curTemp; |
| | | // if (curTemp > max) { |
| | | // max = curTemp; |
| | | // } |
| | | // if (curTemp < min) { |
| | | // min = curTemp; |
| | | // } |
| | | // } |
| | | if (curTemp > max && curTemp < 40) { |
| | | max = curTemp; |
| | | } |
| | | if (curTemp < min && curTemp > 3) { |
| | | min = curTemp; |
| | | } |
| | | if(curTemp > 3 && curTemp < 40){ |
| | | sumT += curTemp; |
| | | if (curTemp > max) { |
| | | max = curTemp; |
| | | } |
| | | if (curTemp < min) { |
| | | min = curTemp; |
| | | } |
| | | sumNum++; |
| | | } |
| | | } |
| | | |
| | |
| | | outPut.setTemperature(temperature); |
| | | outPut.setAvgTemperature(NumberUtil.keepPrecision((sumT / sumNum), 1) + ""); |
| | | outPut.setMinTemperature(min + ""); |
| | | outPut.setMaxTemperature(min + ""); |
| | | outPut.setMaxTemperature(max + ""); |
| | | |
| | | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | GrainOutPut outPut = new GrainOutPut(); |
| | | |
| | | |
| | | double max = ReMessageBuilder.MAX_TEMP, min = ReMessageBuilder.MIN_TEMP, sumT = 0.0, sumNum = cableData.getSumNum(); |
| | | double max = ReMessageBuilder.MAX_TEMP, min = ReMessageBuilder.MIN_TEMP, sumT = 0.0, sumNum =0; |
| | | |
| | | List<GrainTemp> temperature = new ArrayList<>(); |
| | | //根号 |
| | |
| | | temperature.add(new GrainTemp(cableNum + "", z + "", curTemp + "", position + "")); |
| | | |
| | | //求最大最小值 |
| | | if (curTemp < -900) { |
| | | sumNum--; |
| | | } else { |
| | | // if (curTemp < -900) { |
| | | // sumNum--; |
| | | // } else { |
| | | // sumT += curTemp; |
| | | // if (curTemp > max) { |
| | | // max = curTemp; |
| | | // } |
| | | // if (curTemp < min) { |
| | | // min = curTemp; |
| | | // } |
| | | // } |
| | | if (curTemp > max && curTemp < 40) { |
| | | max = curTemp; |
| | | } |
| | | if (curTemp < min && curTemp > 3) { |
| | | min = curTemp; |
| | | } |
| | | if(curTemp > 3 && curTemp < 40){ |
| | | sumT += curTemp; |
| | | if (curTemp > max) { |
| | | max = curTemp; |
| | | } |
| | | if (curTemp < min) { |
| | | min = curTemp; |
| | | } |
| | | sumNum++; |
| | | } |
| | | } |
| | | |
| | |
| | | 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")); |
| | |
| | | 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()); |
| | |
| | | |
| | | 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) { |
| | |
| | | return; |
| | | } |
| | | reportService.reportGrainData(reqData); |
| | | reqData.setData(reportService.grainData2GatewayApiInfoKafka(grainData,reqData.getDevice()).getData()); |
| | | reportService.reportGrainDataByKafka(reqData); |
| | | } |
| | | |
| | | |
| | |
| | | } finally { |
| | | String hexStr = CommandBuild.getMsgTHReply(message.getAddr()); |
| | | log.info("平台--------->>>主机,返回仓温仓湿收到信息,报文={}", hexStr); |
| | | BhznGrainV0ServerEngine.push(message.getIp(), message.getPort(), BytesUtil.hexStrToBytes(hexStr)); |
| | | BhznGrainV0ServerEngine.pushByMin(hexStr); |
| | | } |
| | | } |
| | | |