Skip to content

Commit

Permalink
Merge pull request #215 from IT-Cotato/release
Browse files Browse the repository at this point in the history
[Main] V2.2024.11.22.02
  • Loading branch information
Youthhing authored Nov 22, 2024
2 parents fe81b68 + df146b8 commit 4949c96
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
@Getter
@AllArgsConstructor
public enum AttendanceResult {
PRESENT("출석", "출석", true), // Todo https://youthing.atlassian.net/jira/software/projects/COT/boards/2?selectedIssue=COT-64&sprints=3
ONLINE("대면 출석", "대면으로 출석했습니다.", true),
OFFLINE("비대면 출석", "비대면으로 출석했습니다.", true),
LATE("지각", "기준 시간을 지나 지각 처리 되었습니다.", false),
Expand All @@ -16,4 +15,16 @@ public enum AttendanceResult {
private final String description;
private final String message;
private final boolean isPresented;

public static AttendanceResult getAttendanceResult(AttendanceType attendanceType) {
switch (attendanceType) {
case ONLINE -> {
return ONLINE;
}
case OFFLINE -> {
return OFFLINE;
}
}
return ABSENT;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.cotato.csquiz.domain.attendance.service;

import java.time.LocalDateTime;
import org.cotato.csquiz.api.attendance.dto.AttendResponse;
import org.cotato.csquiz.api.attendance.dto.AttendanceParams;
import org.cotato.csquiz.domain.attendance.entity.Attendance;
import org.cotato.csquiz.domain.attendance.enums.AttendanceType;
import org.cotato.csquiz.domain.generation.entity.Session;

public interface AttendClient {
AttendanceType attendanceType();

AttendResponse request(AttendanceParams params, LocalDateTime sessionStartTime, Long memberId, Attendance attendance);
AttendResponse request(AttendanceParams params, Session session, Long memberId, Attendance attendance);
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void updateAttendance(Session attendanceSession, Attendance attendance,
attendanceDeadLine.lateDeadLine());
attendance.updateLocation(location);

attendanceRecordService.updateAttendanceStatus(attendanceSession.getSessionDateTime(), attendance);
attendanceRecordService.updateAttendanceStatus(attendanceSession, attendance);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public AttendResponse submitRecord(AttendanceParams request, final Long memberId
throw new AppException(ErrorCode.ALREADY_ATTEND);
}

return requestAttendanceService.attend(request, session.getSessionDateTime(), memberId, attendance);
return requestAttendanceService.attend(request, session, memberId, attendance);
}

private void checkIsGenerationMember(Member member, Generation generation) {
Expand Down Expand Up @@ -146,12 +146,12 @@ public MemberAttendanceRecordsResponse findAllRecordsBy(final Long generationId,
}

@Transactional
public void updateAttendanceStatus(LocalDateTime sessionStartTime, Attendance attendance) {
public void updateAttendanceStatus(Session session, Attendance attendance) {
List<AttendanceRecord> attendanceRecords = attendanceRecordRepository.findAllByAttendanceId(attendance.getId());

for (AttendanceRecord attendanceRecord : attendanceRecords) {
AttendanceResult attendanceResult = AttendanceUtil.calculateAttendanceStatus(sessionStartTime, attendance,
attendanceRecord.getAttendTime());
AttendanceResult attendanceResult = AttendanceUtil.calculateAttendanceStatus(session, attendance,
attendanceRecord.getAttendTime(), attendanceRecord.getAttendanceType());
attendanceRecord.updateAttendanceResult(attendanceResult);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.cotato.csquiz.domain.attendance.enums.AttendanceType;
import org.cotato.csquiz.domain.attendance.repository.AttendanceRecordRepository;
import org.cotato.csquiz.domain.attendance.util.AttendanceUtil;
import org.cotato.csquiz.domain.generation.entity.Session;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

Expand All @@ -32,10 +33,10 @@ public AttendanceType attendanceType() {
}

@Override
public AttendResponse request(AttendanceParams params, LocalDateTime sessionStartTime, Long memberId, Attendance attendance) {
public AttendResponse request(AttendanceParams params, Session session, Long memberId, Attendance attendance) {
OfflineAttendanceRequest request = (OfflineAttendanceRequest) params;

AttendanceResult attendanceResult = AttendanceUtil.calculateAttendanceStatus(sessionStartTime, attendance, params.requestTime());
AttendanceResult attendanceResult = AttendanceUtil.calculateAttendanceStatus(session, attendance, params.requestTime(),attendanceType());

log.info("[출결 위치 로그: 위도 {}, 경도 {}]", request.getLocation().getLatitude(), request.getLocation().getLongitude());
Double accuracy = attendance.getLocation().calculateAccuracy(request.getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.cotato.csquiz.domain.attendance.enums.AttendanceType;
import org.cotato.csquiz.domain.attendance.repository.AttendanceRecordRepository;
import org.cotato.csquiz.domain.attendance.util.AttendanceUtil;
import org.cotato.csquiz.domain.generation.entity.Session;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -24,8 +25,8 @@ public AttendanceType attendanceType() {
}

@Override
public AttendResponse request(AttendanceParams params, LocalDateTime sessionStartTime, Long memberId, Attendance attendance) {
AttendanceResult attendanceResult = AttendanceUtil.calculateAttendanceStatus(sessionStartTime, attendance, params.requestTime());
public AttendResponse request(AttendanceParams params, Session session, Long memberId, Attendance attendance) {
AttendanceResult attendanceResult = AttendanceUtil.calculateAttendanceStatus(session, attendance, params.requestTime(), attendanceType());

attendanceRecordRepository.save(AttendanceRecord.onLineRecord(attendance, memberId, attendanceResult, params.requestTime()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.cotato.csquiz.api.attendance.dto.AttendanceParams;
import org.cotato.csquiz.domain.attendance.entity.Attendance;
import org.cotato.csquiz.domain.attendance.enums.AttendanceType;
import org.cotato.csquiz.domain.generation.entity.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -24,8 +25,8 @@ public RequestAttendanceService(List<AttendClient> clients) {
);
}

public AttendResponse attend(AttendanceParams params, LocalDateTime sessionStartTime, Long memberId, Attendance attendance) {
public AttendResponse attend(AttendanceParams params, Session session, Long memberId, Attendance attendance) {
AttendClient attendClient = clients.get(params.attendanceType());
return attendClient.request(params, sessionStartTime, memberId, attendance);
return attendClient.request(params, session, memberId, attendance);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

public class AttendanceExcelUtil {

private static final String PRESENT = "출석";
private static final int DEFAULT_TOTAL_ATTENDANCE = 0;
private static final int DEFAULT_TOTAL_OFFLINE = 0;
private static final int DEFAULT_TOTAL_ONLINE = 0;
Expand Down Expand Up @@ -72,7 +73,7 @@ public static void createHeaderRow(Sheet sheet, Map<String, String> columnNameBy
headerRow.createCell(columnNumber++).setCellValue(columnName);
}

headerRow.createCell(columnNumber++).setCellValue(AttendanceResult.PRESENT.getDescription());
headerRow.createCell(columnNumber++).setCellValue(PRESENT);
headerRow.createCell(columnNumber++).setCellValue(AttendanceType.OFFLINE.getDescription());
headerRow.createCell(columnNumber++).setCellValue(AttendanceType.ONLINE.getDescription());
headerRow.createCell(columnNumber++).setCellValue(AttendanceResult.LATE.getDescription());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package org.cotato.csquiz.domain.attendance.util;

import java.time.LocalDateTime;
import java.time.LocalTime;
import org.cotato.csquiz.common.error.ErrorCode;
import org.cotato.csquiz.common.error.exception.AppException;
import org.cotato.csquiz.domain.attendance.entity.Attendance;
import org.cotato.csquiz.domain.attendance.enums.AttendanceOpenStatus;
import org.cotato.csquiz.domain.attendance.enums.AttendanceResult;
import org.cotato.csquiz.domain.attendance.enums.AttendanceType;
import org.cotato.csquiz.domain.generation.entity.Session;

public class AttendanceUtil {
// 출석 시간에 따른 지각 여부 구분하기
public static AttendanceResult calculateAttendanceStatus(LocalDateTime sessionDateTime, Attendance attendance,
LocalDateTime attendTime) {
public static AttendanceResult calculateAttendanceStatus(Session session, Attendance attendance,
LocalDateTime attendTime, AttendanceType attendanceType) {
LocalDateTime sessionDateTime = session.getSessionDateTime();
// 입력한 날짜와 세션 날짜가 다르거나, 시작 전이라면
if (!attendTime.toLocalDate().equals(sessionDateTime.toLocalDate()) || attendTime.isBefore(sessionDateTime)) {
throw new AppException(ErrorCode.ATTENDANCE_NOT_OPEN);
}

if (attendTime.isAfter(sessionDateTime) && attendTime.isBefore(attendance.getAttendanceDeadLine())) {
return AttendanceResult.PRESENT;
return AttendanceResult.getAttendanceResult(attendanceType);
}
if (attendTime.isBefore(attendance.getLateDeadLine())) {
return AttendanceResult.LATE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import jakarta.persistence.EntityNotFoundException;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -138,7 +137,7 @@ public void updateSessionDateTime(Session session, LocalDateTime newDateTime, Lo
attendance.updateDeadLine(attendanceDeadline, lateDeadline);

attendanceRepository.save(attendance);
attendanceRecordService.updateAttendanceStatus(newDateTime, attendance);
attendanceRecordService.updateAttendanceStatus(session, attendance);
}

public List<SessionListResponse> findSessionsByGenerationId(Long generationId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class AttendancePresentRecordMigrationJob implements MigrationJob {
@Transactional
public void migrate() {
List<AttendanceRecord> presentRecords = attendanceRecordRepository.findAll().stream()
.filter(record -> record.getAttendanceResult() == AttendanceResult.PRESENT)
// .filter(record -> record.getAttendanceResult() == AttendanceResult.PRESENT) // migration 완료로 인한 주석 처리
.collect(Collectors.toList());

presentRecords.forEach(record -> {
Expand Down

0 comments on commit 4949c96

Please sign in to comment.