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 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;
|
|
/**
|
* 气体解析
|
*/
|
@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);
|
|
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<GasInfo> items = new ArrayList<>();
|
GasInfo info;
|
Integer[] n2ValArray = res209.getN2ValArray();
|
Integer[] pH3ValArray = res209.getPH3ValArray();
|
Integer[] cO2ValArray = res209.getCO2ValArray();
|
for (int i=0;i<res209.getCO2ValArray().length;i++){
|
info = new GasInfo();
|
info.setId(ContextUtil.buildInfoId(gas.getCompanyId(), gas.getDepotId(), gas.getBatchId()));
|
info.setPassCode(i+1);
|
info.setPerCo2(cO2ValArray[i].doubleValue());
|
info.setPerO2(99 - (n2ValArray[i].doubleValue() /10 ));
|
info.setPerPh3(pH3ValArray[i].doubleValue());
|
info.setPerN2(n2ValArray[i].doubleValue() / 10);
|
items.add(info);
|
if(i == 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());
|
}
|
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());
|
gasService.saveInfoGas(items);
|
|
gasService.saveOrUpdateData(gas);
|
|
// 调用通知前端
|
notifyInvoker.notifyWeb(gas.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.GAS, depotConf.getDepotName() + " 气体检测:结果返回成功.");
|
|
log.info("控制柜----->>>平台:气体解析完成-仓库={}", depotConf.getDepotName());
|
|
}
|
|
}
|