게시판,휴가 수정

This commit is contained in:
dyhj625 2025-02-14 14:06:05 +09:00
parent e9c007d081
commit 9612b091ba
7 changed files with 196 additions and 9 deletions

View File

@ -172,7 +172,7 @@ public class BoardController {
@Member
@ParameterCheck
@GetMapping("/{boardId}/comments")
public ApiResponse<List<MapDto>> getComments(@ReqMap MapDto map) {
public ApiResponse<PageInfo<MapDto>> getComments(@ReqMap MapDto map) {
return ApiResponse.ok(boardService.getComments(map));
}

View File

@ -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<List<MapDto>> getRemainingVacation() {
List<MapDto> employeeVacations = localVacaService.getEmployeeRemainingVacation();
return ApiResponse.ok(employeeVacations);
}
@GetMapping("/codes")
public ApiResponse<List<MapDto>> getVacationCodeNames() {
return ApiResponse.ok(localVacaService.getCommonCodeList());
}
}

View File

@ -17,6 +17,10 @@ public interface localvacaMapper {
List<MapDto> getUsedVacations(@Param("userId") Long userId);
List<MapDto> getReceivedVacations(@Param("userId") Long userId);
List<MapDto> getEmployeeRemainingVacation();
List<MapDto> getCommonCodeNames();
}

View File

@ -110,8 +110,14 @@ public class localbordService {
}
}
public List<MapDto> getComments(MapDto map) {
return boardMapper.getComments(map);
public PageInfo<MapDto> 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<MapDto> result = boardMapper.getComments(map);
return PageUtil.redefineNavigation(new PageInfo<>(result, size));
}
public void addCommentOrReply(MapDto map) {

View File

@ -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<MapDto> getEmployeeRemainingVacation() {
List<MapDto> 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<MapDto> getCommonCodeList() {
List<MapDto> codeList = localvacaMapper.getCommonCodeNames();
// 데이터가 비어있으면 리스트 반환 (null 방지)
return (codeList != null) ? codeList : new ArrayList<>();
}
}

View File

@ -135,9 +135,11 @@
<!-- 댓글/대댓글 조회 -->
<select id="getComments" resultType="io.company.localhost.common.dto.MapDto">
SELECT
LOCCMTSEQ,LOCBRDSEQ,LOCCMTPNT,LOCCMTRPY,
LOCCMTUDT,LOCCMTPWD,LOCCMTRDT,LOCCMTPNT
FROM localcomt
c.LOCCMTSEQ,c.LOCBRDSEQ,c.LOCCMTPNT,c.LOCCMTRPY,
c.LOCCMTUDT,c.LOCCMTPWD,c.LOCCMTRDT,c.LOCCMTPNT,
m.MEMBERNAM AS author
FROM localcomt c
LEFT JOIN netmember m ON c.MEMBERSEQ = m.MEMBERSEQ
WHERE LOCBRDSEQ = #{LOCBRDSEQ}
ORDER BY LOCCMTPNT ASC, LOCCMTUDT ASC
</select>

View File

@ -4,8 +4,8 @@
<!-- 휴가 저장 -->
<insert id="insertVacation" parameterType="io.company.localhost.common.dto.MapDto">
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})
</insert>
<!-- 휴가 정보 조회 -->
@ -17,7 +17,13 @@
<!-- 사용자가 사용한 연차 목록 조회 -->
<select id="getUsedVacations" resultType="io.company.localhost.common.dto.MapDto">
SELECT LOCVACUDT AS date, LOCVACTYP AS type, COUNT(*) AS count, LOCVACRMM AS receiverId
SELECT LOCVACUDT AS date, LOCVACTYP AS type, COUNT(*) AS count, LOCVACRMM AS receiverId,
-- 반차(700101, 700102)는 0.5, 연차(700103)는 1로 계산
SUM(CASE
WHEN LOCVACTYP IN ('700101', '700102') THEN 0.5
WHEN LOCVACTYP = '700103' THEN 1
ELSE 0
END) AS used_quota
FROM localvaca
WHERE MEMBERSEQ = #{userId}
GROUP BY LOCVACUDT, LOCVACTYP, LOCVACRMM
@ -33,4 +39,75 @@
ORDER BY LOCVACUDT DESC
</select>
<!-- 전체 직원 남은 연차 조회 -->
<select id="getEmployeeRemainingVacation" resultType="io.company.localhost.common.dto.MapDto">
<![CDATA[
SELECT
nm.MEMBERSEQ AS employeeId,
nm.MEMBERNAM AS employeeName,
nm.MEMBERCDT AS hireDate,
-- 📌 총 연차 계산 (1년 미만: 12개, 이후 기본 15개 + 2년마다 1개 추가)
CASE
WHEN TIMESTAMPDIFF(MONTH, nm.MEMBERCDT, CURDATE()) < 12
THEN 12
ELSE
15 + FLOOR(TIMESTAMPDIFF(YEAR, nm.MEMBERCDT, CURDATE()) / 2)
END AS total_quota,
-- 📌 사용한 연차 개수 (반차 0.5, 연차 1)
COALESCE(lv.used_quota, 0) AS used_quota,
-- 📌 받은 연차 개수 (반차 0.5, 연차 1)
COALESCE(rv.received_quota, 0) AS received_quota,
-- 📌 남은 연차 계산 (총 연차 - 사용 연차 + 받은 연차)
(
CASE
WHEN TIMESTAMPDIFF(MONTH, nm.MEMBERCDT, CURDATE()) < 12
THEN 12
ELSE
15 + FLOOR(TIMESTAMPDIFF(YEAR, nm.MEMBERCDT, CURDATE()) / 2)
END
) - COALESCE(lv.used_quota, 0) + COALESCE(rv.received_quota, 0) AS remaining_quota
FROM netmember nm
-- 📌 사용한 연차 개수 가져오기 (반차는 0.5, 연차는 1로 변환)
LEFT JOIN (
SELECT MEMBERSEQ,
SUM(CASE
WHEN LOCVACTYP IN ('700101', '700102') THEN 0.5
WHEN LOCVACTYP = '700103' THEN 1
ELSE 0
END) AS used_quota
FROM localvaca
GROUP BY MEMBERSEQ
) lv ON nm.MEMBERSEQ = lv.MEMBERSEQ
-- 📌 받은 연차 개수 가져오기 (반차는 0.5, 연차는 1로 변환)
LEFT JOIN (
SELECT LOCVACRMM AS MEMBERSEQ,
SUM(CASE
WHEN LOCVACTYP IN ('700101', '700102') THEN 0.5
WHEN LOCVACTYP = '700103' THEN 1
ELSE 0
END) AS received_quota
FROM localvaca
WHERE LOCVACRMM IS NOT NULL
GROUP BY LOCVACRMM
) rv ON nm.MEMBERSEQ = rv.MEMBERSEQ
WHERE nm.MEMBERDEL = 'N' -- 퇴사자 제외
]]>
</select>
<!-- 공통 코드 목록 조회 -->
<select id="getCommonCodeNames" resultType="io.company.localhost.common.dto.MapDto">
SELECT CMNCODVAL AS code, CMNCODNAM AS name
FROM commoncod
WHERE CMNCODVAL IN ('700101', '700102', '700103')
</select>
</mapper>