package cn.ysk.cashier.controller.shop;

import cn.ysk.cashier.annotation.rest.AnonymousGetMapping;
import cn.ysk.cashier.annotation.rest.AnonymousPostMapping;
import cn.ysk.cashier.dto.BaseQueryDto;
import cn.ysk.cashier.dto.shop.ShopTableSaleInfoDto;
import cn.ysk.cashier.service.SummaryService;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * @author lyf
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/summary")
public class SummaryController {
    @Resource
    private SummaryService summaryService;


    //营业板块 上
    @PostMapping("/trade")
    @AnonymousPostMapping
    private Object shopSummaryDate(@RequestBody BaseQueryDto param) {
        return summaryService.trade(param);
    }

    //销售趋势柱状图 左下
    @GetMapping("/dateAmount")
    private Object shopSummaryAmount(@RequestParam Integer shopId, @RequestParam Integer day) {
        return summaryService.selectSummaryAmount(shopId, day);
    }
    //支付占比饼图 左下
    @GetMapping("/datePayType")
    private Object shopSummaryPayType(@RequestParam Integer shopId, @RequestParam Integer day) {
        return summaryService.selectSummaryPayType(shopId, day);
    }

    //商品销售 右下
    @GetMapping("/productSaleDate")
    private Object productSaleDate(
            @RequestParam Integer shopId, @RequestParam Integer day ,@RequestParam Integer page,@RequestParam Integer size) {
        return summaryService.productSaleDate(shopId, day, page, size);
    }

    //台桌统计
    @GetMapping("/table")
    private Object shopSummaryTable(@RequestParam Integer shopId,
                                    @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
                                    @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
        return summaryService.selectSummaryTable(shopId, startTime, endTime);
    }
    //台桌统计导出
    @PostMapping("/table/download")
    private void downloadShopSummaryTable(HttpServletResponse response, @RequestBody ShopTableSaleInfoDto exportRequest) throws IOException {
        summaryService.downloadTableSaleInfo(exportRequest, response);
    }

}
