|
@@ -8,6 +8,7 @@ import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
import com.ruoyi.common.exception.user.ProjectException;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.bean.BeanUtils;
|
|
|
+import com.ruoyi.generator.domain.Community.CommunityArticle;
|
|
|
import com.ruoyi.system.domain.CommunityChatMsg;
|
|
|
import com.ruoyi.system.domain.vo.CommunityChatMsgVo;
|
|
|
import com.ruoyi.system.domain.vo.SysUserVo;
|
|
@@ -16,6 +17,7 @@ import com.ruoyi.system.service.ICommunityChatMsgService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
@@ -51,13 +53,17 @@ public class CommunityChatMsgController extends BaseController {
|
|
|
List<CommunityChatMsgVo> chatMsgVos = new ArrayList<>();
|
|
|
try {
|
|
|
List<CommunityChatMsg> chatMsgList = communityChatMsgService.list(new QueryWrapper<CommunityChatMsg>()
|
|
|
- .eq("sender_id", userId)
|
|
|
- .eq("receiver_id", otherUserId)
|
|
|
- .or()
|
|
|
- .eq("sender_id", otherUserId)
|
|
|
- .eq("receiver_id", userId)
|
|
|
- .eq("type", type)
|
|
|
- .orderByDesc("create_time"));
|
|
|
+ .and(wrapper -> wrapper.eq("sender_id", userId)
|
|
|
+ .eq("receiver_id", otherUserId)
|
|
|
+ .or()
|
|
|
+ .eq("sender_id", otherUserId)
|
|
|
+ .eq("receiver_id", userId)
|
|
|
+ .eq("type", type))
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
+ })
|
|
|
+ .orderByDesc("create_time")
|
|
|
+ );
|
|
|
//更新该消息标记为已读
|
|
|
List<Long> msgId = chatMsgList.stream()
|
|
|
.filter(item -> !item.isReceiverIsRead() && Objects.equals(item.getReceiverId(), SecurityUtils.getUserId()))
|
|
@@ -109,4 +115,31 @@ public class CommunityChatMsgController extends BaseController {
|
|
|
}
|
|
|
return AjaxResult.success(sysUserChatVos);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清空聊天记录
|
|
|
+ */
|
|
|
+ @ApiOperation("清空聊天记录")
|
|
|
+ @PostMapping("/clearChat")
|
|
|
+ public AjaxResult clearChat(Long otherUserId) {
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+ try {
|
|
|
+ boolean update = communityChatMsgService.update(
|
|
|
+ null,
|
|
|
+ new UpdateWrapper<CommunityChatMsg>()
|
|
|
+ .eq("sender_id", userId)
|
|
|
+ .eq("receiver_id", otherUserId)
|
|
|
+ .set("is_delete", true)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
+ })
|
|
|
+ );
|
|
|
+ if (!update) {
|
|
|
+ return success("清空聊天记录失败!");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ProjectException();
|
|
|
+ }
|
|
|
+ return AjaxResult.success("清空聊天记录成功");
|
|
|
+ }
|
|
|
}
|