package org.ts.ddcs.DataTemplate;

import org.ts.ddcs.DataItemTemplate.DataItemTemplate;
import org.ts.ddcs.DataItemTemplate.DataItemTemplateCHLA;
import org.ts.ddcs.DataItemTemplate.DataItemTemplateSzy2012.*;
import org.ts.ddcs.Log.LogHelper;
import org.ts.ddcs.Tool.BytesHelp;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@SuppressWarnings("all")
public class DataTemplateSzy2012CC0 extends DataTemplateSzy2012 {

    /**
     * 采集时间
     */
    private byte[] collectTime;

    /**
     * 发报时间
     */
    private byte[] sendPacketTime;

    /**
     * 接收时间
     */
    private byte[] receiveTime;

    /**
     * 水质参数
     */
    public final static int CONTROL_DIR0_FN_REPORT_WATERQUALITY = 10;


    /**
     * 流速参数
     */
    public final static int CONTROL_DIR0_FN_REPORT_FLOW = 4;

    /**
     * 水位
     */
    public final static int CONTROL_DIR0_FN_WATER_HIGH = 2;

    /**
     * 流量
     */
    public final static int CONTROL_DIR0_FN_FLOW_RATE = 3;


    @Override
    public String GetViewName() {
        return "自报";
    }

    @Override
    public byte[] CollectTime() {
        return this.collectTime;
    }

    @Override
    public byte[] SendPacketTime() {
        return this.sendPacketTime;
    }

    @Override
    public byte[] ReceiveTime() {
        return this.receiveTime;
    }

    @Override
    public void Stream() {
        try {
            if (dataLen > 0) {
                dataItem = new HashMap<>();
                int count = 0;
                int ca = BytesHelp.bcdToInt(this.controlArea[0], 3, 0);
                if (ca == CONTROL_DIR0_FN_REPORT_WATERQUALITY) {

                    byte[] flag = BytesHelp.subBytes(this.dataArea, count, 5);
                    count += 5;
                    byte[] data_flag = new byte[40];
                    for (int i = 0; i < flag.length; i++) {
                        int d0 = BytesHelp.bcdToInt(flag[i], 0, 0);
                        data_flag[i * 8] = (byte) d0;
                        int d1 = BytesHelp.bcdToInt(flag[i], 1, 1);
                        data_flag[i * 8 + 1] = (byte) d1;
                        int d2 = BytesHelp.bcdToInt(flag[i], 2, 2);
                        data_flag[i * 8 + 2] = (byte) d2;
                        int d3 = BytesHelp.bcdToInt(flag[i], 3, 3);
                        data_flag[i * 8 + 3] = (byte) d3;
                        int d4 = BytesHelp.bcdToInt(flag[i], 4, 4);
                        data_flag[i * 8 + 4] = (byte) d4;
                        int d5 = BytesHelp.bcdToInt(flag[i], 5, 5);
                        data_flag[i * 8 + 5] = (byte) d5;
                        int d6 = BytesHelp.bcdToInt(flag[i], 6, 6);
                        data_flag[i * 8 + 6] = (byte) d6;
                        int d7 = BytesHelp.bcdToInt(flag[i], 7, 7);
                        data_flag[i * 8 + 7] = (byte) d7;
                    }

                    for (int i = 0; i < data_flag.length; i++) {
                        if (data_flag[i] == 1) {
                            if (i == 0) {
                                //水温
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D0");
                                template.setColumn("WT");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);

                            } else if (i == 1) {
                                //pH 值
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D1");
                                template.setColumn("PH");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 2) {
                                //溶解氧
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D2");
                                template.setColumn("DOX");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 3) {
                                //高锰酸盐指数
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D3");
                                template.setColumn("CODMN");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 4) {
                                //电导率
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D4");
                                template.setColumn("COND");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 5) {
                                //氧化还原电位
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D5");
                                template.setColumn("ORP");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 6) {
                                //浊度
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D6");
                                template.setColumn("TURB");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 7) {
                                //化学需氧量
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D7");
                                template.setColumn("CODCR");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 8) {
                                //五日生化需氧量
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D8");
                                template.setColumn("CODCR_5D");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 9) {
                                //氨氮
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D9");
                                template.setColumn("NH3N");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 10) {
                                //总氮
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D10");
                                template.setColumn("TN");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 11) {
                                //铜
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D11");
                                template.setColumn("CU");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 12) {
                                //锌
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D12");
                                template.setColumn("ZN");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 13) {
                                //氟化物
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D13");
                                template.setColumn("F");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 14) {
                                //硒
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D14");
                                template.setColumn("SE");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 15) {
                                //砷
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D15");
                                template.setColumn("ARS");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 16) {
                                //汞
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D16");
                                template.setColumn("HG");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 17) {
                                //镉
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D17");
                                template.setColumn("CD");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 18) {
                                //六价铬
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D18");
                                template.setColumn("CR6");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 19) {
                                //铅
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D19");
                                template.setColumn("PB");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 20) {
                                //氰化物
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D20");
                                template.setColumn("CYN");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 21) {
                                //挥发酚
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D21");
                                template.setColumn("VH");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);
                                template.setTable("wq_awqmd_d");

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 22) {
                                //苯酚
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D22");
                                template.setColumn("C6H5OH");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 23) {
                                //硫化物
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D23");
                                template.setColumn("COS");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 24) {
                                //粪大肠菌群
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D24");
                                template.setColumn("EPEC");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 25) {
                                //硫酸盐
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D25");
                                template.setColumn("NaSO4");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 26) {
                                //氯化物
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D26");
                                template.setColumn("CL");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 27) {
                                //硝酸盐氮
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D27");
                                template.setColumn("NO3");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 28) {
                                //铁
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D28");
                                template.setColumn("FE");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 29) {
                                //锰
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D29");
                                template.setColumn("MN");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 30) {
                                //石油类
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D30");
                                template.setColumn("OIL");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 31) {
                                //阴离子表面活性剂
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D31");
                                template.setColumn("AS");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 32) {
                                //六六六
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D32");
                                template.setColumn("SIXSIXSIX");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 33) {
                                //滴滴涕
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D33");
                                template.setColumn("DDT");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 34) {
                                //有机氯农药
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D34");
                                template.setColumn("OCPs");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);

                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 35) {
                                //总磷
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D35");
                                template.setColumn("TP");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateC0_WaterQuality itemTemplate = new DataItemTemplateC0_WaterQuality();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);
                                dataItem.put(template.getColumn(), itemTemplate);
                            } else if (i == 36) {
                                //叶绿素
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_10_D36");
                                template.setColumn("CHLA");
                                template.setTable("wq_awqmd_d");

                                DataItemTemplateCHLA itemTemplate = new DataItemTemplateCHLA();
                                itemTemplate.Init(template);
                                byte[] itemData = BytesHelp.subBytes(this.dataArea, count, 4);
                                itemTemplate.Stream(itemData);
                                dataItem.put(template.getColumn(), itemTemplate);
                            }
                            count += 4;
                        }
                    }

                    /**报警状态*/
                    byte[] waring = BytesHelp.subBytes(this.dataArea, this.dataArea.length - 9, 2);
                    ItemTemplateSet template = new ItemTemplateSet();
                    template.setFeature("C0_04");
                    template.setColumn("status");
                    template.setTable("t_rtu_warning");
                    DataItemTemplateC0_WarningInfo warningInfo = new DataItemTemplateC0_WarningInfo();
                    warningInfo.Init(template);
                    warningInfo.Stream(waring);
                    dataItem.put(template.getColumn(), warningInfo);
                    count += 2;

                    /**测站状态*/
                    byte[] status = BytesHelp.subBytes(this.dataArea, this.dataArea.length - 7, 2);
                    template = new ItemTemplateSet();
                    template.setFeature("C0_04");
                    template.setColumn("status");
                    template.setTable("t_rtu_status");
                    DataItemTemplateC0_RtuStatus rtuStatus = new DataItemTemplateC0_RtuStatus();
                    rtuStatus.Init(template);
                    rtuStatus.Stream(status);
                    dataItem.put(template.getColumn(), rtuStatus);
                    count += 2;

                    /**观测时间*/
                    SimpleDateFormat timeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
                    String dt = timeFormat.format(new Date());

                    this.sendPacketTime = BytesHelp.hexStr2Bytes(dt.substring(2));

                    this.receiveTime = BytesHelp.hexStr2Bytes(dt.substring(2));

                    //水质，采集时间为秒分时日月
                    byte[] tm = BytesHelp.subBytes(this.dataArea, this.dataArea.length - 5, 5);
                    count += 5;
                    byte tmp = tm[0];
                    tm[0] = tm[4];
                    tm[4] = tmp;
                    tmp = tm[1];
                    tm[1] = tm[3];
                    tm[3] = tmp;
                    this.collectTime = BytesHelp.arrayApend(BytesHelp.subBytes(BytesHelp.hexStr2Bytes(dt), 1, 1), tm);
                } else if (ca == CONTROL_DIR0_FN_REPORT_FLOW) {

                    int dataLen = this.dataArea.length - 5 - 4;
                    int index=0;
                    if (dataLen > 0) {
                        int tmpCount=0;
                        while (true){
                            if (tmpCount>=dataLen){
                                break;
                            }
                            ItemTemplateSet template = new ItemTemplateSet();
                            template.setFeature("C0_04");
                            if (index ==0){
                                template.setColumn("FLOW_SPEED");
                            }else{
                                template.setColumn("FLOW_SPEED_"+index);
                            }

                            template.setTable("wq_river");
                            template.setDesc("流速");
                            DataItemTemplateC0_FlowSpeed itemTemplate = new DataItemTemplateC0_FlowSpeed();
                            itemTemplate.Init(template);
                            itemTemplate.Stream(BytesHelp.subBytes(this.dataArea, tmpCount, this.dataArea.length - tmpCount));
                            dataItem.put(template.getColumn(), itemTemplate);
                            tmpCount+=3;
                            index+=1;
                        }

                    }

                    count = dataLen;


                    /**报警状态*/
                    byte[] waring = BytesHelp.subBytes(this.dataArea, this.dataArea.length - 9, 2);
                    ItemTemplateSet template = new ItemTemplateSet();
                    template.setFeature("C0_04");
                    template.setColumn("status");
                    template.setTable("t_rtu_warning");
                    DataItemTemplateC0_WarningInfo warningInfo = new DataItemTemplateC0_WarningInfo();
                    warningInfo.Init(template);
                    warningInfo.Stream(waring);
                    dataItem.put(template.getColumn(), warningInfo);
                    count += 2;

                    /**测站状态*/
                    byte[] status = BytesHelp.subBytes(this.dataArea, this.dataArea.length - 7, 2);
                    template = new ItemTemplateSet();
                    template.setFeature("C0_04");
                    template.setColumn("status");
                    template.setTable("t_rtu_status");
                    DataItemTemplateC0_RtuStatus rtuStatus = new DataItemTemplateC0_RtuStatus();
                    rtuStatus.Init(template);
                    rtuStatus.Stream(status);
                    dataItem.put(template.getColumn(), rtuStatus);
                    count += 2;

                    /**观测时间  秒分时日月*/
                    SimpleDateFormat timeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
                    String dt = timeFormat.format(new Date());

                    this.sendPacketTime = BytesHelp.hexStr2Bytes(dt.substring(2));
                    this.receiveTime = BytesHelp.hexStr2Bytes(dt.substring(2));

                    byte[] tm = BytesHelp.subBytes(this.dataArea, this.dataArea.length - 5, 5);
                    count += 5;
                    byte tmp = tm[0];
                    tm[0] = tm[4];
                    tm[4] = tmp;
                    tmp = tm[1];
                    tm[1] = tm[3];
                    tm[3] = tmp;
                    this.collectTime = BytesHelp.arrayApend(BytesHelp.subBytes(BytesHelp.hexStr2Bytes(dt), 1, 1), tm);


                } else if (ca == CONTROL_DIR0_FN_WATER_HIGH) {
                    int dataLen = this.dataArea.length - 5 - 4;
                    if (dataLen > 0) {
                        ItemTemplateSet template = new ItemTemplateSet();
                        template.setFeature("C0_04");
                        template.setColumn("WATER_HIGH");
                        template.setTable("wq_river");
                        template.setDesc("水位");
                        DataItemTemplateC0_WaterHigh itemTemplate = new DataItemTemplateC0_WaterHigh();
                        itemTemplate.Init(template);
                        itemTemplate.Stream(BytesHelp.subBytes(this.dataArea, 0, this.dataArea.length - dataLen));
                        dataItem.put(template.getColumn(), itemTemplate);
                    }

                    count = dataLen;


                    /**报警状态*/
                    byte[] waring = BytesHelp.subBytes(this.dataArea, this.dataArea.length - 9, 2);
                    ItemTemplateSet template = new ItemTemplateSet();
                    template.setFeature("C0_04");
                    template.setColumn("status");
                    template.setTable("t_rtu_warning");
                    DataItemTemplateC0_WarningInfo warningInfo = new DataItemTemplateC0_WarningInfo();
                    warningInfo.Init(template);
                    warningInfo.Stream(waring);
                    dataItem.put(template.getColumn(), warningInfo);
                    count += 2;

                    /**测站状态*/
                    byte[] status = BytesHelp.subBytes(this.dataArea, this.dataArea.length - 7, 2);
                    template = new ItemTemplateSet();
                    template.setFeature("C0_04");
                    template.setColumn("status");
                    template.setTable("t_rtu_status");
                    DataItemTemplateC0_RtuStatus rtuStatus = new DataItemTemplateC0_RtuStatus();
                    rtuStatus.Init(template);
                    rtuStatus.Stream(status);
                    dataItem.put(template.getColumn(), rtuStatus);
                    count += 2;

                    /**观测时间 秒分时日月*/
                    SimpleDateFormat timeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
                    String dt = timeFormat.format(new Date());

                    this.sendPacketTime = BytesHelp.hexStr2Bytes(dt.substring(2));

                    this.receiveTime = BytesHelp.hexStr2Bytes(dt.substring(2));

                    byte[] tm = BytesHelp.subBytes(this.dataArea, this.dataArea.length - 5, 5);
                    count += 5;
                    byte tmp = tm[0];
                    tm[0] = tm[4];
                    tm[4] = tmp;
                    tmp = tm[1];
                    tm[1] = tm[3];
                    tm[3] = tmp;
                    this.collectTime = BytesHelp.arrayApend(BytesHelp.subBytes(BytesHelp.hexStr2Bytes(dt), 1, 1), tm);


                } else if (ca == CONTROL_DIR0_FN_FLOW_RATE) {
                    int dataLen = this.dataArea.length - 5 - 4;
                    if (dataLen > 0) {
                       int index=0;
                        for (int i=0;i<dataLen;i+=10){
                            if (dataLen-i >=0){
                                index+=1;
                                ItemTemplateSet template = new ItemTemplateSet();
                                template.setFeature("C0_03");
                                template.setColumn("FLOW_RATE_R_"+String.format("%02d",index));
                                template.setTable("t_szy_flow_rate");
                                template.setDesc("瞬时流量");
                                DataItemTemplateC0_FlowRate itemTemplate = new DataItemTemplateC0_FlowRate();
                                itemTemplate.Init(template);
                                itemTemplate.Stream(BytesHelp.subBytes(this.dataArea, count, 5));
                                dataItem.put(template.getColumn(), itemTemplate);
                                count += 5;


                                ItemTemplateSet template_sum = new ItemTemplateSet();
                                template_sum.setFeature("C0_03");
                                template_sum.setColumn("FLOW_RATE_S_"+String.format("%02d",index));
                                template_sum.setTable("t_szy_flow_rate");
                                template_sum.setDesc("累计流量");
                                DataItemTemplateC0_SumFlowRate itemTemplateSum = new DataItemTemplateC0_SumFlowRate();
                                itemTemplateSum.Init(template_sum);
                                itemTemplateSum.Stream(BytesHelp.subBytes(this.dataArea, count, 5));
                                dataItem.put(template_sum.getColumn(), itemTemplateSum);
                                count += 5;
                            }
                        }
                    }


                    /**报警状态*/
                    byte[] waring = BytesHelp.subBytes(this.dataArea, this.dataArea.length - 9, 2);
                    ItemTemplateSet template = new ItemTemplateSet();
                    template.setFeature("C0_04");
                    template.setColumn("status");
                    template.setTable("t_rtu_warning");
                    DataItemTemplateC0_WarningInfo warningInfo = new DataItemTemplateC0_WarningInfo();
                    warningInfo.Init(template);
                    warningInfo.Stream(waring);
                    dataItem.put(template.getColumn(), warningInfo);
                    count += 2;

                    /**测站状态*/
                    byte[] status = BytesHelp.subBytes(this.dataArea, this.dataArea.length - 7, 2);
                    template = new ItemTemplateSet();
                    template.setFeature("C0_04");
                    template.setColumn("status");
                    template.setTable("t_rtu_status");
                    DataItemTemplateC0_RtuStatus rtuStatus = new DataItemTemplateC0_RtuStatus();
                    rtuStatus.Init(template);
                    rtuStatus.Stream(status);
                    dataItem.put(template.getColumn(), rtuStatus);
                    count += 2;

                    /**观测时间 秒分时日*/
                    SimpleDateFormat timeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
                    String dt = timeFormat.format(new Date());

                    this.sendPacketTime = BytesHelp.hexStr2Bytes(dt.substring(2));

                    this.receiveTime = BytesHelp.hexStr2Bytes(dt.substring(2));

                    byte[] tm = BytesHelp.subBytes(this.dataArea, this.dataArea.length - 5, 4);
                    count += 4;
                    byte tmp = tm[0];
                    tm[0] = tm[3];
                    tm[3] = tmp;
                    tmp = tm[1];
                    tm[1] = tm[2];
                    tm[2] = tmp;
                    this.collectTime = BytesHelp.arrayApend(BytesHelp.subBytes(BytesHelp.hexStr2Bytes(dt), 1, 2), tm);

                    count += 1;
                }


                if (count != this.dataArea.length) {
                    LogHelper.info("******************* C0 DATA ERROR******************* ");
                }
            }
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }


}
