Commit 837c1f15 authored by 陈龙's avatar 陈龙

fix: 优化获取点表的逻辑,修复因逻辑问题导致的异常

parent 742989d8
...@@ -37,7 +37,7 @@ path: / ...@@ -37,7 +37,7 @@ path: /
## 多图表 ## 多图表
[//]: # (<code src="./demos/GridDemo.js"></code>) <code src="./demos/GridDemo.js"></code>
## API ## API
......
...@@ -29,7 +29,6 @@ const GridChart = memo((props) => { ...@@ -29,7 +29,6 @@ const GridChart = memo((props) => {
} = props; } = props;
const {prefixCls} = props; const {prefixCls} = props;
const [gridData, setGridData] = useState([]); const [gridData, setGridData] = useState([]);
const [pointAddressData, setPointAddressData] = useState(null);
const [pointAddressEntryData, setPointAddressEntryData] = useState(null); const [pointAddressEntryData, setPointAddressEntryData] = useState(null);
const [sensorType, setSensorType] = useState(null); const [sensorType, setSensorType] = useState(null);
// 新增逻辑:需要区分出哪些是统计值 // 新增逻辑:需要区分出哪些是统计值
...@@ -40,128 +39,127 @@ const GridChart = memo((props) => { ...@@ -40,128 +39,127 @@ const GridChart = memo((props) => {
const handleDataSource = async (dataSource) => { const handleDataSource = async (dataSource) => {
props.setLoading(true); props.setLoading(true);
// 1. 统计设备 // 1. 统计设备
let _deviceTypes = []; try {
let _deviceCodes = dataSource.reduce((final, cur) => { let _deviceTypes = [];
if (!final.includes(cur.stationCode) && !_deviceTypes.includes(cur.deviceType)) { let _deviceCodes = dataSource.reduce((final, cur) => {
final.push(cur.stationCode); if (!final.includes(cur.stationCode) && !_deviceTypes.includes(cur.deviceType)) {
_deviceTypes.push(cur.deviceType); final.push(cur.stationCode);
} _deviceTypes.push(cur.deviceType);
return final; }
}, []); return final;
// 2. 获取对应的版本id }, []);
let _ids = []; // 2. 获取对应的版本id
if (pointAddressData !== null) { let _ids = [];
_ids = pointAddressData;
} else {
let _idRequest = await getPointAddress({code: _deviceCodes.join(',')}); let _idRequest = await getPointAddress({code: _deviceCodes.join(',')});
_ids = _idRequest?.data ?? []; _ids = _idRequest?.data ?? [];
setPointAddressData(_ids) // 3. 获取对应的点表
} let _map = {};
// 3. 获取对应的点表 for await (let item of _ids) {
let _map = {}; let _index = _deviceCodes.findIndex(code => code === item.code);
for await (let item of _ids) { if (pointAddressEntryData && pointAddressEntryData[item.id]) {
let _index = _deviceCodes.findIndex(code => code === item.code); _map[_deviceTypes[_index]] = pointAddressEntryData[item.id];
if (pointAddressEntryData && pointAddressEntryData[item.id]) {
_map[_deviceTypes[_index]] = pointAddressEntryData[item.id];
} else {
let _entry = await getPointAddressEntry({versionId: item.id});
_map[_deviceTypes[_index]] = _entry?.data ?? [];
setPointAddressEntryData({...pointAddressEntryData, [item.id]: _entry?.data})
}
}
// 4. 获取点类型
let _sensorType = []
if (sensorType) {
_sensorType = sensorType;
} else {
_sensorType = (await getSensorType())?.data ?? [];
}
//5. 找出统计值,合并
let _dataSource = cloneDeep(dataSource);
let _nameListMap = {};
let _indexArr = [];
let _tempValue = {};
let _finalData = {};
_dataSource.forEach((item, index) => {
let _sensorTypeId = _map[item.deviceType].find(sensor => sensor.name === item.sensorName)?.sensorTypeID || 0;
let _type = _sensorType.find(sensor => sensor.id === _sensorTypeId)?.type ?? '';
if (_type === '统计值') {
// 移除掉,并存储
_tempValue[`needToReplace_${item.stationCode}_${item.sensorName}`] = _dataSource.splice(index, 1, `needToReplace_${item.stationCode}_${item.sensorName}`)?.[0];
if (!_nameListMap[item.stationCode]) {
_nameListMap[item.stationCode] = {
code: item.stationCode,
deviceType: item.deviceType,
sensors: [item.sensorName]
}
} else { } else {
_nameListMap[item.stationCode].sensors.push(item.sensorName) let _entry = await getPointAddressEntry({versionId: item.id});
_map[_deviceTypes[_index]] = _entry?.data ?? [];
setPointAddressEntryData({...pointAddressEntryData, [item.id]: _entry?.data})
} }
} }
}) // 4. 获取点类型
//6. 请求数据并替换数据。grid模式下,请求的时间是一致的。 let _sensorType = []
let baseParam = { if (sensorType) {
pageIndex: 1, _sensorType = sensorType;
pageSize: 999, } else {
dateFrom: dateRange[0].dateFrom, _sensorType = (await getSensorType())?.data ?? [];
dateTo: dateRange[0].dateTo, }
} //5. 找出统计值,合并
let _arr = Object.values(_nameListMap) let _dataSource = cloneDeep(dataSource);
for await (let item of _arr) { let _nameListMap = {};
let _params = { let _indexArr = [];
...baseParam, let _tempValue = {};
accountName: item.deviceType, let _finalData = {};
deviceCode: item.code, _dataSource.forEach((item, index) => {
nameTypeList: item.sensors.map(sensor => ({ let _sensorTypeId = _map[item.deviceType].find(sensor => sensor.name === item.sensorName)?.sensorTypeID || 0;
name: sensor, let _type = _sensorType.find(sensor => sensor.id === _sensorTypeId)?.type ?? '';
type: 'Sub' if (_type === '统计值') {
})), // 移除掉,并存储
/* nameTypeList: ['今日用电量', '今日供水量'].map(sensor => ({ _tempValue[`needToReplace_${item.stationCode}_${item.sensorName}`] = _dataSource.splice(index, 1, `needToReplace_${item.stationCode}_${item.sensorName}`)?.[0];
name: sensor, if (!_nameListMap[item.stationCode]) {
type: 'Sub' _nameListMap[item.stationCode] = {
})),*/ code: item.stationCode,
dateType: returnDateType(dateRange[0]) deviceType: item.deviceType,
}; sensors: [item.sensorName]
// 虚拟点需要查出实际点后,进行查找 }
let _realSensors = {}; } else {
let _realSensorsMap = {}; _nameListMap[item.stationCode].sensors.push(item.sensorName)
// 统计类的如果是虚拟点,那么需要查出实际数据来源的点,查出映射关系
(await getSensorsRealName(_params))?.data?.forEach(sensor => {
// name 虚拟点 staticName实际的点
_realSensors[sensor.staticName] = sensor.name;
_realSensorsMap[sensor.name] = sensor.staticName;
});
// 请求统计数据时,需要使用实际点去获取
_params.nameTypeList.forEach(sensor => {
sensor.name = _realSensors[sensor.name]
});
// 获取数据后,将原始数据中的dataModel这部分替换掉
((await getStatisticsInfo(_params))?.data?.list?.[0].dNameDataList ?? [])?.forEach(obj => {
let _v = _tempValue[`needToReplace_${item.code}_${_realSensorsMap[obj.dName]}`];
_v.dataModel = obj.nameDate.map(d => {
return {
pt: moment(d.time),
pv: d.value,
maxPV: d.value, minPV: d.value, firstPV: d.value, lastPV: d.value,
} }
});
_finalData[`needToReplace_${item.code}_${_realSensorsMap[obj.dName]}`] = _v;
});
// 替换数据
_dataSource.forEach((d, index) => {
if (_.isString(d) && d.includes('needToReplace') && _finalData[d]) {
_dataSource[index] = _finalData[d];
}
})
// 有不存在数据的,将原始数据替换回来
_dataSource.forEach((d, index) => {
if (_.isString(d) && d.includes('needToReplace')) {
_dataSource[index] = dataSource[index];
} }
}) })
//6. 请求数据并替换数据。grid模式下,请求的时间是一致的。
let baseParam = {
pageIndex: 1,
pageSize: 999,
dateFrom: dateRange[0].dateFrom,
dateTo: dateRange[0].dateTo,
}
let _arr = Object.values(_nameListMap)
for await (let item of _arr) {
let _params = {
...baseParam,
accountName: item.deviceType,
deviceCode: item.code,
nameTypeList: item.sensors.map(sensor => ({
name: sensor,
type: 'Sub'
})),
/* nameTypeList: ['今日用电量', '今日供水量'].map(sensor => ({
name: sensor,
type: 'Sub'
})),*/
dateType: returnDateType(dateRange[0])
};
// 虚拟点需要查出实际点后,进行查找
let _realSensors = {};
let _realSensorsMap = {};
// 统计类的如果是虚拟点,那么需要查出实际数据来源的点,查出映射关系
(await getSensorsRealName(_params))?.data?.forEach(sensor => {
// name 虚拟点 staticName实际的点
_realSensors[sensor.staticName] = sensor.name;
_realSensorsMap[sensor.name] = sensor.staticName;
});
// 请求统计数据时,需要使用实际点去获取
_params.nameTypeList.forEach(sensor => {
sensor.name = _realSensors[sensor.name]
});
// 获取数据后,将原始数据中的dataModel这部分替换掉
((await getStatisticsInfo(_params))?.data?.list?.[0].dNameDataList ?? [])?.forEach(obj => {
let _v = _tempValue[`needToReplace_${item.code}_${_realSensorsMap[obj.dName]}`];
_v.dataModel = obj.nameDate.map(d => {
return {
pt: moment(d.time),
pv: d.value,
maxPV: d.value, minPV: d.value, firstPV: d.value, lastPV: d.value,
}
});
_finalData[`needToReplace_${item.code}_${_realSensorsMap[obj.dName]}`] = _v;
});
// 替换数据
_dataSource.forEach((d, index) => {
if (_.isString(d) && d.includes('needToReplace') && _finalData[d]) {
_dataSource[index] = _finalData[d];
}
})
// 有不存在数据的,将原始数据替换回来
_dataSource.forEach((d, index) => {
if (_.isString(d) && d.includes('needToReplace')) {
_dataSource[index] = dataSource[index];
}
})
}
props.setLoading(false);
return _dataSource
} catch (e) {
props.setLoading(false);
} }
props.setLoading(false);
return _dataSource
}; };
const returnDateType = (date) => { const returnDateType = (date) => {
let {dateFrom, dateTo} = date; let {dateFrom, dateTo} = date;
......
...@@ -72,6 +72,11 @@ import HistoryView from '../index'; ...@@ -72,6 +72,11 @@ import HistoryView from '../index';
]*/ ]*/
const deviceParams = [ const deviceParams = [
{ {
"deviceCode": "EGBF00000141",
"sensors": "进水压力,出水瞬时流量,今日用电量",
"deviceType": "二供泵房"
}
/* {
"deviceCode": "EGBF00000244", "deviceCode": "EGBF00000244",
"sensors": "进水压力,出水瞬时流量,今日用电量,今日供水量", "sensors": "进水压力,出水瞬时流量,今日用电量,今日供水量",
"deviceType": "二供泵房" "deviceType": "二供泵房"
...@@ -85,7 +90,7 @@ const deviceParams = [ ...@@ -85,7 +90,7 @@ const deviceParams = [
"deviceCode": "EGBF00000184", "deviceCode": "EGBF00000184",
"sensors": "进水压力,出水瞬时流量,今日用电量,今日供水量", "sensors": "进水压力,出水瞬时流量,今日用电量,今日供水量",
"deviceType": "二供泵房" "deviceType": "二供泵房"
} }*/
]; ];
const Demo = () => { const Demo = () => {
return <div style={{height: 700}}> return <div style={{height: 700}}>
......
...@@ -191,10 +191,22 @@ import { MobileHistoryChart } from '../mobile'; ...@@ -191,10 +191,22 @@ import { MobileHistoryChart } from '../mobile';
} }
];*/ ];*/
const deviceParams = [ const deviceParams = [
{ // 预测的
/* {
"deviceCode": "YLB00000041", "deviceCode": "YLB00000041",
"sensors": "进水压力", "sensors": "进水压力",
"deviceType": "压力表" "deviceType": "压力表"
}*/
/* {
"deviceCode": "SSBF00000001",
"sensors": "出水压力",
"deviceType": "送水泵房"
}*/
//预测结束
{
"deviceCode": "EGBF00000141",
"sensors": "进水压力,出水瞬时流量,今日用电量",
"deviceType": "二供泵房"
} }
] ]
const Demo = () => { const Demo = () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment