DeliveryRuleServiceRpcClient.java 1.84 KB
package com.infoloop.tianting.service.client;

import com.infoloop.tianting.deliveryruleservice.ClientLabelTypeEnum;
import com.infoloop.tianting.deliveryruleservice.GetClientLabelsByIdsRpcRequest;
import com.infoloop.tianting.deliveryruleservice.GetClientLabelsByIdsRpcResponse;
import com.infoloop.tianting.deliveryruleservice.QueryClientLabelsByConditionRpcRequest;
import com.infoloop.tianting.deliveryruleservice.QueryClientLabelsByConditionRpcResponse;
import com.infoloop.tianting.deliveryruleservice.TiantingDeliveryRuleServiceRpcGrpc;
import com.infoloop.tianting.model.dto.ClientLabelDTO.QueryLabelsDto;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DeliveryRuleServiceRpcClient {

  private final TiantingDeliveryRuleServiceRpcGrpc.TiantingDeliveryRuleServiceRpcBlockingStub
      deliveryRuleServiceRpcBlockingStub;

  public QueryClientLabelsByConditionRpcResponse getLabelsByTypes(QueryLabelsDto queryLabelsDto) {
    final var request = QueryClientLabelsByConditionRpcRequest.newBuilder()
        .setEnterpriseId(queryLabelsDto.getEnterpriseId())
        .setShouldFilterTypes(true)
        .addAllTypes(queryLabelsDto.getTypes())
        .setIncludeDeleted(false)
        .build();
    return deliveryRuleServiceRpcBlockingStub.queryClientLabelsByCondition(request);

  }

  public GetClientLabelsByIdsRpcResponse GetClientLabelsByIds(Integer enterpriseId, List<Integer> ids) {
    final var request = GetClientLabelsByIdsRpcRequest
        .newBuilder()
        .setEnterpriseId(enterpriseId)
        .setIncludeDeleted(false)
        .addAllIds(ids)
        .build();
    return  deliveryRuleServiceRpcBlockingStub.getClientLabelsByIds(request);
  }


}