| | |
| | | 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; |
| | |
| | | |
| | | |
| | | //获取请求信息 |
| | | BaseReqData reqData = ProtocolUtils.getSyncReq(gatewayDevice.getDepotIdSys()); |
| | | BaseReqData reqData = ProtocolUtils.getSyncReq(gatewayDevice.getDeviceSn()); |
| | | if (null == reqData) { |
| | | replayGrain(message); |
| | | log.error("主机-------->>平台,解析粮情失败,未获取到粮情请求信息:" + message.getAddr()); |
| | |
| | | private void analysisGrain2(IoMessage message, BaseReqData reqData, String grainStr, GrainCableData cableData) { |
| | | GatewayDevice device = reqData.getDevice(); |
| | | // 获取完整的粮情包信息 |
| | | int cableZ = cableData.getCableZ(); |
| | | int cableY = cableData.getCableY(); |
| | | int cableX = cableData.getCableX(); |
| | | int sumNum = cableData.getSumNum(); |
| | | |
| | | // 根据层行列获取指定长度 |
| | | int start = 0; |
| | | int start = (Integer.valueOf(device.getCableStart()) - 1) * cableData.getCableZ() * 4; |
| | | int len = 4 * sumNum; |
| | | |
| | | log.info("分机------>>>平台:返回粮情完整信息,分机={}", device.getDeviceName()); |
| | | |
| | | String strPoints = grainStr.substring(start, start + len); |
| | | |
| | | log.info("strPoints = "+ strPoints); |
| | | // 将粮情解析成数组 |
| | | List<Double> temps = new ArrayList<>(); |
| | | double tempValue; |
| | |
| | | String key = "GRAIN_" + message.getAddr(); |
| | | contextMapGrain.put(key, null); |
| | | |
| | | if (cableData.isCir()) { |
| | | |
| | | if (DepotType.TYPE_02.getCode().equals(device.getDepotType()) || DepotType.TYPE_04.getCode().equals(device.getDepotType())) { |
| | | //筒仓 |
| | | analysisAndPush2(temps, reqData, thDto, cableData); |
| | | } else if (DepotType.TYPE_03.getCode().equals(device.getDepotType())) { |
| | | //储油罐 |
| | | analysisAndPush3(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 cableZ = cableData.getCableZ(); |
| | | int cableY = cableData.getCableY(); |
| | | int cableX = cableData.getCableX(); |
| | | |
| | | int sumNum = temps.size(); |
| | | |
| | | log.info("temps:" + temps.toString()); |
| | | //数据封装 |
| | | GrainData grain = new GrainData(); |
| | | grain.setMessageId(ScConstant.getMessageId()); |
| | |
| | | |
| | | |
| | | JSONObject properties = new JSONObject(); |
| | | properties.put("data", JSONObject.toJSONString(outPut)); |
| | | properties.put("timestamp", grain.getTimestamp()); |
| | | |
| | | properties.put("timestamp", grain.getTimestamp()); |
| | | outPut.setDetectTime( grain.getTimestamp()); |
| | | String height = this.getCacheHeight(device); |
| | | if (StringUtils.isEmpty(height)) height = "0.0"; |
| | | properties.put("liquidHeight", height); |
| | | |
| | | grain.setProperties(properties.toJSONString()); |
| | | outPut.setLiquidHeight(height); |
| | | grain.setOutput(JSONObject.toJSONString(outPut)); |
| | | properties.put("output", 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("---浅圆仓封装完成----开始执行推送"); |
| | | |
| | | log.info("---油罐仓信息封装完成----开始执行推送"); |
| | | grain.setProperties(properties); |
| | | reqData.setData(JSONObject.toJSONString(grain)); |
| | | |
| | | doPushGrain(reqData); |
| | | doPushGrain(reqData,grain); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | private String getCacheHeight(GatewayDevice device) { |
| | | //给其他软使用 |
| | | String key = RedisConst.KEY_DEPOT_HEIGHT + ":" + configData.getCompanyId() + "_" + device.getDepotIdSys(); |
| | | return (String) redisUtil.get(key); |
| | | //igds:5012:DEPOT_HEIGHT:0134 |
| | | String key = "igds:"+ device.getOrgId() + ":" + RedisConst.KEY_DEPOT_HEIGHT+ ":" + device.getDepotIdSys(); |
| | | com.ld.igds.grain.dto.GrainData ht = (com.ld.igds.grain.dto.GrainData) redisUtil.get(key); |
| | | log.info("KEY="+key); |
| | | if(ht!=null){ |
| | | log.info("VALUE="+ht.getOilHeight()); |
| | | return ht.getOilHeight() ; |
| | | }else { |
| | | return "0.0"; |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | 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); |
| | | } |
| | | |
| | | |