-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 투자성향 테스트 이후 Flask 서버로 요청을 보내서, 추천 좀목 3개를 받아서 db에 update하는 로직 추가
- Loading branch information
Showing
7 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/main/java/org/ai/roboadvisor/domain/tendency/dto/TendencyDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.ai.roboadvisor.domain.tendency.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.ai.roboadvisor.domain.tendency.entity.Tendency; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class TendencyDto { | ||
private Tendency tendency; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/ai/roboadvisor/domain/tendency/dto/response/TendencyFlaskResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.ai.roboadvisor.domain.tendency.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.ai.roboadvisor.domain.tendency.entity.Tendency; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class TendencyFlaskResponse { | ||
|
||
@JsonProperty("recommended_stocks") | ||
private List<String> recommended_stocks; | ||
|
||
@JsonProperty("tendency") | ||
private Tendency tendency; | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/ai/roboadvisor/domain/tendency/entity/StockKr.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.ai.roboadvisor.domain.tendency.entity; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) // 인자 없는 기본 생성자 필요 | ||
@Entity | ||
@Table(name = "stock_list_kr") | ||
public class StockKr { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false, name = "stock_code") | ||
private String stockCode; | ||
|
||
@Column(nullable = false, name = "stock_name") | ||
private String stockName; | ||
|
||
@Column(nullable = false) | ||
private String market; | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/ai/roboadvisor/domain/tendency/repository/StockKrRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.ai.roboadvisor.domain.tendency.repository; | ||
|
||
|
||
import org.ai.roboadvisor.domain.tendency.entity.StockKr; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface StockKrRepository extends JpaRepository<StockKr, Long> { | ||
|
||
Optional<StockKr> findByStockName(String stockName); | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/org/ai/roboadvisor/domain/tendency/service/FlaskRecommendClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.ai.roboadvisor.domain.tendency.service; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.ai.roboadvisor.domain.tendency.dto.TendencyDto; | ||
import org.ai.roboadvisor.domain.tendency.dto.response.TendencyFlaskResponse; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.time.Duration; | ||
|
||
@Slf4j | ||
@Service | ||
public class FlaskRecommendClient { | ||
|
||
private final WebClient flaskClient; | ||
|
||
@Autowired | ||
public FlaskRecommendClient(@Qualifier("FlaskClient") WebClient flaskClient) { | ||
this.flaskClient = flaskClient; | ||
} | ||
|
||
public TendencyFlaskResponse getStockData(TendencyDto dto) { | ||
log.info(">> run here"); | ||
try { | ||
return flaskClient.post() | ||
.uri("/recommend_stock") | ||
.bodyValue(dto) | ||
.retrieve() | ||
.bodyToMono(TendencyFlaskResponse.class) | ||
.timeout(Duration.ofSeconds(600)) | ||
.onErrorResume(e -> { | ||
log.error("]] Error: Get Recommend stock from Flask Server", e); | ||
return Mono.empty(); | ||
}) | ||
.block(); | ||
} catch (Exception e) { | ||
log.error(">> Exception: Get Recommend stock from Flask Server", e); | ||
return null; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters