BackgroundData.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. import axios from 'axios';
  2. import { config } from '../../config';
  3. export default class BackgroundData {
  4. /* 当前登录用户 */
  5. LoginUser;
  6. /* 标题栏数据 */
  7. TopPoint = [
  8. {
  9. pointName: "TotalPower",// 实时总功率
  10. pointTag: "JSFW.NX_GD_XXX_XX_XX_XXX_XXX_CI0135",
  11. value: 0
  12. }, {
  13. pointName: "DailyPowerGeneration",// 日发电量
  14. pointTag: "JSFW.NX_GD_XXX_XX_XX_XXX_XXX_CI0088",
  15. value: 0
  16. }, {
  17. pointName: "GridPower",// 上网电量
  18. pointTag: "JSFW.NX_GD_XXX_XX_XX_XXX_XXX_CI0136",
  19. value: 0
  20. }, {
  21. pointName: "MonthlyPowerGeneration",// 月发电量
  22. pointTag: "JSFW.NX_GD_XXX_XX_XX_XXX_XXX_CI0146",
  23. value: 0
  24. }, {
  25. pointName: "AnnualPowerGeneration",// 年发电量
  26. pointTag: "JSFW.NX_GD_XXX_XX_XX_XXX_XXX_CI0037",
  27. value: 0
  28. },
  29. ];
  30. /* 推荐区数据 */
  31. Recommends = {
  32. "DWK": {
  33. stationName: "大武口光伏电站",
  34. content: "通讯中断",
  35. createTime: this.formatDate(new Date("2021-04-15 8:17:59"), 'YY-MM-DD hh:mm'),
  36. isActive: true,
  37. },
  38. "NSSFCJSFW.NX_GD_NSSF_XX_XX_XXX_XXX_CI0263": {
  39. stationName: "牛首山风电场",
  40. content: "限电",
  41. createTime: new Date(),
  42. isActive: false,
  43. },
  44. "QSFCJSFW.NX_GD_QSF_XX_XX_XXX_XXX_CI0263": {
  45. stationName: "青山风电场",
  46. content: "限电",
  47. createTime: new Date(),
  48. isActive: false,
  49. },
  50. "SBQFCJSFW.NX_GD_SBQF_XX_XX_XXX_XXX_CI0263": {
  51. stationName: "石板泉一期",
  52. content: "限电",
  53. createTime: new Date(),
  54. isActive: false,
  55. },
  56. "MHSFCJSFW.NX_GD_MHSF_XX_XX_XXX_XXX_CI0263": {
  57. stationName: "麻黄山风电场",
  58. content: "限电",
  59. createTime: new Date(),
  60. isActive: false,
  61. },
  62. "XSFCJSFW.NX_GD_XSF_XX_XX_XXX_XXX_CI0263": {
  63. stationName: "香山风电场",
  64. content: "限电",
  65. createTime: new Date(),
  66. isActive: false,
  67. },
  68. "SLAGC.NX_GD_QSF_DQ_P1_L1_001_DI0165": {
  69. stationName: "青山三期",
  70. content: "限电",
  71. createTime: new Date(),
  72. isActive: false,
  73. },
  74. "SBQFCJSFW.NX_GD_SBQF_XX_XX_XXX_XXX_CI026X": {
  75. stationName: "石板泉二三四期",
  76. content: "限电",
  77. createTime: new Date(),
  78. isActive: false,
  79. },
  80. };
  81. /* 隐患数据 */
  82. HiddenProblems = new Array();
  83. /* 缺陷数据 */
  84. Defects = new Array();
  85. /* 故障数据 */
  86. Failure = new Array();
  87. /* 事故数据 */
  88. Accidents = new Array();
  89. /* 标记数据 */
  90. Marks=[{title:"QG01_01",value:"温度过高"}];
  91. constructor() {
  92. this.refreshTPData = this.refreshTPData.bind(this);
  93. this.onTPMessage = this.onTPMessage.bind(this);
  94. this.refreshAlarmData = this.refreshAlarmData.bind(this);
  95. this.onHiddenProblemsMessage = this.onHiddenProblemsMessage.bind(this);
  96. this.formatDate = this.formatDate.bind(this);
  97. this.onDefectsMessage = this.onDefectsMessage.bind(this);
  98. this.onAccidentsMessage = this.onAccidentsMessage.bind(this);
  99. this.isContains = this.isContains.bind(this);
  100. this.refreshRecommendData = this.refreshRecommendData.bind(this);
  101. this.onRDMessage = this.onRDMessage.bind(this);
  102. this.showdialog = this.showdialog.bind(this);
  103. this.windturbineControl=this.windturbineControl.bind(this);
  104. this.marking=this.marking.bind(this);
  105. this.refreshTPData();
  106. this.refreshAlarmData();
  107. this.refreshRecommendData();
  108. this.refreshTPTimer = setInterval(this.refreshTPData, 3000);// 标题栏数据
  109. this.refreshAlarmTimer = setInterval(this.refreshAlarmData, 10000);// 报警数据
  110. this.refreshRecommendTimer = setInterval(this.refreshRecommendData, 3000);// 推荐数据
  111. }
  112. /* 数据刷新 */
  113. refreshTPData() {
  114. // http://192.168.10.18:8011/ts
  115. var val = '';
  116. for (var v in this.TopPoint) {
  117. val += this.TopPoint[v].pointTag + ',';
  118. }
  119. axios.get(`http://${config.adapterUrl}/ts/latest?keys=${val}`)
  120. .then(this.onTPMessage)
  121. .catch(err =>
  122. console.log(err)
  123. );
  124. }
  125. /* 刷新推荐信息 */
  126. refreshRecommendData() {
  127. var val = '';
  128. for (var v in this.Recommends) {
  129. val += v + ',';
  130. }
  131. axios.get(`http://${config.adapterUrl}/ts/latest?keys=${val}`)
  132. .then(this.onRDMessage)
  133. .catch(err =>
  134. console.log(err)
  135. );
  136. }
  137. /* 刷新报警信息 */
  138. refreshAlarmData() {
  139. // http://192.168.10.18:8075/alarm
  140. // 1、读取一天内的所有open的4级custom报警,作为隐患数据ar
  141. var enddt = new Date();
  142. var tm = enddt.getTime();
  143. enddt = new Date(tm + 900000);
  144. var startdt = new Date(tm - 86400000);
  145. axios.get(`http://${config.shardingUrl}/alarm/snap/page?pagenum=1&pagesize=500&category1=custom&rank=4&isopened=1&starttime=${this.formatDate(startdt)}&endtime=${this.formatDate(enddt)}`)
  146. .then(this.onHiddenProblemsMessage)
  147. .catch(err =>
  148. console.log(err)
  149. );
  150. // 2、读取一天内所有的open的windturbine报警,以故障结尾的报警填充到故障,其他的填充到缺陷
  151. axios.get(`http://${config.shardingUrl}/alarm/snap/page?pagenum=1&pagesize=500&category1=windturbine&isopened=1&starttime=${this.formatDate(startdt)}&endtime=${this.formatDate(enddt)}`)
  152. .then(this.onDefectsMessage)
  153. .catch(err =>
  154. console.log(err)
  155. );
  156. // 3、读取一天内所有open的升压站(SYZ)报警,包含关键字“跳闸”,“开关”,“刀闸”,“断路器”字符的报警信息填充到事故列表
  157. axios.get(`http://${config.shardingUrl}/alarm/snap/page?pagenum=1&pagesize=500&category1=SYZ&isopened=1&starttime=${this.formatDate(startdt)}&endtime=${this.formatDate(enddt)}`)
  158. .then(this.onAccidentsMessage)
  159. .catch(err =>
  160. console.log(err)
  161. );
  162. }
  163. /* 获得故障数据 */
  164. onAccidentsMessage(msg) {
  165. if (!msg.data) return;
  166. this.Accidents = new Array();
  167. for (var v in msg.data.records) {
  168. var val = msg.data.records[v];
  169. if (this.isContains(val.alertText, ["跳闸", "开关", "刀闸", "断路器", "合位", "分位"])) {
  170. this.Accidents.push(val);
  171. } else {
  172. if (val.rank == "5") {
  173. this.Failure.push(val);
  174. } else {
  175. this.Defects.push(val);
  176. }
  177. }
  178. }
  179. }
  180. /* 获得缺陷数据 */
  181. onDefectsMessage(msg) {
  182. if (!msg.data) return;
  183. this.Defects = new Array();
  184. this.Failure = new Array();
  185. for (var v in msg.data.records) {
  186. var val = msg.data.records[v];
  187. if (val.alertText.indexOf("故障") > 0) {
  188. this.Failure.push(val);
  189. } else {
  190. this.Defects.push(val);
  191. }
  192. }
  193. }
  194. /* 获得隐患数据 */
  195. onHiddenProblemsMessage(msg) {
  196. if (!msg.data) return;
  197. this.HiddenProblems = msg.data.records;
  198. }
  199. /* 获得标题栏数据 */
  200. onTPMessage(msg) {
  201. if (!msg.data) return;
  202. for (var v in this.TopPoint) {
  203. var val = this.TopPoint[v];
  204. val.value = msg.data[val.pointTag].doubleValue;
  205. }
  206. }
  207. /* 获得推荐信息数据 */
  208. onRDMessage(msg) {
  209. if (!msg.data) return;
  210. for (var v in msg.data) {
  211. var isact = false;
  212. if (!msg.data[v].doubleValue) {
  213. isact = msg.data[v].booleanValue
  214. } else {
  215. isact = msg.data[v].doubleValue != 0;
  216. }
  217. if (isact && !this.Recommends[v].isActive) {
  218. this.Recommends[v].createTime = this.formatDate(new Date(), 'YY-MM-DD hh:mm');
  219. }
  220. this.Recommends[v].isActive = isact;
  221. }
  222. }
  223. /* 格式化时间 */
  224. formatDate(time, format = 'YY-MM-DD hh:mm:ss') {
  225. var date = new Date(time);
  226. var year = date.getFullYear(),
  227. month = date.getMonth() + 1,//月份是从0开始的
  228. day = date.getDate(),
  229. hour = date.getHours(),
  230. min = date.getMinutes(),
  231. sec = date.getSeconds();
  232. var preArr = Array.apply(null, Array(10)).map(function (elem, index) {
  233. return '0' + index;
  234. });
  235. var newTime = format.replace(/YY/g, year)
  236. .replace(/MM/g, preArr[month] || month)
  237. .replace(/DD/g, preArr[day] || day)
  238. .replace(/hh/g, preArr[hour] || hour)
  239. .replace(/mm/g, preArr[min] || min)
  240. .replace(/ss/g, preArr[sec] || sec);
  241. return newTime;
  242. }
  243. /* 判断一个字符串中是否包含第二个字符串列表中的字符 */
  244. isContains(str, strs) {
  245. for (var v in strs) {
  246. if (str.indexOf(strs[v]) > 0) {
  247. return true;
  248. }
  249. }
  250. return false;
  251. }
  252. login(uname, psd, action) {
  253. axios.get(`http://${config.calcUrl}/user/login?userName=${uname}&psd=${psd}`)
  254. .then(action)
  255. .catch(err => action("登录出现错误:"+err.message));
  256. }
  257. /* 显示提示框 */
  258. showdialog(title,message,detail) {
  259. const { remote } = require("electron");
  260. const { dialog } = remote;
  261. dialog.showMessageBox(remote.getCurrentWindow(), {
  262. type: "none",
  263. title: title,
  264. message: message,
  265. detail: detail,
  266. buttons: ["确定"],
  267. noLink: true,
  268. });
  269. }
  270. /* 风机控制 */
  271. windturbineControl(windturbines){
  272. console.log(windturbines);
  273. }
  274. marking(windturbines){
  275. for(var v in windturbines){
  276. this.Marks.push({title:windturbines[v].windturbineId});
  277. }
  278. }
  279. /* 单例 */
  280. static getInstance() {
  281. if (!BackgroundData.instance) {
  282. BackgroundData.instance = new BackgroundData();
  283. }
  284. return BackgroundData.instance;
  285. }
  286. }