package com.persagy.revit.models.scheduler

import com.alibaba.fastjson.annotation.JSONField
import com.persagy.revit.models.excel.IsPassedEnum
import com.persagy.revit.models.excel.nonBlockingReport.EquipNameCodeReport
import com.persagy.revit.models.excel.report.BlockingTotalReport
import com.persagy.revit.models.scheduler.items.NameCodeCheckItem
import com.persagy.revit.services.excel.ExcelService
import com.persagy.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)
    }
}