ActivityService构建完成,并添加注释

This commit is contained in:
chuyan 2020-09-10 21:27:00 +08:00
parent f8c9d17dc6
commit baf12c0657
3 changed files with 84 additions and 8 deletions

View File

@ -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;
}
}

View File

@ -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<Integer> participantIds = new ArrayList<>();
@ElementCollection
List<Integer> absentees = new ArrayList<>();
// 活动出勤情况对应人员是否出勤
@ElementCollection
Map<Integer, Boolean> attendance = new HashMap<>();
@OneToMany(cascade = CascadeType.MERGE)
List<File> appendixes = new ArrayList<>();
Date registrationDDL;
Date creationTime = new Date();

View File

@ -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<Activity> optionalActivity = activityRepository.findById(activityId);
if(!optionalActivity.isPresent()){
throw new NotFoundException("No such activity.");
}
Activity activity = optionalActivity.get();
Activity activity = getActivity(activityId);
List<User> targets = new ArrayList<>();
List<Integer> 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<MemberInfo> getMemberInfo(int activityId){
Activity activity = getActivity(activityId);
List<MemberInfo> 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<Integer> getAbsentStudents(int activityId){
Activity activity = getActivity(activityId);
return activity.getAbsentees();
}
/**
* 获取指定活动的出勤人员
* @param activityId 活动id
* @return 出勤人员id列表
*/
public List<Integer> 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<Activity> optionalActivity = activityRepository.findById(activityId);
if(!optionalActivity.isPresent()){
throw new NotFoundException("No such activity.");
}
return optionalActivity.get();
}
}