package com.ld.igds.io.impl;
|
|
import com.ld.igds.constant.BizType;
|
import com.ld.igds.constant.Constant;
|
import com.ld.igds.constant.GrainFrequence;
|
import com.ld.igds.grain.dto.GrainItemInfo;
|
import com.ld.igds.grain.service.CoreGrainService;
|
import com.ld.igds.io.constant.OrderRespEnum;
|
import com.ld.igds.io.notify.NotifyGrainInvoker;
|
import com.ld.igds.models.*;
|
import com.ld.igds.order.ExeOrderService;
|
import com.ld.igds.order.data.ExeRequest;
|
import com.ld.igds.weather.CoreWeatherService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.List;
|
|
@Slf4j
|
@Component
|
public class NotifyGrainInvokerImpl extends NotifyWebParent implements NotifyGrainInvoker {
|
|
@Autowired
|
private CoreGrainService grainService;
|
@Autowired
|
private CoreWeatherService weatherService;
|
@Autowired
|
private ExeOrderService exeRequestService;
|
|
@Override
|
public String analysisSuccess(Grain grain, List<GrainItemInfo> listGrainItems, DepotConf depotConf, DicSysConf sysConf, boolean isNotifyWeb, ExeRequest exeRequest) {
|
grain = addWeatherInfo(grain);
|
try {
|
// 如果是一日多次
|
if (null == depotConf) {
|
grainService.saveGrain(grain);
|
} else {
|
if (depotConf.getGrainFreq().equals(
|
GrainFrequence.FREQ_01.getCode())) {
|
grainService.saveGrain(grain);
|
} else {
|
grainService.saveOrUpdateGrain(grain);
|
}
|
}
|
String notifyMsg = depotConf.getDepotName() + " 粮情采集并解析成功,批次号="
|
+ grain.getBatchId();
|
|
//完成
|
exeRequest.setMsg(notifyMsg);
|
exeRequestService.completeCache(exeRequest, false);
|
|
notifyWeb(depotConf.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.GRAIN, notifyMsg);
|
|
log.info(depotConf.getDepotName() + "粮情解析成功:" + grain.getBatchId());
|
|
// 采集点保存,采集点的异常信息不考虑在粮情内部,直接忽略
|
if (StringUtils.isNotEmpty(sysConf.getGrainAddPoint())
|
&& Constant.YN_Y.equals(sysConf.getGrainAddPoint())) {
|
grainService.addGrainItems(listGrainItems, grain);
|
|
}
|
} catch (Exception e) {
|
String notifyMsg = depotConf.getDepotName() + "-保存失败,请勿2分钟内重复采集";
|
|
//完成
|
exeRequest.setMsg(notifyMsg);
|
exeRequestService.completeCache(exeRequest, true);
|
|
notifyWeb(depotConf.getCompanyId(), OrderRespEnum.MSG_ERROR, BizType.GRAIN, notifyMsg);
|
|
log.error(depotConf.getDepotName() + "粮情解析保存失败:" + e);
|
}
|
return null;
|
}
|
|
@Override
|
public String analysisSuccess(Grain grain, Depot depot, DicSysConf sysConf) {
|
grain = addWeatherInfo(grain);
|
|
try {
|
grainService.saveOrUpdateGrain(grain);
|
|
String notifyMsg = depot.getName() + " 收到推送粮情信息并解析成功,批次号=" + grain.getBatchId();
|
|
notifyWeb(grain.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.GRAIN, notifyMsg);
|
|
} catch (Exception e) {
|
String notifyMsg = depot.getName() + "-保存失败,请勿2分钟内重复采集";
|
this.notifyWeb(grain.getCompanyId(), OrderRespEnum.MSG_ERROR, BizType.GRAIN, notifyMsg);
|
|
log.error("粮情解析保存失败:" + e);
|
return notifyMsg;
|
}
|
return null;
|
}
|
|
@Override
|
public String analysisSuccess(Grain grain, ExeRequest exeRequest, DicSysConf sysConf) {
|
|
grain = addWeatherInfo(grain);
|
try {
|
grainService.saveOrUpdateGrain(grain);
|
|
String notifyMsg = exeRequest.getDepotName() + " 粮情采集并解析成功,批次号=" + grain.getBatchId();
|
|
//完成
|
exeRequest.setMsg(notifyMsg);
|
exeRequestService.completeCache(exeRequest, false);
|
|
} catch (Exception e) {
|
String notifyMsg = exeRequest.getDepotName() + "-保存失败,请勿2分钟内重复采集";
|
|
//完成
|
exeRequest.setMsg(notifyMsg);
|
exeRequestService.completeCache(exeRequest, true);
|
|
return notifyMsg;
|
}
|
return null;
|
}
|
|
@Override
|
public String analysisSuccess(Grain grain, ExeRequest exeRequest, DepotConf depotConf, DicSysConf sysConf) {
|
|
grain = addWeatherInfo(grain);
|
try {
|
grainService.saveOrUpdateGrain(grain);
|
|
String notifyMsg = exeRequest.getDepotName() + " 粮情采集并解析成功,批次号=" + grain.getBatchId();
|
|
//完成
|
exeRequest.setMsg(notifyMsg);
|
exeRequestService.completeCache(exeRequest, false);
|
|
notifyWeb(depotConf.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.GRAIN, notifyMsg);
|
log.info(depotConf.getDepotName() + "粮情解析成功:" + grain.getBatchId());
|
} catch (Exception e) {
|
String notifyMsg = exeRequest.getDepotName() + "-保存失败,请勿2分钟内重复采集";
|
|
//完成
|
exeRequest.setMsg(notifyMsg);
|
exeRequestService.completeCache(exeRequest, true);
|
|
notifyWeb(depotConf.getCompanyId(), OrderRespEnum.MSG_ERROR, BizType.GRAIN, notifyMsg);
|
|
log.error(depotConf.getDepotName() + "粮情解析保存失败:" + e);
|
return notifyMsg;
|
}
|
return null;
|
}
|
|
|
// 从缓存中获取当前的外温度外部湿度
|
private Grain addWeatherInfo(Grain grain) {
|
if(grain.getHumidityOut() != null && grain.getTempOut() != null){
|
return grain;
|
}
|
WeatherInfo weatherInfo = weatherService.getCacheWeather(grain.getCompanyId());
|
Double tOut = -100.0, hOut = -100.0;
|
if (null != weatherInfo) {
|
if (weatherInfo.getTemp().indexOf("℃") > 0) {
|
weatherInfo.setTemp(weatherInfo.getTemp().replace("℃", ""));
|
}
|
if (weatherInfo.getHumidity().indexOf("%") > 0) {
|
weatherInfo.setHumidity(weatherInfo.getHumidity().replace("%",
|
""));
|
}
|
tOut = Double.valueOf(weatherInfo.getTemp());
|
hOut = Double.valueOf(weatherInfo.getHumidity());
|
grain.setWeather(weatherInfo.getWeather());
|
}
|
if(grain.getHumidityOut() == null || grain.getHumidityOut() == 0.0){
|
grain.setHumidityOut(hOut);
|
}
|
if(grain.getTempOut() == null || grain.getTempOut() == 0.0){
|
grain.setTempOut(tOut);
|
}
|
return grain;
|
}
|
|
}
|