package com.slodon.b2b2c.util;

import com.slodon.b2b2c.core.response.PagerInfo;
import com.slodon.b2b2c.core.util.StringUtil;
import com.slodon.b2b2c.enums.StatsTimeType;
import com.slodon.b2b2c.model.statistics.*;
import com.slodon.b2b2c.statistics.example.*;
import com.slodon.b2b2c.statistics.pojo.base.*;
import com.slodon.b2b2c.vo.statistics.MovableGoodsVO;
import com.slodon.b2b2c.vo.statistics.SalesTrendVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 统计model工具类
 */
@Component
public class StatsModelUtil {

    @Resource
    private PlatformHourModel platformHourModel;
    @Resource
    private PlatformDayModel platformDayModel;
    @Resource
    private PlatformWeekModel platformWeekModel;
    @Resource
    private PlatformMonthModel platformMonthModel;
    @Resource
    private PlatformYearModel platformYearModel;
    @Resource
    private TerminalHourModel terminalHourModel;
    @Resource
    private TerminalDayModel terminalDayModel;
    @Resource
    private TerminalWeekModel terminalWeekModel;
    @Resource
    private TerminalMonthModel terminalMonthModel;
    @Resource
    private TerminalYearModel terminalYearModel;
    @Resource
    private StoreHourModel storeHourModel;
    @Resource
    private StoreDayModel storeDayModel;
    @Resource
    private StoreWeekModel storeWeekModel;
    @Resource
    private StoreMonthModel storeMonthModel;
    @Resource
    private StoreYearModel storeYearModel;
    @Resource
    private GoodsHourModel goodsHourModel;
    @Resource
    private GoodsDayModel goodsDayModel;
    @Resource
    private GoodsWeekModel goodsWeekModel;
    @Resource
    private GoodsMonthModel goodsMonthModel;
    @Resource
    private GoodsYearModel goodsYearModel;
    @Resource
    private ProvinceHourModel provinceHourModel;
    @Resource
    private ProvinceDayModel provinceDayModel;
    @Resource
    private ProvinceWeekModel provinceWeekModel;
    @Resource
    private ProvinceMonthModel provinceMonthModel;
    @Resource
    private ProvinceYearModel provinceYearModel;
    @Resource
    private BrandHourModel brandHourModel;
    @Resource
    private BrandDayModel brandDayModel;
    @Resource
    private BrandWeekModel brandWeekModel;
    @Resource
    private BrandMonthModel brandMonthModel;
    @Resource
    private BrandYearModel brandYearModel;
    @Resource
    private CategoryHourModel categoryHourModel;
    @Resource
    private CategoryDayModel categoryDayModel;
    @Resource
    private CategoryWeekModel categoryWeekModel;
    @Resource
    private CategoryMonthModel categoryMonthModel;
    @Resource
    private CategoryYearModel categoryYearModel;

    /**
     * 返回对应的平台列表数据
     *
     * @param timeType
     * @param startTime
     * @param endTime
     * @return
     */
    public List<? extends PlatformBase> getPlatformList(StatsTimeType timeType, String webSite, Date startTime, Date endTime) {
        List<? extends PlatformBase> list = new ArrayList<>();
        switch (timeType) {
            case HOUR:
                PlatformHourExample example = new PlatformHourExample();
                example.setStatsTimeAfter(startTime);
                example.setStatsTimeBefore(endTime);
                example.setWebSite(webSite);
                list = platformHourModel.getPlatformHourList(example, null);
                break;
            case WEEK:
                PlatformWeekExample weekExample = new PlatformWeekExample();
                weekExample.setStatsTimeAfter(startTime);
                weekExample.setStatsTimeBefore(endTime);
                weekExample.setWebSite(webSite);
                list = platformWeekModel.getPlatformWeekList(weekExample, null);
                break;
            case MONTH:
                PlatformMonthExample monthExample = new PlatformMonthExample();
                monthExample.setStatsTimeAfter(startTime);
                monthExample.setStatsTimeBefore(endTime);
                monthExample.setWebSite(webSite);
                list = platformMonthModel.getPlatformMonthList(monthExample, null);
                break;
            case YEAR:
                PlatformYearExample yearExample = new PlatformYearExample();
                yearExample.setStatsTimeAfter(startTime);
                yearExample.setStatsTimeBefore(endTime);
                yearExample.setWebSite(webSite);
                list = platformYearModel.getPlatformYearList(yearExample, null);
                break;
            case DAY:
                PlatformDayExample dayExample = new PlatformDayExample();
                dayExample.setStatsTimeAfter(startTime);
                dayExample.setStatsTimeBefore(endTime);
                dayExample.setWebSite(webSite);
                list = platformDayModel.getPlatformList(dayExample);
                break;
        }
        return list;
    }

    /**
     * 返回商品动销趋势列表数据
     *
     * @param timeType
     * @param startTime
     * @param endTime
     * @param webSite
     * @return
     */
    public List<MovableGoodsVO> getPlatformTrendList(StatsTimeType timeType, Date startTime, Date endTime,String webSite) {
        List<MovableGoodsVO> list = new ArrayList<>();
        switch (timeType) {
            case HOUR:
                PlatformHourExample example = new PlatformHourExample();
                example.setStatsTimeAfter(startTime);
                example.setStatsTimeBefore(endTime);
                example.setWebSite(webSite);
                list = platformHourModel.getPlatformTrendList(example);
                break;
            case DAY:
            case WEEK:
            case MONTH:
                PlatformDayExample dayExample = new PlatformDayExample();
                dayExample.setStatsTimeAfter(startTime);
                dayExample.setStatsTimeBefore(endTime);
                dayExample.setWebSite(webSite);
                list = platformDayModel.getPlatformTrendList(dayExample);
                break;
            case YEAR:
                PlatformMonthExample monthExample = new PlatformMonthExample();
                monthExample.setStatsTimeAfter(startTime);
                monthExample.setStatsTimeBefore(endTime);
                monthExample.setWebSite(webSite);
                list = platformMonthModel.getPlatformTrendList(monthExample);
                break;
        }
        return list;
    }

    /**
     * 返回对应的终端列表数据
     *
     * @param timeType
     * @param startTime
     * @param endTime
     * @return
     */
    public List<? extends TerminalBase> getTerminalList(StatsTimeType timeType, Date startTime, Date endTime, String terminalType) {
        List<? extends TerminalBase> list = new ArrayList<>();
        switch (timeType) {
            case HOUR:
                TerminalHourExample example = new TerminalHourExample();
                example.setStatsTimeAfter(startTime);
                example.setStatsTimeBefore(endTime);
                example.setTerminalCode(terminalType);
                list = terminalHourModel.getTerminalHourList(example, null);
                break;
            case WEEK:
                TerminalWeekExample weekExample = new TerminalWeekExample();
                weekExample.setStatsTimeAfter(startTime);
                weekExample.setStatsTimeBefore(endTime);
                weekExample.setTerminalCode(terminalType);
                list = terminalWeekModel.getTerminalWeekList(weekExample, null);
                break;
            case MONTH:
                TerminalMonthExample monthExample = new TerminalMonthExample();
                monthExample.setStatsTimeAfter(startTime);
                monthExample.setStatsTimeBefore(endTime);
                monthExample.setTerminalCode(terminalType);
                list = terminalMonthModel.getTerminalMonthList(monthExample, null);
                break;
            case YEAR:
                TerminalYearExample yearExample = new TerminalYearExample();
                yearExample.setStatsTimeAfter(startTime);
                yearExample.setStatsTimeBefore(endTime);
                yearExample.setTerminalCode(terminalType);
                list = terminalYearModel.getTerminalYearList(yearExample, null);
                break;
            case DAY:
                TerminalDayExample dayExample = new TerminalDayExample();
                dayExample.setStatsTimeAfter(startTime);
                dayExample.setStatsTimeBefore(endTime);
                dayExample.setTerminalCode(terminalType);
                list = terminalDayModel.getTerminalList(dayExample);
                break;
        }
        return list;
    }

    /**
     * 返回各终端销售变化趋势列表数据
     *
     * @param timeType
     * @param startTime
     * @param endTime
     * @return
     */
    public List<SalesTrendVO> getTerminalTrendList(StatsTimeType timeType, Date startTime, Date endTime) {
        List<SalesTrendVO> list = new ArrayList<>();
        switch (timeType) {
            case HOUR:
                TerminalHourExample example = new TerminalHourExample();
                example.setStatsTimeAfter(startTime);
                example.setStatsTimeBefore(endTime);
                list = terminalHourModel.getTerminalTrendList(example);
                break;
            case DAY:
            case WEEK:
            case MONTH:
                TerminalDayExample dayExample = new TerminalDayExample();
                dayExample.setStatsTimeAfter(startTime);
                dayExample.setStatsTimeBefore(endTime);
                list = terminalDayModel.getTerminalTrendList(dayExample);
                break;
            case YEAR:
                TerminalMonthExample monthExample = new TerminalMonthExample();
                monthExample.setStatsTimeAfter(startTime);
                monthExample.setStatsTimeBefore(endTime);
                list = terminalMonthModel.getTerminalTrendList(monthExample);
                break;
        }
        return list;
    }

    /**
     * 返回对应的店铺列表数据
     *
     * @param timeType
     * @param startTime
     * @param endTime
     * @return
     */
    public List<? extends StoreBase> getStoreList(StatsTimeType timeType, Date startTime, Date endTime, String webSite, Integer sort,
                                                  String sortType, Long storeId, PagerInfo pager) {
        List<? extends StoreBase> list = new ArrayList<>();
        //排序规则
        String orderBy;
        if (sortType.equals("sale")) {
            if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                orderBy = "order_pay_num DESC";
            } else {
                orderBy = "order_pay_amount DESC";
            }
        } else {
            if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                orderBy = "visitor_num DESC";
            } else {
                orderBy = "view_num DESC";
            }
        }
        switch (timeType) {
            case HOUR:
                StoreHourExample example = new StoreHourExample();
                example.setStatsTimeAfter(startTime);
                example.setStatsTimeBefore(endTime);
                example.setStoreId(storeId);
                example.setWebSite(webSite);
                example.setOrderBy(orderBy);
                list = storeHourModel.getStoreHourList(example, pager);
                break;
            case WEEK:
                StoreWeekExample weekExample = new StoreWeekExample();
                weekExample.setStatsTimeAfter(startTime);
                weekExample.setStatsTimeBefore(endTime);
                weekExample.setStoreId(storeId);
                weekExample.setWebSite(webSite);
                weekExample.setOrderBy(orderBy);
                list = storeWeekModel.getStoreWeekList(weekExample, pager);
                break;
            case MONTH:
                StoreMonthExample monthExample = new StoreMonthExample();
                monthExample.setStatsTimeAfter(startTime);
                monthExample.setStatsTimeBefore(endTime);
                monthExample.setStoreId(storeId);
                monthExample.setWebSite(webSite);
                monthExample.setOrderBy(orderBy);
                list = storeMonthModel.getStoreMonthList(monthExample, pager);
                break;
            case YEAR:
                StoreYearExample yearExample = new StoreYearExample();
                yearExample.setStatsTimeAfter(startTime);
                yearExample.setStatsTimeBefore(endTime);
                yearExample.setStoreId(storeId);
                yearExample.setWebSite(webSite);
                yearExample.setOrderBy(orderBy);
                list = storeYearModel.getStoreYearList(yearExample, pager);
                break;
            case DAY:
                StoreDayExample dayExample = new StoreDayExample();
                dayExample.setStatsTimeAfter(startTime);
                dayExample.setStatsTimeBefore(endTime);
                dayExample.setStoreId(storeId);
                dayExample.setWebSite(webSite);
                if (sortType.equals("sale")) {
                    if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                        dayExample.setOrderBy("orderPayNum DESC");
                    } else {
                        dayExample.setOrderBy("orderPayAmount DESC");
                    }
                } else {
                    if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                        dayExample.setOrderBy("visitorNum DESC");
                    } else {
                        dayExample.setOrderBy("viewNum DESC");
                    }
                }
                if (pager != null) {
                    list = storeDayModel.getStoreList(dayExample, pager);
                } else {
                    list = storeDayModel.getStoreListByExample(dayExample);
                }
                break;
        }
        return list;
    }

    /**
     * 返回店铺变化趋势列表数据
     *
     * @param timeType
     * @param startTime
     * @param endTime
     * @return
     */
    public List<MovableGoodsVO> getStoreTrendList(StatsTimeType timeType, Date startTime, Date endTime,String webSite, Long storeId) {
        List<MovableGoodsVO> list = new ArrayList<>();
        switch (timeType) {
            case HOUR:
                StoreHourExample example = new StoreHourExample();
                example.setStatsTimeAfter(startTime);
                example.setStatsTimeBefore(endTime);
                example.setStoreId(storeId);
                example.setWebSite(webSite);
                list = storeHourModel.getStoreTrendList(example);
                break;
            case DAY:
            case WEEK:
            case MONTH:
                StoreDayExample dayExample = new StoreDayExample();
                dayExample.setStatsTimeAfter(startTime);
                dayExample.setStatsTimeBefore(endTime);
                dayExample.setStoreId(storeId);
                dayExample.setWebSite(webSite);
                list = storeDayModel.getStoreTrendList(dayExample);
                break;
            case YEAR:
                StoreMonthExample monthExample = new StoreMonthExample();
                monthExample.setStatsTimeAfter(startTime);
                monthExample.setStatsTimeBefore(endTime);
                monthExample.setStoreId(storeId);
                monthExample.setWebSite(webSite);
                list = storeMonthModel.getStoreTrendList(monthExample);
                break;
        }
        return list;
    }

    /**
     * 返回对应的商品列表数据
     *
     * @param timeType
     * @param startTime
     * @param endTime
     * @return
     */
    public List<? extends GoodsBase> getGoodsList(StatsTimeType timeType, Date startTime, Date endTime,String webSite, Integer sort,
                                                  String sortType, Long storeId) {
        //默认查询前十条数据
        PagerInfo pager = new PagerInfo(10, 1);
        List<? extends GoodsBase> list = new ArrayList<>();
        //排序规则
        String orderBy;
        if (sortType.equals("sale")) {
            if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                orderBy = "sale_num DESC, sale_amount DESC";
            } else {
                orderBy = "sale_amount DESC, sale_num DESC";
            }
        } else if (sortType.equals("collection")) {
            if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                orderBy = "goods_price DESC";
            } else {
                orderBy = "collection_num DESC";
            }
        } else if (sortType.equals("prefer")) {
            if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                orderBy = "collection_num DESC";
            } else if (!StringUtil.isNullOrZero(sort) && sort == 3) {
                orderBy = "order_pay_num DESC";
            } else {
                orderBy = "view_num DESC";
            }
        } else {
            if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                orderBy = "visitor_num DESC";
            } else {
                orderBy = "view_num DESC";
            }
        }
        switch (timeType) {
            case HOUR:
                GoodsHourExample example = new GoodsHourExample();
                example.setStatsTimeAfter(startTime);
                example.setStatsTimeBefore(endTime);
                example.setStoreId(storeId);
                example.setWebSite(webSite);
                example.setOrderBy(orderBy);
                list = goodsHourModel.getGoodsHourList(example, pager);
                break;
            case WEEK:
                GoodsWeekExample weekExample = new GoodsWeekExample();
                weekExample.setStatsTimeAfter(startTime);
                weekExample.setStatsTimeBefore(endTime);
                weekExample.setStoreId(storeId);
                weekExample.setWebSite(webSite);
                weekExample.setOrderBy(orderBy);
                list = goodsWeekModel.getGoodsWeekList(weekExample, pager);
                break;
            case MONTH:
                GoodsMonthExample monthExample = new GoodsMonthExample();
                monthExample.setStatsTimeAfter(startTime);
                monthExample.setStatsTimeBefore(endTime);
                monthExample.setStoreId(storeId);
                monthExample.setWebSite(webSite);
                monthExample.setOrderBy(orderBy);
                list = goodsMonthModel.getGoodsMonthList(monthExample, pager);
                break;
            case YEAR:
                GoodsYearExample yearExample = new GoodsYearExample();
                yearExample.setStatsTimeAfter(startTime);
                yearExample.setStatsTimeBefore(endTime);
                yearExample.setStoreId(storeId);
                yearExample.setOrderBy(orderBy);
                yearExample.setWebSite(webSite);
                list = goodsYearModel.getGoodsYearList(yearExample, pager);
                break;
            case DAY:
                GoodsDayExample dayExample = new GoodsDayExample();
                dayExample.setStatsTimeAfter(startTime);
                dayExample.setStatsTimeBefore(endTime);
                dayExample.setStoreId(storeId);
                dayExample.setWebSite(webSite);
                if (sortType.equals("sale")) {
                    if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                        dayExample.setOrderBy("saleNum DESC");
                    } else {
                        dayExample.setOrderBy("saleAmount DESC");
                    }
                } else if (sortType.equals("collection")) {
                    if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                        dayExample.setOrderBy("goodsPrice DESC");
                    } else {
                        dayExample.setOrderBy("collectionNum DESC");
                    }
                } else if (sortType.equals("prefer")) {
                    if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                        dayExample.setOrderBy("collectionNum DESC");
                    } else if (!StringUtil.isNullOrZero(sort) && sort == 3) {
                        dayExample.setOrderBy("orderPayNum DESC");
                    } else {
                        dayExample.setOrderBy("viewNum DESC");
                    }
                } else {
                    if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                        dayExample.setOrderBy("visitorNum DESC");
                    } else {
                        dayExample.setOrderBy("viewNum DESC");
                    }
                }
                list = goodsDayModel.getGoodsList(dayExample, pager);
                break;
        }
        return list;
    }

    /**
     * 返回商品销售变化趋势列表数据
     *
     * @param timeType
     * @param startTime
     * @param endTime
     * @return
     */
    public List<SalesTrendVO> getGoodsTrendList(StatsTimeType timeType, Date startTime, Date endTime, String goodsIds) {
        List<SalesTrendVO> list = new ArrayList<>();
        switch (timeType) {
            case HOUR:
                GoodsHourExample example = new GoodsHourExample();
                example.setStatsTimeAfter(startTime);
                example.setStatsTimeBefore(endTime);
                example.setGoodsIdIn(goodsIds);
                list = goodsHourModel.getGoodsTrendList(example);
                break;
            case DAY:
            case WEEK:
            case MONTH:
                GoodsDayExample dayExample = new GoodsDayExample();
                dayExample.setStatsTimeAfter(startTime);
                dayExample.setStatsTimeBefore(endTime);
                dayExample.setGoodsIdIn(goodsIds);
                list = goodsDayModel.getGoodsTrendList(dayExample);
                break;
            case YEAR:
                GoodsMonthExample monthExample = new GoodsMonthExample();
                monthExample.setStatsTimeAfter(startTime);
                monthExample.setStatsTimeBefore(endTime);
                monthExample.setGoodsIdIn(goodsIds);
                list = goodsMonthModel.getGoodsTrendList(monthExample);
                break;
        }
        return list;
    }

    /**
     * 返回各省份销售变化趋势列表数据
     *
     * @param timeType
     * @param startTime
     * @param endTime
     * @return
     */
    public List<SalesTrendVO> getProvinceTrendList(StatsTimeType timeType, Date startTime, Date endTime, String provinceCode) {
        List<SalesTrendVO> list = new ArrayList<>();
        switch (timeType) {
            case HOUR:
                ProvinceHourExample example = new ProvinceHourExample();
                example.setStatsTimeAfter(startTime);
                example.setStatsTimeBefore(endTime);
                if (!StringUtil.isEmpty(provinceCode)) {
                    example.setProvinceCode(provinceCode);
                } else {
                    //如果编码为空，默认按北京查询
                    example.setProvinceCode("CN003000000");
                }
                list = provinceHourModel.getProvinceTrendList(example);
                break;
            case DAY:
            case WEEK:
            case MONTH:
                ProvinceDayExample dayExample = new ProvinceDayExample();
                dayExample.setStatsTimeAfter(startTime);
                dayExample.setStatsTimeBefore(endTime);
                if (!StringUtil.isEmpty(provinceCode)) {
                    dayExample.setProvinceCode(provinceCode);
                } else {
                    //如果编码为空，默认按北京查询
                    dayExample.setProvinceCode("CN003000000");
                }
                list = provinceDayModel.getProvinceTrendList(dayExample);
                break;
            case YEAR:
                ProvinceMonthExample monthExample = new ProvinceMonthExample();
                monthExample.setStatsTimeAfter(startTime);
                monthExample.setStatsTimeBefore(endTime);
                if (!StringUtil.isEmpty(provinceCode)) {
                    monthExample.setProvinceCode(provinceCode);
                } else {
                    //如果编码为空，默认按北京查询
                    monthExample.setProvinceCode("CN003000000");
                }
                list = provinceMonthModel.getProvinceTrendList(monthExample);
                break;
        }
        return list;
    }

    /**
     * 返回对应的省份列表数据
     *
     * @param timeType
     * @param startTime
     * @param endTime
     * @return
     */
    public List<? extends ProvinceBase> getProvinceList(StatsTimeType timeType, Date startTime, Date endTime, Integer sort) {
        List<? extends ProvinceBase> list = new ArrayList<>();
        //排序规则
        String orderBy;
        if (!StringUtil.isNullOrZero(sort) && sort == 2) {
            orderBy = "order_pay_num DESC";
        } else if (!StringUtil.isNullOrZero(sort) && sort == 3) {
            orderBy = "order_submit_member_num DESC";
        } else {
            orderBy = "order_pay_amount DESC";
        }
        switch (timeType) {
            case HOUR:
                ProvinceHourExample example = new ProvinceHourExample();
                example.setStatsTimeAfter(startTime);
                example.setStatsTimeBefore(endTime);
                example.setOrderBy(orderBy);
                list = provinceHourModel.getProvinceHourList(example, null);
                break;
            case WEEK:
                ProvinceWeekExample weekExample = new ProvinceWeekExample();
                weekExample.setStatsTimeAfter(startTime);
                weekExample.setStatsTimeBefore(endTime);
                weekExample.setOrderBy(orderBy);
                list = provinceWeekModel.getProvinceWeekList(weekExample, null);
                break;
            case MONTH:
                ProvinceMonthExample monthExample = new ProvinceMonthExample();
                monthExample.setStatsTimeAfter(startTime);
                monthExample.setStatsTimeBefore(endTime);
                monthExample.setOrderBy(orderBy);
                list = provinceMonthModel.getProvinceMonthList(monthExample, null);
                break;
            case YEAR:
                ProvinceYearExample yearExample = new ProvinceYearExample();
                yearExample.setStatsTimeAfter(startTime);
                yearExample.setStatsTimeBefore(endTime);
                yearExample.setOrderBy(orderBy);
                list = provinceYearModel.getProvinceYearList(yearExample, null);
                break;
            case DAY:
                ProvinceDayExample dayExample = new ProvinceDayExample();
                dayExample.setStatsTimeAfter(startTime);
                dayExample.setStatsTimeBefore(endTime);
                if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                    dayExample.setOrderBy("orderPayNum DESC");
                } else if (!StringUtil.isNullOrZero(sort) && sort == 3) {
                    dayExample.setOrderBy("orderSubmitMemberNum DESC");
                } else {
                    dayExample.setOrderBy("orderPayAmount DESC");
                }
                list = provinceDayModel.getProvinceList(dayExample);
                break;
        }
        return list;
    }

    /**
     * 返回对应的品牌列表数据
     *
     * @param webSite
     * @param timeType
     * @param startTime
     * @param endTime
     * @return
     */
    public List<? extends BrandBase> getBrandList(StatsTimeType timeType,String webSite, Date startTime, Date endTime, Integer sort, PagerInfo pager) {
        List<? extends BrandBase> list = new ArrayList<>();
        //排序规则
        String orderBy;
        if (!StringUtil.isNullOrZero(sort) && sort == 2) {
            orderBy = "sale_num DESC";
        } else {
            orderBy = "sale_amount DESC";
        }
        switch (timeType) {
            case HOUR:
                BrandHourExample example = new BrandHourExample();
                example.setStatsTimeAfter(startTime);
                example.setStatsTimeBefore(endTime);
                example.setOrderBy(orderBy);
                example.setWebSite(webSite);
                list = brandHourModel.getBrandHourList(example, pager);
                break;
            case WEEK:
                BrandWeekExample weekExample = new BrandWeekExample();
                weekExample.setStatsTimeAfter(startTime);
                weekExample.setStatsTimeBefore(endTime);
                weekExample.setOrderBy(orderBy);
                weekExample.setWebSite(webSite);
                list = brandWeekModel.getBrandWeekList(weekExample, pager);
                break;
            case MONTH:
                BrandMonthExample monthExample = new BrandMonthExample();
                monthExample.setStatsTimeAfter(startTime);
                monthExample.setStatsTimeBefore(endTime);
                monthExample.setOrderBy(orderBy);
                monthExample.setWebSite(webSite);
                list = brandMonthModel.getBrandMonthList(monthExample, pager);
                break;
            case YEAR:
                BrandYearExample yearExample = new BrandYearExample();
                yearExample.setStatsTimeAfter(startTime);
                yearExample.setStatsTimeBefore(endTime);
                yearExample.setOrderBy(orderBy);
                yearExample.setWebSite(webSite);
                list = brandYearModel.getBrandYearList(yearExample, pager);
                break;
            case DAY:
                BrandDayExample dayExample = new BrandDayExample();
                dayExample.setStatsTimeAfter(startTime);
                dayExample.setStatsTimeBefore(endTime);
                dayExample.setWebSite(webSite);
                if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                    dayExample.setOrderBy("saleNum DESC");
                } else {
                    dayExample.setOrderBy("saleAmount DESC");
                }
                list = brandDayModel.getBrandList(dayExample, pager);
                break;
        }
        return list;
    }

    /**
     * 返回对应的商品分类列表数据
     *
     * @param timeType
     * @param startTime
     * @param endTime
     * @return
     */
    public List<? extends CategoryBase> getCategoryList(StatsTimeType timeType, Date startTime, Date endTime, Integer sort, String sortType) {
        //默认查询前十条数据
        PagerInfo pager = new PagerInfo(10, 1);
        List<? extends CategoryBase> list = new ArrayList<>();
        //排序规则
        String orderBy;
        if (sortType.equals("sale")) {
            if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                orderBy = "sale_num DESC";
            } else {
                orderBy = "sale_amount DESC";
            }
        } else {
            if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                orderBy = "visitor_num DESC";
            } else {
                orderBy = "view_num DESC";
            }
        }
        switch (timeType) {
            case HOUR:
                CategoryHourExample example = new CategoryHourExample();
                example.setStatsTimeAfter(startTime);
                example.setStatsTimeBefore(endTime);
                example.setOrderBy(orderBy);
                list = categoryHourModel.getCategoryHourList(example, pager);
                break;
            case WEEK:
                CategoryWeekExample weekExample = new CategoryWeekExample();
                weekExample.setStatsTimeAfter(startTime);
                weekExample.setStatsTimeBefore(endTime);
                weekExample.setOrderBy(orderBy);
                list = categoryWeekModel.getCategoryWeekList(weekExample, pager);
                break;
            case MONTH:
                CategoryMonthExample monthExample = new CategoryMonthExample();
                monthExample.setStatsTimeAfter(startTime);
                monthExample.setStatsTimeBefore(endTime);
                monthExample.setOrderBy(orderBy);
                list = categoryMonthModel.getCategoryMonthList(monthExample, pager);
                break;
            case YEAR:
                CategoryYearExample yearExample = new CategoryYearExample();
                yearExample.setStatsTimeAfter(startTime);
                yearExample.setStatsTimeBefore(endTime);
                yearExample.setOrderBy(orderBy);
                list = categoryYearModel.getCategoryYearList(yearExample, pager);
                break;
            case DAY:
                CategoryDayExample dayExample = new CategoryDayExample();
                dayExample.setStatsTimeAfter(startTime);
                dayExample.setStatsTimeBefore(endTime);
                if (sortType.equals("sale")) {
                    if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                        dayExample.setOrderBy("saleNum DESC");
                    } else {
                        dayExample.setOrderBy("saleAmount DESC");
                    }
                } else {
                    if (!StringUtil.isNullOrZero(sort) && sort == 2) {
                        dayExample.setOrderBy("visitorNum DESC");
                    } else {
                        dayExample.setOrderBy("viewNum DESC");
                    }
                }
                list = categoryDayModel.getCategoryList(dayExample, pager);
                break;
        }
        return list;
    }

    /**
     * 返回商品分类趋势列表数据
     *
     * @param timeType
     * @param startTime
     * @param endTime
     * @return
     */
    public List<SalesTrendVO> getCategoryTrendList(StatsTimeType timeType, Date startTime, Date endTime, String categoryIds) {
        List<SalesTrendVO> list = new ArrayList<>();
        switch (timeType) {
            case HOUR:
                CategoryHourExample example = new CategoryHourExample();
                example.setStatsTimeAfter(startTime);
                example.setStatsTimeBefore(endTime);
                example.setCategoryIdIn(categoryIds);
                list = categoryHourModel.getCategoryTrendList(example);
                break;
            case DAY:
            case WEEK:
            case MONTH:
                CategoryDayExample dayExample = new CategoryDayExample();
                dayExample.setStatsTimeAfter(startTime);
                dayExample.setStatsTimeBefore(endTime);
                dayExample.setCategoryIdIn(categoryIds);
                list = categoryDayModel.getCategoryTrendList(dayExample);
                break;
            case YEAR:
                CategoryMonthExample monthExample = new CategoryMonthExample();
                monthExample.setStatsTimeAfter(startTime);
                monthExample.setStatsTimeBefore(endTime);
                monthExample.setCategoryIdIn(categoryIds);
                list = categoryMonthModel.getCategoryTrendList(monthExample);
                break;
        }
        return list;
    }
}
