package com.casic.electric.detector.utils

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

object ExcelHub {
    fun readLabel(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.markerObjType = sheet.getCell(0, i).contents
            labelBean.markerNumber = sheet.getCell(1, i).contents
            labelBean.objectName = sheet.getCell(2, i).contents
            labelBean.voltageLevel = sheet.getCell(3, i).contents
            labelBean.transformerModel = sheet.getCell(4, i).contents
            labelBean.holeCount = sheet.getCell(5, i).contents
            labelBean.capacity = sheet.getCell(6, i).contents
            labelBean.wellCoverMaterial = sheet.getCell(7, i).contents
            labelBean.coverDepth = sheet.getCell(8, i).contents
            labelBean.transformerSpec = sheet.getCell(9, i).contents
            labelBean.inlineName = sheet.getCell(10, i).contents
            labelBean.size = sheet.getCell(11, i).contents
            labelBean.bottomDepth = sheet.getCell(12, i).contents
            labelBean.height = sheet.getCell(13, i).contents
            labelBean.crossPipeLine = sheet.getCell(14, i).contents
            labelBean.inlineCount = sheet.getCell(15, i).contents
            labelBean.lineNumber = sheet.getCell(16, i).contents
            labelBean.jointCount = sheet.getCell(17, i).contents
            labelBean.outlineCount = sheet.getCell(18, i).contents
            labelBean.remainingChannels = sheet.getCell(19, i).contents
            labelBean.cabinetType = sheet.getCell(20, i).contents
            labelBean.tieCable1 = sheet.getCell(21, i).contents
            labelBean.tieCable2 = sheet.getCell(22, i).contents
            labelBean.casingMaterial = sheet.getCell(23, i).contents
            labelBean.casingSpec = sheet.getCell(24, i).contents
            labelBean.constructTime = sheet.getCell(25, i).contents
            labelBean.inspectionUnit = sheet.getCell(26, i).contents
            labelBean.area = sheet.getCell(27, i).contents
            labelBean.road = sheet.getCell(28, i).contents
            labelBean.memo1 = sheet.getCell(29, i).contents
            labelBean.memo2 = sheet.getCell(30, i).contents
            labelBean.memo3 = sheet.getCell(31, i).contents
            labelBean.markerId = sheet.getCell(32, i).contents
            labelBean.markerType = sheet.getCell(33, i).contents
            labelBean.owner = sheet.getCell(34, i).contents
            labelBean.markerDepth = sheet.getCell(35, i).contents
            labelBean.electricTagCount = sheet.getCell(36, i).contents
            labelBean.installedTime = sheet.getCell(37, i).contents
            labelBean.longitude = sheet.getCell(38, i).contents
            labelBean.latitude = sheet.getCell(39, i).contents
            labelBean.markerMemo1 = sheet.getCell(40, i).contents
            labelBean.markerMemo2 = sheet.getCell(41, i).contents
            labelBean.markerMemo3 = sheet.getCell(42, i).contents

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

        return result
    }

    fun readSmallLabel(filePath: String?): ArrayList<SmallLabelBean> {
        val result = ArrayList<SmallLabelBean>()

        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 = SmallLabelBean()
            labelBean.markerId = sheet.getCell(0, i).contents
            labelBean.locationNumber = sheet.getCell(1, i).contents
            labelBean.locationName = sheet.getCell(2, i).contents
            labelBean.electricMarkerId = sheet.getCell(3, i).contents
            labelBean.cableName = sheet.getCell(4, i).contents
            labelBean.cableNumber = sheet.getCell(5, i).contents
            labelBean.line = sheet.getCell(6, i).contents
            labelBean.voltageLevel = sheet.getCell(7, i).contents
            labelBean.cableType = sheet.getCell(8, i).contents
            labelBean.cableSpec = sheet.getCell(9, i).contents
            labelBean.cableBrand = sheet.getCell(10, i).contents
            labelBean.cableStart = sheet.getCell(11, i).contents
            labelBean.cableEnd = sheet.getCell(12, i).contents
            labelBean.hasJoint = sheet.getCell(13, i).contents
            labelBean.jointCreator = sheet.getCell(14, i).contents
            labelBean.imagePath = sheet.getCell(15, i).contents
            labelBean.memo1 = sheet.getCell(16, i).contents
            labelBean.memo2 = sheet.getCell(17, i).contents
            labelBean.memo3 = sheet.getCell(18, i).contents

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

        return result
    }
}