package cn.sagacloud.server.algorithm.test

import cn.sagacloud.server.algorithm.models.excel.IsPassedEnum
import cn.sagacloud.server.algorithm.models.excel.nonBlockingReport.EquipNameCodeReport
import cn.sagacloud.server.algorithm.services.excel.ExcelService
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner

/**
 *
 *
 * @author jxing
 */
@RunWith(SpringRunner::class)
@SpringBootTest
class ExcelTest {

    @Autowired
    lateinit var excelService: ExcelService

    @Before
    fun readExcel(){
        excelService.readBlockingExcel2007()
    }

    @Test
    fun readTest(){
        var arr = excelService.getSheetAtIndex(0)
        print2DArr(arr)
        arr = excelService.getSheetAtIndex(1)
        print2DArr(arr)
        arr = excelService.getSheetAtIndex(2)
        print2DArr(arr)
        arr = excelService.getSheetAtIndex(3)
        print2DArr(arr)
        arr = excelService.getSheetAtIndex(4)
        print2DArr(arr)
        arr = excelService.getSheetAtIndex(5)
        print2DArr(arr)

    }

    @Test
    fun randomWriteTest(){
        excelService.randomWrite(0, 0, 1, 555)
    }

    @Test
    fun writeSheet(){
        var report = EquipNameCodeReport()
        for(i in 0..99 step 1) {
            var row = EquipNameCodeReport.Data()
            row.floorName = "F${i}"
            row.isPassed = IsPassedEnum.Pass
            row.familyName = "Name $i"
            row.note = "aaa"
            report.rowValue.add(row)
        }
        excelService.insertReport(report)
    }

    fun print2DArr(arr : ArrayList<ArrayList<Any>>){
        var index = 0
        for(subArr in arr){
            println("size: ${subArr.size}, row num: ${++index}")
            for(value in subArr){
                print("$value \t")
            }
            println("")
        }
    }
}