export default {
    toObjData(excelData) {
        return excelData.map(item => {
            const monitorTime = new Date();
            monitorTime.setFullYear(item[0]);
            monitorTime.setMonth(item[10] - 1);
            monitorTime.setDate(item[11]);
            monitorTime.setHours(item[12]);
            monitorTime.setMinutes(item[13]);
            let quarter = 1;
            const month = item[10]
            if (month < 4) {
                quarter = 1
            } else if (month < 7) {
                quarter = 2
            } else if (month < 10) {
                quarter = 3
            } else {
                quarter = 4
            }
            const row = {
                regionCode: "450100",
                monitorYear: item[0],
                place: item[1],
                placeCode: item[2],
                road: item[3],
                area: item[4],
                city: '南宁',
                regionLevel: "市级",
                roadLength: item[5],
                roadWidth: item[6],
                smallTrafficFlow: item[7],
                largeTrafficFlow: item[8],
                timeSlot: item[9],
                monitorMonth: item[10],
                monitorDay: item[11],
                monitorHour: item[12],
                monitorMinute: item[13],
                monitorTime: monitorTime.getTime(),
                indexLeq: item[14],
                indexSd: item[15],
                indexL10: item[16],
                indexL50: item[17],
                indexL90: item[18],
                indexLmin: item[19],
                indexLmax: item[20],
                quarter
            }

            if (row.monitorHour >= 6 && row.monitorHour < 22 && row.timeSlot != "昼") {
                throw new Error(row.place + "时段有误")
            }
            
            if (row.monitorHour <6 && row.monitorHour >= 22 && row.timeSlot != "夜") {
                throw new Error(row.place + "时段有误")
            }
            if(row.indexL10 < row.indexL50 || row.indexL50 < row.indexL90){
                throw new Error(row.place + "数值有误")
            }

            return row;
        })

    },
    toPlaceData(excelData) {
        return excelData.map(item => {
            return {
                place: item[0],
                placeLng: item[1],
                placeLat: item[2],
                motorway: item[3],
                motorwayType: item[4],
                motorwayLevel: item[5],
                refObj: item[6],
                people: item[7],
                station: item[8],
                monitorInstrumentModel: item[9],
                monitorInstrumentCode: item[10],
                beforeMonitorValue: item[11],
                afterMonitorValue: item[12],
                soundPressureValue: item[13],
                soundInstrumentModel: item[14],
                soundInstrumentCode: item[15],

            }
        })

    },
    // 解析县级数据
    toAreaObjData(excelData) {
        return excelData.map(item => {
            const monitorTime = new Date();
            monitorTime.setFullYear(item[1]);
            monitorTime.setMonth(item[14] - 1);
            monitorTime.setDate(item[15]);
            monitorTime.setHours(item[16]);
            monitorTime.setMinutes(item[17]);
            let quarter = 1;
            const month = item[14]
            if (month < 4) {
                quarter = 1
            } else if (month < 7) {
                quarter = 2
            } else if (month < 10) {
                quarter = 3
            } else {
                quarter = 4
            }
            let timeSlot = "夜";
            if (item[16] >= 6 && item[16] <= 22) {
                timeSlot = "昼"
            }
            const row =  {
                regionCode: item[0],
                regionLevel: "县级",
                monitorYear: item[1],
                placeCode: item[2],
                place: item[3],
                placeLng: item[4],
                placeLat: item[5],
                road: item[6],
                roadLength: item[7],
                roadWidth: item[8],
                motorway: item[9],
                motorwayType: item[10],
                motorwayLevel: item[11],
                refObj: item[12],
                people: item[13],
                monitorMonth: item[14],
                monitorDay: item[15],
                monitorHour: item[16],
                monitorMinute: item[17],
                smallTrafficFlow: item[18],
                largeTrafficFlow: item[19],
                indexLeq: item[20],
                indexL10: item[21],
                indexL50: item[22],
                indexL90: item[23],
                indexLmax: item[24],
                indexLmin: item[25],
                indexSd: item[26],
                station: item[27],
                monitorInstrumentModel: item[28],
                monitorInstrumentCode: item[29],
                beforeMonitorValue: item[30],
                afterMonitorValue: item[31],
                soundPressureValue: item[32],
                soundInstrumentModel: item[33],
                soundInstrumentCode: item[34],
                remark: item[35],
                city: '南宁',
                timeSlot,
                monitorTime: monitorTime.getTime(),
                quarter

            }
            if(row.indexL10 < row.indexL50 || row.indexL50 < row.indexL90){
                throw new Error(row.place + "数值有误")
            }
            return row;
        })
    }
}