|
@@ -10,6 +10,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
import cn.com.ty.lift.ud.chat.controller.query.ChatMsgQuery;
|
|
|
import cn.com.ty.lift.ud.chat.mapper.ChatMsgMapper;
|
|
@@ -33,8 +34,7 @@ public class ChatMsgServiceImpl extends ServiceImpl<ChatMsgMapper, ChatMsgEntity
|
|
|
|
|
|
private @Autowired ChatMsgMapper chatMsgMapper;
|
|
|
|
|
|
- private @Autowired
|
|
|
- RedisUtil redis;
|
|
|
+ private @Autowired RedisUtil redis;
|
|
|
|
|
|
@Override
|
|
|
public RestResponse selectByExample(ChatMsgQuery query) {
|
|
@@ -48,15 +48,20 @@ public class ChatMsgServiceImpl extends ServiceImpl<ChatMsgMapper, ChatMsgEntity
|
|
|
|
|
|
@Override
|
|
|
public RestResponse messageHistory(ChatMsgQuery req) throws Exception {
|
|
|
- List<ChatMsgEntity> data = new ArrayList<>();
|
|
|
- ChatDo chatDo = redis.get(req.getSessionid(), ChatDo.class);
|
|
|
+ List<IMMessage> data = new ArrayList<>();
|
|
|
+ List list2 = redis.get("ALLCHATS:" + req.getSessionid(), List.class);
|
|
|
+ for (Object i : list2) {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ IMMessage convertValue = objectMapper.convertValue(i, IMMessage.class);
|
|
|
+ data.add(convertValue);
|
|
|
+ }
|
|
|
|
|
|
// 查询缓存中是否存在聊天记录
|
|
|
- if (null != chatDo) {
|
|
|
+ if (null != data) {
|
|
|
// 如果查询的总记录小于缓存中的总数就从缓存中获取
|
|
|
- if (chatDo.getList().size() >= (req.getPageNum() * req.getPageSize())) {
|
|
|
- for (ChatMsgDTO item : chatDo.getList()) {
|
|
|
- ChatMsgEntity entity = new ChatMsgEntity();
|
|
|
+ if (data.size() >= (req.getPageNum() * req.getPageSize())) {
|
|
|
+ for (IMMessage item : data) {
|
|
|
+ IMMessage entity = new IMMessage();
|
|
|
BeanUtils.copyProperties(item, entity);
|
|
|
data.add(entity);
|
|
|
} ;
|
|
@@ -65,14 +70,14 @@ public class ChatMsgServiceImpl extends ServiceImpl<ChatMsgMapper, ChatMsgEntity
|
|
|
long pageSize = req.getPageSize();
|
|
|
req.setPageNum(1);
|
|
|
req.setPageSize(Integer.MAX_VALUE);
|
|
|
- data = chatMsgMapper.selectByQuery(req.condition(), req);
|
|
|
+ List<IMMessage> list = chatMsgMapper.msgHistoryListQuery(req);
|
|
|
req.setPageNum(pageNum);
|
|
|
req.setPageSize(pageSize);
|
|
|
- for (ChatMsgDTO item : chatDo.getList()) {
|
|
|
- ChatMsgEntity entity = new ChatMsgEntity();
|
|
|
+ for (IMMessage item : list) {
|
|
|
+ IMMessage entity = new IMMessage();
|
|
|
BeanUtils.copyProperties(item, entity);
|
|
|
data.add(entity);
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
} else {
|
|
@@ -80,7 +85,7 @@ public class ChatMsgServiceImpl extends ServiceImpl<ChatMsgMapper, ChatMsgEntity
|
|
|
long pageSize = req.getPageSize();
|
|
|
req.setPageNum(1);
|
|
|
req.setPageSize(Integer.MAX_VALUE);
|
|
|
- data = chatMsgMapper.selectByQuery(req.condition(), req);
|
|
|
+ data = chatMsgMapper.msgHistoryListQuery(req);
|
|
|
req.setPageNum(pageNum);
|
|
|
req.setPageSize(pageSize);
|
|
|
}
|
|
@@ -100,11 +105,11 @@ public class ChatMsgServiceImpl extends ServiceImpl<ChatMsgMapper, ChatMsgEntity
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public IPage paging(List<ChatMsgEntity> list, ChatMsgQuery req) throws Exception {
|
|
|
- List<ChatMsgEntity> pageList = new ArrayList<ChatMsgEntity>();
|
|
|
+ public IPage paging(List<IMMessage> list, ChatMsgQuery req) throws Exception {
|
|
|
+ List<IMMessage> pageList = new ArrayList<IMMessage>();
|
|
|
int currIdx = (int)(req.getPageNum() > 1 ? (req.getPageNum() - 1) * req.getPageSize() : 0);
|
|
|
for (int i = 0; i < req.getPageSize() && i < list.size() - currIdx; i++) {
|
|
|
- ChatMsgEntity listNew = list.get(currIdx + i);
|
|
|
+ IMMessage listNew = list.get(currIdx + i);
|
|
|
pageList.add(listNew);
|
|
|
}
|
|
|
IPage page = req.page();
|
|
@@ -120,7 +125,6 @@ public class ChatMsgServiceImpl extends ServiceImpl<ChatMsgMapper, ChatMsgEntity
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 集合内元素前后顺序颠倒
|
|
|
*
|
|
@@ -142,7 +146,7 @@ public class ChatMsgServiceImpl extends ServiceImpl<ChatMsgMapper, ChatMsgEntity
|
|
|
@Override
|
|
|
public RestResponse msgHistoryList(ChatMsgQuery query) {
|
|
|
IPage page = query.page();
|
|
|
- List<IMMessage> list = chatMsgMapper.msgHistoryListQuery( query);
|
|
|
+ List<IMMessage> list = chatMsgMapper.msgHistoryListQuery(query);
|
|
|
int total = chatMsgMapper.countMsgHistoryList(query);
|
|
|
page.setRecords(list);
|
|
|
page.setTotal(total);
|