package com.clx.performance.controller.pc.loan.owner;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.clx.performance.param.pc.loan.carrier.PageOwnerLoanRecordOfOwner;
import com.clx.performance.service.loan.OwnerLoanRecordService;
import com.clx.performance.vo.pc.loan.carrier.OwnerLoanRecordVO;
import com.clx.performance.vo.pc.loan.owner.OwnerLoanRecordDetail;
import com.msl.common.base.PageData;
import com.msl.common.convertor.aspect.UnitCovert;
import com.msl.common.result.Result;
import com.msl.user.data.UserSessionData;
import com.msl.user.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping(value="/pc/owner/loanRecord")
@Validated
@Api(tags = "货主端-借款管理")
@AllArgsConstructor
public class OwnerLoanRecordController {

    private final OwnerLoanRecordService ownerLoanRecordService;



    @ApiOperation(value = "分页搜索货主借款列表",notes = "<br>By:刘海泉")
    @PostMapping("/pageOwnerLoanRecordOfOwner")
    @UnitCovert(param = false)
    public Result<PageData<OwnerLoanRecordVO>> pageOwnerLoanRecordOfOwner(@RequestBody @Validated PageOwnerLoanRecordOfOwner param) {
        UserSessionData loginUserInfo = TokenUtil.getLoginUserInfo();
        param.setOwnerUserNo(loginUserInfo.getUserNo());
        IPage<OwnerLoanRecordVO> page = ownerLoanRecordService.pageOwnerLoanRecordOfOwner(param);
        return Result.page(page.getRecords(), page.getTotal(), page.getPages());
    }


    @ApiOperation(value = "借款详情",notes = "<br>By:刘海泉")
    @PostMapping("/getOwnerLoanRecordDetail")
    public Result<OwnerLoanRecordDetail> getOwnerLoanRecordDetail() {
        OwnerLoanRecordDetail detail = ownerLoanRecordService.getOwnerLoanRecordDetail();
        return Result.ok(detail);
    }

}
