Jelajahi Sumber

Merge branch 'wyp/0606-resetUserGroup' of Server/long-article-recommend into master

wangyunpeng 1 bulan lalu
induk
melakukan
2f1516c456

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

@@ -49,4 +49,5 @@ public interface CrawlerBaseMapper {
 
     List<Article> getByGhIdInAndPublishTimestampLessThanAndTypeEquals(List<String> ghIds, Long publishTimestamp, String type);
 
+    List<String> getNeedResetUserGroupGhIds();
 }

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

@@ -22,10 +22,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.io.StringReader;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @author dyp
@@ -119,7 +116,7 @@ public class UserManagementService {
         resetUserGroup(gzhId);
     }
 
-    private void resetUserGroup(String gzhId) {
+    public void resetUserGroup(String gzhId) {
         Long count = getGzhUserCount(gzhId);
         long pageSize = gzhUserGroupPerCount;
         int pageNum = 1;
@@ -218,7 +215,6 @@ public class UserManagementService {
     }
 
     private void handleSubscribe(String gzhId, String openId) {
-
         ArticleUserGroup group = articleUserGroupMapperExt.selectByGzhIdAndOpenId(gzhId, openId);
         Long count = getGzhUserCount(gzhId);
         if (group == null) {
@@ -250,6 +246,7 @@ public class UserManagementService {
     private Integer getUserGroupId(List<UserGroupCountDTO> userGroupCountDTOList, long count) {
         if (count >= ((long) gzhUserGroupSize * gzhUserGroupPerCount)
                 || userGroupCountDTOList.size() > gzhUserGroupSize) {
+            userGroupCountDTOList.sort(Comparator.comparing(UserGroupCountDTO::getUserGroupId));
             UserGroupCountDTO max = userGroupCountDTOList.get(userGroupCountDTOList.size() - 1);
             if (max.getCount() < gzhUserGroupPerCount) {
                 return max.getUserGroupId();

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

@@ -115,6 +115,8 @@ public class XxlJobService {
     private AIGCProduceContentAuditService aigcProduceContentAuditService;
     @Autowired
     private AccountRepository accountRepository;
+    @Autowired
+    private UserManagementService userManagementService;
 
     ExecutorService thread = new CommonThreadPoolExecutor(
             5,
@@ -951,4 +953,16 @@ public class XxlJobService {
         return ReturnT.SUCCESS;
     }
 
+    @XxlJob("resetUserGroup")
+    public ReturnT<String> resetUserGroup(String param) {
+        List<String> ghIds = crawlerBaseMapper.getNeedResetUserGroupGhIds();
+        if (CollectionUtil.isEmpty(ghIds)) {
+            return ReturnT.SUCCESS;
+        }
+        for (String ghId : ghIds) {
+            userManagementService.resetUserGroup(ghId);
+        }
+        return ReturnT.SUCCESS;
+    }
+
 }

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

@@ -117,4 +117,9 @@ public class XxlJobController {
         service.autoRestart(null);
     }
 
+    @GetMapping("/resetUserGroup")
+    public void resetUserGroup() {
+        service.resetUserGroup(null);
+    }
+
 }

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

@@ -100,4 +100,11 @@
         and type = #{type}
     </select>
 
+    <select id="getNeedResetUserGroupGhIds" resultType="java.lang.String">
+        select distinct t.gzh_id
+        from (select gzh_id, user_group_id, count(1)
+              from article_user_group
+              GROUP BY gzh_id, user_group_id having count(1) > 10000) t
+    </select>
+
 </mapper>