package org.ts.ddcs.DataTemplate.jtTemplate;


import com.alibaba.fastjson.JSONObject;
import org.ts.ddcs.DataItemTemplate.jtDataItemTemplate.JtDataItemTemplateLocation;
import org.ts.ddcs.log.LogHelper;
import org.ts.ddcs.Tool.BytesHelp;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
 * 交通808-2019规约数据模板
 * created by swp on 2017/8/23
 *
 * @author dylan
 */
public class JtDataTemplateLocation extends JtDataTemplate {


    @Override
    public void Stream() {
        try {
            try {
                if (dataLen > 0 && dataLen == dataArea.length) {
                    int count = 0;
                    //报警

                    count += 4;
                    //

                    count += 4;

                    //纬度
                    byte[] location = BytesHelp.subBytes(this.dataArea, count, 8);
                    JtDataItemTemplateLocation itemTemplateLocation = new JtDataItemTemplateLocation();
                    itemTemplateLocation.Stream(location);
                    this.dataItem = new HashMap<>();
                    this.dataItem.put("location", itemTemplateLocation);

                    count += 8;

                    //经度


                }
            } catch (Exception e) {
                LogHelper.error(e);
            }
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }

    @Override
    public String getDataInfo() {
        JSONObject data = new JSONObject();
        data.put("func", this.featureKey);
        List<JSONObject> items = new LinkedList<>();

        data.put("data", items);
        return data.toJSONString();
    }

}
