package top.zbeboy.isy.service.export

import org.apache.poi.ss.usermodel.Row
import top.zbeboy.isy.domain.tables.pojos.GraduationPracticeUnify
import top.zbeboy.isy.service.util.DateTimeUtils
import top.zbeboy.isy.service.util.ExportUtils

/**
 * Created by zbeboy 2017-12-28 .
 **/
class GraduationPracticeUnifyExport(data: List<GraduationPracticeUnify>) : ExportUtils<GraduationPracticeUnify>(data) {

    // 序号
    private var sequence = 0

    override fun createHeader(row: Row) {
        row.createCell(0).setCellValue("序号")
        row.createCell(1).setCellValue("学生姓名")
        row.createCell(2).setCellValue("专业班级")
        row.createCell(3).setCellValue("性别")
        row.createCell(4).setCellValue("学号")
        row.createCell(5).setCellValue("电话号码")
        row.createCell(6).setCellValue("邮箱（qq）")
        row.createCell(7).setCellValue("父母联系方式")
        row.createCell(8).setCellValue("班主任")
        row.createCell(9).setCellValue("联系方式")
        row.createCell(10).setCellValue("实习单位名称")
        row.createCell(11).setCellValue("实习单位地址")
        row.createCell(12).setCellValue("实习单位联系人")
        row.createCell(13).setCellValue("联系方式")
        row.createCell(14).setCellValue("校内指导教师")
        row.createCell(15).setCellValue("联系方式")
        row.createCell(16).setCellValue("实习期间")
        row.createCell(17).setCellValue("承诺书")
        row.createCell(18).setCellValue("安全责任书")
        row.createCell(19).setCellValue("实践协议书")
        row.createCell(20).setCellValue("实习申请书")
        row.createCell(21).setCellValue("实习接收")
        row.createCell(22).setCellValue("安全教育协议")
        row.createCell(23).setCellValue("父母同意书")
    }

    override fun createCell(row: Row, t: GraduationPracticeUnify) {
        sequence++
        row.createCell(0).setCellValue(sequence.toDouble())
        row.createCell(1).setCellValue(t.studentName)
        row.createCell(2).setCellValue(t.collegeClass)
        row.createCell(3).setCellValue(t.studentSex)
        row.createCell(4).setCellValue(t.studentNumber)
        row.createCell(5).setCellValue(t.phoneNumber)
        row.createCell(6).setCellValue(t.qqMailbox)
        row.createCell(7).setCellValue(t.parentalContact)
        row.createCell(8).setCellValue(t.headmaster)
        row.createCell(9).setCellValue(t.headmasterContact)
        row.createCell(10).setCellValue(t.graduationPracticeUnifyName)
        row.createCell(11).setCellValue(t.graduationPracticeUnifyAddress)
        row.createCell(12).setCellValue(t.graduationPracticeUnifyContacts)
        row.createCell(13).setCellValue(t.graduationPracticeUnifyTel)
        row.createCell(14).setCellValue(t.schoolGuidanceTeacher)
        row.createCell(15).setCellValue(t.schoolGuidanceTeacherTel)
        row.createCell(16).setCellValue(DateTimeUtils.formatDate(t.startTime, "yyyy-MM-dd") + '至' + DateTimeUtils.formatDate(t.endTime, "yyyy-MM-dd"))
        row.createCell(17).setCellValue(dealByte(t.commitmentBook))
        row.createCell(18).setCellValue(dealByte(t.safetyResponsibilityBook))
        row.createCell(19).setCellValue(dealByte(t.practiceAgreement))
        row.createCell(20).setCellValue(dealByte(t.internshipApplication))
        row.createCell(21).setCellValue(dealByte(t.practiceReceiving))
        row.createCell(22).setCellValue(dealByte(t.securityEducationAgreement))
        row.createCell(23).setCellValue(dealByte(t.parentalConsent))
    }

    private fun dealByte(b: Byte?): String {
        return if (b != null && b == 1.toByte()) {
            "已交"
        } else "未交"
    }
}