正在显示
6 个修改的文件
包含
51 行增加
和
4 行删除
| @@ -15,6 +15,8 @@ import java.util.Arrays; | @@ -15,6 +15,8 @@ import java.util.Arrays; | ||
| 15 | import java.util.List; | 15 | import java.util.List; |
| 16 | import java.util.concurrent.ArrayBlockingQueue; | 16 | import java.util.concurrent.ArrayBlockingQueue; |
| 17 | import java.util.concurrent.BlockingQueue; | 17 | import java.util.concurrent.BlockingQueue; |
| 18 | +import java.util.stream.Collectors; | ||
| 19 | +import java.util.stream.Stream; | ||
| 18 | 20 | ||
| 19 | /** | 21 | /** |
| 20 | * Function: | 22 | * Function: |
| @@ -116,4 +118,29 @@ public class AsyncMsgLogger implements MsgLogger { | @@ -116,4 +118,29 @@ public class AsyncMsgLogger implements MsgLogger { | ||
| 116 | started = false; | 118 | started = false; |
| 117 | worker.interrupt(); | 119 | worker.interrupt(); |
| 118 | } | 120 | } |
| 121 | + | ||
| 122 | + @Override | ||
| 123 | + public String query(String key) { | ||
| 124 | + StringBuilder sb = new StringBuilder(); | ||
| 125 | + | ||
| 126 | + Path path = Paths.get(appConfiguration.getMsgLoggerPath() + appConfiguration.getUserName() + "/"); | ||
| 127 | + | ||
| 128 | + try { | ||
| 129 | + Stream<Path> list = Files.list(path); | ||
| 130 | + List<Path> collect = list.collect(Collectors.toList()); | ||
| 131 | + for (Path file : collect) { | ||
| 132 | + List<String> strings = Files.readAllLines(file); | ||
| 133 | + for (String msg : strings) { | ||
| 134 | + if (msg.trim().contains(key)) { | ||
| 135 | + sb.append(msg).append("\n"); | ||
| 136 | + } | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + } | ||
| 140 | + } catch (IOException e) { | ||
| 141 | + LOGGER.info("IOException", e); | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + return sb.toString().replace(key,"\033[31;4m" + key+"\033[0m"); | ||
| 145 | + } | ||
| 119 | } | 146 | } |
| @@ -108,6 +108,10 @@ public class MsgHandler implements MsgHandle { | @@ -108,6 +108,10 @@ public class MsgHandler implements MsgHandle { | ||
| 108 | //打印在线用户 | 108 | //打印在线用户 |
| 109 | printOnlineUsers(); | 109 | printOnlineUsers(); |
| 110 | 110 | ||
| 111 | + } else if (msg.startsWith(SystemCommandEnumType.QUERY.getCommandType().trim() + " ")){ | ||
| 112 | + String[] split = msg.split(" ") ; | ||
| 113 | + String res = msgLogger.query(split[1]); | ||
| 114 | + System.out.println(res); | ||
| 111 | }else { | 115 | }else { |
| 112 | printAllCommand(allStatusCode); | 116 | printAllCommand(allStatusCode); |
| 113 | } | 117 | } |
| @@ -28,4 +28,12 @@ public class AsyncMsgLoggerTest { | @@ -28,4 +28,12 @@ public class AsyncMsgLoggerTest { | ||
| 28 | TimeUnit.SECONDS.sleep(2); | 28 | TimeUnit.SECONDS.sleep(2); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + @Test | ||
| 34 | + public void query(){ | ||
| 35 | + String crossoverJie = msgLogger.query("crossoverJie"); | ||
| 36 | + System.out.println(crossoverJie); | ||
| 37 | + } | ||
| 38 | + | ||
| 31 | } | 39 | } |
| @@ -126,7 +126,7 @@ public class CommonTest { | @@ -126,7 +126,7 @@ public class CommonTest { | ||
| 126 | "\n" + | 126 | "\n" + |
| 127 | "借助 CIM 你可以实现以下需求:" ; | 127 | "借助 CIM 你可以实现以下需求:" ; |
| 128 | 128 | ||
| 129 | - String key = "IM" ; | 129 | + String key = "CIM" ; |
| 130 | 130 | ||
| 131 | String[] split = allMsg.split("\n"); | 131 | String[] split = allMsg.split("\n"); |
| 132 | for (String msg : split) { | 132 | for (String msg : split) { |
| @@ -150,8 +150,8 @@ public class CommonTest { | @@ -150,8 +150,8 @@ public class CommonTest { | ||
| 150 | count ++ ; | 150 | count ++ ; |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | - | ||
| 154 | - System.out.println(sb.toString().replace(key,"**" + key+"**")); | 153 | + System.out.println(sb.toString()); |
| 154 | + System.out.println(sb.toString().replace(key,"\033[31;4m" + key+"\033[0m")); | ||
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | @Test | 157 | @Test |
| @@ -16,7 +16,8 @@ public enum SystemCommandEnumType { | @@ -16,7 +16,8 @@ public enum SystemCommandEnumType { | ||
| 16 | 16 | ||
| 17 | ALL(":all ","获取所有命令"), | 17 | ALL(":all ","获取所有命令"), |
| 18 | ONLINE_USER(":olu ","获取所有在线用户"), | 18 | ONLINE_USER(":olu ","获取所有在线用户"), |
| 19 | - QUIT(":q ","退出程序") | 19 | + QUIT(":q! ","退出程序"), |
| 20 | + QUERY(":q ","查询聊天记录") | ||
| 20 | 21 | ||
| 21 | ; | 22 | ; |
| 22 | 23 |
-
请 注册 或 登录 后发表评论