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

Develop #37

Merged
merged 9 commits into from
Dec 16, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import mvc.promiseme.calendar.dto.CalendarAndTodoAllByRoleDto;
import mvc.promiseme.calendar.dto.CalendarResponseDTO;
import mvc.promiseme.calendar.service.CalendarService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
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;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Slf4j
@RestController
@Controller
@RequiredArgsConstructor
@RequestMapping("/calendar")
public class CalendarController {
Expand All @@ -25,4 +29,13 @@ public class CalendarController {
//
// }

@GetMapping("/todoAll")
public ResponseEntity<List<CalendarAndTodoAllByRoleDto>> calendarTodoAll(
@RequestParam(name = "projectId") Long projectId
, @RequestParam(name = "todoDate") String todoDate){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate localDate = LocalDate.parse(todoDate, formatter);
return ResponseEntity.ok(calendarService.calendarAndtodoAll(projectId, localDate));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package mvc.promiseme.calendar.dto;

import lombok.*;

import java.util.List;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
public class CalendarAndTodoAllByRoleDto {
private String role;
private String recommendation;
private List<MemberDto> members;


@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
public static class MemberDto{
private String name;
private List<TodoDTO> todoList;
}


@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
public static class TodoDTO {
private String content;
private boolean status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

public interface CalendarRepository extends JpaRepository<Calendar, Long> {
// @Query("SELECT NEW mvc.promiseme.calendar.dto.CalendarResponseDTO(c.content, c.startDate, c.finishDate, u.nickname) from Calendar c join c.member m join m.users u where c.project = :project")
// List<CalendarResponseDTO> findByProject(Project project);
List<Calendar> findByProjectAndStartDateLessThanEqualAndFinishDateGreaterThanEqual(Project project, LocalDate startDate, LocalDate finishDate);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package mvc.promiseme.calendar.service;

import mvc.promiseme.calendar.dto.CalendarAndTodoAllByRoleDto;
import mvc.promiseme.calendar.dto.CalendarResponseDTO;

import java.time.LocalDate;
import java.util.List;

public interface CalendarService {

//public List<CalendarResponseDTO>calendarAll(Long projectId);

List<CalendarAndTodoAllByRoleDto> calendarAndtodoAll(Long projectId, LocalDate date);
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,72 @@
package mvc.promiseme.calendar.service;

import lombok.RequiredArgsConstructor;
import mvc.promiseme.calendar.dto.CalendarResponseDTO;
import mvc.promiseme.calendar.dto.CalendarAndTodoAllByRoleDto;
import mvc.promiseme.calendar.entity.Calendar;
import mvc.promiseme.calendar.repository.CalendarRepository;
import mvc.promiseme.project.entity.Member;
import mvc.promiseme.project.entity.Project;
import mvc.promiseme.project.repository.MemberRepository;
import mvc.promiseme.project.repository.ProjectRepository;
import mvc.promiseme.todo.entity.Todo;
import mvc.promiseme.todo.repository.TodoRepository;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

@Service
@RequiredArgsConstructor
public class CalendarServiceImpl implements CalendarService{

private final CalendarRepository calendarRepository;
private final MemberRepository memberRepository;
private final TodoRepository todoRepository;
private final ProjectRepository projectRepository;

@Override
public List<CalendarAndTodoAllByRoleDto> calendarAndtodoAll(Long projectId, LocalDate date) {
//
Project project = projectRepository.findById(projectId)
.orElseThrow(() -> new NoSuchElementException("[ERROR] 해당 프로젝트는 존재하지 않습니다"));
List<Calendar> calendars = calendarRepository
.findByProjectAndStartDateLessThanEqualAndFinishDateGreaterThanEqual(project, date, date);
if(calendars == null) throw new NoSuchElementException("[ERROR] Nothing in the calendar on selected date");

//
List<CalendarAndTodoAllByRoleDto> result = new ArrayList<>();
for(Calendar c : calendars){
CalendarAndTodoAllByRoleDto todoAllByRoleDto = new CalendarAndTodoAllByRoleDto();
todoAllByRoleDto.setRole(c.getRole().getName());
todoAllByRoleDto.setRecommendation(c.getContent());

List<CalendarAndTodoAllByRoleDto.MemberDto> memberDtoList = new ArrayList<>();

List<Member> members = memberRepository.findByProjectAndAndRole(c.getProject(), c.getRole());
for(Member m : members){
CalendarAndTodoAllByRoleDto.MemberDto memberDto = new CalendarAndTodoAllByRoleDto.MemberDto();
memberDto.setName(m.getUsers().getNickname());

List<CalendarAndTodoAllByRoleDto.TodoDTO> todoDTOList = new ArrayList<>();

List<Todo> todoList = todoRepository.findByMemberAndAndTodoDate(m, date);
for(Todo t : todoList){
CalendarAndTodoAllByRoleDto.TodoDTO todoDTO = new CalendarAndTodoAllByRoleDto.TodoDTO();
todoDTO.setContent(t.getContent());
todoDTO.setStatus(t.isCompleted());
todoDTOList.add(todoDTO);
}
memberDto.setTodoList(todoDTOList);
memberDtoList.add(memberDto);
}
todoAllByRoleDto.setMembers(memberDtoList);
result.add(todoAllByRoleDto);
}

return result;
}
// @Override
// public List<CalendarResponseDTO> calendarAll(Long projectId) {
// Project project = Project.builder().projectId(projectId).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import mvc.promiseme.meeting.dto.MeetingResponseDTO;
import mvc.promiseme.meeting.dto.SummaryRequestDTO;
import mvc.promiseme.meeting.service.MeetingService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -30,7 +31,7 @@ public ResponseEntity<String> transferVoice(@RequestParam("voiceFile") Multipart
}

@PostMapping("/summary")
public ResponseEntity<String> summaryText(@RequestParam("meetingContent") String meetingContent, @RequestParam("projectId") Long projectId){
return ResponseEntity.ok(meetingService.textToMeeting(meetingContent, projectId));
public ResponseEntity<String> summaryText(@RequestBody SummaryRequestDTO summaryRequestDTO) {
return ResponseEntity.ok(meetingService.textToMeeting(summaryRequestDTO.getMeetingContent(), summaryRequestDTO.getProjectId()));
}
}
13 changes: 13 additions & 0 deletions src/main/java/mvc/promiseme/meeting/dto/SummaryRequestDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package mvc.promiseme.meeting.dto;

import lombok.*;
import org.springframework.web.bind.annotation.RequestParam;
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
public class SummaryRequestDTO {
private String meetingContent;
private Long projectId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public String voiceToMeeting(MultipartFile multipartFile, Long projectId) {
String summary = summaryTextService.summary(transferredText);
if(summary == null) throw new SummaryException("[ERROR] summary fail");

updateEmptyRecord(meeting, transferredText, summary);
String meetingName = summaryTextService.getTitle(summary);
updateEmptyRecord(meeting, transferredText, meetingName,summary);
return "success";
}

Expand All @@ -56,7 +57,9 @@ public String textToMeeting(String text, Long projectId) {
Meeting meeting = addEmptyRecord(projectId);
String summary = summaryTextService.summary(text);
if(summary == null) throw new SummaryException("[ERROR] summary fail");
updateEmptyRecord(meeting, text, summary);

String meetingName = summaryTextService.getTitle(summary);
updateEmptyRecord(meeting, text,meetingName, summary);
return "success";
}

Expand All @@ -71,10 +74,10 @@ private Meeting addEmptyRecord(Long projectId){
return meeting;
}

private void updateEmptyRecord(Meeting meeting, String content, String summary){
private void updateEmptyRecord(Meeting meeting, String content,String meetingName, String summary){
meeting.setMeetingContent(content);
meeting.setSummary(summary);
meeting.setMeetingName("제목 생성 예정");
meeting.setMeetingName(meetingName);
meetingRepository.save(meeting);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

public interface SummaryTextService {
String summary(String text);

String getTitle(String summary);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.RequiredArgsConstructor;
import mvc.promiseme.project.dto.Message;
import mvc.promiseme.project.service.ClovaStudioRecommend;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.*;

@Service
@RequiredArgsConstructor
public class SummaryTextServiceImpl implements SummaryTextService{

private final ClovaStudioSummary clovaStudioSummary;

private final ClovaStudioRecommend clovaStudioRecommend;
@Override
public String summary(String text) {

Expand Down Expand Up @@ -50,4 +50,88 @@ public String summary(String text) {

return resultText;
}

@Override
public String getTitle(String summary) {
String url = clovaStudioRecommend.getUrl();
String apiKeyClovaStudio = clovaStudioRecommend.getApiKeyClovaStudio();

List<Message> messages = new ArrayList<>();

// 첫 번째 메시지
Message systemMessage = new Message("system", "당신은 주어진 텍스트를 한 줄로 요약하여 제목을 잘 지어주는 전문가입니다. ");
messages.add(systemMessage);

// 두 번째 메시지
Message userMessage = new Message("user","나는 아래와 같은 회의록 요약 내용을 가지고 있어. 이 회의록 요약 내용을 보고 회의록 제목을 작성해줘. \n" +
"\n" +
"\n" +
"\n" +
"- 부서원도 한 명 줄었고 다들 열심히 해보자고 함\n" +
" - 중대 발표를 해야 할 것 같다고 함\n" +
" - 회사에서 부서에 떨어진 프로젝트가 치킨임\n" +
" - 치킨이 굉장히 많고 고생이 많기 때문에 걱정이 됨\n" +
" - 회의할 때 딴 짓 하지 말고 집중하라고 함\n" +
"\n" +
"\n" +
"회의록 제목 : [제목]\n" +
"\n" +
"이 형식으로 작성해줘.\n" +
"\n" +
"다른 말 말고 \"제목\" 한개만 작성해줘.");
messages.add(userMessage);

// 세 번째 메시지
Message assistantMessage = new Message("assistant", "부서 회의록 제목 : 새로운 프로젝트 '치킨' 할당 및 부서원 감소에 따른 대책 논의");
messages.add(assistantMessage);

Message requestMessage = new Message("user", "나는 아래와 같은 회의록 요약 내용을 가지고 있어. 이 회의록 요약 내용을 보고 회의록 제목을 작성해줘. \n" +
"\n" +
"\n" +
"\n" +
summary+
"\n" +
"\n" +
"회의록 제목 : [제목]\n" +
"\n" +
"이 형식으로 작성해줘.\n" +
"\n" +
"다른 말 말고 \"제목\" 한개만 작성해줘.");
messages.add(requestMessage);

HttpHeaders headers = new HttpHeaders();
headers.set("X-NCP-CLOVASTUDIO-API-KEY", apiKeyClovaStudio);
headers.set("X-NCP-APIGW-API-KEY", clovaStudioRecommend.getApiGateWayKey());
headers.set("X-NCP-CLOVASTUDIO-REQUEST-ID", clovaStudioRecommend.getCreateTitleId());
headers.set("Content-Type", "application/json");

Map<String, Object> requestBody = new HashMap<>();
requestBody.put("messages", messages);
requestBody.put("topP", 0.8);
requestBody.put("topK", 0);
requestBody.put("maxTokens", 256);
requestBody.put("temperature", 0.5);
requestBody.put("repeatPenalty", 5.0);
requestBody.put("includeAiFilters", "True");

HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);

RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);

JsonObject jsonObject = JsonParser.parseString(responseEntity.getBody()).getAsJsonObject();
JsonObject messageObject = jsonObject.getAsJsonObject("result").getAsJsonObject("message");
String content = messageObject.get("content").getAsString();
String[] parts = content.split(" : ", 2);

if (parts.length == 2) {
String meetingName = parts[1];
return meetingName;

} else {
String meetingName = "제목 형식이 올바르지 않습니다.";
return meetingName;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import mvc.promiseme.project.entity.Member;
import mvc.promiseme.project.entity.Project;
import mvc.promiseme.project.entity.Role;
import mvc.promiseme.users.entity.Users;
import org.springframework.data.jpa.repository.JpaRepository;

Expand All @@ -11,5 +12,6 @@
public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByUsersAndProject(Users users, Project project);
List<Member> findByUsers(Users users);
List<Member> findByProjectAndAndRole(Project project, Role role);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public class ClovaStudioRecommend {
private String requestMemberId;
@Value("${RECOMMEND_SCHEDULE_REQUEST_ID}")
private String requestScheduleId;
@Value("CREATE_TITLE_REQUEST_ID")
private String createTitleId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void insertCalender(Long projectId, List<Map<String, String>> roleSchedul
role = Role.builder().name(map.get("role")).build();
roleRepository.save(role);
}
Calendar calendar = Calendar.builder().project(project).role(role).content(map.get("content")).finishDate(LocalDate.parse(map.get("finish"))).startDate(LocalDate.parse(map.get("start"))).build();
Calendar calendar = Calendar.builder().project(project).role(role).content(map.get("task")).finishDate(LocalDate.parse(map.get("finish"))).startDate(LocalDate.parse(map.get("start"))).build();
calendarRepository.save(calendar);
}
}
Expand Down
Loading