diff --git a/src/main/java/io/company/localhost/controller/api/BoardController.java b/src/main/java/io/company/localhost/controller/api/BoardController.java index 1b96954..50b7a7e 100644 --- a/src/main/java/io/company/localhost/controller/api/BoardController.java +++ b/src/main/java/io/company/localhost/controller/api/BoardController.java @@ -172,14 +172,14 @@ public class BoardController { @Member @ParameterCheck @GetMapping("/{boardId}/comments") - public ApiResponse> getComments(@ReqMap MapDto map) { + public ApiResponse> getComments(@ReqMap MapDto map) { return ApiResponse.ok(boardService.getComments(map)); } /** * 댓글/대댓글 작성 * @param boardId 게시물 ID - * @ReqMap map 댓글 데이터 (LOCBRDSEQ, LOCCMTRPY, LOCCMTPNT, LOCCMTPWD, MEMBERSEQ 등) + * @ReqMap map 댓글 데이터 (LOCBRDSEQ, LOCCMTRPY, LOCCMTPNT, LOCCMTPWD, MEMBERSEQ ) * @return 작성 결과 메시지 */ @Member diff --git a/src/main/java/io/company/localhost/controller/api/VacationController.java b/src/main/java/io/company/localhost/controller/api/VacationController.java index 3123c9e..ef61e70 100644 --- a/src/main/java/io/company/localhost/controller/api/VacationController.java +++ b/src/main/java/io/company/localhost/controller/api/VacationController.java @@ -1,5 +1,8 @@ package io.company.localhost.controller.api; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; import java.util.List; +import java.util.Map; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -8,11 +11,14 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import io.company.localhost.common.annotation.Member; +import io.company.localhost.common.annotation.ParameterCheck; import io.company.localhost.common.annotation.ReqMap; import io.company.localhost.common.dto.ApiResponse; import io.company.localhost.common.dto.MapDto; import io.company.localhost.service.commoncodService; import io.company.localhost.service.localvacaService; // 서비스 클래스 경로 수정 +import io.company.localhost.utils.AuthUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -23,31 +29,33 @@ import lombok.extern.slf4j.Slf4j; public class VacationController { private final localvacaService localVacaService; - + + @Member + @ParameterCheck @PostMapping - public ApiResponse saveVacations(@RequestBody List map) { - + public ApiResponse saveVacations(@RequestBody List map) { + Long user = AuthUtil.getUser().getId(); for (MapDto request : map) { - // 각 요청 데이터의 필수 값 검증 - Integer employeeId = (Integer) request.get("employeeId"); String date = request.getString("date"); String type = request.getString("type"); + Object receiverId = request.get("receiverId"); - if (employeeId == null || date == null || type == null) { + if ( date == null || type == null) { throw new IllegalArgumentException("요청 데이터에 누락된 값이 있습니다: " + request); } - + request.put("employeeId", user); // 데이터 저장 localVacaService.insertVacation(request); } return ApiResponse.ok("모든 휴가가 성공적으로 저장되었습니다."); } - /** * 특정 연월에 대한 휴가 데이터 조회 */ + @Member + @ParameterCheck @GetMapping("/list/{year}/{month}") public List getVacations(@PathVariable("year") int year, @PathVariable("month") int month) { return localVacaService.getVacationList(year, month); @@ -56,9 +64,44 @@ public class VacationController { /** * 특정 연월에 대한 공휴일 데이터 조회 */ + @Member + @ParameterCheck @GetMapping("/{year}/{month}") public List getHolidays(@PathVariable("year") int year, @PathVariable("month") int month) { return localVacaService.getHolidays(year, month); } + /** + * 내 연차 사용 내역 조회 + */ + @Member + @ParameterCheck + @GetMapping("/history") + public ApiResponse>> getUserVacationHistory() { + Long userId = AuthUtil.getUser().getId(); + return ApiResponse.ok(localVacaService.getUserVacationHistory(userId)); + } + + + @GetMapping("/remaining") + public ApiResponse> getRemainingVacation() { + List employeeVacations = localVacaService.getEmployeeRemainingVacation(); + return ApiResponse.ok(employeeVacations); + } + + @GetMapping("/codes") + public ApiResponse> getVacationCodeNames() { + return ApiResponse.ok(localVacaService.getCommonCodeList()); + } + + @GetMapping("/sent") + public ApiResponse> getSentVacations(@ReqMap MapDto map) { + Long userId = AuthUtil.getUser().getId(); // 현재 로그인한 사용자 ID + map.put("userId", userId); + List sentCount = localVacaService.getSentVacationCount(map); + + + return ApiResponse.ok(sentCount); + } + } diff --git a/src/main/java/io/company/localhost/mapper/localvacaMapper.java b/src/main/java/io/company/localhost/mapper/localvacaMapper.java index 7f034f1..6b4779e 100644 --- a/src/main/java/io/company/localhost/mapper/localvacaMapper.java +++ b/src/main/java/io/company/localhost/mapper/localvacaMapper.java @@ -13,6 +13,16 @@ public interface localvacaMapper { void insertVacation(MapDto map); List findVacations(@Param("year") int year, @Param("month") int month); + + List getUsedVacations(@Param("userId") Long userId); + + List getReceivedVacations(@Param("userId") Long userId); + + List getEmployeeRemainingVacation(); + + List getCommonCodeNames(); + + List countSentVacations(MapDto map); } diff --git a/src/main/java/io/company/localhost/service/localbordService.java b/src/main/java/io/company/localhost/service/localbordService.java index 97af85c..c691e28 100644 --- a/src/main/java/io/company/localhost/service/localbordService.java +++ b/src/main/java/io/company/localhost/service/localbordService.java @@ -110,8 +110,14 @@ public class localbordService { } } - public List getComments(MapDto map) { - return boardMapper.getComments(map); + public PageInfo getComments(MapDto map) { + int page = map.getString("page") != null ? Integer.parseInt(map.getString("page")) : 1; + int size = map.getString("size") != null ? Integer.parseInt(map.getString("size")) : 10; + PageHelper.startPage(page, size); + + List result = boardMapper.getComments(map); + + return PageUtil.redefineNavigation(new PageInfo<>(result, size)); } public void addCommentOrReply(MapDto map) { diff --git a/src/main/java/io/company/localhost/service/localvacaService.java b/src/main/java/io/company/localhost/service/localvacaService.java index b046348..39ebedd 100644 --- a/src/main/java/io/company/localhost/service/localvacaService.java +++ b/src/main/java/io/company/localhost/service/localvacaService.java @@ -2,14 +2,23 @@ package io.company.localhost.service; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import io.company.localhost.common.dto.MapDto; @@ -140,4 +149,97 @@ public class localvacaService { dto.put("name", item.get("dateName")); return dto; } + + /** + * 내 연차 사용 내역 조회 (사용한 연차 & 받은 연차) + */ + public Map> getUserVacationHistory(Long userId) { + List usedVacations = localvacaMapper.getUsedVacations(userId); + List receivedVacations = localvacaMapper.getReceivedVacations(userId); + + Map> history = new HashMap<>(); + history.put("usedVacations", usedVacations); + history.put("receivedVacations", receivedVacations); + + return history; + } + + /** + * 사원별 남은 연차 개수 조회 + */ + public List getEmployeeRemainingVacation() { + List employeeVacations = localvacaMapper.getEmployeeRemainingVacation(); + + return employeeVacations.stream().map(emp -> { + // 🔹 hireDate 변환 (포맷 정규화) + String hireDateString = emp.get("hireDate").toString().split("\\.")[0]; // .0 제거 + LocalDate hireDate; + + try { + if (hireDateString.contains("T")) { + hireDate = LocalDateTime.parse(hireDateString, DateTimeFormatter.ISO_LOCAL_DATE_TIME).toLocalDate(); + } else { + hireDate = LocalDate.parse(hireDateString, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + } + } catch (Exception e) { + throw new RuntimeException("🚨 입사일 변환 오류: " + hireDateString, e); + } + + // 🔹 총 연차 개수 계산 + int totalVacation = calculateTotalVacation(hireDate); + + // 🔹 사용한 연차 개수 처리 (null 방지) + double usedVacation = emp.get("used_quota") != null ? ((Number) emp.get("used_quota")).doubleValue() : 0.0; + + // 🔹 받은 연차 개수 처리 (null 방지) + double receivedVacation = emp.get("received_quota") != null ? ((Number) emp.get("received_quota")).doubleValue() : 0.0; + + // 🔹 남은 연차 개수 계산 (반차 포함) + double remainingVacation = totalVacation - usedVacation + receivedVacation; + + // 🔹 값 업데이트 + emp.put("totalQuota", totalVacation); + emp.put("remainingQuota", remainingVacation); + emp.put("usedQuota", usedVacation); + emp.put("receivedQuota", receivedVacation); + + return emp; + }).collect(Collectors.toList()); + } + + /** + * 총 연차 계산 로직 + */ + private int calculateTotalVacation(LocalDate hireDate) { + LocalDate today = LocalDate.now(); + int yearsWorked = hireDate.until(today).getYears(); + + // 🔹 1년 미만: 연간 12개 지급 + if (yearsWorked < 1) { + return 12; + } + + // 🔹 1년 이상 기본 15개 + int totalVacation = 15; + LocalDate nextIncreaseDate = hireDate.plusYears(2).withMonth(1).withDayOfMonth(1); + + // 🔹 2년마다 1개 추가 + while (nextIncreaseDate.isBefore(today) || nextIncreaseDate.isEqual(today)) { + totalVacation += 1; + nextIncreaseDate = nextIncreaseDate.plusYears(2); + } + + return totalVacation; + } + + public List getCommonCodeList() { + List codeList = localvacaMapper.getCommonCodeNames(); + + // 데이터가 비어있으면 빈 리스트 반환 (null 방지) + return (codeList != null) ? codeList : new ArrayList<>(); + } + + public List getSentVacationCount(MapDto map) { + return localvacaMapper.countSentVacations(map); + } } diff --git a/src/main/resources/mapper/localbordMapper.xml b/src/main/resources/mapper/localbordMapper.xml index fe7a59c..9785673 100644 --- a/src/main/resources/mapper/localbordMapper.xml +++ b/src/main/resources/mapper/localbordMapper.xml @@ -135,9 +135,11 @@ diff --git a/src/main/resources/mapper/localvacaMapper.xml b/src/main/resources/mapper/localvacaMapper.xml index a6728d8..2aceeee 100644 --- a/src/main/resources/mapper/localvacaMapper.xml +++ b/src/main/resources/mapper/localvacaMapper.xml @@ -4,8 +4,8 @@ - INSERT INTO localvaca (MEMBERSEQ, LOCVACUDT, LOCVACTYP, LOCVACRDT) - VALUES (#{employeeId}, #{date}, #{type}, NOW()) + INSERT INTO localvaca (MEMBERSEQ, LOCVACUDT, LOCVACTYP, LOCVACRDT, LOCVACRMM) + VALUES (#{employeeId}, #{date}, #{type}, NOW(), #{receiverId}) @@ -14,5 +14,104 @@ FROM localvaca WHERE DATE_FORMAT(LOCVACUDT, '%Y-%m') = CONCAT(#{year}, '-', LPAD(#{month}, 2, '0')) + + + + + + + + + + + + + + + \ No newline at end of file