package com.iformall.controller.contract;

import com.github.pagehelper.PageInfo;
import com.iformall.annotation.SystemControllerLog;
import com.iformall.annotation.UserDataRuleAnnotation;
import com.iformall.common.ResultData;
import com.iformall.controller.base.BaseController;
import com.iformall.domain.po.MallUserInfo;
import com.iformall.domain.po.WxRentContract;
import com.iformall.domain.vo.WxRentPropertyContractVo;
import com.iformall.service.WxRentPropertyContractService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
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("wxRentPropertyContract")
public class WxRentPropertyContractController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxRentPropertyContractService wxRentPropertyContractService;

    @UserDataRuleAnnotation("rent_property_contract_list")
    @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 WxRentPropertyContractVo wxRentPropertyContractVo, Integer pageNum, Integer pageSize) {
        logger.debug("[" + getIpAddr() + "] wxRentPropertyContract::list");
        if (null == wxRentPropertyContractVo) {
            wxRentPropertyContractVo = new WxRentPropertyContractVo();
        }
        wxRentPropertyContractVo.setTenantId(getTenantId());
        final PageInfo<WxRentPropertyContractVo> page = wxRentPropertyContractService.listContractVo(wxRentPropertyContractVo, pageNum, pageSize);
        return new ResultData(page);
    }

    @ApiOperation("根据id查询接口")
    @GetMapping("/findById")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "租赁物业合同-根据id查询接口")
    public ResultData findById(Long id) {
        logger.debug("[" + getIpAddr() + "] wxRentPropertyContract::findById");
        return wxRentPropertyContractService.getContractInfo(id);
    }

    @ApiOperation("合同审批详情")
    @GetMapping("/getContractApplyInfo")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    @SystemControllerLog(description = "租赁物业合同-合同审批详情")
    public ResultData getContractApplyInfo(Long id) {
        logger.debug("[" + getIpAddr() + "] wxRentPropertyContract::getContractApplyInfo");
        return wxRentPropertyContractService.getContractApplyInfo(id);
    }

    @PostMapping("insertRentForCreate")
    @SystemControllerLog(description = "租赁合同-添加")
    public ResultData insertRent(@RequestBody WxRentContract wxRentContract) {
        logger.debug("[" + getIpAddr() + "] wxRentPropertyContract::insertRentForCreate");
        MallUserInfo user = getUser();
        wxRentContract.setTenantId(user.getTenantId());
        return wxRentPropertyContractService.insertRentForCreate(wxRentContract);
    }

}


