Commit b1ac6981 authored by 李纪文's avatar 李纪文

fix: 历史回放增加统计取值

parent 2a8744b5
......@@ -12,7 +12,13 @@ import GuidedDraggingTool from './js/GuidedDraggingTool';
import TopRotatingTool from './js/RotatingTool';
import BarLink from './js/BarLink';
import WaterFlowControlView from './js/WaterFlowControlView';
import { getSketchPadList, getSketchPadContent, getPointAddress, getHistoryInfo } from './apis';
import {
getSketchPadList,
getSketchPadContent,
getPointAddress,
getHistoryInfo,
getStatisticsInfo,
} from './apis';
import {
deepCopy,
hexToRgba,
......@@ -57,7 +63,15 @@ const ConfigurationView = (props) => {
twoID = `TDG${Date.now().toString(36)}`;
const ConfigurationRef = useRef();
const customBack = props.customBack ? props.customBack : () => {};
const { devices = [], config, isZoom = false, flowShow = true, deviceName = [] } = props;
const {
devices = [],
config,
isZoom = false,
flowShow = true,
deviceName = [],
dataType = '统计',
statisticType = [],
} = props;
let devicesCode = [];
const globalConfig = window.globalConfig || config;
let isClose = false;
......@@ -627,7 +641,8 @@ const ConfigurationView = (props) => {
useEffect(() => {
historyParams = props.params;
getHistoryData(false);
if (dataType === '历史') getHistoryData(false);
if (dataType === '统计') getStatisticsData(false);
}, [props.params]);
/** ************************************获取画板JSON******************************* */
......@@ -661,7 +676,8 @@ const ConfigurationView = (props) => {
// });
// });
diagramRender(typeof fromJson === 'string' ? fromJson : JSON.stringify(fromJson), list);
getHistoryData(true);
if (dataType === '历史') getHistoryData(true);
if (dataType === '统计') getStatisticsData(true);
} else {
message.error(response.msg);
}
......@@ -692,8 +708,8 @@ const ConfigurationView = (props) => {
});
});
const params = {
isDilute: true,
zoom: '1',
isDilute: false,
zoom: '30',
unit: 'h',
ignoreOutliers: false,
isVertical: false, // 是否查询竖表
......@@ -723,6 +739,81 @@ const ConfigurationView = (props) => {
}
};
/** ************************************统计数据获取******************************* */
const getStatisticsData = async (flag) => {
try {
if (!myDiagram) return false;
setSpinLoad(true);
speed = 0;
const json = JSON.parse(myDiagram.model.toJson());
const jsonCopy = JSON.parse(JSON.stringify(json));
const acrossTables = [];
bindData.map((list) => {
let sensors = [];
jsonCopy.nodeDataArray.forEach((item) => {
item.shName && item.stationName === list.name && sensors.push(item.shName);
});
jsonCopy.linkDataArray.forEach((item) => {
item.shName && item.stationName === list.name && sensors.push(item.shName);
});
if (sensors.length && list.code)
acrossTables.push({
accountName: list.type,
nameTypeList: sensors.map((item) => {
const listType = statisticType.find((arr) => {
return arr.name === item;
})
return {
name: item,
type: listType?.type || 'Sub',
};
}),
dateFrom: historyParams.dateFrom || moment(new Date()).format('yyyy-MM-DD 00:00:00'),
dateTo: historyParams.dateTo || moment(new Date()).format('yyyy-MM-DD 23:59:59'),
deviceCode: list.code,
});
});
const params = {
pageIndex: 1,
pageSize: 999,
q_DeviceReports: acrossTables,
dateType: 'day',
...historyParams,
};
const results = await getStatisticsInfo(params);
const res = results?.data?.list || [];
let timeArr = [];
let statisticsData = [];
res.forEach((item) => {
const listData = item.dNameDataList.map((list) => {
return {
code: item.code,
eName: item.eName,
eShortName: item.eShortName,
...list,
};
});
statisticsData = statisticsData.concat(listData);
});
historyData = [].concat(statisticsData);
historyData.forEach((item) => {
const timeList = item.nameDate.map((list) => {
return moment(list.time).format('yyyy-MM-DD HH:mm:ss');
});
timeArr = timeArr.concat(timeList);
});
const _timeData = dataUnique(timeArr);
timeData = _timeData.sort(function (a, b) {
return new Date(a).getTime() - new Date(b).getTime();
});
chartStatisticsDataRender(historyData);
if (flag) historyTimeRender();
setSpinLoad(false);
} catch (err) {
setSpinLoad(false);
}
};
/** ****************************************数据去重******************************* */
const dataUnique = (arr) => {
return Array.from(new Set(arr));
......@@ -835,6 +926,113 @@ const ConfigurationView = (props) => {
}
};
/** ***********************************图表历史数据处理**************************** */
const chartStatisticsDataRender = (mqttData) => {
const time = timeData[speed];
loopLoadMethod(time);
const json = JSON.parse(myDiagram.model.toJson());
const jsonCopy = JSON.parse(JSON.stringify(json));
const oldJson = deepCopy(jsonCopy);
try {
jsonCopy.linkDataArray.forEach((item) => {
if (!item.shName || item.shType !== '线条展示') return false;
mqttData.forEach((list) => {
const bindList = bindData.find((arr) => {
return arr.code === list.code;
});
const pvList = list.nameDate.find((arr) => {
return moment(arr.time).format('yyyy-MM-DD HH:mm:ss') === time;
});
if (!bindList || item.stationName !== bindList.name) return false;
if (
!pvList ||
pvList.value === null ||
list.dName !== item.shName ||
item.realVal === pvList.value
)
return false;
item.realVal = pvList.value * 1;
const shRule = ruleOperation(item, item.realVal);
if (shRule) {
myDiagram.model.setDataProperty(item, 'stroke', shRule.attr);
myDiagram.model.setDataProperty(item, 'waterStroke', shRule.text);
} else {
myDiagram.model.setDataProperty(item, 'stroke', item.stroke);
myDiagram.model.setDataProperty(item, 'waterStroke', item.waterStroke);
}
});
});
} catch (e) {
// 水流展示
}
try {
jsonCopy.nodeDataArray.forEach((item) => {
if (!(item.shName || item.figure === 'updateTime')) return false;
const node = myDiagram.model.findNodeDataForKey(item.key);
mqttData.forEach((list) => {
if (node.figure === 'updateTime') {
myDiagram.model.setDataProperty(
node,
'text',
moment(list.value).format('yyyy-MM-DD HH:mm:ss'),
);
return false;
}
const bindList = bindData.find((arr) => {
return arr.code === list.code;
});
const pvList = list.nameDate.find((arr) => {
return moment(arr.time).format('yyyy-MM-DD HH:mm:ss') === time;
});
if (!bindList || item.stationName !== bindList.name) return false;
if (
(!pvList ||
pvList.value === null ||
list.dName !== item.shName ||
item.realVal === pvList.value) &&
list.dName !== item.stateName
)
return false;
pvList.Value = pvList.value;
if (list.dName === item.shName) showNodeMethod(node, pvList);
if (list.dName === item.stateName) stateMethod(node, pvList);
});
});
} catch (e) {
// 节点展示
}
try {
const jsonModel = waterFlow.waterFlowControlByDiagramJson(oldJson, myDiagram);
if (!jsonModel) return false;
const oldLink = myDiagram.model.linkDataArray;
const dataLink = [];
jsonModel.linkDataArray.forEach((item, index) => {
const list = Object.assign({}, oldLink[index]);
list.isHavingDash = item.isHavingDash;
dataLink.push(list);
});
jsonModel.nodeDataArray.forEach((item) => {
if (item.category === 'HBar') {
const node = myDiagram.model.findNodeDataForKey(item.key);
const waterStroke = item.typeDash ? 'transparent' : item.hBarClolor;
if (item.typeDash != node.typeDash) {
myDiagram.model.setDataProperty(node, 'waterStroke', waterStroke);
myDiagram.model.setDataProperty(node, 'typeDash', item.typeDash);
}
}
});
dataLink.forEach((item) => {
const node = myDiagram.findLinkForData(item);
if (item.isHavingDash != node.data.isHavingDash)
myDiagram.model.setDataProperty(node.data, 'isHavingDash', item.isHavingDash);
});
} catch (e) {
// 水流展示
}
};
/** **********************历史数据循环**************************** */
const historyTimeRender = () => {
historyInterval(() => {
......@@ -845,7 +1043,8 @@ const ConfigurationView = (props) => {
loopLoadMethod(timeData.slice(-1)[0]);
return false;
}
chartHistoryDataRender(historyData);
if (dataType === '历史') chartHistoryDataRender(historyData);
if (dataType === '统计') chartStatisticsDataRender(historyData);
});
};
......@@ -2182,6 +2381,7 @@ ConfigurationView.defaultProps = {
times: 2,
callback: (speed, total, play, time) => {},
params: {},
statisticType: [],
};
ConfigurationView.propTypes = {
......@@ -2197,6 +2397,7 @@ ConfigurationView.propTypes = {
times: PropTypes.number,
callback: PropTypes.func,
params: PropTypes.object,
statisticType: PropTypes.array,
};
export default ConfigurationView;
......@@ -1020,6 +1020,7 @@ const ConfigurationView = (props) => {
/** **************************************历史模态渲染****************************************** */
const historyModalRender = (data, list) => {
if(!data.shName) return false;
historyInfoParams = [
{
deviceCode: list.code,
......
......@@ -67,3 +67,12 @@ export function getVideoDetail(params) {
params,
});
}
// 获取统计数据
export function getStatisticsInfo(data) {
return request({
url: `${baseURI}/PandaMonitor/Monitor/Device/EquipmentDataReports`,
method: REQUEST_METHOD_POST,
data,
});
}
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