휴가 저장로직 수정

This commit is contained in:
dyhj625 2025-03-19 17:45:46 +09:00
parent ea50617980
commit 42bb0dd244
4 changed files with 70 additions and 16 deletions

View File

@ -100,20 +100,23 @@ public class VacationController {
List<MapDto> addRequests = map.getList("add", MapDto.class);
List<Long> deleteIds = map.getList("delete", Long.class);
if (addRequests != null) {
// 1 삭제 먼저 처리
if (deleteIds != null && !deleteIds.isEmpty()) {
localVacaService.deleteVacation(deleteIds);
}
// 2 추가 또는 업데이트 처리
if (addRequests != null && !addRequests.isEmpty()) {
for (MapDto addRequest : addRequests) {
addRequest.put("employeeId", user);
localVacaService.insertVacation(addRequest);
}
}
if (deleteIds != null) {
for (Long deleteId : deleteIds) {
localVacaService.deleteVacation(deleteId);
localVacaService.upsertVacation(addRequest);
}
}
return ApiResponse.ok("휴가 변경이 성공적으로 처리되었습니다.");
}
/**
* 전체 사원의 휴가 조회
* @param year, month

View File

@ -26,7 +26,7 @@ import io.company.localhost.common.dto.MapDto;
public interface localvacaMapper {
void insertVacation(MapDto map);
void deleteVacation(Long vacationId);
void deleteVacation(@Param("vacationIds") List<Long> vacationIds);
List<MapDto> selectVacations(@Param("year") int year, @Param("month") int month);
@ -37,6 +37,10 @@ public interface localvacaMapper {
List<MapDto> selectEmployeeRemainingVacation();
List<MapDto> selectSentVacationCount(MapDto map);
Long findVacationIdByDate(@Param("userId") Long employeeId, @Param("date") String date);
void updateVacation(MapDto vacation);
}

View File

@ -34,6 +34,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import io.company.localhost.common.dto.MapDto;
import io.company.localhost.mapper.localvacaMapper;
@ -53,9 +54,38 @@ public class localvacaService {
localvacaMapper.insertVacation(vacation);
}
public void deleteVacation(Long vacationId) {
localvacaMapper.deleteVacation(vacationId);
/**
* 여러 개의 휴가를 삭제
*/
@Transactional
public void deleteVacation(List<Long> vacationIds) {
if (vacationIds != null && !vacationIds.isEmpty()) {
localvacaMapper.deleteVacation(vacationIds);
}
}
/**
* 휴가 추가 또는 업데이트 (중복 검사 처리)
*/
@Transactional
public void upsertVacation(MapDto vacation) {
String date = vacation.getString("date");
Long employeeId = vacation.getLong("employeeId");
// 기존 데이터 확인
Long existingId = localvacaMapper.findVacationIdByDate(employeeId, date);
if (existingId != null) {
// 기존 휴가가 존재하면 업데이트
vacation.put("id", existingId);
localvacaMapper.updateVacation(vacation);
} else {
System.out.println(vacation);
// 기존 휴가가 없으면 새롭게 추가
localvacaMapper.insertVacation(vacation);
}
}
public List<MapDto> selectVacationList(int year, int month) {
return localvacaMapper.selectVacations(year, month);

View File

@ -8,10 +8,27 @@
VALUES (#{employeeId}, #{date}, #{type}, NOW(), #{receiverId})
</insert>
<!-- 휴가 데이터 삭제 -->
<delete id="deleteVacation" parameterType="long">
<!-- 특정 날짜의 휴가 ID 조회 (존재 여부 확인) -->
<select id="findVacationIdByDate" resultType="Long">
SELECT LOCVACSEQ
FROM localvaca
WHERE MEMBERSEQ = #{userId} AND LOCVACUDT = #{date}
</select>
<!-- 휴가 수정 (기존 데이터가 존재하는 경우) -->
<update id="updateVacation">
UPDATE localvaca
SET LOCVACTYP = #{type}
WHERE LOCVACSEQ = #{id}
</update>
<!-- ✅ 여러 개의 휴가 삭제 -->
<delete id="deleteVacation">
DELETE FROM localvaca
WHERE LOCVACSEQ = #{vacationId}
WHERE LOCVACSEQ IN
<foreach item="id" collection="vacationIds" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<!-- 휴가 정보 조회 -->