package com.nokia.alarm.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.nokia.alarm.entity.MessageCfg;

public class SDKUtil {
    private final static DateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static MessageCfg getBody(Date date) {
        // 查询开始时间
        String startTime = addDateMinut(date, -35);
        // 查询结束时间
        String endTime = addDateMinut(date, -30);
        MessageCfg cfg = new MessageCfg();
        cfg.setStartTime(startTime);
        cfg.setEndTime(endTime);
        cfg.setResultDataType(1);
        cfg.setResultFieldType(1);
        cfg.setPageNum(0);
        List<String> provincelist = new ArrayList<>();
        provincelist.add("河北省");
        cfg.setProvince(provincelist);
        List<String> networklist = new ArrayList<>();
        networklist.add("104");
        networklist.add("105");
        cfg.setNetworkType(networklist);
        cfg.setPageSize(10000);
        return cfg;
    }

    public static MessageCfg gethistoryBody(Date date) {
        // 查询开始时间 1个月前
        String startTime = addDateMonth(date, -1);
        // 查询结束时间 当前时间
        String endTime = FORMAT.format(date);
        MessageCfg cfg = new MessageCfg();
        cfg.setStartTime(startTime);
        cfg.setEndTime(endTime);
        cfg.setResultDataType(1);
        cfg.setResultFieldType(1);
        cfg.setPageNum(0);
        List<String> provincelist = new ArrayList<>();
        provincelist.add("河北省");
        cfg.setProvince(provincelist);
        List<String> networklist = new ArrayList<>();
        networklist.add("104");
        networklist.add("105");
        List<String> cancelTime = new ArrayList<>();
        // 告警消除的开始时间
        cancelTime.add(addDateMinut(date, -35));
        // 告警消除的结束时间
        cancelTime.add(addDateMinut(date, -30));
        cfg.setCancelTime(cancelTime);
        cfg.setNetworkType(networklist);
        cfg.setPageSize(10000);
        return cfg;
    }

    public static String addDateMonth(Date date, int x) {
        if (date == null)
            return "";
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MONTH, x);// 24小时制
        date = cal.getTime();
        cal = null;
        return FORMAT.format(date);
    }

    private static String addDateMinut(Date date, int x) {
        // 引号里面个格
        if (date == null)
            return "";
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MINUTE, x);// 24小时制
        date = cal.getTime();
        cal = null;
        return FORMAT.format(date);
    }
}
