|
|
@@ -1,5 +1,6 @@
|
|
|
package com.izouma.dingdong.repo;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import com.izouma.dingdong.domain.Chat;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
@@ -7,10 +8,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+
|
|
|
@RunWith(SpringRunner.class)
|
|
|
@SpringBootTest
|
|
|
public class ChatRepoTest {
|
|
|
@@ -18,7 +21,7 @@ public class ChatRepoTest {
|
|
|
private ChatRepo chatRepo;
|
|
|
|
|
|
@Test
|
|
|
- public void show(){
|
|
|
+ public void show() {
|
|
|
List<Chat> cs = chatRepo.findAllBySendUserIdAndReceiveUserId(82L, 158L);
|
|
|
List<Chat> chats = chatRepo.findAllBySendUserIdAndReceiveUserId(158L, 82L);
|
|
|
chats.addAll(cs);
|
|
|
@@ -28,13 +31,28 @@ public class ChatRepoTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void showMy(){
|
|
|
+ public void showMy() {
|
|
|
List<Chat> chats = chatRepo.findAllBySendUserIdOrReceiveUserId(82L, 82L);
|
|
|
Set<Long> sends = chats.stream().map(Chat::getSendUserId).collect(Collectors.toSet());
|
|
|
Set<Long> reces = chats.stream().map(Chat::getReceiveUserId).collect(Collectors.toSet());
|
|
|
sends.addAll(reces);
|
|
|
sends.remove(82L);
|
|
|
- System.out.println(sends);
|
|
|
+ // System.out.println(sends);
|
|
|
+
|
|
|
+ List<Chat> ch = new ArrayList<>();
|
|
|
+
|
|
|
+ sends.forEach(s -> {
|
|
|
+ List<Chat> c1 = chatRepo.findAllBySendUserIdAndReceiveUserId(s, 82L);
|
|
|
+ List<Chat> c2 = chatRepo.findAllBySendUserIdAndReceiveUserId(82L, s);
|
|
|
+ c1.addAll(c2);
|
|
|
+
|
|
|
+ c1.sort((a,b)->b.getId().compareTo(a.getId()));
|
|
|
+ //CollUtil.sort(c1,(a,b)->b.getId().compareTo(a.getId()));
|
|
|
+
|
|
|
+ ch.add(c1.get(0));
|
|
|
+ });
|
|
|
+
|
|
|
+ System.out.println(ch);
|
|
|
|
|
|
//System.out.println(chatRepo.findAllBySendUserIdOrReceiveUserId(82L,82L));
|
|
|
}
|