| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.commons.lang.time.DateFormatUtils; |
| | | import org.apache.commons.lang3.RandomUtils; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @Component |
| | |
| | | |
| | | @Resource |
| | | private Fzzy40CommonService fzzy40CommonService; |
| | | |
| | | @Resource |
| | | private DeviceReportServiceImpl deviceReportService; |
| | | |
| | | @Override |
| | | public String getProtocol() { |
| | |
| | | } |
| | | |
| | | private BaseResp pushByV40(BaseReqData reqData, Date start, Date end) { |
| | | |
| | | |
| | | GatewayDevice device = reqData.getDevice(); |
| | | String depotIdSys = device.getDepotIdSys(); |
| | | |
| | | if (StringUtils.isEmpty(depotIdSys)) { |
| | | log.error("--------设备--{}-未配置系统相关仓库编码,无法执行当前操作", device.getDeviceName()); |
| | | return new BaseResp(BaseResp.CODE_50, "未配置系统相关仓库编码,无法执行当前操作"); |
| | | return new BaseResp(BaseResp.CODE_500, "未配置系统相关仓库编码,无法执行当前操作"); |
| | | } |
| | | |
| | | List<Fz40Grain> listGrain = fzzy40CommonService.listGrain(depotIdSys, start, end); |
| | | if (null == listGrain || listGrain.isEmpty()) { |
| | | log.error("---------设备---{}--未同步到粮情信息,请确认当前条件下是否有数据", device.getDeviceName()); |
| | | return new BaseResp(BaseResp.CODE_50, "未同步到粮情信息,请确认当前条件下是否有数据"); |
| | | log.error("---------设备-{}-系统仓库编码-{}-未同步到粮情信息,请确认当前条件下是否有数据", device.getDeviceName(), device.getDepotIdSys()); |
| | | return new BaseResp(BaseResp.CODE_500, "未同步到粮情信息,请确认当前条件下是否有数据"); |
| | | } |
| | | |
| | | //获取最后一条粮情作为当前数据 |
| | | Fz40Grain lastData = listGrain.get(listGrain.size() - 1); |
| | | KafaGrainData pushData = this.lastData2PushData(lastData, device); |
| | | //获取第一条数据执行推送 |
| | | Fz40Grain lastData = listGrain.get(0); |
| | | |
| | | return new BaseResp(JSONObject.toJSONString(pushData)); |
| | | return deviceReportService.grainData2GatewayApiInfo(lastData,device); |
| | | } |
| | | |
| | | /** |
| | | * 将粮情数据转换为推送需要的数据格式 |
| | | * |
| | | * @param lastData |
| | | * @return |
| | | */ |
| | | private KafaGrainData lastData2PushData(Fz40Grain lastData, GatewayDevice device) { |
| | | KafaGrainData result = new KafaGrainData(); |
| | | // /** |
| | | // * 将粮情数据转换为推送需要的数据格式 |
| | | // * |
| | | // * @param grainData |
| | | // * @return |
| | | // */ |
| | | // private KafaGrainData lastData2PushData(Fz40Grain grainData, GatewayDevice device) { |
| | | // KafaGrainData result = new KafaGrainData(); |
| | | // |
| | | // result.setMessageId(ScConstant.getMessageId()); |
| | | // result.setMessgeId(result.getMessageId()); |
| | | // result.setDeviceID(device.getDeviceId()); |
| | | // result.setAvgTemperature(grainData.getTempAve() + ""); |
| | | // result.setMinTemperature(grainData.getTempMin() + ""); |
| | | // result.setMaxTemperature(grainData.getTempMax() + ""); |
| | | // result.setCollectTime(DateFormatUtils.format(grainData.getReceiveDate(), "yyyy-MM-dd HH:mm:ss")); |
| | | // |
| | | // //层-行-列 |
| | | // String[] attrCable = grainData.getCable().split("-"); |
| | | // if (StringUtils.isNotEmpty(grainData.getCableCir())) { |
| | | // return lastData2PushData2(grainData, device); |
| | | // } |
| | | // |
| | | // //层行列 |
| | | // int cableZ = Integer.valueOf(attrCable[0]); |
| | | // int cableY = Integer.valueOf(attrCable[1]); |
| | | // int cableX = Integer.valueOf(attrCable[2]); |
| | | // |
| | | // //温度集合 |
| | | // String[] attr = grainData.getPoints().split(","); |
| | | // |
| | | // //根号 |
| | | // int cableNum = 1, position = 0; |
| | | // String curTemp; |
| | | // List<KafkaGrainDataDetail1> temperature = new ArrayList<>(); |
| | | // |
| | | // int x = 0, y = 0, z = 0; |
| | | // for (int i = 0; i < attr.length; i++) { |
| | | // position = i; |
| | | // z = i % cableZ + 1; |
| | | // x = i / (cableZ * cableY); |
| | | // y = x * (cableZ * cableY); |
| | | // y = (i - y) / cableZ; |
| | | // // 倒转X轴 |
| | | // x = cableX - 1 - x; |
| | | // //根号 |
| | | // cableNum = (i / cableZ) + 1; |
| | | // curTemp = attr[i]; |
| | | // |
| | | // |
| | | // //如果是异常值,执行调整数据 TODO |
| | | // if (Double.valueOf(curTemp) < -99.9) { |
| | | // |
| | | // curTemp = grainData.getTempAve() + ""; |
| | | // |
| | | // } else { |
| | | // //判断最大 |
| | | // if (curTemp.equals(result.getMaxTemperature())) { |
| | | // result.setMaxX(x + ""); |
| | | // result.setMaxY(y + ""); |
| | | // result.setMaxZ(position + ""); |
| | | // } |
| | | // //判断最小 |
| | | // if (curTemp.equals(result.getMinTemperature())) { |
| | | // result.setMinX(x + ""); |
| | | // result.setMinY(y + ""); |
| | | // result.setMinZ(position + ""); |
| | | // } |
| | | // } |
| | | // |
| | | // temperature.add(new KafkaGrainDataDetail1(cableNum + "", z + "", curTemp, position + "", x + "", y + "")); |
| | | // } |
| | | // |
| | | // //粮温信息 |
| | | // JSONObject trhInfo = new JSONObject(); |
| | | // // TRHInfo trhInfo = new TRHInfo(); |
| | | // trhInfo.put("temperature", temperature); |
| | | // |
| | | // |
| | | // //仓温度信息 |
| | | // KafkaGrainTH grainTH = new KafkaGrainTH(); |
| | | // grainTH.setHumidity(grainData.getHumidityIn() + ""); |
| | | // grainTH.setTemperature(grainData.getTempIn() + ""); |
| | | // grainTH.setAirHumidity(grainData.getHumidityOut() + ""); |
| | | // grainTH.setAirTemperature(grainData.getTempOut() + ""); |
| | | // |
| | | // List<KafkaGrainTH> temperatureAndhumidity = new ArrayList<>(); |
| | | // temperatureAndhumidity.add(grainTH); |
| | | // |
| | | // trhInfo.put("temperatureAndhumidity", temperatureAndhumidity); |
| | | // //trhInfo.put("temperatureAndhumidity",grainTH); |
| | | // |
| | | // JSONObject params = new JSONObject(); |
| | | // params.put("TRHInfo", trhInfo); |
| | | // |
| | | // result.setParams(params); |
| | | // |
| | | // return result; |
| | | // } |
| | | |
| | | result.setMessageId(ScConstant.getMessageId()); |
| | | result.setMessgeId(result.getMessageId()); |
| | | result.setDeviceID(device.getDeviceId()); |
| | | result.setAvgTemperature(lastData.getTempAve() + ""); |
| | | result.setMinTemperature(lastData.getTempMin() + ""); |
| | | result.setMaxTemperature(lastData.getTempMax() + ""); |
| | | result.setCollectTime(DateFormatUtils.format(lastData.getReceiveDate(), "yyyy-MM-dd HH:mm:ss")); |
| | | |
| | | //层-行-列 |
| | | String[] attrCable = lastData.getCable().split("-"); |
| | | |
| | | |
| | | if (StringUtils.isNotEmpty(lastData.getCableCir())) { |
| | | return lastData2PushData2(lastData, device); |
| | | } |
| | | |
| | | //层行列 |
| | | int cableZ = Integer.valueOf(attrCable[0]); |
| | | int cableY = Integer.valueOf(attrCable[1]); |
| | | int cableX = Integer.valueOf(attrCable[2]); |
| | | |
| | | //温度集合 |
| | | String[] attr = lastData.getPoints().split(","); |
| | | |
| | | //根号 |
| | | int cableNum = 1, position = 0; |
| | | |
| | | String curTemp; |
| | | List<KafkaGrainDataDetail1> temperature = new ArrayList<>(); |
| | | |
| | | int x = 0, y = 0, z = 0; |
| | | for (int i = 0; i < attr.length; i++) { |
| | | |
| | | position = i; |
| | | |
| | | z = i % cableZ + 1; |
| | | x = i / (cableZ * cableY); |
| | | y = x * (cableZ * cableY); |
| | | y = (i - y) / cableZ; |
| | | |
| | | // 倒转X轴 |
| | | x = cableX - 1 - x; |
| | | |
| | | //根号 |
| | | cableNum = (i / cableZ) + 1; |
| | | |
| | | curTemp = attr[i]; |
| | | |
| | | |
| | | //判断最大 |
| | | if (curTemp.equals(result.getMaxTemperature())) { |
| | | result.setMaxX(x + ""); |
| | | result.setMaxY(y + ""); |
| | | result.setMaxZ(position + ""); |
| | | } |
| | | |
| | | |
| | | //判断最小 |
| | | if (curTemp.equals(result.getMinTemperature())) { |
| | | result.setMinX(x + ""); |
| | | result.setMinY(y + ""); |
| | | result.setMinZ(position + ""); |
| | | } |
| | | |
| | | temperature.add(new KafkaGrainDataDetail1(cableNum + "", z + "", curTemp, position + "", x + "", y + "")); |
| | | } |
| | | |
| | | //粮温信息 |
| | | |
| | | JSONObject trhInfo = new JSONObject(); |
| | | // TRHInfo trhInfo = new TRHInfo(); |
| | | trhInfo.put("temperature", temperature); |
| | | |
| | | |
| | | //仓温度信息 |
| | | KafkaGrainTH grainTH = new KafkaGrainTH(); |
| | | grainTH.setHumidity(lastData.getHumidityIn() + ""); |
| | | grainTH.setTemperature(lastData.getTempIn() + ""); |
| | | grainTH.setAirHumidity(lastData.getHumidityOut() + ""); |
| | | grainTH.setAirTemperature(lastData.getTempOut() + ""); |
| | | |
| | | List<KafkaGrainTH> temperatureAndhumidity = new ArrayList<>(); |
| | | temperatureAndhumidity.add(grainTH); |
| | | |
| | | trhInfo.put("temperatureAndhumidity", temperatureAndhumidity); |
| | | //trhInfo.put("temperatureAndhumidity",grainTH); |
| | | |
| | | JSONObject params = new JSONObject(); |
| | | params.put("TRHInfo", trhInfo); |
| | | |
| | | result.setParams(params); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 针对筒仓 TODO ----- |
| | | * |
| | | * @param lastData |
| | | * @param device |
| | | * @return |
| | | */ |
| | | private KafaGrainData lastData2PushData2(Fz40Grain lastData, GatewayDevice device) { |
| | | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | @Override |
| | |
| | | |
| | | |
| | | WeatherWebDto weather = WeatherWebDto.contextMap.get("default"); |
| | | double tMIn = 20, tMax = 25; |
| | | double tMIn = 10, tMax = 15; |
| | | if (null != weather) { |
| | | double tOut = Double.valueOf(weather.getTem()); |
| | | tMIn = tOut - 4; |
| | | if (tMIn < 4) tMIn = 5; |
| | | tMax = tOut + 0; |
| | | if (tMax < 15) tMax = 15; |
| | | tMIn = tOut - 5; |
| | | tMax = tOut; |
| | | } |
| | | |
| | | if (tMIn < 10) tMIn = 10; |
| | | if (tMIn > 20) tMIn = 20; |
| | | if (tMax < 15) tMax = 15; |
| | | if (tMax > 25) tMax = 25; |
| | | |
| | | //数据封装 |
| | | GrainData grain = new GrainData(); |
| | |
| | | double randomNumber = tMIn; |
| | | int x = 0, y = 0, z = 0; |
| | | for (int i = 0; i < sumNum; i++) { |
| | | if ((i) % Integer.valueOf(cableRule[0]) == 0) { |
| | | randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn; |
| | | |
| | | } else if ((i) % Integer.valueOf(cableRule[0]) == 1) { |
| | | randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn; |
| | | |
| | | } else if ((i) % Integer.valueOf(cableRule[0]) == 2) { |
| | | randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn; |
| | | |
| | | } else if ((i) % Integer.valueOf(cableRule[0]) == 3) { |
| | | randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn; |
| | | |
| | | } else if ((i) % Integer.valueOf(cableRule[0]) == 4) { |
| | | randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn; |
| | | |
| | | } else { |
| | | randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn; |
| | | |
| | | log.info("i=:" + i); |
| | | if (i % cableZ == 0) { |
| | | randomNumber = RandomUtils.nextDouble(tMIn, tMax + 1.5); |
| | | log.info("第1层温度:" + randomNumber); |
| | | } else if (i % cableZ == 1) { |
| | | randomNumber = RandomUtils.nextDouble(tMIn - 1, tMax - 0); |
| | | log.info("第2层温度:" + randomNumber); |
| | | } else if (i % cableZ == 2) { |
| | | randomNumber = RandomUtils.nextDouble(tMIn - 2, tMax - 1.5); |
| | | log.info("第3层温度:" + randomNumber); |
| | | } else if (i % cableZ == 3) { |
| | | randomNumber = RandomUtils.nextDouble(tMIn - 3, tMax - 3); |
| | | log.info("第4层温度:" + randomNumber); |
| | | } else if (i % cableZ == 4) { |
| | | randomNumber = RandomUtils.nextDouble(tMIn - 4, tMax - 4.5); |
| | | log.info("第5层温度:" + randomNumber); |
| | | } |
| | | // randomNumber = Math.random() * (tMax - tMIn + 1) + tMIn; |
| | | curTemp = NumberUtil.keepPrecision(randomNumber, 1); |
| | |
| | | } |
| | | |
| | | outPut.setTemperature(temperature); |
| | | List<GrainTH> ths = new ArrayList<>(); |
| | | |
| | | ths.add(new GrainTH(weather.getTem() != null ? weather.getTem() + "" : "", weather.getHumidity() != null ? weather.getHumidity() + "" : "", "1")); |
| | | outPut.setTemperatureAndhumidity(ths); |
| | | |
| | | grain.setOutput(JSONObject.toJSONString(outPut)); |
| | | |