package cn.com.ty.lift.batch.applet.dao.model.request;

import cn.com.ty.lift.batch.applet.constants.DataStatisticsConstants;
import cn.com.ty.lift.batch.applet.util.DataStatisticsUtil;
import cn.hutool.core.date.DatePattern;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author huangyuan
 * @date 2020/2/3
 * @description
 */
@Data
public class CommonRequest implements Serializable {
    /**
     * 起始时间-日期格式
     */
    private LocalDateTime startTimeDate;
    /**
     * 起始时间-字符串格式
     */
    private String startTimeDateStr;
    /**
     * 终止时间-日期格式
     */
    private LocalDateTime endTimeDate;
    /**
     * 结束时间-字符串形式
     */
    private String endTimeDateStr;

    /**
     * 公司id
     */
    private Long mtCompanyId;

    /**
     * 5 - all
     */
    private String numFlag;

    public LocalDateTime getStartTimeDate() {
        if (startTimeDate != null) {
            return startTimeDate;
        }
        if(StringUtils.isNotBlank(startTimeDateStr)) {
            return DataStatisticsUtil.getLocalDateTimeFromStr(startTimeDateStr,
                    DataStatisticsConstants.DATA_STATISTICS_TIME_FORMAT);
        }
        return DataStatisticsUtil.getYearFirstTime();
    }

    public LocalDateTime getEndTimeDate() {
        if (endTimeDate != null) {
            return endTimeDate;
        }
        if(StringUtils.isNotBlank(endTimeDateStr)) {
            return DataStatisticsUtil.getLocalDateTimeFromStr(endTimeDateStr,
                    DataStatisticsConstants.DATA_STATISTICS_TIME_FORMAT);
        }
        return LocalDateTime.now();
    }

    public String getStartTimeDateStr() {
        if (StringUtils.isNotBlank(startTimeDateStr)) {
            return startTimeDateStr;
        }
        return DataStatisticsUtil.getYearFirstTime().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN));
    }

    public String getEndTimeDateStr() {
        if (StringUtils.isNotBlank(endTimeDateStr)) {
            return endTimeDateStr;
        }
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN));
    }
}
