Skip to content

Commit

Permalink
Feat: Topic, Sentiment ์ €์žฅ
Browse files Browse the repository at this point in the history
  • Loading branch information
rrosiee committed Jul 9, 2024
1 parent 6600972 commit 9ff1d63
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,6 +19,7 @@
import java.util.Optional;

@Getter
@Setter
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "cultural_event", indexes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,6 +48,7 @@ public class CulturalEventBatchService {
/**
* CulturalEvent ์ƒ์„ฑ
*/
@Scheduled(cron = "0 0 4 * * *") // ๋งค์ผ ์ƒˆ๋ฒฝ 4์‹œ์— ์‹คํ–‰
public void createCulturalEvents() {
Map<CategoryTitle, List<String>> interparkGoodsCodeMap = getInterparkGoodsCodeMap();
for (CategoryTitle categoryTitle : interparkGoodsCodeMap.keySet()) {
Expand Down Expand Up @@ -90,6 +92,9 @@ public CulturalEvent createCulturalEvent(String goodsCode, CulturalEventCreateDt
ticketingSite.setCulturalEvent(culturalEvent);
});

// Sentiment & Topic ์ถ”์ถœ
setKeywordSentiment(culturalEvent, goodsCode);

// ์ €์žฅ
CulturalEvent savedCulturalEvent = culturalEventRepository.save(culturalEvent);

Expand Down Expand Up @@ -123,8 +128,8 @@ public Map<CategoryTitle, List<String>> getInterparkGoodsCodeMap() {
List<String> 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<String> response = restTemplate.exchange(
uriBuilder.toUriString(),
Expand Down Expand Up @@ -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<Map<String, Object>> response = restTemplate.exchange(
uriBuilder.toUriString(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<Map<String, Object>>() {
});

Map<String, Object> responseBody = response.getBody();
String topic = (String) responseBody.get("topic");
String sentiment = (String) responseBody.get("sentiment");

culturalEvent.setTopic(topic);
culturalEvent.setSentiment(sentiment);
}
}


0 comments on commit 9ff1d63

Please sign in to comment.