package com.ld.igds.protocol.fzzy.analysis; import com.alibaba.fastjson.JSONObject; import com.ld.igds.common.CoreCommonService; import com.ld.igds.constant.BizType; import com.ld.igds.constant.Constant; import com.ld.igds.gas.CoreGasService; import com.ld.igds.gas.dto.GasProgressData; import com.ld.igds.io.notify.NotifyWebInvoker; import com.ld.igds.io.constant.OrderRespEnum; import com.ld.igds.models.DepotConf; import com.ld.igds.models.DeviceSer; import com.ld.igds.models.Gas; import com.ld.igds.models.GasInfo; import com.ld.igds.order.ExeOrderService; import com.ld.igds.protocol.fzzy.ServerUtils; import com.ld.igds.protocol.fzzy.command.BaseRemoteImpl; import com.ld.igds.protocol.fzzy.dto.ReMessage; import com.ld.igds.protocol.fzzy.dto.SendMessage; import com.ld.igds.protocol.fzzy.req.Request2302; import com.ld.igds.protocol.fzzy.req.Request2303; import com.ld.igds.protocol.fzzy.req.RequestBody2303; import com.ld.igds.protocol.fzzy.builder.SimpleCommandBuilder; 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.util.ArrayList; import java.util.Date; import java.util.List; /** * 气体解析 * * @author vince */ @Slf4j @Component(AnalysisGas.BEAN_ID) public class AnalysisGas extends BaseRemoteImpl { public static final String BEAN_ID = "fzzy.analysisGas"; @Autowired private CoreGasService gasService; @Autowired private CoreCommonService commonService; @Autowired private NotifyWebInvoker notifyInvoker; public static Double ERROR_TAG = -1000.0; public static Double ERROR_TAG2 = -2000.0; public void analysis2301(ReMessage message, DeviceSer ser) { //DO NOTHING } public void analysis2302(ReMessage reMessage, DeviceSer ser) { //平台不反馈 //终端请求-返回的进度信息 Request2302 request = JSONObject.parseObject(reMessage.getContent(), Request2302.class); GasProgressData gasProgress = new GasProgressData(); gasProgress.setCompanyId(ser.getCompanyId()); gasProgress.setCheckPoint(request.getPoint()); gasProgress.setSerId(ser.getId()); gasProgress.setDepotId(request.getHouseId()); gasProgress.setSumCheckNum(0); DepotConf depotConf = commonService.getCacheDepotConf( ser.getCompanyId(), request.getHouseId()); gasProgress.setMsg("气体检测进度:仓库:" + depotConf.getDepotName() + " 当前:" + gasProgress.getCheckPoint()); notifyInvoker.notifyGasProgress(gasProgress); } public void analysis2303(ReMessage reMessage, DeviceSer ser) { //平台反馈 SimpleCommandBuilder commandBuilder = SimpleCommandBuilder.getInstance(); SendMessage message = commandBuilder.buildMessage(ser, ServerUtils.FUNCTION_2303); send(message); //解析结果 Request2303 request2303 = JSONObject.parseObject(reMessage.getContent(), Request2303.class); List points = request2303.getPoints(); DepotConf depotConf = commonService.getCacheDepotConf(ser.getCompanyId(), request2303.getHouseId()); //主体信息 Gas gas = new Gas(); gas.setBatchId(request2303.getTime().substring(0, 12)); gas.setCheckNum(points.size()); gas.setCompanyId(ser.getCompanyId()); gas.setDepotId(request2303.getHouseId()); gas.setGasEnd(depotConf.getPestEnd()); gas.setGasStart(depotConf.getPestStart()); gas.setReceiveDate(new Date()); List items = new ArrayList<>(); GasInfo info; StringBuffer sb = new StringBuffer(); double sumO2 = 0.0, sumCo2 = 0.0, sumPh3 = 0.0, sumN2 = 0.0; int index = 0; for (RequestBody2303 point : points) { info = new GasInfo(); info.setId(ContextUtil.buildInfoId(gas.getCompanyId(), gas.getDepotId(), gas.getBatchId())); //调整错误码 if (point.getCo2() == ERROR_TAG || point.getCo2() == ERROR_TAG2) { point.setCo2(Constant.ERROR_TEMP); } if (point.getO2() == ERROR_TAG || point.getO2() == ERROR_TAG2) { point.setO2(Constant.ERROR_TEMP); } if (point.getPh3() == ERROR_TAG || point.getPh3() == ERROR_TAG2) { point.setPh3(Constant.ERROR_TEMP); } if (point.getN2() == ERROR_TAG || point.getN2() == ERROR_TAG2) { point.setN2(Constant.ERROR_TEMP); } info.setPassCode(point.getPoint()); info.setPerCo2(point.getCo2()); info.setPerO2(point.getO2()); info.setPerPh3(point.getPh3()); info.setPerN2(point.getN2()); items.add(info); if(index == 0){ //添加最大值和最小值 gas.setPerCo2Max(info.getPerCo2()); gas.setPerCo2Min(info.getPerCo2()); gas.setPerO2Max(info.getPerO2()); gas.setPerO2Min(info.getPerO2()); gas.setPerPh3Max(info.getPerPh3()); gas.setPerPh3Min(info.getPerPh3()); gas.setPerN2Max(info.getPerN2()); gas.setPerN2Min(info.getPerN2()); } sumO2 += info.getPerO2(); sumCo2 += info.getPerCo2(); sumPh3 += info.getPerPh3(); sumN2 += info.getPerN2(); index ++; if (info.getPerCo2() > 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()); } //固定为: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(";"); } gas.setPoints(sb.toString()); //计算平均值 if(index > 0){ gas.setPerCo2(NumberUtil.keepPrecision(sumCo2/index, 2)); gas.setPerO2(NumberUtil.keepPrecision(sumO2/index, 2)); gas.setPerN2(NumberUtil.keepPrecision(sumN2/index, 2)); gas.setPerPh3(NumberUtil.keepPrecision(sumPh3/index, 2)); } gasService.saveInfoGas(items); gasService.saveOrUpdateData(gas); // 调用通知前端 notifyInvoker.notifyWeb(gas.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.GAS, depotConf.getDepotName() + " 气体检测:结果返回成功."); log.info("控制柜----->>>平台:气体解析完成-仓库={}", depotConf.getDepotName()); } public void analysis2304(ReMessage message, DeviceSer ser) { //DO NOTHING } }