|
@@ -1,10 +1,12 @@
|
|
|
package com.ruoyi.generator.controller;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.system.domain.CommunityChatMsg;
|
|
|
+import com.ruoyi.system.domain.vo.SysUserVo;
|
|
|
import com.ruoyi.system.service.ICommunityChatMsgService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -14,6 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 聊天记录
|
|
@@ -42,6 +45,25 @@ public class CommunityChatMsgController extends BaseController {
|
|
|
.eq("sender_id", otherUserId)
|
|
|
.eq("receiver_id", userId)
|
|
|
.orderByDesc("create_time"));
|
|
|
+ //更新该消息标记为已读
|
|
|
+ List<Long> msgId = chatMsgList.stream()
|
|
|
+ .filter(item -> !item.isRead())
|
|
|
+ .map(CommunityChatMsg::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ CommunityChatMsg chatMsg = new CommunityChatMsg();
|
|
|
+ chatMsg.setRead(true);
|
|
|
+ communityChatMsgService.update(chatMsg, new UpdateWrapper<CommunityChatMsg>().in("id", msgId));
|
|
|
return AjaxResult.success(chatMsgList);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前登录用户聊天记录
|
|
|
+ */
|
|
|
+ @ApiOperation("获取当前登录用户聊天列表")
|
|
|
+ @GetMapping("/list")
|
|
|
+ public AjaxResult chatList() {
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+ List<SysUserVo> sysUserChatVos = communityChatMsgService.getChatListWithLatestMessage(userId);
|
|
|
+ return AjaxResult.success(sysUserChatVos);
|
|
|
+ }
|
|
|
}
|