zengh
2022-05-16 63ad2c3598400370dd7da5534659fd7e768a0a4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
 * @Description: 监测页面的公共方法
 * @Version: 1.0
 * @Author: yangsx
 * @Date: 2019-11-29 09:12:06
 * @LastEditors: yangsx
 * @LastEditTime: 2019-12-13 17:08:09
 */
 
/**
 * @description: 获取时间
 * @param {type}
 * @return:
 * @author: yangsx
 */
 
function currentTime(date) {
  var day = date;
  var Year = 0;
  var Month = 0;
  var Day = 0;
  var Hour = 0;
  var Minute = 0;
  var Second = 0;
  var CurrentDateMap = {
    monthDate: "",
    dayDate: "",
    hourDate: "",
    minuteDate: "",
    secondDate: ""
  };
  var CurrentDate = "";
  //初始化时间
  Year = day.getFullYear();
  Month = day.getMonth() + 1;
  Day = day.getDate();
  Hour = day.getHours();
  Minute = day.getMinutes();
  Second = day.getSeconds();
  CurrentDate = CurrentDate + Year + "-";
  if (Month >= 10) {
    CurrentDate = CurrentDate + Month;
  } else {
    CurrentDate = CurrentDate + "0" + Month;
  }
  CurrentDateMap.monthDate = CurrentDate;
  if (Day >= 10) {
    CurrentDate = CurrentDate + "-" + Day;
  } else {
    CurrentDate = CurrentDate + "-0" + Day;
  }
  CurrentDateMap.dayDate = CurrentDate;
  if (Hour >= 10) {
    CurrentDate += " " + Hour;
  } else {
    CurrentDate += " 0" + Hour;
  }
  CurrentDateMap.hourDate = CurrentDate;
  if (Minute >= 10) {
    CurrentDate = CurrentDate + ":" + Minute;
  } else {
    CurrentDate = CurrentDate + ":0" + Minute;
  }
  CurrentDateMap.minuteDate = CurrentDate;
  if (Second >= 10) {
    CurrentDate = CurrentDate + ":" + Second;
  } else {
    CurrentDate = CurrentDate + ":0" + Second;
  }
  CurrentDateMap.secondDate = CurrentDate;
  return CurrentDateMap;
}
 
/**
 * @description: 获取本周时间区间
 * @param {type}
 * @return:
 * @author: yangsx
 */
function getWeekSL() {
  return (
    currentTime(
      new Date(new Date() - 24 * 60 * 60 * 1000 * (new Date().getDay() - 1))
    ).dayDate + " 00:00:00"
  );
}
/**
 * @description: 获取本月时间区间
 * @param {type}
 * @return:
 * @author: yangsx
 */
function getMonthSL() {
  return currentTime(new Date()).monthDate + "-01 00:00:00";
}
 
/**
 * @description: 更新时间显示
 * @param {type}
 * @return:
 * @author: yangsx
 */
(function upCurrentTime() {
  $("#currentTime").html(currentTime(new Date()).minuteDate);
  setTimeout(function() {
    upCurrentTime();
  }, 1000);
})();
 
/**
 * @description: 点击查询调用的事件
 * @param {void} method 事件函数
 * @return:
 * @author: yangsx
 */
function queryHistoricalData(method) {
  var queryStart = $("#queryStart").val();
  var queryEnd = $("#queryEnd").val();
  method(queryStart, queryEnd);
}
 
//数据查询定时器
var todayTimeout;
/**
 * @description: 当查询时间段为今日时将进行轮询
 * @param {type}
 * @return:
 * @author: yangsx
 */
function todayTimeoutMethod() {
  todayTimeout = setTimeout(function() {
    queryHistoricalData(function(queryStart, queryEnd) {
      getPastData(queryStart, queryEnd);
      todayTimeoutMethod();
    });
  }, 1000 * 60 * 2);
}
 
//快捷选择日,周,月查询
$("#selectInterval span").click(function() {
  $("#selectInterval span").removeClass("active");
  $(this).addClass("active");
  var name = $(this).attr("name");
  var slStartDate = "";
  var slEndDate = currentTime(new Date()).secondDate;
  if (name === "today") {
    slStartDate = currentTime(new Date()).dayDate + " 00:00:00";
  } else if (name === "week") {
    slStartDate = getWeekSL();
  } else if (name === "month") {
    slStartDate = getMonthSL();
  }
  $("#queryStart").val(slStartDate);
  $("#queryEnd").val(slEndDate);
  if (todayTimeout) {
    clearTimeout(todayTimeout);
  }
  if (name === "today") {
    queryHistoricalData(function(queryStart, queryEnd) {
      getPastData(queryStart, queryEnd);
    });
    todayTimeoutMethod();
  } else {
    queryHistoricalData(function(queryStart, queryEnd) {
      getPastData(queryStart, queryEnd);
    });
  }
});
 
//点击查询事件
$("#queryHistorical").click(function() {
  $("#queryReset").removeClass("active");
  $(this).addClass("active");
  queryHistoricalData(function(queryStart, queryEnd) {
    getPastData(queryStart, queryEnd);
  });
});
 
// 点击取消事件(已取消该功能)
$("#queryReset").click(function() {
  $("#queryHistorical").removeClass("active");
  $(this).addClass("active");
});
 
//打开阈值设置界面
$(".historical_data_threshold").click(function() {
  var index = $(this).attr("index");
  var flag = $("#" + index + "").css("display") == "none";
 
  if (flag) {
    $(".threshold_content").hide();
    $("#" + index + "").show(100);
    $("#" + index + " input:nth-child(2)").val(
      $("#" + index + "").attr("minThreshold")
    );
    $("#" + index + " input:nth-child(4)").val(
      $("#" + index + "").attr("maxThreshold")
    );
    $("#" + index + " input:nth-child(2)").bind(
      "input propertychange",
      function() {
        $("#" + index + "").attr("minThreshold", $(this).val());
      }
    );
    $("#" + index + " input:nth-child(4)").bind(
      "input propertychange",
      function() {
        $("#" + index + "").attr("maxThreshold", $(this).val());
      }
    );
  } else {
    $("#" + index + "").hide();
  }
  $(".threshold_content_confirm").unbind();
  $(".threshold_content_confirm").click(function() {
    var minYz = Number($("#" + index + "").attr("minThreshold"));
    var maxYz = Number($("#" + index + "").attr("maxThreshold"));
 
    if (minYz >= maxYz) {
      alert("阈值最小值不能大于等于最大值");
      return;
    }
    $("#" + index + "").hide();
    updateYzByStcdAndField(
      {
        stcd: stcd,
        field: index,
        minYz: minYz,
        maxYz: maxYz
      },
      function(res) {
        queryHistoricalData(function(queryStart, queryEnd) {
          getPastData(queryStart, queryEnd);
        });
      }
    );
  });
});
 
/**
 * @description: 提取图表的 x y 轴坐标
 * @param {map} list 数据集合
 * @param {number} fixed 需要保留的小数点位数
 * @return: x y 轴数据集合
 * @author: yangsx
 */
function getCoordinate(list, fixed) {
  var echartsX = [];
  var echartsY = [];
  for (var i = 0; i < list.length; i++) {
    echartsX.push(list[i].endTime);
    echartsY.push(Number(list[i].value).toFixed(fixed ? fixed : 2));
  }
  return {
    echartsX: echartsX,
    echartsY: echartsY
  };
}
 
/**
 * @description: 解析设置阈值
 * @param {type} obj 数据
 * @return:
 * @author: yangsx
 */
function setThreshold(obj) {
  $("#" + obj.code + "").attr(
    "minThreshold",
    obj.minYz == "notNumber" ? 0 : obj.minYz
  );
  $("#" + obj.code + "").attr(
    "maxThreshold",
    obj.maxYz == "notNumber" ? 1 : obj.maxYz
  );
}
 
//数据导出功能
$("#exportHistorical").click(function() {
  var startTimeE = $("#queryStart").val();
  var endTimeE = $("#queryEnd").val();
  var eleType = $(this).attr("eleType");
  var title = $(this).attr("title");
  layui.use("layer", function() {
    var layer = layui.layer;
    layer.confirm(
      "导出 " + startTimeE + " 至 " + endTimeE + " 的数据!",
      {
        btn: ["是", "否"] //按钮
      },
      function() {
        booleanExcelExportElements(
          {
            stcd: stcd,
            startTime: startTimeE,
            endTime: endTimeE,
            eleType: eleType,
            title: title
          },
          function(res) {
            if (!res.success) {
              layer.msg(res.message);
            } else {
              var excelUrl = excelExportElements(
                "?stcd=" +
                  stcd +
                  "&startTime=" +
                  startTimeE +
                  "&endTime=" +
                  endTimeE +
                  "&eleType=" +
                  eleType +
                  "&title=" +
                  title
              );
              layer.closeAll();
              window.location.href = excelUrl;
            }
          }
        );
      },
      function() {}
    );
  });
});