휴가 수정

This commit is contained in:
dyhj625 2025-02-21 16:21:03 +09:00
parent 7e8f19d136
commit 873910358c
8 changed files with 114 additions and 85 deletions

View File

@ -29,11 +29,17 @@ import lombok.extern.slf4j.Slf4j;
public class VacationController { public class VacationController {
private final localvacaService localVacaService; private final localvacaService localVacaService;
private final commoncodService commonCodService;
/**
* 휴가 선물하기
* @ReqMap map 요청 파라미터 (LOCVACTYP, LOCVACRDT, LOCVACUDT, LOCVACRMM, MEMBERSEQ)
* @return 결과 메시지
*/
@Member @Member
@ParameterCheck @ParameterCheck
@PostMapping @PostMapping
public ApiResponse<?> saveVacations(@RequestBody List<MapDto> list) { public ApiResponse<?> insertVacations(@RequestBody List<MapDto> list) {
Long user = AuthUtil.getUser().getId(); Long user = AuthUtil.getUser().getId();
for (MapDto request : list) { for (MapDto request : list) {
String date = request.getString("date"); String date = request.getString("date");
@ -45,7 +51,6 @@ public class VacationController {
throw new IllegalArgumentException("요청 데이터에 누락된 값이 있습니다: " + request); throw new IllegalArgumentException("요청 데이터에 누락된 값이 있습니다: " + request);
} }
// count 필드가 있으면, 해당 값만큼 반복해서 insert
Integer count = request.getInt("count"); Integer count = request.getInt("count");
if (count == null || count < 1) { if (count == null || count < 1) {
count = 1; count = 1;
@ -56,11 +61,16 @@ public class VacationController {
} }
return ApiResponse.ok("모든 휴가가 성공적으로 저장되었습니다."); return ApiResponse.ok("모든 휴가가 성공적으로 저장되었습니다.");
} }
/**
* 휴가 저장/수정
* @ReqMap map 요청 파라미터 (LOCVACTYP, LOCVACRDT, LOCVACUDT, MEMBERSEQ / LOCVACSEQ)
* @return 결과 메시지
*/
@Member @Member
@ParameterCheck @ParameterCheck
@PostMapping("/batchUpdate") @PostMapping("/batchUpdate")
public ApiResponse<?> batchUpdateVacations(@ReqMap MapDto map) { public ApiResponse<?> saveVacations(@ReqMap MapDto map) {
Long user = AuthUtil.getUser().getId(); Long user = AuthUtil.getUser().getId();
List<MapDto> addRequests = map.getList("add", MapDto.class); List<MapDto> addRequests = map.getList("add", MapDto.class);
List<Long> deleteIds = map.getList("delete", Long.class); List<Long> deleteIds = map.getList("delete", Long.class);
@ -80,56 +90,73 @@ public class VacationController {
} }
/** /**
* 특정 연월에 대한 휴가 데이터 조회 * 전체 사원의 휴가 조회
* @param year, month
* @return 휴가 데이터 목록
*/ */
@Member @Member
@ParameterCheck @ParameterCheck
@GetMapping("/list/{year}/{month}") @GetMapping("/list/{year}/{month}")
public List<MapDto> getVacations(@PathVariable("year") int year, @PathVariable("month") int month) { public List<MapDto> selectVacations(@PathVariable("year") int year, @PathVariable("month") int month) {
return localVacaService.getVacationList(year, month); return localVacaService.selectVacationList(year, month);
} }
/** /**
* 특정 연월에 대한 공휴일 데이터 조회 * 공휴일 정보 조회
* @param year, month
* @return 공휴일 데이터 목록
*/ */
@Member @Member
@ParameterCheck @ParameterCheck
@GetMapping("/{year}/{month}") @GetMapping("/{year}/{month}")
public List<MapDto> getHolidays(@PathVariable("year") int year, @PathVariable("month") int month) { public List<MapDto> selectHolidays(@PathVariable("year") int year, @PathVariable("month") int month) {
return localVacaService.getHolidays(year, month); return localVacaService.selectHolidays(year, month);
} }
/** /**
* 연차 사용 내역 조회 * 로그인한 회원의 연차 사용 내역 조회
*/ */
@Member @Member
@ParameterCheck @ParameterCheck
@GetMapping("/history") @GetMapping("/history")
public ApiResponse<Map<String, List<MapDto>>> getUserVacationHistory() { public ApiResponse<Map<String, List<MapDto>>> selectUserVacationHistory() {
Long userId = AuthUtil.getUser().getId(); Long userId = AuthUtil.getUser().getId();
return ApiResponse.ok(localVacaService.getUserVacationHistory(userId)); return ApiResponse.ok(localVacaService.selectUserVacationHistory(userId));
} }
/**
* 사원별 남은 연차 개수 조회
*/
@Member
@ParameterCheck
@GetMapping("/remaining") @GetMapping("/remaining")
public ApiResponse<List<MapDto>> getRemainingVacation() { public ApiResponse<List<MapDto>> selectRemainingVacation() {
List<MapDto> employeeVacations = localVacaService.getEmployeeRemainingVacation(); List<MapDto> employeeVacations = localVacaService.selectEmployeeRemainingVacation();
return ApiResponse.ok(employeeVacations); return ApiResponse.ok(employeeVacations);
} }
/**
* 휴가 종류 조회(공통코드)
*/
@Member
@ParameterCheck
@GetMapping("/codes") @GetMapping("/codes")
public ApiResponse<List<MapDto>> getVacationCodeNames() { public ApiResponse<List<MapDto>> selectVacationType() {
return ApiResponse.ok(localVacaService.getCommonCodeList()); return ApiResponse.ok(commonCodService.selectVacationType());
} }
/**
* 사원 남은 보내기개수
* @ReqMap map 요청 파라미터 (LOCVACRMM, MEMBERSEQ)
* @return 남은 선물보내기 개수
*/
@Member
@ParameterCheck
@GetMapping("/sent") @GetMapping("/sent")
public ApiResponse<List<MapDto>> getSentVacations(@ReqMap MapDto map) { public ApiResponse<List<MapDto>> selectSentVacationCount(@ReqMap MapDto map) {
Long userId = AuthUtil.getUser().getId(); // 현재 로그인한 사용자 ID Long userId = AuthUtil.getUser().getId();
map.put("userId", userId); map.put("userId", userId);
List<MapDto> sentCount = localVacaService.getSentVacationCount(map); return ApiResponse.ok(localVacaService.selectSentVacationCount(map));
return ApiResponse.ok(sentCount);
} }
} }

View File

@ -15,6 +15,27 @@
*************************************************************/ *************************************************************/
package io.company.localhost.controller.common; package io.company.localhost.controller.common;
import static org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.security.authentication.RememberMeAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.context.SecurityContextHolderStrategy;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import io.company.localhost.common.annotation.Admin; import io.company.localhost.common.annotation.Admin;
import io.company.localhost.common.annotation.Guest; import io.company.localhost.common.annotation.Guest;
import io.company.localhost.common.annotation.Member; import io.company.localhost.common.annotation.Member;
@ -33,26 +54,6 @@ import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.RememberMeAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.context.SecurityContextHolderStrategy;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY;
@Slf4j @Slf4j
@RestController @RestController
@ -71,7 +72,7 @@ public class UserController {
*/ */
@ParameterCheck @ParameterCheck
@GetMapping("/color") @GetMapping("/color")
public ApiResponse<List<MapDto>> selectColorList(String type) { public ApiResponse<List<MapDto>> selectColorList(@RequestParam("type") String type) {
List<MapDto> ColorList = commoncodservice.selectColorList(type); List<MapDto> ColorList = commoncodservice.selectColorList(type);
return ApiResponse.ok(ColorList); return ApiResponse.ok(ColorList);
} }
@ -123,7 +124,7 @@ public class UserController {
* *
*/ */
@GetMapping("/checkId") @GetMapping("/checkId")
public ApiResponse<Boolean> selectCheckId(@RequestParam String memberIds) { public ApiResponse<Boolean> selectCheckId(@RequestParam("memberIds") String memberIds) {
boolean isDuplicate = netmemberservice.selectCheckId(memberIds); boolean isDuplicate = netmemberservice.selectCheckId(memberIds);
return ApiResponse.ok(!isDuplicate); return ApiResponse.ok(!isDuplicate);
} }

View File

@ -42,4 +42,6 @@ public interface commoncodMapper {
List<MapDto> selectCategories(); List<MapDto> selectCategories();
Long selectcheckCategoryExists(MapDto map); Long selectcheckCategoryExists(MapDto map);
List<MapDto> selectVacationType();
} }

View File

@ -14,17 +14,15 @@ public interface localvacaMapper {
void deleteVacation(Long vacationId); void deleteVacation(Long vacationId);
List<MapDto> findVacations(@Param("year") int year, @Param("month") int month); List<MapDto> selectVacations(@Param("year") int year, @Param("month") int month);
List<MapDto> getUsedVacations(@Param("userId") Long userId); List<MapDto> selectUsedVacations(@Param("userId") Long userId);
List<MapDto> getReceivedVacations(@Param("userId") Long userId); List<MapDto> selectReceivedVacations(@Param("userId") Long userId);
List<MapDto> getEmployeeRemainingVacation(); List<MapDto> selectEmployeeRemainingVacation();
List<MapDto> getCommonCodeNames(); List<MapDto> selectSentVacationCount(MapDto map);
List<MapDto> countSentVacations(MapDto map);
} }

View File

@ -14,6 +14,7 @@
*************************************************************/ *************************************************************/
package io.company.localhost.service; package io.company.localhost.service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -60,4 +61,11 @@ public class commoncodService {
public List<MapDto> selectCategoryList() { public List<MapDto> selectCategoryList() {
return commoncodmapper.selectCategories(); return commoncodmapper.selectCategories();
} }
public List<MapDto> selectVacationType() {
List<MapDto> codeList = commoncodmapper.selectVacationType();
// 데이터가 비어있으면 리스트 반환 (null 방지)
return (codeList != null) ? codeList : new ArrayList<>();
}
} }

View File

@ -43,14 +43,14 @@ public class localvacaService {
localvacaMapper.deleteVacation(vacationId); localvacaMapper.deleteVacation(vacationId);
} }
public List<MapDto> getVacationList(int year, int month) { public List<MapDto> selectVacationList(int year, int month) {
return localvacaMapper.findVacations(year, month); return localvacaMapper.selectVacations(year, month);
} }
/** /**
* 🔹 특정 연월에 대한 공휴일 데이터 조회 * 🔹 특정 연월에 대한 공휴일 데이터 조회
*/ */
public List<MapDto> getHolidays(int year, int month) { public List<MapDto> selectHolidays(int year, int month) {
// ServiceKey를 디코딩해서 사용 // ServiceKey를 디코딩해서 사용
String decodedServiceKey = URLDecoder.decode(serviceKey, StandardCharsets.UTF_8); String decodedServiceKey = URLDecoder.decode(serviceKey, StandardCharsets.UTF_8);
System.out.println("📌 디코딩된 ServiceKey: " + decodedServiceKey); System.out.println("📌 디코딩된 ServiceKey: " + decodedServiceKey);
@ -158,9 +158,9 @@ public class localvacaService {
/** /**
* 연차 사용 내역 조회 (사용한 연차 & 받은 연차) * 연차 사용 내역 조회 (사용한 연차 & 받은 연차)
*/ */
public Map<String, List<MapDto>> getUserVacationHistory(Long userId) { public Map<String, List<MapDto>> selectUserVacationHistory(Long userId) {
List<MapDto> usedVacations = localvacaMapper.getUsedVacations(userId); List<MapDto> usedVacations = localvacaMapper.selectUsedVacations(userId);
List<MapDto> receivedVacations = localvacaMapper.getReceivedVacations(userId); List<MapDto> receivedVacations = localvacaMapper.selectReceivedVacations(userId);
Map<String, List<MapDto>> history = new HashMap<>(); Map<String, List<MapDto>> history = new HashMap<>();
history.put("usedVacations", usedVacations); history.put("usedVacations", usedVacations);
@ -172,8 +172,8 @@ public class localvacaService {
/** /**
* 사원별 남은 연차 개수 조회 * 사원별 남은 연차 개수 조회
*/ */
public List<MapDto> getEmployeeRemainingVacation() { public List<MapDto> selectEmployeeRemainingVacation() {
List<MapDto> employeeVacations = localvacaMapper.getEmployeeRemainingVacation(); List<MapDto> employeeVacations = localvacaMapper.selectEmployeeRemainingVacation();
return employeeVacations.stream().map(emp -> { return employeeVacations.stream().map(emp -> {
// 🔹 hireDate 변환 (포맷 정규화) // 🔹 hireDate 변환 (포맷 정규화)
@ -191,7 +191,7 @@ public class localvacaService {
} }
// 🔹 연차 개수 계산 // 🔹 연차 개수 계산
int totalVacation = calculateTotalVacation(hireDate); int totalVacation = procCalculateTotalVacation(hireDate);
// 🔹 사용한 연차 개수 처리 (null 방지) // 🔹 사용한 연차 개수 처리 (null 방지)
double usedVacation = emp.get("used_quota") != null ? ((Number) emp.get("used_quota")).doubleValue() : 0.0; double usedVacation = emp.get("used_quota") != null ? ((Number) emp.get("used_quota")).doubleValue() : 0.0;
@ -215,7 +215,7 @@ public class localvacaService {
/** /**
* 연차 계산 로직 * 연차 계산 로직
*/ */
private int calculateTotalVacation(LocalDate hireDate) { private int procCalculateTotalVacation(LocalDate hireDate) {
LocalDate today = LocalDate.now(); LocalDate today = LocalDate.now();
int yearsWorked = hireDate.until(today).getYears(); int yearsWorked = hireDate.until(today).getYears();
@ -237,14 +237,7 @@ public class localvacaService {
return totalVacation; return totalVacation;
} }
public List<MapDto> getCommonCodeList() { public List<MapDto> selectSentVacationCount(MapDto map) {
List<MapDto> codeList = localvacaMapper.getCommonCodeNames(); return localvacaMapper.selectSentVacationCount(map);
// 데이터가 비어있으면 리스트 반환 (null 방지)
return (codeList != null) ? codeList : new ArrayList<>();
}
public List<MapDto> getSentVacationCount(MapDto map) {
return localvacaMapper.countSentVacations(map);
} }
} }

View File

@ -120,4 +120,11 @@
where where
CMNCODNAM = #{CMNCODNAM} CMNCODNAM = #{CMNCODNAM}
</select> </select>
<!-- 공통 코드 목록 조회 -->
<select id="selectVacationType" resultType="io.company.localhost.common.dto.MapDto">
SELECT CMNCODVAL AS code, CMNCODNAM AS name
FROM commoncod
WHERE CMNCODVAL IN ('700101', '700102', '700103')
</select>
</mapper> </mapper>

View File

@ -15,14 +15,14 @@
</delete> </delete>
<!-- 휴가 정보 조회 --> <!-- 휴가 정보 조회 -->
<select id="findVacations" parameterType="map" resultType="io.company.localhost.common.dto.MapDto"> <select id="selectVacations" parameterType="map" resultType="io.company.localhost.common.dto.MapDto">
SELECT LOCVACSEQ, MEMBERSEQ, LOCVACUDT, LOCVACTYP, LOCVACRMM SELECT LOCVACSEQ, MEMBERSEQ, LOCVACUDT, LOCVACTYP, LOCVACRMM
FROM localvaca FROM localvaca
WHERE DATE_FORMAT(LOCVACUDT, '%Y-%m') = CONCAT(#{year}, '-', LPAD(#{month}, 2, '0')) WHERE DATE_FORMAT(LOCVACUDT, '%Y-%m') = CONCAT(#{year}, '-', LPAD(#{month}, 2, '0'))
</select> </select>
<!-- 사용자가 사용한 연차 목록 조회 --> <!-- 사용자가 사용한 연차 목록 조회 -->
<select id="getUsedVacations" resultType="io.company.localhost.common.dto.MapDto"> <select id="selectUsedVacations" resultType="io.company.localhost.common.dto.MapDto">
SELECT LOCVACUDT AS date, LOCVACTYP AS type, LOCVACRMM AS receiverId, SELECT LOCVACUDT AS date, LOCVACTYP AS type, LOCVACRMM AS receiverId,
-- 반차(700101, 700102)는 0.5, 연차(700103)는 1로 계산 -- 반차(700101, 700102)는 0.5, 연차(700103)는 1로 계산
SUM(CASE SUM(CASE
@ -38,7 +38,7 @@
</select> </select>
<!-- 사용자가 받은 연차 목록 조회 --> <!-- 사용자가 받은 연차 목록 조회 -->
<select id="getReceivedVacations" resultType="io.company.localhost.common.dto.MapDto"> <select id="selectReceivedVacations" resultType="io.company.localhost.common.dto.MapDto">
SELECT LOCVACUDT AS date, LOCVACTYP AS type, MEMBERSEQ AS senderId SELECT LOCVACUDT AS date, LOCVACTYP AS type, MEMBERSEQ AS senderId
FROM localvaca FROM localvaca
WHERE LOCVACRMM = #{userId} WHERE LOCVACRMM = #{userId}
@ -49,7 +49,7 @@
<!-- 전체 직원 남은 연차 조회 --> <!-- 전체 직원 남은 연차 조회 -->
<select id="getEmployeeRemainingVacation" resultType="io.company.localhost.common.dto.MapDto"> <select id="selectEmployeeRemainingVacation" resultType="io.company.localhost.common.dto.MapDto">
<![CDATA[ <![CDATA[
SELECT SELECT
nm.MEMBERSEQ AS employeeId, nm.MEMBERSEQ AS employeeId,
@ -111,14 +111,7 @@
]]> ]]>
</select> </select>
<!-- 공통 코드 목록 조회 --> <select id="selectSentVacationCount" resultType="io.company.localhost.common.dto.MapDto">
<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>
<select id="countSentVacations" resultType="io.company.localhost.common.dto.MapDto">
SELECT COUNT(*) as count FROM localvaca WHERE MEMBERSEQ = #{userId} AND LOCVACRMM = #{receiverId} SELECT COUNT(*) as count FROM localvaca WHERE MEMBERSEQ = #{userId} AND LOCVACRMM = #{receiverId}
</select> </select>