丁云鹏 10 mesi fa
parent
commit
ee2125aa4b

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

@@ -1,26 +0,0 @@
-package com.tzld.longarticle.recommend.server.repository.crawler;
-
-import com.tzld.longarticle.recommend.server.repository.entity.crawler.ArticleUserGroupNew;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.jpa.repository.Modifying;
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.query.Param;
-import org.springframework.stereotype.Repository;
-
-import java.util.List;
-
-@Repository
-public interface ArticleUserGroupRepository extends JpaRepository<ArticleUserGroupNew, Long> {
-    @Query("select distinct userGroupId from ArticleUserGroupNew where gzhId = :gzhId and isDelete = 0")
-    List<Integer> findAllUserGroupId(String gzhId);
-
-    ArticleUserGroupNew findFirstByGzhIdAndOpenId(String gzhId, String openId);
-
-    @Query("select distinct openId from ArticleUserGroupNew where gzhId = :gzhId" +
-            " and userGroupId = :userGroupId and isDelete = 0")
-    List<String> findAllOpenId(String gzhId, int userGroupId);
-
-    @Modifying
-    @Query("UPDATE ArticleUserGroupNew a SET a.userGroupId = a.id % :groupNum WHERE a.gzhId = :gzhId")
-    void updateUserGroupIdWithMod(@Param("gzhId") String gzhId, @Param("groupNum") int groupNum);
-}

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

@@ -1,25 +0,0 @@
-package com.tzld.longarticle.recommend.server.repository.entity.crawler;
-
-import lombok.Data;
-
-import javax.persistence.*;
-
-/**
- * @author dyp
- */
-@Data
-@Entity
-@Table(name = "article_user_group")
-public class ArticleUserGroupNew {
-    @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
-    private Long id;
-    @Column(name = "gzh_id")
-    private String gzhId;
-    @Column(name = "user_group_id")
-    private int userGroupId;
-    @Column(name = "open_id")
-    private String openId;
-    @Column(name = "is_delete")
-    private int isDelete;
-}

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

@@ -99,4 +99,11 @@ public interface ArticleUserGroupMapper {
     int updateByPrimaryKey(ArticleUserGroup row);
 
     int insertBatch(List<ArticleUserGroup> list);
+
+    ArticleUserGroup selectByGzhIdAndOpenId(String gzhId, String openId);
+
+    List<Integer> selectUserGroupIdByGzhId(String gzhId);
+
+    List<String> selectOpenIdByGzhIdAndUserGroupId(String gzhId, Integer userGroupId);
+
 }

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

@@ -3,11 +3,11 @@ package com.tzld.longarticle.recommend.server.service;
 import com.alibaba.fastjson.JSONObject;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.tzld.longarticle.recommend.server.model.*;
-import com.tzld.longarticle.recommend.server.repository.crawler.ArticleUserGroupRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.PublishContentSortLogRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.PublishSortLogRepository;
 import com.tzld.longarticle.recommend.server.repository.entity.crawler.PublishContentSortLog;
 import com.tzld.longarticle.recommend.server.repository.entity.crawler.PublishSortLog;
+import com.tzld.longarticle.recommend.server.repository.mapper.crawler.ArticleUserGroupMapper;
 import com.tzld.longarticle.recommend.server.service.rank.RankParam;
 import com.tzld.longarticle.recommend.server.service.rank.RankResult;
 import com.tzld.longarticle.recommend.server.service.rank.RankService;
@@ -52,7 +52,7 @@ public class RecommendService {
     @Autowired
     AccountIndexAvgViewCountService accountIndexAvgViewCountService;
     @Autowired
-    private ArticleUserGroupRepository articleUserGroupRepository;
+    private ArticleUserGroupMapper articleUserGroupMapper;
 
     @ApolloJsonValue("${accountStrategyConfig:{}}")
     private Map<String, String> accountStrategyConfigMap;
@@ -164,7 +164,7 @@ public class RecommendService {
 
         switch (abCode) {
             case FWH_COLD_START:
-                List<Integer> userGroupIds = articleUserGroupRepository.findAllUserGroupId(request.getGhId());
+                List<Integer> userGroupIds = articleUserGroupMapper.selectUserGroupIdByGzhId(request.getGhId());
                 LocalDate today = LocalDate.now(); // 获取当前日期
                 int dayOfYear = today.getDayOfYear();
                 int tailNum = dayOfYear % 8;
@@ -175,7 +175,6 @@ public class RecommendService {
                     }
                 }
                 param.setUserGroupIds(needPushUserGroupIds);
-
                 break;
         }
 

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

@@ -2,8 +2,6 @@ package com.tzld.longarticle.recommend.server.service;
 
 import com.tzld.longarticle.recommend.server.model.WxUserGetResponse;
 import com.tzld.longarticle.recommend.server.remote.WxUserManagementRemoteService;
-import com.tzld.longarticle.recommend.server.repository.crawler.ArticleUserGroupRepository;
-import com.tzld.longarticle.recommend.server.repository.entity.crawler.ArticleUserGroupNew;
 import com.tzld.longarticle.recommend.server.repository.mapper.crawler.ArticleUserGroupMapper;
 import com.tzld.longarticle.recommend.server.repository.model.ArticleUserGroup;
 import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
@@ -27,8 +25,6 @@ import java.util.*;
 public class UserManagementService {
     @Autowired
     private WxUserManagementRemoteService wxUserManagementRemoteService;
-    @Autowired
-    private ArticleUserGroupRepository articleUserGroupRepository;
 
     @Autowired
     private ArticleUserGroupMapper articleUserGroupMapper;
@@ -168,36 +164,37 @@ public class UserManagementService {
     }
 
     private void handleSubscribe(String gzhId, String openId) {
-        //
-        ArticleUserGroupNew group = articleUserGroupRepository.findFirstByGzhIdAndOpenId(gzhId, openId);
+
+        ArticleUserGroup group = articleUserGroupMapper.selectByGzhIdAndOpenId(gzhId, openId);
         if (group == null) {
             // insert
             // 查库,知道所有分组
-            List<Integer> ugIds = articleUserGroupRepository.findAllUserGroupId(gzhId);
+            List<Integer> ugIds = articleUserGroupMapper.selectUserGroupIdByGzhId(gzhId);
             // 随机选一个组
             int ugId = ugIds.get(RandomUtils.nextInt(ugIds.size()));
-            group = new ArticleUserGroupNew();
+            group = new ArticleUserGroup();
             group.setGzhId(gzhId);
             group.setOpenId(openId);
             group.setUserGroupId(ugId);
-            articleUserGroupRepository.save(group);
+            group.setIsDelete(0);
+            articleUserGroupMapper.insert(group);
         } else {
             // update
             group.setIsDelete(0);
-            articleUserGroupRepository.save(group);
+            articleUserGroupMapper.updateByPrimaryKey(group);
         }
 
     }
 
     private void handleUnsubscribe(String gzhId, String openId) {
-        ArticleUserGroupNew group = articleUserGroupRepository.findFirstByGzhIdAndOpenId(gzhId, openId);
+        ArticleUserGroup group = articleUserGroupMapper.selectByGzhIdAndOpenId(gzhId, openId);
         if (group != null) {
             group.setIsDelete(1);
-            articleUserGroupRepository.save(group);
+            articleUserGroupMapper.updateByPrimaryKey(group);
         }
     }
 
     public List<String> listByUserGroupId(String gzhId, int userGroupId) {
-        return articleUserGroupRepository.findAllOpenId(gzhId, userGroupId);
+        return articleUserGroupMapper.selectOpenIdByGzhIdAndUserGroupId(gzhId, userGroupId);
     }
 }

+ 24 - 0
long-article-recommend-service/src/main/resources/mapper/crawler/ArticleUserGroupMapper.xml

@@ -13,6 +13,7 @@
     <result column="open_id" jdbcType="VARCHAR" property="openId" />
     <result column="is_delete" jdbcType="INTEGER" property="isDelete" />
   </resultMap>
+
   <sql id="Example_Where_Clause">
     <!--
       WARNING - @mbg.generated
@@ -291,4 +292,27 @@
       (#{item.gzhId}, #{item.userGroupId}, #{item.openId}, #{item.isDelete})
     </foreach>
   </insert>
+
+  <select id="selectByGzhIdAndOpenId" resultMap="BaseResultMap">
+    select
+    <include refid="Base_Column_List" />
+    from article_user_group
+    where gzh_id = #{gzhId}
+    and open_id = #{openId}
+  </select>
+
+  <select id="selectUserGroupIdByGzhId" parameterType="java.lang.String" resultType="integer">
+    select
+    distinct user_group_id
+    from article_user_group
+    where gzh_id = #{gzhId}
+  </select>
+
+  <select id="selectOpenIdByGzhIdAndUserGroupId" resultType="string">
+    select
+      distinct user_group_id
+    from article_user_group
+    where gzh_id = #{gzhId}
+    and open_id = #{openId}
+  </select>
 </mapper>