package com.iformall.controller;


import com.github.pagehelper.PageInfo;
import com.iformall.common.ResultData;
import com.iformall.domain.po.*;
import com.iformall.domain.vo.WxCardSpendVo;
import com.iformall.service.WxCardSpendService;
import com.iformall.service.WxMerchantService;
import com.iformall.service.WxOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
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.*;

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

/**
 * @author Stormeye Wu wuguoqiang@iformall.com
 */
@RestController
@Api(description = "C端扫B端商户码储值卡支付")
@RequestMapping("/api/cardPay")
public class WxCardPayController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    WxMerchantService wxMerchantService;

    @Autowired
    WxOrderService wxOrderService;

    @Autowired
    WxCardSpendService wxCardSpendService;

    @ApiOperation("C端扫B端储值卡交易流水(消费记录 + 补贴)列表接口")
    @GetMapping("list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
    public ResultData cardSpendlist(@ModelAttribute WxCardSpendVo wxCardSpendVo, Integer pageNum, Integer pageSize) {
        String ipStr = getIpAddr();
        logger.info("cardSpendlist: " + ipStr + " ：" + wxCardSpendVo.toString());
        if (wxCardSpendVo == null) wxCardSpendVo = new WxCardSpendVo();
        WxMerchantBUser user = getUser();
        wxCardSpendVo.setTenantId(user.getTenantId());
        wxCardSpendVo.setMerchantId(user.getMerchantId());
        final PageInfo<WxCardSpendVo> page = wxCardSpendService.listAsPage(wxCardSpendVo, pageNum, pageSize);
        return new ResultData(page);
    }

    @ApiOperation("C端扫B端储值卡交易流水SUM")
    @GetMapping("sum")
    public ResultData sumCardSpendList(@ModelAttribute WxCardSpendVo wxCardSpend) {
        String ipStr = getIpAddr();
        logger.info("sumCardSpendList: " + ipStr + " ：" + wxCardSpend.toString());
        if (wxCardSpend == null) wxCardSpend = new WxCardSpendVo();
        WxMerchantBUser user = getUser();
        wxCardSpend.setTenantId(user.getTenantId());
        wxCardSpend.setMerchantId(user.getMerchantId());
        final List<Map<String, Object>> mapList = wxCardSpendService.sumCardSpendForMerchant(wxCardSpend);
        return new ResultData(mapList);
    }
}
