package com.iformall.controller;

import com.iformall.common.ResultData;
import com.iformall.domain.vo.WxBillAll;
import com.iformall.service.WxBillAllService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author gongbiao
 */
@RestController
@RequestMapping("wxBillAll")
public class WxBillAllController extends BaseController
{
	@Autowired
    private WxBillAllService wxBillAllService;

    private Logger logger = LoggerFactory.getLogger(WxBillAllController.class);

    @GetMapping("oweBillCount")
    @ApiImplicitParams({
            @ApiImplicitParam(name="contractId",value="合同id",dataType="long", paramType = "query",required=true),
            @ApiImplicitParam(name="type",value="类型1租赁合同2物业合同",dataType="int", paramType = "query",required=true)})
    public ResultData oweBillCount(Long contractId,Integer type) {
        Long count = wxBillAllService.hasOweBill(contractId,type);
        return new ResultData(count);
    }

    @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 list(@ModelAttribute WxBillAll wxBillAll, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] WxBillAllController::list");
    	if (null == wxBillAll){
            wxBillAll = new WxBillAll();
        }
        wxBillAll.setTenantId(getTenantId());
        Map<String, Object> result = wxBillAllService.listAsPage(wxBillAll, pageNum, pageSize);
        return new ResultData(result);
    }

    @GetMapping("exportBill")
    public void exportBill(@ModelAttribute WxBillAll wxBillAll,HttpServletRequest request, HttpServletResponse response){
        wxBillAll.setTenantId(getTenantId());
        wxBillAllService.exportBill(request,response,wxBillAll);
    }

    @GetMapping("getBillInfo")
    public ResultData getBillInfo(@ModelAttribute WxBillAll wxBillAll) {
        wxBillAll.setTenantId(getTenantId());
        Object billInfo = wxBillAllService.getBillInfo(wxBillAll);
        return new ResultData(billInfo);
    }



}
