|
@@ -1,6 +1,7 @@
|
|
|
package com.tzld.piaoquan.recommend.feature.service;
|
|
|
|
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
+import com.google.common.base.Strings;
|
|
|
import com.tzld.piaoquan.recommend.feature.model.common.Result;
|
|
|
import com.tzld.piaoquan.recommend.feature.model.feature.FeatureKeyProto;
|
|
|
import com.tzld.piaoquan.recommend.feature.model.feature.MultiGetFeatureRequest;
|
|
@@ -11,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -39,20 +41,21 @@ public class FeatureV2Service {
|
|
|
List<String> redisKeys = CommonCollectionUtils.toList(request.getFeatureKeyList(), fk -> redisKey(fk));
|
|
|
List<String> values = redisTemplate.opsForValue().multiGet(redisKeys);
|
|
|
|
|
|
- Map<String, String> feature = new HashMap<>();
|
|
|
- for (int i = 0; i < request.getFeatureKeyCount(); i++) {
|
|
|
- feature.put(request.getFeatureKeyList().get(i).getUniqueKey(), values.get(i));
|
|
|
- }
|
|
|
-
|
|
|
MultiGetFeatureResponse.Builder builder = MultiGetFeatureResponse.newBuilder();
|
|
|
builder.setResult(Result.newBuilder().setCode(1));
|
|
|
- builder.putAllFeature(feature);
|
|
|
+ for (int i = 0; i < request.getFeatureKeyCount(); i++) {
|
|
|
+ builder.putFeature(request.getFeatureKeyList().get(i).getUniqueKey(),
|
|
|
+ Strings.nullToEmpty(values.get(i)));
|
|
|
+ }
|
|
|
return builder.build();
|
|
|
}
|
|
|
|
|
|
// Note:写入和读取的key生成规则应保持一致
|
|
|
private String redisKey(FeatureKeyProto fk) {
|
|
|
List<String> fields = tableFieldConfig.get(fk.getTableName());
|
|
|
+ if (CollectionUtils.isEmpty(fields)) {
|
|
|
+ return fk.getTableName();
|
|
|
+ }
|
|
|
StringBuilder sb = new StringBuilder(fk.getTableName());
|
|
|
for (String field : fields) {
|
|
|
sb.append(":");
|