package com.iformall.controller.market;

import com.github.pagehelper.PageInfo;
import com.iformall.annotation.SystemControllerLog;
import com.iformall.common.ResultData;
import com.iformall.controller.base.BaseController;
import com.iformall.domain.dto.WxOrderReportDto;
import com.iformall.domain.vo.WxMerchantMicroPayVo;
import com.iformall.enums.EnumOrderStatus;
import com.iformall.enums.EnumOrderType;
import com.iformall.service.MarkingDataReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("wxMerchantMicroPay")
@Api(description = "B端收银台相关接口")
public class WxMerchantMicroPayController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MarkingDataReportService markingDataReportService;

    @ApiOperation("获得商场近30日刷卡")
    @GetMapping("/listMonth")
    @SystemControllerLog(description = "收银台-近30日刷卡列表")
    public ResultData listMonth() {
        logger.debug("[" + getIpAddr() + "] WxMerchantMicroPayController::listMonth");
        WxOrderReportDto  wxOrderReportDto = new WxOrderReportDto();
        wxOrderReportDto.setTenantId(getTenantId());
        wxOrderReportDto.setType(EnumOrderType.MICROPAY.getCode());
        wxOrderReportDto.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode());
        return new ResultData(markingDataReportService.listOrderReportByDate(wxOrderReportDto));
    }


    @ApiOperation("获商户得近30日刷卡")
    @GetMapping("/detail")
    @SystemControllerLog(description = "收银台-近30日刷卡列表详情")
    public ResultData detail(@RequestParam Long merchantId) {
        logger.debug("[" + getIpAddr() + "] WxMerchantMicroPayController::detail");
        WxOrderReportDto  wxOrderReportDto = new WxOrderReportDto();
        wxOrderReportDto.setTenantId(getTenantId());
        wxOrderReportDto.setMerchantId(merchantId);
        return new ResultData(markingDataReportService.listMicroPayOrderReportByDateAndMerchant(wxOrderReportDto));
    }

    @ApiOperation("获得昨日刷卡列表")
    @GetMapping("/listYesterday")
    @SystemControllerLog(description = "收银台-获得昨日刷卡列表")
    public ResultData listYesterday(@ModelAttribute WxOrderReportDto wxOrderReportDto,  Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] WxMerchantTradeDailyController::listYesterday");
        if (wxOrderReportDto == null)
            wxOrderReportDto = new WxOrderReportDto();
        wxOrderReportDto.setTenantId(getTenantId());
        final PageInfo<WxMerchantMicroPayVo> page = markingDataReportService.listMerchantMicroPayOrderReportByDate(wxOrderReportDto, pageNum, pageSize);
        return new ResultData(page);
    }

}
