휴가 수정
This commit is contained in:
parent
ab66477be2
commit
e2ef67a3d9
@ -20,7 +20,11 @@ import org.springframework.util.ObjectUtils;
|
|||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class MapDto extends ListOrderedMap {
|
public class MapDto extends ListOrderedMap {
|
||||||
|
|
||||||
@ -74,6 +78,32 @@ public class MapDto extends ListOrderedMap {
|
|||||||
}
|
}
|
||||||
return null;
|
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,24 +33,52 @@ public class VacationController {
|
|||||||
@Member
|
@Member
|
||||||
@ParameterCheck
|
@ParameterCheck
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public ApiResponse<?> saveVacations(@RequestBody List<MapDto> map) {
|
public ApiResponse<?> saveVacations(@RequestBody List<MapDto> list) {
|
||||||
Long user = AuthUtil.getUser().getId();
|
Long user = AuthUtil.getUser().getId();
|
||||||
for (MapDto request : map) {
|
for (MapDto request : list) {
|
||||||
String date = request.getString("date");
|
String date = request.getString("date");
|
||||||
String type = request.getString("type");
|
String type = request.getString("type");
|
||||||
Object receiverId = request.get("receiverId");
|
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);
|
return ApiResponse.ok("모든 휴가가 성공적으로 저장되었습니다.");
|
||||||
// 데이터 저장
|
|
||||||
localVacaService.insertVacation(request);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
public interface localvacaMapper {
|
||||||
void insertVacation(MapDto map);
|
void insertVacation(MapDto map);
|
||||||
|
|
||||||
|
void deleteVacation(Long vacationId);
|
||||||
|
|
||||||
List<MapDto> findVacations(@Param("year") int year, @Param("month") int month);
|
List<MapDto> findVacations(@Param("year") int year, @Param("month") int month);
|
||||||
|
|
||||||
List<MapDto> getUsedVacations(@Param("userId") Long userId);
|
List<MapDto> getUsedVacations(@Param("userId") Long userId);
|
||||||
|
|||||||
@ -34,8 +34,13 @@ public class localvacaService {
|
|||||||
@Value("${api.public-holiday.key}")
|
@Value("${api.public-holiday.key}")
|
||||||
private String serviceKey;
|
private String serviceKey;
|
||||||
|
|
||||||
public void insertVacation(MapDto map) {
|
public void insertVacation(MapDto vacation) {
|
||||||
localvacaMapper.insertVacation(map);
|
// 필요한 경우 데이터 검증/전처리 후 매퍼 호출
|
||||||
|
localvacaMapper.insertVacation(vacation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteVacation(Long vacationId) {
|
||||||
|
localvacaMapper.deleteVacation(vacationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MapDto> getVacationList(int year, int month) {
|
public List<MapDto> getVacationList(int year, int month) {
|
||||||
|
|||||||
@ -8,9 +8,15 @@
|
|||||||
VALUES (#{employeeId}, #{date}, #{type}, NOW(), #{receiverId})
|
VALUES (#{employeeId}, #{date}, #{type}, NOW(), #{receiverId})
|
||||||
</insert>
|
</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 id="findVacations" parameterType="map" resultType="io.company.localhost.common.dto.MapDto">
|
||||||
SELECT 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>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user