package com.gic.haoban.manage.web.utils.eventtracking;

import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.DataApiUtils;
import com.gic.commons.util.DateUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author guojx
 * @Date 2024/5/30 15:34
 */
public class DateExpandUtils {

    public static List<String> getDateList(String startDate, String endDate, Integer dateType) {
        //数据类型 1天 2近7天 3近30天 4周 5月
        List<String> list = new ArrayList<>();
        if (dateType == null) {
            dateType = 1;
        }
        try {
            switch (dateType) {
                case 1:
                    list.add(startDate);
                    break;
                case 4:
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("startDate", startDate);
                    jsonObject.put("pageNum", 1);
                    jsonObject.put("pageSize", 100);
                    Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_pub_date_week");
                    List<JSONObject> data = DataApiUtils.getPageList(res);
                    list = data.stream().map(e ->e.getString("weekYear")).collect(Collectors.toList());
                    break;
                default:
                    list = DateUtil.getBetweenDates(startDate, endDate);
            }
        } catch (Exception e) {

        }
        return list;
    }
}
