|
@@ -0,0 +1,56 @@
|
|
|
|
+package com.tzld.piaoquan.abtest.client;
|
|
|
|
+
|
|
|
|
+import com.tzld.piaoquan.abtest.client.model.*;
|
|
|
|
+import net.devh.boot.grpc.client.inject.GrpcClient;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+import static com.google.common.base.Strings.nullToEmpty;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author dyp
|
|
|
|
+ */
|
|
|
|
+@Component
|
|
|
|
+//@Slf4j
|
|
|
|
+public class ABTestClient {
|
|
|
|
+ @GrpcClient("abtest")
|
|
|
|
+ private ExpServiceGrpc.ExpServiceBlockingStub expClient;
|
|
|
|
+ @GrpcClient("abtest")
|
|
|
|
+ private GroupServiceGrpc.GroupServiceBlockingStub groupClient;
|
|
|
|
+
|
|
|
|
+ public String getGroup(String mid, String uid, int appType, String group) {
|
|
|
|
+ GetGroupRequest request = GetGroupRequest.newBuilder()
|
|
|
|
+ .setMid(nullToEmpty(mid))
|
|
|
|
+ .setUid(nullToEmpty(uid))
|
|
|
|
+ .setAppType(appType)
|
|
|
|
+ .setGroup(group)
|
|
|
|
+ .build();
|
|
|
|
+ GetGroupResponse response = groupClient.getGroup(request);
|
|
|
|
+ if (response == null || !response.hasResult()) {
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+ if (response.getResult().getCode() != 1) {
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+ return response.getGroup();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Map<String, String> getExp(String mid, String uid, int appType, String group) {
|
|
|
|
+ GetExpRequest request = GetExpRequest.newBuilder()
|
|
|
|
+ .setMid(nullToEmpty(mid))
|
|
|
|
+ .setUid(nullToEmpty(uid))
|
|
|
|
+ .setAppType(appType)
|
|
|
|
+ .setGroup(group)
|
|
|
|
+ .build();
|
|
|
|
+ GetExpResponse response = expClient.getExp(request);
|
|
|
|
+ if (response == null || !response.hasResult()) {
|
|
|
|
+ return Collections.emptyMap();
|
|
|
|
+ }
|
|
|
|
+ if (response.getResult().getCode() != 1) {
|
|
|
|
+ return Collections.emptyMap();
|
|
|
|
+ }
|
|
|
|
+ return response.getExpMap();
|
|
|
|
+ }
|
|
|
|
+}
|