diff --git a/src/main/java/com/codesdream/ase/component/student/MemberInfo.java b/src/main/java/com/codesdream/ase/component/student/MemberInfo.java new file mode 100644 index 0000000..d6e5611 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/student/MemberInfo.java @@ -0,0 +1,19 @@ +package com.codesdream.ase.component.student; + +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class MemberInfo { + + private int memberId; + + // -1:创建人 0:管理员 1:普通参与者 + private int memberType; + + public MemberInfo(int memberId, int memberType){ + this.memberId = memberId; + this.memberType = memberType; + } +} diff --git a/src/main/java/com/codesdream/ase/model/activity/Activity.java b/src/main/java/com/codesdream/ase/model/activity/Activity.java index b3690a8..e3377ad 100644 --- a/src/main/java/com/codesdream/ase/model/activity/Activity.java +++ b/src/main/java/com/codesdream/ase/model/activity/Activity.java @@ -5,9 +5,7 @@ import com.codesdream.ase.model.mark.Tag; import lombok.Data; import javax.persistence.*; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; @Entity @Table @@ -26,9 +24,17 @@ public class Activity { @ElementCollection List participantIds = new ArrayList<>(); + @ElementCollection + List absentees = new ArrayList<>(); + + // 活动出勤情况,对应人员是否出勤 + @ElementCollection + Map attendance = new HashMap<>(); + @OneToMany(cascade = CascadeType.MERGE) List appendixes = new ArrayList<>(); + Date registrationDDL; Date creationTime = new Date(); diff --git a/src/main/java/com/codesdream/ase/service/ActivityService.java b/src/main/java/com/codesdream/ase/service/ActivityService.java index 5266e6a..17dcf0e 100644 --- a/src/main/java/com/codesdream/ase/service/ActivityService.java +++ b/src/main/java/com/codesdream/ase/service/ActivityService.java @@ -1,5 +1,6 @@ package com.codesdream.ase.service; +import com.codesdream.ase.component.student.MemberInfo; import com.codesdream.ase.exception.notfound.NotFoundException; import com.codesdream.ase.model.activity.Activity; import com.codesdream.ase.model.message.Message; @@ -104,11 +105,7 @@ public class ActivityService { */ public boolean sendDDLToGroup(int activityId){ - Optional optionalActivity = activityRepository.findById(activityId); - if(!optionalActivity.isPresent()){ - throw new NotFoundException("No such activity."); - } - Activity activity = optionalActivity.get(); + Activity activity = getActivity(activityId); List targets = new ArrayList<>(); List memberIds = activity.getParticipantIds(); for(Integer memberId : memberIds){ @@ -127,7 +124,61 @@ public class ActivityService { return messageService.sendMessage(message, targets); + } + /** + * 获取指定活动的成员信息 + * @see MemberInfo + * @param activityId 活动id + * @return 成员信息表 + */ + public List getMemberInfo(int activityId){ + + Activity activity = getActivity(activityId); + List memberInfoList = new ArrayList<>(); + memberInfoList.add(new MemberInfo(activity.getCreatorId(), -1)); + for (Integer manager : activity.getManagerIds()){ + memberInfoList.add(new MemberInfo(manager, 0)); + } + for (Integer participant : activity.getParticipantIds()){ + memberInfoList.add(new MemberInfo(participant, 1)); + } + return memberInfoList; + } + + /** + * 获取缺勤人员信息 + * @param activityId 活动id + * @return 缺勤人员id列表 + */ + public List getAbsentStudents(int activityId){ + Activity activity = getActivity(activityId); + return activity.getAbsentees(); + } + + /** + * 获取指定活动的出勤人员 + * @param activityId 活动id + * @return 出勤人员id列表 + */ + public List getAttendants(int activityId){ + Activity activity = getActivity(activityId); + return new ArrayList<>(activity.getAttendance().keySet()); + } + + /** + * 对于给定activityId获取数据库中的一个活动实例,若不存在则抛出异常 + * @exception NotFoundException 对应activityId在数据库中无记录 + * @see NotFoundException + * @param activityId + * @return + */ + private Activity getActivity(int activityId){ + Optional optionalActivity = activityRepository.findById(activityId); + if(!optionalActivity.isPresent()){ + throw new NotFoundException("No such activity."); + } + return optionalActivity.get(); } }