package com.iformall.controller;

import com.github.pagehelper.PageInfo;
import com.iformall.common.ResultData;
import com.iformall.domain.vo.WxMerchantTradeDailyVo;
import com.iformall.service.WxMerchantTradeDailyService;
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.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@RestController
@RequestMapping("wxMerchantTradeDaily")
public class WxMerchantTradeDailyController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxMerchantTradeDailyService wxMerchantTradeDailyService;



    @ApiOperation("获得昨日解单列表")
    @GetMapping("/listYesterday")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
    public ResultData listYesterday(@ModelAttribute WxMerchantTradeDailyVo wxMerchantTradeDaily, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] WxMerchantTradeDailyController::listYesterday");
        if (wxMerchantTradeDaily == null) wxMerchantTradeDaily = new WxMerchantTradeDailyVo();
        wxMerchantTradeDaily.setTenantId(getTenantId());
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.add(Calendar.DAY_OF_YEAR, -1);
        SimpleDateFormat fmt=new SimpleDateFormat("yyyy-MM-dd");
        wxMerchantTradeDaily.setReportDate(fmt.format(cal.getTime()));
        wxMerchantTradeDaily.setSortColumns(WxMerchantTradeDailyVo.Field.MerchantId_DESC);
        PageInfo<WxMerchantTradeDailyVo> page = wxMerchantTradeDailyService.listAsPageVo(wxMerchantTradeDaily, pageNum, pageSize);
        return new ResultData(page);
    }

    @ApiOperation("获商户得近30日解单")
    @GetMapping("/detail")
    public ResultData detail(Long merchantId) {
        logger.debug("[" + getIpAddr() + "] WxMerchantTradeDailyController::detail");
        return wxMerchantTradeDailyService.getVolumeOfMonth(merchantId);
    }

    @ApiOperation("获得商场近30日解单")
    @GetMapping("/listMonth")
    public ResultData listMonth() {
        logger.debug("[" + getIpAddr() + "] WxMerchantTradeDailyController::listMonth");
        return wxMerchantTradeDailyService.getVolumeTotalOfMonth(getTenantId());
    }

    @ApiOperation("更新解单数据")
    @PostMapping("/updateYesterday")
    public ResultData updateYesterday(@RequestBody WxMerchantTradeDailyVo wxMerchantTradeDaily) {
        logger.debug("[" + getIpAddr() + "] WxMerchantTradeDailyController::updateYesterday");
        wxMerchantTradeDaily.setTenantId(getTenantId());
        return wxMerchantTradeDailyService.updateYesterday(wxMerchantTradeDaily);
    }

    @ApiOperation("查询解单数据")
    @GetMapping("/queryTradeDaily")
    public ResultData queryTradeDaily(@ModelAttribute WxMerchantTradeDailyVo wxMerchantTradeDaily) {
        logger.debug("[" + getIpAddr() + "] WxMerchantTradeDailyController::queryTradeDaily");
        wxMerchantTradeDaily.setTenantId(getTenantId());
        return wxMerchantTradeDailyService.queryTradeDaily(wxMerchantTradeDaily);
    }



}
