package com.engine.recruit.entity.card;

import org.apache.commons.lang3.StringUtils;
import weaver.general.BaseBean;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author:dxfeng
 * @createTime: 2024/08/01
 * @version: 1.0
 */
public class EduInfo {
    private String time;
    private String start;
    private String end;
    private String school;
    private String professional;

    public void setStart(String start) {
        this.start = start;
    }

    public void setEnd(String end) {
        this.end = end;
    }

    public String getTime() {
        String dateTimeStart = formatEduDateTime(start);
        String dateTimeEnd = formatEduDateTime(end);
        if (StringUtils.isNotBlank(dateTimeStart) && StringUtils.isNotBlank(dateTimeEnd)) {
            return dateTimeStart + " - " + dateTimeEnd;
        }
        if (StringUtils.isNotBlank(dateTimeStart) && StringUtils.isBlank(dateTimeEnd)) {
            return dateTimeStart + " - 至今";
        }
        return "";

    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    public String getProfessional() {
        return professional;
    }

    public void setProfessional(String professional) {
        this.professional = professional;
    }

    /**
     * 日期格式化
     *
     * @param dateStr
     * @return
     */
    private String formatEduDateTime(String dateStr) {
        if(StringUtils.isBlank(dateStr)){
            return "";
        }
        String dateTime = "";
        SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy.MM");

        try {
            // 解析输入日期字符串
            Date date = inputFormat.parse(dateStr);
            // 格式化为目标格式
            dateTime = outputFormat.format(date);
        } catch (Exception e) {
            new BaseBean().writeLog("教育信息日期格式化失败", e);
        }
        return dateTime;
    }
}
