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.WxBillOtherDeposit;
import com.iformall.service.WxBillOtherDepositService;
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;
import java.util.Map;

/**
 * @author gongbiao
 */
@RestController
@RequestMapping("wxBillOtherDeposit")
public class WxBillOtherDepositController extends BaseController {
    @Autowired
    private WxBillOtherDepositService wxBillOtherDepositService;

    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 WxBillOtherDeposit wxBillOtherDeposit, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] WxBillOtherDepositController::list");
        if (null == wxBillOtherDeposit) {
            wxBillOtherDeposit = new WxBillOtherDeposit();
        }
        wxBillOtherDeposit.setTenantId(getTenantId());
        final PageInfo<WxBillOtherDeposit> page = wxBillOtherDepositService.listAsPage(wxBillOtherDeposit, pageNum, pageSize);
        return new ResultData(page);
    }

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

    @PostMapping("update")
    @SystemControllerLog(description = "其它押金账单-更新")
    public ResultData update(@RequestBody WxBillOtherDeposit wxBillOtherDeposit) {
        logger.debug("[" + getIpAddr() + "] WxBillOtherDepositController::update");
        MallUserInfo user = getUser();
        wxBillOtherDeposit.setUserId(user.getId());
        return wxBillOtherDepositService.saveOrUpdate(wxBillOtherDeposit, user);
    }

    @GetMapping("/del")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "其它押金账单-删除")
    public ResultData delete(Long id) {
        logger.debug("[" + getIpAddr() + "] WxBillOtherDepositController::delete");
        wxBillOtherDepositService.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() + "] WxBillOtherDepositController::findById");
        return new ResultData(Result.SUCCESS, "查询成功", wxBillOtherDepositService.getById(id));
    }

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

    @PostMapping("returnDeposit")
    @SystemControllerLog(description = "其它押金账单-退回押金")
    public ResultData returnDeposit(@RequestBody WxBillOtherDeposit wxBillDeposit) {
        logger.debug("[" + getIpAddr() + "] WxBillOtherDepositController::returnDeposit");
        return wxBillOtherDepositService.returnDeposit(wxBillDeposit, getUser());

    }

    @PostMapping("adjustDeposit")
    @SystemControllerLog(description = "其它押金账单-调整押金")
    public ResultData adjustDeposit(@RequestBody WxBillOtherDeposit wxBillDeposit) {
        logger.debug("[" + getIpAddr() + "] WxBillOtherDepositController::adjustDeposit");
        return wxBillOtherDepositService.adjustDeposit(wxBillDeposit);
    }

    @GetMapping("exportBill")
    @SystemControllerLog(description = "其它押金账单-导出")
    public void exportBill(@ModelAttribute WxBillOtherDeposit wxBillDeposit, HttpServletRequest request, HttpServletResponse response) {
        wxBillDeposit.setTenantId(getTenantId());
        wxBillOtherDepositService.exportBill(request, response, wxBillDeposit);
    }

}
