alarmCommon.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. var colors = [
  2. '#C1232B', '#B5C334', '#FCCE10', '#E87C25', '#27727B',
  3. '#FE8463', '#9BCA63', '#FAD860', '#F3A43B', '#60C0DD',
  4. '#D7504B', '#C6E579', '#F4E001', '#F0805A', '#26C0C0'
  5. ];
  6. var gzLevel = ['电网停机', '快速停机', '变桨停机', '安全链停机']; //属于故障的报警级别
  7. //获取条件搜索集合
  8. (function (W) {
  9. function getFilterCondition(beginTime, endTime, dataAreaName, alarmlevel) {
  10. var condition = [];
  11. if (beginTime != null || beginTime != "") {
  12. var contionTimeInfo = new FieldCondition();
  13. contionTimeInfo.field = "alarm_time";
  14. contionTimeInfo.value = beginTime;
  15. contionTimeInfo.method = 4; //>=
  16. condition.push(contionTimeInfo);
  17. }
  18. if (endTime != null || endTime != "") {
  19. var contionTimeInfo = new FieldCondition();
  20. contionTimeInfo.field = "alarm_time";
  21. contionTimeInfo.value = endTime;
  22. contionTimeInfo.method = 5; //<=
  23. condition.push(contionTimeInfo);
  24. }
  25. if (dataAreaName != null && dataAreaName != "*") {
  26. var conditionAreainfo = new FieldCondition();
  27. conditionAreainfo.field = "state1";
  28. if (JSON.stringify(alarmAreaDicName) != "{}") {
  29. conditionAreainfo.value = typeof (alarmAreaDicName[dataAreaName]) == "undefined" ? -1 : alarmAreaDicName[dataAreaName].id;
  30. }
  31. conditionAreainfo.method = 0;
  32. condition.push(conditionAreainfo);
  33. }
  34. if (alarmlevel != null && alarmlevel != "*") {
  35. for (var i = 0; i < alarmlevel.length; i++) {
  36. var conditionLevelInfo = new FieldCondition();
  37. conditionLevelInfo.field = "state0";
  38. if (JSON.stringify(alarmLevelDicName) != "{}") {
  39. conditionLevelInfo.value = alarmLevelDicName[alarmlevel[i]] && alarmLevelDicName[alarmlevel[i]].level; //getAlarmLevelNameByName(alarmlevel);
  40. }
  41. conditionLevelInfo.method = 0;
  42. condition.push(conditionLevelInfo);
  43. }
  44. }
  45. //筛选首出故障
  46. var conditionIsFirstfo = new FieldCondition();
  47. conditionIsFirstfo.field = "is_first";
  48. conditionIsFirstfo.value = 1;
  49. conditionIsFirstfo.method = 0;
  50. condition.push(conditionIsFirstfo);
  51. return condition;
  52. }
  53. //获取报警级别统计数据
  54. function getAlarmLevelChartData(beginTime, endTime, alarmAreaName, chartType, chartName, callback) {
  55. getAlarmGroups(function (data) {
  56. if (!GD.isEmptyObj(data)) {
  57. getAlarmLevelsData(function (levelData) {
  58. if (!GD.isEmptyObj(data)) {
  59. var condition = getFilterCondition(beginTime, endTime, alarmAreaName);
  60. var reqData = {
  61. "method": "GetHistoryCountByLevel",
  62. "param": {
  63. "groupby": "state0",
  64. "condition": condition
  65. }
  66. };
  67. var flag = 'GetHistoryCountByLevel';
  68. var eventName = "/alarm/doservice?" + flag;
  69. socket.alarmPost(eventName, reqData, function (data) {
  70. if (data && data.success) {
  71. var alarmLevelInfos = data.data.data;
  72. if (chartType == "alarmLevelPie") {
  73. //pie图参数
  74. chartName.option.legend.data = [];
  75. chartName.option.series[0].data = [];
  76. } else if (chartType == "alarmLevelBar") {
  77. chartName.option.legend.data = [];
  78. chartName.lables = [];
  79. chartName.option.xAxis[0].data = [];
  80. chartName.option.series[0].data = [];
  81. chartName.option.series[1].data = [];
  82. }
  83. for (key in alarmLevelDic) {
  84. if (key > 10) continue;
  85. if (chartType == "alarmLevelPie") {
  86. chartName.option.legend.data.push(alarmLevelDic[key].level_name);
  87. } else if (chartType == "alarmLevelBar") {
  88. //给柱状图赋值
  89. chartName.lables.push(alarmLevelDic[key].level_name);
  90. chartName.option.legend.data.push(alarmLevelDic[key].level_name);
  91. chartName.option.xAxis[0].data.push(alarmLevelDic[key].level_name);
  92. }
  93. if (alarmLevelInfos.length == 0) {
  94. if (chartType == "alarmLevelPie") {
  95. var obj = new Object();
  96. obj.name = alarmLevelDic[key].level_name;
  97. obj.value = 0;
  98. chartName.option.series[0].data.push(obj);
  99. } else if (chartType == "alarmLevelBar") {
  100. chartName.option.series[1].data.push(0);
  101. }
  102. }
  103. for (var i = 0; i < alarmLevelInfos.length; i++) {
  104. if (chartType == "alarmLevelPie") {
  105. //给pie图赋值
  106. if (key != alarmLevelInfos[i].level_id) {
  107. if (i == alarmLevelInfos.length - 1) {
  108. var obj = new Object();
  109. obj.name = alarmLevelDic[key].level_name;
  110. obj.value = 0;
  111. chartName.option.series[0].data.push(obj);
  112. }
  113. continue;
  114. } else {
  115. var obj = new Object();
  116. obj.name = alarmLevelDic[alarmLevelInfos[i].level_id].level_name;
  117. obj.value = alarmLevelInfos[i].count;
  118. chartName.option.series[0].data.push(obj);
  119. break;
  120. }
  121. } else if (chartType == "alarmLevelBar") {
  122. //给柱状图赋值
  123. if (key != alarmLevelInfos[i].level_id) {
  124. if (i == alarmLevelInfos.length - 1) {
  125. chartName.option.series[1].data.push(0);
  126. }
  127. continue;
  128. } else {
  129. chartName.option.series[1].data.push(alarmLevelInfos[i].count);
  130. break;
  131. }
  132. }
  133. }
  134. }
  135. callback(chartName.option, chartName.lables);
  136. }
  137. })
  138. }
  139. })
  140. }
  141. })
  142. }
  143. //-------------------获取报警组数据绘制图表-------------------------
  144. function getAlarmGroupChartData(beginTime, endTime, alarmAreaName, chartType, chartName, callback) {
  145. getAlarmGroups(function (data) {
  146. if (!GD.isEmptyObj(data)) {
  147. var condition = getFilterCondition(beginTime, endTime, alarmAreaName, gzLevel);
  148. var reqData = {
  149. "method": "GetHistoryCountByType",
  150. "param": {
  151. "groupby": "state2",
  152. "condition": condition
  153. }
  154. };
  155. var flag = "GetHistoryCountByType";
  156. var eventName = "/alarm/doservice?" + flag;
  157. socket.alarmPost(eventName, reqData, function (data) {
  158. if (data && data.success) {
  159. var alarmGroupInfos = data.data.data;
  160. if (chartType == "alarmGroupPie") {
  161. //pie图参数
  162. chartName.option.legend.data = [];
  163. chartName.option.series[0].data = [];
  164. } else if (chartType == "alarmGroupBar") {
  165. chartName.option.legend.data = [];
  166. chartName.lables = [];
  167. chartName.option.xAxis[0].data = [];
  168. chartName.option.series[0].data = [];
  169. chartName.option.series[1].data = [];
  170. }
  171. // console.log(alarmGroupDicName);
  172. // for(var key in alarmGroupDicName){
  173. // for(var i=0;i<alarmGroupInfos.length;i++){
  174. // if(key==alarmGroupInfos[i].type_id){
  175. // alarmGroupInfos[i].group_name=alarmGroupDicName[key].group_name;
  176. // }
  177. // }
  178. // }
  179. // console.log(alarmGroupInfos);
  180. for (var key in alarmGroupDicName) {
  181. if (chartType == "alarmGroupPie") {
  182. chartName.option.legend.data.push(alarmGroupDicName[key].group_name);
  183. } else if (chartType == "alarmGroupBar") {
  184. chartName.lables.push(alarmGroupDicName[key]).group_name;
  185. chartName.option.legend.data.push(alarmGroupDicName[key].group_name);
  186. chartName.option.xAxis[0].data.push(alarmGroupDicName[key].group_name);
  187. }
  188. if (alarmGroupInfos.length == 0) {
  189. if (chartType == "alarmGroupPie") {
  190. var obj = new Object();
  191. obj.name = alarmGroupDicName[key].group_name;
  192. obj.value = 0;
  193. chartName.option.series[0].data.push(obj);
  194. } else if (chartType == "alarmGroupBar") {
  195. chartName.option.series[1].data.push(0);
  196. }
  197. }
  198. for (var i = 0; i < alarmGroupInfos.length; i++) {
  199. if (chartType == "alarmGroupPie") {
  200. //给pie图赋值
  201. if (key != alarmGroupInfos[i].type_id) {
  202. if (i == alarmGroupInfos.length - 1) {
  203. var obj = new Object();
  204. obj.name = alarmGroupDicName[key].group_name;
  205. obj.value = 0;
  206. chartName.option.series[0].data.push(obj);
  207. }
  208. continue;
  209. } else {
  210. var obj = new Object();
  211. obj.name = alarmGroupDicName[alarmGroupInfos[i].type_id].group_name;
  212. obj.value = alarmGroupInfos[i].count
  213. chartName.option.series[0].data.push(obj);
  214. break;
  215. }
  216. } else if (chartType == "alarmGroupBar") {
  217. //给柱状图赋值
  218. if (key != alarmGroupInfos[i].type_id) {
  219. if (i == alarmGroupInfos.length - 1) {
  220. chartName.option.series[1].data.push(0);
  221. }
  222. continue;
  223. } else {
  224. chartName.option.series[1].data.push(alarmGroupInfos[i].count);
  225. break;
  226. }
  227. }
  228. }
  229. }
  230. }
  231. callback(chartName.option, chartName.lables);
  232. })
  233. }
  234. })
  235. }
  236. W.getAlarmGroupChartData = getAlarmGroupChartData;
  237. W.getAlarmLevelChartData = getAlarmLevelChartData;
  238. })(window);