From 9ff1d63fc94176663ce001add1571138ee46a7c3 Mon Sep 17 00:00:00 2001 From: gabang2 Date: Tue, 9 Jul 2024 14:19:50 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20Topic,=20Sentiment=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../culturalevent/entity/CulturalEvent.java | 6 ++-- .../service/CulturalEventBatchService.java | 30 +++++++++++++++---- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/main/java/project/backend/domain/culturalevent/entity/CulturalEvent.java b/src/main/java/project/backend/domain/culturalevent/entity/CulturalEvent.java index b45b413..46177a7 100644 --- a/src/main/java/project/backend/domain/culturalevent/entity/CulturalEvent.java +++ b/src/main/java/project/backend/domain/culturalevent/entity/CulturalEvent.java @@ -1,9 +1,6 @@ package project.backend.domain.culturalevent.entity; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; +import lombok.*; import project.backend.domain.common.entity.BaseEntity; import project.backend.domain.culturaleventevalutaion.entity.CulturalEventEvaluation; import project.backend.domain.like.entity.CulturalEventLike; @@ -22,6 +19,7 @@ import java.util.Optional; @Getter +@Setter @RequiredArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name = "cultural_event", indexes = { diff --git a/src/main/java/project/backend/domain/culturalevent/service/CulturalEventBatchService.java b/src/main/java/project/backend/domain/culturalevent/service/CulturalEventBatchService.java index b700bf1..b94af41 100644 --- a/src/main/java/project/backend/domain/culturalevent/service/CulturalEventBatchService.java +++ b/src/main/java/project/backend/domain/culturalevent/service/CulturalEventBatchService.java @@ -8,6 +8,7 @@ import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; @@ -47,6 +48,7 @@ public class CulturalEventBatchService { /** * CulturalEvent 생성 */ + @Scheduled(cron = "0 0 4 * * *") // 매일 새벽 4시에 실행 public void createCulturalEvents() { Map> interparkGoodsCodeMap = getInterparkGoodsCodeMap(); for (CategoryTitle categoryTitle : interparkGoodsCodeMap.keySet()) { @@ -90,6 +92,9 @@ public CulturalEvent createCulturalEvent(String goodsCode, CulturalEventCreateDt ticketingSite.setCulturalEvent(culturalEvent); }); + // Sentiment & Topic 추출 + setKeywordSentiment(culturalEvent, goodsCode); + // 저장 CulturalEvent savedCulturalEvent = culturalEventRepository.save(culturalEvent); @@ -123,8 +128,8 @@ public Map> getInterparkGoodsCodeMap() { List goodsCodeList = new ArrayList<>(); UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(baseUrl) .queryParam("genre", categoryTitle.getType()) - .queryParam("page", "2") - .queryParam("pageSize", "20"); + .queryParam("page", "1") + .queryParam("pageSize", "1000"); ResponseEntity response = restTemplate.exchange( uriBuilder.toUriString(), @@ -175,11 +180,26 @@ public CulturalEventCreateDto getDetailCulturalEventFromGoodsCode(String goodsCo /** * 기대평 기반 감정 저장 */ - public void setKeywordSentiment(String goodsCode) { - // GET 하는 내용 + public void setKeywordSentiment(CulturalEvent culturalEvent, String goodsCode) { + RestTemplate restTemplate = new RestTemplate(); + String keywordSentimentUrl = "http://13.125.32.85:8080/api/keyword"; + UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(keywordSentimentUrl) + .queryParam("goods_code", goodsCode); - } + ResponseEntity> response = restTemplate.exchange( + uriBuilder.toUriString(), + HttpMethod.GET, + null, + new ParameterizedTypeReference>() { + }); + Map responseBody = response.getBody(); + String topic = (String) responseBody.get("topic"); + String sentiment = (String) responseBody.get("sentiment"); + + culturalEvent.setTopic(topic); + culturalEvent.setSentiment(sentiment); + } }