【SaaS云会议系统开发】会议排序算法测试
排序算法
@Override
public List<Meeting> getMeetingByUserId(Integer userId) {
List<MeetingUserRelation> relations = meetingUserRelationRepository.findByUserId(userId);
List<Meeting> meetings = new ArrayList<>();
for (MeetingUserRelation relation : relations) {
Meeting meeting = meetingRepository.findMeetingByIdAndStatus(relation.getMeetingId(), 100);
if (meeting != null) {
meetings.add(meeting);
}
}
meetings = myMeetingSort(meetings);
return meetings;
}
//我的会议列表排序
public List<Meeting> myMeetingSort(List<Meeting> meetings) {
if (meetings.size() <= 1) return meetings;
List<Meeting> temps = new ArrayList<>();
for (int i = 0; i < meetings.size(); i++) {
Meeting temp = meetings.get(i);
if (i == 0)
temps.add(temp);
else
for (int j = 0; j < temps.size(); j++) {
if (temp.getStartTime().getTime() < temps.get(j).getStartTime().getTime()) {
temps.add(j, temp);
break;
}else if (j == temps.size() - 1) {
temps.add(temp);
break;
}
}
}
meetings = temps;
return meetings;
}
测试程序
对Service进行测试
package com.rjxy.Test;
import com.rjxy.Entity.Meeting;
import com.rjxy.ServerApplication;
import com.rjxy.Service.Impl.MeetingServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.transaction.Transactional;
import java.util.List;
@SpringBootTest(classes = ServerApplication.class)
@RunWith(SpringRunner.class)
public class GetMyMeetingTest {
@Autowired
private MeetingServiceImpl meetingServiceImpl;
@Test
@Transactional
public void getMyMeeting(){
//测试service类
List<Meeting> ms = meetingServiceImpl.getMeetingByUserId(910);
for (Meeting m : ms) {
System.out.println(m.getId());
System.out.println(m.getStartTime());
}
System.out.println(ms.size());
}
}
测试结果
可以看到得到了对应结果,并进行了排序。