This commit is contained in:
nevermoregb 2025-03-13 10:37:23 +09:00
commit c182f749b8
2 changed files with 33 additions and 11 deletions

View File

@ -13,6 +13,7 @@
* *
*************************************************************/ *************************************************************/
package io.company.localhost.controller.api; package io.company.localhost.controller.api;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -54,11 +55,12 @@ public class VacationController {
@PostMapping @PostMapping
public ApiResponse<?> insertVacations(@RequestBody List<MapDto> list) { public ApiResponse<?> insertVacations(@RequestBody List<MapDto> list) {
Long user = AuthUtil.getUser().getId(); Long user = AuthUtil.getUser().getId();
List<MapDto> savedVacations = new ArrayList<>();
for (MapDto request : list) { 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) { if (date == null || type == null) {
throw new IllegalArgumentException("요청 데이터에 누락된 값이 있습니다: " + request); throw new IllegalArgumentException("요청 데이터에 누락된 값이 있습니다: " + request);
@ -68,11 +70,21 @@ public class VacationController {
if (count == null || count < 1) { if (count == null || count < 1) {
count = 1; count = 1;
} }
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
localVacaService.insertVacation(request); MapDto vacationRequest = new MapDto();
vacationRequest.put("date", date);
vacationRequest.put("type", type);
vacationRequest.put("receiverId", receiverId);
vacationRequest.put("employeeId", user);
// 실제 저장
localVacaService.insertVacation(vacationRequest);
savedVacations.add(vacationRequest);
} }
} }
return ApiResponse.ok("모든 휴가가 성공적으로 저장되었습니다.");
return ApiResponse.ok(savedVacations);
} }
/** /**

View File

@ -39,15 +39,25 @@
<!-- 사용자가 받은 연차 목록 조회 --> <!-- 사용자가 받은 연차 목록 조회 -->
<select id="selectReceivedVacations" resultType="io.company.localhost.common.dto.MapDto"> <select id="selectReceivedVacations" resultType="io.company.localhost.common.dto.MapDto">
SELECT LOCVACUDT AS date, LOCVACTYP AS type, MEMBERSEQ AS senderId SELECT
LOCVACUDT AS date,
LOCVACTYP AS type,
MEMBERSEQ AS senderId,
-- 반차(700101, 700102)는 0.5, 연차(700103)는 1로 계산하여 받은 연차 수량 저장
SUM(
CASE
WHEN LOCVACTYP IN ('700101', '700102') THEN 0.5
WHEN LOCVACTYP = '700103' THEN 1
ELSE 0
END
) AS received_quota
FROM localvaca FROM localvaca
WHERE LOCVACRMM = #{userId} WHERE LOCVACRMM = #{userId} -- 현재 로그인한 사용자가 받은 연차
AND YEAR(LOCVACUDT) = #{year} AND YEAR(LOCVACUDT) = #{year} -- 해당 연도의 데이터만 가져옴
GROUP BY LOCVACUDT, LOCVACTYP, MEMBERSEQ GROUP BY LOCVACUDT, LOCVACTYP, MEMBERSEQ -- 연차를 보낸 사람별로 그룹화
ORDER BY LOCVACUDT DESC ORDER BY LOCVACUDT DESC;
</select> </select>
<!-- 전체 직원 남은 연차 조회 --> <!-- 전체 직원 남은 연차 조회 -->
<select id="selectEmployeeRemainingVacation" resultType="io.company.localhost.common.dto.MapDto"> <select id="selectEmployeeRemainingVacation" resultType="io.company.localhost.common.dto.MapDto">
<![CDATA[ <![CDATA[