package com.fs.course.vo;

import com.fs.common.annotation.Excel;
import lombok.Data;

import java.math.BigDecimal;

/**
 * @author MixLiu
 * @date 2025/11/10 下午3:47)
 */
@Data
public class StatisticsSummaryVO {

    private Long companyId;

    @Excel(name = "公司名称")
    private String companyName;

    private Long deptId;

    @Excel(name = "部门名称")
    private String deptName;

    @Excel(name = "统计日期范围")
    private String dateRange;

    // 原始字节数（不用于导出）
    private Long totalInternetTraffic;

    @Excel(name = "总流量 (GB)")
    private String formattedTotalTraffic;

    @Excel(name = "金额（元）")
    private String totalAmount;

    // 工具方法：根据 totalInternetTraffic 自动计算 formattedTotalTraffic
    public void formatTraffic() {
        if (this.totalInternetTraffic == null) {
            this.formattedTotalTraffic = "0.0000 GB";
        } else {
            BigDecimal gb = new BigDecimal(this.totalInternetTraffic.doubleValue()).divide(new BigDecimal(1024 * 1024 * 1024)).setScale(4, BigDecimal.ROUND_HALF_UP);
//            double gb = this.totalInternetTraffic.doubleValue() / (1024 * 1024 * 1024);
            this.formattedTotalTraffic = String.format("%.4f GB", gb);
        }
    }

    /**
     * 根据 totalInternetTraffic 计算金额值
     * @param proportion
     */
    public void calculateAmount(BigDecimal proportion){
        if (this.totalInternetTraffic == null) {
            this.totalAmount = "0.00（元）";
        } else {
            BigDecimal gb = new BigDecimal(this.totalInternetTraffic.doubleValue()).divide(new BigDecimal(1024 * 1024 * 1024)).setScale(4, BigDecimal.ROUND_HALF_UP);
            BigDecimal bigDecimal = proportion.multiply(gb).setScale(2, BigDecimal.ROUND_HALF_UP);
            this.totalAmount = String.format("%.2f（元）",bigDecimal);
        }
    }


}
