优化航班延误的处理,添加航班延误增加航班异常信息功能

This commit is contained in:
zhouxiunai
2019-01-15 15:40:43 +08:00
parent 30a69b8cfa
commit 22f10ef7a2
5 changed files with 149 additions and 17 deletions
@@ -7,9 +7,25 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class ABNDATA {
@XmlElement(name = "TYPE", required = true)
@JsonProperty("TYPE")
protected String 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;
}
}
@@ -0,0 +1,21 @@
package com.gzzn.omms.msgexchangeapi.entity.msg;
/**
* 异常状态类型
* @author 航班异常状态类型
*
*/
public enum ABNORMALTYPE {
DLY,
CAN,
RTN,
ALT;
public String value() {
return name();
}
public static ABNORMALTYPE fromValue(String v) {
return valueOf(v);
}
}
@@ -2063,6 +2063,16 @@ public class SCHD
this.lreno = lreno;
}
public List<ABNDATA> getAbn() {
if (abn == null) {
abn = new ArrayList<ABNDATA>();
}
return abn;
}
public void setAbn(List<ABNDATA> abn) {
this.abn = abn;
}
}
}
@@ -1,13 +1,16 @@
package com.gzzn.omms.msgexchangeapi.msghandler.flop;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import com.gzzn.omms.msgexchangeapi.entity.msg.ABNDATA;
import com.gzzn.omms.msgexchangeapi.entity.msg.ABNORMALTYPE;
import com.gzzn.omms.msgexchangeapi.entity.msg.DELAYDATA;
import com.gzzn.omms.msgexchangeapi.entity.msg.FLOP;
import com.gzzn.omms.msgexchangeapi.entity.msg.OPTDELAYDATA;
import com.gzzn.omms.msgexchangeapi.entity.msg.SCHD;
import com.gzzn.omms.msgexchangeapi.msghandler.flop.base.FlopBaseHandler;
import com.gzzn.omms.msgexchangeapi.utils.JsonUtil;
/**
* 航班延误消息处理
@@ -19,24 +22,68 @@ public class DELYHandler extends FlopBaseHandler {
@Override
protected SCHD.FLTR updateFltr(FLOP flop,SCHD.FLTR fltr)
{
//update
if(CollectionUtils.isEmpty(flop.getDELY()) )
//清空上次旧的航班延误信息
fltr.getDELY().clear();
//空标签,取消航班延误状态
if(flop.getDELY().size() == 1
&& StringUtils.isEmpty(flop.getDELY().get(0).getCODE())
)
{
//清空延误信息
fltr.getDELY().clear();
}
else {
//延误信息只新增
for (OPTDELAYDATA optdelaydata : flop.getDELY() ) {
DELAYDATA delaydata = new DELAYDATA();
BeanUtils.copyProperties(optdelaydata, delaydata);
fltr.getDELY().add(delaydata);
}
//清空航班异常信息中的延误信息
fltr = clearDelyInfo(fltr);
return fltr;
}
//更新延误信息
for (OPTDELAYDATA optdelaydata : flop.getDELY() ) {
DELAYDATA delaydata = new DELAYDATA();
BeanUtils.copyProperties(optdelaydata, delaydata);
fltr.getDELY().add(delaydata);
}
//更新航班异常信息,先清空旧的再加入新的
for(int i=0;i<fltr.getAbn().size();i++)
{
ABNDATA abndata = fltr.getAbn().get(i);
if(abndata.getType() == ABNORMALTYPE.DLY)
{
fltr.getAbn().remove(i);
}
}
for (OPTDELAYDATA optdelaydata : flop.getDELY() ) {
ABNDATA abndata = new ABNDATA();
abndata.setType(ABNORMALTYPE.DLY);
abndata.setBody(JsonUtil.getString(optdelaydata));
fltr.getAbn().add(abndata);
}
return fltr;
}
}//end function
/**
* 清空航班动态异常信息中的延误信息
* @param fltr 航班动态
* @return 新的航班动态
*/
private SCHD.FLTR clearDelyInfo(SCHD.FLTR fltr)
{
int i=0;
while(i < fltr.getAbn().size() )
{
ABNDATA abndata = fltr.getAbn().get(i);
if(abndata.getType() == ABNORMALTYPE.DLY)
{
fltr.getAbn().remove(i);
}
else {
i++;
}
}//end while
return fltr;
} //end function
}
@@ -0,0 +1,38 @@
package com.gzzn.omms.msgexchangeapi.msghandler.flop;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.gzzn.omms.msgexchangeapi.dao.CminmsgDao;
import com.gzzn.omms.msgexchangeapi.entity.Cminmsg;
import com.gzzn.omms.msgexchangeapi.entity.CminmsgWapper;
import com.gzzn.omms.msgexchangeapi.msghandler.HandlerResult;
import com.gzzn.omms.msgexchangeapi.service.exchange.IExchangeService;
import com.gzzn.omms.msgexchangeapi.utils.JsonUtil;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DELYHandlerTest {
@Autowired
private CminmsgDao cminmsgDao;
@Autowired
private IExchangeService exchangeService;
@Test
public void testRun()
{
Cminmsg cminmsg = cminmsgDao.findOne(240451L);
CminmsgWapper cminmsgWapper = new CminmsgWapper(cminmsg);
cminmsgWapper.setMsg(exchangeService.xmlToMsg(cminmsg.getCminmsgsClobMsg()));
DELYHandler delyhandler = new DELYHandler();
HandlerResult result = delyhandler.run(cminmsgWapper);
System.out.println(JsonUtil.getString(result));
}
}