package cn.newfeifan.mall.framework.common.pojo.echarts;

import lombok.Builder;
import lombok.Data;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 返回echarts的结果类
 */

@Data
@Builder
public class EChartsResult {

    /**
     * day对象
     */
    private Axis xaxis;

    /**
     * 数量对象集合
     */
    private List<Series> series;


    @Data
    public static class Axis {
        private String type;
        private List<LocalDate> data;

        public List<String> getData(){
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            return data.stream().map(date -> date.format(formatter)).collect(Collectors.toList());
        }

        public Axis(){
            this.type = "category";
        }
    }

    @Data
    public static class Series{
        private Long money;
        private Integer count;
    }
}
