发布于2021-07-24 21:07 阅读(1246) 评论(0) 点赞(2) 收藏(0)
@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());
}
}
可以看到得到了对应结果,并进行了排序。
原文链接:https://blog.csdn.net/tongye1984/article/details/118873108
作者:每个人身上都有毛毛
链接:http://www.pythonpdf.com/blog/article/298/db261535e757aeedbb09/
来源:编程知识网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!