package com.ld.igds.protocol.bhzn.verb.analysis; import com.alibaba.fastjson.JSONObject; import com.ld.igds.common.CoreCommonService; import com.ld.igds.common.CoreDeviceService; import com.ld.igds.constant.BizType; import com.ld.igds.constant.DeviceStatus; import com.ld.igds.gas.CoreGasService; import com.ld.igds.io.constant.OrderRespEnum; import com.ld.igds.io.notify.NotifyWebInvoker; import com.ld.igds.io.request.ExeDevice; import com.ld.igds.models.*; import com.ld.igds.protocol.bhzn.verb.command.BaseRemoteImpl; import com.ld.igds.protocol.bhzn.verb.dto.IoMessage; import com.ld.igds.protocol.bhzn.verb.dto.Res209; import com.ld.igds.protocol.bhzn.verb.dto.Res247; import com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerUtils; import com.ld.igds.temp.dto.TempParam; import com.ld.igds.util.BytesUtil; import com.ld.igds.util.ContextUtil; import com.ld.igds.util.NumberUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * 气体解析 */ @Slf4j @Component(AnalysisGas.BEAN_ID) public class AnalysisGas extends BaseRemoteImpl { public static final String BEAN_ID = "bhzn.analysisGas"; @Autowired private CoreDeviceService deviceService; @Autowired private NotifyWebInvoker notifyInvoker; @Autowired private CoreGasService gasService; @Autowired private CoreCommonService commonService; /** * 设备状态 * * @param reMessage * @param ser */ public void analysis(IoMessage reMessage, DeviceSer ser) { log.info("气体检测开始解析"); Res209 res209 = JSONObject.parseObject(reMessage.getContentStr(),Res209.class); if(2==res209.getState()){ }else{ log.info("气体没有采集完成,取消解析!"); return; } DepotConf depotConf = commonService.getCacheDepotConfBySerId(ser.getCompanyId(),ser.getId() ); //主体信息 Gas gas = new Gas(); gas.setBatchId(ContextUtil.getDefaultBatchId()); gas.setCheckNum(res209.getCO2ValArray().length); gas.setCompanyId(ser.getCompanyId()); gas.setDepotId(depotConf.getDepotId()); gas.setGasEnd(depotConf.getPestEnd()); gas.setGasStart(depotConf.getPestStart()); gas.setReceiveDate(new Date()); StringBuffer sb = new StringBuffer(); List items = new ArrayList<>(); GasInfo info; Integer[] n2ValArray = res209.getN2ValArray(); Integer[] pH3ValArray = res209.getPH3ValArray(); Integer[] cO2ValArray = res209.getCO2ValArray(); double sumO2 = 0.0, sumCo2 = 0.0, sumPh3 = 0.0, sumN2 = 0.0; for (int i=0;i gas.getPerCo2Max()) { gas.setPerCo2Max(info.getPerCo2()); } if (info.getPerCo2() < gas.getPerCo2Min()) { gas.setPerCo2Min(info.getPerCo2()); } if (info.getPerO2() > gas.getPerO2Max()) { gas.setPerO2Max(info.getPerO2()); } if (info.getPerO2() < gas.getPerO2Min()) { gas.setPerO2Min(info.getPerO2()); } if (info.getPerPh3() > gas.getPerPh3Max()) { gas.setPerPh3Max(info.getPerPh3()); } if (info.getPerPh3() < gas.getPerPh3Min()) { gas.setPerPh3Min(info.getPerPh3()); } if (info.getPerN2() > gas.getPerN2Max()) { gas.setPerN2Max(info.getPerN2()); } if (info.getPerN2() < gas.getPerN2Min()) { gas.setPerN2Min(info.getPerN2()); } sumO2 += info.getPerO2(); sumCo2 += info.getPerCo2(); sumPh3 += info.getPerPh3(); sumN2 += info.getPerN2(); //固定为:passCode,co2,o2,ph3,n2;passCode,co2,o2,ph3,n2;" sb.append(info.getPassCode()); sb.append(","); sb.append(info.getPerCo2()); sb.append(","); sb.append(info.getPerO2()); sb.append(","); sb.append(info.getPerPh3()); sb.append(","); sb.append(info.getPerN2()); sb.append(";"); } if(res209.getCO2ValArray().length>1){ gas.setPerCo2(NumberUtil.keepPrecision(sumCo2/res209.getCO2ValArray().length, 2)); gas.setPerO2(NumberUtil.keepPrecision(sumO2/res209.getCO2ValArray().length, 2)); gas.setPerN2(NumberUtil.keepPrecision(sumN2/res209.getCO2ValArray().length, 2)); gas.setPerPh3(NumberUtil.keepPrecision(sumPh3/res209.getCO2ValArray().length, 2)); } gas.setPoints(sb.toString()); gasService.saveInfoGas(items); gasService.saveOrUpdateData(gas); // 调用通知前端 notifyInvoker.notifyWeb(gas.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.GAS, depotConf.getDepotName() + " 气体检测:结果返回成功."); log.info("控制柜----->>>平台:气体解析完成-仓库={}", depotConf.getDepotName()); } }