czt
2025-06-11 283da741b2429cf5a53786e5ee1b5528b757fdf6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package com.fzzy.igds.dzhwk.v1.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.fzzy.igds.dzhwk.domain.Gas;
import com.fzzy.igds.gas.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<ApiV1Data2002> list = JSONObject.parseArray(dataStr, ApiV1Data2002.class);
        if(null == list || list.isEmpty()){
            log.error("-----未获取到气体检测信息,不解析---------");
            return;
        }
        try {
            Gas gas;
            List<String> co2List = new ArrayList<>();
            List<String> o2List = new ArrayList<>();
            List<String> ph3List = new ArrayList<>();
            List<String> 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());
        }
 
    }
}