package com.ld.igds.protocol.beibo.grain.analysis;
|
|
import com.ld.igds.common.CoreCommonService;
|
import com.ld.igds.common.CoreSerService;
|
import com.ld.igds.common.dto.THDto;
|
import com.ld.igds.constant.BizType;
|
import com.ld.igds.grain.GrainUtil;
|
import com.ld.igds.io.notify.NotifyGrainInvoker;
|
import com.ld.igds.models.DepotConf;
|
import com.ld.igds.models.DeviceSer;
|
import com.ld.igds.models.DicSysConf;
|
import com.ld.igds.order.ExeOrderService;
|
import com.ld.igds.order.data.ExeRequest;
|
import com.ld.igds.protocol.beibo.grain.util.BeiboGrainServerUtils;
|
import com.ld.igds.util.ContextUtil;
|
import com.ld.igds.warn.WarnUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.*;
|
|
/**
|
* 协议解析
|
*
|
* @author vince
|
*/
|
@Slf4j
|
@Component(AnalysisService.BEAN_ID)
|
public class AnalysisService {
|
|
|
/**
|
* 针对分包粮情报文进行封装
|
*/
|
public static Map<String, String> contextMapGrain = new HashMap<>();
|
|
/**
|
* 用于存放返回的仓温仓湿信息
|
*/
|
public static Map<String, THDto> contextMapTH = new HashMap<>();
|
|
public static final String BEAN_ID = "beiboGrain.analysisService";
|
|
@Autowired
|
private CoreSerService coreSerService;
|
@Autowired
|
private CoreCommonService commonService;
|
@Autowired
|
private NotifyGrainInvoker notifyGrainInvoker;
|
@Autowired
|
private GrainUtil grainUtil;
|
@Autowired
|
private WarnUtils warnUtils;
|
@Autowired
|
private ExeOrderService exeOrderService;
|
|
/**
|
*
|
* @param result
|
*/
|
public void analysis(String result){
|
log.info("贝博分机------->>平台:信息报文={}", result);
|
if(!result.startsWith(BeiboGrainServerUtils.MSG_START)){
|
log.error("贝博分机------->>平台,解析粮情失败:报文起始符错误,不解析");
|
}
|
//去除起始符
|
result = result.substring(9*2-1);
|
|
analysisGrain(result);
|
}
|
|
|
private void analysisGrain(String result) {
|
try {
|
|
//截取分机地址
|
String serId = result.substring(0, 2);
|
//根据分机地址获取分机信息
|
DeviceSer ser = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(),serId);
|
if (ser == null) {
|
log.error("贝博分机-------->>平台,解析粮情失败,未获取到系统粮情主机配置:" + serId);
|
return;
|
}
|
|
// 首先获取到系统参数,判断是否需要批次自动优化
|
DicSysConf sysConf = commonService.getCacheSysConf(ser.getCompanyId());
|
List<ExeRequest> list = exeOrderService.getInProgressOrderBySerId(BizType.GRAIN.getCode(), ser.getId());
|
|
if (null == list || list.isEmpty()) {
|
String info = "粮情解析失败:分机=" + ser.getName() + "没有获取到所属仓库信息。";
|
log.error("贝博分机------>>>平台:" + info);
|
return;
|
}
|
|
//获取针对当前仓库的命令
|
ExeRequest exeRequest = list.get(0);
|
if (null == exeRequest) {
|
String info = "粮情解析失败:分机=" + ser.getName() + "没有获取历史命令。";
|
log.error("贝博分机------>>>平台:" + info);
|
return;
|
}
|
|
DepotConf depotConf = commonService.getCacheDepotConf(exeRequest.getCompanyId(), exeRequest.getDepotId());
|
|
if (null == depotConf) {
|
String info = "粮情解析失败:分机=" + ser.getName() + "没有获取到粮情参数配置信息。";
|
log.error("贝博分机------>>>平台:" + info);
|
return;
|
}
|
|
// 粮情的批次号重新根据频率调整
|
String batchId = ContextUtil.getBatchIdByFireq(depotConf.getGrainFreq());
|
|
//TODO 根据实际报文,待实现
|
|
|
|
|
|
} catch (Exception e) {
|
log.error(e.getMessage(), e);
|
}
|
}
|
}
|