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

import com.gree.mall.manager.annotation.ApiNotAuth;
import com.gree.mall.manager.bean.admin.AdminUserCom;
import com.gree.mall.manager.bean.count.CountBean;
import com.gree.mall.manager.bean.count.CountOrderBean;
import com.gree.mall.manager.bean.count.GoodsRankBean;
import com.gree.mall.manager.bean.count.WebsitSaleCountBean;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.count.CountLogic;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

@Slf4j
@RestController
@Api(value = "统计", tags ={"统计"} )
@RequestMapping(value = "/count", produces = "application/json; charset=utf-8")
public class CountController {


    @Autowired
    CountLogic countLogic;

    @GetMapping("/info")
    @ApiOperation(value = "概况")
    public ResponseHelper<CountBean> info(HttpServletRequest request) {
        CountBean info = countLogic.info(request);
        return ResponseHelper.success(info);
    }

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


    @GetMapping("/order")
    @ApiOperation(value = "交易概述")
    public ResponseHelper<CountOrderBean> order(
            @ApiParam(value = "INSTALL:产品  REPAIR:服务",required = false) @RequestParam(required = false) String workOrderType,
            @ApiParam(value = "时间类型(1=今天，2=昨日，3=最近7天，4=本月)",required = true) @RequestParam Integer flag,
            HttpServletRequest request
    ) {
        CountOrderBean order = countLogic.order(workOrderType,flag,request);
        return ResponseHelper.success(order);
    }

    @ApiNotAuth
    @GetMapping("/work/amount")
    @ApiOperation("师傅销售额")
    public ResponseHelper<List<Map<String, Object>>> workAmount(
            @ApiParam(value = "开始时间",required = true) @RequestParam String startTime,
            @ApiParam(value = "结束时间",required = true) @RequestParam String endTime,
            HttpServletRequest request
    ) {
        List<Map<String, Object>> maps = countLogic.queryWorkAmount(startTime, endTime,request);
        return ResponseHelper.success(maps);
    }


    @ApiNotAuth
    @GetMapping("/websit/amount")
    @ApiOperation("网点销售额")
    public ResponseHelper<WebsitSaleCountBean> workAmount(
            @ApiParam(value = "网点编号集",required = true) @RequestParam List<String> websitNumbers
    ) {
        WebsitSaleCountBean websitSaleCountBean = countLogic.queryWebsitAmount(websitNumbers);
        return ResponseHelper.success(websitSaleCountBean);
    }

}
