package cn.sagacloud.server.algorithm.models.scheduler

import cn.sagacloud.server.algorithm.models.scheduler.items.NameCodeCheckItem
import cn.sagacloud.server.algorithm.models.excel.IsPassedEnum
import cn.sagacloud.server.algorithm.models.excel.nonBlockingReport.EquipNameCodeReport
import cn.sagacloud.server.algorithm.models.excel.report.BlockingTotalReport
import cn.sagacloud.server.algorithm.services.excel.ExcelService
import com.alibaba.fastjson.annotation.JSONField
import com.sybotan.service.utils.SSpringContextUtil

/**
 *
 *
 * @author jxing
 */
class NameCodeCheckResult {

    @JSONField(name = "Name")
    var name : String? = null

    @JSONField(name = "Content")
    var content : ArrayList<NameCodeCheckItem>? = null

    @JSONField(serialize = false, deserialize = false)
    var report : EquipNameCodeReport = SSpringContextUtil.getBean(EquipNameCodeReport::class.java) as EquipNameCodeReport

    /**
     * 将当前的检查结果写入excel里
     */
    fun writeReport(excelService: ExcelService, floorName: String?, totalReport: BlockingTotalReport){
        if(content == null || content!!.isEmpty())
        // 异常处理
            return
        for(item in content!!){
            val row = EquipNameCodeReport.Data()
            row.familyName = item.familyName?:""
            row.note = item.resultMsg ?: ""
            row.floorName = floorName?: ""
            if("success".equals(item.result, true)){
                row.isPassed = IsPassedEnum.Pass
            }else{
                row.isPassed = IsPassedEnum.Unpass
            }
            report.rowValue.add(row)
        }
        excelService.insertReport(report)
    }
}