YYC
2023-09-07 7243e0b4bd9a267a633d2e481e17646509b6868d
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
package com.ld.igds.protocol.zldz.analysis;
 
import com.ld.igds.common.dto.THDto;
import com.ld.igds.constant.BizType;
import com.ld.igds.constant.Constant;
import com.ld.igds.io.notify.NotifyWebInvoker;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.models.DeviceSer;
import com.ld.igds.order.ExeOrderService;
import com.ld.igds.order.data.ExeRequest;
import com.ld.igds.protocol.zldz.analysis.message.ReMessage;
import com.ld.igds.th.CoreThService;
import com.ld.igds.util.BytesUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.List;
 
/**
 * 解析温湿度信息
 *
 * @author Andy
 */
@Slf4j
@Component(AnalysisTH.BEAN_ID)
public class AnalysisTH {
 
    public static final String BEAN_ID = "zldz.analysisTH";
 
    @Autowired
    private CoreThService thService;
 
    @Autowired
    private NotifyWebInvoker notifyWebInvoker;
 
    @Autowired
    private ExeOrderService exeOrderService;
 
    public static int ERROR_TH_TAG = -50;
 
    /**
     * 解析仓库温湿度信息,将信息放在缓存中,以便粮情使用
     *
     * @param msg
     * @param ser
     */
    public void analysis8828(ReMessage msg, DeviceSer ser) {
 
        log.debug("-----------analysis8828------------{}-{}.{}", ser.getCompanyId(), ser.getIp(), ser.getPort());
 
        String content = msg.getBody().getContent();
 
        //温湿度地址,截取4位
        String temp = content.substring(0, 0 + 2 * 2);
        //高低位转换
        temp = BytesUtil.tran_LH(temp);
        int thConf = BytesUtil.hexToInt(temp);
 
        List<ExeRequest> list = exeOrderService.getInProgressOrderBySerId(BizType.SYS.getCode(), ser.getId() + "_" + thConf);
        ExeRequest exeRequest = list.get(0);
 
        int t, h;
 
        THDto th = new THDto();
        th.setCompanyId(ser.getCompanyId());
        th.setTempIn(Constant.ERROR_TEMP);
        th.setHumidityIn(Constant.ERROR_TEMP);
 
        //温度
        int start = 2, len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        t = BytesUtil.hexToInt(temp);
        if (t > 127) {//说明是负数
            t = BytesUtil.hexToInt("FF" + temp);
        }
        if (t == ERROR_TH_TAG) {
            log.error("{}温湿度解析异常,原因:没有检测到传感器", ser.getName());
            th.setRemark(ser.getName() + "温湿度解析异常,原因:没有检测到传感器");
        } else {
            th.setTempIn(Double.valueOf(t));
        }
 
        //湿度
        start = 3;
        len = 1;
        temp = content.substring(start * 2, start * 2 + len * 2);
        h = BytesUtil.hexToInt(temp);
        if (h > 127) {//说明是负数
            h = BytesUtil.hexToInt("FF" + temp);
        }
        if (h == ERROR_TH_TAG) {
            log.error("{}温湿度解析异常,原因:没有检测到传感器", ser.getName());
            th.setRemark(ser.getName() + "温湿度解析异常,原因:没有检测到传感器");
        } else {
            th.setHumidityIn(Double.valueOf(h));
        }
 
        th.setSerId(ser.getId());
        if (null != exeRequest) {
            th.setThConf(exeRequest.getThConf());
        } else {
            th.setThConf(thConf + "");
        }
 
        log.info("仓温仓湿解析完成={}", th.toString());
 
        //按照分机采集来确定
        thService.setCacheTH(th);
 
        String info = ser.getName() + " 温湿度获取完成";
        if (null != exeRequest) {
            //完成
            exeRequest.setMsg(info);
            exeOrderService.completeCache(exeRequest, false);
        }
        notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.SYS, info);
 
    }
}