configurable.api.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. import { floor, isArray, random, slice } from 'lodash-es';
  2. import { defHttp } from '/@/utils/http/axios';
  3. import { get } from '../billboard/utils';
  4. import { useGlobSetting } from '/@/hooks/setting';
  5. import { ref, reactive } from 'vue'
  6. enum Api {
  7. list = '/safety/ventanalyDevice/homedata2',
  8. getHomeData = '/safety/ventanalyDevice/homedata',
  9. getDisHome = '/monitor/disaster/getDisHome',
  10. getBDDustData = '/monitor/disaster/getDisDustHome',
  11. getBDFireData = '/monitor/disaster/getDisFireHome',
  12. getDeviceSys = '/ventanaly-device/monitor/getSysFireHomeInfo',
  13. getAlarmRecord = '/ventanaly-device/safety/ventanalyAlarmLog/sysLinkDevAlarmLog',
  14. getTotal = '/safety/ventanalyAlarmLog/total',
  15. sysTypeWarnList = '/safety/ventanalyAlarmLog/sysTypeWarn',
  16. getDisasterProportion = '/safety/ventanalyAlarmLog/getDisasterProportion'
  17. }
  18. // 搞这个缓存是由于:目前代码上的设计是多个模块发出多次请求,每个模块自己负责消费前者的响应。
  19. // 这会导致相同的请求被同时发送多次。
  20. const cache = new Map<string, Promise<any>>();
  21. /**
  22. * 列表接口,5.5专用,和6.0的getHomeData基本一致
  23. * @param params
  24. */
  25. export const list = (params) => {
  26. const key = `${Api.list}?${JSON.stringify(params)}`;
  27. if (!cache.has(key)) {
  28. cache.set(
  29. key,
  30. defHttp.post({ url: Api.list, params }).finally(() => {
  31. cache.delete(key);
  32. })
  33. );
  34. }
  35. return (cache.get(key) as Promise<any>).then((res) => {
  36. if (res.fanmain) {
  37. // 处理频率字段,为了兼容旧版保留,现配置项已支持一级动态字段
  38. res.fanmain.forEach((e) => {
  39. if (e.readData.Fan2StartStatus === '1') {
  40. e.current = '二号';
  41. e.readData.FanFreqHz = e.readData.Fan2FreqHz;
  42. } else {
  43. e.current = '一号';
  44. e.readData.FanFreqHz = e.readData.Fan1FreqHz;
  45. }
  46. });
  47. }
  48. if (res.fanlocal) {
  49. res.fanlocal.forEach((e) => {
  50. e.chartData = [
  51. {
  52. x: '吸风量',
  53. yRealtime: e.readData.windQuantity1,
  54. yMock: floor(parseFloat(e.inletAirVolume_merge) * random(0.98, 1, false), 2),
  55. y: e.inletAirVolume_merge,
  56. },
  57. {
  58. x: '供风量',
  59. yRealtime: e.readData.windQuantity2,
  60. yMock: floor(parseFloat(e.ductOutletAirVolume_merge) * random(0.98, 1, false), 2),
  61. y: e.ductOutletAirVolume_merge,
  62. },
  63. ];
  64. if (e.readData.Fan2StartStatus === '1') {
  65. e.current = '二号';
  66. e.readData.FanfHz = e.readData.Fan2fHz;
  67. } else {
  68. e.current = '一号';
  69. e.readData.FanfHz = e.readData.Fan1fHz;
  70. }
  71. });
  72. }
  73. if (res.sys_majorpath) {
  74. res.sys_majorpath.forEach((e) => {
  75. const { drag_1, drag_2, drag_3, drag_total } = e.majorpath;
  76. const { fy_merge = { value: '1' } } = e.readData;
  77. const drag_merge = parseInt(fy_merge.value);
  78. // const m3_merge = parseInt(retM3_merge.value);
  79. e.piechart = [
  80. { val: drag_1, valMock: floor((drag_1 / drag_total) * drag_merge), label: '进风区(Pa)' },
  81. { val: drag_2, valMock: floor((drag_2 / drag_total) * drag_merge), label: '用风区(Pa)' },
  82. { val: drag_3, valMock: floor((drag_3 / drag_total) * drag_merge), label: '回风区(Pa)' },
  83. ];
  84. e.readData.dengjikong_merge = get(res, 'midinfo[0].sysinfo.equalarea');
  85. e.readData.fy_merge_int = drag_merge;
  86. // e.dengjikong_merge = floor((1.19 * (m3_merge / 60)) / Math.sqrt(drag_merge), 2);
  87. });
  88. }
  89. if (res.sys_surface_caimei) {
  90. res.sys_surface_caimei.forEach((e) => {
  91. if (isArray(e.history)) {
  92. e.history = slice(e.history, e.history.length - 30, e.history.length);
  93. }
  94. if (isArray(e.history_report)) {
  95. e.history_report = slice(e.history_report, e.history_report.length - 30, e.history_report.length);
  96. }
  97. });
  98. }
  99. if (res.device_arr) {
  100. res.device_arr = Object.values(res.device);
  101. }
  102. if (res.sys_wind) {
  103. res.sys_wind.forEach((e) => {
  104. if (e.readData.m3) {
  105. e.readData.m3 = e.readData.m3.replace('-', '');
  106. }
  107. if (e.readData.va) {
  108. e.readData.va = e.readData.va.replace('-', '');
  109. }
  110. });
  111. }
  112. if (res.windrect) {
  113. res.windrect.forEach((e) => {
  114. if (e.readData.m3) {
  115. e.readData.m3 = e.readData.m3.replace('-', '');
  116. }
  117. if (e.readData.va) {
  118. e.readData.va = e.readData.va.replace('-', '');
  119. }
  120. });
  121. }
  122. return res;
  123. });
  124. };
  125. export const getHomeData = (params) => {
  126. const key = `${Api.getHomeData}?${JSON.stringify(params)}`;
  127. if (!cache.has(key)) {
  128. cache.set(
  129. key,
  130. defHttp.post({ url: Api.getHomeData, params }).finally(() => {
  131. cache.delete(key);
  132. })
  133. );
  134. }
  135. return (cache.get(key) as Promise<any>).then((res) => {
  136. res.fanmain.forEach((e) => {
  137. if (e.readData.Fan2StartStatus === '1') {
  138. e.current = '二号';
  139. e.readData.FanFreqHz = e.readData.Fan2FreqHz;
  140. } else {
  141. e.current = '一号';
  142. e.readData.FanFreqHz = e.readData.Fan1FreqHz;
  143. }
  144. });
  145. res.fanlocal.forEach((e) => {
  146. e.chartData = [
  147. {
  148. x: '吸风量',
  149. y: e.readData.windQuantity1,
  150. },
  151. {
  152. x: '供风量',
  153. y: e.readData.windQuantity2,
  154. },
  155. ];
  156. if (e.readData.Fan2StartStatus === '1') {
  157. e.current = '二号';
  158. e.readData.FanfHz = e.readData.Fan2fHz;
  159. } else {
  160. e.current = '一号';
  161. e.readData.FanfHz = e.readData.Fan1fHz;
  162. }
  163. });
  164. res.sys_majorpath.forEach((e) => {
  165. e.piechart = [
  166. { val: e.majorpath.drag_1, label: '进风区' },
  167. { val: e.majorpath.drag_2, label: '用风区' },
  168. { val: e.majorpath.drag_3, label: '回风区' },
  169. ];
  170. });
  171. return res;
  172. });
  173. };
  174. export const getBDDustData = (params) => {
  175. const key = `${Api.getBDDustData}?${JSON.stringify(params)}`;
  176. if (!cache.has(key)) {
  177. cache.set(
  178. key,
  179. defHttp.post({ url: Api.getBDDustData, params }).finally(() => {
  180. cache.delete(key);
  181. })
  182. );
  183. }
  184. return cache.get(key) as Promise<any>;
  185. };
  186. export const getBDFireData = (params) => {
  187. const key = `${Api.getBDFireData}?${JSON.stringify(params)}`;
  188. if (!cache.has(key)) {
  189. cache.set(
  190. key,
  191. defHttp.post({ url: Api.getBDFireData, params }).finally(() => {
  192. cache.delete(key);
  193. })
  194. );
  195. }
  196. return (cache.get(key) as Promise<any>).then((res) => {
  197. res.pdArray.forEach((e) => {
  198. e.arrayFiber.forEach((j) => {
  199. j.fibreTemperatureArr = JSON.parse(j.fibreTemperature);
  200. });
  201. });
  202. res.sgGxObj.devGxcw.forEach((e) => {
  203. e.fibreTemperatureArr = JSON.parse(e.fibreTemperature);
  204. });
  205. res.sgGxObj.devSgjc.forEach((e) => {
  206. e.o2val = e.o2Val || 0;
  207. e.coval = e.coVal || 0;
  208. e.gasval = e.gasVal || 0;
  209. e.ch2val = e.ch2Val || 0;
  210. e.chval = e.chVal || 0;
  211. });
  212. return res;
  213. });
  214. };
  215. // 塔山火灾预警页面获取数据接口
  216. export const getDeviceSys = (params) => {
  217. const key = `${Api.getDeviceSys}?${JSON.stringify(params)}`;
  218. if (!cache.has(key)) {
  219. cache.set(
  220. key,
  221. defHttp.post({ url: Api.getDeviceSys, params }).finally(() => {
  222. cache.delete(key);
  223. })
  224. );
  225. }
  226. return (cache.get(key) as Promise<any>).then((res) => {
  227. return res;
  228. });
  229. };
  230. export const getAlarmRecord = (params) => {
  231. const key = `${Api.getAlarmRecord}?${JSON.stringify(params)}`;
  232. if (!cache.has(key)) {
  233. cache.set(
  234. key,
  235. defHttp.post({ url: Api.getAlarmRecord, params }).finally(() => {
  236. cache.delete(key);
  237. })
  238. );
  239. }
  240. return (cache.get(key) as Promise<any>).then((res) => {
  241. return res;
  242. });
  243. };
  244. export const getDisHome = (params) => {
  245. const key = `${Api.getDisHome}?${JSON.stringify(params)}`;
  246. if (!cache.has(key)) {
  247. cache.set(
  248. key,
  249. defHttp.post({ url: Api.getDisHome, params }).finally(() => {
  250. cache.delete(key);
  251. })
  252. );
  253. }
  254. return (cache.get(key) as Promise<any>).then((res) => {
  255. if (res.pdArray) {
  256. res.pdArray.forEach((e) => {
  257. e.arrayFiber.forEach((j) => {
  258. j.fibreTemperatureArr = JSON.parse(j.fibreTemperature);
  259. });
  260. });
  261. }
  262. if (res.sgGxObj) {
  263. res.sgGxObj.devGxcw.forEach((e) => {
  264. e.fibreTemperatureArr = JSON.parse(e.fibreTemperature);
  265. });
  266. res.sgGxObj.devSgjc.forEach((e) => {
  267. e.o2val = e.o2Val || 0;
  268. e.coval = e.coVal || 0;
  269. e.gasval = e.gasVal || 0;
  270. e.ch2val = e.ch2Val || 0;
  271. e.chval = e.chVal || 0;
  272. });
  273. }
  274. if (res.obfObj) {
  275. res.obfObj.obfObjModded = [
  276. {
  277. objType: '氧气',
  278. arrayDev: res.obfObj.arrayDev.map((e) => {
  279. return {
  280. strinstallpos: e.strinstallpos,
  281. val: e.o2Val || 0,
  282. };
  283. }),
  284. },
  285. {
  286. objType: '甲烷',
  287. arrayDev: res.obfObj.arrayDev.map((e) => {
  288. return {
  289. strinstallpos: e.strinstallpos,
  290. val: e.ch4Val || 0,
  291. };
  292. }),
  293. },
  294. {
  295. objType: '一氧化碳',
  296. arrayDev: res.obfObj.arrayDev.map((e) => {
  297. return {
  298. strinstallpos: e.strinstallpos,
  299. val: e.coVal || 0,
  300. };
  301. }),
  302. },
  303. {
  304. objType: '乙炔',
  305. arrayDev: res.obfObj.arrayDev.map((e) => {
  306. return {
  307. strinstallpos: e.strinstallpos,
  308. val: e.c2h2Val || 0,
  309. };
  310. }),
  311. },
  312. {
  313. objType: '二氧化碳',
  314. arrayDev: res.obfObj.arrayDev.map((e) => {
  315. return {
  316. strinstallpos: e.strinstallpos,
  317. val: e.co2Val || 0,
  318. };
  319. }),
  320. },
  321. {
  322. objType: '乙烯',
  323. arrayDev: res.obfObj.arrayDev.map((e) => {
  324. return {
  325. strinstallpos: e.strinstallpos,
  326. val: e.c2h4Val || 0,
  327. };
  328. }),
  329. },
  330. {
  331. objType: '压差',
  332. arrayDev: res.obfObj.arrayDev.map((e) => {
  333. return {
  334. strinstallpos: e.strinstallpos,
  335. val: e.dpVal || 0,
  336. };
  337. }),
  338. },
  339. {
  340. objType: '温度',
  341. arrayDev: res.obfObj.arrayDev.map((e) => {
  342. return {
  343. strinstallpos: e.strinstallpos,
  344. val: e.tempVal || 0,
  345. };
  346. }),
  347. },
  348. ];
  349. }
  350. return res;
  351. });
  352. };
  353. //获取通风监测预警图表数据
  354. export const sysTypeWarnList = (params) => {
  355. const key = `${Api.sysTypeWarnList}?${JSON.stringify(params)}`;
  356. if (!cache.has(key)) {
  357. cache.set(
  358. key,
  359. defHttp.post({ url: Api.sysTypeWarnList, params }).finally(() => {
  360. cache.delete(key);
  361. })
  362. );
  363. }
  364. return (cache.get(key) as Promise<any>).then((res) => {
  365. return res;
  366. });
  367. };
  368. //获取多灾融合预警-风险权重比例数据
  369. export const getDisasterProportion = (params) => {
  370. const key = `${Api.getDisasterProportion}?${JSON.stringify(params)}`;
  371. if (!cache.has(key)) {
  372. cache.set(
  373. key,
  374. defHttp.post({ url: Api.getDisasterProportion, params }).finally(() => {
  375. cache.delete(key);
  376. })
  377. );
  378. }
  379. return (cache.get(key) as Promise<any>).then((res) => {
  380. return res;
  381. });
  382. };
  383. //多灾融合预警
  384. function getLevelNum() {
  385. return new Promise(async (resolve) => {
  386. const list = {}
  387. const typeArr = ['fire', 'dust', 'vent', 'gas'];
  388. for (let i = 0; i < typeArr.length; i++) {
  389. const type = typeArr[i];
  390. const result = await sysTypeWarnList({ type });
  391. if (type == 'fire') {
  392. list.fire = result.length || 0
  393. } else if (type == 'dust') {
  394. list.dust = result.length || 0
  395. } else if (type == 'vent') {
  396. list.vent = result.length || 0
  397. } else if (type == 'gas') {
  398. list.gas = result.length || 0
  399. }
  400. }
  401. resolve(list);
  402. });
  403. }
  404. export const getTotal = (params) => {
  405. const { sysOrgCode, sysDataType } = useGlobSetting();
  406. const key = `${Api.getTotal}?${JSON.stringify(params)}`;
  407. if (!cache.has(key)) {
  408. cache.set(
  409. key,
  410. defHttp.get({ url: Api.getTotal, params }).finally(() => {
  411. cache.delete(key);
  412. })
  413. );
  414. }
  415. return (cache.get(key) as Promise<any>).then(async (res) => {
  416. console.log(res, '多灾融合预警数据')
  417. let dataVent=await getLevelNum()
  418. const levelsList = [
  419. {
  420. name: "报警",
  421. value: 0
  422. },
  423. {
  424. name: "重大风险",
  425. value: 0
  426. },
  427. {
  428. name: "较大风险",
  429. value: 0
  430. },
  431. {
  432. name: "一般风险",
  433. value: 0
  434. },
  435. {
  436. name: "低风险",
  437. value: dataVent.vent || 0
  438. },
  439. ];
  440. //通风监测预警数据
  441. switch (sysDataType) {
  442. case 'monitor':
  443. res.ventWarn = {
  444. ventJf: res.ventInfo.zongjinfeng,
  445. ventXf: res.ventInfo.xufengliang,
  446. ventHf: res.ventInfo.zonghuifeng,
  447. }
  448. res.ventData = [
  449. {
  450. name: "报警",
  451. value: res.info.sysInfo.ventS.levels.alarm
  452. },
  453. {
  454. name: "重大风险",
  455. value: res.info.sysInfo.ventS.levels.red
  456. },
  457. {
  458. name: "较大风险",
  459. value: res.info.sysInfo.ventS.levels.orange
  460. },
  461. {
  462. name: "一般风险",
  463. value: res.info.sysInfo.ventS.levels.yellow
  464. },
  465. {
  466. name: "低风险",
  467. value: dataVent.vent ? dataVent.vent : res.info.sysInfo.ventS.levels.blue
  468. },
  469. ];
  470. break;
  471. case 'report':
  472. res.ventWarn = {
  473. ventJf: res.ventInfo.totalIntM3,
  474. ventXf: res.ventInfo.xufengliang,
  475. ventHf: res.ventInfo.totalRetM3,
  476. }
  477. res.ventData = levelsList
  478. break;
  479. default:
  480. res.ventWarn = {
  481. ventJf: res.ventInfo.totalIntM3,
  482. ventXf: res.ventInfo.xufengliang,
  483. ventHf: res.ventInfo.totalRetM3,
  484. }
  485. res.ventData = levelsList
  486. }
  487. //设备监测预警数据
  488. res.deviceWarn = reactive({})
  489. Object.keys(res.info.devicekindInfo).forEach((el, index) => {
  490. res.deviceWarn[`${el}_all`] = res.info.devicekindInfo[el].totalcount;
  491. res.deviceWarn[`${el}_warn`] = res.info.devicekindInfo[el].count;
  492. res.deviceWarn[`${el}_close`] = res.info.devicekindInfo[el].netstatus;
  493. })
  494. //瓦斯监测预警数据
  495. res.gasData = reactive({})
  496. res.gasData.safety_sum = res.info.sysInfo.gasS.devices.reduce((a, b) => a + b.gasNumber, 0)
  497. res.gasData.gas_sum = res.info.sysInfo.gasS.devices.reduce((a, b) => a + b.pumpNumber, 0)
  498. res.gasData.monitorData = res.info.sysInfo.gasS.devices.map(el => {
  499. return {
  500. label: el.systemname,
  501. value: el.gasNumber,
  502. value1: el.pumpNumber
  503. }
  504. })
  505. //火灾监测预警数据
  506. res.fireInfos = reactive({})
  507. res.fireInfos.dataOn = []
  508. if (res.bundletubeInfo && res.bundletubeInfo.msgTxt.length != 0 && res.bundletubeInfo.msgTxt[0].datalist.length != 0) {
  509. res.bundletubeInfo.msgTxt[0].datalist.forEach((el, ind) => {
  510. res.fireInfos.dataOn.push({
  511. warnLevel: el.syswarnLevel_str,
  512. smokeJd: el.syswarnLevel_des,
  513. value1: el.strinstallpos,
  514. });
  515. });
  516. } else {
  517. res.fireInfos.dataOn = []
  518. }
  519. res.fireInfos.tempVal = res.info.sysInfo.fireS.summaryInfo
  520. ? res.info.sysInfo.fireS.summaryInfo.external.temperature && res.info.sysInfo.fireS.summaryInfo.external.temperature.maxlevel == '0'
  521. ? '低风险'
  522. : '低风险'
  523. : '';
  524. res.fireInfos.smokeVal = res.info.sysInfo.fireS.summaryInfo
  525. ? res.info.sysInfo.fireS.summaryInfo.external.smokeval &&
  526. res.info.sysInfo.fireS.summaryInfo.external.smokeval.maxlevel &&
  527. res.info.sysInfo.fireS.summaryInfo.external.smokeval.maxlevel == '0'
  528. ? '低风险'
  529. : '低风险'
  530. : '';
  531. res.fireInfos.fireVal = res.info.sysInfo.fireS.summaryInfo
  532. ? res.info.sysInfo.fireS.summaryInfo.external.fireval &&
  533. res.info.sysInfo.fireS.summaryInfo.external.fireval.maxlevel &&
  534. res.info.sysInfo.fireS.summaryInfo.external.fireval.maxlevel == '0'
  535. ? '低风险'
  536. : '低风险'
  537. : '';
  538. res.fireInfos.coVal = res.info.sysInfo.fireS.summaryInfo
  539. ? res.info.sysInfo.fireS.summaryInfo.external.coval && res.info.sysInfo.fireS.summaryInfo.external.coval.value
  540. ? res.info.sysInfo.fireS.summaryInfo.external.coval.value
  541. : '-'
  542. : '';
  543. //粉尘监测预警数据
  544. res.dustInfo = [
  545. {
  546. name: "报警",
  547. value: res.info.sysInfo.dustS.levels.alarm
  548. },
  549. {
  550. name: "重大风险",
  551. value: res.info.sysInfo.dustS.levels.red
  552. },
  553. {
  554. name: "较大风险",
  555. value: res.info.sysInfo.dustS.levels.orange
  556. },
  557. {
  558. name: "一般风险",
  559. value: res.info.sysInfo.dustS.levels.yellow
  560. },
  561. {
  562. name: "低风险",
  563. value: dataVent.dust ? dataVent.dust : res.info.sysInfo.dustS.levels.blue
  564. },
  565. ];
  566. return res;
  567. });
  568. };