mazhenhang 3 settimane fa
parent
commit
caca39745d

+ 19 - 0
LiangZhiYUMao/pages/message/chat.vue

@@ -487,6 +487,25 @@ export default {
   },
 
   methods: {
+    /**
+     * 根据语音时长计算语音气泡宽度
+     */
+    getVoiceWidth(duration) {
+      // 基础宽度 120rpx,每秒增加 10rpx,最大 300rpx
+      const baseWidth = 120;
+      const perSecondWidth = 10;
+      const maxWidth = 300;
+      const minWidth = 120;
+      
+      const seconds = parseInt(duration) || 0;
+      let width = baseWidth + seconds * perSecondWidth;
+      
+      // 限制在最小和最大范围内
+      width = Math.max(minWidth, Math.min(maxWidth, width));
+      
+      return width + 'rpx';
+    },
+    
     /**
      * 红娘入口:根据当前登录用户ID获取红娘资料并设置头像
      */

+ 35 - 0
service/websocket/src/main/java/com/zhentao/controller/ChatFriendController.java

@@ -6,6 +6,7 @@ import com.zhentao.vo.ResultVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
 import java.util.Map;
 
 @RestController
@@ -57,4 +58,38 @@ public class ChatFriendController {
         }
     }
 
+    /**
+     * 更新好友备注
+     * @param params 包含userId、friendId、remark的JSON对象
+     * @return 操作结果
+     */
+    @PostMapping("/updateRemark")
+    public ResultVo updateRemark(@RequestBody Map<String, Object> params) {
+        Long userId = Long.parseLong(params.get("userId").toString());
+        Long friendId = Long.parseLong(params.get("friendId").toString());
+        String remark = params.get("remark").toString();
+        
+        boolean result = chatFriendService.updateRemark(userId, friendId, remark);
+        if (result) {
+            return ResultVo.success("备注更新成功");
+        } else {
+            return ResultVo.fail("备注更新失败");
+        }
+    }
+
+    /**
+     * 批量获取好友备注
+     * @param params 包含userId和friendIds的JSON对象
+     * @return 备注列表
+     */
+    @PostMapping("/batchGetRemarks")
+    public ResultVo batchGetRemarks(@RequestBody Map<String, Object> params) {
+        Long userId = Long.parseLong(params.get("userId").toString());
+        @SuppressWarnings("unchecked")
+        List<String> friendIds = (List<String>) params.get("friendIds");
+        
+        List<Map<String, Object>> remarks = chatFriendService.batchGetRemarks(userId, friendIds);
+        return ResultVo.success("查询成功", remarks);
+    }
+
 }

+ 7 - 0
service/websocket/src/main/java/com/zhentao/service/ChatFriendService.java

@@ -5,6 +5,9 @@ import com.zhentao.entity.ChatFriend;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.zhentao.vo.ResultVo;
 
+import java.util.List;
+import java.util.Map;
+
 /**
 * @author 26621
 * @description 针对表【chat_friend(好友关系表)】的数据库操作Service
@@ -21,4 +24,8 @@ public interface ChatFriendService extends IService<ChatFriend> {
     ResultVo getblocklist(Long userId);
 
     boolean removeFromBlacklist(Long userId, Long blockedUserId);
+
+    boolean updateRemark(Long userId, Long friendId, String remark);
+
+    List<Map<String, Object>> batchGetRemarks(Long userId, List<String> friendIds);
 }

+ 73 - 0
service/websocket/src/main/java/com/zhentao/service/impl/ChatFriendServiceImpl.java

@@ -20,7 +20,9 @@ import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
 * @author 26621
@@ -150,6 +152,77 @@ public class ChatFriendServiceImpl extends ServiceImpl<ChatFriendMapper, ChatFri
         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){