完善动态航班转历史功能,完善插入es的异常捕获及日志打印.修复FDIV结构和ES结构不符导致的插入异常问题。
This commit is contained in:
+56
-1
@@ -3,16 +3,24 @@ package com.gzzn.omms.msgexchangeapi.service.flightInfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.gzzn.omms.msgexchangeapi.elasticsearch.ElasticsearchUtil;
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.DIVERSIONDATA;
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.MOVEMENTINDICATOR;
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.SCHD.FLTR;
|
||||
import com.gzzn.omms.msgexchangeapi.utils.DateTimeUtil;
|
||||
import com.gzzn.omms.msgexchangeapi.utils.JsonUtil;
|
||||
|
||||
/**
|
||||
* 航班历史服务
|
||||
@@ -21,7 +29,8 @@ import com.gzzn.omms.msgexchangeapi.utils.DateTimeUtil;
|
||||
*/
|
||||
@Service
|
||||
public class FlightHisServiceImpl {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(FlightHisServiceImpl.class);
|
||||
|
||||
/**
|
||||
* 航班到达超过多久则成为历史航班数据(单位:秒)
|
||||
*/
|
||||
@@ -45,6 +54,16 @@ public class FlightHisServiceImpl {
|
||||
@Value("${hstCondition.SODT_HST_TIME}")
|
||||
private Integer SODT_HST_TIME ;
|
||||
|
||||
|
||||
/**
|
||||
* 历史航班数据索引
|
||||
*/
|
||||
private final String INDEX_NAME = "flight_hts";
|
||||
/**
|
||||
* 历史航班数据类型
|
||||
*/
|
||||
private final String ES_TYPE = "_doc";
|
||||
|
||||
/**
|
||||
* 获取可以进行转历史操作的航班
|
||||
* 遍历 查找出已经 可以作为历史数据的动态消息
|
||||
@@ -97,6 +116,42 @@ public class FlightHisServiceImpl {
|
||||
} //end function
|
||||
|
||||
|
||||
/**
|
||||
* 保存航班历史到ELK
|
||||
* @param fltrs
|
||||
* @return
|
||||
*/
|
||||
public boolean save(List<FLTR> fltrs)
|
||||
{
|
||||
for(FLTR fltr : fltrs){
|
||||
JSONObject jsondata = JSONObject.parseObject(JsonUtil.getString(fltr));
|
||||
//判断是否已经拥有该历史数据 因es类型原因请注意类型转换
|
||||
String SODT = fltr.getSODT();
|
||||
Long FLID = fltr.getFLID().longValue();
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
|
||||
.must(QueryBuilders.termQuery("SODT",SODT))
|
||||
.must(QueryBuilders.termQuery("FLID",FLID));
|
||||
List<Map<String, Object>> listInEs = ElasticsearchUtil.searchListData(INDEX_NAME, ES_TYPE, boolQuery, null, "FLID", null, null, null);
|
||||
|
||||
try {
|
||||
if(!CollectionUtils.isEmpty(listInEs)){
|
||||
//更新
|
||||
Map<String, Object> map = listInEs.get(0);
|
||||
String id = (String) map.get("id");
|
||||
ElasticsearchUtil.updateDataById(jsondata, INDEX_NAME, ES_TYPE, id);
|
||||
}else{
|
||||
//新增
|
||||
ElasticsearchUtil.addData(jsondata, INDEX_NAME, ES_TYPE);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("插入或更新动态航班历史错误:{}",e.getMessage());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 计划时间是否满足转历史要求
|
||||
* @param fltr 动态航班信息
|
||||
|
||||
Reference in New Issue
Block a user