Browse Source

增加账号类别 历史表现按账号类别计算 rankV15增加裂变值排序

wangyunpeng 3 tháng trước cách đây
mục cha
commit
07924d8c44

+ 32 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/aigc/MiniprogramUseTypeEnum.java

@@ -0,0 +1,32 @@
+package com.tzld.longarticle.recommend.server.common.enums.aigc;
+
+import lombok.Getter;
+
+@Getter
+public enum MiniprogramUseTypeEnum {
+    Default(1, "自然流"),
+    Touliu(2, "投流"),
+    Qiwei(3, "企微"),
+    Daitou(4, "代投"),
+    GzhDaixuan(5, "公众号合作代选"),
+    ;
+
+
+    private final int val;
+    private final String description;
+
+    MiniprogramUseTypeEnum(int val, String description) {
+        this.val = val;
+        this.description = description;
+    }
+
+    public static MiniprogramUseTypeEnum from(int val) {
+        for (MiniprogramUseTypeEnum typeEnum : MiniprogramUseTypeEnum.values()) {
+            if (typeEnum.getVal() == val) {
+                return typeEnum;
+            }
+        }
+
+        return Default;
+    }
+}

+ 7 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/mapper/aigc/PublishContentMapper.java

@@ -2,6 +2,7 @@ package com.tzld.longarticle.recommend.server.mapper.aigc;
 
 import com.tzld.longarticle.recommend.server.model.dto.*;
 import com.tzld.longarticle.recommend.server.model.entity.aigc.*;
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.Account;
 import com.tzld.longarticle.recommend.server.model.param.MiniprogramTaskParam;
 import com.tzld.longarticle.recommend.server.model.param.PublishContentParam;
 import org.apache.ibatis.annotations.Mapper;
@@ -56,4 +57,10 @@ public interface PublishContentMapper {
     void updatePublishContentSingleMiniProgram(List<String> publishContentIds);
 
     void updatePublishContentStatus(String sourceId, Integer status, Integer oldStatus);
+
+    List<String> getPublishAccountIds();
+
+    List<Account> getAccountByIds(List<String> accountIds);
+
+    List<PublishPlanMiniprogramTask> getAccountMiniprogramTaskList(String id);
 }

+ 1 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/dto/ContentHisPublishArticle.java

@@ -12,6 +12,7 @@ public class ContentHisPublishArticle {
 
     private String ghId;
     private String accountName;
+    private String accountType;
     private String msgId;
     private String title;
     private Integer itemIndex;

+ 41 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/entity/longArticle/Account.java

@@ -0,0 +1,41 @@
+package com.tzld.longarticle.recommend.server.model.entity.longArticle;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Entity
+@Table(name = "account")
+public class Account {
+
+    @Id
+    @Column(name = "id")
+    private String id;
+
+    @Column(name = "name")
+    private String name;
+
+    @Column(name = "gh_id")
+    private String ghId;
+
+    @Column(name = "type")
+    private String type;
+
+    @Column(name = "status")
+    private Integer status;
+
+    @Column(name = "create_timestamp")
+    private Long createTimestamp;
+
+    @Column(name = "update_timestamp")
+    private Long updateTimestamp;
+
+}

+ 15 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/longArticle/AccountRepository.java

@@ -0,0 +1,15 @@
+package com.tzld.longarticle.recommend.server.repository.longArticle;
+
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.Account;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface AccountRepository extends JpaRepository<Account, String> {
+
+    List<Account> getByStatus(Integer status);
+
+    Account getByGhId(String ghId);
+}

+ 82 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/XxlJobService.java

@@ -9,6 +9,7 @@ import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import com.tzld.longarticle.recommend.server.common.CommonThreadPoolExecutor;
 import com.tzld.longarticle.recommend.server.common.enums.FieshuTableColumnDataTypeEnum;
+import com.tzld.longarticle.recommend.server.common.enums.aigc.MiniprogramUseTypeEnum;
 import com.tzld.longarticle.recommend.server.common.enums.aigc.ProduceContentAuditStatusEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.AccountBusinessTypeEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ContentPoolEnum;
@@ -20,10 +21,7 @@ import com.tzld.longarticle.recommend.server.mapper.growth.NewPushMessageCallbac
 import com.tzld.longarticle.recommend.server.mapper.longArticle.LongArticleBaseMapper;
 import com.tzld.longarticle.recommend.server.model.dto.*;
 import com.tzld.longarticle.recommend.server.model.dto.aigc.BadCrawlerAccountDTO;
-import com.tzld.longarticle.recommend.server.model.entity.aigc.CrawlerPlan;
-import com.tzld.longarticle.recommend.server.model.entity.aigc.ProducePlan;
-import com.tzld.longarticle.recommend.server.model.entity.aigc.ProduceReviewRecord;
-import com.tzld.longarticle.recommend.server.model.entity.aigc.PublishAccount;
+import com.tzld.longarticle.recommend.server.model.entity.aigc.*;
 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.LongArticlesVideo;
@@ -110,6 +108,8 @@ public class XxlJobService {
     private ProducePlanRepository producePlanRepository;
     @Autowired
     private AIGCProduceContentAuditService aigcProduceContentAuditService;
+    @Autowired
+    private AccountRepository accountRepository;
 
     ExecutorService thread = new CommonThreadPoolExecutor(
             5,
@@ -843,4 +843,82 @@ public class XxlJobService {
         return ReturnT.SUCCESS;
     }
 
+    @XxlJob("refreshAccountJob")
+    public ReturnT<String> refreshAccount(String param) {
+        List<String> accountIds = publishContentMapper.getPublishAccountIds();
+        List<Account> accountList = publishContentMapper.getAccountByIds(accountIds);
+        List<Account> existsAccounts = accountRepository.findAll();
+        Map<String, Account> existsAccountMap = existsAccounts.stream().collect(
+                Collectors.toMap(Account::getId, Function.identity()));
+        List<String> existsAccountIds = existsAccounts.stream().map(Account::getId).collect(Collectors.toList());
+        Long now = System.currentTimeMillis();
+        Map<String, List<Integer>> accountNameMap = new HashMap<>();
+        for (Account account : accountList) {
+            String type = StringUtils.hasText(account.getType()) && account.getType().contains("买号") ? "买号" : "代运营";
+            // 投流判断
+            List<PublishPlanMiniprogramTask> miniprogramTaskList = publishContentMapper.getAccountMiniprogramTaskList(account.getId());
+            if (CollectionUtil.isNotEmpty(miniprogramTaskList)) {
+                List<Integer> useTypeList = miniprogramTaskList.stream().map(PublishPlanMiniprogramTask::getMiniprogramUseType)
+                        .distinct().collect(Collectors.toList());
+                for (Integer useType : useTypeList) {
+                    if (useType.equals(MiniprogramUseTypeEnum.Touliu.getVal())
+                            || useType.equals(MiniprogramUseTypeEnum.Daitou.getVal()))  {
+                        type = MiniprogramUseTypeEnum.from(useType).getDescription();
+                        break;
+                    }
+                }
+                if (useTypeList.size() > 1) {
+                    accountNameMap.put(account.getName(), useTypeList);
+                }
+            }
+            account.setType(type);
+            if (!existsAccountIds.contains(account.getId())) {
+                account.setStatus(1);
+                account.setCreateTimestamp(now);
+            } else {
+                Account existAccount = existsAccountMap.get(account.getId());
+                account.setStatus(existAccount.getStatus());
+                account.setCreateTimestamp(existAccount.getCreateTimestamp());
+            }
+            account.setUpdateTimestamp(now);
+            accountRepository.save(account);
+        }
+        sendRefreshAccountMsg(accountNameMap);
+        return ReturnT.SUCCESS;
+    }
+
+    private void sendRefreshAccountMsg(Map<String, List<Integer>> accountNameMap) {
+        if (CollectionUtil.isNotEmpty(accountNameMap)) {
+            List<FeishuTableDTO.Column> columns = buildRefreshAccountColumns();
+            List<JSONObject> rows = new ArrayList<>();
+            for (Map.Entry<String, List<Integer>> entry : accountNameMap.entrySet()) {
+                JSONObject row = new JSONObject();
+                row.put("account_name", entry.getKey());
+                List<String> useTypeList = entry.getValue().stream().map(MiniprogramUseTypeEnum::from)
+                        .map(MiniprogramUseTypeEnum::getDescription).collect(Collectors.toList());
+                row.put("ues_type", useTypeList);
+                rows.add(row);
+            }
+
+            FeishuTableDTO tableDTO = FeishuTableDTO.createTable("账号类型更新异常", columns, rows, true);
+            JSONObject content = JSONObject.parseObject(JSONObject.toJSONString(tableDTO));
+            JSONObject bodyParam = new JSONObject();
+            bodyParam.put("msg_type", "interactive");
+            bodyParam.put("card", content);
+            FeishuMessageSender.sendWebHookMessage(FeishuRobotIdEnum.DAILY.getRobotId(), bodyParam);
+        }
+    }
+
+    private List<FeishuTableDTO.Column> buildRefreshAccountColumns() {
+        List<FeishuTableDTO.Column> columns = new ArrayList<>();
+        FeishuTableDTO.Column planIdColumn = FeishuTableDTO.createFeishuColumns(
+                FieshuTableColumnDataTypeEnum.TEXT.getType(), "account_name", "账号名称", null);
+        columns.add(planIdColumn);
+        FeishuTableDTO.Column planNameColumn = FeishuTableDTO.createFeishuColumns(
+                FieshuTableColumnDataTypeEnum.TEXT.getType(), "ues_type", "用途类型列表", null);
+        columns.add(planNameColumn);
+
+        return columns;
+    }
+
 }

+ 26 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV15Strategy.java

@@ -38,8 +38,8 @@ public class RankV15Strategy implements RankStrategy {
     @Autowired
     private StrategyIndexScoreWeightService weightService;
 
-    @ApolloJsonValue("${touliu.account.ghIds:[\"gh_93e00e187787\", \"gh_ac43e43b253b\", \"gh_68e7fdc09fe4\",\"gh_77f36c109fb1\", \"gh_b181786a6c8c\", \"gh_1ee2e1b39ccf\"]}")
-    private List<String> touliuAccountGhIds;
+    @ApolloJsonValue("${notAddFissionScoreAccount:[]}")
+    private List<String> notAddFissionScoreAccount;
 
     public RankResult rank(RankParam param) {
         List<Content> result = new ArrayList<>();
@@ -57,8 +57,30 @@ public class RankV15Strategy implements RankStrategy {
             item.setScoreMap(scoreMap.get(c.getId()));
             double score;
             int index = weightService.getIndex(item.getContent().getContentPoolType(), contentPools);
-            if (contentPools[0].equals(item.getContent().getContentPoolType())
-                    || contentPools[1].equals(item.getContent().getContentPoolType())) {
+            if (contentPools[0].equals(item.getContent().getContentPoolType())) {
+                score = item.getScore(ScoreStrategyEnum.HIS_FISSION_DE_WEIGHT_AVG_READ_SUM_RATE.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.HIS_FISSION_DE_WEIGHT_AVG_READ_SUM_RATE.value())
+                        + item.getScore(ScoreStrategyEnum.SIMILARITY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.SIMILARITY.value())
+                        + item.getScore(ScoreStrategyEnum.CATEGORY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.CATEGORY.value())
+                        + item.getScore(ScoreStrategyEnum.FLOW_CTL_DECREASE.value())
+                        + item.getScore(ScoreStrategyEnum.CRAWLER_DAYS_DECREASE_STRATEGY.value());
+                if (item.getScore(ScoreStrategyEnum.PUBLISH_TIMES.value()) >= 0) {
+                    score += item.getScore(ScoreStrategyEnum.VIEW_COUNT_RATE.value())
+                            * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                            ScoreStrategyEnum.VIEW_COUNT_RATE.value());
+                }
+                // 部分账号实验 不增加裂变分
+                if (notAddFissionScoreAccount.contains(param.getAccountName())) {
+                    score -= item.getScore(ScoreStrategyEnum.HIS_FISSION_DE_WEIGHT_AVG_READ_SUM_RATE.value())
+                            * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                            ScoreStrategyEnum.HIS_FISSION_DE_WEIGHT_AVG_READ_SUM_RATE.value());
+                }
+            } else if (contentPools[1].equals(item.getContent().getContentPoolType())) {
                 score = item.getScore(ScoreStrategyEnum.SIMILARITY.value())
                         * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
                         ScoreStrategyEnum.SIMILARITY.value())

+ 17 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/recall/RecallService.java

@@ -116,6 +116,8 @@ public class RecallService implements ApplicationContextAware {
     PublishPlanRepository publishPlanRepository;
     @Autowired
     ProducePlanExeRecordRepository producePlanExeRecordRepository;
+    @Autowired
+    AccountRepository accountRepository;
 
     private final Map<String, RecallStrategy> strategyMap = new HashMap<>();
     private ApplicationContext applicationContext;
@@ -375,7 +377,7 @@ public class RecallService implements ApplicationContextAware {
                 content.setKimiSafeScore(cache.getKimiSafeScore());
                 content.setRootPublishTimestamp(cache.getRootPublishTimestamp());
                 content.setHisPublishArticleList(hisPublishArticleList);
-                setT0Data(content);
+                setT0Data(content, ghId);
                 continue;
             }
             if (articlesWithHistory.containsKey(content.getSourceId())) {
@@ -390,7 +392,7 @@ public class RecallService implements ApplicationContextAware {
                 for (ContentHisPublishArticle article : content.getHisPublishArticleList()) {
                     article.setCorrelation(Optional.ofNullable(accountCorrelationMap.get(article.getGhId())).orElse(0.0));
                 }
-                setT0Data(content);
+                setT0Data(content, ghId);
                 if (!newCacheSourceIdSet.contains(content.getSourceId())) {
                     newCacheSaveList.add(content);
                     newCacheSourceIdSet.add(content.getSourceId());
@@ -520,6 +522,9 @@ public class RecallService implements ApplicationContextAware {
         List<ProduceTaskAtom> safeScoreList = aigcBaseMapper.getProduceScoreByContentId(sourceIds);
         Map<String, ProduceTaskAtom> safeScoreMap = safeScoreList.stream().filter(o -> StringUtils.hasText(o.getOutput()))
                .collect(Collectors.toMap(ProduceTaskAtom::getPlanExeId, o -> o));
+        List<Account> accountList = accountRepository.getByStatus(1);
+        Map<String, Account> accountMap = accountList.stream()
+              .collect(Collectors.toMap(Account::getGhId, Function.identity()));
 
         for (TitleHisCacheParam cacheParam : paramList) {
             Content res = new Content();
@@ -601,6 +606,10 @@ public class RecallService implements ApplicationContextAware {
                 }
                 ContentHisPublishArticle article = new ContentHisPublishArticle();
                 BeanUtils.copyProperties(hisArticle, article);
+                Account account = accountMap.get(article.getGhId());
+                if (Objects.nonNull(account)) {
+                    article.setAccountType(account.getType());
+                }
                 article.setViewCount(hisArticle.getShowViewCount());
                 article.setWxSn(hisArticle.getWxSn());
                 article.setArticleDetailInfoList(articleDetailInfoMap.get(hisArticle.getWxSn()));
@@ -661,10 +670,11 @@ public class RecallService implements ApplicationContextAware {
         return result;
     }
 
-    private void setT0Data(Content content) {
+    private void setT0Data(Content content, String ghId) {
         if (CollectionUtils.isEmpty(content.getHisPublishArticleList())) {
             return;
         }
+        Account account = accountRepository.getByGhId(ghId);
         int firstLevelSize = 0;
         int fissionSum = 0;
         double fissionWeightSum = 0;
@@ -677,6 +687,9 @@ public class RecallService implements ApplicationContextAware {
             if (article.getItemIndex() != 1 || !article.isInnerAccount()) {
                 continue;
             }
+            if (Objects.nonNull(account) && !account.getType().equals(article.getAccountType())) {
+                continue;
+            }
             if (CollectionUtils.isEmpty(article.getArticleDetailInfoList())) {
                 // 仅判断7.12以后发布文章
                 if (article.getPublishTimestamp() > 1720713600 && contentHisFeishuEnable) {
@@ -714,7 +727,7 @@ public class RecallService implements ApplicationContextAware {
             }
             if (Objects.nonNull(article.getAvgViewCount()) && article.getAvgViewCount() > 0) {
                 article.setT0FissionByReadAvg(sumFission0 * 1.0 / (article.getAvgViewCount() + 500));
-                avgReadCountSum += article.getAvgViewCount();
+                avgReadCountSum += article.getAvgViewCount() + 500;
                 t0FissionByReadAvgSum += article.getT0FissionByReadAvg();
                 t0FissionByReadAvgCorrelationSum += article.getT0FissionByReadAvg() * correlation;
             }

+ 5 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/XxlJobController.java

@@ -107,4 +107,9 @@ public class XxlJobController {
         articlePromotionService.topContentReSend(null);
     }
 
+    @GetMapping("/refreshAccount")
+    public void refreshAccount() {
+        service.refreshAccount(null);
+    }
+
 }

+ 32 - 0
long-article-recommend-service/src/main/resources/mapper/aigc/PublishContentMapper.xml

@@ -258,6 +258,7 @@
             #{item}
         </foreach>
     </update>
+
     <update id="updatePublishContentStatus">
         update publish_content
         set status = #{status}
@@ -265,4 +266,35 @@
         and status = #{oldStatus}
     </update>
 
+    <select id="getPublishAccountIds" resultType="java.lang.String">
+        select distinct ppa.account_id
+        from publish_plan_account ppa
+        join publish_plan pp on ppa.plan_id = pp.id
+        where pp.plan_status = 1 and pp.channel = 5 and ppa.publish_open_flag = 1 and pp.name not like '%自动回复%'
+    </select>
+
+    <select id="getAccountByIds"
+            resultType="com.tzld.longarticle.recommend.server.model.entity.longArticle.Account">
+        select pa.id, pa.name, pa.gh_id, wsgsa.group_source_name as type
+        from publish_account pa
+        left join wx_statistics_group_source_account wsgsa on pa.id = wsgsa.account_id
+        where pa.id in
+        <foreach collection="accountIds" item="item" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
+
+    </select>
+
+    <select id="getAccountMiniprogramTaskList"
+            resultType="com.tzld.longarticle.recommend.server.model.entity.aigc.PublishPlanMiniprogramTask">
+        select ppmt.*
+        from publish_plan_miniprogram_task ppmt
+        join publish_plan_account ppa on ppmt.plan_id = ppa.plan_id
+        join publish_plan pp on ppa.plan_id = pp.id
+        where ppa.account_id = #{accountId}
+          and pp.plan_status = 1
+          and ppa.publish_open_flag = 1
+          and ppmt.account_ids like CONCAT("%", #{accountId}, "%")
+    </select>
+
 </mapper>