176 lines
6.0 KiB
Java
176 lines
6.0 KiB
Java
/************************************************************
|
|
*
|
|
* @packageName : io.company.localhost.controller.api
|
|
* @fileName : VacationController.java
|
|
* @author : 서지희
|
|
* @date : 25.02.06
|
|
* @description : 게시판
|
|
*
|
|
* ===========================================================
|
|
* DATE AUTHOR NOTE
|
|
* -----------------------------------------------------------
|
|
* 25.02.06 서지희 최초 생성
|
|
*
|
|
*************************************************************/
|
|
package io.company.localhost.controller.api;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
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;
|
|
|
|
@Slf4j
|
|
@RequiredArgsConstructor
|
|
@RestController
|
|
@RequestMapping("/api/vacation")
|
|
public class VacationController {
|
|
|
|
private final localvacaService localVacaService;
|
|
private final commoncodService commonCodService;
|
|
|
|
/**
|
|
* 휴가 선물하기
|
|
* @ReqMap map 요청 파라미터 (LOCVACTYP, LOCVACRDT, LOCVACUDT, LOCVACRMM, MEMBERSEQ)
|
|
* @return 결과 메시지
|
|
*/
|
|
@Member
|
|
@ParameterCheck
|
|
@PostMapping
|
|
public ApiResponse<?> insertVacations(@RequestBody List<MapDto> list) {
|
|
Long user = AuthUtil.getUser().getId();
|
|
for (MapDto request : list) {
|
|
String date = request.getString("date");
|
|
String type = request.getString("type");
|
|
Object receiverId = request.get("receiverId");
|
|
request.put("employeeId", user);
|
|
|
|
if (date == null || type == null) {
|
|
throw new IllegalArgumentException("요청 데이터에 누락된 값이 있습니다: " + request);
|
|
}
|
|
|
|
Integer count = request.getInt("count");
|
|
if (count == null || count < 1) {
|
|
count = 1;
|
|
}
|
|
for (int i = 0; i < count; i++) {
|
|
localVacaService.insertVacation(request);
|
|
}
|
|
}
|
|
return ApiResponse.ok("모든 휴가가 성공적으로 저장되었습니다.");
|
|
}
|
|
|
|
/**
|
|
* 휴가 저장/수정
|
|
* @ReqMap map 요청 파라미터 (LOCVACTYP, LOCVACRDT, LOCVACUDT, MEMBERSEQ / LOCVACSEQ)
|
|
* @return 결과 메시지
|
|
*/
|
|
@Member
|
|
@ParameterCheck
|
|
@PostMapping("/batchUpdate")
|
|
public ApiResponse<?> saveVacations(@ReqMap MapDto map) {
|
|
Long user = AuthUtil.getUser().getId();
|
|
List<MapDto> addRequests = map.getList("add", MapDto.class);
|
|
List<Long> deleteIds = map.getList("delete", Long.class);
|
|
|
|
if (addRequests != null) {
|
|
for (MapDto addRequest : addRequests) {
|
|
addRequest.put("employeeId", user);
|
|
localVacaService.insertVacation(addRequest);
|
|
}
|
|
}
|
|
if (deleteIds != null) {
|
|
for (Long deleteId : deleteIds) {
|
|
localVacaService.deleteVacation(deleteId);
|
|
}
|
|
}
|
|
return ApiResponse.ok("휴가 변경이 성공적으로 처리되었습니다.");
|
|
}
|
|
|
|
/**
|
|
* 전체 사원의 휴가 조회
|
|
* @param year, month
|
|
* @return 휴가 데이터 목록
|
|
*/
|
|
@Member
|
|
@ParameterCheck
|
|
@GetMapping("/list/{year}/{month}")
|
|
public List<MapDto> selectVacations(@PathVariable("year") int year, @PathVariable("month") int month) {
|
|
return localVacaService.selectVacationList(year, month);
|
|
}
|
|
|
|
/**
|
|
* 공휴일 정보 조회
|
|
* @param year, month
|
|
* @return 공휴일 데이터 목록
|
|
*/
|
|
@Member
|
|
@ParameterCheck
|
|
@GetMapping("/{year}/{month}")
|
|
public List<MapDto> selectHolidays(@PathVariable("year") int year, @PathVariable("month") int month) {
|
|
return localVacaService.selectHolidays(year, month);
|
|
}
|
|
|
|
/**
|
|
* 로그인한 회원의 연차 사용 내역 조회
|
|
*/
|
|
@Member
|
|
@ParameterCheck
|
|
@GetMapping("/history")
|
|
public ApiResponse<Map<String, List<MapDto>>> selectUserVacationHistory(@RequestParam("year") int year) {
|
|
Long userId = AuthUtil.getUser().getId();
|
|
return ApiResponse.ok(localVacaService.selectUserVacationHistory(userId, year));
|
|
}
|
|
|
|
/**
|
|
* 사원별 남은 연차 개수 조회
|
|
*/
|
|
@Member
|
|
@ParameterCheck
|
|
@GetMapping("/remaining")
|
|
public ApiResponse<List<MapDto>> selectRemainingVacation() {
|
|
List<MapDto> employeeVacations = localVacaService.selectEmployeeRemainingVacation();
|
|
return ApiResponse.ok(employeeVacations);
|
|
}
|
|
|
|
/**
|
|
* 휴가 종류 조회(공통코드)
|
|
*/
|
|
@Member
|
|
@ParameterCheck
|
|
@GetMapping("/codes")
|
|
public ApiResponse<List<MapDto>> selectVacationType() {
|
|
return ApiResponse.ok(commonCodService.selectVacationType());
|
|
}
|
|
|
|
/**
|
|
* 사원 별 남은 보내기개수
|
|
* @ReqMap map 요청 파라미터 (LOCVACRMM, MEMBERSEQ)
|
|
* @return 남은 선물보내기 개수
|
|
*/
|
|
@Member
|
|
@ParameterCheck
|
|
@GetMapping("/sent")
|
|
public ApiResponse<List<MapDto>> selectSentVacationCount(@ReqMap MapDto map) {
|
|
Long userId = AuthUtil.getUser().getId();
|
|
map.put("userId", userId);
|
|
return ApiResponse.ok(localVacaService.selectSentVacationCount(map));
|
|
}
|
|
|
|
}
|