configurable.api.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. import { floor, isArray, random, slice } from 'lodash-es';
  2. import { defHttp } from '/@/utils/http/axios';
  3. import { get } from '../billboard/utils';
  4. enum Api {
  5. list = '/safety/ventanalyDevice/homedata2',
  6. getHomeData = '/safety/ventanalyDevice/homedata',
  7. getDisHome = '/monitor/disaster/getDisHome',
  8. getBDDustData = '/monitor/disaster/getDisDustHome',
  9. getBDFireData = '/monitor/disaster/getDisFireHome',
  10. getDeviceSys = '/ventanaly-device/monitor/system',
  11. getAlarmRecord = '/ventanaly-device/safety/ventanalyAlarmLog/sysLinkDevAlarmLog',
  12. }
  13. // 搞这个缓存是由于:目前代码上的设计是多个模块发出多次请求,每个模块自己负责消费前者的响应。
  14. // 这会导致相同的请求被同时发送多次。
  15. const cache = new Map<string, Promise<any>>();
  16. /**
  17. * 列表接口,5.5专用,和6.0的getHomeData基本一致
  18. * @param params
  19. */
  20. export const list = (params) => {
  21. const key = `${Api.list}?${JSON.stringify(params)}`;
  22. if (!cache.has(key)) {
  23. cache.set(
  24. key,
  25. defHttp.post({ url: Api.list, params }).finally(() => {
  26. cache.delete(key);
  27. })
  28. );
  29. }
  30. return (cache.get(key) as Promise<any>).then((res) => {
  31. if (res.fanmain) {
  32. // 处理频率字段,为了兼容旧版保留,现配置项已支持一级动态字段
  33. res.fanmain.forEach((e) => {
  34. if (e.readData.Fan2StartStatus === '1') {
  35. e.current = '二号';
  36. e.readData.FanFreqHz = e.readData.Fan2FreqHz;
  37. } else {
  38. e.current = '一号';
  39. e.readData.FanFreqHz = e.readData.Fan1FreqHz;
  40. }
  41. });
  42. }
  43. if (res.fanlocal) {
  44. res.fanlocal.forEach((e) => {
  45. e.chartData = [
  46. {
  47. x: '吸风量',
  48. yRealtime: e.readData.windQuantity1,
  49. yMock: floor(parseFloat(e.inletAirVolume_merge) * random(0.98, 1, false), 2),
  50. y: e.inletAirVolume_merge,
  51. },
  52. {
  53. x: '供风量',
  54. yRealtime: e.readData.windQuantity2,
  55. yMock: floor(parseFloat(e.ductOutletAirVolume_merge) * random(0.98, 1, false), 2),
  56. y: e.ductOutletAirVolume_merge,
  57. },
  58. ];
  59. if (e.readData.Fan2StartStatus === '1') {
  60. e.current = '二号';
  61. e.readData.FanfHz = e.readData.Fan2fHz;
  62. } else {
  63. e.current = '一号';
  64. e.readData.FanfHz = e.readData.Fan1fHz;
  65. }
  66. });
  67. }
  68. if (res.sys_majorpath) {
  69. res.sys_majorpath.forEach((e) => {
  70. const { drag_1, drag_2, drag_3, drag_total } = e.majorpath;
  71. const { fy_merge = { value: '1' } } = e.readData;
  72. const drag_merge = parseInt(fy_merge.value);
  73. // const m3_merge = parseInt(retM3_merge.value);
  74. e.piechart = [
  75. { val: drag_1, valMock: floor((drag_1 / drag_total) * drag_merge), label: '进风区(Pa)' },
  76. { val: drag_2, valMock: floor((drag_2 / drag_total) * drag_merge), label: '用风区(Pa)' },
  77. { val: drag_3, valMock: floor((drag_3 / drag_total) * drag_merge), label: '回风区(Pa)' },
  78. ];
  79. e.readData.dengjikong_merge = get(res, 'midinfo[0].sysinfo.equalarea');
  80. e.readData.fy_merge_int = drag_merge;
  81. // e.dengjikong_merge = floor((1.19 * (m3_merge / 60)) / Math.sqrt(drag_merge), 2);
  82. });
  83. }
  84. if (res.sys_surface_caimei) {
  85. res.sys_surface_caimei.forEach((e) => {
  86. if (isArray(e.history)) {
  87. e.history = slice(e.history, e.history.length - 30, e.history.length);
  88. }
  89. if (isArray(e.history_report)) {
  90. e.history_report = slice(e.history_report, e.history_report.length - 30, e.history_report.length);
  91. }
  92. });
  93. }
  94. if (res.device_arr) {
  95. res.device_arr = Object.values(res.device);
  96. }
  97. if (res.sys_wind) {
  98. res.sys_wind.forEach((e) => {
  99. if (e.readData.m3) {
  100. e.readData.m3 = e.readData.m3.replace('-', '');
  101. }
  102. if (e.readData.va) {
  103. e.readData.va = e.readData.va.replace('-', '');
  104. }
  105. });
  106. }
  107. if (res.windrect) {
  108. res.windrect.forEach((e) => {
  109. if (e.readData.m3) {
  110. e.readData.m3 = e.readData.m3.replace('-', '');
  111. }
  112. if (e.readData.va) {
  113. e.readData.va = e.readData.va.replace('-', '');
  114. }
  115. });
  116. }
  117. return res;
  118. });
  119. };
  120. export const getHomeData = (params) => {
  121. const key = `${Api.getHomeData}?${JSON.stringify(params)}`;
  122. if (!cache.has(key)) {
  123. cache.set(
  124. key,
  125. defHttp.post({ url: Api.getHomeData, params }).finally(() => {
  126. cache.delete(key);
  127. })
  128. );
  129. }
  130. return (cache.get(key) as Promise<any>).then((res) => {
  131. res.fanmain.forEach((e) => {
  132. if (e.readData.Fan2StartStatus === '1') {
  133. e.current = '二号';
  134. e.readData.FanFreqHz = e.readData.Fan2FreqHz;
  135. } else {
  136. e.current = '一号';
  137. e.readData.FanFreqHz = e.readData.Fan1FreqHz;
  138. }
  139. });
  140. res.fanlocal.forEach((e) => {
  141. e.chartData = [
  142. {
  143. x: '吸风量',
  144. y: e.readData.windQuantity1,
  145. },
  146. {
  147. x: '供风量',
  148. y: e.readData.windQuantity2,
  149. },
  150. ];
  151. if (e.readData.Fan2StartStatus === '1') {
  152. e.current = '二号';
  153. e.readData.FanfHz = e.readData.Fan2fHz;
  154. } else {
  155. e.current = '一号';
  156. e.readData.FanfHz = e.readData.Fan1fHz;
  157. }
  158. });
  159. res.sys_majorpath.forEach((e) => {
  160. e.piechart = [
  161. { val: e.majorpath.drag_1, label: '进风区' },
  162. { val: e.majorpath.drag_2, label: '用风区' },
  163. { val: e.majorpath.drag_3, label: '回风区' },
  164. ];
  165. });
  166. return res;
  167. });
  168. };
  169. export const getBDDustData = (params) => {
  170. const key = `${Api.getBDDustData}?${JSON.stringify(params)}`;
  171. if (!cache.has(key)) {
  172. cache.set(
  173. key,
  174. defHttp.post({ url: Api.getBDDustData, params }).finally(() => {
  175. cache.delete(key);
  176. })
  177. );
  178. }
  179. return cache.get(key) as Promise<any>;
  180. };
  181. export const getBDFireData = (params) => {
  182. const key = `${Api.getBDFireData}?${JSON.stringify(params)}`;
  183. if (!cache.has(key)) {
  184. cache.set(
  185. key,
  186. defHttp.post({ url: Api.getBDFireData, params }).finally(() => {
  187. cache.delete(key);
  188. })
  189. );
  190. }
  191. return (cache.get(key) as Promise<any>).then((res) => {
  192. res.pdArray.forEach((e) => {
  193. e.arrayFiber.forEach((j) => {
  194. j.fibreTemperatureArr = JSON.parse(j.fibreTemperature);
  195. });
  196. });
  197. res.sgGxObj.devGxcw.forEach((e) => {
  198. e.fibreTemperatureArr = JSON.parse(e.fibreTemperature);
  199. });
  200. res.sgGxObj.devSgjc.forEach((e) => {
  201. e.o2val = e.o2Val || 0;
  202. e.coval = e.coVal || 0;
  203. e.gasval = e.gasVal || 0;
  204. e.ch2val = e.ch2Val || 0;
  205. e.chval = e.chVal || 0;
  206. });
  207. return res;
  208. });
  209. };
  210. // ceshi
  211. export const getDeviceSys = (params) => {
  212. const key = `${Api.getDeviceSys}?${JSON.stringify(params)}`;
  213. if (!cache.has(key)) {
  214. cache.set(
  215. key,
  216. defHttp.post({ url: Api.getDeviceSys, params }).finally(() => {
  217. cache.delete(key);
  218. })
  219. );
  220. }
  221. return (cache.get(key) as Promise<any>).then((res) => {
  222. return res;
  223. });
  224. };
  225. export const getAlarmRecord = (params) => {
  226. const key = `${Api.getAlarmRecord}?${JSON.stringify(params)}`;
  227. if (!cache.has(key)) {
  228. cache.set(
  229. key,
  230. defHttp.post({ url: Api.getAlarmRecord, params }).finally(() => {
  231. cache.delete(key);
  232. })
  233. );
  234. }
  235. return (cache.get(key) as Promise<any>).then((res) => {
  236. return res;
  237. });
  238. };
  239. export const getDisHome = (params) => {
  240. const key = `${Api.getDisHome}?${JSON.stringify(params)}`;
  241. if (!cache.has(key)) {
  242. cache.set(
  243. key,
  244. defHttp.post({ url: Api.getDisHome, params }).finally(() => {
  245. cache.delete(key);
  246. })
  247. );
  248. }
  249. return (cache.get(key) as Promise<any>).then((res) => {
  250. if (res.pdArray) {
  251. res.pdArray.forEach((e) => {
  252. e.arrayFiber.forEach((j) => {
  253. j.fibreTemperatureArr = JSON.parse(j.fibreTemperature);
  254. });
  255. });
  256. }
  257. if (res.sgGxObj) {
  258. res.sgGxObj.devGxcw.forEach((e) => {
  259. e.fibreTemperatureArr = JSON.parse(e.fibreTemperature);
  260. });
  261. res.sgGxObj.devSgjc.forEach((e) => {
  262. e.o2val = e.o2Val || 0;
  263. e.coval = e.coVal || 0;
  264. e.gasval = e.gasVal || 0;
  265. e.ch2val = e.ch2Val || 0;
  266. e.chval = e.chVal || 0;
  267. });
  268. }
  269. if (res.obfObj) {
  270. res.obfObj.obfObjModded = [
  271. {
  272. objType: '氧气',
  273. arrayDev: res.obfObj.arrayDev.map((e) => {
  274. return {
  275. strinstallpos: e.strinstallpos,
  276. val: e.o2Val || 0,
  277. };
  278. }),
  279. },
  280. {
  281. objType: '甲烷',
  282. arrayDev: res.obfObj.arrayDev.map((e) => {
  283. return {
  284. strinstallpos: e.strinstallpos,
  285. val: e.ch4Val || 0,
  286. };
  287. }),
  288. },
  289. {
  290. objType: '一氧化碳',
  291. arrayDev: res.obfObj.arrayDev.map((e) => {
  292. return {
  293. strinstallpos: e.strinstallpos,
  294. val: e.coVal || 0,
  295. };
  296. }),
  297. },
  298. {
  299. objType: '乙炔',
  300. arrayDev: res.obfObj.arrayDev.map((e) => {
  301. return {
  302. strinstallpos: e.strinstallpos,
  303. val: e.c2h2Val || 0,
  304. };
  305. }),
  306. },
  307. {
  308. objType: '二氧化碳',
  309. arrayDev: res.obfObj.arrayDev.map((e) => {
  310. return {
  311. strinstallpos: e.strinstallpos,
  312. val: e.co2Val || 0,
  313. };
  314. }),
  315. },
  316. {
  317. objType: '乙烯',
  318. arrayDev: res.obfObj.arrayDev.map((e) => {
  319. return {
  320. strinstallpos: e.strinstallpos,
  321. val: e.c2h4Val || 0,
  322. };
  323. }),
  324. },
  325. {
  326. objType: '压差',
  327. arrayDev: res.obfObj.arrayDev.map((e) => {
  328. return {
  329. strinstallpos: e.strinstallpos,
  330. val: e.dpVal || 0,
  331. };
  332. }),
  333. },
  334. {
  335. objType: '温度',
  336. arrayDev: res.obfObj.arrayDev.map((e) => {
  337. return {
  338. strinstallpos: e.strinstallpos,
  339. val: e.tempVal || 0,
  340. };
  341. }),
  342. },
  343. ];
  344. }
  345. return res;
  346. });
  347. };