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.WxBillDeposit;
import com.iformall.service.WxBillDepositService;
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.*;

/**
 * @author gongbiao
 */
@RestController
@RequestMapping("wxBillDeposit")
public class WxBillDepositController extends BaseController {
    @Autowired
    private WxBillDepositService wxBillDepositService;

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

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

    @PostMapping("add")
    @SystemControllerLog(description = "租赁押金-新增")
    public ResultData add(@RequestBody WxBillDeposit wxBillDeposit) {
        logger.debug("[" + getIpAddr() + "] WxBillDepositController::add");
        wxBillDeposit.setTenantId(getTenantId());
        return wxBillDepositService.saveOrUpdate(wxBillDeposit, getUser());

    }

    @PostMapping("update")
    @SystemControllerLog(description = "租赁押金-更新")
    public ResultData update(@RequestBody WxBillDeposit wxBillDeposit) {
        logger.debug("[" + getIpAddr() + "] WxBillDepositController::update");
        return wxBillDepositService.saveOrUpdate(wxBillDeposit, getUser());

    }

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

    @PostMapping("returnDeposit")
    @SystemControllerLog(description = "租赁押金-退回押金")
    public ResultData returnDeposit(@RequestBody WxBillDeposit wxBillDeposit) {
        logger.debug("[" + getIpAddr() + "] WxBillDepositController::returnDeposit");
        return wxBillDepositService.returnDeposit(wxBillDeposit, getUser());

    }

    @PostMapping("adjustDeposit")
    @SystemControllerLog(description = "租赁押金-调整押金")
    public ResultData adjustDeposit(@RequestBody WxBillDeposit wxBillDeposit) {
        logger.debug("[" + getIpAddr() + "] WxBillDepositController::adjustDeposit");
        return wxBillDepositService.adjustDeposit(wxBillDeposit);

    }


}
