createTableData.js 6.2 KB
Newer Older
DarkForst's avatar
DarkForst committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
import { Row, Col } from 'antd'
import style from '../index.less'
import _ from 'lodash'
// 表格数据...表格columns
export const createTableData = (data) => {
    if (!data || data?.length === 0) return { columns: [], dataSource: [] };
    const columns = [
        { title: '时间', dataIndex: 'time' },
    ]
    let dataSource = []
    const dateRange = data[0].trendLineList;
    if (dateRange && dateRange.length > 0) {
        dateRange.forEach((item, index) => {
            columns.push({
                title: `${item.name} ${index === 0 ? '' : '( 小时 )'}`,
                dataIndex: `data-${index}`,
                render: text => {
                    if (text) {
                        if (index !== 0) {
                            return (parseInt(text, 10) / 3600).toFixed(2)
                        }
                        return text || 0
                    }
                    return 0
                }
            })
        })
        const dataTime = dateRange[0].trendIndexList;
        dataSource = dataTime.map((item, index) => {
            const dataGroup = {};
            dateRange.forEach((child, index2) => {
                dataGroup[`data-${index2}`] = dateRange[index2]?.trendIndexList[index]?.yvalue || 0
            })
            return {
                id: index,
                time: item.xvalueText,
                ...dataGroup
            }
        })
    }
    return {
        columns,
        dataSource
    }
}

// 运行参数仪表数据处理
export const paramsMeterTableData = (data) => {
    let tableData = []
    const columns = [{
        title: '时间',
        dataIndex: 'dateTimeText',
        width: '150px'
    }];
    if (!data || data.length === 0) return [];
    _.forEach(data, item => {
        const arrObj = {};
        const arrValue = {};
        arrValue.dateTimeText = item?.dateTimeText;
        item?.deviceAndMeters?.map(i => {
            i?.deviceAndAttrInfos?.map(child => {
                child?.attrAndValueInfos?.map(children => {
                    arrValue[`${child?.device.id}-${children?.meterAttr?.id}`] = children?.value || ''
                    // console.log(i?.device?.id , children?.value)
                })
            })
        })
        tableData.push(arrValue)
        // console.log( arrValue )
        // console.log( tableData)
    })
    // const dealData = (data) => {
    //     const array1 = []
    //     const timeData = _.uniq(data?.map(item => item?.dateTimeText));
    //     const tempTimeText = [];
    //     const resultArr = [];
    //     data.forEach(item => {
    //         if(!tempTimeText.includes(item.dateTimeText)){
    //             tempTimeText.push(item.dateTimeText);
    //             resultArr.push({

    //             })
    //         }
    //     });

    //     // array1.push(arrValue)
    //     return array1
    // }
    // console.log(tableData)
    const { deviceAndMeters } = data[0];
    if (deviceAndMeters && deviceAndMeters.length > 0) {
        deviceAndMeters.forEach(item => {
            columns.push({
                // dataIndex: item.device.id,
                title: item.device.name,
                children: item?.deviceAndAttrInfos && item?.deviceAndAttrInfos.length > 0 && item?.deviceAndAttrInfos.map(child => {
                    return {
                        title: child?.device?.name || '',
                        // dataIndex: child?.device?.id,
                        children: child?.attrAndValueInfos && child?.attrAndValueInfos?.length > 0 && child?.attrAndValueInfos?.map(children => ({
                            title: `${children?.meterAttr?.name || ''}(${children?.meterAttr?.unitName || ''})`,
                            dataIndex: `${child?.device.id}-${children?.meterAttr?.id}`,
                        })) || []
                    }
                }) || []
            })
        })
    }
    // console.log(tableData , `-----------------------`)
    return {
        columns,
        tableData
    }
}

// 运行参数设备数据处理
export const paramsDeviceTableData = (data) => {
    const tableData = []
    const columns = [{
        title: '仪表类型',
        width: '150px',
        children: [
            {
                title: '时间', dataIndex: 'dateTimeText',
                render: (text, row, index) => {
                    return {
                        children: text,
                        props: {
                            rowSpan: row.rowSpan,
                        },
                    };
                },
            },
            { title: '属性', dataIndex: 'meter' }
        ]
    }];
    if (!data || data.length === 0) return [];
    data.forEach(item => {

        if (item.deviceRBOS && item.deviceRBOS.length > 0) {
            item.deviceRBOS.forEach((i, j) => {
                const arrValue = {};
                arrValue.meter = i.name;
                arrValue.dateTimeText = item?.dateTimeText;
                arrValue.rowSpan = j === 0 ? item?.deviceRBOS?.length : 0;
                i?.ambos?.forEach(child => {
                    if (child?.parameters && child?.parameters?.length > 0) {
                        child?.parameters?.map(items => {
                            arrValue[items?.meterAttr?.name] = items?.value || ''
                        })
                    }
                })
                // arrValue[i.id] = paramsTypes
                tableData.push(arrValue)
            })
        }

    })
    const { deviceRBOS } = data[0];
    if (deviceRBOS && deviceRBOS.length > 0) {
        deviceRBOS.forEach(item => {
            if (item?.ambos && item?.ambos?.length > 0) {
                item?.ambos?.forEach(child => {
                    if(columns?.findIndex(x=>x?.title === child?.typeName) < 0)
                    columns?.push({
                        title: child?.typeName || '',
                        children: child?.parameters?.map(items=>({
                            title: `${items?.meterAttr?.name || ''}(${items?.meterAttr?.unitName || ''})`,
                            dataIndex: items?.meterAttr?.name,
                        }))
                    })
                })
            }
        })
    }
    // console.log(tableData, `-------`, columns)
    return {
        columns,
        tableData
    }
}