Explorar el Código

Merge branch 'master' into feature_20230906_qjl_cgiReply

Joe hace 7 meses
padre
commit
e60428baa8
Se han modificado 23 ficheros con 1676 adiciones y 109 borrados
  1. 1 1
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/ThreadPoolFactory.java
  2. 2 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/NewSortStrategyExport.java
  3. 61 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/remote/WxFetchRemoteService.java
  4. 10 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/crawler/DatastatSortStrategyRepository.java
  5. 100 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/entity/crawler/DatastatSortStrategy.java
  6. 35 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/mapper/crawler/ArticleContentLinkMapper.java
  7. 8 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/mapper/crawler/CrawlerBaseMapper.java
  8. 83 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/model/ArticleContentLink.java
  9. 709 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/model/ArticleContentLinkExample.java
  10. 33 9
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/DataDashboardService.java
  11. 61 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/JobService.java
  12. 81 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/MessageSendCallbackService.java
  13. 8 16
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/UserManagementService.java
  14. 31 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/WXListenService.java
  15. 4 1
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/rank/strategy/RankV8Strategy.java
  16. 51 10
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/strategy/ViewCountRateStrategy.java
  17. 2 2
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/util/JSONUtils.java
  18. 33 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/JobController.java
  19. 6 2
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/UserManagementController.java
  20. 1 1
      long-article-recommend-service/src/main/resources/generatorConfig.xml
  21. 267 0
      long-article-recommend-service/src/main/resources/mapper/crawler/ArticleContentLinkMapper.xml
  22. 22 0
      long-article-recommend-service/src/main/resources/mapper/crawler/CrawlerBaseMapper.xml
  23. 67 67
      long-article-recommend-service/src/test/java/com/tzld/longarticle/recommend/server/RecommendTest.java

+ 1 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/ThreadPoolFactory.java

@@ -26,8 +26,8 @@ public final class ThreadPoolFactory {
             new ThreadFactoryBuilder().setNameFormat("RecallService-%d").build(),
             new ThreadPoolExecutor.AbortPolicy());
     private final static ExecutorService FILTER = new CommonThreadPoolExecutor(
-            32,
             128,
+            256,
             0L, TimeUnit.SECONDS,
             new LinkedBlockingQueue<>(1000),
             new ThreadFactoryBuilder().setNameFormat("FilterService-%d").build(),

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/NewSortStrategyExport.java

@@ -16,6 +16,8 @@ public class NewSortStrategyExport {
     private long fans;
     private Integer viewCount;
     private Double avgViewCount;
+    private Integer firstViewCount;
+    private Double firstAvgViewCount;
     private Integer firstLevel;
     private Integer fission0;
     private Integer fission1;

+ 61 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/remote/WxFetchRemoteService.java

@@ -0,0 +1,61 @@
+package com.tzld.longarticle.recommend.server.remote;
+
+import com.alibaba.fastjson.JSONObject;
+import com.tzld.longarticle.recommend.server.common.HttpPoolFactory;
+import com.tzld.longarticle.recommend.server.model.Content;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpEntity;
+import org.apache.http.StatusLine;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.util.EntityUtils;
+import org.springframework.stereotype.Service;
+
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+
+/**
+ * @author dyp
+ */
+@Service
+@Slf4j
+public class WxFetchRemoteService {
+    private final CloseableHttpClient client = HttpPoolFactory.aigcPool();
+    private static final String url = "http://8.217.190.241:8888/crawler/wei_xin/detail";
+
+
+    public Map<String, String> getContent(String contentUrl) {
+        Map<String, String> result = new HashMap<>();
+        JSONObject bodyParam = new JSONObject();
+        bodyParam.put("content_link", contentUrl);
+        bodyParam.put("is_count", true);
+        bodyParam.put("is_cache", false);
+        try {
+            HttpPost httpPost = new HttpPost(url);
+            StringEntity stringEntity = new StringEntity(bodyParam.toJSONString(), StandardCharsets.UTF_8);
+            httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
+            httpPost.setEntity(stringEntity);
+            CloseableHttpResponse response = client.execute(httpPost);
+            StatusLine statusLine = response.getStatusLine();
+            if (statusLine.getStatusCode() == 200) {
+                HttpEntity responseEntity = response.getEntity();
+                if (Objects.nonNull(responseEntity)) {
+                    String responseBody = EntityUtils.toString(responseEntity, "UTF-8");
+                    JSONObject jsonObject = JSONObject.parseObject(responseBody);
+                    if (jsonObject.getInteger("code") == 0) {
+                        JSONObject data = jsonObject.getJSONObject("data");
+                        data = data.getJSONObject("data");
+                        result.put("view_count", data.getString("view_count"));
+                        result.put("title", data.getString("title"));
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("getViewCount error", e);
+        }
+        return result;
+    }
+
+}

+ 10 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/crawler/DatastatSortStrategyRepository.java

@@ -0,0 +1,10 @@
+package com.tzld.longarticle.recommend.server.repository.crawler;
+
+import com.tzld.longarticle.recommend.server.repository.entity.crawler.DatastatSortStrategy;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface DatastatSortStrategyRepository extends JpaRepository<DatastatSortStrategy, DatastatSortStrategy.PK> {
+
+}

+ 100 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/entity/crawler/DatastatSortStrategy.java

@@ -0,0 +1,100 @@
+package com.tzld.longarticle.recommend.server.repository.entity.crawler;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Entity
+@Table(name = "datastat_sort_strategy")
+@IdClass(DatastatSortStrategy.PK.class)
+public class DatastatSortStrategy  implements Serializable {
+
+    @Id
+    private String dateStr;
+    @Id
+    private String publishTime;
+    @Id
+    private String accountName;
+    @Id
+    private Integer position;
+
+    @Column(name = "account_mode")
+    private String accountMode;
+    @Column(name = "account_source")
+    private String accountSource;
+    @Column(name = "account_type")
+    private String accountType;
+    @Column(name = "account_status")
+    private String accountStatus;
+    @Column(name = "strategy")
+    private String strategy;
+    @Column(name = "fans")
+    private long fans;
+    @Column(name = "view_count")
+    private Integer viewCount;
+    @Column(name = "avg_view_count")
+    private Double avgViewCount;
+    @Column(name = "first_view_count")
+    private Integer firstViewCount;
+    @Column(name = "first_avg_view_count")
+    private Double firstAvgViewCount;
+    @Column(name = "first_level")
+    private Integer firstLevel;
+    @Column(name = "fission0")
+    private Integer fission0;
+    @Column(name = "fission1")
+    private Integer fission1;
+    @Column(name = "fission2")
+    private Integer fission2;
+    @Column(name = "read_rate")
+    private Double readRate;
+    @Column(name = "read_fans_rate")
+    private Double readFansRate;
+    @Column(name = "first_read_rate")
+    private Double firstReadRate;
+    @Column(name = "fission0_first_rate")
+    private Double fission0FirstRate;
+    @Column(name = "fission1_fission0_rate")
+    private Double fission1Fission0Rate;
+    @Column(name = "fission0_read_avg_rate")
+    private Double fission0ReadAvgRate;
+    @Column(name = "gh_id")
+    private String ghId;
+    @Column(name = "title")
+    private String title;
+    @Column(name = "link")
+    private String link;
+    @Column(name = "wx_sn")
+    private String wxSn;
+    @Column(name = "fission0_read_avg_100_rate")
+    private Double fission0ReadAvg100Rate;
+    @Column(name = "fission0_read_avg_500_rate")
+    private Double fission0ReadAvg500Rate;
+    @Column(name = "fission0_read_avg_1000_rate")
+    private Double fission0ReadAvg1000Rate;
+
+
+    @Data
+    public static class PK implements Serializable {
+
+        @Column(name = "date_str")
+        private String dateStr;
+        @Column(name = "publish_time")
+        private String publishTime;
+        @Column(name = "account_name")
+        private String accountName;
+        @Column(name = "position")
+        private Integer position;
+
+        public PK() {
+        }
+
+
+    }
+}

+ 35 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/mapper/crawler/ArticleContentLinkMapper.java

@@ -0,0 +1,35 @@
+package com.tzld.longarticle.recommend.server.repository.mapper.crawler;
+
+import com.tzld.longarticle.recommend.server.repository.model.ArticleContentLink;
+import com.tzld.longarticle.recommend.server.repository.model.ArticleContentLinkExample;
+import java.util.List;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+@Mapper
+public interface ArticleContentLinkMapper {
+    long countByExample(ArticleContentLinkExample example);
+
+    int deleteByExample(ArticleContentLinkExample example);
+
+    int deleteByPrimaryKey(Long id);
+
+    int insert(ArticleContentLink row);
+
+    int insertSelective(ArticleContentLink row);
+
+    List<ArticleContentLink> selectByExample(ArticleContentLinkExample example);
+
+    ArticleContentLink selectByPrimaryKey(Long id);
+
+    int updateByExampleSelective(@Param("row") ArticleContentLink row, @Param("example") ArticleContentLinkExample example);
+
+    int updateByExample(@Param("row") ArticleContentLink row, @Param("example") ArticleContentLinkExample example);
+
+    int updateByPrimaryKeySelective(ArticleContentLink row);
+
+    int updateByPrimaryKey(ArticleContentLink row);
+
+    int insertBatch(List<ArticleContentLink> list);
+}

+ 8 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/mapper/crawler/CrawlerBaseMapper.java

@@ -1,5 +1,13 @@
 package com.tzld.longarticle.recommend.server.repository.mapper.crawler;
 
+import com.tzld.longarticle.recommend.server.repository.entity.crawler.DatastatSortStrategy;
+
+import java.util.List;
+
 public interface CrawlerBaseMapper {
 
+    void deleteByDateStrGreaterThanEqual(String dateStr);
+
+    void batchInsertDatastatSortStrategy(List<DatastatSortStrategy> list);
+
 }

+ 83 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/model/ArticleContentLink.java

@@ -0,0 +1,83 @@
+package com.tzld.longarticle.recommend.server.repository.model;
+
+public class ArticleContentLink {
+    private Long id;
+
+    private String gzhId;
+
+    private Integer idx;
+
+    private String contentLink;
+
+    private Long createTime;
+
+    private String title;
+
+    private Long viewCount;
+
+    private Long updateTime;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getGzhId() {
+        return gzhId;
+    }
+
+    public void setGzhId(String gzhId) {
+        this.gzhId = gzhId == null ? null : gzhId.trim();
+    }
+
+    public Integer getIdx() {
+        return idx;
+    }
+
+    public void setIdx(Integer idx) {
+        this.idx = idx;
+    }
+
+    public String getContentLink() {
+        return contentLink;
+    }
+
+    public void setContentLink(String contentLink) {
+        this.contentLink = contentLink == null ? null : contentLink.trim();
+    }
+
+    public Long getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Long createTime) {
+        this.createTime = createTime;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title == null ? null : title.trim();
+    }
+
+    public Long getViewCount() {
+        return viewCount;
+    }
+
+    public void setViewCount(Long viewCount) {
+        this.viewCount = viewCount;
+    }
+
+    public Long getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Long updateTime) {
+        this.updateTime = updateTime;
+    }
+}

+ 709 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/model/ArticleContentLinkExample.java

@@ -0,0 +1,709 @@
+package com.tzld.longarticle.recommend.server.repository.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ArticleContentLinkExample {
+    protected String orderByClause;
+
+    protected boolean distinct;
+
+    protected List<Criteria> oredCriteria;
+
+    public ArticleContentLinkExample() {
+        oredCriteria = new ArrayList<>();
+    }
+
+    public void setOrderByClause(String orderByClause) {
+        this.orderByClause = orderByClause;
+    }
+
+    public String getOrderByClause() {
+        return orderByClause;
+    }
+
+    public void setDistinct(boolean distinct) {
+        this.distinct = distinct;
+    }
+
+    public boolean isDistinct() {
+        return distinct;
+    }
+
+    public List<Criteria> getOredCriteria() {
+        return oredCriteria;
+    }
+
+    public void or(Criteria criteria) {
+        oredCriteria.add(criteria);
+    }
+
+    public Criteria or() {
+        Criteria criteria = createCriteriaInternal();
+        oredCriteria.add(criteria);
+        return criteria;
+    }
+
+    public Criteria createCriteria() {
+        Criteria criteria = createCriteriaInternal();
+        if (oredCriteria.size() == 0) {
+            oredCriteria.add(criteria);
+        }
+        return criteria;
+    }
+
+    protected Criteria createCriteriaInternal() {
+        Criteria criteria = new Criteria();
+        return criteria;
+    }
+
+    public void clear() {
+        oredCriteria.clear();
+        orderByClause = null;
+        distinct = false;
+    }
+
+    protected abstract static class GeneratedCriteria {
+        protected List<Criterion> criteria;
+
+        protected GeneratedCriteria() {
+            super();
+            criteria = new ArrayList<>();
+        }
+
+        public boolean isValid() {
+            return criteria.size() > 0;
+        }
+
+        public List<Criterion> getAllCriteria() {
+            return criteria;
+        }
+
+        public List<Criterion> getCriteria() {
+            return criteria;
+        }
+
+        protected void addCriterion(String condition) {
+            if (condition == null) {
+                throw new RuntimeException("Value for condition cannot be null");
+            }
+            criteria.add(new Criterion(condition));
+        }
+
+        protected void addCriterion(String condition, Object value, String property) {
+            if (value == null) {
+                throw new RuntimeException("Value for " + property + " cannot be null");
+            }
+            criteria.add(new Criterion(condition, value));
+        }
+
+        protected void addCriterion(String condition, Object value1, Object value2, String property) {
+            if (value1 == null || value2 == null) {
+                throw new RuntimeException("Between values for " + property + " cannot be null");
+            }
+            criteria.add(new Criterion(condition, value1, value2));
+        }
+
+        public Criteria andIdIsNull() {
+            addCriterion("id is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdIsNotNull() {
+            addCriterion("id is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdEqualTo(Long value) {
+            addCriterion("id =", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdNotEqualTo(Long value) {
+            addCriterion("id <>", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdGreaterThan(Long value) {
+            addCriterion("id >", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdGreaterThanOrEqualTo(Long value) {
+            addCriterion("id >=", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdLessThan(Long value) {
+            addCriterion("id <", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdLessThanOrEqualTo(Long value) {
+            addCriterion("id <=", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdIn(List<Long> values) {
+            addCriterion("id in", values, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdNotIn(List<Long> values) {
+            addCriterion("id not in", values, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdBetween(Long value1, Long value2) {
+            addCriterion("id between", value1, value2, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdNotBetween(Long value1, Long value2) {
+            addCriterion("id not between", value1, value2, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdIsNull() {
+            addCriterion("gzh_id is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdIsNotNull() {
+            addCriterion("gzh_id is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdEqualTo(String value) {
+            addCriterion("gzh_id =", value, "gzhId");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdNotEqualTo(String value) {
+            addCriterion("gzh_id <>", value, "gzhId");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdGreaterThan(String value) {
+            addCriterion("gzh_id >", value, "gzhId");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdGreaterThanOrEqualTo(String value) {
+            addCriterion("gzh_id >=", value, "gzhId");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdLessThan(String value) {
+            addCriterion("gzh_id <", value, "gzhId");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdLessThanOrEqualTo(String value) {
+            addCriterion("gzh_id <=", value, "gzhId");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdLike(String value) {
+            addCriterion("gzh_id like", value, "gzhId");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdNotLike(String value) {
+            addCriterion("gzh_id not like", value, "gzhId");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdIn(List<String> values) {
+            addCriterion("gzh_id in", values, "gzhId");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdNotIn(List<String> values) {
+            addCriterion("gzh_id not in", values, "gzhId");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdBetween(String value1, String value2) {
+            addCriterion("gzh_id between", value1, value2, "gzhId");
+            return (Criteria) this;
+        }
+
+        public Criteria andGzhIdNotBetween(String value1, String value2) {
+            addCriterion("gzh_id not between", value1, value2, "gzhId");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdxIsNull() {
+            addCriterion("idx is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdxIsNotNull() {
+            addCriterion("idx is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdxEqualTo(Integer value) {
+            addCriterion("idx =", value, "idx");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdxNotEqualTo(Integer value) {
+            addCriterion("idx <>", value, "idx");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdxGreaterThan(Integer value) {
+            addCriterion("idx >", value, "idx");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdxGreaterThanOrEqualTo(Integer value) {
+            addCriterion("idx >=", value, "idx");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdxLessThan(Integer value) {
+            addCriterion("idx <", value, "idx");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdxLessThanOrEqualTo(Integer value) {
+            addCriterion("idx <=", value, "idx");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdxIn(List<Integer> values) {
+            addCriterion("idx in", values, "idx");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdxNotIn(List<Integer> values) {
+            addCriterion("idx not in", values, "idx");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdxBetween(Integer value1, Integer value2) {
+            addCriterion("idx between", value1, value2, "idx");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdxNotBetween(Integer value1, Integer value2) {
+            addCriterion("idx not between", value1, value2, "idx");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkIsNull() {
+            addCriterion("content_link is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkIsNotNull() {
+            addCriterion("content_link is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkEqualTo(String value) {
+            addCriterion("content_link =", value, "contentLink");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkNotEqualTo(String value) {
+            addCriterion("content_link <>", value, "contentLink");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkGreaterThan(String value) {
+            addCriterion("content_link >", value, "contentLink");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkGreaterThanOrEqualTo(String value) {
+            addCriterion("content_link >=", value, "contentLink");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkLessThan(String value) {
+            addCriterion("content_link <", value, "contentLink");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkLessThanOrEqualTo(String value) {
+            addCriterion("content_link <=", value, "contentLink");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkLike(String value) {
+            addCriterion("content_link like", value, "contentLink");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkNotLike(String value) {
+            addCriterion("content_link not like", value, "contentLink");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkIn(List<String> values) {
+            addCriterion("content_link in", values, "contentLink");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkNotIn(List<String> values) {
+            addCriterion("content_link not in", values, "contentLink");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkBetween(String value1, String value2) {
+            addCriterion("content_link between", value1, value2, "contentLink");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLinkNotBetween(String value1, String value2) {
+            addCriterion("content_link not between", value1, value2, "contentLink");
+            return (Criteria) this;
+        }
+
+        public Criteria andCreateTimeIsNull() {
+            addCriterion("create_time is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andCreateTimeIsNotNull() {
+            addCriterion("create_time is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andCreateTimeEqualTo(Long value) {
+            addCriterion("create_time =", value, "createTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andCreateTimeNotEqualTo(Long value) {
+            addCriterion("create_time <>", value, "createTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andCreateTimeGreaterThan(Long value) {
+            addCriterion("create_time >", value, "createTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andCreateTimeGreaterThanOrEqualTo(Long value) {
+            addCriterion("create_time >=", value, "createTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andCreateTimeLessThan(Long value) {
+            addCriterion("create_time <", value, "createTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andCreateTimeLessThanOrEqualTo(Long value) {
+            addCriterion("create_time <=", value, "createTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andCreateTimeIn(List<Long> values) {
+            addCriterion("create_time in", values, "createTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andCreateTimeNotIn(List<Long> values) {
+            addCriterion("create_time not in", values, "createTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andCreateTimeBetween(Long value1, Long value2) {
+            addCriterion("create_time between", value1, value2, "createTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andCreateTimeNotBetween(Long value1, Long value2) {
+            addCriterion("create_time not between", value1, value2, "createTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleIsNull() {
+            addCriterion("title is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleIsNotNull() {
+            addCriterion("title is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleEqualTo(String value) {
+            addCriterion("title =", value, "title");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleNotEqualTo(String value) {
+            addCriterion("title <>", value, "title");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleGreaterThan(String value) {
+            addCriterion("title >", value, "title");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleGreaterThanOrEqualTo(String value) {
+            addCriterion("title >=", value, "title");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleLessThan(String value) {
+            addCriterion("title <", value, "title");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleLessThanOrEqualTo(String value) {
+            addCriterion("title <=", value, "title");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleLike(String value) {
+            addCriterion("title like", value, "title");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleNotLike(String value) {
+            addCriterion("title not like", value, "title");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleIn(List<String> values) {
+            addCriterion("title in", values, "title");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleNotIn(List<String> values) {
+            addCriterion("title not in", values, "title");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleBetween(String value1, String value2) {
+            addCriterion("title between", value1, value2, "title");
+            return (Criteria) this;
+        }
+
+        public Criteria andTitleNotBetween(String value1, String value2) {
+            addCriterion("title not between", value1, value2, "title");
+            return (Criteria) this;
+        }
+
+        public Criteria andViewCountIsNull() {
+            addCriterion("view_count is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andViewCountIsNotNull() {
+            addCriterion("view_count is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andViewCountEqualTo(Long value) {
+            addCriterion("view_count =", value, "viewCount");
+            return (Criteria) this;
+        }
+
+        public Criteria andViewCountNotEqualTo(Long value) {
+            addCriterion("view_count <>", value, "viewCount");
+            return (Criteria) this;
+        }
+
+        public Criteria andViewCountGreaterThan(Long value) {
+            addCriterion("view_count >", value, "viewCount");
+            return (Criteria) this;
+        }
+
+        public Criteria andViewCountGreaterThanOrEqualTo(Long value) {
+            addCriterion("view_count >=", value, "viewCount");
+            return (Criteria) this;
+        }
+
+        public Criteria andViewCountLessThan(Long value) {
+            addCriterion("view_count <", value, "viewCount");
+            return (Criteria) this;
+        }
+
+        public Criteria andViewCountLessThanOrEqualTo(Long value) {
+            addCriterion("view_count <=", value, "viewCount");
+            return (Criteria) this;
+        }
+
+        public Criteria andViewCountIn(List<Long> values) {
+            addCriterion("view_count in", values, "viewCount");
+            return (Criteria) this;
+        }
+
+        public Criteria andViewCountNotIn(List<Long> values) {
+            addCriterion("view_count not in", values, "viewCount");
+            return (Criteria) this;
+        }
+
+        public Criteria andViewCountBetween(Long value1, Long value2) {
+            addCriterion("view_count between", value1, value2, "viewCount");
+            return (Criteria) this;
+        }
+
+        public Criteria andViewCountNotBetween(Long value1, Long value2) {
+            addCriterion("view_count not between", value1, value2, "viewCount");
+            return (Criteria) this;
+        }
+
+        public Criteria andUpdateTimeIsNull() {
+            addCriterion("update_time is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andUpdateTimeIsNotNull() {
+            addCriterion("update_time is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andUpdateTimeEqualTo(Long value) {
+            addCriterion("update_time =", value, "updateTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andUpdateTimeNotEqualTo(Long value) {
+            addCriterion("update_time <>", value, "updateTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andUpdateTimeGreaterThan(Long value) {
+            addCriterion("update_time >", value, "updateTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andUpdateTimeGreaterThanOrEqualTo(Long value) {
+            addCriterion("update_time >=", value, "updateTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andUpdateTimeLessThan(Long value) {
+            addCriterion("update_time <", value, "updateTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andUpdateTimeLessThanOrEqualTo(Long value) {
+            addCriterion("update_time <=", value, "updateTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andUpdateTimeIn(List<Long> values) {
+            addCriterion("update_time in", values, "updateTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andUpdateTimeNotIn(List<Long> values) {
+            addCriterion("update_time not in", values, "updateTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andUpdateTimeBetween(Long value1, Long value2) {
+            addCriterion("update_time between", value1, value2, "updateTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andUpdateTimeNotBetween(Long value1, Long value2) {
+            addCriterion("update_time not between", value1, value2, "updateTime");
+            return (Criteria) this;
+        }
+    }
+
+    public static class Criteria extends GeneratedCriteria {
+        protected Criteria() {
+            super();
+        }
+    }
+
+    public static class Criterion {
+        private String condition;
+
+        private Object value;
+
+        private Object secondValue;
+
+        private boolean noValue;
+
+        private boolean singleValue;
+
+        private boolean betweenValue;
+
+        private boolean listValue;
+
+        private String typeHandler;
+
+        public String getCondition() {
+            return condition;
+        }
+
+        public Object getValue() {
+            return value;
+        }
+
+        public Object getSecondValue() {
+            return secondValue;
+        }
+
+        public boolean isNoValue() {
+            return noValue;
+        }
+
+        public boolean isSingleValue() {
+            return singleValue;
+        }
+
+        public boolean isBetweenValue() {
+            return betweenValue;
+        }
+
+        public boolean isListValue() {
+            return listValue;
+        }
+
+        public String getTypeHandler() {
+            return typeHandler;
+        }
+
+        protected Criterion(String condition) {
+            super();
+            this.condition = condition;
+            this.typeHandler = null;
+            this.noValue = true;
+        }
+
+        protected Criterion(String condition, Object value, String typeHandler) {
+            super();
+            this.condition = condition;
+            this.value = value;
+            this.typeHandler = typeHandler;
+            if (value instanceof List<?>) {
+                this.listValue = true;
+            } else {
+                this.singleValue = true;
+            }
+        }
+
+        protected Criterion(String condition, Object value) {
+            this(condition, value, null);
+        }
+
+        protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
+            super();
+            this.condition = condition;
+            this.value = value;
+            this.secondValue = secondValue;
+            this.typeHandler = typeHandler;
+            this.betweenValue = true;
+        }
+
+        protected Criterion(String condition, Object value, Object secondValue) {
+            this(condition, value, secondValue, null);
+        }
+    }
+}

+ 33 - 9
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/DataDashboardService.java

@@ -10,15 +10,14 @@ import com.tzld.longarticle.recommend.server.repository.crawler.AccountAvgInfoRe
 import com.tzld.longarticle.recommend.server.repository.crawler.ArticleDetailInfoRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.PublishSortLogRepository;
-import com.tzld.longarticle.recommend.server.repository.entity.crawler.AccountAvgInfo;
-import com.tzld.longarticle.recommend.server.repository.entity.crawler.Article;
-import com.tzld.longarticle.recommend.server.repository.entity.crawler.ArticleDetailInfo;
-import com.tzld.longarticle.recommend.server.repository.entity.crawler.PublishSortLog;
+import com.tzld.longarticle.recommend.server.repository.entity.crawler.*;
+import com.tzld.longarticle.recommend.server.repository.mapper.crawler.CrawlerBaseMapper;
 import com.tzld.longarticle.recommend.server.util.DateUtils;
 import com.tzld.longarticle.recommend.server.util.MapBuilder;
 import com.tzld.longarticle.recommend.server.util.feishu.FeiShu;
 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.data.util.Pair;
 import org.springframework.http.*;
@@ -45,6 +44,8 @@ public class DataDashboardService {
     private AccountAvgInfoRepository accountAvgInfoRepository;
     @Autowired
     private PublishSortLogRepository publishSortLogRepository;
+    @Autowired
+    private CrawlerBaseMapper crawlerBaseMapper;
 
     @ApolloJsonValue("${export.account.ghId:[]}")
     private static List<String> ghIdList;
@@ -113,15 +114,15 @@ public class DataDashboardService {
 
         List<Pair<String, String>> styles = Arrays
                 .asList(
-                        Pair.of("P", "0.00%"),
-                        Pair.of("Q", "0.00%"),
                         Pair.of("R", "0.00%"),
                         Pair.of("S", "0.00%"),
                         Pair.of("T", "0.00%"),
                         Pair.of("U", "0.00%"),
-                        Pair.of("AA", "0.00%"),
-                        Pair.of("AB", "0.00%"),
-                        Pair.of("AC", "0.00%")
+                        Pair.of("V", "0.00%"),
+                        Pair.of("W", "0.00%"),
+                        Pair.of("AC", "0.00%"),
+                        Pair.of("AD", "0.00%"),
+                        Pair.of("AE", "0.00%")
                 );
 
         doSendFeishuSheet(dateStrList, sheetToken, sheetId, rowNum, rows, 2, styles);
@@ -132,6 +133,8 @@ public class DataDashboardService {
         List<AccountAvgInfo> accountAvgInfoList = accountAvgInfoRepository.getAllByStatusEquals(1);
         Set<String> ghIds = accountAvgInfoList.stream().map(AccountAvgInfo::getGhId).collect(Collectors.toSet());
         List<Article> articleList = articleRepository.getByGhIdInAndUpdateTimeGreaterThan(ghIds, timestamp);
+        Map<String, Map<String, Map<Integer, Article>>> articleMap = articleList.stream().collect(Collectors.groupingBy(Article::getGhId,
+                Collectors.groupingBy(Article::getAppMsgId, Collectors.toMap(Article::getItemIndex, o -> o))));
 
         Set<String> snList = articleList.stream().map(Article::getWxSn).collect(Collectors.toSet());
         List<ArticleDetailInfo> articleDetailInfoList = articleDetailInfoRepository.getAllByWxSnIn(new ArrayList<>(snList));
@@ -150,6 +153,7 @@ public class DataDashboardService {
             if (CollectionUtils.isEmpty(articleDetailInfos)) {
                 continue;
             }
+            Article firstArticle = articleMap.get(article.getGhId()).get(article.getAppMsgId()).get(1);
             Map<String, String> dateStrategy = sortStrategyMap.get(article.getGhId());
             Date minDate = articleDetailInfos.stream().map(ArticleDetailInfo::getRecallDt).min(Date::compareTo).orElse(new Date());
             int sumfirstLevel = 0;
@@ -166,8 +170,10 @@ public class DataDashboardService {
             }
             Map<String, AccountAvgInfo> accountAvgInfoMap = accountAvgInfoIndexMap.get(article.getGhId());
             AccountAvgInfo avgInfo = null;
+            AccountAvgInfo firstAvgInfo = null;
             if (Objects.nonNull(accountAvgInfoMap)) {
                 avgInfo = accountAvgInfoMap.get(article.getItemIndex().toString());
+                firstAvgInfo = accountAvgInfoMap.get("1");
             }
             String date = DateUtils.timestampToYMDStr(article.getUpdateTime(), "yyyyMMdd");
             NewSortStrategyExport obj = new NewSortStrategyExport();
@@ -184,6 +190,12 @@ public class DataDashboardService {
             obj.setFission1(sumFission1);
             obj.setFission2(sumFission2);
             obj.setWxSn(article.getWxSn());
+            if (Objects.nonNull(firstArticle)) {
+                obj.setFirstViewCount(firstArticle.getShowViewCount());
+            }
+            if (Objects.nonNull(firstAvgInfo)) {
+                obj.setFirstAvgViewCount(firstAvgInfo.getReadAvg());
+            }
             if (Objects.nonNull(dateStrategy)) {
                 obj.setStrategy(dateStrategy.get(date));
             }
@@ -218,6 +230,18 @@ public class DataDashboardService {
         }
         result.sort(Comparator.comparing(NewSortStrategyExport::getDateStr).reversed()
                 .thenComparing(NewSortStrategyExport::getGhId).thenComparing(NewSortStrategyExport::getPosition));
+        if (CollectionUtils.isNotEmpty(result)) {
+            crawlerBaseMapper.deleteByDateStrGreaterThanEqual(dateStr);
+            List<DatastatSortStrategy> saveList = new ArrayList<>();
+            for (NewSortStrategyExport newSortStrategyExport : result) {
+                DatastatSortStrategy item = new DatastatSortStrategy();
+                BeanUtils.copyProperties(newSortStrategyExport, item);
+                saveList.add(item);
+            }
+            for (List<DatastatSortStrategy> saveListPartition : Lists.partition(saveList, 1000)) {
+                crawlerBaseMapper.batchInsertDatastatSortStrategy(saveListPartition);
+            }
+        }
         return result;
     }
 

+ 61 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/JobService.java

@@ -0,0 +1,61 @@
+package com.tzld.longarticle.recommend.server.service;
+
+import com.tzld.longarticle.recommend.server.common.ThreadPoolFactory;
+import com.tzld.longarticle.recommend.server.remote.WxFetchRemoteService;
+import com.tzld.longarticle.recommend.server.repository.mapper.crawler.ArticleContentLinkMapper;
+import com.tzld.longarticle.recommend.server.repository.model.ArticleContentLink;
+import com.tzld.longarticle.recommend.server.repository.model.ArticleContentLinkExample;
+import com.tzld.longarticle.recommend.server.util.DateUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.math.NumberUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author dyp
+ */
+@Service
+@Slf4j
+public class JobService {
+
+    @Autowired
+    private ArticleContentLinkMapper articleContentLinkMapper;
+    @Autowired
+    private WxFetchRemoteService wxFetchRemoteService;
+
+    private long seconds1d = 60 * 60 * 24 * 1000;
+    private long seconds7d = 7 * seconds1d;
+
+    public void syncViewCount() {
+        ArticleContentLinkExample example = new ArticleContentLinkExample();
+
+
+        LocalDate today = LocalDate.now();
+        // 计算7天前的日期
+        LocalDate dateSevenDaysAgo = today.minusDays(7);
+        // 将日期转换为当天开始的时间(00:00:00)并指定时区
+        ZonedDateTime zonedDateTime = dateSevenDaysAgo.atStartOfDay(ZoneId.systemDefault());
+        // 将ZonedDateTime转换为时间戳(毫秒)
+        long time = zonedDateTime.toInstant().toEpochMilli();
+
+
+        example.createCriteria().andCreateTimeGreaterThanOrEqualTo(time);
+        List<ArticleContentLink> links = articleContentLinkMapper.selectByExample(example);
+        for (ArticleContentLink link : links) {
+            Map<String, String> content = wxFetchRemoteService.getContent(link.getContentLink());
+            link.setTitle(content.getOrDefault("title", ""));
+            link.setViewCount(NumberUtils.toLong(content.getOrDefault("view_count", "0"), 0L));
+            link.setUpdateTime(System.currentTimeMillis());
+
+            articleContentLinkMapper.updateByPrimaryKey(link);
+        }
+
+
+    }
+}

+ 81 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/MessageSendCallbackService.java

@@ -0,0 +1,81 @@
+package com.tzld.longarticle.recommend.server.service;
+
+import com.tzld.longarticle.recommend.server.repository.mapper.crawler.ArticleContentLinkMapper;
+import com.tzld.longarticle.recommend.server.repository.mapper.crawler.ArticleGzhDeveloperMapper;
+import com.tzld.longarticle.recommend.server.repository.model.ArticleContentLink;
+import com.tzld.longarticle.recommend.server.repository.model.ArticleGzhDeveloper;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.math.NumberUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author dyp
+ */
+@Slf4j
+@Service
+public class MessageSendCallbackService {
+
+    @Autowired
+    private ArticleContentLinkMapper articleContentLinkMapper;
+
+    @Autowired
+    private ArticleGzhDeveloperMapper articleGzhDeveloperMapper;
+
+    /**
+     * https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Batch_Sends_and_Originality_Checks.html#_8%E3%80%81%E4%BA%8B%E4%BB%B6%E6%8E%A8%E9%80%81%E7%BE%A4%E5%8F%91%E7%BB%93%E6%9E%9C
+     */
+    public void listenWx(String xmlData) {
+        try {
+            SAXReader saxReader = new SAXReader();
+            Document document = saxReader.read(new StringReader(xmlData));
+            Element root = document.getRootElement();
+
+            String msgType = root.elementText("MsgType");
+            String event = root.elementText("Event");
+            if (!StringUtils.equals("event", msgType)
+                    || !StringUtils.equals("MASSSENDJOBFINISH", event)) {
+                return;
+            }
+
+
+            String gzhId = root.elementText("ToUserName");
+            ArticleGzhDeveloper agd = articleGzhDeveloperMapper.selectByPrimaryKey(gzhId);
+            if (agd == null) {
+                // 不再体系内的账号,不记录链接
+                return;
+            }
+
+
+            long createTime = NumberUtils.toLong(root.elementText("CreateTime"), 0) * 1000;
+
+            Element articleUrlResultEle = root.element("ArticleUrlResult");
+            Element resultListEle = articleUrlResultEle.element("ResultList");
+            List<Element> itemEle = resultListEle.elements("item");
+            List<ArticleContentLink> links = new ArrayList<>();
+            for (Element item : itemEle) {
+                ArticleContentLink link = new ArticleContentLink();
+                link.setGzhId(gzhId);
+                link.setIdx(NumberUtils.toInt(item.elementText("ArticleIdx"), 0));
+                link.setContentLink(item.elementText("ArticleUrl"));
+                link.setCreateTime(createTime);
+                link.setTitle("");
+                link.setUpdateTime(createTime);
+                link.setViewCount(-1L);
+                links.add(link);
+            }
+            articleContentLinkMapper.insertBatch(links);
+        } catch (Exception e) {
+            log.error("listenWx handle error {} ", xmlData, e);
+        }
+    }
+
+}

+ 8 - 16
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/UserManagementService.java

@@ -100,7 +100,6 @@ public class UserManagementService {
         obj.setAppId(appId);
         obj.setGzhId(gzhId);
         articleGzhDeveloperMapper.insert(obj);
-//        log.info("start group gzhId={}", gzhId);
 
 
     }
@@ -153,29 +152,22 @@ public class UserManagementService {
                 param.put(e.getName(), e.getTextTrim());
             }
 
-            String appId = "";
-            String gzhId = "";
-            String openId = "";
+            String gzhId = param.get("ToUserName");
+            String openId = param.get("FromUserName");
+
+            ArticleGzhDeveloper agd = articleGzhDeveloperMapper.selectByPrimaryKey(gzhId);
+            if (agd == null) {
+                // 不再体系内的账号,不记录链接
+                return;
+            }
 
             if (StringUtils.equals("event", param.get("MsgType"))) {
                 String event = param.get("Event");
                 switch (event) {
                     case "subscribe":
-                        appId = param.get("ToUserName");
-                        gzhId = articleGzhDeveloperMapper.selectGzhIdByAppId(appId);
-                        if (StringUtils.isBlank(gzhId)) {
-                            break;
-                        }
-                        openId = param.get("FromUserName");
                         handleSubscribe(gzhId, openId);
                         break;
                     case "unsubscribe":
-                        appId = param.get("ToUserName");
-                        gzhId = articleGzhDeveloperMapper.selectGzhIdByAppId(appId);
-                        if (StringUtils.isBlank(gzhId)) {
-                            break;
-                        }
-                        openId = param.get("FromUserName");
                         handleUnsubscribe(gzhId, openId);
                         break;
                     default:

+ 31 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/WXListenService.java

@@ -0,0 +1,31 @@
+package com.tzld.longarticle.recommend.server.service;
+
+import com.tzld.longarticle.recommend.server.common.ThreadPoolFactory;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author dyp
+ */
+@Service
+@Slf4j
+public class WXListenService {
+    @Autowired
+    private UserManagementService userManagementService;
+
+    @Autowired
+    private MessageSendCallbackService messageSendCallbackService;
+
+    public void listenWx(String xmlData) {
+
+        ThreadPoolFactory.defaultPool().submit(() -> {
+            userManagementService.listenWx(xmlData);
+        });
+
+        ThreadPoolFactory.defaultPool().submit(() -> {
+            messageSendCallbackService.listenWx(xmlData);
+        });
+
+    }
+}

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

@@ -51,7 +51,10 @@ public class RankV8Strategy implements RankStrategy {
             item.setScoreMap(scoreMap.get(c.getId()));
             double score;
             if (contentPools[0].equals(item.getContent().getContentPoolType())) {
-                score = item.getScore(HisFissionFansSumRateStrategy.class.getSimpleName());
+                score = item.getScore(SimilarityStrategy.class.getSimpleName())
+                        + item.getScore(CategoryStrategy.class.getSimpleName())
+                        + item.getScore(FlowCtlDecreaseStrategy.class.getSimpleName());
+                score += item.getScore(HisFissionAvgReadRateRateStrategy.class.getSimpleName());
             } else if (contentPools[1].equals(item.getContent().getContentPoolType())) {
                 score = item.getScore(SimilarityStrategy.class.getSimpleName())
                         + item.getScore(CategoryStrategy.class.getSimpleName())

+ 51 - 10
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/strategy/ViewCountRateStrategy.java

@@ -36,31 +36,69 @@ public class ViewCountRateStrategy implements ScoreStrategy {
         String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
         List<AccountAvgInfo> avgInfoList = accountAvgInfoRepository.getAllByGhIdEqualsAndStatusEquals(param.getGhId(), 1);
         double avgViewCountFirst = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 1);
+        double avgViewCountSecond = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 2);
+        double avgViewCountThird = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), 3);
+        // 缺省头条均值设置为2w,次条为1w
+        if (avgViewCountFirst < 10) {
+            avgViewCountFirst = 20000D;
+            avgViewCountSecond = 10000D;
+            avgViewCountThird = 400D;
+        }
         for (Content content : param.getContents()) {
             for (int i = 0; i < contentPools.length; i++) {
                 if (!contentPools[i].equals(content.getContentPoolType())) {
                     continue;
                 }
                 double avgViewCountPos = accountIndexAvgViewCountService.getAvgReadCountByDB(avgInfoList, param.getGhId(), i + 1);
+                // 缺省头条均值设置为2w,次条为1w
+                if (avgViewCountPos < 10) {
+                    if (i == 0) {
+                        avgViewCountPos = 20000D;
+                    } else if (i == 1) {
+                        avgViewCountPos = 10000D;
+                    } else {
+                        avgViewCountPos = 400D;
+                    }
+                }
                 double showViewCountSum = 0D;
                 double avgViewCountSum = 0D;
                 double showViewCountSumFirst = 0D;
                 double avgViewCountSumFirst = 0D;
                 double showViewCountSumSecond = 0D;
                 double avgViewCountSumSecond = 0D;
+                double maxAvgViewCount = 0D;
                 for (ContentHisPublishArticle hisItem : content.getHisPublishArticleList()) {
                     if (hisItem.isInnerAccount() && Objects.nonNull(hisItem.getViewCount())
                             && hisItem.getViewCount() > 0 && Objects.nonNull(hisItem.getAvgViewCount())
                             && hisItem.getAvgViewCount() > 0) {
+                        maxAvgViewCount = Math.max(maxAvgViewCount, hisItem.getAvgViewCount());
                         if (hisItem.getItemIndex() == 1) {
                             showViewCountSumFirst += hisItem.getViewCount();
                             avgViewCountSumFirst += hisItem.getAvgViewCount();
                         } else if (hisItem.getItemIndex() == 2) {
-                            showViewCountSumSecond += hisItem.getViewCount();
-                            avgViewCountSumSecond += hisItem.getAvgViewCount();
+                            if (Objects.nonNull(hisItem.getFirstViewCount()) &&  hisItem.getFirstViewCount() > 0 &&
+                                    Objects.nonNull(hisItem.getFirstViewCountRate()) && hisItem.getFirstViewCountRate() > 0) {
+                                showViewCountSumSecond += hisItem.getViewCount();
+                                if (hisItem.getFirstViewCountRate() > 1) {
+                                    // 对于头条均值倍数大于1的情况,次条均值线性增加,用于debias;
+                                    // TODO: 对于小于1的情况,是否要减去?
+                                    avgViewCountSumSecond += hisItem.getAvgViewCount() * hisItem.getFirstViewCountRate();
+                                } else {
+                                    avgViewCountSumSecond += hisItem.getAvgViewCount();
+                                }
+                            }
                         } else {
-                            showViewCountSum += hisItem.getViewCount();
-                            avgViewCountSum += hisItem.getAvgViewCount();
+                            if (Objects.nonNull(hisItem.getFirstViewCount()) && hisItem.getFirstViewCount() > 0
+                                    && Objects.nonNull(hisItem.getFirstViewCountRate()) && hisItem.getFirstViewCountRate() > 0) {
+                                showViewCountSum += hisItem.getViewCount();
+                                if (hisItem.getFirstViewCountRate() > 1) {
+                                    // 对于头条均值倍数大于1的情况,次条均值线性增加,用于debias;
+                                    // TODO: 对于小于1的情况,是否要减去?
+                                    avgViewCountSum += hisItem.getAvgViewCount() * hisItem.getFirstViewCountRate();
+                                } else {
+                                    avgViewCountSum += hisItem.getAvgViewCount();
+                                }
+                            }
                         }
                     }
                 }
@@ -70,23 +108,26 @@ public class ViewCountRateStrategy implements ScoreStrategy {
                 if (showViewCountSumFirst > 0) {
                     showViewCountSum = showViewCountSumFirst;
                     avgViewCountSum = avgViewCountSumFirst;
-                    avgViewCountPos = avgViewCountFirst;
                 } else if (showViewCountSumSecond > 0) {
                     showViewCountSum = showViewCountSumSecond;
                     avgViewCountSum = avgViewCountSumSecond;
-                    avgViewCountPos = avgViewCountFirst;
                     // 如果是大号头条,则降权
-                    if (avgViewCountFirst >= 2000 && i == 0) {
-                        minRate = 1.001D;
-                    }
+//                    if (avgViewCountFirst >= 2000 && i == 0) {
+//                        minRate = 1.001D;
+//                    }
                 }
+                // 均值倍数
                 if (avgViewCountSum > 0) {
                     viewCountRate = showViewCountSum / avgViewCountSum;
                 }
+                // 置信度
                 double viewCountRateW = MathUtils.sigmoid(avgViewCountSum, 0.0005, avgViewCountPos);
                 double viewCountRateScore = 0;
+
                 if (viewCountRate > 0) {
-                    viewCountRateScore = (Math.min(viewCountRate, minRate) - 1D) * viewCountRateW;
+                    // 最终分数 = 置信度 * 均值倍数
+                    viewCountRateScore = viewCountRateW * viewCountRate;
+//                    viewCountRateScore = (Math.min(viewCountRate, minRate) - 1D) * viewCountRateW;
                 }
                 Score score = new Score();
                 score.setStrategy(this);

+ 2 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/util/JSONUtils.java

@@ -2,7 +2,7 @@ package com.tzld.longarticle.recommend.server.util;
 
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.reflect.TypeToken;
-import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 
@@ -27,7 +27,7 @@ public class JSONUtils {
             return "";
         }
         try {
-            return new Gson().toJson(obj);
+            return new GsonBuilder().disableHtmlEscaping().create().toJson(obj);
         } catch (Exception e) {
             log.error("toJson exception", e);
             return "";

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

@@ -0,0 +1,33 @@
+package com.tzld.longarticle.recommend.server.web;
+
+import com.tzld.longarticle.recommend.server.model.Result;
+import com.tzld.longarticle.recommend.server.service.JobService;
+import com.tzld.longarticle.recommend.server.service.UserManagementService;
+import com.tzld.longarticle.recommend.server.service.WXListenService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @author dyp
+ */
+@RestController
+@Slf4j
+@RequestMapping("/job")
+public class JobController {
+    @Autowired
+    private JobService jobService;
+
+
+    @RequestMapping("/syncViewCount")
+    public String syncViewCount() {
+        jobService.syncViewCount();
+        return "success";
+    }
+
+}

+ 6 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/UserManagementController.java

@@ -2,6 +2,7 @@ package com.tzld.longarticle.recommend.server.web;
 
 import com.tzld.longarticle.recommend.server.model.Result;
 import com.tzld.longarticle.recommend.server.service.UserManagementService;
+import com.tzld.longarticle.recommend.server.service.WXListenService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -21,12 +22,15 @@ public class UserManagementController {
     @Autowired
     private UserManagementService userManagementService;
 
+    @Autowired
+    private WXListenService wxListenService;
+
 
     @RequestMapping("/addGZH")
     public String addGZH(@RequestParam(name = "gzhId") String gzhId,
                          @RequestParam(name = "appId") String appId,
                          @RequestParam(name = "groupNum") int groupNum) {
-        userManagementService.addGZH(gzhId,appId, groupNum);
+        userManagementService.addGZH(gzhId, appId, groupNum);
         return "success";
     }
 
@@ -43,7 +47,7 @@ public class UserManagementController {
      */
     @RequestMapping("/listenWx")
     public String listenWx(@RequestBody String xmlData) {
-        userManagementService.listenWx(xmlData);
+        wxListenService.listenWx(xmlData);
         return "success";
     }
 

+ 1 - 1
long-article-recommend-service/src/main/resources/generatorConfig.xml

@@ -33,7 +33,7 @@
             <property name="enableSubPackages" value="true" />
         </javaClientGenerator>
 
-        <table schema="mybatis" tableName="article_gzh_developer" >
+        <table schema="mybatis" tableName="article_content_link" >
             <generatedKey column="id" sqlStatement="mysql" identity="true" />
         </table>
 

+ 267 - 0
long-article-recommend-service/src/main/resources/mapper/crawler/ArticleContentLinkMapper.xml

@@ -0,0 +1,267 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.tzld.longarticle.recommend.server.repository.mapper.crawler.ArticleContentLinkMapper">
+  <resultMap id="BaseResultMap" type="com.tzld.longarticle.recommend.server.repository.model.ArticleContentLink">
+    <id column="id" jdbcType="BIGINT" property="id" />
+    <result column="gzh_id" jdbcType="VARCHAR" property="gzhId" />
+    <result column="idx" jdbcType="INTEGER" property="idx" />
+    <result column="content_link" jdbcType="VARCHAR" property="contentLink" />
+    <result column="create_time" jdbcType="BIGINT" property="createTime" />
+    <result column="title" jdbcType="VARCHAR" property="title" />
+    <result column="view_count" jdbcType="BIGINT" property="viewCount" />
+    <result column="update_time" jdbcType="BIGINT" property="updateTime" />
+  </resultMap>
+  <sql id="Example_Where_Clause">
+    <where>
+      <foreach collection="oredCriteria" item="criteria" separator="or">
+        <if test="criteria.valid">
+          <trim prefix="(" prefixOverrides="and" suffix=")">
+            <foreach collection="criteria.criteria" item="criterion">
+              <choose>
+                <when test="criterion.noValue">
+                  and ${criterion.condition}
+                </when>
+                <when test="criterion.singleValue">
+                  and ${criterion.condition} #{criterion.value}
+                </when>
+                <when test="criterion.betweenValue">
+                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
+                </when>
+                <when test="criterion.listValue">
+                  and ${criterion.condition}
+                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
+                    #{listItem}
+                  </foreach>
+                </when>
+              </choose>
+            </foreach>
+          </trim>
+        </if>
+      </foreach>
+    </where>
+  </sql>
+  <sql id="Update_By_Example_Where_Clause">
+    <where>
+      <foreach collection="example.oredCriteria" item="criteria" separator="or">
+        <if test="criteria.valid">
+          <trim prefix="(" prefixOverrides="and" suffix=")">
+            <foreach collection="criteria.criteria" item="criterion">
+              <choose>
+                <when test="criterion.noValue">
+                  and ${criterion.condition}
+                </when>
+                <when test="criterion.singleValue">
+                  and ${criterion.condition} #{criterion.value}
+                </when>
+                <when test="criterion.betweenValue">
+                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
+                </when>
+                <when test="criterion.listValue">
+                  and ${criterion.condition}
+                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
+                    #{listItem}
+                  </foreach>
+                </when>
+              </choose>
+            </foreach>
+          </trim>
+        </if>
+      </foreach>
+    </where>
+  </sql>
+  <sql id="Base_Column_List">
+    id, gzh_id, idx, content_link, create_time, title, view_count, update_time
+  </sql>
+  <select id="selectByExample" parameterType="com.tzld.longarticle.recommend.server.repository.model.ArticleContentLinkExample" resultMap="BaseResultMap">
+    select
+    <if test="distinct">
+      distinct
+    </if>
+    <include refid="Base_Column_List" />
+    from article_content_link
+    <if test="_parameter != null">
+      <include refid="Example_Where_Clause" />
+    </if>
+    <if test="orderByClause != null">
+      order by ${orderByClause}
+    </if>
+  </select>
+  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
+    select 
+    <include refid="Base_Column_List" />
+    from article_content_link
+    where id = #{id,jdbcType=BIGINT}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
+    delete from article_content_link
+    where id = #{id,jdbcType=BIGINT}
+  </delete>
+  <delete id="deleteByExample" parameterType="com.tzld.longarticle.recommend.server.repository.model.ArticleContentLinkExample">
+    delete from article_content_link
+    <if test="_parameter != null">
+      <include refid="Example_Where_Clause" />
+    </if>
+  </delete>
+  <insert id="insert" parameterType="com.tzld.longarticle.recommend.server.repository.model.ArticleContentLink">
+    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
+      SELECT LAST_INSERT_ID()
+    </selectKey>
+    insert into article_content_link (gzh_id, idx, content_link, 
+      create_time, title, view_count, 
+      update_time)
+    values (#{gzhId,jdbcType=VARCHAR}, #{idx,jdbcType=INTEGER}, #{contentLink,jdbcType=VARCHAR}, 
+      #{createTime,jdbcType=BIGINT}, #{title,jdbcType=VARCHAR}, #{viewCount,jdbcType=BIGINT}, 
+      #{updateTime,jdbcType=BIGINT})
+  </insert>
+  <insert id="insertSelective" parameterType="com.tzld.longarticle.recommend.server.repository.model.ArticleContentLink">
+    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
+      SELECT LAST_INSERT_ID()
+    </selectKey>
+    insert into article_content_link
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="gzhId != null">
+        gzh_id,
+      </if>
+      <if test="idx != null">
+        idx,
+      </if>
+      <if test="contentLink != null">
+        content_link,
+      </if>
+      <if test="createTime != null">
+        create_time,
+      </if>
+      <if test="title != null">
+        title,
+      </if>
+      <if test="viewCount != null">
+        view_count,
+      </if>
+      <if test="updateTime != null">
+        update_time,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="gzhId != null">
+        #{gzhId,jdbcType=VARCHAR},
+      </if>
+      <if test="idx != null">
+        #{idx,jdbcType=INTEGER},
+      </if>
+      <if test="contentLink != null">
+        #{contentLink,jdbcType=VARCHAR},
+      </if>
+      <if test="createTime != null">
+        #{createTime,jdbcType=BIGINT},
+      </if>
+      <if test="title != null">
+        #{title,jdbcType=VARCHAR},
+      </if>
+      <if test="viewCount != null">
+        #{viewCount,jdbcType=BIGINT},
+      </if>
+      <if test="updateTime != null">
+        #{updateTime,jdbcType=BIGINT},
+      </if>
+    </trim>
+  </insert>
+  <select id="countByExample" parameterType="com.tzld.longarticle.recommend.server.repository.model.ArticleContentLinkExample" resultType="java.lang.Long">
+    select count(*) from article_content_link
+    <if test="_parameter != null">
+      <include refid="Example_Where_Clause" />
+    </if>
+  </select>
+  <update id="updateByExampleSelective" parameterType="map">
+    update article_content_link
+    <set>
+      <if test="row.id != null">
+        id = #{row.id,jdbcType=BIGINT},
+      </if>
+      <if test="row.gzhId != null">
+        gzh_id = #{row.gzhId,jdbcType=VARCHAR},
+      </if>
+      <if test="row.idx != null">
+        idx = #{row.idx,jdbcType=INTEGER},
+      </if>
+      <if test="row.contentLink != null">
+        content_link = #{row.contentLink,jdbcType=VARCHAR},
+      </if>
+      <if test="row.createTime != null">
+        create_time = #{row.createTime,jdbcType=BIGINT},
+      </if>
+      <if test="row.title != null">
+        title = #{row.title,jdbcType=VARCHAR},
+      </if>
+      <if test="row.viewCount != null">
+        view_count = #{row.viewCount,jdbcType=BIGINT},
+      </if>
+      <if test="row.updateTime != null">
+        update_time = #{row.updateTime,jdbcType=BIGINT},
+      </if>
+    </set>
+    <if test="example != null">
+      <include refid="Update_By_Example_Where_Clause" />
+    </if>
+  </update>
+  <update id="updateByExample" parameterType="map">
+    update article_content_link
+    set id = #{row.id,jdbcType=BIGINT},
+      gzh_id = #{row.gzhId,jdbcType=VARCHAR},
+      idx = #{row.idx,jdbcType=INTEGER},
+      content_link = #{row.contentLink,jdbcType=VARCHAR},
+      create_time = #{row.createTime,jdbcType=BIGINT},
+      title = #{row.title,jdbcType=VARCHAR},
+      view_count = #{row.viewCount,jdbcType=BIGINT},
+      update_time = #{row.updateTime,jdbcType=BIGINT}
+    <if test="example != null">
+      <include refid="Update_By_Example_Where_Clause" />
+    </if>
+  </update>
+  <update id="updateByPrimaryKeySelective" parameterType="com.tzld.longarticle.recommend.server.repository.model.ArticleContentLink">
+    update article_content_link
+    <set>
+      <if test="gzhId != null">
+        gzh_id = #{gzhId,jdbcType=VARCHAR},
+      </if>
+      <if test="idx != null">
+        idx = #{idx,jdbcType=INTEGER},
+      </if>
+      <if test="contentLink != null">
+        content_link = #{contentLink,jdbcType=VARCHAR},
+      </if>
+      <if test="createTime != null">
+        create_time = #{createTime,jdbcType=BIGINT},
+      </if>
+      <if test="title != null">
+        title = #{title,jdbcType=VARCHAR},
+      </if>
+      <if test="viewCount != null">
+        view_count = #{viewCount,jdbcType=BIGINT},
+      </if>
+      <if test="updateTime != null">
+        update_time = #{updateTime,jdbcType=BIGINT},
+      </if>
+    </set>
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.tzld.longarticle.recommend.server.repository.model.ArticleContentLink">
+    update article_content_link
+    set gzh_id = #{gzhId,jdbcType=VARCHAR},
+      idx = #{idx,jdbcType=INTEGER},
+      content_link = #{contentLink,jdbcType=VARCHAR},
+      create_time = #{createTime,jdbcType=BIGINT},
+      title = #{title,jdbcType=VARCHAR},
+      view_count = #{viewCount,jdbcType=BIGINT},
+      update_time = #{updateTime,jdbcType=BIGINT}
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+
+  <insert id="insertBatch" parameterType="list">
+    INSERT INTO article_content_link (gzh_id, idx, content_link, create_time, title, view_count, update_time)
+    VALUES
+    <foreach collection="list" item="item" separator=",">
+      (#{item.gzhId}, #{item.idx}, #{item.contentLink}, #{item.createTime}, #{item.title}, #{item.viewCount},
+      #{item.updateTime})
+    </foreach>
+  </insert>
+</mapper>

+ 22 - 0
long-article-recommend-service/src/main/resources/mapper/crawler/CrawlerBaseMapper.xml

@@ -2,5 +2,27 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.tzld.longarticle.recommend.server.repository.mapper.crawler.CrawlerBaseMapper">
 
+    <delete id="deleteByDateStrGreaterThanEqual">
+        delete from datastat_sort_strategy where date_str >= #{dateStr}
+    </delete>
 
+    <insert id="batchInsertDatastatSortStrategy">
+        INSERT INTO datastat_sort_strategy
+        (date_str, publish_time, account_mode, account_source, account_type, account_status, account_name, strategy,
+         fans, view_count, avg_view_count, first_view_count, first_avg_view_count, first_level, fission0, fission1,
+         fission2, read_rate, read_fans_rate, first_read_rate, fission0_first_rate, fission1_fission0_rate,
+         fission0_read_avg_rate, position, gh_id, title, link, wx_sn, fission0_read_avg_100_rate,
+         fission0_read_avg_500_rate, fission0_read_avg_1000_rate)
+        VALUES
+        <foreach collection="list" item="item" separator=",">
+            (#{item.dateStr}, #{item.publishTime}, #{item.accountMode}, #{item.accountSource}, #{item.accountType},
+             #{item.accountStatus}, #{item.accountName}, #{item.strategy}, #{item.fans}, #{item.viewCount},
+             #{item.avgViewCount}, #{item.firstViewCount}, #{item.firstAvgViewCount}, #{item.firstLevel},
+             #{item.fission0}, #{item.fission1}, #{item.fission2}, #{item.readRate}, #{item.readFansRate},
+             #{item.firstReadRate}, #{item.fission0FirstRate}, #{item.fission1Fission0Rate},
+             #{item.fission0ReadAvgRate}, #{item.position}, #{item.ghId}, #{item.title}, #{item.link},
+             #{item.wxSn}, #{item.fission0ReadAvg100Rate}, #{item.fission0ReadAvg500Rate},
+             #{item.fission0ReadAvg1000Rate})
+        </foreach>
+    </insert>
 </mapper>

+ 67 - 67
long-article-recommend-service/src/test/java/com/tzld/longarticle/recommend/server/RecommendTest.java

@@ -35,72 +35,72 @@ public class RecommendTest {
     @Resource
     private AccountAvgInfoRepository accountAvgInfoRepository;
 
-    @Test
-    void recall() {
-        RecallParam param = new RecallParam();
-        param.setAccountId("20231213123536190184852");
-        param.setPlanId("20240718181730864154902");
-        RecallResult recallResult = recallService.recall(param);
-        System.out.println(JSONObject.toJSONString(recallResult));
-    }
-
-    @Test
-    void exportData() {
-        Set<String> ghIds = new HashSet<>(Arrays.asList("gh_adca24a8f429", "gh_e0eb490115f5", "gh_51e4ad40466d", "gh_95ed5ecf9363"));
-        List<Article> articleList = articleRepository.getByGhIdInAndUpdateTimeGreaterThan(ghIds, 1722441600L);
-
-        Map<String, Map<Integer, List<Article>>> map = articleList.stream()
-                .collect(Collectors.groupingBy(Article::getTitle, Collectors.groupingBy(Article::getItemIndex)));
-        Set<String> snList = articleList.stream().map(Article::getWxSn).collect(Collectors.toSet());
-        List<ArticleDetailInfo> articleDetailInfoList = articleDetailInfoRepository.getAllByWxSnIn(snList);
-        Map<String, List<ArticleDetailInfo>> articleDetailInfoMap = articleDetailInfoList.stream()
-                .collect(Collectors.groupingBy(ArticleDetailInfo::getWxSn));
-
-        List<AccountAvgInfo> accountAvgInfoList = accountAvgInfoRepository.getAllByGhIdInAndStatusEquals(ghIds, 1);
-        Map<String, Map<String, AccountAvgInfo>> accountAvgInfoIndexMap = accountAvgInfoList.stream().collect(
-                Collectors.groupingBy(AccountAvgInfo::getGhId, Collectors.toMap(AccountAvgInfo::getPosition, o -> o)));
-        JSONArray jsonArray = new JSONArray();
-        for (Article article : articleList) {
-            List<ArticleDetailInfo> articleDetailInfos = articleDetailInfoMap.get(article.getWxSn());
-            if (CollectionUtils.isEmpty(articleDetailInfos)) {
-                continue;
-            }
-            Date minDate = articleDetailInfos.stream().map(ArticleDetailInfo::getRecallDt).min(Date::compareTo).orElse(new Date());
-            int sumfirstLevel = 0;
-            int sumFission0 = 0;
-            int sumFission1 = 0;
-            int sumFission2 = 0;
-            for (ArticleDetailInfo articleDetailInfo : articleDetailInfos) {
-                if (articleDetailInfo.getRecallDt().equals(minDate)) {
-                    sumfirstLevel += Optional.ofNullable(articleDetailInfo.getFirstLevel()).orElse(0);
-                    sumFission0 += Optional.ofNullable(articleDetailInfo.getFission0()).orElse(0);
-                    sumFission1 += Optional.ofNullable(articleDetailInfo.getFission1()).orElse(0);
-                    sumFission2 += Optional.ofNullable(articleDetailInfo.getFission2()).orElse(0);
-                }
-            }
-            Map<String, AccountAvgInfo> accountAvgInfoMap = accountAvgInfoIndexMap.get(article.getGhId());
-            AccountAvgInfo avgInfo = accountAvgInfoMap.get(article.getItemIndex().toString());
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
-            String date = sdf.format(new Date(article.getUpdateTime() * 1000));
-            JSONObject obj = new JSONObject();
-            obj.put("ghId", article.getGhId());
-            obj.put("accountName", article.getAccountName());
-            obj.put("title", article.getTitle());
-            obj.put("index", article.getItemIndex());
-            obj.put("viewCount", article.getShowViewCount());
-            obj.put("time", date);
-            if (Objects.nonNull(avgInfo)) {
-                obj.put("fans", avgInfo.getFans());
-                obj.put("avgViewCount", avgInfo.getReadAvg());
-                obj.put("viewCountRate", (article.getShowViewCount() * 1.0) / avgInfo.getReadAvg());
-            }
-            obj.put("firstLevel", sumfirstLevel);
-            obj.put("fission0", sumFission0);
-            obj.put("fission1", sumFission1);
-            obj.put("fission2", sumFission2);
-            jsonArray.add(obj);
-        }
-        System.out.println(jsonArray.toJSONString());
-    }
+//    @Test
+//    void recall() {
+//        RecallParam param = new RecallParam();
+//        param.setAccountId("20231213123536190184852");
+//        param.setPlanId("20240718181730864154902");
+//        RecallResult recallResult = recallService.recall(param);
+//        System.out.println(JSONObject.toJSONString(recallResult));
+//    }
+//
+//    @Test
+//    void exportData() {
+//        Set<String> ghIds = new HashSet<>(Arrays.asList("gh_adca24a8f429", "gh_e0eb490115f5", "gh_51e4ad40466d", "gh_95ed5ecf9363"));
+//        List<Article> articleList = articleRepository.getByGhIdInAndUpdateTimeGreaterThan(ghIds, 1722441600L);
+//
+//        Map<String, Map<Integer, List<Article>>> map = articleList.stream()
+//                .collect(Collectors.groupingBy(Article::getTitle, Collectors.groupingBy(Article::getItemIndex)));
+//        Set<String> snList = articleList.stream().map(Article::getWxSn).collect(Collectors.toSet());
+//        List<ArticleDetailInfo> articleDetailInfoList = articleDetailInfoRepository.getAllByWxSnIn(snList);
+//        Map<String, List<ArticleDetailInfo>> articleDetailInfoMap = articleDetailInfoList.stream()
+//                .collect(Collectors.groupingBy(ArticleDetailInfo::getWxSn));
+//
+//        List<AccountAvgInfo> accountAvgInfoList = accountAvgInfoRepository.getAllByGhIdInAndStatusEquals(ghIds, 1);
+//        Map<String, Map<String, AccountAvgInfo>> accountAvgInfoIndexMap = accountAvgInfoList.stream().collect(
+//                Collectors.groupingBy(AccountAvgInfo::getGhId, Collectors.toMap(AccountAvgInfo::getPosition, o -> o)));
+//        JSONArray jsonArray = new JSONArray();
+//        for (Article article : articleList) {
+//            List<ArticleDetailInfo> articleDetailInfos = articleDetailInfoMap.get(article.getWxSn());
+//            if (CollectionUtils.isEmpty(articleDetailInfos)) {
+//                continue;
+//            }
+//            Date minDate = articleDetailInfos.stream().map(ArticleDetailInfo::getRecallDt).min(Date::compareTo).orElse(new Date());
+//            int sumfirstLevel = 0;
+//            int sumFission0 = 0;
+//            int sumFission1 = 0;
+//            int sumFission2 = 0;
+//            for (ArticleDetailInfo articleDetailInfo : articleDetailInfos) {
+//                if (articleDetailInfo.getRecallDt().equals(minDate)) {
+//                    sumfirstLevel += Optional.ofNullable(articleDetailInfo.getFirstLevel()).orElse(0);
+//                    sumFission0 += Optional.ofNullable(articleDetailInfo.getFission0()).orElse(0);
+//                    sumFission1 += Optional.ofNullable(articleDetailInfo.getFission1()).orElse(0);
+//                    sumFission2 += Optional.ofNullable(articleDetailInfo.getFission2()).orElse(0);
+//                }
+//            }
+//            Map<String, AccountAvgInfo> accountAvgInfoMap = accountAvgInfoIndexMap.get(article.getGhId());
+//            AccountAvgInfo avgInfo = accountAvgInfoMap.get(article.getItemIndex().toString());
+//            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+//            String date = sdf.format(new Date(article.getUpdateTime() * 1000));
+//            JSONObject obj = new JSONObject();
+//            obj.put("ghId", article.getGhId());
+//            obj.put("accountName", article.getAccountName());
+//            obj.put("title", article.getTitle());
+//            obj.put("index", article.getItemIndex());
+//            obj.put("viewCount", article.getShowViewCount());
+//            obj.put("time", date);
+//            if (Objects.nonNull(avgInfo)) {
+//                obj.put("fans", avgInfo.getFans());
+//                obj.put("avgViewCount", avgInfo.getReadAvg());
+//                obj.put("viewCountRate", (article.getShowViewCount() * 1.0) / avgInfo.getReadAvg());
+//            }
+//            obj.put("firstLevel", sumfirstLevel);
+//            obj.put("fission0", sumFission0);
+//            obj.put("fission1", sumFission1);
+//            obj.put("fission2", sumFission2);
+//            jsonArray.add(obj);
+//        }
+//        System.out.println(jsonArray.toJSONString());
+//    }
 
 }