1.增加FltrEsDto在存入es的时候,对ABN字段的body格式化成字符串存储。2.修复转航班历史失败依然删除了redis上的航班记录导致航班丢失的问题。
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.gzzn.omms.msgexchangeapi.dto.msg;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.ABNORMALTYPE;
|
||||
|
||||
public class ABNDATADto {
|
||||
@XmlElement(name = "TYPE", required = true)
|
||||
@JsonProperty("TYPE")
|
||||
protected ABNORMALTYPE type;
|
||||
|
||||
@XmlElement(name = "BODY")
|
||||
@JsonProperty("BODY")
|
||||
protected String body;//json字符串,根据type而不同
|
||||
|
||||
public ABNORMALTYPE getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(ABNORMALTYPE type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,51 @@
|
||||
package com.gzzn.omms.msgexchangeapi.dto.msg.convert;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
import com.gzzn.omms.msgexchangeapi.dto.msg.ABNDATADto;
|
||||
import com.gzzn.omms.msgexchangeapi.dto.msg.FltrEsDto;
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.ABNDATA;
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.SCHD;
|
||||
import com.gzzn.omms.msgexchangeapi.utils.JsonUtil;
|
||||
|
||||
/**
|
||||
* 航班转换
|
||||
* @author zhouxiunai
|
||||
*
|
||||
*/
|
||||
@Mapper(componentModel="spring",imports = JsonUtil.class)
|
||||
public interface FltrConvert {
|
||||
|
||||
/**
|
||||
* 转es中的dto
|
||||
* @param abndata
|
||||
* @return
|
||||
*/
|
||||
@Mapping(target = "body" , expression = "java( JsonUtil.getString(abndata.getBody()) )" )
|
||||
ABNDATADto abndataToAbndataDto(ABNDATA abndata) throws Exception;
|
||||
|
||||
/**
|
||||
* es中的dto转abndata
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@Mapping(target = "body" , expression = "java( JsonUtil.getObject(dto.getBody(),ABNDATADto.class) )" )
|
||||
ABNDATA abndataDtoToAbndata(ABNDATADto dto) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* 转换为es的dto 对象
|
||||
* @param fltr
|
||||
* @return es 的 dto
|
||||
*/
|
||||
FltrEsDto FltrToFltrEsDto(SCHD.FLTR fltr);
|
||||
|
||||
|
||||
/**
|
||||
* 转换航班动态为
|
||||
* @param fltrEsdto
|
||||
* @return 航班动态信息
|
||||
*/
|
||||
SCHD.FLTR FltrEsDtoToFltr(FltrEsDto fltrEsdto);
|
||||
}
|
||||
@@ -63,13 +63,17 @@ public class FlightHisScheduled {
|
||||
logger.info("获取到历史动态航班数据:{}条,准备转历史",fltrsHistory.size());
|
||||
|
||||
//航班历史写入ELK
|
||||
flightHisServiceImpl.save(fltrsHistory);
|
||||
List<FLTR> successSaveFltr = flightHisServiceImpl.save(fltrsHistory);
|
||||
|
||||
//从redis中删除历史航班
|
||||
List<String> fltrIdForHistory = fltrsHistory.stream().map(node->{
|
||||
//从redis中删除成功保存的历史航班
|
||||
List<String> fltrIdForHistory = successSaveFltr.stream().map(node->{
|
||||
return node.getFLID().toString();
|
||||
}).collect(Collectors.toList());
|
||||
flightInfoService.batchDeleteFltr(fltrIdForHistory);
|
||||
|
||||
if(!CollectionUtils.isEmpty(fltrIdForHistory))
|
||||
{
|
||||
flightInfoService.batchDeleteFltr(fltrIdForHistory);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("动态航班转历史错误:{}",e.getMessage());
|
||||
}
|
||||
|
||||
+19
-4
@@ -9,12 +9,15 @@ 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.Autowired;
|
||||
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.dto.msg.FltrEsDto;
|
||||
import com.gzzn.omms.msgexchangeapi.dto.msg.convert.FltrConvert;
|
||||
import com.gzzn.omms.msgexchangeapi.elasticsearch.ElasticsearchUtil;
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.DIVERSIONDATA;
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.MOVEMENTINDICATOR;
|
||||
@@ -22,6 +25,7 @@ import com.gzzn.omms.msgexchangeapi.entity.msg.SCHD.FLTR;
|
||||
import com.gzzn.omms.msgexchangeapi.utils.DateTimeUtil;
|
||||
import com.gzzn.omms.msgexchangeapi.utils.JsonUtil;
|
||||
|
||||
|
||||
/**
|
||||
* 航班历史服务
|
||||
* @author zhouxiunai
|
||||
@@ -54,6 +58,9 @@ public class FlightHisServiceImpl {
|
||||
@Value("${hstCondition.SODT_HST_TIME}")
|
||||
private Integer SODT_HST_TIME ;
|
||||
|
||||
@Autowired
|
||||
FltrConvert fltrConvert;
|
||||
|
||||
|
||||
/**
|
||||
* 历史航班数据索引
|
||||
@@ -119,13 +126,19 @@ public class FlightHisServiceImpl {
|
||||
/**
|
||||
* 保存航班历史到ELK
|
||||
* @param fltrs
|
||||
* @return
|
||||
* @return 成功保存的航班动态
|
||||
*/
|
||||
public boolean save(List<FLTR> fltrs)
|
||||
public List<FLTR> save(List<FLTR> fltrs)
|
||||
{
|
||||
List<FLTR> fltrSaveSuccess = new ArrayList<FLTR>(); //成功转历史的航班列表信息
|
||||
|
||||
for(FLTR fltr : fltrs){
|
||||
try {
|
||||
JSONObject jsondata = JSONObject.parseObject(JsonUtil.getString(fltr));
|
||||
//先转换航班信息为可存储到es 中的fltr dto 对象
|
||||
FltrEsDto fltrEsDto = fltrConvert.FltrToFltrEsDto(fltr);
|
||||
|
||||
|
||||
JSONObject jsondata = JSONObject.parseObject(JsonUtil.getString(fltrEsDto));
|
||||
//判断是否已经拥有该历史数据 因es类型原因请注意类型转换
|
||||
String SODT = fltr.getSODT();
|
||||
Long FLID = fltr.getFLID().longValue();
|
||||
@@ -143,11 +156,13 @@ public class FlightHisServiceImpl {
|
||||
//新增
|
||||
ElasticsearchUtil.addData(jsondata, INDEX_NAME, ES_TYPE);
|
||||
}
|
||||
|
||||
fltrSaveSuccess.add(fltr);
|
||||
} catch (Exception e) {
|
||||
logger.error("插入或更新动态航班历史错误:{}",e.getMessage());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return fltrSaveSuccess;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+14
-1
@@ -43,8 +43,21 @@ public class FlightHisServiceImplTest {
|
||||
List<FLTR> fltrsHis = flightHisServiceImpl.getHisToBeTran(fltrs);
|
||||
System.out.println("等待转历史航班动态条数:"+fltrsHis.size());
|
||||
|
||||
//flightHisServiceImpl.save(fltrsHis);
|
||||
|
||||
assertThat(fltrsHis).isNotEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试保存航班历史
|
||||
*/
|
||||
@Test
|
||||
public void testSave()
|
||||
{
|
||||
List<FLTR> fltrs = flightInfoService.findAll();
|
||||
assertThat(fltrs).isNotEmpty();
|
||||
|
||||
|
||||
List<FLTR> fltrsSuccess = flightHisServiceImpl.save(fltrs);
|
||||
assertThat(fltrsSuccess).hasSize(fltrs.size());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user