휴가 저장로직 수정
This commit is contained in:
parent
ea50617980
commit
42bb0dd244
@ -99,20 +99,23 @@ public class VacationController {
|
|||||||
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);
|
||||||
|
|
||||||
if (addRequests != null) {
|
// 1️⃣ 삭제 먼저 처리
|
||||||
|
if (deleteIds != null && !deleteIds.isEmpty()) {
|
||||||
|
localVacaService.deleteVacation(deleteIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2️⃣ 추가 또는 업데이트 처리
|
||||||
|
if (addRequests != null && !addRequests.isEmpty()) {
|
||||||
for (MapDto addRequest : addRequests) {
|
for (MapDto addRequest : addRequests) {
|
||||||
addRequest.put("employeeId", user);
|
addRequest.put("employeeId", user);
|
||||||
localVacaService.insertVacation(addRequest);
|
localVacaService.upsertVacation(addRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (deleteIds != null) {
|
|
||||||
for (Long deleteId : deleteIds) {
|
|
||||||
localVacaService.deleteVacation(deleteId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ApiResponse.ok("휴가 변경이 성공적으로 처리되었습니다.");
|
return ApiResponse.ok("휴가 변경이 성공적으로 처리되었습니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 전체 사원의 휴가 조회
|
* 전체 사원의 휴가 조회
|
||||||
|
|||||||
@ -25,8 +25,8 @@ import io.company.localhost.common.dto.MapDto;
|
|||||||
@Mapper
|
@Mapper
|
||||||
public interface localvacaMapper {
|
public interface localvacaMapper {
|
||||||
void insertVacation(MapDto map);
|
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);
|
List<MapDto> selectVacations(@Param("year") int year, @Param("month") int month);
|
||||||
|
|
||||||
@ -37,6 +37,10 @@ public interface localvacaMapper {
|
|||||||
List<MapDto> selectEmployeeRemainingVacation();
|
List<MapDto> selectEmployeeRemainingVacation();
|
||||||
|
|
||||||
List<MapDto> selectSentVacationCount(MapDto map);
|
List<MapDto> selectSentVacationCount(MapDto map);
|
||||||
|
|
||||||
|
Long findVacationIdByDate(@Param("userId") Long employeeId, @Param("date") String date);
|
||||||
|
|
||||||
|
void updateVacation(MapDto vacation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -34,6 +34,7 @@ import org.springframework.http.HttpMethod;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import io.company.localhost.common.dto.MapDto;
|
import io.company.localhost.common.dto.MapDto;
|
||||||
import io.company.localhost.mapper.localvacaMapper;
|
import io.company.localhost.mapper.localvacaMapper;
|
||||||
@ -53,10 +54,39 @@ public class localvacaService {
|
|||||||
localvacaMapper.insertVacation(vacation);
|
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) {
|
public List<MapDto> selectVacationList(int year, int month) {
|
||||||
return localvacaMapper.selectVacations(year, month);
|
return localvacaMapper.selectVacations(year, month);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,10 +8,27 @@
|
|||||||
VALUES (#{employeeId}, #{date}, #{type}, NOW(), #{receiverId})
|
VALUES (#{employeeId}, #{date}, #{type}, NOW(), #{receiverId})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<!-- 휴가 데이터 삭제 -->
|
<!-- 특정 날짜의 휴가 ID 조회 (존재 여부 확인) -->
|
||||||
<delete id="deleteVacation" parameterType="long">
|
<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
|
DELETE FROM localvaca
|
||||||
WHERE LOCVACSEQ = #{vacationId}
|
WHERE LOCVACSEQ IN
|
||||||
|
<foreach item="id" collection="vacationIds" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<!-- 휴가 정보 조회 -->
|
<!-- 휴가 정보 조회 -->
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user