Browse Source

通过rootSourceId获取ghId

wangyunpeng 11 hours ago
parent
commit
170aa2c9ad

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/longArticle/LongArticlesRootSourceIdRepository.java

@@ -11,5 +11,7 @@ public interface LongArticlesRootSourceIdRepository extends JpaRepository<LongAr
 
     List<LongArticlesRootSourceId> getByRootSourceIdIn(List<String> rootSourceIds);
 
+    LongArticlesRootSourceId getByRootSourceId(String rootSourceId);
+
     int countByTraceId(String traceId);
 }

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

@@ -0,0 +1,5 @@
+package com.tzld.longarticle.recommend.server.service.api;
+
+public interface ApiService {
+    String getGhIdByRootSourceId(String rootSourceId);
+}

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

@@ -0,0 +1,28 @@
+package com.tzld.longarticle.recommend.server.service.api.impl;
+
+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;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Objects;
+
+@Service
+@Slf4j
+public class ApiServiceImpl implements ApiService {
+
+    @Autowired
+    LongArticlesRootSourceIdRepository longArticlesRootSourceIdRepository;
+
+    @Override
+    public String getGhIdByRootSourceId(String rootSourceId) {
+        LongArticlesRootSourceId longArticlesRootSourceId = longArticlesRootSourceIdRepository.getByRootSourceId(rootSourceId);
+        if (Objects.isNull(longArticlesRootSourceId)) {
+            return null;
+        }
+        return longArticlesRootSourceId.getGhId();
+    }
+
+}

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

@@ -0,0 +1,25 @@
+package com.tzld.longarticle.recommend.server.web;
+
+import com.tzld.longarticle.recommend.server.common.response.CommonResponse;
+import com.tzld.longarticle.recommend.server.service.api.ApiService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/api")
+@Slf4j
+public class ApiController {
+
+    @Autowired
+    private ApiService service;
+
+    @GetMapping("/getGhIdByRootSourceId")
+    public CommonResponse<String> getGhIdByRootSourceId(@RequestParam String rootSourceId) {
+        return CommonResponse.success(service.getGhIdByRootSourceId(rootSourceId));
+    }
+
+}