Skip to content

Commit

Permalink
[What 135] feat : 유저별 출공결결석 횟수 확인 (#73)
Browse files Browse the repository at this point in the history
개인별 출공결 확인
  • Loading branch information
dPwls0125 authored Sep 24, 2023
1 parent a7999db commit e42407f
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public ResponseEntity<?> startAttendance(@PathVariable(name = "scheduleId") Long
description = "관리자가 출석을 종료")
@DeleteMapping("/{scheduleId}/attendance")
public ResponseEntity<?> finishAttendance(Long scheduleId) throws NotImplementedException {
attendanceService.reflectAttendanceByUser(scheduleId);
return attendanceService.finishAttendance(scheduleId);
}
// 출석 재시작
Expand Down Expand Up @@ -72,5 +73,4 @@ public ResponseEntity openAttendance(@PathVariable(name = "scheduleId") Long sch
public ResponseEntity<?> doAttendance(@PathVariable Long scheduleId, @RequestBody CheckNumDto dto) throws Exception {
return attendanceService.doAttendance(scheduleId, dto.getNumber());
}

}
13 changes: 6 additions & 7 deletions src/main/java/gdg/whatssue/entity/CheckedListByUser.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package gdg.whatssue.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.*;

@Entity
@Getter
@AllArgsConstructor
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Setter
public class CheckedListByUser {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long checkedListByUserId;

private int checkedCount;
Expand All @@ -24,4 +21,6 @@ public class CheckedListByUser {
@OneToOne
@JoinColumn(name = "club_member_mapping_id")
private ClubMemberMapping club_member_mapping;


}
3 changes: 3 additions & 0 deletions src/main/java/gdg/whatssue/entity/Club.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class Club {
@OneToOne(mappedBy = "club", cascade = CascadeType.ALL, orphanRemoval = true)
private MoneyBook moneyBook;

@OneToMany(mappedBy = "club", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ClubMemberMapping> clubMemberMappingList = new ArrayList<>();

@Builder
public Club(String clubName, String clubInfo, String clubCategory, List<Admin> adminList, List<Member> memberList, List<Schedule> scheduleList, Link link) {
this.clubName = clubName;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/gdg/whatssue/entity/ClubMemberMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@Getter
@AllArgsConstructor
@Builder
@NoArgsConstructor
public class ClubMemberMapping {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -32,6 +33,4 @@ public class ClubMemberMapping {
@OneToOne(mappedBy = "club_member_mapping")
private CheckedListByUser checkedListByUser;

public ClubMemberMapping() {
}
}
3 changes: 2 additions & 1 deletion src/main/java/gdg/whatssue/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ public class Member {
@JoinColumn(name = "club_id")
private Club club;


@OneToOne(mappedBy = "member")
private Admin admin;

@OneToMany(mappedBy = "member")
private List<ClubMemberMapping> clubList;

@OneToMany(mappedBy = "member")
private List<ClubMemberMapping> clubMemberMappingList = new ArrayList<>();
@Builder
public Member(String memberNickName, String memberPw, String memberName, String memberEmail, String memberPhone) {
this.memberNickName = memberNickName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package gdg.whatssue.repository;

import gdg.whatssue.entity.CheckedListByUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CheckedListByUserRepository extends JpaRepository<gdg.whatssue.entity.CheckedListByUser, Long> {
CheckedListByUser findByClubMemberMapping_ClubMemberMappingId(Long clubMemberMappingId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface ClubMemberMappingRepository extends JpaRepository<ClubMemberMapping, Long> {

ClubMemberMapping findByMember_MemberId(Long memberId);
}
49 changes: 43 additions & 6 deletions src/main/java/gdg/whatssue/service/AttendanceService.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package gdg.whatssue.service;

import gdg.whatssue.entity.AttendanceByUserBySchedule;
import gdg.whatssue.entity.Schedule;
import gdg.whatssue.repository.ApplyOfficialAbsentRepository;
import gdg.whatssue.repository.AttendanceByUserByScheduleRepository;
import gdg.whatssue.repository.MemberRepository;
import gdg.whatssue.repository.ScheduleRepository;
import gdg.whatssue.entity.*;
import gdg.whatssue.repository.*;
import gdg.whatssue.service.dto.AttendanceStateBySheduleDto;
import gdg.whatssue.service.dto.CheckNumDto;
import jakarta.annotation.PostConstruct;
Expand All @@ -29,6 +25,9 @@ public class AttendanceService {
private final ScheduleRepository scheduleRepository;
private final MemberRepository memberRepository;
private final AttendanceByUserByScheduleRepository attendanceByUserByScheduleRepository;
private final CheckedListByUserRepository checkedListByUserRepository;
private final ClubMemberMappingRepository clubMemberMappingRepository;
private final ClubRepository clubRepository;
private final Map<Long, Integer> checkNumMap = new HashMap<>();
//출석 시작
public Integer startAttendance(Long scheduleId){
Expand Down Expand Up @@ -103,6 +102,44 @@ public ResponseEntity finishAttendance(Long scheduleId){
return ResponseEntity.ok("출석이 종료되었습니다.");
}else return new ResponseEntity("출석이 종료되지 않았습니다.", null, 404);
}

public ResponseEntity<?> reflectAttendanceByUser(Long scheduleId){
List<AttendanceByUserBySchedule> AScheUserList = attendanceByUserByScheduleRepository.findBySchedule_ScheduleId(scheduleId);

for(AttendanceByUserBySchedule attendance : AScheUserList){
Member member = attendance.getMember();

Optional<ClubMemberMapping> clubMemberMappingOptional = Optional.ofNullable(clubMemberMappingRepository.findByMember_MemberId(member.getMemberId()));
ClubMemberMapping clubMemberMapping = clubMemberMappingOptional.orElseGet(() -> {
// 값이 없는 경우 ClubMemberMapping을 빌드하여 생성
ClubMemberMapping newClubMemberMapping = ClubMemberMapping.builder()
.member(member)
.club(member.getClub())
.build();

// 생성한 ClubMemberMapping 저장
clubMemberMappingRepository.save(newClubMemberMapping);
return newClubMemberMapping;
});

clubMemberMappingOptional.ifPresent(value -> {
CheckedListByUser checkedListByUser = checkedListByUserRepository.findByClubMemberMapping_ClubMemberMappingId(clubMemberMapping.getClubMemberMappingId());
if(attendance.getAttendanceType().equals("출석")){
checkedListByUser.setCheckedCount(checkedListByUser.getCheckedCount()+1);
}else if(attendance.getAttendanceType().equals("결석")){
checkedListByUser.setAbsentCount(checkedListByUser.getAbsentCount()+1);
} else if (attendance.getAttendanceType().equals("공결")) {
checkedListByUser.setOfficialAbsentCount(checkedListByUser.getOfficialAbsentCount()+1);
}else {
return;
}
checkedListByUserRepository.save(checkedListByUser);
});

}
return ResponseEntity.ok("출석이 반영되었습니다.");
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@Getter
@NoArgsConstructor
public class CheckIdDuplicateDto {

@NotBlank
String memberNickName;
}

0 comments on commit e42407f

Please sign in to comment.