|
@@ -4,6 +4,7 @@ import com.google.common.reflect.TypeToken;
|
|
import com.tzld.piaoquan.recommend.feature.model.feature.FeatureKeyProto;
|
|
import com.tzld.piaoquan.recommend.feature.model.feature.FeatureKeyProto;
|
|
import com.tzld.piaoquan.recommend.server.remote.FeatureV2RemoteService;
|
|
import com.tzld.piaoquan.recommend.server.remote.FeatureV2RemoteService;
|
|
import com.tzld.piaoquan.recommend.server.util.JSONUtils;
|
|
import com.tzld.piaoquan.recommend.server.util.JSONUtils;
|
|
|
|
+import lombok.Data;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -24,8 +25,8 @@ public class FeatureService {
|
|
/**
|
|
/**
|
|
* @return k1:视频、k2:表、k3:特征、v:特征值
|
|
* @return k1:视频、k2:表、k3:特征、v:特征值
|
|
*/
|
|
*/
|
|
- public Map<String, Map<String, Map<String, String>>> getFeature(List<String> vidList, String appType,
|
|
|
|
- String province) {
|
|
|
|
|
|
+ public Feature getFeature(String mid, List<String> vidList, String appType,
|
|
|
|
+ String province) {
|
|
|
|
|
|
List<FeatureKeyProto> protos = new ArrayList<>();
|
|
List<FeatureKeyProto> protos = new ArrayList<>();
|
|
|
|
|
|
@@ -70,31 +71,44 @@ public class FeatureService {
|
|
|
|
|
|
Map<String, String> result = remoteService.getFeature(protos);
|
|
Map<String, String> result = remoteService.getFeature(protos);
|
|
|
|
|
|
- Map<String, Map<String, Map<String, String>>> data = new HashMap<>();
|
|
|
|
|
|
+ Feature feature = new Feature();
|
|
|
|
|
|
result.entrySet().forEach(e -> {
|
|
result.entrySet().forEach(e -> {
|
|
|
|
|
|
|
|
+ String[] uk = StringUtils.split(e.getKey(), ":");
|
|
|
|
+ String prefix = uk[0];
|
|
|
|
+ String table = uk[1];
|
|
Map<String, String> colMap = JSONUtils.fromJson(e.getValue(), new TypeToken<Map<String, String>>() {
|
|
Map<String, String> colMap = JSONUtils.fromJson(e.getValue(), new TypeToken<Map<String, String>>() {
|
|
}, Collections.emptyMap());
|
|
}, Collections.emptyMap());
|
|
- String feature = colMap.get("feature");
|
|
|
|
|
|
+ String featureStr = colMap.get("feature");
|
|
|
|
+
|
|
|
|
+ switch (prefix) {
|
|
|
|
+ case "v":
|
|
|
|
+ String vid = uk[2];
|
|
|
|
+ Map<String, Map<String, String>> tableFeatureMap = feature.getVideoFeature().getOrDefault(vid, new HashMap<>());
|
|
|
|
+ tableFeatureMap.put(table, JSONUtils.fromJson(featureStr, new TypeToken<Map<String, String>>() {
|
|
|
|
+ }, Collections.emptyMap()));
|
|
|
|
+ feature.getVideoFeature().put(vid, tableFeatureMap);
|
|
|
|
+ break;
|
|
|
|
+ case "u":
|
|
|
|
+ feature.getUserFeature().put(table, JSONUtils.fromJson(featureStr, new TypeToken<Map<String, String>>() {
|
|
|
|
+ }, Collections.emptyMap()));
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
|
|
- String[] uk = StringUtils.split(e.getKey(), ":");
|
|
|
|
- String vid = uk[1];
|
|
|
|
- String table = uk[0];
|
|
|
|
- Map<String, Map<String, String>> tableFeatureMap = data.getOrDefault(vid, new HashMap<>());
|
|
|
|
- tableFeatureMap.put(table, JSONUtils.fromJson(feature, new TypeToken<Map<String, String>>() {
|
|
|
|
- }, Collections.emptyMap()));
|
|
|
|
- data.put(vid, tableFeatureMap);
|
|
|
|
});
|
|
});
|
|
|
|
|
|
return data;
|
|
return data;
|
|
}
|
|
}
|
|
|
|
|
|
- private final String ukFormat = "%s:%s";
|
|
|
|
|
|
+ private final String videoUkFormat = "v:%s:%s";
|
|
|
|
+ private final String userUkFormat = "u:%s";
|
|
|
|
|
|
private FeatureKeyProto genWithVid(String table, String vid) {
|
|
private FeatureKeyProto genWithVid(String table, String vid) {
|
|
return FeatureKeyProto.newBuilder()
|
|
return FeatureKeyProto.newBuilder()
|
|
- .setUniqueKey(String.format(ukFormat, table, vid))
|
|
|
|
|
|
+ .setUniqueKey(String.format(videoUkFormat, table, vid))
|
|
.setTableName(table)
|
|
.setTableName(table)
|
|
.putFieldValue("vid", vid)
|
|
.putFieldValue("vid", vid)
|
|
.build();
|
|
.build();
|
|
@@ -102,7 +116,7 @@ public class FeatureService {
|
|
|
|
|
|
private FeatureKeyProto genWithVidAndAppType(String table, String vid, String appType) {
|
|
private FeatureKeyProto genWithVidAndAppType(String table, String vid, String appType) {
|
|
return FeatureKeyProto.newBuilder()
|
|
return FeatureKeyProto.newBuilder()
|
|
- .setUniqueKey(String.format(ukFormat, table, vid))
|
|
|
|
|
|
+ .setUniqueKey(String.format(videoUkFormat, table, vid))
|
|
.setTableName(table)
|
|
.setTableName(table)
|
|
.putFieldValue("vid", vid)
|
|
.putFieldValue("vid", vid)
|
|
.putFieldValue("apptype", appType)
|
|
.putFieldValue("apptype", appType)
|
|
@@ -111,7 +125,7 @@ public class FeatureService {
|
|
|
|
|
|
private FeatureKeyProto genWithVidAndProvince(String table, String vid, String province) {
|
|
private FeatureKeyProto genWithVidAndProvince(String table, String vid, String province) {
|
|
return FeatureKeyProto.newBuilder()
|
|
return FeatureKeyProto.newBuilder()
|
|
- .setUniqueKey(String.format(ukFormat, table, vid))
|
|
|
|
|
|
+ .setUniqueKey(String.format(videoUkFormat, table, vid))
|
|
.setTableName(table)
|
|
.setTableName(table)
|
|
.putFieldValue("vid", vid)
|
|
.putFieldValue("vid", vid)
|
|
.putFieldValue("province", province)
|
|
.putFieldValue("province", province)
|
|
@@ -120,7 +134,7 @@ public class FeatureService {
|
|
|
|
|
|
private FeatureKeyProto genWithVidAndHeadVid(String table, String vid, String headVid) {
|
|
private FeatureKeyProto genWithVidAndHeadVid(String table, String vid, String headVid) {
|
|
return FeatureKeyProto.newBuilder()
|
|
return FeatureKeyProto.newBuilder()
|
|
- .setUniqueKey(String.format(ukFormat, table, vid))
|
|
|
|
|
|
+ .setUniqueKey(String.format(videoUkFormat, table, vid))
|
|
.setTableName(table)
|
|
.setTableName(table)
|
|
.putFieldValue("vid", vid)
|
|
.putFieldValue("vid", vid)
|
|
.putFieldValue("headVid", )
|
|
.putFieldValue("headVid", )
|
|
@@ -129,11 +143,19 @@ public class FeatureService {
|
|
|
|
|
|
private FeatureKeyProto genWithMid(String table, String mid) {
|
|
private FeatureKeyProto genWithMid(String table, String mid) {
|
|
return FeatureKeyProto.newBuilder()
|
|
return FeatureKeyProto.newBuilder()
|
|
- .setUniqueKey(String.format(ukFormat, table, mid))
|
|
|
|
|
|
+ .setUniqueKey(String.format(userUkFormat, table))
|
|
.setTableName(table)
|
|
.setTableName(table)
|
|
.putFieldValue("mid", )
|
|
.putFieldValue("mid", )
|
|
.build();
|
|
.build();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Data
|
|
|
|
+ public static class Feature {
|
|
|
|
+ // k1:视频、k2:表、k3:特征、v:特征值
|
|
|
|
+ private Map<String, Map<String, Map<String, String>>> videoFeature = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ // k1:表、k2:特征、v:特征值
|
|
|
|
+ private Map<String, Map<String, String>> userFeature = new HashMap<>();
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|