MerchantStaffWithdrawalService.java 7.69 KB
package cn.com.glsx.merchants.service;

import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.convert.ConvertRequest;
import cn.com.glsx.merchants.convert.ConvertResponse;
import cn.com.glsx.merchants.request.withdrawal.MerchantStaffFailBatchRopRequest;
import cn.com.glsx.merchants.request.withdrawal.MerchantStaffWithdrawalSearchRopRequest;
import cn.com.glsx.merchants.request.withdrawal.MerchantStaffWithdrawalUpdateRopRequest;
import cn.com.glsx.merchants.request.withdrawal.StaffWithdrawalImportRopRequest;
import cn.com.glsx.merchants.response.withdrawal.MerchantStaffWithdrawalListRopResponse;
import cn.com.glsx.merchants.response.withdrawal.StaffImportWithdrawalRopResponse;
import cn.com.glsx.merchants.response.withdrawal.StaffWithdrawalUrlRopResponse;
import cn.com.glsx.merchants.util.WithdrawalPagination;
import cn.com.glsx.stoassistant.model.request.withdrawal.MerchantStaffFailBatchRpcRequest;
import cn.com.glsx.stoassistant.model.request.withdrawal.MerchantStaffWithdrawalInsertRpcRequest;
import cn.com.glsx.stoassistant.model.request.withdrawal.MerchantStaffWithdrawalSearchRpcRequest;
import cn.com.glsx.stoassistant.model.request.withdrawal.StaffWithdrawalImportRpcRequest;
import cn.com.glsx.stoassistant.model.response.withdrawal.MerchantStaffWithdrawalListRpcResponse;
import cn.com.glsx.stoassistant.model.response.withdrawal.MerchantStaffWithdrawalPageRpcResponse;
import cn.com.glsx.stoassistant.model.response.withdrawal.StaffImportWithdrawalRpcResponse;
import cn.com.glsx.stoassistant.model.response.withdrawal.StaffWithdrawalUrlRpcResponse;
import cn.com.glsx.stoassistant.remote.MerchantStaffWithdrawalRemote;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName MerchantStaffWithdrawalService
 * @Description
 * @Author lichongyuan
 * @Date 2022/10/14
 */
@Service
public class MerchantStaffWithdrawalService {

    @Autowired
    private MerchantStaffWithdrawalRemote merchantStaffWithdrawalRemote;

    /**
     * 获取提现管理列表
     *
     * @param request
     * @return
     */
    public WithdrawalPagination<MerchantStaffWithdrawalListRopResponse> getWithdrawalPage(MerchantStaffWithdrawalSearchRopRequest request) {
        RpcPagination<MerchantStaffWithdrawalSearchRpcRequest> param = ConvertRequest.convertPage(request, new MerchantStaffWithdrawalSearchRpcRequest());
        param.getCondition().setMerchantId(request.getMerchantNo());
        RpcResponse<MerchantStaffWithdrawalPageRpcResponse> rpcResponse = merchantStaffWithdrawalRemote.getPage(param);
        if (rpcResponse.isSuccess()) {
            WithdrawalPagination<MerchantStaffWithdrawalListRopResponse> pagination = convertWithdrawalPage(rpcResponse.getResult(), MerchantStaffWithdrawalListRopResponse.class);
            return pagination;
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
    }

    /**
     * 提现列表分页转换
     *
     * @return 新分页参数
     */
    private static <E, T> WithdrawalPagination<T> convertWithdrawalPage(MerchantStaffWithdrawalPageRpcResponse response, Class<T> clazz) {
        RpcPagination<MerchantStaffWithdrawalListRpcResponse> list = response.getPagination();
        WithdrawalPagination pagination = new WithdrawalPagination();
        BeanUtils.copyProperties(response, pagination);
        pagination.setReceivedAmount(response.getReceivedAmount());
        pagination.setReceivingAmount(response.getReceivingAmount());
        pagination.setReviewingAmount(response.getReviewingAmount());
        pagination.setFailureAmount(response.getFailureAmount());
        pagination.setTotalAmount(response.getTotalAmount());
        pagination.setPageNum(list.getPageNum());
        List<T> newList = ConvertResponse.convertList(list.getList(), clazz);
        pagination.setData(newList);
        pagination.setCount((int) list.getTotal());
        pagination.setPageSize(list.getPageSize());
        return pagination;
    }

    /**
     * 批量提现审核
     */
    public void batchWithdrawal(MerchantStaffWithdrawalUpdateRopRequest request) {
        MerchantStaffWithdrawalInsertRpcRequest param = ConvertRequest.convertRequest(request, new MerchantStaffWithdrawalInsertRpcRequest());
        param.setMerchantId(request.getMerchantNo());
        param.setIdList(request.getIdList());
        RpcResponse<Boolean> rpcResponse = merchantStaffWithdrawalRemote.batchWithdrawal(param);
        if (rpcResponse.isFailed()) {
            throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
        }
    }

    /**
     * 导出提现列表
     * @param request
     * @return
     */
    public String exportList(MerchantStaffWithdrawalSearchRopRequest request) {
        MerchantStaffWithdrawalSearchRpcRequest param = ConvertRequest.convertRequest(request, new MerchantStaffWithdrawalSearchRpcRequest());
        param.setMerchantId(request.getMerchantNo());
        RpcResponse<String> rpcResponse = merchantStaffWithdrawalRemote.exportList(param);
        if (rpcResponse.isSuccess()) {
            return rpcResponse.getResult();
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
    }

    public Boolean failBatch(MerchantStaffFailBatchRopRequest request) {
        MerchantStaffFailBatchRpcRequest rpcRequest = ConvertRequest.convertRequest(request, new MerchantStaffFailBatchRpcRequest());
        RpcResponse<Boolean> rpcResponse = merchantStaffWithdrawalRemote.failBatch(rpcRequest);
        if (rpcResponse.isSuccess()) {
            return rpcResponse.getResult();
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
    }

    public StaffImportWithdrawalRopResponse importBankWithdrawal(StaffWithdrawalImportRopRequest request) {

        StaffWithdrawalImportRpcRequest rpcRequest = ConvertRequest.convertRequest(request, new StaffWithdrawalImportRpcRequest());
        RpcResponse<StaffImportWithdrawalRpcResponse> rpcResponse = merchantStaffWithdrawalRemote.importBankWithdrawal(rpcRequest);
        if (rpcResponse.isSuccess()) {
            return ConvertResponse.convertObject(rpcResponse.getResult(),StaffImportWithdrawalRopResponse.class);
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());
    }

    public StaffWithdrawalUrlRopResponse exportBankWithdrawal(MerchantStaffWithdrawalSearchRopRequest request) {
        MerchantStaffWithdrawalSearchRpcRequest rpcRequest = ConvertRequest.convertRequest(request, new MerchantStaffWithdrawalSearchRpcRequest());
        RpcResponse<StaffWithdrawalUrlRpcResponse> rpcResponse = merchantStaffWithdrawalRemote.exportBankWithdrawal(rpcRequest);
        if (rpcResponse.isSuccess()) {
            return ConvertResponse.convertObject(rpcResponse.getResult(),StaffWithdrawalUrlRopResponse.class);
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());

    }

    public String getWithdrawalRate(Integer merchantId) {
        RpcResponse<String> rpcResponse = merchantStaffWithdrawalRemote.getWithdrawalRate(merchantId);
        if (rpcResponse.isSuccess()) {
            return rpcResponse.getResult();
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getMessage());

    }
}