Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 버블파트 메인 수정 #34

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ dependencies {

implementation 'org.springframework.boot:spring-boot-starter-security'

implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.2'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'

// implementation "org.springframework.cloud:spring-cloud-starter-bootstrap"
implementation 'org.springframework.boot:spring-boot-starter-actuator'
Expand All @@ -59,24 +59,24 @@ dependencies {
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

// Jwt
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.2'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'

// WebClient
implementation 'org.springframework.boot:spring-boot-starter-webflux'

// Feign
implementation 'io.github.openfeign:feign-httpclient:12.1'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:3.1.4'
implementation 'io.github.openfeign:feign-httpclient:12.2'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:4.0.1'

implementation 'org.springframework.boot:spring-boot-starter-data-redis'

// 형태소
implementation 'com.github.shin285:KOMORAN:3.3.4'

implementation 'org.json:json:20210307'
implementation 'com.googlecode.json-simple:json-simple:1.1'
implementation 'org.json:json:20230227'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'



Expand All @@ -90,12 +90,14 @@ dependencies {
implementation 'commons-logging:commons-logging:1.2'
implementation group: 'log4j', name: 'log4j', version: '1.2.17'


implementation group: 'org.springframework.cloud', name: 'spring-cloud-stream-binder-kafka', version: '3.2.1'
implementation 'org.springframework.cloud:spring-cloud-stream'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-stream-binder-kafka', version: '3.2.1'

implementation 'org.springframework.cloud:spring-cloud-stream:3.2.1'


}

dependencyManagement {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gwangjang/server/KeywordServiceApplication.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package gwangjang.server;


import gwangjang.server.domain.Issue.adapter.in.web.dto.get.SubscribeData;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.stream.annotation.EnableBinding;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package gwangjang.server.domain.Issue.application.dto.res;

import java.util.List;

public class BubbleChartRes {
String topic;
List<issueList> issueList;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gwangjang.server.domain.Issue.application.dto.res;

import lombok.*;

@Builder
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class IssueBySubscribersRes {

private Long categoryId;
private String category; //영역
private Long titleId;
private String title; //주제
private Long subscribeCount;
private String imgUrl;

public IssueBySubscribersRes(Long titleId, Long subscribeCount) {
this.titleId = titleId;
this.subscribeCount = subscribeCount;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package gwangjang.server.domain.Issue.application.dto.res;

public class issueList {
String name;
Long value;

}
Original file line number Diff line number Diff line change
@@ -1,47 +1,91 @@
package gwangjang.server.domain.Issue.application.service;

import gwangjang.server.domain.Issue.application.dto.res.IssueBySubscribersRes;
import gwangjang.server.domain.Issue.application.dto.res.MainBubbleData;
import gwangjang.server.domain.Issue.application.dto.res.MainBubbleRes;
import gwangjang.server.domain.Issue.domain.service.IssueService;
import gwangjang.server.global.feign.FindMemberFeignClient;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional
@RequiredArgsConstructor
public class KeywordSubscribeUseCase {

private final IssueService issueService;
private final FindMemberFeignClient findMemberFeignClient;
// public List<MainBubbleRes> getBubbleData() {
//// List<MainBubbleRes> mainBubbleRes = new ArrayList<>();
//// List<MainBubbleData> mainBubbleData1 = new ArrayList<>();
//// mainBubbleData1.add(new MainBubbleData("후쿠시마 오염수", 356L));
//// mainBubbleData1.add(new MainBubbleData("일회용품 사용 규제 시행", 123L));
//// mainBubbleRes.add(new MainBubbleRes("환경", mainBubbleData1));
////
//// List<MainBubbleData> mainBubbleData2 = new ArrayList<>();
//// mainBubbleData2.add(new MainBubbleData("SPC 불매 운동", 335L));
//// mainBubbleData2.add(new MainBubbleData("쿠팡 노동자 사망", 121L));
//// mainBubbleData2.add(new MainBubbleData("주 69시간 근로시간 제도 개편", 50L));
//// mainBubbleRes.add(new MainBubbleRes("일자리/노동", mainBubbleData2));
////
//// List<MainBubbleData> mainBubbleData3 = new ArrayList<>();
//// mainBubbleData3.add(new MainBubbleData("이태원 참사", 90L));
//// mainBubbleData3.add(new MainBubbleData("국민연금 개혁", 323L));
//// mainBubbleRes.add(new MainBubbleRes("주거/사회안전망", mainBubbleData3));
////
//// List<MainBubbleData> mainBubbleData4 = new ArrayList<>();
//// mainBubbleData4.add(new MainBubbleData("의대 정원 확대", 156L));
//// mainBubbleData4.add(new MainBubbleData("서이초 교사 사건", 400L));
//// mainBubbleRes.add(new MainBubbleRes("교육", mainBubbleData4));
//
//
//
//
// return null;
// }
public List<MainBubbleRes> getBubbleData() {
List<MainBubbleRes> mainBubbleRes = new ArrayList<>();
List<IssueBySubscribersRes> subscribersRes = findMemberFeignClient.getIssuesBySubscribers("guest").getBody().getData();
return mapToMainBubbleResList(subscribersRes);
}

List<MainBubbleData> mainBubbleData2 = new ArrayList<>();
mainBubbleData2.add(new MainBubbleData("SPC 불매 운동", 335L));
mainBubbleData2.add(new MainBubbleData("쿠팡 노동자 사망", 121L));
mainBubbleData2.add(new MainBubbleData("주 69시간 근로시간 제도 개편", 50L));
mainBubbleRes.add(new MainBubbleRes("일자리/노동", mainBubbleData2));
public List<MainBubbleRes> mapToMainBubbleResList(List<IssueBySubscribersRes> subscribersRes) {
return subscribersRes.stream()
.collect(Collectors.groupingBy(IssueBySubscribersRes::getCategory))
.entrySet().stream()
.map(entry -> {
MainBubbleRes mainBubbleRes = new MainBubbleRes();
mainBubbleRes.setName(entry.getKey());

List<MainBubbleData> mainBubbleData3 = new ArrayList<>();
mainBubbleData3.add(new MainBubbleData("이태원 참사", 90L));
mainBubbleData3.add(new MainBubbleData("국민연금 개혁", 323L));
mainBubbleRes.add(new MainBubbleRes("주거/사회안전망", mainBubbleData3));
List<MainBubbleData> mainBubbleDataList = entry.getValue().stream()
.map(this::mapToMainBubbleData)
.collect(Collectors.toList());

mainBubbleRes.setData(mainBubbleDataList);
return mainBubbleRes;
})
.collect(Collectors.toList());
}

private MainBubbleData mapToMainBubbleData(IssueBySubscribersRes issueBySubscribersRes) {
MainBubbleData mainBubbleData = new MainBubbleData();
mainBubbleData.setName(issueBySubscribersRes.getTitle());

List<MainBubbleData> mainBubbleData1 = new ArrayList<>();
mainBubbleData1.add(new MainBubbleData("후쿠시마 오염", 356L));
mainBubbleData1.add(new MainBubbleData("일회용품 사용 규제 시행", 123L));
mainBubbleRes.add(new MainBubbleRes("환경", mainBubbleData1));
// Calculate subscriber count within the specified ratio (e.g., 50%)
mainBubbleData.setValue((long) calculateRatioBasedSubscriberCount(0.5));

return mainBubbleData;
}

private int calculateRatioBasedSubscriberCount(double ratio) {
int minSubscriberCount = 100;
int maxSubscriberCount = 400;

List<MainBubbleData> mainBubbleData4 = new ArrayList<>();
mainBubbleData4.add(new MainBubbleData("의대 정원 확대", 156L));
mainBubbleData4.add(new MainBubbleData("서이초 교사 사건", 400L));
mainBubbleRes.add(new MainBubbleRes("교육", mainBubbleData4));
// Calculate subscriber count within the specified ratio
return (int) (minSubscriberCount + (maxSubscriberCount - minSubscriberCount + 1) * ratio);

return mainBubbleRes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.*;

@Service
@Transactional
Expand All @@ -29,14 +28,14 @@ public NaverTrendDto getNaverTrend(String issue) {

TrendRes trendRes = naverTrendUtil.main(replace);


String [] month = new String[] {"5월 1주차", "5월 2주차", "5월 3주차", "5월 4주차", "5월 5주차", "6월 1주차",
"6월 2주차", "6월 3주차", "6월 4주차", "7월 1주차", "7월 2주차", "7월 3주차", "7월 4주차","7월 5주차",
"8월 1주차", "8월 2주차", "8월 3주차", "8월 4주차", "8월 5주차", "9월 1주차", "9월 2주차", "9월 3주차",
"9월 4주차","10월 1주차","10월 2주차","10월 3주차","10월 4주차","10월 5주차","11월 1주차","11월 2주차","11월 3주차" } ;

List<TrendRes.Trend> trendList = new ArrayList<>();


List<DataPoint> data = trendRes.getResults().get(0).getData();

data.stream().forEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,5 @@ public List<TopicIssue> findRandomIssues() {

return resultList;
}
//분석된 결과 다ㅓㅅ개
//분석된 결과
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import gwangjang.server.domain.Issue.domain.repository.KeywordRepository;
import gwangjang.server.domain.Issue.domain.repository.TopicRepository;
import gwangjang.server.domain.Issue.exception.NotFoundIssueException;
import gwangjang.server.global.feign.FindMemberFeignClient;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -30,6 +31,8 @@ public class IssueService {
private final IssueMapper issueMapper = new IssueMapper();




public IssueRes findIssueAndTopicById(Long issueId) {
return issueQueryRepository.findIssueAndTopicById(issueId).orElseThrow(NotFoundIssueException::new);
}
Expand Down Expand Up @@ -138,5 +141,4 @@ public SearchRes search(String keyword) {
public List<TopicIssue> findRandomIssues(){
return issueRepository.findRandomIssues();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ public ResponseEntity<SuccessResponse<List<TopicIssue>>> getRandomIssue() {
return ResponseEntity.ok(SuccessResponse.create(IssueResponseMessage.GET_ISSUE_SUCCESS.getMessage(),this.issueService.findRandomIssues()));
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gwangjang.server.domain.Issue.presentation;


import gwangjang.server.domain.Issue.application.dto.res.*;
import gwangjang.server.domain.Issue.application.dto.res.MainBubbleRes;
import gwangjang.server.domain.Issue.application.dto.res.NaverTrendDto;
import gwangjang.server.domain.Issue.application.dto.res.TrendIssueGraphRes;
Expand All @@ -17,6 +17,7 @@
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

import static gwangjang.server.domain.Issue.presentation.constant.IssueResponseMessage.GET_MAIN_BUBBLE_CHART;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package gwangjang.server.global.feign;

import gwangjang.server.domain.Issue.application.dto.res.IssueBySubscribersRes;
import gwangjang.server.global.response.SuccessResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;

import java.util.List;

@FeignClient(name="MEMBERSERVICE")
public interface FindMemberFeignClient {
@GetMapping("/subscribe/issue")
ResponseEntity<SuccessResponse<List<IssueBySubscribersRes>>> getIssuesBySubscribers(@RequestHeader(value = "user-id") String socialId);
}
37 changes: 37 additions & 0 deletions src/main/java/gwangjang/server/global/rabbitMQ/Email.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package gwangjang.server.global.rabbitMQ;

public class Email {

private String to;
private String body;

public Email() {
}

public Email(String to, String body) {
this.to = to;
this.body = body;
}

public String getTo() {
return to;
}

public void setTo(String to) {
this.to = to;
}

public String getBody() {
return body;
}

public void setBody(String body) {
this.body = body;
}

@Override
public String toString() {
return String.format("Email{to=%s, body=%s}", getTo(), getBody());
}

}
29 changes: 29 additions & 0 deletions src/main/java/gwangjang/server/global/rabbitMQ/RabbitMQConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package gwangjang.server.global.rabbitMQ;

import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

@Bean
public TopicExchange topic() {
return new TopicExchange("amq.topic");
}

@Bean
public Jackson2JsonMessageConverter producerJackson2MessageConverter() {
return new Jackson2JsonMessageConverter();
}

@Bean
public RabbitTemplate rabbitTemplate(final ConnectionFactory connectionFactory) {
final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setMessageConverter(producerJackson2MessageConverter());
return rabbitTemplate;
}
}
Loading
Loading