package com.cf.imes.module.executor.controller.admin.plan.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.jetbrains.annotations.NotNull;

/**
 * @author Gqr
 * @since 2024/8/7 15:12
 */

@Schema(description = "管理后台 - 排单统计RespVO")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString(callSuper = true)
public class OrderPlanStatisticsCountRespVO implements Comparable<OrderPlanStatisticsCountRespVO> {

    @Schema(description = "数量")
    private Integer count;

    @Schema(description = "统计时间")
    private String date;

    @Override
    public int compareTo(@NotNull OrderPlanStatisticsCountRespVO other) {
        // 解析 date 字符串为年、月、周
        String[] partsThis = date.split("-");
        String[] partsOther = other.date.split("-");

        // 比较年份
        int yearComparison = Integer.compare(Integer.parseInt(partsThis[0]), Integer.parseInt(partsOther[0]));
        if (yearComparison != 0) {
            return yearComparison;
        }

        // 比较月份
        if (partsThis.length > 1 && partsOther.length > 1) {
            int monthComparison = Integer.compare(Integer.parseInt(partsThis[1]), Integer.parseInt(partsOther[1]));
            if (monthComparison != 0) {
                return monthComparison;
            }
        }

        // 比较周数
        if (partsThis.length > 2 && partsOther.length > 2) {
            int weekComparison = Integer.compare(Integer.parseInt(partsThis[2]), Integer.parseInt(partsOther[2]));
            if (weekComparison != 0) {
                return weekComparison;
            }
        }

        // 如果所有部分都相同，则按面积排序
        return this.count.compareTo(other.count);
    }
}
