Explorar o código

修改会话时长和客服第一次回复的代码bug 和 撤销信息 判断消息是否是 原发送人的消息 bug

779513719 %!s(int64=5) %!d(string=hai) anos
pai
achega
d87b816923

+ 1 - 1
jim-server/src/main/java/org/jim/server/command/handler/CloseReqHandler.java

@@ -29,7 +29,7 @@ public class CloseReqHandler extends AbstractCmdHandler
 
 	private static JedisTemplate jedisTemplate = null;
 
-	private static final String GROUP_PROPERTY = " group_id,name,avatar,service_account_role_department_middle_id,consumer_id,group_type,company_id,department_id ";
+	private static final String GROUP_PROPERTY = " * ";
 
 	private static final String CURRENT_SYSTEM_ALL_USER_ID = "CURRENT_SYSTEM_ALL_USER_ID";
 

+ 3 - 0
jim-server/src/main/java/org/jim/server/command/handler/IMCancelMessageReqHandler.java

@@ -60,6 +60,9 @@ public class IMCancelMessageReqHandler extends AbstractCmdHandler {
         }
         if( CancelMessageTypeEnum.CANCEL.getKey() == cancelMessageReqBody.getMsgState() ){
             ImPacket respPacket = cancelMessageProcessor.get(0).handler(cancelMessageReqBody,channelContext);
+            if( null == respPacket){
+                return null;
+            }
             if( respPacket.getStatus().getCode() == ImStatus.C10025.getCode() ){
                 return respPacket;
             }

+ 1 - 4
jim-server/src/main/java/org/jim/server/command/handler/processor/chat/IMAutoMessageProcessor.java

@@ -63,10 +63,7 @@ public class IMAutoMessageProcessor implements CmdProcessor, ImConst {
                     //聊天数据包
                     ImPacket chatPacket = new ImPacket(
                             Command.COMMAND_CHAT_REQ
-                            , new RespBody(
-                                    Command.COMMAND_CHAT_REQ
-                                    ,createChatBody(message, accountRoleDepartmentId, group_id)
-                            ).toByte()
+                            , createChatBody(message, accountRoleDepartmentId, group_id).toByte()
                     );
                     //设置同步序列号;
                     chatPacket.setSynSeq(0);

+ 32 - 12
jim-server/src/main/java/org/jim/server/command/handler/processor/chat/IMCancelMessageProcessor.java

@@ -1,15 +1,19 @@
 package org.jim.server.command.handler.processor.chat;
 
+import com.alibaba.fastjson.JSONObject;
+import org.jim.common.ImAio;
 import org.jim.common.ImConfig;
 import org.jim.common.ImConst;
 import org.jim.common.ImPacket;
 import org.jim.common.message.MessageHelper;
 import org.jim.common.packets.CancelMessageReqBody;
 import org.jim.common.packets.ChatType;
+import org.jim.common.packets.User;
 import org.jim.common.utils.ChatKit;
 import org.jim.server.command.CommandManager;
 import org.jim.server.command.handler.processor.CmdProcessor;
 import org.jim.server.enums.CancelMessageTypeEnum;
+import org.jim.server.enums.VisitTypeEnum;
 import org.jim.server.model.ConversationRecord;
 import org.jim.server.util.CancelMessageKit;
 import org.tio.core.ChannelContext;
@@ -38,21 +42,37 @@ public class IMCancelMessageProcessor implements CmdProcessor {
         String chatBodyId = cancelMessageReqBody.getId();
         ConversationRecord conversationRecord = ConversationRecord.dao
                 .findFirst("select * from sw_conversation_record where chat_body_id = ? ", chatBodyId);
-        String oldFromId = conversationRecord.getStr("from_id");
-        if( oldFromId.equals(cancelMessageReqBody.getFrom()) ){
-            //表示当前撤销的信息 是 当前人 发的消息 可以撤销
-            //1.修改 sw_conversation_record 数据中相关对应字段 is_recall 消息是否撤回 1:是 0:否
-            conversationRecord.set("is_recall", CancelMessageTypeEnum.CANCEL.getKey()).update();
-            //2. 对redis 对应数据 进行更改
-            if(ImConst.ON.equals(imConfig.getIsStore())){
-                //更改reids中 已经 持久化的 消息
-                if(ChatType.CHAT_TYPE_PUBLIC.getNumber() == cancelMessageReqBody.getChatType()){
-                    removeGroupMessage(cancelMessageReqBody);
+        if( null != conversationRecord ){
+            String oldFromId;
+            User user = ImAio.getUser(cancelMessageReqBody.getFrom());
+            if(user != null){
+                String visitType = user.getVisitType();
+                if(VisitTypeEnum.CUSTOMER.getKey().equals(visitType)){
+                    oldFromId = user.getExtras().getString("customerId");
+                }else if(VisitTypeEnum.VISITOR.getKey().equals(visitType)){
+                    // VISITOR 游客  发送的消息
+                    oldFromId = user.getExtras().getString("visitorId");
+                }else {
+                    //SERVICEACCOUNT 客服  发送的消息
+                    oldFromId = user.getExtras().getString("serviceAccountId");
                 }
+                if( oldFromId.equals(conversationRecord.getStr("from_id")) ){
+                    //表示当前撤销的信息 是 当前人 发的消息 可以撤销
+                    //1.修改 sw_conversation_record 数据中相关对应字段 is_recall 消息是否撤回 1:是 0:否
+                    conversationRecord.set("is_recall", CancelMessageTypeEnum.CANCEL.getKey()).update();
+                    //2. 对redis 对应数据 进行更改
+                    if(ImConst.ON.equals(imConfig.getIsStore())){
+                        //更改reids中 已经 持久化的 消息
+                        if(ChatType.CHAT_TYPE_PUBLIC.getNumber() == cancelMessageReqBody.getChatType()){
+                            removeGroupMessage(cancelMessageReqBody);
+                        }
+                    }
+                    return CancelMessageKit.sendSuccessRespPacket(channelContext);
+                }
+                return CancelMessageKit.fromIdInCorrectRespPacket(channelContext);
             }
-            return CancelMessageKit.sendSuccessRespPacket(channelContext);
         }
-        return CancelMessageKit.fromIdInCorrectRespPacket(channelContext);
+        return null;
     }
 
     /**

+ 1 - 1
server-chat/src/main/java/com/cn/ServerChatStart.java

@@ -54,7 +54,7 @@ public class ServerChatStart {
 
     private static final String CURRENT_SYSTEM_ALL_USER_ID = "CURRENT_SYSTEM_ALL_USER_ID";
 
-    private static final String GROUP_PROPERTY = " group_id,name,avatar,service_account_role_department_middle_id,consumer_id,group_type,company_id,department_id ";
+    private static final String GROUP_PROPERTY = " * ";
 
     static {
         try {

+ 3 - 2
server-chat/src/main/java/com/cn/listener/IMChatGroupListener.java

@@ -74,8 +74,9 @@ public class IMChatGroupListener extends ImGroupListener {
                             //会话创建时间的格林威治时间 毫秒数
                             long createTimeMillis = createTime.getTime();
                             if(currentTimeMillis > createTimeMillis){
-                                conversation.set("end_time",currentTime);
-                                conversation.set("conversation_lenth",Integer.valueOf( String.valueOf( (currentTimeMillis - createTimeMillis)/1000 )));
+                                conversation.set("end_time",currentTime)
+                                            .set("conversation_lenth",Integer.valueOf( String.valueOf( (currentTimeMillis - createTimeMillis)/1000 )))
+                                            .update();
                             }
                         }
                     }

+ 6 - 8
server-chat/src/main/java/com/cn/processor/IMChatAsyncChatMessageProcessor.java

@@ -35,7 +35,6 @@ public class IMChatAsyncChatMessageProcessor extends DefaultAsyncChatMessageProc
 
     @Override
     public void doHandler(ChatBody chatBody, ChannelContext channelContext) {
-
         log.info("聊天记录持久化... 开始:" + sdf.format(new Date()));
         //聊天类型(如 0:未知 1:群聊、2:私聊)
         Integer chatType = chatBody.getChatType();
@@ -45,8 +44,9 @@ public class IMChatAsyncChatMessageProcessor extends DefaultAsyncChatMessageProc
             //群聊
             ChatGroup group = ChatGroup.dao.findById(chatBody.getGroup_id());
             if( null != group){
+                String group_id = group.getStr("group_id");
                 GroupConversationMiddle groupConversationMiddle
-                        = this.getGroupConversationMiddleByGroupId(group.getLong("group_id"));
+                        = this.getGroupConversationMiddleByGroupId(group_id);
                 if( null != groupConversationMiddle ){
                     Conversation conversation = Conversation.dao.findById(groupConversationMiddle.getLong("conversation_id"));
                     if( null != conversation){
@@ -57,9 +57,7 @@ public class IMChatAsyncChatMessageProcessor extends DefaultAsyncChatMessageProc
                 }
             }
         }
-
         log.info("聊天记录持久化... 结束:" + sdf.format(new Date()));
-
     }
 
     /**
@@ -120,10 +118,10 @@ public class IMChatAsyncChatMessageProcessor extends DefaultAsyncChatMessageProc
                     //会话创建时间的格林威治时间 毫秒数
                     long createTimeMillis = createTime.getTime();
                     if(currentTimeMillis > createTimeMillis){
-                        conversation.set("first_answer_time",currentTime);
-                        conversation.set("first_answer_lenth",Integer.valueOf( String.valueOf( (currentTimeMillis - createTimeMillis)/1000 )));
+                        conversation.set("first_answer_time",currentTime)
+                                    .set("first_answer_lenth",Integer.valueOf( String.valueOf( (currentTimeMillis - createTimeMillis)/1000 )))
+                                    .update();
                     }
-
                 }
             }
         }
@@ -141,7 +139,7 @@ public class IMChatAsyncChatMessageProcessor extends DefaultAsyncChatMessageProc
      * @author Darren
      * @date 2020/2/11 19:03
      */
-    private GroupConversationMiddle getGroupConversationMiddleByGroupId(Long groupId){
+    private GroupConversationMiddle getGroupConversationMiddleByGroupId(String groupId){
         StringBuilder sql = new StringBuilder();
         sql.append(" select * from sw_group_conversation_middle where group_id = " + groupId)
                 .append(" order by create_time desc limit 1");

+ 1 - 1
server-chat/src/main/java/com/cn/service/IMChatLoginServiceProcessor.java

@@ -29,7 +29,7 @@ public class IMChatLoginServiceProcessor implements LoginCmdProcessor {
 
     private static JedisTemplate jedisTemplate = null;
 
-    private static final String GROUP_PROPERTY = " group_id,name,avatar,service_account_role_department_middle_id,consumer_id,group_type,company_id,department_id ";
+    private static final String GROUP_PROPERTY = " * ";
 
     private static final String CURRENT_SYSTEM_ALL_USER_ID = "CURRENT_SYSTEM_ALL_USER_ID";