|
@@ -4,9 +4,13 @@ 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.core.domain.entity.SysUser;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import com.ruoyi.common.utils.bean.BeanUtils;
|
|
|
import com.ruoyi.system.domain.CommunityChatMsg;
|
|
|
+import com.ruoyi.system.domain.vo.CommunityChatMsgVo;
|
|
|
import com.ruoyi.system.domain.vo.SysUserVo;
|
|
|
+import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
import com.ruoyi.system.service.ICommunityChatMsgService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -15,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -31,6 +36,9 @@ public class CommunityChatMsgController extends BaseController {
|
|
|
@Resource
|
|
|
private ICommunityChatMsgService communityChatMsgService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 获取当前登录用户聊天记录
|
|
|
*/
|
|
@@ -50,10 +58,26 @@ public class CommunityChatMsgController extends BaseController {
|
|
|
.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);
|
|
|
+ if (!msgId.isEmpty()) {
|
|
|
+ CommunityChatMsg chatMsg = new CommunityChatMsg();
|
|
|
+ chatMsg.setRead(true);
|
|
|
+ communityChatMsgService.update(chatMsg, new UpdateWrapper<CommunityChatMsg>().in("id", msgId));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CommunityChatMsgVo> chatMsgVos = new ArrayList<>();
|
|
|
+ CommunityChatMsgVo chatMsgVo = null;
|
|
|
+ for (CommunityChatMsg chatMsg : chatMsgList) {
|
|
|
+ chatMsgVo = new CommunityChatMsgVo();
|
|
|
+ BeanUtils.copyProperties(chatMsg, chatMsgVo);
|
|
|
+ SysUser senderUser = sysUserMapper.selectUserById(chatMsgVo.getSenderId());
|
|
|
+ SysUser receiveUser = sysUserMapper.selectUserById(chatMsgVo.getReceiverId());
|
|
|
+ chatMsgVo.setSenderNickName(senderUser.getNickName());
|
|
|
+ chatMsgVo.setSenderAvatar(senderUser.getAvatar());
|
|
|
+ chatMsgVo.setReceiverNickName(receiveUser.getNickName());
|
|
|
+ chatMsgVo.setReceiverAvatar(receiveUser.getAvatar());
|
|
|
+ chatMsgVos.add(chatMsgVo);
|
|
|
+ }
|
|
|
+ return AjaxResult.success(chatMsgVos);
|
|
|
}
|
|
|
|
|
|
/**
|