import { floor, isArray, random, slice } from 'lodash-es'; import { defHttp } from '/@/utils/http/axios'; import { get } from '../billboard/utils'; enum Api { list = '/safety/ventanalyDevice/homedata2', getHomeData = '/safety/ventanalyDevice/homedata', getDisHome = '/monitor/disaster/getDisHome', getBDDustData = '/monitor/disaster/getDisDustHome', getBDFireData = '/monitor/disaster/getDisFireHome', } // 搞这个缓存是由于:目前代码上的设计是多个模块发出多次请求,每个模块自己负责消费前者的响应。 // 这会导致相同的请求被同时发送多次。 const cache = new Map>(); /** * 列表接口,5.5专用,和6.0的getHomeData基本一致 * @param params */ export const list = (params) => { const key = `${Api.list}?${JSON.stringify(params)}`; if (!cache.has(key)) { cache.set( key, defHttp.post({ url: Api.list, params }).finally(() => { cache.delete(key); }) ); } return (cache.get(key) as Promise).then((res) => { if (res.fanmain) { // 处理频率字段,为了兼容旧版保留,现配置项已支持一级动态字段 res.fanmain.forEach((e) => { if (e.readData.Fan2StartStatus === '1') { e.current = '二号'; e.readData.FanFreqHz = e.readData.Fan2FreqHz; } else { e.current = '一号'; e.readData.FanFreqHz = e.readData.Fan1FreqHz; } }); } if (res.fanlocal) { res.fanlocal.forEach((e) => { e.chartData = [ { x: '吸风量', yRealtime: e.readData.windQuantity1, yMock: floor(parseFloat(e.inletAirVolume_merge) * random(0.98, 1, false), 2), y: e.inletAirVolume_merge, }, { x: '供风量', yRealtime: e.readData.windQuantity2, yMock: floor(parseFloat(e.ductOutletAirVolume_merge) * random(0.98, 1, false), 2), y: e.ductOutletAirVolume_merge, }, ]; if (e.readData.Fan2StartStatus === '1') { e.current = '二号'; e.readData.FanfHz = e.readData.Fan2fHz; } else { e.current = '一号'; e.readData.FanfHz = e.readData.Fan1fHz; } }); } if (res.sys_majorpath) { res.sys_majorpath.forEach((e) => { const { drag_1, drag_2, drag_3, drag_total } = e.majorpath; const { fy_merge = { value: '1' } } = e.readData; const drag_merge = parseInt(fy_merge.value); // const m3_merge = parseInt(retM3_merge.value); e.piechart = [ { val: drag_1, valMock: floor((drag_1 / drag_total) * drag_merge), label: '进风区(Pa)' }, { val: drag_2, valMock: floor((drag_2 / drag_total) * drag_merge), label: '用风区(Pa)' }, { val: drag_3, valMock: floor((drag_3 / drag_total) * drag_merge), label: '回风区(Pa)' }, ]; e.readData.dengjikong_merge = get(res, 'midinfo[0].sysinfo.equalarea'); e.readData.fy_merge_int = drag_merge; // e.dengjikong_merge = floor((1.19 * (m3_merge / 60)) / Math.sqrt(drag_merge), 2); }); } if (res.sys_surface_caimei) { res.sys_surface_caimei.forEach((e) => { if (isArray(e.history)) { e.history = slice(e.history, e.history.length - 30, e.history.length); } if (isArray(e.history_report)) { e.history_report = slice(e.history_report, e.history_report.length - 30, e.history_report.length); } }); } if (res.device_arr) { res.device_arr = Object.values(res.device); } return res; }); }; export const getHomeData = (params) => { const key = `${Api.getHomeData}?${JSON.stringify(params)}`; if (!cache.has(key)) { cache.set( key, defHttp.post({ url: Api.getHomeData, params }).finally(() => { cache.delete(key); }) ); } return (cache.get(key) as Promise).then((res) => { res.fanmain.forEach((e) => { if (e.readData.Fan2StartStatus === '1') { e.current = '二号'; e.readData.FanFreqHz = e.readData.Fan2FreqHz; } else { e.current = '一号'; e.readData.FanFreqHz = e.readData.Fan1FreqHz; } }); res.fanlocal.forEach((e) => { e.chartData = [ { x: '吸风量', y: e.readData.windQuantity1, }, { x: '供风量', y: e.readData.windQuantity2, }, ]; if (e.readData.Fan2StartStatus === '1') { e.current = '二号'; e.readData.FanfHz = e.readData.Fan2fHz; } else { e.current = '一号'; e.readData.FanfHz = e.readData.Fan1fHz; } }); res.sys_majorpath.forEach((e) => { e.piechart = [ { val: e.majorpath.drag_1, label: '进风区' }, { val: e.majorpath.drag_2, label: '用风区' }, { val: e.majorpath.drag_3, label: '回风区' }, ]; }); return res; }); }; export const getBDDustData = (params) => { const key = `${Api.getBDDustData}?${JSON.stringify(params)}`; if (!cache.has(key)) { cache.set( key, defHttp.post({ url: Api.getBDDustData, params }).finally(() => { cache.delete(key); }) ); } return cache.get(key) as Promise; }; export const getBDFireData = (params) => { const key = `${Api.getBDFireData}?${JSON.stringify(params)}`; if (!cache.has(key)) { cache.set( key, defHttp.post({ url: Api.getBDFireData, params }).finally(() => { cache.delete(key); }) ); } return (cache.get(key) as Promise).then((res) => { res.pdArray.forEach((e) => { e.arrayFiber.forEach((j) => { j.fibreTemperatureArr = JSON.parse(j.fibreTemperature); }); }); res.sgGxObj.devGxcw.forEach((e) => { e.fibreTemperatureArr = JSON.parse(e.fibreTemperature); }); res.sgGxObj.devSgjc.forEach((e) => { e.o2val = e.o2Val || 0; e.coval = e.coVal || 0; e.gasval = e.gasVal || 0; e.ch2val = e.ch2Val || 0; e.chval = e.chVal || 0; }); return res; }); }; export const getDisHome = (params) => { const key = `${Api.getDisHome}?${JSON.stringify(params)}`; if (!cache.has(key)) { cache.set( key, defHttp.post({ url: Api.getDisHome, params }).finally(() => { cache.delete(key); }) ); } return (cache.get(key) as Promise).then((res) => { if (res.pdArray) { res.pdArray.forEach((e) => { e.arrayFiber.forEach((j) => { j.fibreTemperatureArr = JSON.parse(j.fibreTemperature); }); }); } if (res.sgGxObj) { res.sgGxObj.devGxcw.forEach((e) => { e.fibreTemperatureArr = JSON.parse(e.fibreTemperature); }); res.sgGxObj.devSgjc.forEach((e) => { e.o2val = e.o2Val || 0; e.coval = e.coVal || 0; e.gasval = e.gasVal || 0; e.ch2val = e.ch2Val || 0; e.chval = e.chVal || 0; }); } if (res.obfObj) { res.obfObj.obfObjModded = [ { objType: '甲烷', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.ch4Val || 0, }; }), }, { objType: '一氧化碳', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.coVal || 0, }; }), }, { objType: '乙炔', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.c2h2Val || 0, }; }), }, { objType: '二氧化碳', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.co2Val || 0, }; }), }, { objType: '氧气', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.o2Val || 0, }; }), }, { objType: '乙烯', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.c2h4Val || 0, }; }), }, { objType: '压差', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.dpVal || 0, }; }), }, { objType: '温度', arrayDev: res.obfObj.arrayDev.map((e) => { return { strinstallpos: e.strinstallpos, val: e.tempVal || 0, }; }), }, ]; } return res; }); };