package com.gree.mall.manager.controller.es;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.manager.bean.count.CountOrderBean;
import com.gree.mall.manager.bean.count.EsCountBean;
import com.gree.mall.manager.bean.count.EsGoodsRankBean;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.es.EsCountLogic;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RequiredArgsConstructor
@Validated
@RestController
@Api(value = "二手首页统计", tags ={"二手首页统计"} )
@RequestMapping("es/count")
public class EsCountController {


    private final EsCountLogic esCountLogic;

    @GetMapping("/info")
    @ApiOperation(value = "概况-统计1")
    public ResponseHelper<EsCountBean> info(HttpServletRequest request) {
        EsCountBean info = esCountLogic.info();
        return ResponseHelper.success(info);
    }


    @GetMapping("/order")
    @ApiOperation(value = "交易概述-统计2")
    public ResponseHelper<CountOrderBean> order(
            @ApiParam(value ="时间类型(1=今天，2=昨日，3=最近7天，4=本月)",required = true) @RequestParam Integer flag,
            HttpServletRequest request
    ) {
        CountOrderBean order = esCountLogic.order(flag);
        return ResponseHelper.success(order);
    }

    @GetMapping("/goods/rank")
    @ApiOperation(value = "商品销量排行-统计3")
    public ResponseHelper<IPage<EsGoodsRankBean>> goodsRank(
            @ApiParam(value = "时间类型(1=今天，2=昨日，3=最近7天，4=本月)",required = true) @RequestParam Integer flag,
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            HttpServletRequest request
    ) {
        IPage<EsGoodsRankBean> goodsRankBeans = esCountLogic.countGoodsRank(flag,pageNum,pageSize);
        return ResponseHelper.success(goodsRankBeans);
    }




}
