package com.njcn.cloud.pojo.vo;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 终端消息详情
 * @Author: wr
 * @Date: 2023/11/7 10:59
 */
@Data
public class DevMsgDetailInfo implements Serializable {
    @ApiModelProperty("未读条数")
    Integer unstate;
    @ApiModelProperty("终端信息")
    Page<DevMsgDetailInfo.Unstate> page;

    @Data
    public static class Unstate implements Serializable {
        @ApiModelProperty("终端消息列表Guid")
        private String devmsgIndex;

        @ApiModelProperty("终端消息id")
        private String topId;

        @ApiModelProperty("终端Id")
        private String devIndex;

        @ApiModelProperty("供电公司")
        private String gdName;

        @ApiModelProperty("变电站名称")
        private String bdzName;

        @ApiModelProperty("终端名称")
        private String devName;

        @ApiModelProperty("ip")
        private String ip;

        @ApiModelProperty("统计时间")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime timeID;

        @ApiModelProperty("总告警次数")
        private Integer allNum;

        @ApiModelProperty("终端告警")
        private Integer alarmNum;

        @ApiModelProperty("通讯中断")
        private Integer comOutNum;

        @ApiModelProperty("终端流量百分比")
        private Float flowNum;

        @ApiModelProperty("中断描述")
        private List<String> comoutDesc;

        @ApiModelProperty("告警描述")
        private List<String> alarmDesc;

        @ApiModelProperty("读取状态")
        private Integer state;

        public void setComoutDesc(String comoutDesc) {
            List<String> collect = new ArrayList<>();
            if (StrUtil.isNotBlank(comoutDesc)) {
                String[] split = comoutDesc.split(",");
                collect = Arrays.stream(split).sorted().collect(Collectors.toList());
            }
            this.comoutDesc = collect;
        }

        public void setAlarmDesc(String alarmDesc) {
            List<String> collect = new ArrayList<>();
            if (StrUtil.isNotBlank(alarmDesc)) {
                String[] split = alarmDesc.split(",");
                collect = Arrays.stream(split).sorted().collect(Collectors.toList());
            }
            this.alarmDesc = collect;
        }
    }
}