휴가 수정
This commit is contained in:
parent
ab66477be2
commit
e2ef67a3d9
@ -20,7 +20,11 @@ import org.springframework.util.ObjectUtils;
|
||||
import java.io.Serial;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MapDto extends ListOrderedMap {
|
||||
|
||||
@ -75,5 +79,31 @@ public class MapDto extends ListOrderedMap {
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T> List<T> getList(String key, Class<T> clazz) {
|
||||
Object value = this.get(key);
|
||||
if (value == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (!(value instanceof List<?>)) {
|
||||
throw new IllegalArgumentException("Value for key " + key + " is not a List");
|
||||
}
|
||||
List<?> list = (List<?>) value;
|
||||
List<T> result = new ArrayList<>();
|
||||
for (Object item : list) {
|
||||
if (item == null) {
|
||||
continue; // null인 항목은 건너뜁니다.
|
||||
}
|
||||
if (clazz.isInstance(item)) {
|
||||
result.add(clazz.cast(item));
|
||||
} else if (clazz.equals(Long.class) && item instanceof Integer) {
|
||||
result.add(clazz.cast(Long.valueOf((Integer) item)));
|
||||
} else if (item instanceof Map && clazz.equals(MapDto.class)) {
|
||||
result.add(clazz.cast(new MapDto((Map<String, Object>) item)));
|
||||
} else {
|
||||
throw new ClassCastException("Cannot cast " + item.getClass() + " to " + clazz);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -33,22 +33,50 @@ public class VacationController {
|
||||
@Member
|
||||
@ParameterCheck
|
||||
@PostMapping
|
||||
public ApiResponse<?> saveVacations(@RequestBody List<MapDto> map) {
|
||||
Long user = AuthUtil.getUser().getId();
|
||||
for (MapDto request : map) {
|
||||
String date = request.getString("date");
|
||||
String type = request.getString("type");
|
||||
Object receiverId = request.get("receiverId");
|
||||
public ApiResponse<?> saveVacations(@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);
|
||||
if (date == null || type == null) {
|
||||
throw new IllegalArgumentException("요청 데이터에 누락된 값이 있습니다: " + request);
|
||||
}
|
||||
|
||||
// count 필드가 있으면, 해당 값만큼 반복해서 insert
|
||||
Integer count = request.getInt("count");
|
||||
if (count == null || count < 1) {
|
||||
count = 1;
|
||||
}
|
||||
for (int i = 0; i < count; i++) {
|
||||
localVacaService.insertVacation(request);
|
||||
}
|
||||
}
|
||||
request.put("employeeId", user);
|
||||
// 데이터 저장
|
||||
localVacaService.insertVacation(request);
|
||||
return ApiResponse.ok("모든 휴가가 성공적으로 저장되었습니다.");
|
||||
}
|
||||
|
||||
return ApiResponse.ok("모든 휴가가 성공적으로 저장되었습니다.");
|
||||
@Member
|
||||
@ParameterCheck
|
||||
@PostMapping("/batchUpdate")
|
||||
public ApiResponse<?> batchUpdateVacations(@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("휴가 변경이 성공적으로 처리되었습니다.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -12,6 +12,8 @@ import io.company.localhost.common.dto.MapDto;
|
||||
public interface localvacaMapper {
|
||||
void insertVacation(MapDto map);
|
||||
|
||||
void deleteVacation(Long vacationId);
|
||||
|
||||
List<MapDto> findVacations(@Param("year") int year, @Param("month") int month);
|
||||
|
||||
List<MapDto> getUsedVacations(@Param("userId") Long userId);
|
||||
|
||||
@ -34,8 +34,13 @@ public class localvacaService {
|
||||
@Value("${api.public-holiday.key}")
|
||||
private String serviceKey;
|
||||
|
||||
public void insertVacation(MapDto map) {
|
||||
localvacaMapper.insertVacation(map);
|
||||
public void insertVacation(MapDto vacation) {
|
||||
// 필요한 경우 데이터 검증/전처리 후 매퍼 호출
|
||||
localvacaMapper.insertVacation(vacation);
|
||||
}
|
||||
|
||||
public void deleteVacation(Long vacationId) {
|
||||
localvacaMapper.deleteVacation(vacationId);
|
||||
}
|
||||
|
||||
public List<MapDto> getVacationList(int year, int month) {
|
||||
|
||||
@ -8,9 +8,15 @@
|
||||
VALUES (#{employeeId}, #{date}, #{type}, NOW(), #{receiverId})
|
||||
</insert>
|
||||
|
||||
<!-- 휴가 데이터 삭제 -->
|
||||
<delete id="deleteVacation" parameterType="long">
|
||||
DELETE FROM localvaca
|
||||
WHERE LOCVACSEQ = #{vacationId}
|
||||
</delete>
|
||||
|
||||
<!-- 휴가 정보 조회 -->
|
||||
<select id="findVacations" parameterType="map" resultType="io.company.localhost.common.dto.MapDto">
|
||||
SELECT MEMBERSEQ, LOCVACUDT, LOCVACTYP, LOCVACRMM
|
||||
SELECT LOCVACSEQ, MEMBERSEQ, LOCVACUDT, LOCVACTYP, LOCVACRMM
|
||||
FROM localvaca
|
||||
WHERE DATE_FORMAT(LOCVACUDT, '%Y-%m') = CONCAT(#{year}, '-', LPAD(#{month}, 2, '0'))
|
||||
</select>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user