| 
					
				 | 
			
			
				@@ -1,31 +1,106 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.tzld.longarticle.recommend.server; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.repository.crawler.AccountAvgInfoRepository; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+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.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.service.RecommendService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.longarticle.recommend.server.service.recall.RecallParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.longarticle.recommend.server.service.recall.RecallResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.tzld.longarticle.recommend.server.service.recall.RecallService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.commons.collections4.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.junit.jupiter.api.Test; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.boot.test.context.SpringBootTest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import javax.annotation.Resource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.text.SimpleDateFormat; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-@SpringBootTest(classes = RecommendTest.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@SpringBootTest(classes = Application.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class RecommendTest { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private RecommendService recommendService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private RecallService recallService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ArticleRepository articleRepository; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ArticleDetailInfoRepository articleDetailInfoRepository; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @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)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//    @Test 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//    void recall() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        RecallParam param = new RecallParam(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        param.setAccountId("20231213123536190184852"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        param.setPlanId("20240718181730864154902"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        RecallResult recallResult = recallService.recall(param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        System.out.println(JSONObject.toJSONString(recallResult)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<AccountAvgInfo> accountAvgInfoList = accountAvgInfoRepository.getAllByGhIdIn(ghIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        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 firstLevel = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int sumFission0 = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int sumFission1 = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int sumFission2 = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (ArticleDetailInfo articleDetailInfo : articleDetailInfos) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (articleDetailInfo.getRecallDt().equals(minDate)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    firstLevel += 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", sumFission0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            obj.put("fission0", sumFission0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            obj.put("fission1", sumFission1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            obj.put("fission2", sumFission2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            jsonArray.add(obj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        System.out.println(jsonArray.toJSONString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |