|
|
|
@ -28,17 +28,127 @@ const mappingFunction = async (data, method) => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.type === 2) {
|
|
|
|
|
let getTime = (e) => {
|
|
|
|
|
if (e === '1') {
|
|
|
|
|
return [(new Date().getTime() - (1000 * 60 * 60 * 24)), (new Date().getTime())]
|
|
|
|
|
}
|
|
|
|
|
if (e === '2') {
|
|
|
|
|
return [(new Date().getTime() - (1000 * 60 * 60 * 24)), (new Date().getTime())]
|
|
|
|
|
}
|
|
|
|
|
if (e === '3') {
|
|
|
|
|
return [(new Date().getTime() - (1000 * 60 * 60 * 24 * 7)), (new Date().getTime())]
|
|
|
|
|
}
|
|
|
|
|
if (e === '4') {
|
|
|
|
|
return [(new Date().getTime() - (1000 * 60 * 60 * 24 * 30)), (new Date().getTime())]
|
|
|
|
|
}
|
|
|
|
|
if (e === '5') {
|
|
|
|
|
return [(new Date().getTime() - (1000 * 60 * 60 * 24 * 365)), (new Date().getTime())]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const getTimeList = (e, isRealTime, startTimeArg, endTimeArg) => {
|
|
|
|
|
let startTime, endTime
|
|
|
|
|
if (!isRealTime) {
|
|
|
|
|
startTime = startTimeArg
|
|
|
|
|
endTime = endTimeArg
|
|
|
|
|
} else {
|
|
|
|
|
startTime = getTime(e)[0]
|
|
|
|
|
endTime = getTime(e)[1]
|
|
|
|
|
}
|
|
|
|
|
if (e === '1') {
|
|
|
|
|
let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60)) || 0
|
|
|
|
|
let arr = Array(scope).fill(1).map((v, k) => {
|
|
|
|
|
return parseTime(endTime - (1000 * 60 * 60) * k, '{y}-{m}-{d} {h}:{i}')
|
|
|
|
|
})
|
|
|
|
|
return arr
|
|
|
|
|
}
|
|
|
|
|
if (e === '2') {
|
|
|
|
|
let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60)) || 0
|
|
|
|
|
let arr = Array(scope).fill(1).map((v, k) => {
|
|
|
|
|
return parseTime(endTime - (1000 * 60 * 60) * k, '{y}-{m}-{d} {h}')
|
|
|
|
|
})
|
|
|
|
|
return arr
|
|
|
|
|
}
|
|
|
|
|
if (e === '3') {
|
|
|
|
|
let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60 * 24)) || 0
|
|
|
|
|
let arr = Array(scope).fill(1).map((v, k) => {
|
|
|
|
|
return parseTime(endTime - (1000 * 60 * 60 * 24) * k, '{y}-{m}-{d}')
|
|
|
|
|
})
|
|
|
|
|
return arr
|
|
|
|
|
}
|
|
|
|
|
if (e === '4') {
|
|
|
|
|
let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60 * 24)) || 0
|
|
|
|
|
let arr = Array(scope).fill(1).map((v, k) => {
|
|
|
|
|
return parseTime(endTime - (1000 * 60 * 60 * 24) * k, '{y}-{m}-{d}')
|
|
|
|
|
})
|
|
|
|
|
return arr
|
|
|
|
|
}
|
|
|
|
|
if (e === '5') {
|
|
|
|
|
let scope = Math.ceil((endTime - startTime) / (1000 * 60 * 60 * 24 * 30)) || 0
|
|
|
|
|
let arr = Array(scope).fill(1).map((v, k) => {
|
|
|
|
|
return parseTime(endTime - (1000 * 60 * 60 * 24 * 30) * k, '{y}-{m}')
|
|
|
|
|
})
|
|
|
|
|
return arr
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let res2 = await getHistoryData({
|
|
|
|
|
deviceModeId: data.deviceModeId,
|
|
|
|
|
functionIdentifier: data.functionIdentifier,
|
|
|
|
|
interval: data.interval,
|
|
|
|
|
"sceneId": 144,
|
|
|
|
|
"deviceId": data.deviceId,
|
|
|
|
|
startTime: data.startTime,
|
|
|
|
|
endTime: data.endTime,
|
|
|
|
|
startTime: data.isRealTime ? getTime(data.interval)?.[0] : data.startTime,
|
|
|
|
|
endTime: data.isRealTime ? getTime(data.interval)?.[1] : data.endTime,
|
|
|
|
|
intervalType: 1 || data.intervalType,
|
|
|
|
|
})
|
|
|
|
|
console.log('datadata', data.interval)
|
|
|
|
|
console.log('datadata', data)
|
|
|
|
|
if (data.isRealTime) {
|
|
|
|
|
if (data.interval === '1') {
|
|
|
|
|
let arr = getTimeList(data.interval, data.isRealTime)
|
|
|
|
|
|
|
|
|
|
res2.data.groupDeviceData.dataList = arr.map(v => {
|
|
|
|
|
let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}-{d} {h}:{i}') === v)
|
|
|
|
|
return {...data, time: v}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (data.interval === '2') {
|
|
|
|
|
let arr = getTimeList(data.interval, data.isRealTime)
|
|
|
|
|
|
|
|
|
|
res2.data.groupDeviceData.dataList = arr.map(v => {
|
|
|
|
|
let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}-{d} {h}') === v)
|
|
|
|
|
return {...data, time: v}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (data.interval === '3') {
|
|
|
|
|
let arr = getTimeList(data.interval, data.isRealTime)
|
|
|
|
|
console.log('arr', arr)
|
|
|
|
|
|
|
|
|
|
res2.data.groupDeviceData.dataList = arr.map(v => {
|
|
|
|
|
let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}-{d}') === v)
|
|
|
|
|
return {...data, time: v}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (data.interval === '4') {
|
|
|
|
|
let arr = getTimeList(data.interval, data.isRealTime)
|
|
|
|
|
console.log('arr', arr)
|
|
|
|
|
|
|
|
|
|
res2.data.groupDeviceData.dataList = arr.map(v => {
|
|
|
|
|
let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}-{d}') === v)
|
|
|
|
|
return {...data, time: v}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (data.interval === '5') {
|
|
|
|
|
let arr = getTimeList(data.interval, data.isRealTime)
|
|
|
|
|
console.log('arr', arr)
|
|
|
|
|
|
|
|
|
|
res2.data.groupDeviceData.dataList = arr.map(v => {
|
|
|
|
|
let data = res2.data.groupDeviceData.dataList.find(vv => parseTime(vv.time, '{y}-{m}') === v)
|
|
|
|
|
return {...data, time: v}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (data.interval === '5') {
|
|
|
|
|
res2.data.groupDeviceData.dataList = res2.data.groupDeviceData.dataList.map(e => {
|
|
|
|
|
return {...e, time: parseTime(e.time, '{y}-{m}')}
|
|
|
|
@ -52,6 +162,8 @@ const mappingFunction = async (data, method) => {
|
|
|
|
|
return {...e, time: parseTime(e.time, '{y}-{m}-{d} {h}:{i}:{s}')}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log(res2)
|
|
|
|
|
let returnRes = {}
|
|
|
|
|
method?.mappingArr?.forEach(v => {
|
|
|
|
|
let res = res2.data
|
|
|
|
@ -64,6 +176,7 @@ const mappingFunction = async (data, method) => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (v?.isArray && v?.mapData && Array.isArray(res)) {
|
|
|
|
|
console.log(res)
|
|
|
|
|
res = res.map(e => e[v.mapData])
|
|
|
|
|
}
|
|
|
|
|
returnRes = {
|
|
|
|
|