|
@@ -20,7 +20,9 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author 26621
|
|
* @author 26621
|
|
@@ -150,6 +152,77 @@ public class ChatFriendServiceImpl extends ServiceImpl<ChatFriendMapper, ChatFri
|
|
|
return this.updateById(chatFriend);
|
|
return this.updateById(chatFriend);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean updateRemark(Long userId, Long friendId, String remark) {
|
|
|
|
|
+ // 1. 查询好友关系记录
|
|
|
|
|
+ LambdaQueryWrapper<ChatFriend> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq(ChatFriend::getUserId, userId)
|
|
|
|
|
+ .eq(ChatFriend::getFriendId, friendId)
|
|
|
|
|
+ .eq(ChatFriend::getIsDeleted, 0); // 未删除的记录
|
|
|
|
|
+
|
|
|
|
|
+ ChatFriend chatFriend = this.getOne(queryWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ if (chatFriend == null) {
|
|
|
|
|
+ // 如果不存在好友关系,创建一个新的记录
|
|
|
|
|
+ chatFriend = new ChatFriend();
|
|
|
|
|
+ chatFriend.setUserId(userId);
|
|
|
|
|
+ chatFriend.setFriendId(friendId);
|
|
|
|
|
+ chatFriend.setFriendName(remark);
|
|
|
|
|
+ chatFriend.setStatus(1); // 正常状态
|
|
|
|
|
+ chatFriend.setIsDeleted(0);
|
|
|
|
|
+ chatFriend.setCreateTime(new Date());
|
|
|
|
|
+ chatFriend.setUpdateTime(new Date());
|
|
|
|
|
+ return this.save(chatFriend);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 更新现有记录的备注
|
|
|
|
|
+ chatFriend.setFriendName(remark);
|
|
|
|
|
+ chatFriend.setUpdateTime(new Date());
|
|
|
|
|
+ return this.updateById(chatFriend);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<Map<String, Object>> batchGetRemarks(Long userId, List<String> friendIds) {
|
|
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ if (friendIds == null || friendIds.isEmpty()) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 转换friendIds为Long类型
|
|
|
|
|
+ List<Long> friendIdList = new ArrayList<>();
|
|
|
|
|
+ for (String friendId : friendIds) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ friendIdList.add(Long.parseLong(friendId));
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ // 忽略无效的ID
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (friendIdList.isEmpty()) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 批量查询备注
|
|
|
|
|
+ LambdaQueryWrapper<ChatFriend> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq(ChatFriend::getUserId, userId)
|
|
|
|
|
+ .in(ChatFriend::getFriendId, friendIdList)
|
|
|
|
|
+ .eq(ChatFriend::getIsDeleted, 0)
|
|
|
|
|
+ .isNotNull(ChatFriend::getFriendName);
|
|
|
|
|
+
|
|
|
|
|
+ List<ChatFriend> chatFriends = this.list(queryWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ // 转换为Map格式
|
|
|
|
|
+ for (ChatFriend chatFriend : chatFriends) {
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("friendId", chatFriend.getFriendId().toString());
|
|
|
|
|
+ map.put("friendName", chatFriend.getFriendName());
|
|
|
|
|
+ result.add(map);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
public void deleteChatConversation(BlockDto dto){
|
|
public void deleteChatConversation(BlockDto dto){
|