diff --git a/src/main/java/mvc/promiseme/calendar/controller/CalendarController.java b/src/main/java/mvc/promiseme/calendar/controller/CalendarController.java index 53aedbb..9dbc2ff 100644 --- a/src/main/java/mvc/promiseme/calendar/controller/CalendarController.java +++ b/src/main/java/mvc/promiseme/calendar/controller/CalendarController.java @@ -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 { @@ -25,4 +29,13 @@ public class CalendarController { // // } + @GetMapping("/todoAll") + public ResponseEntity> 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)); + } + } diff --git a/src/main/java/mvc/promiseme/calendar/dto/CalendarAndTodoAllByRoleDto.java b/src/main/java/mvc/promiseme/calendar/dto/CalendarAndTodoAllByRoleDto.java new file mode 100644 index 0000000..6809f2c --- /dev/null +++ b/src/main/java/mvc/promiseme/calendar/dto/CalendarAndTodoAllByRoleDto.java @@ -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 members; + + + @NoArgsConstructor + @AllArgsConstructor + @Getter + @Setter + @Builder + public static class MemberDto{ + private String name; + private List todoList; + } + + + @NoArgsConstructor + @AllArgsConstructor + @Getter + @Setter + @Builder + public static class TodoDTO { + private String content; + private boolean status; + } +} diff --git a/src/main/java/mvc/promiseme/calendar/repository/CalendarRepository.java b/src/main/java/mvc/promiseme/calendar/repository/CalendarRepository.java index c7af2b5..5896602 100644 --- a/src/main/java/mvc/promiseme/calendar/repository/CalendarRepository.java +++ b/src/main/java/mvc/promiseme/calendar/repository/CalendarRepository.java @@ -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 { // @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 findByProject(Project project); + List findByProjectAndStartDateLessThanEqualAndFinishDateGreaterThanEqual(Project project, LocalDate startDate, LocalDate finishDate); } diff --git a/src/main/java/mvc/promiseme/calendar/service/CalendarService.java b/src/main/java/mvc/promiseme/calendar/service/CalendarService.java index 0d2f0f9..f1dcc58 100644 --- a/src/main/java/mvc/promiseme/calendar/service/CalendarService.java +++ b/src/main/java/mvc/promiseme/calendar/service/CalendarService.java @@ -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 ListcalendarAll(Long projectId); + + List calendarAndtodoAll(Long projectId, LocalDate date); } diff --git a/src/main/java/mvc/promiseme/calendar/service/CalendarServiceImpl.java b/src/main/java/mvc/promiseme/calendar/service/CalendarServiceImpl.java index 1878578..2a15c2e 100644 --- a/src/main/java/mvc/promiseme/calendar/service/CalendarServiceImpl.java +++ b/src/main/java/mvc/promiseme/calendar/service/CalendarServiceImpl.java @@ -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 calendarAndtodoAll(Long projectId, LocalDate date) { + // + Project project = projectRepository.findById(projectId) + .orElseThrow(() -> new NoSuchElementException("[ERROR] 해당 프로젝트는 존재하지 않습니다")); + List calendars = calendarRepository + .findByProjectAndStartDateLessThanEqualAndFinishDateGreaterThanEqual(project, date, date); + if(calendars == null) throw new NoSuchElementException("[ERROR] Nothing in the calendar on selected date"); + + // + List result = new ArrayList<>(); + for(Calendar c : calendars){ + CalendarAndTodoAllByRoleDto todoAllByRoleDto = new CalendarAndTodoAllByRoleDto(); + todoAllByRoleDto.setRole(c.getRole().getName()); + todoAllByRoleDto.setRecommendation(c.getContent()); + + List memberDtoList = new ArrayList<>(); + + List members = memberRepository.findByProjectAndAndRole(c.getProject(), c.getRole()); + for(Member m : members){ + CalendarAndTodoAllByRoleDto.MemberDto memberDto = new CalendarAndTodoAllByRoleDto.MemberDto(); + memberDto.setName(m.getUsers().getNickname()); + + List todoDTOList = new ArrayList<>(); + + List 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 calendarAll(Long projectId) { // Project project = Project.builder().projectId(projectId).build(); diff --git a/src/main/java/mvc/promiseme/meeting/controller/MeetingController.java b/src/main/java/mvc/promiseme/meeting/controller/MeetingController.java index 2d22e4e..39b71d7 100644 --- a/src/main/java/mvc/promiseme/meeting/controller/MeetingController.java +++ b/src/main/java/mvc/promiseme/meeting/controller/MeetingController.java @@ -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.*; @@ -30,7 +31,7 @@ public ResponseEntity transferVoice(@RequestParam("voiceFile") Multipart } @PostMapping("/summary") - public ResponseEntity summaryText(@RequestParam("meetingContent") String meetingContent, @RequestParam("projectId") Long projectId){ - return ResponseEntity.ok(meetingService.textToMeeting(meetingContent, projectId)); + public ResponseEntity summaryText(@RequestBody SummaryRequestDTO summaryRequestDTO) { + return ResponseEntity.ok(meetingService.textToMeeting(summaryRequestDTO.getMeetingContent(), summaryRequestDTO.getProjectId())); } } diff --git a/src/main/java/mvc/promiseme/meeting/dto/SummaryRequestDTO.java b/src/main/java/mvc/promiseme/meeting/dto/SummaryRequestDTO.java new file mode 100644 index 0000000..e53ccee --- /dev/null +++ b/src/main/java/mvc/promiseme/meeting/dto/SummaryRequestDTO.java @@ -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; +} diff --git a/src/main/java/mvc/promiseme/meeting/service/MeetingServiceImpl.java b/src/main/java/mvc/promiseme/meeting/service/MeetingServiceImpl.java index a5d78d5..a69da2e 100644 --- a/src/main/java/mvc/promiseme/meeting/service/MeetingServiceImpl.java +++ b/src/main/java/mvc/promiseme/meeting/service/MeetingServiceImpl.java @@ -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"; } @@ -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"; } @@ -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); } diff --git a/src/main/java/mvc/promiseme/meeting/service/SummaryTextService.java b/src/main/java/mvc/promiseme/meeting/service/SummaryTextService.java index 2f9783f..0ccf9b6 100644 --- a/src/main/java/mvc/promiseme/meeting/service/SummaryTextService.java +++ b/src/main/java/mvc/promiseme/meeting/service/SummaryTextService.java @@ -2,4 +2,6 @@ public interface SummaryTextService { String summary(String text); + + String getTitle(String summary); } diff --git a/src/main/java/mvc/promiseme/meeting/service/SummaryTextServiceImpl.java b/src/main/java/mvc/promiseme/meeting/service/SummaryTextServiceImpl.java index 4ae2810..f0b3910 100644 --- a/src/main/java/mvc/promiseme/meeting/service/SummaryTextServiceImpl.java +++ b/src/main/java/mvc/promiseme/meeting/service/SummaryTextServiceImpl.java @@ -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) { @@ -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 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 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> requestEntity = new HttpEntity<>(requestBody, headers); + + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity 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; + } + + } } diff --git a/src/main/java/mvc/promiseme/project/repository/MemberRepository.java b/src/main/java/mvc/promiseme/project/repository/MemberRepository.java index d28d9c5..ed5bbbb 100644 --- a/src/main/java/mvc/promiseme/project/repository/MemberRepository.java +++ b/src/main/java/mvc/promiseme/project/repository/MemberRepository.java @@ -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; @@ -11,5 +12,6 @@ public interface MemberRepository extends JpaRepository { Optional findByUsersAndProject(Users users, Project project); List findByUsers(Users users); + List findByProjectAndAndRole(Project project, Role role); } diff --git a/src/main/java/mvc/promiseme/project/service/ClovaStudioRecommend.java b/src/main/java/mvc/promiseme/project/service/ClovaStudioRecommend.java index 807c190..2b2987f 100644 --- a/src/main/java/mvc/promiseme/project/service/ClovaStudioRecommend.java +++ b/src/main/java/mvc/promiseme/project/service/ClovaStudioRecommend.java @@ -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; } \ No newline at end of file diff --git a/src/main/java/mvc/promiseme/project/service/RecommendServiceImpl.java b/src/main/java/mvc/promiseme/project/service/RecommendServiceImpl.java index 0f41b7c..08ea294 100644 --- a/src/main/java/mvc/promiseme/project/service/RecommendServiceImpl.java +++ b/src/main/java/mvc/promiseme/project/service/RecommendServiceImpl.java @@ -264,7 +264,7 @@ public void insertCalender(Long projectId, List> 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); } } diff --git a/src/test/java/mvc/promiseme/todo/TodoServiceImplTest.java b/src/test/java/mvc/promiseme/todo/TodoServiceImplTest.java index 5636125..1b82234 100644 --- a/src/test/java/mvc/promiseme/todo/TodoServiceImplTest.java +++ b/src/test/java/mvc/promiseme/todo/TodoServiceImplTest.java @@ -6,6 +6,7 @@ import mvc.promiseme.project.repository.ProjectRepository; import mvc.promiseme.todo.dto.TodoRequestDTO; import mvc.promiseme.todo.repository.TodoRepository; +import mvc.promiseme.todo.service.TodoService; import mvc.promiseme.todo.service.TodoServiceImpl; import mvc.promiseme.users.entity.Users; import mvc.promiseme.users.repository.UserRepository; @@ -14,7 +15,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import java.time.LocalDate; import java.util.NoSuchElementException; import java.util.Optional; @@ -97,4 +100,9 @@ void insert_userNotFound() { assertThrows(NoSuchElementException.class, () -> todoService.insert(todoRequestDTO)); verify(todoRepository, never()).save(any()); } + @Test + public void getMember(){ + TodoRequestDTO todoRequestDTO = TodoRequestDTO.builder().todoDate(LocalDate.parse("2023-12-17")).projectId(3L).content("잠자기").userId(1L).build(); + todoService.insert(todoRequestDTO); + } }