正在显示
8 个修改的文件
包含
74 行增加
和
14 行删除
| @@ -14,5 +14,5 @@ public interface EchoService { | @@ -14,5 +14,5 @@ public interface EchoService { | ||
| 14 | * @param msg message | 14 | * @param msg message |
| 15 | * @param replace | 15 | * @param replace |
| 16 | */ | 16 | */ |
| 17 | - void echo(String msg, String... replace) ; | 17 | + void echo(String msg, Object... replace) ; |
| 18 | } | 18 | } |
| @@ -38,7 +38,7 @@ public class ClientInfo { | @@ -38,7 +38,7 @@ public class ClientInfo { | ||
| 38 | return this; | 38 | return this; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | - private class Info{ | 41 | + public class Info{ |
| 42 | private String userName; | 42 | private String userName; |
| 43 | private long userId ; | 43 | private long userId ; |
| 44 | private String serviceInfo ; | 44 | private String serviceInfo ; |
| @@ -21,12 +21,52 @@ public class EchoServiceImpl implements EchoService { | @@ -21,12 +21,52 @@ public class EchoServiceImpl implements EchoService { | ||
| 21 | private AppConfiguration appConfiguration; | 21 | private AppConfiguration appConfiguration; |
| 22 | 22 | ||
| 23 | @Override | 23 | @Override |
| 24 | - public void echo(String msg,String... replace) { | 24 | + public void echo(String msg,Object... replace) { |
| 25 | msg = "\033[31;4m" + appConfiguration.getUserName() + PREFIX + "\033[0m" + " " + msg; | 25 | msg = "\033[31;4m" + appConfiguration.getUserName() + PREFIX + "\033[0m" + " " + msg; |
| 26 | 26 | ||
| 27 | - for (String str : replace) { | ||
| 28 | -// msg.replaceAll("{}",str) ; | 27 | + String log = print(msg, replace); |
| 28 | + | ||
| 29 | + System.out.println(log); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * print msg | ||
| 35 | + * @param msg | ||
| 36 | + * @param place | ||
| 37 | + * @return | ||
| 38 | + */ | ||
| 39 | + private String print(String msg, Object... place) { | ||
| 40 | + StringBuilder sb = new StringBuilder(); | ||
| 41 | + int k = 0; | ||
| 42 | + for (int i = 0; i < place.length; i++) { | ||
| 43 | + int index = msg.indexOf("{}", k); | ||
| 44 | + | ||
| 45 | + if (index == -1){ | ||
| 46 | + return msg; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + if (index != 0) { | ||
| 50 | + sb.append(msg, k, index); | ||
| 51 | + sb.append(place[i]); | ||
| 52 | + | ||
| 53 | + if (place.length == 1) { | ||
| 54 | + sb.append(msg, index + 2, msg.length()); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + } else { | ||
| 58 | + sb.append(place[i]); | ||
| 59 | + if (place.length == 1) { | ||
| 60 | + sb.append(msg, index + 2, msg.length()); | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + k = index + 2; | ||
| 65 | + } | ||
| 66 | + if (sb.toString().equals("")){ | ||
| 67 | + return msg ; | ||
| 68 | + }else { | ||
| 69 | + return sb.toString(); | ||
| 29 | } | 70 | } |
| 30 | - System.out.println(msg); | ||
| 31 | } | 71 | } |
| 32 | } | 72 | } |
| 1 | package com.crossoverjie.cim.client.service.impl.command; | 1 | package com.crossoverjie.cim.client.service.impl.command; |
| 2 | 2 | ||
| 3 | +import com.crossoverjie.cim.client.service.EchoService; | ||
| 3 | import com.crossoverjie.cim.client.service.InnerCommand; | 4 | import com.crossoverjie.cim.client.service.InnerCommand; |
| 4 | import com.crossoverjie.cim.client.service.MsgHandle; | 5 | import com.crossoverjie.cim.client.service.MsgHandle; |
| 5 | import org.slf4j.Logger; | 6 | import org.slf4j.Logger; |
| @@ -22,9 +23,13 @@ public class CloseAIModelCommand implements InnerCommand { | @@ -22,9 +23,13 @@ public class CloseAIModelCommand implements InnerCommand { | ||
| 22 | @Autowired | 23 | @Autowired |
| 23 | private MsgHandle msgHandle ; | 24 | private MsgHandle msgHandle ; |
| 24 | 25 | ||
| 26 | + @Autowired | ||
| 27 | + private EchoService echoService ; | ||
| 28 | + | ||
| 25 | @Override | 29 | @Override |
| 26 | public void process(String msg) { | 30 | public void process(String msg) { |
| 27 | msgHandle.closeAIModel(); | 31 | msgHandle.closeAIModel(); |
| 28 | - System.out.println("\033[31;4m" + "。゚(゚´ω`゚)゚。 AI 下线了!" + "\033[0m"); | 32 | + |
| 33 | + echoService.echo("\033[31;4m" + "。゚(゚´ω`゚)゚。 AI 下线了!" + "\033[0m"); | ||
| 29 | } | 34 | } |
| 30 | } | 35 | } |
| 1 | package com.crossoverjie.cim.client.service.impl.command; | 1 | package com.crossoverjie.cim.client.service.impl.command; |
| 2 | 2 | ||
| 3 | -import com.alibaba.fastjson.JSON; | 3 | +import com.crossoverjie.cim.client.service.EchoService; |
| 4 | import com.crossoverjie.cim.client.service.InnerCommand; | 4 | import com.crossoverjie.cim.client.service.InnerCommand; |
| 5 | import com.crossoverjie.cim.client.service.impl.ClientInfo; | 5 | import com.crossoverjie.cim.client.service.impl.ClientInfo; |
| 6 | import org.slf4j.Logger; | 6 | import org.slf4j.Logger; |
| @@ -23,10 +23,13 @@ public class EchoInfoCommand implements InnerCommand { | @@ -23,10 +23,13 @@ public class EchoInfoCommand implements InnerCommand { | ||
| 23 | @Autowired | 23 | @Autowired |
| 24 | private ClientInfo clientInfo; | 24 | private ClientInfo clientInfo; |
| 25 | 25 | ||
| 26 | + @Autowired | ||
| 27 | + private EchoService echoService ; | ||
| 28 | + | ||
| 26 | @Override | 29 | @Override |
| 27 | public void process(String msg) { | 30 | public void process(String msg) { |
| 28 | - LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); | ||
| 29 | - LOGGER.info("client info=[{}]", JSON.toJSONString(clientInfo.get())); | ||
| 30 | - LOGGER.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); | 31 | + echoService.echo("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); |
| 32 | + echoService.echo("client info={}", clientInfo.get().getUserName()); | ||
| 33 | + echoService.echo("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); | ||
| 31 | } | 34 | } |
| 32 | } | 35 | } |
| 1 | package com.crossoverjie.cim.client.service.impl.command; | 1 | package com.crossoverjie.cim.client.service.impl.command; |
| 2 | 2 | ||
| 3 | +import com.crossoverjie.cim.client.service.EchoService; | ||
| 3 | import com.crossoverjie.cim.client.service.InnerCommand; | 4 | import com.crossoverjie.cim.client.service.InnerCommand; |
| 4 | import com.vdurmont.emoji.Emoji; | 5 | import com.vdurmont.emoji.Emoji; |
| 5 | import com.vdurmont.emoji.EmojiManager; | 6 | import com.vdurmont.emoji.EmojiManager; |
| 6 | import com.vdurmont.emoji.EmojiParser; | 7 | import com.vdurmont.emoji.EmojiParser; |
| 7 | import org.slf4j.Logger; | 8 | import org.slf4j.Logger; |
| 8 | import org.slf4j.LoggerFactory; | 9 | import org.slf4j.LoggerFactory; |
| 10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 10 | 12 | ||
| 11 | import java.util.List; | 13 | import java.util.List; |
| @@ -21,9 +23,16 @@ import java.util.List; | @@ -21,9 +23,16 @@ import java.util.List; | ||
| 21 | public class EmojiCommand implements InnerCommand { | 23 | public class EmojiCommand implements InnerCommand { |
| 22 | private final static Logger LOGGER = LoggerFactory.getLogger(EmojiCommand.class); | 24 | private final static Logger LOGGER = LoggerFactory.getLogger(EmojiCommand.class); |
| 23 | 25 | ||
| 26 | + @Autowired | ||
| 27 | + private EchoService echoService ; | ||
| 28 | + | ||
| 24 | 29 | ||
| 25 | @Override | 30 | @Override |
| 26 | public void process(String msg) { | 31 | public void process(String msg) { |
| 32 | + if (msg.split(" ").length <=1){ | ||
| 33 | + echoService.echo("incorrect commond, :emoji [option]") ; | ||
| 34 | + return ; | ||
| 35 | + } | ||
| 27 | String value = msg.split(" ")[1]; | 36 | String value = msg.split(" ")[1]; |
| 28 | if (value != null) { | 37 | if (value != null) { |
| 29 | Integer index = Integer.parseInt(value); | 38 | Integer index = Integer.parseInt(value); |
| @@ -31,7 +40,7 @@ public class EmojiCommand implements InnerCommand { | @@ -31,7 +40,7 @@ public class EmojiCommand implements InnerCommand { | ||
| 31 | all = all.subList(5 * index, 5 * index + 5); | 40 | all = all.subList(5 * index, 5 * index + 5); |
| 32 | 41 | ||
| 33 | for (Emoji emoji : all) { | 42 | for (Emoji emoji : all) { |
| 34 | - System.out.println(EmojiParser.parseToAliases(emoji.getUnicode()) + "--->" + emoji.getUnicode()); | 43 | + echoService.echo(EmojiParser.parseToAliases(emoji.getUnicode()) + "--->" + emoji.getUnicode()); |
| 35 | } | 44 | } |
| 36 | } | 45 | } |
| 37 | 46 |
| 1 | package com.crossoverjie.cim.client.service.impl.command; | 1 | package com.crossoverjie.cim.client.service.impl.command; |
| 2 | 2 | ||
| 3 | +import com.crossoverjie.cim.client.service.EchoService; | ||
| 3 | import com.crossoverjie.cim.client.service.InnerCommand; | 4 | import com.crossoverjie.cim.client.service.InnerCommand; |
| 4 | import com.crossoverjie.cim.client.service.RouteRequest; | 5 | import com.crossoverjie.cim.client.service.RouteRequest; |
| 5 | import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO; | 6 | import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO; |
| @@ -25,6 +26,8 @@ public class PrefixSearchCommand implements InnerCommand { | @@ -25,6 +26,8 @@ public class PrefixSearchCommand implements InnerCommand { | ||
| 25 | 26 | ||
| 26 | @Autowired | 27 | @Autowired |
| 27 | private RouteRequest routeRequest ; | 28 | private RouteRequest routeRequest ; |
| 29 | + @Autowired | ||
| 30 | + private EchoService echoService ; | ||
| 28 | 31 | ||
| 29 | @Override | 32 | @Override |
| 30 | public void process(String msg) { | 33 | public void process(String msg) { |
| @@ -41,7 +44,7 @@ public class PrefixSearchCommand implements InnerCommand { | @@ -41,7 +44,7 @@ public class PrefixSearchCommand implements InnerCommand { | ||
| 41 | 44 | ||
| 42 | for (String res : list) { | 45 | for (String res : list) { |
| 43 | res = res.replace(key, "\033[31;4m" + key + "\033[0m"); | 46 | res = res.replace(key, "\033[31;4m" + key + "\033[0m"); |
| 44 | - System.out.println(res); | 47 | + echoService.echo(res) ; |
| 45 | } | 48 | } |
| 46 | 49 | ||
| 47 | } catch (Exception e) { | 50 | } catch (Exception e) { |
| @@ -36,7 +36,7 @@ public class PrintOnlineUsersCommand implements InnerCommand { | @@ -36,7 +36,7 @@ public class PrintOnlineUsersCommand implements InnerCommand { | ||
| 36 | 36 | ||
| 37 | echoService.echo("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); | 37 | echoService.echo("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); |
| 38 | for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) { | 38 | for (OnlineUsersResVO.DataBodyBean onlineUser : onlineUsers) { |
| 39 | - LOGGER.info("userId={}=====userName={}", onlineUser.getUserId(), onlineUser.getUserName()); | 39 | + echoService.echo("userId={}=====userName={}",onlineUser.getUserId(),onlineUser.getUserName()); |
| 40 | } | 40 | } |
| 41 | echoService.echo("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); | 41 | echoService.echo("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); |
| 42 | 42 |
-
请 注册 或 登录 后发表评论