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.WxBillPropertyDeposit;
import com.iformall.service.WxBillPropertyDepositService;
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("wxBillPropertyDeposit")
public class WxBillPropertyDepositController extends BaseController {
    @Autowired
    private WxBillPropertyDepositService wxBillPropertyDepositService;

    private Logger logger = LoggerFactory.getLogger(WxBillPropertyDepositController.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 WxBillPropertyDeposit wxBillPropertyDeposit, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] WxBillPropertyDepositController::list");
        if (null == wxBillPropertyDeposit) {
            wxBillPropertyDeposit = new WxBillPropertyDeposit();
        }
        wxBillPropertyDeposit.setTenantId(getTenantId());
        PageInfo<WxBillPropertyDeposit> result = wxBillPropertyDepositService.listAsPage(wxBillPropertyDeposit, pageNum, pageSize);
        return new ResultData(result);
    }

    @PostMapping("add")
    @SystemControllerLog(description = "物业押金账单-新增")
    public ResultData add(@RequestBody WxBillPropertyDeposit wxBillPropertyDeposit) {
        logger.debug("[" + getIpAddr() + "] WxBillPropertyDepositController::add");
        wxBillPropertyDeposit.setTenantId(getTenantId());
        wxBillPropertyDepositService.saveOrUpdate(wxBillPropertyDeposit, getUser());
        return new ResultData();
    }

    @PostMapping("update")
    @SystemControllerLog(description = "物业押金账单-更新")
    public ResultData update(@RequestBody WxBillPropertyDeposit wxBillPropertyDeposit) {
        logger.debug("[" + getIpAddr() + "] WxBillPropertyDepositController::update");
        return wxBillPropertyDepositService.saveOrUpdate(wxBillPropertyDeposit, getUser());
    }

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

    @GetMapping("/findById")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "物业押金账单-id查找")
    public ResultData findById(Long id) {
        logger.debug("[" + getIpAddr() + "] WxBillPropertyDepositController::findById");
        return new ResultData(Result.SUCCESS, "查询成功", wxBillPropertyDepositService.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() + "] WxBillPropertyDepositController::updatePaid");
        return wxBillPropertyDepositService.updatePaid(id);
    }

    @PostMapping("returnDeposit")
    @SystemControllerLog(description = "物业押金账单-退回押金")
    public ResultData returnDeposit(@RequestBody WxBillPropertyDeposit wxBillPropertyDeposit) {
        logger.debug("[" + getIpAddr() + "] WxBillPropertyDepositController::returnDeposit");
        return wxBillPropertyDepositService.returnDeposit(wxBillPropertyDeposit, getUser());

    }


    @PostMapping("adjustDeposit")
    @SystemControllerLog(description = "物业押金账单-调整押金")
    public ResultData adjustDeposit(@RequestBody WxBillPropertyDeposit wxBillPropertyDeposit) {
        logger.debug("[" + getIpAddr() + "] WxBillPropertyDepositController::adjustDeposit");
        return wxBillPropertyDepositService.adjustDeposit(wxBillPropertyDeposit);

    }


}
