添加滚动搜索功能

This commit is contained in:
zhouxiunai
2019-04-29 18:07:49 +08:00
parent 1c31f623e5
commit dc9d41623c
3 changed files with 188 additions and 1 deletions
@@ -1,15 +1,28 @@
package com.gzzn.omms.msgexchangeapi.controller;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gzzn.omms.msgexchangeapi.dto.ResponseDto;
import com.gzzn.omms.msgexchangeapi.elasticsearch.ElasticsearchUtil;
import com.gzzn.omms.msgexchangeapi.entity.msg.ABNDATA;
import com.gzzn.omms.msgexchangeapi.entity.msg.DIVERSIONDATA;
import com.gzzn.omms.msgexchangeapi.entity.msg.OPTDELAYDATA;
import com.gzzn.omms.msgexchangeapi.entity.msg.RETURNDATA;
import com.gzzn.omms.msgexchangeapi.entity.msg.SCHD;
import com.gzzn.omms.msgexchangeapi.service.flightInfo.IFlightInfoService;
import com.gzzn.omms.msgexchangeapi.utils.JsonUtil;
@RestController
public class FlightsController {
@@ -32,4 +45,86 @@ public class FlightsController {
return ResponseDto.success(fltrsRt);
}
/**
* 迁移航班历史信息
* @return
*/
@GetMapping("/flights/migrate")
public ResponseDto migrateFlightHst()
{
//get old fltrs
MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();
List<Map<String, Object>> listInEs = ElasticsearchUtil
.searchListDataWithScoll(
"flight_hts",
"_doc",
matchAllQueryBuilder,
null,
null,
null);
//trans to new fltrs
List<SCHD.FLTR> lsFltrs = transToNewFltrs(listInEs);
//fltrs save to new index
for (SCHD.FLTR fltr : lsFltrs) {
JSONObject jsondata = JSONObject.parseObject(JsonUtil.getString(fltr));
ElasticsearchUtil.addData(jsondata, "flight_hts2", "_doc");
}
return ResponseDto.success();
}//end function
private List<SCHD.FLTR> transToNewFltrs(List<Map<String, Object>> listInEs)
{
List<SCHD.FLTR> lsFltrs = new ArrayList<SCHD.FLTR>();
for (Map<String, Object> map : listInEs) {
ObjectMapper objMappper = new ObjectMapper();
SCHD.FLTR fltr = objMappper.convertValue(map, SCHD.FLTR.class);
//add BODY to Spec key
for (int i=0;i < fltr.getAbn().size();i++) {
ABNDATA abn = fltr.getAbn().get(i);
List<Map<String, Object>> lsAbn = (List<Map<String, Object>>)map.get("ABN");
Map abnMap = lsAbn.get(i);
switch (abn.getType()) {
case DLY:
abn.setDly(mapToDly((List<Map<String, Object>>) abnMap.get("BODY")));
break;
case CAN:
abn.setCan(objMappper.convertValue(abnMap.get("BODY"), String.class));
break;
case RTN:
abn.setRtn(objMappper.convertValue(abnMap.get("BODY"), RETURNDATA.class));
break;
case ALT:
abn.setAlt(objMappper.convertValue(abnMap.get("BODY"), DIVERSIONDATA .class));
break;
}
} //end for
lsFltrs.add(fltr);
}//end for
return lsFltrs;
}//end function
private List<OPTDELAYDATA> mapToDly(List<Map<String,Object>> ls)
{
List<OPTDELAYDATA> rtLs = new ArrayList<>(ls.size());
for(Map<String, Object> map : ls)
{
ObjectMapper objMappper = new ObjectMapper();
OPTDELAYDATA optdelaydata = objMappper.convertValue(map, OPTDELAYDATA.class);
rtLs.add(optdelaydata);
}
return rtLs;
}
}