Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wisdom-components
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
wisdom-components
Commits
837c1f15
Commit
837c1f15
authored
Feb 22, 2024
by
陈龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 优化获取点表的逻辑,修复因逻辑问题导致的异常
parent
742989d8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
132 additions
and
117 deletions
+132
-117
EC_HistoryView.md
...es/extend-components/EC_HistoryView/src/EC_HistoryView.md
+1
-1
GridChart.js
packages/extend-components/EC_HistoryView/src/GridChart.js
+112
-114
GridDemo.js
...es/extend-components/EC_HistoryView/src/demos/GridDemo.js
+6
-1
index.js
packages/extend-components/EC_HistoryView/src/demos/index.js
+13
-1
No files found.
packages/extend-components/EC_HistoryView/src/EC_HistoryView.md
View file @
837c1f15
...
...
@@ -37,7 +37,7 @@ path: /
## 多图表
[
//
]:
#
(<code src="./demos/GridDemo.js"></code>)
<code
src=
"./demos/GridDemo.js"
></code>
## API
...
...
packages/extend-components/EC_HistoryView/src/GridChart.js
View file @
837c1f15
...
...
@@ -29,7 +29,6 @@ const GridChart = memo((props) => {
}
=
props
;
const
{
prefixCls
}
=
props
;
const
[
gridData
,
setGridData
]
=
useState
([]);
const
[
pointAddressData
,
setPointAddressData
]
=
useState
(
null
);
const
[
pointAddressEntryData
,
setPointAddressEntryData
]
=
useState
(
null
);
const
[
sensorType
,
setSensorType
]
=
useState
(
null
);
// 新增逻辑:需要区分出哪些是统计值
...
...
@@ -40,128 +39,127 @@ const GridChart = memo((props) => {
const
handleDataSource
=
async
(
dataSource
)
=>
{
props
.
setLoading
(
true
);
// 1. 统计设备
let
_deviceTypes
=
[];
let
_deviceCodes
=
dataSource
.
reduce
((
final
,
cur
)
=>
{
if
(
!
final
.
includes
(
cur
.
stationCode
)
&&
!
_deviceTypes
.
includes
(
cur
.
deviceType
))
{
final
.
push
(
cur
.
stationCode
);
_deviceTypes
.
push
(
cur
.
deviceType
);
}
return
final
;
},
[]);
// 2. 获取对应的版本id
let
_ids
=
[];
if
(
pointAddressData
!==
null
)
{
_ids
=
pointAddressData
;
}
else
{
try
{
let
_deviceTypes
=
[];
let
_deviceCodes
=
dataSource
.
reduce
((
final
,
cur
)
=>
{
if
(
!
final
.
includes
(
cur
.
stationCode
)
&&
!
_deviceTypes
.
includes
(
cur
.
deviceType
))
{
final
.
push
(
cur
.
stationCode
);
_deviceTypes
.
push
(
cur
.
deviceType
);
}
return
final
;
},
[]);
// 2. 获取对应的版本id
let
_ids
=
[];
let
_idRequest
=
await
getPointAddress
({
code
:
_deviceCodes
.
join
(
','
)});
_ids
=
_idRequest
?.
data
??
[];
setPointAddressData
(
_ids
)
}
// 3. 获取对应的点表
let
_map
=
{};
for
await
(
let
item
of
_ids
)
{
let
_index
=
_deviceCodes
.
findIndex
(
code
=>
code
===
item
.
code
);
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
]
}
// 3. 获取对应的点表
let
_map
=
{};
for
await
(
let
item
of
_ids
)
{
let
_index
=
_deviceCodes
.
findIndex
(
code
=>
code
===
item
.
code
);
if
(
pointAddressEntryData
&&
pointAddressEntryData
[
item
.
id
])
{
_map
[
_deviceTypes
[
_index
]]
=
pointAddressEntryData
[
item
.
id
];
}
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
})
}
}
})
//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
,
// 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
{
_nameListMap
[
item
.
stationCode
].
sensors
.
push
(
item
.
sensorName
)
}
});
_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
)
=>
{
let
{
dateFrom
,
dateTo
}
=
date
;
...
...
packages/extend-components/EC_HistoryView/src/demos/GridDemo.js
View file @
837c1f15
...
...
@@ -72,6 +72,11 @@ import HistoryView from '../index';
]*/
const
deviceParams
=
[
{
"deviceCode"
:
"EGBF00000141"
,
"sensors"
:
"进水压力,出水瞬时流量,今日用电量"
,
"deviceType"
:
"二供泵房"
}
/* {
"deviceCode": "EGBF00000244",
"sensors": "进水压力,出水瞬时流量,今日用电量,今日供水量",
"deviceType": "二供泵房"
...
...
@@ -85,7 +90,7 @@ const deviceParams = [
"deviceCode": "EGBF00000184",
"sensors": "进水压力,出水瞬时流量,今日用电量,今日供水量",
"deviceType": "二供泵房"
}
}
*/
];
const
Demo
=
()
=>
{
return
<
div
style
=
{{
height
:
700
}}
>
...
...
packages/extend-components/EC_HistoryView/src/demos/index.js
View file @
837c1f15
...
...
@@ -191,10 +191,22 @@ import { MobileHistoryChart } from '../mobile';
}
];*/
const
deviceParams
=
[
{
// 预测的
/* {
"deviceCode": "YLB00000041",
"sensors": "进水压力",
"deviceType": "压力表"
}*/
/* {
"deviceCode": "SSBF00000001",
"sensors": "出水压力",
"deviceType": "送水泵房"
}*/
//预测结束
{
"deviceCode"
:
"EGBF00000141"
,
"sensors"
:
"进水压力,出水瞬时流量,今日用电量"
,
"deviceType"
:
"二供泵房"
}
]
const
Demo
=
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment