package org.ts.ddcs.DataItemTemplate;

import org.ts.ddcs.log.LogHelper;
import org.ts.ddcs.Tool.BytesHelp;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 0xF5
 * 1小时内5分钟间隔相对水位1;河道水位、闸坝（泵）站上水位
 */
@SuppressWarnings("all")
public class DataItemTemplateDRZ1 extends DataItemTemplate  {
    @Override
    public byte[] Stream(byte[] data) {
        byte[] remain = data;
        if(this.macth){
            return remain;
        }
        String flag = BytesHelp.byte2HexStr(remain,0,1);
        if(flag.equals(this.feture)){
            byte[] len = BytesHelp.subBytes(remain, 1, 1);
            if ((remain.length - 2) >= 24) {
                byte[] drz = BytesHelp.subBytes(remain, 2, 24);
                byte[] valueBuff = new byte[2];
                for (int i = 0; i < 12; i++) {
                    valueBuff[0] = drz[i * 2];
                    valueBuff[1] = drz[i * 2 + 1];
                    short v = BytesHelp.bytes2short(valueBuff);
                    this.datas.put("drz1_" + String.format("%d",i + 1), new BigDecimal((float) v * (float) 0.01));
                }
                remain = BytesHelp.subBytes(remain, 26, remain.length - (26));
            } else {
                LogHelper.info("F6 数据错误 " + "1小时内5分钟间隔相对水位2");
            }
            this.macth = true;
        }
        return remain;
    }

    @Override
    public String toString() {
        String viewInfo = "";
        if (null != this.datas && this.datas.size() == 12) {
            BigDecimal v = (BigDecimal) this.datas.get("drz1_1");
            v =v.setScale(2, RoundingMode.HALF_UP);//保留两位小数
            viewInfo += "0分=" + v.toPlainString()+"米";
            v =v.setScale(2, RoundingMode.HALF_UP);//保留两位小数
            v = (BigDecimal) this.datas.get("drz1_2");
            v =v.setScale(2, RoundingMode.HALF_UP);//保留两位小数
            viewInfo += " 5分=" + v.toPlainString()+"米";
            v = (BigDecimal) this.datas.get("drz1_3");
            v =v.setScale(2, RoundingMode.HALF_UP);//保留两位小数
            viewInfo += " 10分=" + v.toPlainString()+"米";
            v = (BigDecimal) this.datas.get("drz1_4");
            v =v.setScale(2, RoundingMode.HALF_UP);//保留两位小数
            viewInfo += " 15分=" + v.toPlainString()+"米";
            v = (BigDecimal) this.datas.get("drz1_5");
            v =v.setScale(2, RoundingMode.HALF_UP);//保留两位小数
            viewInfo += " 20分=" + v.toPlainString()+"米";
            v = (BigDecimal) this.datas.get("drz1_6");
            v =v.setScale(2, RoundingMode.HALF_UP);//保留两位小数
            viewInfo += " 25分=" + v.toPlainString()+"米";
            v = (BigDecimal) this.datas.get("drz1_7");
            v =v.setScale(2, RoundingMode.HALF_UP);//保留两位小数
            viewInfo += " 30分=" + v.toPlainString()+"米";
            v = (BigDecimal) this.datas.get("drz1_8");
            v =v.setScale(2, RoundingMode.HALF_UP);//保留两位小数
            viewInfo += " 35分=" + v.toPlainString()+"米";
            v = (BigDecimal) this.datas.get("drz1_9");
            v =v.setScale(2, RoundingMode.HALF_UP);//保留两位小数
            viewInfo += " 40分=" + v.toPlainString()+"米";
            v = (BigDecimal) this.datas.get("drz1_10");
            v =v.setScale(2, RoundingMode.HALF_UP);//保留两位小数
            viewInfo += " 45分=" + v.toPlainString()+"米";
            v = (BigDecimal) this.datas.get("drz1_11");
            v =v.setScale(2, RoundingMode.HALF_UP);//保留两位小数
            viewInfo += " 50分=" + v.toPlainString()+"米";
            v = (BigDecimal) this.datas.get("drz1_12");
            v =v.setScale(2, RoundingMode.HALF_UP);//保留两位小数
            viewInfo += " 55分=" + v.toPlainString()+"米";
        }
        return viewInfo;
    }
}
