package com.cf.imes.module.system.controller.admin.funds.organamount.vo;

import lombok.Data;
import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;

/**
 * 组织收支趋势按创建时间分组 Resp VO
 *
 * @author Gqr
 * @since 2025/9/1 15:58
 */
@Data
public class OrganAmountGroupByCreateTimeRespVO implements Comparable<OrganAmountGroupByCreateTimeRespVO> {
    /**
     * 金额
     */
    private BigDecimal amount;

    /**
     * 时间
     */
    private String date;

    @Override
    public int compareTo(@NotNull OrganAmountGroupByCreateTimeRespVO other) {
        // 解析 orderDate 字符串为年、月、周
        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.amount.compareTo(other.amount);
    }
}
