package com.casic.detector.utils

import com.casic.detector.bean.LabelBean
import jxl.Workbook
import java.io.File

object ExcelHub {
    fun read(filePath: String?): ArrayList<LabelBean> {
        val result = ArrayList<LabelBean>()

        if (filePath.isNullOrBlank()) {
            return result
        }

        val workbook = Workbook.getWorkbook(File(filePath))
        val sheet = workbook.getSheet(0)

        for (i in 1 until sheet.rows) {
            val labelBean = LabelBean()
            labelBean.pipelineType = sheet.getCell(0, i).contents
            labelBean.pipelineDiameter = sheet.getCell(1, i).contents
            labelBean.pipelineMaterial = sheet.getCell(2, i).contents
            labelBean.buryMethod = sheet.getCell(3, i).contents
            labelBean.buryDeep = sheet.getCell(4, i).contents
            labelBean.area = sheet.getCell(5, i).contents
            labelBean.line = sheet.getCell(6, i).contents
            labelBean.road = sheet.getCell(7, i).contents
            labelBean.constructTime = sheet.getCell(8, i).contents
            labelBean.owner = sheet.getCell(9, i).contents
            labelBean.objectId = sheet.getCell(10, i).contents
            labelBean.identifierId = sheet.getCell(11, i).contents
            labelBean.identifierType = sheet.getCell(12, i).contents
            labelBean.identifierDeep = sheet.getCell(13, i).contents
            labelBean.person = sheet.getCell(14, i).contents
            labelBean.lng = sheet.getCell(15, i).contents
            labelBean.lat = sheet.getCell(16, i).contents
            labelBean.installTime = sheet.getCell(17, i).contents
            labelBean.remark = sheet.getCell(18, i).contents
            labelBean.lowerType = sheet.getCell(19, i).contents
            labelBean.lowerDeep = sheet.getCell(20, i).contents
            labelBean.lowerDiameter = sheet.getCell(21, i).contents
            labelBean.lowerMaterial = sheet.getCell(22, i).contents
            labelBean.objectType = sheet.getCell(23, i).contents
            labelBean.color = sheet.getCell(24, i).contents
            labelBean.imagePath = sheet.getCell(25, i).contents

            result.add(labelBean)
        }
        workbook.close()

        return result
    }
}