package cn.com.ty.lift.business.contract.controller;

import cn.com.ty.lift.business.contract.dao.entity.model.request.PaymentRequest;
import cn.com.ty.lift.business.contract.dao.entity.model.response.PaymentHistoryResponse;
import cn.com.ty.lift.business.contract.dao.entity.model.response.PaymentListResponse;
import cn.com.ty.lift.business.contract.dao.entity.model.response.PaymentResponse;
import cn.com.ty.lift.business.contract.service.PaymentHistoryService;
import cn.com.ty.lift.business.contract.service.PaymentService;
import cn.com.ty.lift.business.framework.util.MessageUtils;
import cn.com.ty.lift.common.verify.Val;
import cn.com.ty.lift.common.verify.Validation;
import cn.com.xwy.boot.web.dto.RestResponse;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
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;

import javax.annotation.Resource;

/**
 * @author bieao
 * @date 2020/2/20
 * @description 收款管理控制层
 */
@RestController
@RequestMapping("payment")
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @Resource
    private PaymentHistoryService paymentHistoryService;

    /**
     * @param request 收款列表查询条件
     * @return RestResponse 付款分页列表结果
     * @description 查询维保收款列表
     * @date 2020/2/20 3:10 下午
     */
    @PostMapping("maintenance/list")
    @Validation(fields = {"mtCompanyId"})
    public RestResponse maintenanceList(@Val @RequestBody PaymentRequest request) {
        IPage<PaymentListResponse> page = paymentService.maintenanceList(request);
        return RestResponse.success(page, MessageUtils.get("msg.query.success"));
    }

    /**
     * @param request 收款列表查询条件
     * @return RestResponse 付款分页列表结果
     * @description 查询大修收款列表
     * @date 2020/4/27 11:15 上午
     */
    @PostMapping("capital/list")
    @Validation(fields = {"mtCompanyId"})
    public RestResponse capitalList(@Val @RequestBody PaymentRequest request) {
        IPage<PaymentListResponse> page = paymentService.capitalList(request);
        return RestResponse.success(page, MessageUtils.get("msg.query.success"));
    }

    /**
     * @param request 收款详情查询条件
     * @return RestResponse 付款详情
     * @description 查询维保收款详情
     * @date 2020/2/24 10:47 上午
     */
    @PostMapping("maintenance/detail")
    @Validation(fields = {"mtCompanyId", "id"})
    public RestResponse maintenanceDetail(@Val @RequestBody PaymentRequest request){
        PaymentResponse response = paymentService.maintenanceDetail(request);
       if (ObjectUtil.isEmpty(response)){
           return RestResponse.success();
       }
       return RestResponse.success(response, MessageUtils.get("msg.query.detail.success"));
    }

    /**
     * @param request 收款详情查询条件
     * @return RestResponse 付款详情
     * @description 查询大修收款详情
     * @date 2020/4/28 2:16 下午
     */
    @PostMapping("capital/detail")
    @Validation(fields = {"mtCompanyId", "id"})
    public RestResponse capitalDetail(@Val @RequestBody PaymentRequest request){
        PaymentResponse response = paymentService.capitalDetail(request);
        if (ObjectUtil.isEmpty(response)){
            return RestResponse.success();
        }
        return RestResponse.success(response, MessageUtils.get("msg.query.detail.success"));
    }

    /**
     * @param request 收款列表
     * @return 1.成功, 0.失败, 消息描述
     * @description 批量修改收款信息
     * @date 2020/2/24 10:47 上午
     */
    @PostMapping("batch/modify")
    @Validation(fields = {"paymentList"})
    public RestResponse batchModify(@Val @RequestBody PaymentRequest request) {
        return paymentService.modifyBatchById(request);
    }

    /**
     * @param request 操作记录查询条件
     * @return RestResponse 付款操作记录分页列表结果
     * @description 查询付款操作记录列表
     * @date 2020/2/26 5:13 下午
     */
    @PostMapping("history/list")
    @Validation(fields = {"contractId"})
    public RestResponse historyList(@Val @RequestBody PaymentRequest request) {
        IPage<PaymentHistoryResponse> page = paymentHistoryService.list(request);
        return RestResponse.success(page, MessageUtils.get("msg.query.success"));
    }
}
