BackgroundData.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. // import axios from 'axios';
  2. import api from "api/index";
  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: false,
  37. stationID: 'DWK_AGC',
  38. values:'DWK'
  39. },
  40. "NSSFCJSFW.NX_GD_NSSF_XX_XX_XXX_XXX_CI0263": {
  41. stationName: "牛首山风电场",
  42. content: "限电",
  43. createTime: new Date(),
  44. isActive: false,
  45. stationID: 'NSS_AGC',
  46. values:'NSSFCJSFW.NX_GD_NSSF_XX_XX_XXX_XXX_CI0263'
  47. },
  48. "QSFCJSFW.NX_GD_QSF_XX_XX_XXX_XXX_CI0263": {
  49. stationName: "青山风电场",
  50. content: "限电",
  51. createTime: new Date(),
  52. isActive: false,
  53. stationID: 'QS_AGC',
  54. values:'QSFCJSFW.NX_GD_QSF_XX_XX_XXX_XXX_CI0263'
  55. },
  56. "SBQFCJSFW.NX_GD_SBQF_XX_XX_XXX_XXX_CI0263": {
  57. stationName: "星能第六风电场",
  58. content: "限电",
  59. createTime: new Date(),
  60. isActive: false,
  61. stationID: 'XNL_AGC',
  62. values:'SBQFCJSFW.NX_GD_SBQF_XX_XX_XXX_XXX_CI0263'
  63. },
  64. "MHSFCJSFW.NX_GD_MHSF_XX_XX_XXX_XXX_CI0263": {
  65. stationName: "麻黄山风电场",
  66. content: "限电",
  67. createTime: new Date(),
  68. isActive: false,
  69. stationID: 'MHS_AGC',
  70. values:'MHSFCJSFW.NX_GD_MHSF_XX_XX_XXX_XXX_CI0263'
  71. },
  72. "XSFCJSFW.NX_GD_XSF_XX_XX_XXX_XXX_CI0263": {
  73. stationName: "香山风电场",
  74. content: "限电",
  75. createTime: new Date(),
  76. isActive: false,
  77. stationID: 'XS_AGC',
  78. values:'XSFCJSFW.NX_GD_XSF_XX_XX_XXX_XXX_CI0263'
  79. },
  80. "SBQFCJSFW.NX_GD_SBQF_XX_XX_XXX_XXX_CI026X": {
  81. stationName: "牛首山第五风电场",
  82. content: "限电",
  83. createTime: new Date(),
  84. isActive: false,
  85. stationID: 'NW_AGC',
  86. values:'SBQFCJSFW.NX_GD_SBQF_XX_XX_XXX_XXX_CI026X'
  87. },
  88. "SLAGC.NX_GD_QSF_DQ_P1_L1_001_DI0165": {
  89. stationName: "宋堡第六风电场",
  90. content: "限电",
  91. createTime: new Date(),
  92. isActive: false,
  93. stationID: 'QS3_AGC',
  94. values:'SLAGC.NX_GD_QSF_DQ_P1_L1_001_DI0165'
  95. },
  96. };
  97. /* 隐患数据 */
  98. HiddenProblems = new Array();
  99. /* 缺陷数据 */
  100. Defects = new Array();
  101. /* 故障数据 */
  102. Failure = new Array();
  103. /* 事故数据 */
  104. Accidents = new Array();
  105. /* 标记数据 */
  106. Marks = [];
  107. /* 校验区数据 */
  108. checkouts = [];
  109. MarkIndex = 0;
  110. constructor() {
  111. this.refreshTPData = this.refreshTPData.bind(this);
  112. this.onTPMessage = this.onTPMessage.bind(this);
  113. this.refreshAlarmData = this.refreshAlarmData.bind(this);
  114. this.onHiddenProblemsMessage = this.onHiddenProblemsMessage.bind(this);
  115. this.formatDate = this.formatDate.bind(this);
  116. this.onDefectsMessage = this.onDefectsMessage.bind(this);
  117. this.onAccidentsMessage = this.onAccidentsMessage.bind(this);
  118. this.isContains = this.isContains.bind(this);
  119. this.refreshRecommendData = this.refreshRecommendData.bind(this);
  120. this.onRDMessage = this.onRDMessage.bind(this);
  121. this.windturbineControl = this.windturbineControl.bind(this);
  122. this.marking = this.marking.bind(this);
  123. this.removeMarked = this.removeMarked.bind(this);
  124. this.initWinturbineBaseData = this.initWinturbineBaseData.bind(this);
  125. this.refreshTPData();
  126. this.refreshAlarmData();
  127. this.refreshRecommendData();
  128. this.refreshTPTimer = setInterval(this.refreshTPData, 3000);// 标题栏数据
  129. this.refreshAlarmTimer = setInterval(this.refreshAlarmData, 10000);// 报警数据
  130. this.refreshRecommendTimer = setInterval(this.refreshRecommendData, 3000);// 推荐数据
  131. }
  132. /* 数据刷新 */
  133. refreshTPData() {
  134. // http://192.168.10.18:8011/ts
  135. var val = '';
  136. for (var v in this.TopPoint) {
  137. val += this.TopPoint[v].pointTag + ',';
  138. }
  139. // api.refreshData(val).then(this.onTPMessage)
  140. // axios.get(process.env.VUE_APP_ADAPTERURL+`/ts/latest?keys=${val}`)
  141. // .then(this.onTPMessage)
  142. // .catch(err =>
  143. // console.log(err)
  144. // );
  145. }
  146. /* 刷新推荐信息 */
  147. refreshRecommendData() {
  148. var val = '';
  149. for (var v in this.Recommends) {
  150. val += v + ',';
  151. }
  152. // api.refreshData(val).then(this.onRDMessage)
  153. // axios.get(process.env.VUE_APP_ADAPTERURL+`/ts/latest?keys=${val}`)
  154. // .then(this.onRDMessage)
  155. // .catch(err =>
  156. // console.log(err)
  157. // );
  158. }
  159. /* 刷新报警信息 */
  160. refreshAlarmData() {
  161. // http://192.168.10.18:8075/alarm
  162. // 1、读取一天内的所有open的4级custom报警,作为隐患数据ar
  163. var enddt = new Date();
  164. var tm = enddt.getTime();
  165. enddt = new Date(tm + 900000);
  166. var startdt = new Date(tm - 86400000);
  167. // api.getSnap({
  168. // pagenum:'1',
  169. // pagesize:'500',
  170. // category1:'custom',
  171. // isopened:'1',
  172. // starttime:this.formatDate(startdt),
  173. // endtime:this.formatDate(enddt),
  174. // }).then(this.onHiddenProblemsMessage)
  175. // api.getSnap({
  176. // pagenum:'1',
  177. // pagesize:'500',
  178. // category1:'windturbine',
  179. // isopened:'1',
  180. // starttime:this.formatDate(startdt),
  181. // endtime:this.formatDate(enddt),
  182. // }).then(this.onHiddenProblemsMessage)
  183. // api.getSnap({
  184. // pagenum:'1',
  185. // pagesize:'500',
  186. // category1:'SYZ',
  187. // isopened:'1',
  188. // starttime:this.formatDate(startdt),
  189. // endtime:this.formatDate(enddt),
  190. // }).then(this.onHiddenProblemsMessage)
  191. }
  192. /* 获得故障数据 */
  193. onAccidentsMessage(msg) {
  194. if (!msg.data) return;
  195. this.Accidents = new Array();
  196. for (var v in msg.data.records) {
  197. var val = msg.data.records[v];
  198. if (this.isContains(val.alertText, ["跳闸", "开关", "刀闸", "断路器", "合位", "分位"])) {
  199. // todo 暂时隐藏事故报警
  200. //this.Accidents.push(val);
  201. } else {
  202. if (val.rank == "5") {
  203. this.Failure.push(val);
  204. } else {
  205. this.Defects.push(val);
  206. }
  207. }
  208. }
  209. }
  210. /* 获得缺陷数据 */
  211. onDefectsMessage(msg) {
  212. if (!msg.data) return;
  213. this.Defects = new Array();
  214. this.Failure = new Array();
  215. for (var v in msg.data.records) {
  216. var val = msg.data.records[v];
  217. if (val.alertText.indexOf("故障") > 0) {
  218. this.Failure.push(val);
  219. } else {
  220. this.Defects.push(val);
  221. }
  222. }
  223. }
  224. /* 获得隐患数据 */
  225. onHiddenProblemsMessage(msg) {
  226. if (!msg.data) return;
  227. this.HiddenProblems = msg.data.records;
  228. }
  229. /* 获得标题栏数据 */
  230. onTPMessage(msg) {
  231. if (!msg.data) return;
  232. for (var v in this.TopPoint) {
  233. var val = this.TopPoint[v];
  234. val.value = msg.data[val.pointTag].doubleValue;
  235. }
  236. }
  237. /* 获得推荐信息数据 */
  238. onRDMessage(msg) {
  239. if (!msg.data) return;
  240. for (var v in msg.data) {
  241. var isact = false;
  242. if (!msg.data[v].doubleValue) {
  243. isact = msg.data[v].booleanValue
  244. } else {
  245. isact = msg.data[v].doubleValue != 0;
  246. }
  247. if (isact && !this.Recommends[v].isActive) {
  248. this.Recommends[v].createTime = this.formatDate(new Date(), 'YY-MM-DD hh:mm');
  249. }
  250. this.Recommends[v].isActive = isact;
  251. }
  252. }
  253. /* 格式化时间 */
  254. formatDate(time, format = 'YY-MM-DD hh:mm:ss') {
  255. var date = new Date(time);
  256. var year = date.getFullYear(),
  257. month = date.getMonth() + 1,//月份是从0开始的
  258. day = date.getDate(),
  259. hour = date.getHours(),
  260. min = date.getMinutes(),
  261. sec = date.getSeconds();
  262. var preArr = Array.apply(null, Array(10)).map(function (elem, index) {
  263. return '0' + index;
  264. });
  265. var newTime = format.replace(/YY/g, year)
  266. .replace(/MM/g, preArr[month] || month)
  267. .replace(/DD/g, preArr[day] || day)
  268. .replace(/hh/g, preArr[hour] || hour)
  269. .replace(/mm/g, preArr[min] || min)
  270. .replace(/ss/g, preArr[sec] || sec);
  271. return newTime;
  272. }
  273. /* 判断一个字符串中是否包含第二个字符串列表中的字符 */
  274. isContains(str, strs) {
  275. for (var v in strs) {
  276. if (str.indexOf(strs[v]) > 0) {
  277. return true;
  278. }
  279. }
  280. return false;
  281. }
  282. /* 登录 */
  283. // login(uname, psd, action) {
  284. // axios.get(process.env.VUE_APP_API+`/api/user/login?userName=${uname}&psd=${psd}`)
  285. // .then(action)
  286. // .catch(err => action("登录出现错误:" + err.message));
  287. // }
  288. /* 风机控制 */
  289. windturbineControl(windturbines, isLockOrUnlock, automatic, test ,success, error) {
  290. var pairs = {};
  291. for (var ind in windturbines) {
  292. var wb = windturbines[ind];
  293. var ct = {
  294. windturbineId: wb.windturbineId,
  295. stationId: wb.stationId,
  296. projectId: wb.projectId,
  297. modelId: wb.modelId,
  298. controlType: wb.controlType,
  299. lockType: wb.lockType,
  300. userName: automatic?'system_'+this.LoginUser.name:this.LoginUser.name,
  301. userId: this.LoginUser.id,
  302. };
  303. pairs[ct.windturbineId] = ct;
  304. }
  305. api.windturbControl(pairs).then(res =>{
  306. success(res);
  307. })
  308. // axios.post(process.env.VUE_APP_API+`/api/control/send?isLockOrUnlock=${isLockOrUnlock}`, pairs)
  309. // .then(msg => {
  310. // success(msg);
  311. // })
  312. // .catch(err => {
  313. // error(err);
  314. // });
  315. console.log(isLockOrUnlock);
  316. }
  317. /* 系统控制风机,自动下发命令 */
  318. windturbineControlSystem(windturbines) {
  319. var pairs = {};
  320. for (var ind in windturbines) {
  321. var wb = windturbines[ind];
  322. var ct = {
  323. windturbineId: wb.windturbineId,
  324. stationId: wb.stationId,
  325. projectId: wb.projectId,
  326. modelId: wb.modelId,
  327. controlType: wb.controlType,
  328. lockType: wb.lockType,
  329. userName: 'system',
  330. userId: 0,
  331. };
  332. pairs[ct.windturbineId] = ct;
  333. }
  334. let isLockOrUnlock = false
  335. api.windturbControl(pairs).then(res =>{
  336. success(res);
  337. })
  338. // axios.post(process.env.VUE_APP_API+`/api/control/send?isLockOrUnlock=false`, pairs)
  339. // .then(msg => {
  340. // console.log(msg);
  341. // })
  342. // .catch(err => {
  343. // this.showdialog("错误", "风机控制出现错误", err.message);
  344. // console.log(err);
  345. // });
  346. }
  347. /* 标记 */
  348. marking(windturbines) {
  349. for (var v in windturbines) {
  350. ++this.MarkIndex;
  351. this.Marks.push({ title: windturbines[v].windturbineId, id: this.MarkIndex });
  352. }
  353. }
  354. updateMarks(windturbine, value) {
  355. this.Marks.forEach(item => {
  356. if (windturbine.windturbineId === item.title) {
  357. item.value = value
  358. }
  359. })
  360. }
  361. /* 校验区数据 */
  362. checkout(windturbines) {
  363. windturbines.forEach(item => {
  364. item.checkTime = (new Date()).getTime()
  365. if (!this.checkouts.filter(items => items.windturbineId === item.windturbineId)[0]) {
  366. this.checkouts.push(item)
  367. }
  368. })
  369. }
  370. removeCheckouts(mk) {
  371. var indx = -1;
  372. for (var id in this.checkouts) {
  373. if (this.checkouts[id].windturbineId == mk.windturbineId) {
  374. indx = id;
  375. break;
  376. }
  377. }
  378. if (indx < 0) return;
  379. this.checkouts.splice(indx, 1);
  380. }
  381. /* 移除标记 */
  382. removeMarked(mk) {
  383. var indx = -1;
  384. for (var id in this.Marks) {
  385. if (this.Marks[id].id == mk.id) {
  386. indx = id;
  387. break;
  388. }
  389. }
  390. if (indx < 0) return;
  391. this.Marks.splice(indx, 1);
  392. }
  393. /* 获取风机详情页面数据 */
  394. initWinturbineBaseData(info, action) {
  395. api.nitWinturbineBaseData({
  396. thingType: 'windturbine',
  397. thingId: info.windturbineId,
  398. uniformCodes: info.codes,
  399. }).then(res =>{
  400. action(res.data);
  401. }).catch(err => {
  402. console.log(err);
  403. });
  404. // axios.get(process.env.VUE_APP_ADAPTERURL+`/ts/latest?thingType=windturbine&thingId=${info.windturbineId}&uniformCodes=${info.codes}`)
  405. // .then(msg => {
  406. // action(msg.data);
  407. // })
  408. // .catch(err => {
  409. // console.log(err);
  410. // });
  411. }
  412. /* 单例 */
  413. static getInstance() {
  414. if (!BackgroundData.instance) {
  415. BackgroundData.instance = new BackgroundData();
  416. }
  417. return BackgroundData.instance;
  418. }
  419. }