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);
|
|
}
|
}
|