|
@@ -1,17 +1,25 @@
|
|
|
package com.tzld.longarticle.recommend.server.service.recommend;
|
|
|
|
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
+import com.tzld.longarticle.recommend.server.mapper.longArticle.LongArticleBaseMapper;
|
|
|
+import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishAccount;
|
|
|
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.ArticlePoolPromotionSource;
|
|
|
import com.tzld.longarticle.recommend.server.model.entity.longArticle.DatastatSortStrategy;
|
|
|
import com.tzld.longarticle.recommend.server.model.vo.IdNameVO;
|
|
|
+import com.tzld.longarticle.recommend.server.model.vo.WxContentDetailResponse;
|
|
|
import com.tzld.longarticle.recommend.server.model.vo.aigc.ProduceContentListItemVO;
|
|
|
import com.tzld.longarticle.recommend.server.model.vo.aigc.ProducePlanDetailVO;
|
|
|
import com.tzld.longarticle.recommend.server.model.vo.aigc.ProducePlanInputSourceParam;
|
|
|
+import com.tzld.longarticle.recommend.server.remote.WxFetchRemoteService;
|
|
|
import com.tzld.longarticle.recommend.server.remote.aigc.AIGCCrawlerPlanSaveService;
|
|
|
import com.tzld.longarticle.recommend.server.remote.aigc.AIGCProduceContentListService;
|
|
|
import com.tzld.longarticle.recommend.server.remote.aigc.AIGCProducePlanDetailService;
|
|
|
import com.tzld.longarticle.recommend.server.remote.aigc.AIGCProducePlanSaveService;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.aigc.PublishAccountRepository;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.longArticle.ArticlePoolPromotionSourceRepository;
|
|
|
import com.tzld.longarticle.recommend.server.repository.longArticle.DatastatSortStrategyRepository;
|
|
|
import com.tzld.longarticle.recommend.server.util.DateUtils;
|
|
|
+import com.tzld.longarticle.recommend.server.util.Md5Util;
|
|
|
import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -26,6 +34,8 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
public class ArticlePromotionService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ LongArticleBaseMapper longArticleBaseMapper;
|
|
|
@Autowired
|
|
|
DatastatSortStrategyRepository datastatSortStrategyRepository;
|
|
|
@Autowired
|
|
@@ -36,6 +46,12 @@ public class ArticlePromotionService {
|
|
|
AIGCProducePlanSaveService aigcProducePlanSaveService;
|
|
|
@Autowired
|
|
|
AIGCProduceContentListService aigcProduceContentListService;
|
|
|
+ @Autowired
|
|
|
+ ArticlePoolPromotionSourceRepository articlePoolPromotionSourceRepository;
|
|
|
+ @Autowired
|
|
|
+ WxFetchRemoteService wxFetchRemoteService;
|
|
|
+ @Autowired
|
|
|
+ PublishAccountRepository publishAccountRepository;
|
|
|
|
|
|
@ApolloJsonValue("${articlePromotionProduceConfig:{}}")
|
|
|
private Map<String, Map<String, Map<String, String>>> produceConfig;
|
|
@@ -45,9 +61,11 @@ public class ArticlePromotionService {
|
|
|
public void articlePromotion(String pos, String way, String accountNickName, String tag,
|
|
|
Integer viewCountFilter, Double viewCountRateFilter, List<Integer> positionFilter) {
|
|
|
String today = DateUtils.getCurrentDateStr("yyyyMMdd");
|
|
|
+ String dateStrFilter = DateUtils.getBeforeDaysDateStr("yyyyMMdd", 10);
|
|
|
// 获取内部表现
|
|
|
- List<DatastatSortStrategy> list = datastatSortStrategyRepository.getByViewCountGreaterThanEqualAndReadRateGreaterThanEqualAndPositionIn(
|
|
|
- viewCountFilter, viewCountRateFilter, positionFilter);
|
|
|
+ List<DatastatSortStrategy> list = longArticleBaseMapper.getArticlePromotion(viewCountFilter, viewCountRateFilter,
|
|
|
+ 10000, dateStrFilter, positionFilter);
|
|
|
+ list = filterEarlyContent(list);
|
|
|
log.info("优质{}文章数量: {}", accountNickName, list.size());
|
|
|
List<DatastatSortStrategy> distinct = filterSameTitle(list);
|
|
|
distinct.sort(Comparator.comparing(DatastatSortStrategy::getDateStr, Comparator.reverseOrder()));
|
|
@@ -55,6 +73,19 @@ public class ArticlePromotionService {
|
|
|
addUrlListToAccount(accountNickName, distinct, pos, way, today, tag);
|
|
|
}
|
|
|
|
|
|
+ private List<DatastatSortStrategy> filterEarlyContent(List<DatastatSortStrategy> list) {
|
|
|
+ List<String> ghIds = list.stream().map(DatastatSortStrategy::getGhId).distinct().collect(Collectors.toList());
|
|
|
+ List<PublishAccount> publishAccountList = publishAccountRepository.getAllByGhIdIn(ghIds);
|
|
|
+ Map<String, Long> publishAccountCreateTimeMap = publishAccountList.stream().collect(Collectors.toMap(
|
|
|
+ PublishAccount::getGhId, PublishAccount::getCreateTimestamp));
|
|
|
+ list = list.stream().filter(o -> {
|
|
|
+ long publishTime = DateUtils.dateStrToTimestamp(o.getDateStr(), "yyyyMMdd");
|
|
|
+ Long accountCreateTime = publishAccountCreateTimeMap.get(o.getGhId());
|
|
|
+ return publishTime * 1000 > accountCreateTime;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
private List<DatastatSortStrategy> filterSameTitle(List<DatastatSortStrategy> list) {
|
|
|
List<DatastatSortStrategy> result = new ArrayList<>();
|
|
|
List<String> titles = new ArrayList<>();
|
|
@@ -103,11 +134,11 @@ public class ArticlePromotionService {
|
|
|
continue;
|
|
|
}
|
|
|
filterUrlList.add(url);
|
|
|
- // todo 调用爬虫 detail 接口并保存数据
|
|
|
- Map<String, String> detail = getArticleDetail(url);
|
|
|
+ // 调用爬虫 detail 接口并保存数据
|
|
|
+ WxContentDetailResponse detail = getArticleDetail(url);
|
|
|
if (detail != null) {
|
|
|
String level = pos.equals("【1】") ? contentPoolType.get(0) : contentPoolType.get(1);
|
|
|
- saveArticlePoolPromotionSource(detail.get("channel_content_id"), wxSn, title, level);
|
|
|
+ saveArticlePoolPromotionSource(detail.getChannelContentId(), wxSn, title, level);
|
|
|
}
|
|
|
}
|
|
|
if (filterUrlList.isEmpty()) {
|
|
@@ -228,14 +259,27 @@ public class ArticlePromotionService {
|
|
|
return params;
|
|
|
}
|
|
|
|
|
|
- private Map<String, String> getArticleDetail(String url) {
|
|
|
- // 返回文章详情的逻辑
|
|
|
- return new HashMap<>();
|
|
|
+ public WxContentDetailResponse getArticleDetail(String url) {
|
|
|
+ if (url == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return wxFetchRemoteService.getContent(url);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("URL error: " + url);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
private void saveArticlePoolPromotionSource(String channelContentId, String wxSn, String title, String level) {
|
|
|
- // 保存文章数据的逻辑
|
|
|
- log.info("Saved: " + channelContentId + ", " + wxSn + ", " + title + ", " + level);
|
|
|
+ ArticlePoolPromotionSource articlePromotion = new ArticlePoolPromotionSource();
|
|
|
+ articlePromotion.setChannelContentId(channelContentId);
|
|
|
+ articlePromotion.setWxSn(wxSn);
|
|
|
+ articlePromotion.setTitle(title);
|
|
|
+ articlePromotion.setTitleMd5(Md5Util.encoderByMd5(title));
|
|
|
+ articlePromotion.setLevel(level);
|
|
|
+ articlePromotion.setCreateTimestamp(System.currentTimeMillis());
|
|
|
+ articlePoolPromotionSourceRepository.save(articlePromotion);
|
|
|
}
|
|
|
|
|
|
private void articleAddDependPlan(String produceId, String planId, String planName) {
|