package com.iformall.controller;

import com.github.pagehelper.PageInfo;
import com.iformall.common.ResultData;
import com.iformall.domain.po.WxMerchantBUser;
import com.iformall.domain.po.WxMerchantSubsidy;
import com.iformall.domain.vo.WxMerchantSubsidyVo;
import com.iformall.service.WxMerchantSubsidyService;
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;

@RestController
@RequestMapping("/api/subsidy")
public class WxMerchantSubsidyController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    WxMerchantSubsidyService wxMerchantSubsidyService;

    @ApiOperation("补贴记录汇总")
    @GetMapping("sum")
    public ResultData count(@ModelAttribute WxMerchantSubsidyVo wxMerchantSubsidy) {
        String ipStr = getIpAddr();
        logger.info("subsidy/sum: " + ipStr + " ：" + wxMerchantSubsidy.toString());
        if (wxMerchantSubsidy == null) wxMerchantSubsidy = new WxMerchantSubsidyVo();
        WxMerchantBUser user = getUser();
        wxMerchantSubsidy.setTenantId(user.getTenantId());
        wxMerchantSubsidy.setMerchantId(user.getMerchantId());
        List<Map<String, Object>> retMap = wxMerchantSubsidyService.sumForSubsidy(wxMerchantSubsidy);
        return new ResultData(retMap);
    }

    @ApiOperation("补贴记录")
    @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 listMonth(@ModelAttribute WxMerchantSubsidyVo wxMerchantSubsidy, Integer pageNum, Integer pageSize) {
        String ipStr = getIpAddr();
        logger.info("subsidy/list: " + ipStr + " ：" + wxMerchantSubsidy.toString());
        if (wxMerchantSubsidy == null) wxMerchantSubsidy = new WxMerchantSubsidyVo();
        WxMerchantBUser user = getUser();
        wxMerchantSubsidy.setTenantId(user.getTenantId());
        wxMerchantSubsidy.setMerchantId(user.getMerchantId());
        final PageInfo<WxMerchantSubsidyVo> page = wxMerchantSubsidyService.listAsPage(wxMerchantSubsidy, pageNum, pageSize);
        return new ResultData(page);
    }

}
