package jtznyj.engineer.service.winform.data;

import java.util.ArrayList;
import java.util.Date;

/**
 * 监控报警记录集
 * 按照时间的先后倒序入列
 */
public class MonitorAlarmRecords extends ArrayList<MonitorAlarmRecord> {
    /**
     * 报警名称
     */
    public String groupName = "";

    /**
     * 合并监控预警信息
     * @param name
     * @param listMds
     */
    public boolean tryAddMonitorDescriptions(String name, Date preSiblingDate,Date currentDate, ArrayList<MonitorDescription> listMds) {
        if(!this.groupName.equals(name)){
            return false;
        }
        if(listMds.size() == 0){
            return true;
        }
        int iFind = -1;
        Date dtStart = listMds.get(0)._dtStart;
        Date dtEnd = listMds.get(0)._dtEnd;
        for (int i = 0; i < this.size(); i++) {
            MonitorAlarmRecord item = this.get(i);
            if(item._dtStart.getTime() == preSiblingDate.getTime()){

            }
            if ((item._dtStart.getTime() == preSiblingDate.getTime() || preSiblingDate.getTime() == item._dtEnd.getTime()) ||
                    (item._dtStart.getTime() <= dtEnd.getTime() && dtEnd.getTime() <= item._dtEnd.getTime())) {
                iFind = i;
                break;
            } else if (this.get(i)._name == name && this.get(i)._dtStart == dtStart) {
                iFind = i;
                break;
            }
        }
        MonitorAlarmRecord newAlarmRecord = new MonitorAlarmRecord(name, dtStart, dtEnd, listMds);
        for (int j = 0; j < listMds.size(); j++) {
            newAlarmRecord._secondStates.add(listMds.get(j)._secondState);
        }
        newAlarmRecord._isNeedUpdate = true;
        if (iFind == -1) {
            newAlarmRecord._dtFirstForcast = dtEnd;
            this.add(newAlarmRecord);
        } else {
            this.get(iFind)._dtEnd = newAlarmRecord._dtEnd;
            this.get(iFind)._bitDepthEnd = newAlarmRecord._bitDepthEnd;
            this.get(iFind)._realDepthEnd = newAlarmRecord._realDepthEnd;
        }

        return true;
    }
}

