完成整体航班动态消息处理框架
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package com.gzzn.omms.msgexchangeapi.msghandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.schd.dnld.FLTR;
|
||||
|
||||
public class HandlerResult {
|
||||
private Boolean isSuccess;//是否更新成功
|
||||
private List<FLTR> fltrs; //影响的航班动态信息
|
||||
|
||||
public Boolean getIsSuccess() {
|
||||
return isSuccess;
|
||||
}
|
||||
public void setIsSuccess(Boolean isSuccess) {
|
||||
this.isSuccess = isSuccess;
|
||||
}
|
||||
public List<FLTR> getFltrs() {
|
||||
return fltrs;
|
||||
}
|
||||
public void setFltrs(List<FLTR> fltrs) {
|
||||
this.fltrs = fltrs;
|
||||
}
|
||||
|
||||
|
||||
public static HandlerResult success(FLTR fltr)
|
||||
{
|
||||
HandlerResult handlerResult = new HandlerResult();
|
||||
handlerResult.isSuccess = true;
|
||||
|
||||
List<FLTR> fltrs = new ArrayList();
|
||||
fltrs.add(fltr);
|
||||
|
||||
handlerResult.fltrs = fltrs;
|
||||
|
||||
return handlerResult;
|
||||
}//end function
|
||||
|
||||
public static HandlerResult success(List<FLTR> fltrs)
|
||||
{
|
||||
HandlerResult handlerResult = new HandlerResult();
|
||||
handlerResult.isSuccess = true;
|
||||
handlerResult.fltrs = fltrs;
|
||||
|
||||
return handlerResult;
|
||||
}//end function
|
||||
|
||||
public static HandlerResult failure()
|
||||
{
|
||||
HandlerResult handlerResult = new HandlerResult();
|
||||
handlerResult.isSuccess = false;
|
||||
|
||||
return handlerResult;
|
||||
}//end function
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.gzzn.omms.msgexchangeapi.msghandler;
|
||||
|
||||
public interface IBaseHandler {
|
||||
public HandlerResult run(String msg);
|
||||
}
|
||||
@@ -8,14 +8,13 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.Msg;
|
||||
import com.gzzn.omms.msgexchangeapi.service.IExchangeService;
|
||||
import com.gzzn.omms.msgexchangeapi.service.flightInfo.UpdateByCminmsgsResult;
|
||||
|
||||
@Service
|
||||
public class MsgHandlerDispatcher {
|
||||
@Autowired
|
||||
IExchangeService exchangeService;
|
||||
|
||||
public UpdateByCminmsgsResult dispatch(String xmlMsg)
|
||||
public HandlerResult dispatch(String xmlMsg)
|
||||
{
|
||||
Msg msg = exchangeService.xmlstrToObject(xmlMsg, Msg.class);
|
||||
String type = msg.getMeta().getType();
|
||||
@@ -26,7 +25,7 @@ public class MsgHandlerDispatcher {
|
||||
Class clazzHandler = Class.forName(getHandlerClassName(type,subType));
|
||||
Object classObject = clazzHandler.newInstance();
|
||||
Method runMethod = clazzHandler.getMethod("run", String.class);
|
||||
UpdateByCminmsgsResult result = (UpdateByCminmsgsResult) runMethod.invoke(classObject, xmlMsg);
|
||||
HandlerResult result = (HandlerResult) runMethod.invoke(classObject, xmlMsg);
|
||||
return result;
|
||||
} catch (ClassNotFoundException
|
||||
| InstantiationException
|
||||
@@ -50,7 +49,7 @@ public class MsgHandlerDispatcher {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("com.gzzn.omms.msgexchangeapi.msghandler" );
|
||||
buffer.append(".");
|
||||
buffer.append(type);
|
||||
buffer.append(type.toLowerCase());
|
||||
buffer.append(".");
|
||||
buffer.append(subType);
|
||||
buffer.append("Handler");
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.gzzn.omms.msgexchangeapi.msghandler.flop;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.flop.acft.ACFTMsg;
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.schd.dnld.FLTR;
|
||||
import com.gzzn.omms.msgexchangeapi.msghandler.HandlerResult;
|
||||
import com.gzzn.omms.msgexchangeapi.msghandler.IBaseHandler;
|
||||
import com.gzzn.omms.msgexchangeapi.service.IExchangeService;
|
||||
import com.gzzn.omms.msgexchangeapi.service.flightInfo.IFlightInfoService;
|
||||
|
||||
public class ACFTHandler implements IBaseHandler {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ACFTHandler.class);
|
||||
|
||||
@Autowired
|
||||
IExchangeService exchangeService;
|
||||
|
||||
@Autowired
|
||||
IFlightInfoService flightInfoService;
|
||||
|
||||
/**
|
||||
* 处理航班消息,更新航班动态信息
|
||||
*/
|
||||
@Override
|
||||
public HandlerResult run(String msg) {
|
||||
ACFTMsg acftMsg = exchangeService.xmlstrToObject(msg, ACFTMsg.class);
|
||||
FLTR fltr = flightInfoService.getByFlid(acftMsg.getFLOP().getFLID());
|
||||
if(null != fltr)
|
||||
{
|
||||
fltr.setAcft(acftMsg.getFLOP().getACFT());
|
||||
flightInfoService.saveFltr(fltr);
|
||||
return HandlerResult.success(fltr);
|
||||
}
|
||||
else {
|
||||
//没有该动态航班信息
|
||||
logger.warn("没有flid为:{}的消息",acftMsg.getFLOP().getFLID());
|
||||
}
|
||||
|
||||
return HandlerResult.failure();
|
||||
}//end function
|
||||
}
|
||||
Reference in New Issue
Block a user