package com.yami.shop.multishop.controller;


import cn.hutool.core.date.DateUtil;
import com.yami.shop.bean.param.OrderPayParam;
import com.yami.shop.bean.param.StatisticsRefundParam;
import com.yami.shop.security.multishop.util.SecurityUtils;
import com.yami.shop.service.OrderRefundService;
import com.yami.shop.service.OrderService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
/**
 * @author lhd on 2019/10/17.
 */
@RestController
@RequestMapping("/shop/statisticsOrder")
@AllArgsConstructor
public class StatisticsOrderController {

    private final OrderService orderService;
    private final OrderRefundService orderRefundService;


    @GetMapping("/orderPayByShopId")
    @ApiOperation(value = "通过时间获取支付信息")
    public ResponseEntity<OrderPayParam> orderPayByShopId() {
        OrderPayParam actualTotal = orderService.getPayUserCountByshopId(
                SecurityUtils.getShopUser().getShopId(),DateUtil.beginOfDay(DateUtil.date()), DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(actualTotal);
    }

    @GetMapping("/getActualTotalByHour")
    @ApiOperation(value = "通过24小时分段获取支付金额")
    public ResponseEntity<OrderPayParam> getActualTotalByHour() {
        OrderPayParam payList = orderService.getActualTotalByHour(
                SecurityUtils.getShopUser().getShopId(),DateUtil.beginOfDay(DateUtil.date()),DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(payList);
    }

    @GetMapping("/getActualTotalByDay")
    @ApiOperation(value = "通过天数分段获取支付金额")
    public ResponseEntity<List<OrderPayParam>> getActualTotalByDay() {
        List<OrderPayParam> payList = orderService.getActualTotalByDay(
                SecurityUtils.getShopUser().getShopId(),DateUtil.endOfDay(DateUtil.lastMonth()),DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(payList);
    }

    @GetMapping("/getOrderRefundByTime")
    @ApiOperation(value = "通过时间获取比率信息")
    public ResponseEntity<StatisticsRefundParam> getOrderRefundByTime() {
        StatisticsRefundParam refundParam = orderRefundService.getOrderRefundByShopId(
                SecurityUtils.getShopUser().getShopId(),DateUtil.beginOfDay(DateUtil.date()), DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(refundParam);
    }

    @GetMapping("/getOrderRefundDayByTime")
    @ApiOperation(value = "通过时间获取分段比率信息及退款金额信息")
    public ResponseEntity<List<StatisticsRefundParam>> getOrderRefundById() {
        List<StatisticsRefundParam> refundList = orderRefundService.getOrderRefundByShopIdAndDay(
                SecurityUtils.getShopUser().getShopId(),DateUtil.endOfDay(DateUtil.lastMonth()),DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(refundList);
    }

    @GetMapping("/getRefundRankingByProd")
    @ApiOperation(value = "根据商品名生成退款排行")
    public ResponseEntity<List<StatisticsRefundParam>> getRefundRankingByProd() {
        List<StatisticsRefundParam> refundList = orderRefundService.getRefundRankingByProd(
                SecurityUtils.getShopUser().getShopId(),DateUtil.endOfDay(DateUtil.lastMonth()),DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(refundList);
    }

    @GetMapping("/getRefundRankingByReason")
    @ApiOperation(value = "根据退款原因生成退款排行")
    public ResponseEntity<List<StatisticsRefundParam>> getRefundRankingByReason() {
        List<StatisticsRefundParam> refundList = orderRefundService.getRefundRankingByReason(
                SecurityUtils.getShopUser().getShopId(),DateUtil.endOfDay(DateUtil.lastMonth()),DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(refundList);
    }

}
