Ver Fonte

历史聊天记录

Wei Ruifeng há 5 anos atrás
pai
commit
23d8bdb866

+ 7 - 0
lift-ud-service/src/main/java/cn/com/ty/lift/ud/chat/controller/ChatMsgController.java

@@ -41,6 +41,13 @@ public class ChatMsgController
         return chatMsgService;
     }
     
+    // 根据条件查询
+    @PostMapping("/msgHistoryList")
+    @ApiOperation(value = "聊天室历史记录分页查询")
+    public RestResponse msgHistoryList(@RequestBody ChatMsgQuery request) {
+        return chatMsgService.msgHistoryList(request);
+    }
+    
     // 根据条件查询
     @PostMapping("/query-page")
     @ApiOperation(value = "分页查询")

+ 2 - 1
lift-ud-service/src/main/java/cn/com/ty/lift/ud/chat/controller/model/ChatSessionReq.java

@@ -15,5 +15,6 @@ public class ChatSessionReq {
     private Integer status;
     
     private String sessionId;
-
+    
+    private List<String> sessionList;
 }

+ 8 - 2
lift-ud-service/src/main/java/cn/com/ty/lift/ud/chat/mapper/ChatMsgMapper.java

@@ -3,13 +3,15 @@ package cn.com.ty.lift.ud.chat.mapper;
 
 import java.util.List;
 
-import cn.com.ty.lift.ud.chat.controller.query.ChatMsgQuery;
-import cn.com.ty.lift.ud.chat.mapper.entity.ChatMsgEntity;
 import org.apache.ibatis.annotations.Param;
 
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import  com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
+import cn.com.ty.lift.ud.chat.controller.query.ChatMsgQuery;
+import cn.com.ty.lift.ud.chat.mapper.entity.ChatMsgEntity;
+import cn.com.ty.lift.ud.neety.protocol.IMMessage;
+
 /**
  * 聊天记录 -Repository
  * 
@@ -69,4 +71,8 @@ public interface ChatMsgMapper extends BaseMapper<ChatMsgEntity> {
     List<ChatMsgEntity> selectByQuery(@Param("ew") Wrapper wrapper, @Param("page") ChatMsgQuery query);
 
     int countByQuery(@Param("ew") Wrapper wrapper);
+    
+    List<IMMessage>msgHistoryListQuery(@Param("page") ChatMsgQuery query);
+    
+    int countMsgHistoryList(@Param("page") ChatMsgQuery query);
 }

+ 34 - 0
lift-ud-service/src/main/java/cn/com/ty/lift/ud/chat/mapper/ChatMsgMapper.xml

@@ -238,4 +238,38 @@
         ${ew.sqlSegment}
     </where>
   </select>
+  
+  <select id="msgHistoryListQuery" resultType="cn.com.ty.lift.ud.neety.protocol.IMMessage">
+  SELECT 
+  'CHAT' cmd,
+  users.`name` `name`,
+  users.avatar_url AS avatarUrl,
+  t.type `type`,
+  t.`sessionid`,
+  t.`to_user` receiver,
+  t.`from_user` userId,
+  t.`from_user` fromUser,
+  cs.data_table dataTable,
+  t.`msg` 
+FROM
+  chat_msg AS t 
+  LEFT JOIN user_info AS users 
+    ON t.from_user = users.user_id 
+  LEFT JOIN chat_session cs 
+    ON cs.`sessionid` = t.sessionid 
+WHERE t.`sessionid` = #{page.sessionid}
+limit #{page.pageIndex},#{page.pageSize}
+  </select>
+  
+  <select id="countMsgHistoryList" resultType="java.lang.Integer">
+   SELECT 
+  count(0) 
+FROM
+  chat_msg AS t 
+  LEFT JOIN user_info AS users 
+    ON t.from_user = users.user_id 
+  LEFT JOIN chat_session cs 
+    ON cs.`sessionid` = t.sessionid 
+WHERE t.`sessionid` = #{page.sessionid}
+  </select>
 </mapper>

+ 2 - 2
lift-ud-service/src/main/java/cn/com/ty/lift/ud/chat/mapper/ChatSessionMapper.xml

@@ -216,8 +216,8 @@
   </select>
   
   <update id="batchUpdate" >
-   update chat_session set statuz = #{req.status} where  id in 
-   <foreach collection="req.ids" item="item" index="index" open="(" close=")" separator=",">
+   update chat_session set statuz = #{req.status} where  sessionid in 
+   <foreach collection="req.sessionList" item="item" index="index" open="(" close=")" separator=",">
         #{item}
     </foreach>
   </update>

+ 2 - 0
lift-ud-service/src/main/java/cn/com/ty/lift/ud/chat/service/IChatMsgService.java

@@ -22,5 +22,7 @@ public interface IChatMsgService extends IService<ChatMsgEntity> {
      * @return
      */
     RestResponse messageHistory(ChatMsgQuery req) throws Exception ;
+    
+    RestResponse msgHistoryList(ChatMsgQuery request);
 
 }

+ 15 - 4
lift-ud-service/src/main/java/cn/com/ty/lift/ud/chat/service/impl/ChatMsgServiceImpl.java

@@ -3,10 +3,6 @@ package cn.com.ty.lift.ud.chat.service.impl;
 import java.util.ArrayList;
 import java.util.List;
 
-import cn.com.ty.lift.ud.chat.controller.query.ChatMsgQuery;
-import cn.com.ty.lift.ud.neety.protocol.ChatMsgDTO;
-import cn.com.ty.lift.ud.redis.ChatDo;
-import cn.com.ty.lift.ud.redis.RedisUtil;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -15,9 +11,14 @@ import org.springframework.transaction.annotation.Transactional;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
+import cn.com.ty.lift.ud.chat.controller.query.ChatMsgQuery;
 import cn.com.ty.lift.ud.chat.mapper.ChatMsgMapper;
 import cn.com.ty.lift.ud.chat.mapper.entity.ChatMsgEntity;
 import cn.com.ty.lift.ud.chat.service.IChatMsgService;
+import cn.com.ty.lift.ud.neety.protocol.ChatMsgDTO;
+import cn.com.ty.lift.ud.neety.protocol.IMMessage;
+import cn.com.ty.lift.ud.redis.ChatDo;
+import cn.com.ty.lift.ud.redis.RedisUtil;
 import cn.com.xwy.boot.web.dto.RestResponse;
 
 /**
@@ -137,4 +138,14 @@ public class ChatMsgServiceImpl extends ServiceImpl<ChatMsgMapper, ChatMsgEntity
         }
         return list1;
     }
+
+    @Override
+    public RestResponse msgHistoryList(ChatMsgQuery query) {
+        IPage page = query.page();
+        List<IMMessage> list = chatMsgMapper.msgHistoryListQuery( query);
+        int total = chatMsgMapper.countMsgHistoryList(query);
+        page.setRecords(list);
+        page.setTotal(total);
+        return RestResponse.success(list, "Queried successfully");
+    }
 }

+ 6 - 1
lift-ud-service/src/main/java/cn/com/ty/lift/ud/chat/service/impl/ChatSessionServiceImpl.java

@@ -75,7 +75,12 @@ public class ChatSessionServiceImpl extends ServiceImpl<ChatSessionMapper, ChatS
 
     @Override
     public RestResponse batchUpdate(ChatSessionReq req) {
-
+        List<String> sessionList = new ArrayList<>();
+        for(Long id :req.getIds()) {
+            ChatSessionEntity selectById = sessionMapper.selectById(id);
+            sessionList.add(selectById.getSessionid());
+        }
+        req.setSessionList(sessionList);
         int flag = sessionMapper.batchUpdate(req);
         if (flag > 0)
             return RestResponse.success("Updated successfully");