Selaa lähdekoodia

微信会话内容存储获取优化

anderx 5 kuukautta sitten
vanhempi
commit
7f6d191925

+ 3 - 2
src/main/java/com/kede/common/dao/ChatMsgUserMapper.java

@@ -2,6 +2,7 @@ package com.kede.common.dao;
 
 import com.kede.common.model.ChatMsgUser;
 import com.kede.wechat.bo.ChatMsgUserBo;
+import com.kede.wechat.bo.InputgetUserMsg;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -84,8 +85,8 @@ public interface ChatMsgUserMapper {
 
     List<ChatMsgUser> getUserList(@Param("type")Integer type);
 
-    List<ChatMsgUser>  selectMyIdByUser(String userId);
+    List<ChatMsgUser>  selectMyIdByUser(InputgetUserMsg in);
 
-    List<ChatMsgUser>  selectMyIdByRoom(String userId);
+    List<ChatMsgUser>  selectMyIdByRoom(InputgetUserMsg in);
 }
 

+ 17 - 5
src/main/java/com/kede/common/mapper/ChatMsgUserMapper.xml

@@ -149,22 +149,34 @@
         from (select tolist user_id
               from chat_msg
               where from_id = #{userId} and type=0
+              <if test="startTime != null and startTime != ''">
+                  and msgtime between  #{startTime} and #{endTime}
+              </if>
               union
               select from_id user_id
               from chat_msg
-              where find_in_set(#{userId},tolist) and type=0)x
-                 left join chat_msg_user b on x.user_id=b.user_id
+              where find_in_set(#{userId},tolist) and type=0
+                <if test="startTime != null and startTime != ''">
+                    and msgtime between  #{startTime} and #{endTime}
+                </if>
+              )x left join chat_msg_user b on x.user_id=b.user_id
     </select>
     <select id="selectMyIdByRoom" resultType="com.kede.common.model.ChatMsgUser">
         select x.roomid userId,b.name
         from (select roomid
               from chat_msg
               where from_id = #{userId} and type=1
-              union
+        <if test="startTime != null and startTime != ''">
+            and msgtime between  #{startTime} and #{endTime}
+        </if>
+        union
               select roomid
               from chat_msg
-              where find_in_set(#{userId},tolist) and type=1)x
-                 left join chat_msg_user b on x.roomid=b.user_id
+              where find_in_set(#{userId},tolist) and type=1
+        <if test="startTime != null and startTime != ''">
+            and msgtime between  #{startTime} and #{endTime}
+        </if>
+              )x left join chat_msg_user b on x.roomid=b.user_id
     </select>
 
 </mapper>

+ 10 - 0
src/main/java/com/kede/common/model/ChatMsg.java

@@ -75,6 +75,16 @@ public class ChatMsg implements Serializable {
 
     private String msgType;
 
+    private String typeName;
+
+    public String getTypeName() {
+        return typeName;
+    }
+
+    public void setTypeName(String typeName) {
+        this.typeName = typeName;
+    }
+
     public String getMsgType() {
         return msgType;
     }

+ 10 - 2
src/main/java/com/kede/wechat/service/impl/ConversationContentServiceImpl.java

@@ -607,16 +607,19 @@ public class ConversationContentServiceImpl extends BaseMybatisDao<ChatMsgUserMa
 
     @Override
     public Object getMyIdByUser(InputgetUserMsg in) {
-        return chatMsgUserMapper.selectMyIdByUser(in.getUserId());
+        if (in.getEndTime()!=null)in.setEndTime(in.getEndTime()+" 23:59:59");
+        return chatMsgUserMapper.selectMyIdByUser(in);
     }
 
     @Override
     public Object getMyIdByRoom(InputgetUserMsg in) {
-        return chatMsgUserMapper.selectMyIdByRoom(in.getUserId());
+        if (in.getEndTime()!=null)in.setEndTime(in.getEndTime()+" 23:59:59");
+        return chatMsgUserMapper.selectMyIdByRoom(in);
     }
 
     @Override
     public Object getMsgList(InputgetUserMsg in) {
+        if (in.getEndTime()!=null)in.setEndTime(in.getEndTime()+" 23:59:59");
         List<ChatMsg> chatMsgs=new ArrayList<>();
         if (StringUtils.isNotEmpty(in.getRoomId())){
             chatMsgs = chatMsgMapper.selectByRoomId(in);
@@ -634,6 +637,11 @@ public class ConversationContentServiceImpl extends BaseMybatisDao<ChatMsgUserMa
                 String desc = field.getDesc();
                 e.setMsgType(desc);
             }
+            if (e.getType()==0){
+                e.setTypeName("单聊");
+            }else if (e.getType()==1){
+                e.setTypeName("群聊");
+            }
         }
         return chatMsgs;
     }