IMFReader.java 2.8 KB
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.airport.core;

import com.airport.Main;
import com.airport.dao.impl.DaoImpl;
import com.airport.util.SystemBean;
import com.airport.util.Utils;
import com.airport.util.parse.XMPParse;
import com.caac.imf.api.IMFClient;
import java.util.Date;
import org.apache.log4j.Logger;

public class IMFReader extends Thread {
    private static final Logger logger = Logger.getLogger(IMFReader.class);
    private static final String stype = "/MSG/META/STYP";
    private IMFClient client;

    public IMFReader(IMFClient client) {
        this.client = client;
    }

    public void run() {
        while(true) {
            if (Main.LOGIN_OK) {
                synchronized(this) {
                    String message = this.client.getMSG();
                    if (message != null) {
                        this.save(message);
                    }
                }
            } else {
                //logger.info("***");
            }

            try {
                Thread.sleep(100L);
            } catch (InterruptedException var3) {
                var3.printStackTrace();
            }
        }
    }

    private void save(String message) {
        Date dt = new Date();
        DaoImpl dao = (DaoImpl)SystemBean.getBean("dao");
        String path = "data/" + Utils.dateToStr(dt, "yyyy-MM-dd") + "/";
        if (Utils.createDir(path)) {
            String fileName = "";

            try {
                String stype_value = XMPParse.getNodeValueFromXmlString(message, "/MSG/META/STYP");
                String type_value = XMPParse.getNodeValueFromXmlString(message, "/MSG/META/TYPE");
                String sender_value = XMPParse.getNodeValueFromXmlString(message, "/MSG/META/SNDR");
                String sntm_value = XMPParse.getNodeValueFromXmlString(message, "/MSG/META/DDTM");
                String seqn_value = XMPParse.getNodeValueFromXmlString(message, "/MSG/META/SEQN");

//                fileName = path + stype_value + "_" + Utils.dateToStr(dt, "yyyyMMddhhmmssSSS") + ".xml";
//                Utils.saveFile(fileName, message);
                dao.saveRecord("ALL", sender_value,sntm_value, message,type_value,stype_value,seqn_value);
//                logger.info("created  " + fileName + " ok");
            } catch (Exception var7) {
                //出错的报文存储到报文目录
                fileName = path + Utils.dateToStr(dt, "yyyyMMddhhmmssSSS") + ".txt";
                Utils.saveFile(fileName, message);
                logger.warn("报文入库失败已存储成备份文件:created  " + fileName + " ok");
                logger.error(var7);
                logger.warn(var7);
            }
        } else {
            logger.warn("创建目录失败.");
            logger.warn(message);
        }

    }
}