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 7368d47..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,7 +172,7 @@ 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)); } 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 5aa7af6..bd259fe 100644 --- a/src/main/java/io/company/localhost/controller/api/VacationController.java +++ b/src/main/java/io/company/localhost/controller/api/VacationController.java @@ -1,4 +1,6 @@ package io.company.localhost.controller.api; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; import java.util.List; import java.util.Map; @@ -78,4 +80,17 @@ public class VacationController { 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()); + } + } diff --git a/src/main/java/io/company/localhost/mapper/localvacaMapper.java b/src/main/java/io/company/localhost/mapper/localvacaMapper.java index e094214..ee3d883 100644 --- a/src/main/java/io/company/localhost/mapper/localvacaMapper.java +++ b/src/main/java/io/company/localhost/mapper/localvacaMapper.java @@ -17,6 +17,10 @@ public interface localvacaMapper { List getUsedVacations(@Param("userId") Long userId); List getReceivedVacations(@Param("userId") Long userId); + + List getEmployeeRemainingVacation(); + + List getCommonCodeNames(); } 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 d51d859..b8c0dfc 100644 --- a/src/main/java/io/company/localhost/service/localvacaService.java +++ b/src/main/java/io/company/localhost/service/localvacaService.java @@ -2,15 +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; @@ -155,4 +163,79 @@ public class localvacaService { 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<>(); + } } 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 944cc46..c75ba51 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}) @@ -17,7 +17,13 @@ + + + + + + + \ No newline at end of file