GatherInfoHandle.java 2.1 KB
package com.sy.bwAnalysis;

import com.sy.bwAssist.Message;
import com.sy.model.GatherInfo;
import com.sy.model.commandInfo;
import org.apache.commons.lang.NullArgumentException;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

/**
 * 车辆过卡报文处理器
 * @author mrz
 */
@Component
public class GatherInfoHandle implements Runnable{

    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        /**
         * 1). 非空验证
         */
        if (StringUtils.isNotEmpty(message)){
            this.message = message;
        }else {
            throw new NullArgumentException("报文内容为空");
        }

    }



    @Override
    public void run() {

        /**
         * 一. 报文处理
         */
        stypConfirmAndRoute();



    }

    /**
     * 1). 通过将xml转实体类进行验证,
     *     同时验证报文的合法性,
     *     转换失败会throw 异常出来
     */
    private Message xmlTransToBean(){
        message = message.replace("Msg","MSG");
        MessageAnalysis analysis = new MessageAnalysis();
        return analysis.readTicketsXml(message);
    }

    /**
     * XML报文类型判断
     * 通过META节点的STYP节点判定
     */
    private void stypConfirmAndRoute(){
        Message messageBean = xmlTransToBean();
        String stype = messageBean.getMeta().getSmType();

        if ("CARM".equals(stype)) {
            if(messageBean.getComInfo() !=null){
                CommandInfoAnalysis commandInfoAnalysis = new CommandInfoAnalysis();
                commandInfo info  = commandInfoAnalysis.toJavaBean(messageBean);
                /**
                 * x22 commandInfo抬杆指令报文的处理
                 */
            }else{
                /**
                 * x21 gatherInfo通道采集报文的处理
                 */
                GatherInfoAnalysis gatherInfoAnalysis = new GatherInfoAnalysis();
                GatherInfo info = gatherInfoAnalysis.toJavaBean(messageBean);

            }
        }
    }
}