BusiAssistantMerchantService.java 9.81 KB
package cn.com.glsx.busassistant.service;

import cn.com.glsx.busassistant.converter.ConvertRequest;
import cn.com.glsx.busassistant.converter.ConvertResponse;
import cn.com.glsx.busassistant.model.request.activity.CoProductRpcRequest;
import cn.com.glsx.busassistant.model.request.activity.MerchantBySceneRemoteRpcRequest;
import cn.com.glsx.busassistant.model.request.merchant.MerchantApplyPageRequest;
import cn.com.glsx.busassistant.model.request.merchant.MerchantApplyRpcRequest;
import cn.com.glsx.busassistant.model.request.merchant.MerchantBySceneRpcRequest;
import cn.com.glsx.busassistant.model.request.merchant.MerchantConfirmRpcRequest;
import cn.com.glsx.busassistant.model.request.messageBox.MessageBoxPageRpcRequest;
import cn.com.glsx.busassistant.model.response.merchant.MerchantApplyRpcResponse;
import cn.com.glsx.busassistant.model.response.merchant.MerchantBaseRpcResponse;
import cn.com.glsx.busassistant.model.response.merchant.MerchantBySceneRpcResponse;
import cn.com.glsx.busassistant.model.response.messageBox.MessageBoxPageRpcResponse;
import cn.com.glsx.busassistant.remote.BusiAssistantMerchantRemote;
import cn.com.glsx.busassistant.remote.BusiAssistantMessageBoxRemote;
import cn.com.glsx.busassistant.request.merchant.CoProductRopRequest;
import cn.com.glsx.busassistant.request.merchant.*;
import cn.com.glsx.busassistant.request.messageBox.MessageBoxPageRopRequest;
import cn.com.glsx.busassistant.response.ServiceMerchantRopResponse;
import cn.com.glsx.busassistant.response.merchant.MerchantBaseRopResponse;
import cn.com.glsx.busassistant.response.merchant.MerchantBySceneRopResponse;
import cn.com.glsx.busassistant.response.merchant.MerchantPageRopResponse;
import cn.com.glsx.busassistant.response.merchant.MerchantRopResponse;
import cn.com.glsx.busassistant.response.messageBox.MessageBoxPageRopResponse;
import cn.com.glsx.busassistant.util.Pagination;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.merchants.model.request.serviceCenter.SearchMerchantRpcRequest;
import cn.com.glsx.merchants.model.response.serviceCenter.SearchMerchantRpcResponse;
import cn.com.glsx.merchants.remote.MerchantRemote;
import cn.com.glsx.scrm.proxy.enums.ProxyRequestSourceEnum;
import cn.com.glsx.scrm.proxy.model.CommonProxyRequest;
import cn.com.glsx.scrm.proxy.model.ProxyBaseResponse;
import cn.com.glsx.scrm.proxy.remote.CommonProxyRemote;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author xiongzs
 * @Description 生意助手-门店服务
 * @date 2022/10/16 15:18
 * @Version 1.0
 */

@Service
@Slf4j
public class BusiAssistantMerchantService {

    @Autowired
    private BusiAssistantMerchantRemote merchantRemote;

    @Autowired
    private BusiAssistantMessageBoxRemote messageBoxRemote;

    @Autowired
    private CommonProxyRemote commonProxyRemote;

    @Autowired
    private MerchantRemote platformMerchantRemote;



    /**
     * 门店申请列表
     *
     * @param ropRequest
     * @return
     */
    public Pagination<MerchantPageRopResponse> getApplyMerchantPage(MerchantPageRopRequest ropRequest) {
        MerchantApplyPageRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new MerchantApplyPageRequest());
        RpcResponse<RpcPagination<MerchantApplyRpcResponse>> rpcResponse = merchantRemote.getApplyMerchantPage(rpcRequest);
        if (rpcResponse.isSuccess()) {
            return ConvertResponse.convertPage(rpcResponse.getResult(), MerchantPageRopResponse.class);
        }
        throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
    }

    /**
     * 申请门店
     *
     * @param request
     * @return
     */
    public void addApplyMerchant(MerchantApplyRopRequest request) {
        MerchantApplyRpcRequest rpcRequest = ConvertRequest.convertRequest(request, new MerchantApplyRpcRequest());
        RpcResponse<Boolean> response = merchantRemote.addApplyMerchant(rpcRequest);
        if (response.isFailed()) {
            throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
        }
    }

    /**
     * 确认开通门店
     *
     * @param ropRequest
     */
    public void confirmMerchant(MerchantConfirmRopRequest ropRequest) {
        MerchantConfirmRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new MerchantConfirmRpcRequest());
        RpcResponse<Boolean> response = merchantRemote.confirmMerchant(rpcRequest);
        if (response.isFailed()) {
            throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
        }
    }


    /**
     * 根据场景查询已开通的商户
     *
     * @param ropRequest
     */
    public List<MerchantBySceneRopResponse> findMerchantByScene(MerchantBySceneRopRequest ropRequest) {
        MerchantBySceneRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new MerchantBySceneRpcRequest());
        RpcResponse<List<MerchantBySceneRpcResponse>> response = merchantRemote.findMerchantByScene(rpcRequest);
        if (response.isSuccess()) {
            return ConvertResponse.convertList(response.getResult(), MerchantBySceneRopResponse.class);
        }
        throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
    }

    /**
     * 查询消息列表
     *
     * @param pageReuest
     * @return
     */
    public Pagination<MessageBoxPageRopResponse> getMessageBoxPage(MessageBoxPageRopRequest pageReuest) {
        MessageBoxPageRpcRequest rpcRequest = ConvertRequest.convertRequest(pageReuest, new MessageBoxPageRpcRequest());
        RpcResponse<RpcPagination<MessageBoxPageRpcResponse>> rpcResponse = messageBoxRemote.getMessageBoxPage(rpcRequest);
        if (rpcResponse.isSuccess()) {
            return ConvertResponse.convertPage(rpcResponse.getResult(), MessageBoxPageRopResponse.class);
        }
        throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
    }

    /**
     * 查询是否有未读消息
     *
     * @param serviceMerchantId
     */
    public Boolean checkMessageReadStatus(Integer serviceMerchantId) {
        RpcResponse<Boolean> response = messageBoxRemote.checkMessageReadStatus(serviceMerchantId);
        if (response.isSuccess()) {
            return response.getResult();
        }
        throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
    }

    public MessageBoxPageRopResponse getNewestMessage(Integer serviceMerchantId) {
        RpcResponse<MessageBoxPageRpcResponse> response = messageBoxRemote.getNewestMessage(serviceMerchantId);
        if (response.isSuccess()) {
            return ConvertResponse.convertObject(response.getResult(), MessageBoxPageRopResponse.class);
        }
        throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
    }

    public Boolean addCoProduct(CoProductRopRequest ropRequest){
        CoProductRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new CoProductRpcRequest());
        RpcResponse<Boolean> response = merchantRemote.addCoProduct(rpcRequest);
        if (response.isSuccess()) {
            return response.getResult();
        }
        throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
    }

    public List<MerchantBaseRopResponse> getMerchantListBySceneRemote(MerchantBySceneRemoteRopRequest ropRequest){

        MerchantBySceneRemoteRpcRequest rpcRequest = ConvertRequest.convertRequest(ropRequest, new MerchantBySceneRemoteRpcRequest());
        RpcResponse<List<MerchantBaseRpcResponse>> response = merchantRemote.getMerchantListBySceneRemote(rpcRequest);
        if (response.isSuccess()) {
            return ConvertResponse.convertList(response.getResult(), MerchantBaseRopResponse.class);
        }
        throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
    }


    public List<MerchantRopResponse> getMerchantIdByMerchantNo(MerchantRopRequest request){
        final String requestMethod = "merchants.api.open.findMerchantList";
        CommonProxyRequest proxyRequest = new CommonProxyRequest();
        LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("merchantNoStr",request.getMerchantNos());
        proxyRequest.setRequestMethod(requestMethod);
        proxyRequest.setRequestSource(ProxyRequestSourceEnum.MERCHANT.getSource());
        proxyRequest.setParams(params);
        RpcResponse<ProxyBaseResponse> response = commonProxyRemote.proxyRequest(proxyRequest);
        if (!response.hasResult()){
            throw new RpcServiceException(DefaultErrorEnum.RPC_ERROR.getValue(),"查询商户详情失败");
        }
        return response.getResult().getList(MerchantRopResponse.class);
    }

    public List<ServiceMerchantRopResponse> selectMerchantPage(SearchMerchantRpcRequest rpcRequest){
        RpcResponse<RpcPagination<SearchMerchantRpcResponse>> merchantRpcPage = platformMerchantRemote.searchByMerchantNos(rpcRequest);
        List<ServiceMerchantRopResponse> resultList = new ArrayList<>();
        if (!merchantRpcPage.hasResult()){
            log.error("查询商户分页失败");
            return resultList;
        }
        List<SearchMerchantRpcResponse> list = merchantRpcPage.getResult().getList();
        list.forEach(v->{
            ServiceMerchantRopResponse response = new ServiceMerchantRopResponse();
            BeanUtils.copyProperties(v,response);
            resultList.add(response);
        });
        return resultList;
    }
}