正在显示
3 个修改的文件
包含
34 行增加
和
35 行删除
| @@ -5,11 +5,9 @@ import com.crossoverjie.cim.client.service.MsgHandle; | @@ -5,11 +5,9 @@ import com.crossoverjie.cim.client.service.MsgHandle; | ||
| 5 | import com.crossoverjie.cim.client.util.SpringBeanFactory; | 5 | import com.crossoverjie.cim.client.util.SpringBeanFactory; |
| 6 | import com.crossoverjie.cim.client.vo.req.GroupReqVO; | 6 | import com.crossoverjie.cim.client.vo.req.GroupReqVO; |
| 7 | import com.crossoverjie.cim.client.vo.req.P2PReqVO; | 7 | import com.crossoverjie.cim.client.vo.req.P2PReqVO; |
| 8 | -import com.crossoverjie.cim.common.enums.SystemCommandEnumType; | ||
| 9 | import org.slf4j.Logger; | 8 | import org.slf4j.Logger; |
| 10 | import org.slf4j.LoggerFactory; | 9 | import org.slf4j.LoggerFactory; |
| 11 | 10 | ||
| 12 | -import java.util.Map; | ||
| 13 | import java.util.Scanner; | 11 | import java.util.Scanner; |
| 14 | 12 | ||
| 15 | /** | 13 | /** |
| @@ -52,43 +50,14 @@ public class Scan implements Runnable { | @@ -52,43 +50,14 @@ public class Scan implements Runnable { | ||
| 52 | continue; | 50 | continue; |
| 53 | } | 51 | } |
| 54 | 52 | ||
| 55 | - | ||
| 56 | - //单聊 | ||
| 57 | - totalMsg = msg.split("><"); | ||
| 58 | - if (totalMsg.length > 1) { | ||
| 59 | - //私聊 | ||
| 60 | - p2pChat(totalMsg); | ||
| 61 | - } else { | ||
| 62 | - //群聊 | ||
| 63 | - groupChat(msg); | ||
| 64 | - } | 53 | + //真正的发送消息 |
| 54 | + msgHandle.sendMsg(msg) ; | ||
| 65 | 55 | ||
| 66 | 56 | ||
| 67 | LOGGER.info("{}:【{}】", configuration.getUserName(), msg); | 57 | LOGGER.info("{}:【{}】", configuration.getUserName(), msg); |
| 68 | } | 58 | } |
| 69 | } | 59 | } |
| 70 | 60 | ||
| 71 | - /** | ||
| 72 | - * 处理内置函数 | ||
| 73 | - */ | ||
| 74 | - private void innerCommand(String msg) { | ||
| 75 | - Map<String, String> allStatusCode = SystemCommandEnumType.getAllStatusCode(); | ||
| 76 | - | ||
| 77 | - if (SystemCommandEnumType.QUIT.getCommandType().equals(msg)){ | ||
| 78 | - LOGGER.info("系统关闭中。。。。"); | ||
| 79 | - System.exit(0); | ||
| 80 | - }else { | ||
| 81 | - LOGGER.warn("===================================="); | ||
| 82 | - for (Map.Entry<String, String> stringStringEntry : allStatusCode.entrySet()) { | ||
| 83 | - String key = stringStringEntry.getKey(); | ||
| 84 | - String value = stringStringEntry.getValue(); | ||
| 85 | - LOGGER.warn(key + "----->" + value); | ||
| 86 | - } | ||
| 87 | - LOGGER.warn("===================================="); | ||
| 88 | - } | ||
| 89 | - | ||
| 90 | - return; | ||
| 91 | - } | ||
| 92 | 61 | ||
| 93 | private void p2pChat(String[] totalMsg) { | 62 | private void p2pChat(String[] totalMsg) { |
| 94 | P2PReqVO p2PReqVO = new P2PReqVO(); | 63 | P2PReqVO p2PReqVO = new P2PReqVO(); |
| @@ -12,6 +12,11 @@ import com.crossoverjie.cim.client.vo.req.P2PReqVO; | @@ -12,6 +12,11 @@ import com.crossoverjie.cim.client.vo.req.P2PReqVO; | ||
| 12 | */ | 12 | */ |
| 13 | public interface MsgHandle { | 13 | public interface MsgHandle { |
| 14 | 14 | ||
| 15 | + /** | ||
| 16 | + * 统一的发送接口,包含了 groupChat p2pChat | ||
| 17 | + * @param msg | ||
| 18 | + */ | ||
| 19 | + void sendMsg(String msg) ; | ||
| 15 | 20 | ||
| 16 | /** | 21 | /** |
| 17 | * 群聊 | 22 | * 群聊 |
| @@ -25,7 +30,7 @@ public interface MsgHandle { | @@ -25,7 +30,7 @@ public interface MsgHandle { | ||
| 25 | * @param p2PReqVO 私聊请求 | 30 | * @param p2PReqVO 私聊请求 |
| 26 | * @throws Exception | 31 | * @throws Exception |
| 27 | */ | 32 | */ |
| 28 | - void p2pChat(P2PReqVO p2PReqVO) throws Exception; | 33 | + void p2pChat(P2PReqVO p2PReqVO) ; |
| 29 | 34 | ||
| 30 | 35 | ||
| 31 | // TODO: 2018/12/26 后续对消息的处理可以优化为责任链模式 | 36 | // TODO: 2018/12/26 后续对消息的处理可以优化为责任链模式 |
| 1 | package com.crossoverjie.cim.client.service.impl; | 1 | package com.crossoverjie.cim.client.service.impl; |
| 2 | 2 | ||
| 3 | import com.crossoverjie.cim.client.client.CIMClient; | 3 | import com.crossoverjie.cim.client.client.CIMClient; |
| 4 | +import com.crossoverjie.cim.client.config.AppConfiguration; | ||
| 4 | import com.crossoverjie.cim.client.service.MsgHandle; | 5 | import com.crossoverjie.cim.client.service.MsgHandle; |
| 5 | import com.crossoverjie.cim.client.service.RouteRequest; | 6 | import com.crossoverjie.cim.client.service.RouteRequest; |
| 6 | import com.crossoverjie.cim.client.vo.req.GroupReqVO; | 7 | import com.crossoverjie.cim.client.vo.req.GroupReqVO; |
| @@ -29,6 +30,8 @@ public class MsgHandler implements MsgHandle { | @@ -29,6 +30,8 @@ public class MsgHandler implements MsgHandle { | ||
| 29 | @Autowired | 30 | @Autowired |
| 30 | private RouteRequest routeRequest ; | 31 | private RouteRequest routeRequest ; |
| 31 | 32 | ||
| 33 | + @Autowired | ||
| 34 | + private AppConfiguration configuration; | ||
| 32 | 35 | ||
| 33 | @Autowired | 36 | @Autowired |
| 34 | private ThreadPoolExecutor executor ; | 37 | private ThreadPoolExecutor executor ; |
| @@ -37,12 +40,34 @@ public class MsgHandler implements MsgHandle { | @@ -37,12 +40,34 @@ public class MsgHandler implements MsgHandle { | ||
| 37 | private CIMClient cimClient ; | 40 | private CIMClient cimClient ; |
| 38 | 41 | ||
| 39 | @Override | 42 | @Override |
| 43 | + public void sendMsg(String msg) { | ||
| 44 | + String[] totalMsg = msg.split("><"); | ||
| 45 | + if (totalMsg.length > 1) { | ||
| 46 | + //私聊 | ||
| 47 | + P2PReqVO p2PReqVO = new P2PReqVO(); | ||
| 48 | + p2PReqVO.setUserId(configuration.getUserId()); | ||
| 49 | + p2PReqVO.setReceiveUserId(Long.parseLong(totalMsg[0])); | ||
| 50 | + p2PReqVO.setMsg(totalMsg[1]); | ||
| 51 | + p2pChat(p2PReqVO); | ||
| 52 | + | ||
| 53 | + } else { | ||
| 54 | + //群聊 | ||
| 55 | + GroupReqVO groupReqVO = new GroupReqVO(configuration.getUserId(), msg); | ||
| 56 | + try { | ||
| 57 | + groupChat(groupReqVO); | ||
| 58 | + } catch (Exception e) { | ||
| 59 | + LOGGER.error("Exception",e); | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Override | ||
| 40 | public void groupChat(GroupReqVO groupReqVO) throws Exception { | 65 | public void groupChat(GroupReqVO groupReqVO) throws Exception { |
| 41 | routeRequest.sendGroupMsg(groupReqVO); | 66 | routeRequest.sendGroupMsg(groupReqVO); |
| 42 | } | 67 | } |
| 43 | 68 | ||
| 44 | @Override | 69 | @Override |
| 45 | - public void p2pChat(P2PReqVO p2PReqVO) throws Exception { | 70 | + public void p2pChat(P2PReqVO p2PReqVO) { |
| 46 | 71 | ||
| 47 | } | 72 | } |
| 48 | 73 |
-
请 注册 或 登录 后发表评论