SycService.java 5.83 KB
package cn.com.glsx.entmicro.service;

import cn.com.glsx.entmicro.convert.ConvertRequest;
import cn.com.glsx.entmicro.model.request.SyncCustomerBaseRpcRequest;
import cn.com.glsx.entmicro.model.request.SyncCustomerRpcRequest;
import cn.com.glsx.entmicro.model.request.SyncDepartmentRpcRequest;
import cn.com.glsx.entmicro.model.request.SyncStaffRpcRequest;
import cn.com.glsx.entmicro.remote.SyncRemote;
import cn.com.glsx.entmicro.request.synchronization.SyncCustomerBaseRequest;
import cn.com.glsx.entmicro.request.synchronization.SyncCustomerRequest;
import cn.com.glsx.entmicro.request.synchronization.SyncDepartmentRequest;
import cn.com.glsx.entmicro.request.synchronization.SyncStaffRequest;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author Lichongyuan
 * @Description: 同步服务
 * @date 2021/10/19 16:07
 */
@Service
@Slf4j
public class SycService {

    @Autowired
    private SyncRemote syncRemote;

    /**
     * 同步部门
     *
     * @param syncDepartmentRequest
     */
    public void sycDepartment(SyncDepartmentRequest syncDepartmentRequest) {
        SyncDepartmentRpcRequest sycDepartmentRpcRequest = ConvertRequest.convertRequest(syncDepartmentRequest, new SyncDepartmentRpcRequest());
        RpcResponse<Boolean> response = syncRemote.sycDepartment(sycDepartmentRpcRequest);
        if (response.isFailed()) {
            throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
        }
    }

    /**
     * 同步员工
     *
     * @param syncStaffRequest
     */
    public void sycStaff(SyncStaffRequest syncStaffRequest) {
        SyncStaffRpcRequest sycStaffRpcRequest = ConvertRequest.convertRequest(syncStaffRequest, new SyncStaffRpcRequest());
        RpcResponse<Boolean> response = syncRemote.sycStaff(sycStaffRpcRequest);
        if (response.isFailed()) {
            throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
        }
    }

    /**
     * 同步客户
     *
     * @param syncCustomerRequest
     */
    public void sycCustomer(SyncCustomerRequest syncCustomerRequest) {
        SyncCustomerRpcRequest sycCustomerRpcRequest = ConvertRequest.convertRequest(syncCustomerRequest, new SyncCustomerRpcRequest());
        RpcResponse<Boolean> response = syncRemote.sycCustomer(sycCustomerRpcRequest);
        if (StringUtils.isNotEmpty(syncCustomerRequest.getUserIdList())) {
            String[] split = syncCustomerRequest.getUserIdList().split(",");
            sycCustomerRpcRequest.setUserIds(new ArrayList<>(Arrays.asList(split)));
        }
        if (response.isFailed()) {
            throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
        }
    }

    /**
     * 同步客户群
     */
    public void sycCustomerBase(SyncCustomerBaseRequest syncCustomerBaseRequest) {
        SyncCustomerBaseRpcRequest sycCustomerBaseRpcRequest = ConvertRequest.convertRequest(syncCustomerBaseRequest, new SyncCustomerBaseRpcRequest());
        if (StringUtils.isNotEmpty(syncCustomerBaseRequest.getUserIdList())) {
            String[] split = syncCustomerBaseRequest.getUserIdList().split(",");
            sycCustomerBaseRpcRequest.setUserIds(new ArrayList<>(Arrays.asList(split)));
        }
        RpcResponse<Boolean> response = syncRemote.sycCustomerBase(sycCustomerBaseRpcRequest);
        if (response.isFailed()) {
            throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
        }
    }


    /**
     * 同步标签
     */
    public void syncTag(SyncCustomerBaseRequest syncCustomerBaseRequest) {
        SyncCustomerBaseRpcRequest sycCustomerBaseRpcRequest = ConvertRequest.convertRequest(syncCustomerBaseRequest, new SyncCustomerBaseRpcRequest());
        RpcResponse<Boolean> response = syncRemote.syncTag(sycCustomerBaseRpcRequest);
        if (response.isFailed()) {
            throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
        }
    }

    /**
     * 维格表同步指定门店企微客户
     */
    public Boolean syncCustomer2Vika(SyncDepartmentRequest syncDepartmentRequest) {
        SyncDepartmentRpcRequest request = ConvertRequest.convertRequest(syncDepartmentRequest, new SyncDepartmentRpcRequest());
        RpcResponse<Boolean> response = syncRemote.syncCustomer2Vika(request);
        if (response.isFailed()) {
            throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
        }
        return response.getResult();
    }

    /**
     * 同步客户企微类型标签
     */
    public Boolean syncCustomerTypeTagHandle(SyncCustomerRequest syncCustomerRequest) {
        SyncCustomerRpcRequest request = ConvertRequest.convertRequest(syncCustomerRequest, new SyncCustomerRpcRequest());
        RpcResponse<Boolean> response = syncRemote.syncCustomerTypeTagHandle(request);
        if (response.isFailed()) {
            throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
        }
        return response.getResult();
    }

    /**
     * 同步客户企微类型标签
     */
    public Boolean syncCustomerRemarkToCdp(SyncCustomerRequest syncCustomerRequest) {
        SyncCustomerRpcRequest request = ConvertRequest.convertRequest(syncCustomerRequest, new SyncCustomerRpcRequest());
        RpcResponse<Boolean> response = syncRemote.syncCustomerRemarkToCdp(null);
        if (response.isFailed()) {
            throw new RpcServiceException(response.getException().getErrId(), response.getMessage());
        }
        return response.getResult();
    }
}