|
@@ -1,7 +1,10 @@
|
|
|
package com.tzld.longarticle.recommend.server.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
import com.tzld.longarticle.recommend.server.model.*;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.crawler.PublishContentSortLogRepository;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.entity.crawler.PublishContentSortLog;
|
|
|
import com.tzld.longarticle.recommend.server.service.rank.RankParam;
|
|
|
import com.tzld.longarticle.recommend.server.service.rank.RankResult;
|
|
|
import com.tzld.longarticle.recommend.server.service.rank.RankService;
|
|
@@ -13,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
@@ -20,6 +24,7 @@ import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author dyp
|
|
@@ -32,9 +37,13 @@ public class RecommendService {
|
|
|
private RecallService recallService;
|
|
|
@Autowired
|
|
|
private RankService rankService;
|
|
|
+ @Autowired
|
|
|
+ private PublishContentSortLogRepository publishContentSortLogRepository;
|
|
|
|
|
|
@ApolloJsonValue("${accountStrategyConfig:{}}")
|
|
|
private Map<String, String> accountStrategyConfigMap;
|
|
|
+ @Value("${spring.profiles.active}")
|
|
|
+ private String env;
|
|
|
|
|
|
|
|
|
public RecommendResponse recommend(RecommendRequest request) {
|
|
@@ -52,6 +61,8 @@ public class RecommendService {
|
|
|
RankResult rankResult = rankService.rank(convertToRankParam(param, recallResult));
|
|
|
log.info("rankResult {}", JSONUtils.toJson(rankResult));
|
|
|
|
|
|
+ saveSortLog(param, rankResult);
|
|
|
+
|
|
|
return buildRecommendResponse(recallResult, rankResult, param.getPublishNum());
|
|
|
}
|
|
|
|
|
@@ -123,4 +134,23 @@ public class RecommendService {
|
|
|
return rankParam;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 记录 账号、排序策略、结果。。。
|
|
|
+ * @param param
|
|
|
+ * @param rankResult
|
|
|
+ */
|
|
|
+ private void saveSortLog(RecommendParam param, RankResult rankResult) {
|
|
|
+ if (!"prod".equals(env)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ PublishContentSortLog log = new PublishContentSortLog();
|
|
|
+ log.setGhId(param.getGhId());
|
|
|
+ log.setAccountName(param.getAccountName());
|
|
|
+ log.setStrategy(param.getStrategy());
|
|
|
+ List<String> publishContentIds = rankResult.getContents().stream().map(Content::getId).collect(Collectors.toList());
|
|
|
+ log.setPublishContentId(JSONObject.toJSONString(publishContentIds));
|
|
|
+ log.setCreateTimestamp(System.currentTimeMillis());
|
|
|
+ publishContentSortLogRepository.save(log);
|
|
|
+ }
|
|
|
+
|
|
|
}
|