Prechádzať zdrojové kódy

Merge branch 'feature_fuwuhao' of Server/long-article-recommend into master

dingyunpeng 10 mesiacov pred
rodič
commit
5c7a9a86f6

+ 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(),

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

@@ -0,0 +1,36 @@
+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);
+}

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

@@ -0,0 +1,53 @@
+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;
+
+    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;
+    }
+}

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

@@ -0,0 +1,519 @@
+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 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);
+        }
+    }
+}

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

@@ -0,0 +1,78 @@
+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);
+
+            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);
+                links.add(link);
+            }
+            articleContentLinkMapper.insertBatch(links);
+        } catch (Exception e) {
+            log.error("listenWx handle error {} ", xmlData, e);
+        }
+    }
+
+}

+ 2 - 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,16 @@ 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");
 
             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);
+        });
+
+    }
+}

+ 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>
 

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

@@ -0,0 +1,219 @@
+<?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" />
+  </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
+  </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)
+    values (#{gzhId,jdbcType=VARCHAR}, #{idx,jdbcType=INTEGER}, #{contentLink,jdbcType=VARCHAR}, 
+      #{createTime,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>
+    </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>
+    </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>
+    </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}
+    <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>
+    </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}
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+
+  <insert id="insertBatch" parameterType="list">
+    INSERT INTO article_content_link (gzh_id, idx, content_link, create_time)
+    VALUES
+    <foreach collection="list" item="item" separator=",">
+      (#{item.gzhId}, #{item.idx}, #{item.contentLink}, #{item.createTime})
+    </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());
+//    }
 
 }