MerchantStaffPersonalService.java 9.54 KB
package cn.com.glsx.stoassistant.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.scrm.shopmall.dto.integral.motivation.ShopmallStaffMotivationDTO;
import cn.com.glsx.scrm.shopmall.enums.integral.MerchantScoreSourceEnum;
import cn.com.glsx.scrm.shopmall.model.ShopmallStaffMotivationOperation;
import cn.com.glsx.scrm.shopmall.remote.StaffMotivationRemote;
import cn.com.glsx.stoassistant.annotation.LogSupport;
import cn.com.glsx.stoassistant.convert.ConvertRequest;
import cn.com.glsx.stoassistant.convert.ConvertResponse;
import cn.com.glsx.stoassistant.model.request.score.MerchantStaffScoreSearchRpcRequest;
import cn.com.glsx.stoassistant.model.request.withdrawal.MerchantStaffWithdrawalBankDTO;
import cn.com.glsx.stoassistant.model.request.withdrawal.MerchantStaffWithdrawalInsertRpcRequest;
import cn.com.glsx.stoassistant.model.request.withdrawal.MerchantStaffWithdrawalSearchRpcRequest;
import cn.com.glsx.stoassistant.model.response.score.MerchantStaffScoreDetailRpcResponse;
import cn.com.glsx.stoassistant.model.response.score.MerchantStaffScoreListRpcResponse;
import cn.com.glsx.stoassistant.model.response.score.MerchantStaffScorePageRpcResponse;
import cn.com.glsx.stoassistant.model.response.withdrawal.MerchantStaffWithdrawalListRpcResponse;
import cn.com.glsx.stoassistant.remote.MerchantStaffScoreRemote;
import cn.com.glsx.stoassistant.remote.MerchantStaffWithdrawalRemote;
import cn.com.glsx.stoassistant.request.CommonIdRequest;
import cn.com.glsx.stoassistant.request.merchant.MerchantBaseInfoRequest;
import cn.com.glsx.stoassistant.request.withdrawal.MerchantStaffScoreSearchRopRequest;
import cn.com.glsx.stoassistant.request.withdrawal.MerchantStaffWithdrawalBankRequest;
import cn.com.glsx.stoassistant.request.withdrawal.MerchantStaffWithdrawalInsertRopRequest;
import cn.com.glsx.stoassistant.response.score.MerchantStaffScoreDetailRopResponse;
import cn.com.glsx.stoassistant.response.score.MerchantStaffScoreListRopResponse;
import cn.com.glsx.stoassistant.response.score.MerchantStaffWithdrawalBankVO;
import cn.com.glsx.stoassistant.response.withdrawal.MerchantStaffWithdrawalListRopResponse;
import cn.com.glsx.stoassistant.utils.CommonUtil;
import cn.com.glsx.stoassistant.utils.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName MerchantStaffPersonalService
 * @Description
 * @Author lichongyuan
 * @Date 2022/10/15
 */
@Service
public class MerchantStaffPersonalService {

    @Autowired
    private MerchantStaffWithdrawalRemote merchantStaffWithdrawalRemote;

    @Autowired
    private MerchantStaffScoreRemote merchantStaffScoreRemote;

    @Autowired
    private StaffMotivationRemote staffMotivationRemote;

    /**
     * 个人中心-员工积分列表()
     *
     * @param request
     */
    @LogSupport(module = "个人中心",method = "员工积分列表")
    public MerchantStaffScoreDetailRopResponse getStaffScoreDetail(MerchantStaffScoreSearchRopRequest request) {
        MerchantStaffScoreSearchRpcRequest param = ConvertRequest.convertRequest(request, new MerchantStaffScoreSearchRpcRequest());
        RpcResponse<MerchantStaffScoreDetailRpcResponse> rpcResponse = merchantStaffScoreRemote.getStaffScoreDetail(param);
        if (rpcResponse.isSuccess()) {
            MerchantStaffScoreDetailRpcResponse result = rpcResponse.getResult();
            MerchantStaffScoreDetailRopResponse response = ConvertResponse.convertObject(result, MerchantStaffScoreDetailRopResponse.class);
            return response;
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getException().getMessage());
    }

    /**
     * 个人中心-员工提现列表
     *
     * @param request
     * @return
     */
    @LogSupport(module = "个人中心",method = "员工提现列表")
    public List<MerchantStaffWithdrawalListRopResponse> getWithdrawalList(MerchantStaffScoreSearchRopRequest request) {
        MerchantStaffWithdrawalSearchRpcRequest param = ConvertRequest.convertRequest(request, new MerchantStaffWithdrawalSearchRpcRequest());
        RpcResponse<List<MerchantStaffWithdrawalListRpcResponse>> rpcResponse = merchantStaffWithdrawalRemote.getList(param);
        if (rpcResponse.isSuccess()) {
            List<MerchantStaffWithdrawalListRopResponse> response = ConvertResponse.convertList(rpcResponse.getResult(), MerchantStaffWithdrawalListRopResponse.class);
            return response;
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getException().getMessage());
    }

    /**
     * 单个提现
     *
     * @param request
     */
    @LogSupport(module = "个人中心",method = "单个提现")
    public void insertWithdrawal(MerchantStaffWithdrawalInsertRopRequest request) {
        MerchantStaffWithdrawalInsertRpcRequest param = ConvertRequest.convertRequest(request, new MerchantStaffWithdrawalInsertRpcRequest());
        param.setStaffSource(MerchantScoreSourceEnum.MERCHANT_4S.getValue());
        RpcResponse<Boolean> rpcResponse = merchantStaffWithdrawalRemote.insertWithdrawal(param);
        if (rpcResponse.isFailed()) {
            throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getException().getMessage());
        }
    }

    /**
     * 获取员工收益列表分页
     * @param request
     * @return
     */
    public Pagination<MerchantStaffScoreListRopResponse> getStaffScoreList(MerchantStaffScoreSearchRopRequest request) {
        RpcPagination<MerchantStaffScoreSearchRpcRequest> param = ConvertRequest.convertPage(request, new MerchantStaffScoreSearchRpcRequest());
        RpcResponse<MerchantStaffScorePageRpcResponse> rpcResponse = merchantStaffScoreRemote.getPage(param);
        if (rpcResponse.isSuccess()) {
            MerchantStaffScorePageRpcResponse result = rpcResponse.getResult();
            Pagination<MerchantStaffScoreListRopResponse> response = ConvertResponse.convertPage(result.getPagination(), MerchantStaffScoreListRopResponse.class);
            return response;
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getException().getMessage());
    }

    public MerchantStaffScoreListRpcResponse getStaffScoreDetailById(CommonIdRequest request) {
        RpcResponse<MerchantStaffScoreListRpcResponse> rpcResponse = merchantStaffScoreRemote.getById(request.getId());
        if (rpcResponse.isSuccess()) {
            return rpcResponse.getResult();
        }
        throw new RpcServiceException(rpcResponse.getException().getMessage());
    }

    /**
     * 插入或更新员工银行卡信息
     *
     * @param request
     */
    public Boolean insertOrUpdateStaffBank(MerchantStaffWithdrawalBankRequest request) {
        MerchantStaffWithdrawalBankDTO param = ConvertRequest.convertRequest(request, new MerchantStaffWithdrawalBankDTO());
        RpcResponse<Boolean> rpcResponse = merchantStaffWithdrawalRemote.insertOrUpdateStaffBank(param);
        if (rpcResponse.isSuccess()){
            return rpcResponse.getResult();
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getException().getMessage());
    }

    /**
     * 根据员工id查询员工银行卡列表
     *
     * @param request
     */
    public List<MerchantStaffWithdrawalBankVO> staffBankList(MerchantStaffWithdrawalBankRequest request) {
        MerchantStaffWithdrawalBankDTO param = ConvertRequest.convertRequest(request, new MerchantStaffWithdrawalBankDTO());
        RpcResponse<List<MerchantStaffWithdrawalBankDTO>> rpcResponse = merchantStaffWithdrawalRemote.staffBankList(param);
        if (rpcResponse.isSuccess()){
            return ConvertResponse.convertList(rpcResponse.getResult(),MerchantStaffWithdrawalBankVO.class);
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getException().getMessage());
    }

    /**
     * 根据员工id查询员工银行卡列表
     *
     * @param request
     */
    public MerchantStaffWithdrawalBankVO staffBankDetail(MerchantStaffWithdrawalBankRequest request) {
        RpcResponse<MerchantStaffWithdrawalBankDTO> rpcResponse = merchantStaffWithdrawalRemote.staffBankDetail(request.getId());
        if (rpcResponse.isSuccess()){
            return ConvertResponse.convertObject(rpcResponse.getResult(),MerchantStaffWithdrawalBankVO.class);
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getException().getMessage());
    }

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

    }

    public List<ShopmallStaffMotivationOperation> getOrderOperation(MerchantStaffScoreSearchRopRequest request) {
        ShopmallStaffMotivationDTO req = CommonUtil.convertRequest(ShopmallStaffMotivationDTO.class);
        RpcResponse<List<ShopmallStaffMotivationOperation>> rpcResponse = staffMotivationRemote.getOrderOperation(req);
        if (rpcResponse.isSuccess()) {
            return rpcResponse.getResult();
        }
        throw new RpcServiceException(rpcResponse.getException().getErrId(), rpcResponse.getException().getMessage());
    }
}