| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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()); |
| | |
| | | } |
| | | |
| | | // 判断数据有没有收取完整 |
| | | GrainCableData cableData = this.getCableData(gatewayDevice); |
| | | GrainCableData cableData = GatewayUtils.getCableData(gatewayDevice); |
| | | |
| | | //获取当前粮情温度报文 |
| | | String grainHex = message.getContent().substring(16); |
| | |
| | | } |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 返回粮情收到报文信息,需要注意:如果存在分包情况下,需要等所有包收到后返回 |
| | | * |
| | |
| | | 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(); |
| | | |
| | |
| | | |
| | | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |