CZT
2023-10-11 564295458c720206db9b5194b90481b711f4b010
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
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<RequestBody2303> 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<GasInfo> 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
    }
}