package com.yida.data.mall.controller;

import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.mall.EduBill;
import com.yida.data.mall.dto.ExportBillStatisticsDTO;
import com.yida.data.mall.service.EduBillService;
import com.yida.data.mall.service.EduBillStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 缴费账单统计 Controller
 *
 * @author ZYJ
 * @date 2022/7/7
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("bill/statistics")
@Api(tags = "缴费账单统计后台api")
public class EduBillStatisticsController {

    private final EduBillService eduBillService;
    private final EduBillStatisticsService eduBillStatisticsService;

    @GetMapping("/listBill")
    @ApiOperation("查询账单集合数据")
    public ResultBean<List<EduBill>> listBill(
            @ApiParam(value = "查询类型. 0-全部, 1-已开始账单") @RequestParam(required = false) Integer type) {
        List<EduBill> list = eduBillService.listBill(type);
        return ResultBean.buildSuccess(list);
    }

    @GetMapping("/billStatistics")
    @ApiOperation("查询账单缴费统计数据")
    public ResultBean<List<Map<String, Object>>> billStatistics(@RequestParam Long billId) {
        List<Map<String, Object>> list = eduBillStatisticsService.billStatistics(billId);
        return ResultBean.buildSuccess(list);
    }

    @PostMapping("/exportBillStatistics")
    @ApiOperation("导出账单缴费统计数据")
    public ResultBean<String> exportBillStatistics(@RequestBody ExportBillStatisticsDTO dto) {
        return ResultBean.buildSuccess(eduBillStatisticsService.exportBillStatistics(dto));
    }
}
