vince
2023-07-01 7d84b6cbf8268a6993f661e22a842ffa12c13732
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
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());
 
    }
 
}