|
@@ -6,9 +6,11 @@ import com.ruoyi.common.core.controller.BaseController;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
import com.ruoyi.common.exception.user.ProjectException;
|
|
import com.ruoyi.common.exception.user.ProjectException;
|
|
|
|
+import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.common.utils.bean.BeanUtils;
|
|
import com.ruoyi.common.utils.bean.BeanUtils;
|
|
import com.ruoyi.generator.domain.Community.CommunityUserBlock;
|
|
import com.ruoyi.generator.domain.Community.CommunityUserBlock;
|
|
|
|
+import com.ruoyi.generator.domain.ReqEntity.UpdateAnonName;
|
|
import com.ruoyi.generator.mapper.community.CommunityUserBlockMapper;
|
|
import com.ruoyi.generator.mapper.community.CommunityUserBlockMapper;
|
|
import com.ruoyi.system.domain.CommunityChatMsg;
|
|
import com.ruoyi.system.domain.CommunityChatMsg;
|
|
import com.ruoyi.system.domain.vo.CommunityChatMsgVo;
|
|
import com.ruoyi.system.domain.vo.CommunityChatMsgVo;
|
|
@@ -18,10 +20,7 @@ import com.ruoyi.system.mapper.SysUserMapper;
|
|
import com.ruoyi.system.service.ICommunityChatMsgService;
|
|
import com.ruoyi.system.service.ICommunityChatMsgService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
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;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -50,6 +49,7 @@ public class CommunityChatMsgController extends BaseController {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private CommunityChatMsgMapper communitychatMsgMapper;
|
|
private CommunityChatMsgMapper communitychatMsgMapper;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取当前登录用户聊天记录
|
|
* 获取当前登录用户聊天记录
|
|
*/
|
|
*/
|
|
@@ -104,9 +104,9 @@ public class CommunityChatMsgController extends BaseController {
|
|
chatMsgVo.setReceiverIsRead(true);
|
|
chatMsgVo.setReceiverIsRead(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- chatMsgVo.setSenderNickName(senderUser.getNickName());
|
|
|
|
|
|
+ chatMsgVo.setSenderNickName("chat".equals(chatMsg.getType()) ? senderUser.getNickName() : chatMsg.getSenderAnonName());
|
|
chatMsgVo.setSenderAvatar(senderUser.getAvatar());
|
|
chatMsgVo.setSenderAvatar(senderUser.getAvatar());
|
|
- chatMsgVo.setReceiverNickName(receiveUser.getNickName());
|
|
|
|
|
|
+ chatMsgVo.setReceiverNickName("chat".equals(chatMsg.getType()) ? receiveUser.getNickName() : chatMsg.getReceiverAnonName());
|
|
chatMsgVo.setReceiverAvatar(receiveUser.getAvatar());
|
|
chatMsgVo.setReceiverAvatar(receiveUser.getAvatar());
|
|
chatMsgVos.add(chatMsgVo);
|
|
chatMsgVos.add(chatMsgVo);
|
|
}
|
|
}
|
|
@@ -120,7 +120,7 @@ public class CommunityChatMsgController extends BaseController {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 获取当前登录用户聊天记录
|
|
|
|
|
|
+ * 获取当前登录用户聊天列表
|
|
*/
|
|
*/
|
|
@ApiOperation("获取当前登录用户聊天列表")
|
|
@ApiOperation("获取当前登录用户聊天列表")
|
|
@GetMapping("/list")
|
|
@GetMapping("/list")
|
|
@@ -178,7 +178,7 @@ public class CommunityChatMsgController extends BaseController {
|
|
communityChatMsgService.update(
|
|
communityChatMsgService.update(
|
|
null,
|
|
null,
|
|
new UpdateWrapper<CommunityChatMsg>()
|
|
new UpdateWrapper<CommunityChatMsg>()
|
|
- .eq("sender_id", otherUserId )
|
|
|
|
|
|
+ .eq("sender_id", otherUserId)
|
|
.eq("receiver_id", userId)
|
|
.eq("receiver_id", userId)
|
|
.set("receiver_is_delete", true)
|
|
.set("receiver_is_delete", true)
|
|
.and((wrapper) -> {
|
|
.and((wrapper) -> {
|
|
@@ -191,4 +191,38 @@ public class CommunityChatMsgController extends BaseController {
|
|
}
|
|
}
|
|
return AjaxResult.success("清空聊天记录成功");
|
|
return AjaxResult.success("清空聊天记录成功");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 更新对方聊天匿名名称
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation("更新对方聊天匿名名称")
|
|
|
|
+ @PostMapping("/updateAnonName")
|
|
|
|
+ public AjaxResult updateAnonName(@RequestBody UpdateAnonName updateAnonName) {
|
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
|
+ long otherUserId = updateAnonName.getOtherUserId();
|
|
|
|
+ String newAnonName = updateAnonName.getNewAnonName();
|
|
|
|
+ String type = updateAnonName.getType();
|
|
|
|
+ try {
|
|
|
|
+ if ("anonymous".equals(type)) {
|
|
|
|
+ List<CommunityChatMsg> chatMsgList = communitychatMsgMapper.getChatMsgRecord(userId, otherUserId, type);
|
|
|
|
+ for (CommunityChatMsg chatMsg : chatMsgList) {
|
|
|
|
+ if (chatMsg.getSenderId().equals(otherUserId)) {
|
|
|
|
+ chatMsg.setSenderAnonName(newAnonName);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (chatMsg.getReceiverId().equals(otherUserId)) {
|
|
|
|
+ chatMsg.setReceiverAnonName(newAnonName);
|
|
|
|
+ }
|
|
|
|
+ chatMsg.setUpdateBy(SecurityUtils.getUserId());
|
|
|
|
+ chatMsg.setUpdateTime(DateUtils.parseDate(DateUtils.getDate()));
|
|
|
|
+ }
|
|
|
|
+ communityChatMsgService.updateBatchById(chatMsgList);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ System.out.println(e.getMessage());
|
|
|
|
+ throw new ProjectException();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return success("更新成功!");
|
|
|
|
+ }
|
|
}
|
|
}
|