Просмотр исходного кода

增加获取账号已发布内容sourceId接口

wangyunpeng 2 часов назад
Родитель
Сommit
6c38209779

+ 3 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/mapper/longArticle/LongArticleBaseMapper.java

@@ -128,4 +128,7 @@ public interface LongArticleBaseMapper {
     List<DatastatSortStrategy> getNullCategoryDatastat();
 
     String getCooperateArticleIdByRootSourceId(String rootSourceId);
+
+    List<DatastatSortStrategy> getByAccountAndOptionalParams(String accountName, String type, Integer position,
+                                                             String dateStrStart, String dateStrEnd);
 }

+ 4 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/api/ApiService.java

@@ -1,9 +1,13 @@
 package com.tzld.longarticle.recommend.server.service.api;
 
+import java.util.List;
+
 public interface ApiService {
 
     String getGhIdByRootSourceId(String rootSourceId);
 
     Boolean checkExistRootSourceId(String rootSourceId);
 
+    List<String> getSourceIdsByAccount(String accountName, String type, Integer position, String dateStrStart, String dateStrEnd);
+
 }

+ 19 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/api/impl/ApiServiceImpl.java

@@ -1,5 +1,7 @@
 package com.tzld.longarticle.recommend.server.service.api.impl;
 
+import com.tzld.longarticle.recommend.server.mapper.longArticle.LongArticleBaseMapper;
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.DatastatSortStrategy;
 import com.tzld.longarticle.recommend.server.model.entity.longArticle.LongArticlesRootSourceId;
 import com.tzld.longarticle.recommend.server.repository.longArticle.LongArticlesRootSourceIdRepository;
 import com.tzld.longarticle.recommend.server.service.api.ApiService;
@@ -9,7 +11,9 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 @Service
 @Slf4j
@@ -18,6 +22,9 @@ public class ApiServiceImpl implements ApiService {
     @Autowired
     LongArticlesRootSourceIdRepository longArticlesRootSourceIdRepository;
 
+    @Autowired
+    private LongArticleBaseMapper longArticleBaseMapper;
+
     @Autowired
     private RedisUtil redisUtil;
 
@@ -45,4 +52,16 @@ public class ApiServiceImpl implements ApiService {
         return exists;
     }
 
+    @Override
+    public List<String> getSourceIdsByAccount(String accountName, String type, Integer position,
+                                              String dateStrStart, String dateStrEnd) {
+        List<DatastatSortStrategy> list = longArticleBaseMapper.getByAccountAndOptionalParams(accountName, type, position,
+                dateStrStart, dateStrEnd);
+        return list.stream()
+                .map(DatastatSortStrategy::getSourceId)
+                .filter(StringUtils::isNotEmpty)
+                .distinct()
+                .collect(Collectors.toList());
+    }
+
 }

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

@@ -9,6 +9,8 @@ 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;
+
 @RestController
 @RequestMapping("/api")
 @Slf4j
@@ -27,4 +29,13 @@ public class ApiController {
         return CommonResponse.success(service.checkExistRootSourceId(rootSourceId));
     }
 
+    @GetMapping("/getSourceIdsByAccount")
+    public CommonResponse<List<String>> getSourceIdsByAccount(@RequestParam String accountName,
+                                                               @RequestParam(required = false) String type,
+                                                               @RequestParam(required = false) Integer position,
+                                                               @RequestParam(required = false) String dateStrStart,
+                                                               @RequestParam(required = false) String dateStrEnd) {
+        return CommonResponse.success(service.getSourceIdsByAccount(accountName, type, position, dateStrStart, dateStrEnd));
+    }
+
 }

+ 19 - 0
long-article-recommend-service/src/main/resources/mapper/longArticle/LongArticleBaseMapper.xml

@@ -536,4 +536,23 @@
         limit 1
     </select>
 
+    <select id="getByAccountAndOptionalParams"
+            resultType="com.tzld.longarticle.recommend.server.model.entity.longArticle.DatastatSortStrategy">
+        select *
+        from datastat_sort_strategy
+        where account_name = #{accountName}
+        <if test="position != null">
+            and position = #{position}
+        </if>
+        <if test="type != null">
+            and type = #{type}
+        </if>
+        <if test="dateStrStart != null and dateStrStart != ''">
+            and date_str >= #{dateStrStart}
+        </if>
+        <if test="dateStrEnd != null and dateStrEnd != ''">
+            and date_str &lt;= #{dateStrEnd}
+        </if>
+    </select>
+
 </mapper>