package org.ts.ddcs.Worker;

import com.alibaba.fastjson.JSONObject;
import org.ts.ddcs.DataItemTemplate.DataItemTemplateInterface;
import org.ts.ddcs.DataTemplate.DataTemplateLine;
import org.ts.ddcs.DataTemplate.DataTemplateManager;
import org.ts.ddcs.DataTemplate.TemplateLineNode;
import org.ts.ddcs.log.LogHelper;
import org.ts.ddcs.Tool.BytesHelp;
import org.ts.ddcs.utils.GBConstants;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.concurrent.Callable;

@SuppressWarnings("all")
public class SupplementDataGramSzy2012Process implements Callable<Integer> {

    private String _msg;

    private HashMap<String, DataItemTemplateInterface> dataItem;

    SupplementDataGramSzy2012Process(String msg) {
        this._msg = msg;

    }

    @Override
    public Integer call() {
        try {
            LogHelper.info("SupplementDataGramSzy2012Process " + this._msg);
            JSONObject body = JSONObject.parseObject(this._msg);
            if (body.containsKey(GBConstants.BASE_KEY_DATAGRAM)) {
                String datagram = body.getString(GBConstants.BASE_KEY_DATAGRAM);

                String datagramPickTime = body.getString("datagramPickTime");
                byte[] data_gram_buff = BytesHelp.hexStr2Bytes(datagram);
                DataTemplateLine line = DataTemplateManager.newInstance().createTemplateLine(GBConstants.AGREEMENT_KIND_SZY);
                line.Stream(data_gram_buff);
                TemplateLineNode macth = line.MacthTemplate();
                if (null != macth) {
                    macth.getDataTemplate().SupplementInfo(datagramPickTime);
                    /**数据入库处理*/

//                    if (DataProcessHolder.newInstance().dataProcess.dataBaseSave) {
//                        DataProcessHolder.newInstance().dataProcess.SubmitDataSaveTask(macth);
//                    }
                }
            }
        } catch (Exception e) {
            LogHelper.error(e);
        }
        return 0;
    }
}
