package com.yuchen.saas.parking.api.util;

import com.yuchen.saas.parking.api.vo.PieChartVo;
import com.yuchen.saas.parking.api.vo.SevenVo;
import org.nest.springwrap.core.tool.utils.DateUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 图表数据封装类
 */
public class PieChartUtils {
    /**
     * 封装近七天统计数据图表对象
     * 对象数据形式：
     * {
     * 	"abscissa": [
     * 		"yyyy-MM-dd",
     * 		"yyyy-MM-dd",
     * 		"yyyy-MM-dd",
     * 		"yyyy-MM-dd",
     * 		"yyyy-MM-dd",
     * 		"yyyy-MM-dd",
     * 		"yyyy-MM-dd"
     * 	],
     * 	"ordinate": [
     * 		"0",
     * 		"0",
     * 		"0",
     * 		"0",
     * 		"0",
     * 		"0",
     * 		"0"
     * 	]
     * }
     * @param voList
     * @return
     */
    public static PieChartVo getPicChart(List<SevenVo> voList) {
        // 定义图表对象
        PieChartVo pieChartVo = new PieChartVo();
        // 选项名(横坐标)
        List<String> abscissa = new ArrayList<String>();
        // 选项名对应的值(纵坐标)[有可能是整数、有可能是小数等]
        List<Object> ordinate = new ArrayList<Object>();

        if(voList != null && voList.size() > 0) {
            voList.forEach(peopleCount ->{
                abscissa.add(DateUtil.format(peopleCount.getCreateTime(), "yyyy-MM-dd"));
                ordinate.add(peopleCount.getValue());
            });
        }

        // 封装图表集合数据
        pieChartVo.setAbscissa(abscissa);
        pieChartVo.setOrdinate(ordinate);
        return pieChartVo;
    }
}
