|
@@ -3,21 +3,26 @@ package com.tzld.longarticle.recommend.server.service;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
+import com.tzld.longarticle.recommend.server.common.enums.AccountBusinessTypeEnum;
|
|
|
import com.tzld.longarticle.recommend.server.common.enums.FeishuRobotIdEnum;
|
|
|
import com.tzld.longarticle.recommend.server.mapper.aigc.AigcBaseMapper;
|
|
|
import com.tzld.longarticle.recommend.server.mapper.crawler.CrawlerBaseMapper;
|
|
|
+import com.tzld.longarticle.recommend.server.model.dto.AccountTypeFansDTO;
|
|
|
import com.tzld.longarticle.recommend.server.model.dto.NotPublishPlan;
|
|
|
import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishAccount;
|
|
|
+import com.tzld.longarticle.recommend.server.model.entity.crawler.AccountAvgInfo;
|
|
|
import com.tzld.longarticle.recommend.server.model.entity.crawler.GetOffVideoCrawler;
|
|
|
import com.tzld.longarticle.recommend.server.model.entity.crawler.LongArticlesRootSourceId;
|
|
|
import com.tzld.longarticle.recommend.server.model.entity.crawler.LongArticlesVideo;
|
|
|
import com.tzld.longarticle.recommend.server.model.entity.longArticle.GetOffVideoArticle;
|
|
|
import com.tzld.longarticle.recommend.server.model.entity.longArticle.LongArticlesMatchVideo;
|
|
|
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.LongArticlesReadRate;
|
|
|
import com.tzld.longarticle.recommend.server.repository.crawler.GetOffVideoCrawlerRepository;
|
|
|
-import com.tzld.longarticle.recommend.server.repository.crawler.LongArticlesRootSourceIdRepository;
|
|
|
import com.tzld.longarticle.recommend.server.repository.crawler.LongArticlesVideoRepository;
|
|
|
import com.tzld.longarticle.recommend.server.repository.longArticle.GetOffVideoArticleRepository;
|
|
|
import com.tzld.longarticle.recommend.server.repository.longArticle.LongArticlesMatchVideoRepository;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.longArticle.LongArticlesReadRateRepository;
|
|
|
import com.tzld.longarticle.recommend.server.util.DateUtils;
|
|
|
import com.tzld.longarticle.recommend.server.util.feishu.FeishuMessageSender;
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
@@ -30,6 +35,7 @@ import org.springframework.util.StringUtils;
|
|
|
import java.time.LocalTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -49,7 +55,10 @@ public class XxlJobService {
|
|
|
@Autowired
|
|
|
private LongArticlesMatchVideoRepository longArticlesMatchVideoRepository;
|
|
|
@Autowired
|
|
|
- private LongArticlesRootSourceIdRepository longArticlesRootSourceIdRepository;
|
|
|
+ private LongArticlesReadRateRepository longArticlesReadRateRepository;
|
|
|
+
|
|
|
+ @ApolloJsonValue("${touliu.account.ghIds:[\"gh_93e00e187787\", \"gh_ac43e43b253b\", \"gh_68e7fdc09fe4\",\"gh_77f36c109fb1\", \"gh_b181786a6c8c\", \"gh_1ee2e1b39ccf\"]}")
|
|
|
+ private List<String> touliuAccountGhIds;
|
|
|
|
|
|
@XxlJob("checkPublishPlan")
|
|
|
public ReturnT<String> checkPublishPlan(String param) {
|
|
@@ -149,8 +158,8 @@ public class XxlJobService {
|
|
|
log.error("Error processCrawlerEachData: {}", JSONObject.toJSONString(longArticlesVideo), e);
|
|
|
FeishuMessageSender.sendWebHookMessage(FeishuRobotIdEnum.JOB.getRobotId(),
|
|
|
"processCrawlerEachData 异常\n"
|
|
|
- + "异常数据: " + longArticlesVideo.getTraceId() + "\n"
|
|
|
- + "错误信息:" + e.getMessage());
|
|
|
+ + "异常数据: " + longArticlesVideo.getTraceId() + "\n"
|
|
|
+ + "错误信息:" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -205,4 +214,60 @@ public class XxlJobService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @XxlJob("accountAvgInfoV3Job")
|
|
|
+ public ReturnT<String> accountAvgInfoV3Job(String param) {
|
|
|
+ long timeStamp = DateUtils.getBeforeDayStart(1);
|
|
|
+ if (StringUtils.hasText(param)) {
|
|
|
+ timeStamp = DateUtils.getStartOfDay(param, "yyyyMMdd");
|
|
|
+ }
|
|
|
+ String dateStr = DateUtils.timestampToYMDStr(timeStamp, "yyyy-MM-dd");
|
|
|
+ List<AccountTypeFansDTO> accountList = aigcBaseMapper.getAccountTypeFans();
|
|
|
+ List<LongArticlesReadRate> readRateList = longArticlesReadRateRepository.findAll();
|
|
|
+ Map<String, Double> rateDict = readRateList.stream().collect(Collectors.toMap(o -> o.getGhId() + "_" + o.getPosition(),
|
|
|
+ LongArticlesReadRate::getReadRateAvg));
|
|
|
+ for (AccountTypeFansDTO accountTypeFansDTO : accountList) {
|
|
|
+ saveAccountAvgInfo(accountTypeFansDTO, rateDict, dateStr);
|
|
|
+ }
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void saveAccountAvgInfo(AccountTypeFansDTO account, Map<String, Double> rateDict, String date) {
|
|
|
+ int businessType = touliuAccountGhIds.contains(account.getGhId()) ?
|
|
|
+ AccountBusinessTypeEnum.TOULIU.getType() : AccountBusinessTypeEnum.CHANGWEN.getType();
|
|
|
+ if (account.getFollowerCount() > 0) {
|
|
|
+ List<AccountAvgInfo> saveList = new ArrayList<>();
|
|
|
+ for (int index = 1; index <= 8; index++) {
|
|
|
+ String ghIdPosition = account.getGhId() + "_" + index;
|
|
|
+ if (rateDict.containsKey(ghIdPosition)) {
|
|
|
+ double rate = rateDict.get(ghIdPosition);
|
|
|
+ double readAvg = account.getFollowerCount() * rate;
|
|
|
+ AccountAvgInfo accountAvgInfo = new AccountAvgInfo();
|
|
|
+ accountAvgInfo.setGhId(account.getGhId());
|
|
|
+ accountAvgInfo.setPosition(String.valueOf(index));
|
|
|
+ accountAvgInfo.setUpdateTime(date);
|
|
|
+ accountAvgInfo.setAccountName(account.getName());
|
|
|
+ accountAvgInfo.setFans(account.getFollowerCount());
|
|
|
+ accountAvgInfo.setReadAvg(readAvg);
|
|
|
+ accountAvgInfo.setStatus(1);
|
|
|
+ accountAvgInfo.setAccountType(account.getAccountType());
|
|
|
+ accountAvgInfo.setAccountMode(account.getModeType());
|
|
|
+ accountAvgInfo.setAccountSource(account.getAccountSourceName());
|
|
|
+ accountAvgInfo.setAccountStatus(account.getStatus());
|
|
|
+ accountAvgInfo.setBusinessType(businessType);
|
|
|
+ accountAvgInfo.setReadRateAvg(rate);
|
|
|
+ saveList.add(accountAvgInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isNotEmpty(saveList)) {
|
|
|
+ try {
|
|
|
+ crawlerBaseMapper.batchInsertAccountAvgInfo(saveList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ crawlerBaseMapper.deleteAccountAvgInfoByGhIdAndUpdateTime(account.getGhId(), date);
|
|
|
+ crawlerBaseMapper.batchInsertAccountAvgInfo(saveList);
|
|
|
+ }
|
|
|
+ crawlerBaseMapper.updateAccountAvgInfoStatus(account.getGhId(), date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|