package com.fzzy.igds.dzhwk.v1.impl; import com.alibaba.fastjson.JSONObject; import com.fzzy.igds.dzhwk.domain.Gas; import com.fzzy.igds.dzhwk.service.repository.GasRepository; import com.fzzy.igds.dzhwk.v1.ApiV1Service; import com.fzzy.igds.dzhwk.v1.dto.ApiV1Data2002; import com.fzzy.igds.dzhwk.v1.dto.ApiV1ReqDto; import com.ruoyi.common.utils.StringUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.time.DateUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; /** * @Description 解析气体信息 * @Author CZT * @Date 2025/6/04 20:11 */ @Slf4j @Service public class ApiV1ServiceImpl2002 implements ApiV1Service { @Resource private GasRepository gasRepository; @Override public String getInterfaceId() { return "2002"; } @Override public void analysis(String dataStr, ApiV1ReqDto configData) { List list = JSONObject.parseArray(dataStr, ApiV1Data2002.class); if(null == list || list.isEmpty()){ log.error("-----未获取到气体检测信息,不解析---------"); return; } try { Gas gas; List co2List = new ArrayList<>(); List o2List = new ArrayList<>(); List ph3List = new ArrayList<>(); List n2List = new ArrayList<>(); Double max = 0.0; Double min = 0.0; Double sum = 0.0; Double temp = 0.0; for (ApiV1Data2002 apiData : list) { gas = new Gas(); gas.setBatchId(apiData.getQtndjcdh()); gas.setCompanyId(configData.getSign()); gas.setDepotId(apiData.getHwdm()); gas.setType(apiData.getZylx() + ""); //CO2 if(StringUtils.isNotEmpty(apiData.getEyhthlzjh())){ String[] split = apiData.getEyhthlzjh().split("\\|"); String points = split[0]; String[] values = points.split(","); for(int i = 0; i < values.length; i++){ temp = Double.valueOf(values[i]); if (i ==0) { sum = 0.0; max = temp; min = temp; } if(temp > max){ max = temp; } if(temp < min){ min = temp; } sum += temp; o2List.add(values[i]); } gas.setPerCo2(sum / values.length); gas.setPerCo2Max(max); gas.setPerCo2Min(min); } //O2 if(StringUtils.isNotEmpty(apiData.getYqhlzjh())){ String[] split = apiData.getYqhlzjh().split("\\|"); String points = split[0]; String[] values = points.split(","); for(int i = 0; i < values.length; i++){ temp = Double.valueOf(values[i]); if (i ==0) { sum = 0.0; max = temp; min = temp; } if(temp > max){ max = temp; } if(temp < min){ min = temp; } sum += temp; o2List.add(values[i]); } gas.setPerO2(sum / values.length); gas.setPerO2Max(max); gas.setPerO2Min(min); } //Ph3 if(StringUtils.isNotEmpty(apiData.getLhqndzjh())){ String[] split = apiData.getLhqndzjh().split("\\|"); String points = split[0]; String[] values = points.split(","); for(int i = 0; i < values.length; i++){ temp = Double.valueOf(values[i]); if (i ==0) { sum = 0.0; max = temp; min = temp; } if(temp > max){ max = temp; } if(temp < min){ min = temp; } sum += temp; o2List.add(values[i]); } gas.setPerPh3(sum / values.length); gas.setPerPh3Max(max); gas.setPerPh3Min(min); } //N2 if(StringUtils.isNotEmpty(apiData.getDqndzjh())){ String[] split = apiData.getDqndzjh().split("\\|"); String points = split[0]; String[] values = points.split(","); for(int i = 0; i < values.length; i++){ temp = Double.valueOf(values[i]); if (i ==0) { sum = 0.0; max = temp; min = temp; } if(temp > max){ max = temp; } if(temp < min){ min = temp; } sum += temp; o2List.add(values[i]); } gas.setPerN2(sum / values.length); gas.setPerN2Max(max); gas.setPerN2Min(min); } //点位各气体浓度 String pointStr = ""; for(int i = 0; i < o2List.size(); i++){ pointStr += i + "," + co2List.get(i) + "," + o2List.get(i) + "," + ph3List.get(i) + "," + n2List.get(i) + ";"; } gas.setPoints(pointStr); gas.setReceiveDate(DateUtils.parseDate(apiData.getJcsj(), "yyyy-MM-dd HH:mm:ss")); gas.setCheckUser(""); gas.setRemark(""); gasRepository.save(gas); } }catch (Exception e){ log.error("-----解析错误={}---------", e.toString()); } } }