package com.pqs9900.pojo.message;

import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class MsgTemplateData {
    private String deptsId; //部门id
    private List<String> listPhone;//手机账号
    private List<String> listUserId;
    private List<String> listEvent;
    private Map<String, Set<String>> bdGd;
    private Set<Integer> listLineId; //发生暂降事件的id
    private String startTime;
    private String endTime;
    private String template;
    private Integer count; //发生暂降的次数

    public List<String> getListUserId() {
        return listUserId;
    }

    public void setListUserId(List<String> listUserId) {
        this.listUserId = listUserId;
    }


    public MsgTemplateData() {
    }

    public Map<String, Set<String>> getBdGd() {
        return bdGd;
    }

    public void setBdGd(Map<String, Set<String>> bdGd) {
        this.bdGd = bdGd;
    }

    public List<String> getListPhone() {
        return listPhone;
    }

    public void setListPhone(List<String> listPhone) {
        this.listPhone = listPhone;
    }

    public Set<Integer> getListLineId() {
        return listLineId;
    }

    public void setListLineId(Set<Integer> listLineId) {
        this.listLineId = listLineId;
    }

    public String getTemplate() {
        return template;
    }

    public void setTemplate(Map<String, Map<String, List<EventdetailInfo>>> map) {
        String[] num = {"①","②","③","④","⑤","⑥","⑦","⑧","⑨","⑩"};
        StringBuilder stringBuilder = new StringBuilder("");

        Iterator<Map.Entry<String, Map<String, List<EventdetailInfo>>>> iterator = map.entrySet().iterator();


        stringBuilder.append("于" + startTime + "至" + endTime + "时间段内共发生"+count+"条暂降事件。");

        int dela = 0;//用于判断是那条暂降事件
        while (iterator.hasNext()) {
            Map.Entry<String, Map<String, List<EventdetailInfo>>> mapMap = iterator.next();
            Map<String, List<EventdetailInfo>> list = mapMap.getValue();
            Iterator<Map.Entry<String, List<EventdetailInfo>>> iterator1 = list.entrySet().iterator();

            while (iterator1.hasNext()) {
                Map.Entry<String, List<EventdetailInfo>> maa = iterator1.next();
                String bdName = maa.getKey();
                List<EventdetailInfo> list1 = maa.getValue();


                for (int j = 0; j < list1.size(); j++) {
                    if (count != null && count <= 10) {


                            BigDecimal d = null;
                            String v = list1.get(j).getVoltage().substring(0,list1.get(j).getVoltage().indexOf("kV"));


                            d = new BigDecimal(v).divide(new BigDecimal(1.73),2,BigDecimal.ROUND_HALF_UP);


                            stringBuilder.append(num[dela]+"、"+list1.get(j).getStrTime()+" "+bdName+" "+list1.get(j).getLineName()+"发生暂降事件,特征幅值:" +new BigDecimal(list1.get(j).getValue()).setScale(2,BigDecimal.ROUND_HALF_UP)+"p.u.("+new BigDecimal(list1.get(j).getValue()).multiply(d).setScale(2,BigDecimal.ROUND_HALF_UP)+" kV)" + ",持续时间:" +
                                    (list1.get(j).getMsTime())/(1000) + "s;");
                            dela++;

                    } else{
                        stringBuilder.append(bdName+" "+list1.get(j).getLineName() + "发生" + list1.get(j).getCount().toString() + "次暂降事件");
                        stringBuilder.append(j == list1.size() - 1 ? ";" : ";");
                    }
                }
            }

            if (!iterator.hasNext()) {
                stringBuilder.append("详情请登录海南电网电能质量监测系统查看!");
            }
        }

        this.template = stringBuilder.toString();
    }

    public String getDeptsId() {
        return deptsId;
    }

    public void setDeptsId(String deptsId) {
        this.deptsId = deptsId;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public List<String> getListEvent() {
        return listEvent;
    }

    public void setListEvent(List<String> listEvent) {
        this.listEvent = listEvent;
    }

    public void setTemplate(String template) {
        this.template = template;
    }
}
