package com.iformall.controller.rent;

import com.github.pagehelper.PageInfo;
import com.iformall.annotation.SystemControllerLog;
import com.iformall.common.Result;
import com.iformall.common.ResultData;
import com.iformall.controller.base.BaseController;
import com.iformall.domain.po.MallUserInfo;
import com.iformall.domain.po.WxBillOther;
import com.iformall.domain.po.WxBillOtherDeposit;
import com.iformall.service.WxBillOtherService;
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.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author gongbiao
 */
@RestController
@RequestMapping("wxBillOther")
public class WxBillOtherController extends BaseController {
    @Autowired
    private WxBillOtherService wxBillOtherService;

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @GetMapping("list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
    @SystemControllerLog(description = "其它账单-列表")
    public ResultData list(@ModelAttribute WxBillOther wxBillOther, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] WxBillOtherController::list");
        if (null == wxBillOther) {
            wxBillOther = new WxBillOther();
        }
        wxBillOther.setTenantId(getTenantId());
        final PageInfo<WxBillOther> page = wxBillOtherService.listAsPage(wxBillOther, pageNum, pageSize);
        return new ResultData(page);
    }

    @PostMapping("add")
    @SystemControllerLog(description = "其它账单-新增")
    public ResultData add(@RequestBody WxBillOther wxBillOther) {
        logger.debug("[" + getIpAddr() + "] WxBillOtherController::add");
        MallUserInfo user = getUser();
        wxBillOther.setTenantId(user.getTenantId());
        wxBillOther.setUserId(user.getId());
        return wxBillOtherService.saveOrUpdate(wxBillOther, user);
    }

    @PostMapping("update")
    @SystemControllerLog(description = "其它账单-更新")
    public ResultData update(@RequestBody WxBillOther wxBillOther) {
        logger.debug("[" + getIpAddr() + "] WxBillOtherController::update");
        MallUserInfo user = getUser();
        wxBillOther.setUserId(user.getId());
        return wxBillOtherService.saveOrUpdate(wxBillOther, user);
    }

    @GetMapping("/del")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "其它账单-删除")
    public ResultData delete(Long id) {
        logger.debug("[" + getIpAddr() + "] WxBillOtherController::delete");
        wxBillOtherService.deleteById(id);
        return new ResultData(Result.SUCCESS, "删除成功", null);
    }

    @GetMapping("/findById")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "其它账单-查询")
    public ResultData findById(Long id) {
        logger.debug("[" + getIpAddr() + "] WxBillOtherController::findById");
        return new ResultData(Result.SUCCESS, "查询成功", wxBillOtherService.getById(id));
    }

    /**
     * 结单
     * @param id
     * @return
     */
    @GetMapping("/updatePaid")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "其它账单-支付更新")
    public ResultData updatePaid(Long id) {
        logger.debug("[" + getIpAddr() + "] WxBillOtherController::updatePaid");
        return wxBillOtherService.updatePaid(id);
    }

    @GetMapping("exportBill")
    @SystemControllerLog(description = "其它账单-导出")
    public void exportBill(@ModelAttribute WxBillOther wxBillOther, HttpServletRequest request, HttpServletResponse response) {
        wxBillOther.setTenantId(getTenantId());
        wxBillOtherService.exportBill(request, response, wxBillOther);
    }

}
