package com.gic.haoban.manage.web.qo.content.statistics;

import com.gic.api.base.commons.BasePageInfo;
import com.gic.haoban.common.utils.DateUtil;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;

import java.util.Date;
import java.util.List;

/**
 * @Author MUSI
 * @Date 2023/3/23 12:49 PM
 * @Description
 * @Version
 **/
@Data
public class MaterialStatisticsBaseQO extends BasePageInfo {

    /**
     * 企业id
     */
    private String enterpriseId;

    /**
     * 微信企业id
     */
    private String wxEnterpriseId;

    /**
     * 导购id
     */
    private String clerkId;

    /**
     * 门店id
     */
    private String storeId;

    /**
     * 门店id列表
     */
    private List<String> storeIdList;

    /**
     * 开始时间
     */
    private String startDate;

    /**
     * 结束时间
     */
    private String endDate;

    /**
     * 时间筛选
     * 1 过去7天(默认选中),2 过去30天,3 过去60天,4 过去90天,5本周,6 本月,7 上月,8 上上月,9 上上上月
     */
    private Integer fixedDateDiff;

    private Integer storeStatusFilter;


    public String getEnterpriseId() {
        return enterpriseId;
    }

    public void setEnterpriseId(String enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public String getClerkId() {
        return clerkId;
    }

    public void setClerkId(String clerkId) {
        this.clerkId = clerkId;
    }

    public String getStoreId() {
        return storeId;
    }

    public void setStoreId(String storeId) {
        this.storeId = storeId;
    }

    public List<String> getStoreIdList() {
        return storeIdList;
    }

    public void setStoreIdList(List<String> storeIdList) {
        this.storeIdList = storeIdList;
    }

    public String getStartDate() {
        if (StringUtils.isNotBlank(this.startDate)) {
            return this.startDate;
        }
        if (this.fixedDateDiff != null) {
            return convertStartDate(this.fixedDateDiff);
        }
        return startDate;
    }

    public void setStartDate(String startDate) {
        this.startDate = startDate;
    }

    public String getEndDate() {
        if (StringUtils.isBlank(this.endDate)) {
            return DateUtil.dateToStr(DateUtils.addDays(new Date(), -1), "yyyy-MM-dd");
        }
        return endDate;
    }

    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }

    public Integer getStoreStatusFilter() {
        return storeStatusFilter;
    }

    public void setStoreStatusFilter(Integer storeStatusFilter) {
        this.storeStatusFilter = storeStatusFilter;
    }

    public String convertStartDate(Integer fixedDateDiff) {
        if (fixedDateDiff == null) {
            return null;
        }
        switch (fixedDateDiff) {
            case 1:
                return DateUtil.dateToStr(DateUtils.addDays(new Date(), -7), "yyyy-MM-dd");
            case 2:
                return DateUtil.dateToStr(DateUtils.addDays(new Date(), -30), "yyyy-MM-dd");
            case 3:
                return DateUtil.dateToStr(DateUtils.addDays(new Date(), -60), "yyyy-MM-dd");
            case 4:
                return DateUtil.dateToStr(DateUtils.addDays(new Date(), -90), "yyyy-MM-dd");
            case 5:
                return DateUtil.dateToStr(cn.hutool.core.date.DateUtil.beginOfWeek(new Date()), "yyyy-MM-dd");
            case 6:
                return DateUtil.dateToStr(cn.hutool.core.date.DateUtil.beginOfMonth(new Date()), "yyyy-MM-dd");
            case 7:
                return DateUtil.dateToStr(cn.hutool.core.date.DateUtil.lastMonth(), "yyyy-MM-dd");
            case 8:
                return DateUtil.dateToStr(cn.hutool.core.date.DateUtil.beginOfMonth(cn.hutool.core.date.DateUtil.offsetMonth(new Date(), -2)), "yyyy-MM-dd");
            case 9:
                return DateUtil.dateToStr(cn.hutool.core.date.DateUtil.beginOfMonth(cn.hutool.core.date.DateUtil.offsetMonth(new Date(), -3)), "yyyy-MM-dd");
            default:
                return null;
        }
    }
}
