<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>终端运行异常通知详情</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <link rel="stylesheet" href="${ctx}/css/plugin/bootstrap/bootstrap.css">
    <link rel="stylesheet" href="${ctx}/css/basic.css">
    <style>

        .title{
            padding: 1px;
            line-height: 1.6;
            border-left: 5px solid #5FB878;
            border-radius: 0 2px 2px 0;
            background-color: #FAFAFA;
            text-align: left;
        }
        .content{
            text-align: left;
            padding:10px;
        }
    </style>
</head>
<body>
<div class="container-fluid">
   <table class="mt10" style="width: 100%;height: 100%;overflow-y: hidden">
       <tr>
           <td>
               <div>
                   <div class="title">终端基础信息</div>
               </div>
               <div class="content" id="baseInfo">

               </div>

           </td>
       </tr>
       <tr>
           <td>
               <div>
                   <div class="title">数据完整性</div>
               </div>
               <div class="content" id="limitInfo">

               </div>
           </td>
       </tr>
       <tr>
           <td>
               <div>
                   <div class="title">终端通讯信息</div>
               </div>
               <div class="content" id="comoutInfo" style="overflow-y: auto">

               </div>
           </td>
       </tr>
       <tr>
           <td>
               <div>
                   <div class="title">终端告警信息</div>
               </div>
               <div class="content" id="alarmInfo" style="overflow-y: auto">

               </div>
           </td>
       </tr>
       <tr>
           <td>
               <div>
                   <div class="title">终端流量信息</div>
               </div>
               <div class="content" id="flowInfo">

               </div>
           </td>
       </tr>
   </table>
</div>

</body>
<script src="${ctx}/js/plugin/jquery/jquery.min.js"></script>
<script src="${ctx}/js/plugin/bootstrap/bootstrap.min.js"></script>
<script src="${ctx}/js/plugin/layui/layer.js"></script>
<script src="${ctx}/jspJS/utils/loading.js"></script>
<script src="${ctx}/jspJS/utils/common.js"></script>
<script src="${ctx}/jspJS/utils/judgeAjaxStatus.js"></script>
<script>
    var dataObject;
    let timeId = getQueryString("timeId")
    let devIndex = getQueryString("devIndex")
    var height = $(window).height()



    $(function () {
        $("#comoutInfo").css("height",height*0.23)
        $("#alarmInfo").css("height",height*0.23)
        initView()

    });


    function initView() {
        let loading;
        $.ajax({
            type: "POST",
            url: "/pqs9900/inStrategy/getRunExceptionDetailById",
            dataType: 'json',
            data: {
                timeId: timeId,
                devIndex: devIndex
            },
            beforeSend: function () {
                loading = ityzl_SHOW_LOAD_LAYER()
            },
            success: function (data) {
                if (data.code == 200) {
                    let da = data.body

                    $("#comoutInfo").empty();
                    $("#baseInfo").empty();
                    $("#alarmInfo").empty();
                    $("#flowInfo").empty();
                    $("#limitInfo").empty();


                    let base = da.gdName+" , "+da.scale+da.subName+" , "+da.devName+";"

                    $("#baseInfo").append(base)

                    let offHtml='';
                    if (da.comoutDesc != null) {
                        offHtml = da.devName+"通讯中断"+da.comoutNum+"次,具体如下所示:<br/>"
                        let offArr = da.comoutDesc.split(";")
                        for (let j = 0; j < offArr.length; j++) {
                            let desc = offArr[j] + '<br>'
                            offHtml += desc;
                        }
                    } else {
                        let desc = '[暂无通讯中断信息]'
                        offHtml += desc
                    }
                    $("#comoutInfo").append(offHtml)


                    let alarmHtml = '';
                    if (da.alarmDesc != null) {
                        alarmHtml = da.devName+"告警"+da.alarmNum+"次,具体如下所示:<br/>"
                        let alarmArr = da.alarmDesc.split(";")
                        for (let j = 0; j < alarmArr.length; j++) {
                            let desc = alarmArr[j] + '<br>'
                            alarmHtml += desc;
                        }
                    } else {
                        let desc = '[暂无告警信息]'
                        alarmHtml += desc
                    }
                    $("#alarmInfo").append(alarmHtml)

                    let flowHtml = da.devName+'终端流量已使用 ' + da.flowNum + ' %'
                    $("#flowInfo").append(flowHtml)

                    let limit = da.overLimit == 1 ? "不合格":"合格"
                    let info=''
                    if(da.overLimit == 1){
                        info= "数据完整性 : "+(da.limitValue==null?0:da.limitValue)+" % ["+limit+" ]"
                    }else{
                        info="数据完整性 : ["+limit+" ]";
                    }
                    $("#limitInfo").append(info)

                } else {
                    layer.msg('获取失败', {icon: 2})

                }
                ityzl_CLOSE_LOAD_LAYER(loading)
            }
        })

    }


    $("#export").click(function () {
        if (dataObject != null) {
            if (dataObject.length != 0) {
                let html = '序号,时间,供电公司,变电站,设备名称,数据完整性是否达标,告警事件,中断详情,流量使用率,终端等级,\n'
                let time = formatTime(dataObject[0].timeId,2)
                for (let i = 0; i < dataObject.length; i++) {

                    let overLimit = dataObject[i].overLimit == 1 ?"否":"/";
                    let alarm = dataObject[i].alarmDesc ==null ?"/":dataObject[i].alarmDesc
                    let off =dataObject[i].comoutDesc==null?"/":dataObject[i].comoutDesc
                    let lineGrade =  toChange(dataObject[i].lineGrade)
                    let item =  i+1+",\t\t"+time+ "\t,"+dataObject[i].gdName + "," + dataObject[i].subName + "," + dataObject[i].devName +","+overLimit+","+alarm+","+off+","+dataObject[i].flowNum+","+lineGrade+",\n"
                    html+=item;
                }
                var aaaa = "data:text/csv;charset=utf-8,\ufeff" + html;
                var link = document.createElement("a");
                link.setAttribute("href", aaaa);
                link.setAttribute("download", time+"终端异常详情" + ".csv");
                link.click();




            }
        }

    })

    function toChange(lineGrade) {
        switch (lineGrade){
            case 0: return "极重要";
            case 1: return "重要";
            case 2: return "普通";
            case 3: return "不重要";
            default : return "/"
        }
    }



</script>
</html>
