caolinxuan 1 week ago
parent
commit
a776c73daf

+ 11 - 0
src/main/java/com/zhentao/ImApplication.java

@@ -1,8 +1,12 @@
 package com.zhentao;
 package com.zhentao;
 
 
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import org.mybatis.spring.annotation.MapperScan;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
 
 
 @SpringBootApplication
 @SpringBootApplication
 @MapperScan("com.zhentao.*.mapper")
 @MapperScan("com.zhentao.*.mapper")
@@ -11,5 +15,12 @@ public class ImApplication {
     public static void main(String[] args){
     public static void main(String[] args){
         SpringApplication.run(ImApplication.class, args);
         SpringApplication.run(ImApplication.class, args);
     }
     }
+    @Bean
+    public MybatisPlusInterceptor mybatisPlusInterceptor() {
+        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); // 如果配置多个插件, 切记分页最后添加
+        // 如果有多数据源可以不配具体类型, 否则都建议配上具体的 DbType
+        return interceptor;
+    }
 
 
 }
 }

+ 12 - 0
src/main/java/com/zhentao/config/JacksonConfig.java

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
 import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
 
 
 @Configuration
 @Configuration
 public class JacksonConfig {
 public class JacksonConfig {
@@ -20,4 +21,15 @@ public class JacksonConfig {
 
 
         return objectMapper;
         return objectMapper;
     }
     }
+    @Bean
+    public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
+        SimpleModule module = new SimpleModule();
+        // 全局配置Long和Long.TYPE序列化为字符串
+        module.addSerializer(Long.class, ToStringSerializer.instance);
+        module.addSerializer(Long.TYPE, ToStringSerializer.instance);
+
+        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
+        converter.getObjectMapper().registerModule(module);
+        return converter;
+    }
 }
 }

+ 1 - 0
src/main/java/com/zhentao/intercepoter/Userinterceptor.java

@@ -21,6 +21,7 @@ public class Userinterceptor implements HandlerInterceptor {
         HandlerMethod handlerMethod = (HandlerMethod) handler;
         HandlerMethod handlerMethod = (HandlerMethod) handler;
         NullLogin annotation = handlerMethod.getMethod().getAnnotation(NullLogin.class);
         NullLogin annotation = handlerMethod.getMethod().getAnnotation(NullLogin.class);
         System.err.println("自定义注解"+annotation);
         System.err.println("自定义注解"+annotation);
+        System.err.println(request.getRequestURI());
         if (annotation!=null){
         if (annotation!=null){
             return true;
             return true;
         }
         }

+ 13 - 4
src/main/java/com/zhentao/moment/controller/MonmentController.java

@@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartFile;
 
 
+import java.io.IOException;
 import java.util.List;
 import java.util.List;
 
 
 @RestController
 @RestController
@@ -47,14 +48,14 @@ public class MonmentController {
         return Result.OK(userMomentsService.getFriendMonment(Long.valueOf(uid)),"查询成功");
         return Result.OK(userMomentsService.getFriendMonment(Long.valueOf(uid)),"查询成功");
     }
     }
 //    点赞接口
 //    点赞接口
-    @RequestMapping("likeMonment")
+    @RequestMapping(value = "likeMonment",produces = "application/json;charset=UTF-8")
     public Result likeMonment(@RequestHeader String token,@RequestBody MonmentDto monmentDto){
     public Result likeMonment(@RequestHeader String token,@RequestBody MonmentDto monmentDto){
         String uid = TokenUtils.getUserIdFromToken(token);
         String uid = TokenUtils.getUserIdFromToken(token);
         monmentDto.setUid(Long.valueOf(uid));
         monmentDto.setUid(Long.valueOf(uid));
         return userMomentsService.likeMonment(Long.valueOf(uid),monmentDto);
         return userMomentsService.likeMonment(Long.valueOf(uid),monmentDto);
     }
     }
     //  评论朋友圈
     //  评论朋友圈
-    @RequestMapping("commentMonment")
+    @RequestMapping(value = "commentMonment",produces = "application/json;charset=UTF-8")
     public Result commentMonment(@RequestHeader String token, @RequestBody CommentsDto commentsDto){
     public Result commentMonment(@RequestHeader String token, @RequestBody CommentsDto commentsDto){
         String uid = TokenUtils.getUserIdFromToken(token);
         String uid = TokenUtils.getUserIdFromToken(token);
         commentsDto.setUserId(Long.valueOf(uid));
         commentsDto.setUserId(Long.valueOf(uid));
@@ -74,11 +75,19 @@ public class MonmentController {
         commentsDto.setUserId(Long.valueOf(uid));
         commentsDto.setUserId(Long.valueOf(uid));
         return userMomentsService.commentList(Long.valueOf(uid),commentsDto);
         return userMomentsService.commentList(Long.valueOf(uid),commentsDto);
     }
     }
+
+//    合并所有接口,分页查询
+    @RequestMapping("allListPage")
+    public Result allListPage(@RequestHeader String token,@RequestBody MonmentDto monmentDto){
+        String uid = TokenUtils.getUserIdFromToken(token);
+        monmentDto.setUid(Long.valueOf(uid));
+        return userMomentsService.allListPage(Long.valueOf(uid),monmentDto);
+    }
 //    更改朋友圈背景图
 //    更改朋友圈背景图
     @RequestMapping("updateBackground")
     @RequestMapping("updateBackground")
-    public Result updateBackground(@RequestHeader String token,@RequestParam("file") MultipartFile file){
+    public Result updateBackground(@RequestHeader String token,@RequestParam("file") MultipartFile file) throws IOException {
         String uid = TokenUtils.getUserIdFromToken(token);
         String uid = TokenUtils.getUserIdFromToken(token);
         return userMomentsService.updateBackground(Long.valueOf(uid),file);
         return userMomentsService.updateBackground(Long.valueOf(uid),file);
     }
     }
-//    11111
+
 }
 }

+ 1 - 0
src/main/java/com/zhentao/moment/domain/MomentComments.java

@@ -52,6 +52,7 @@ public class MomentComments implements Serializable {
     /**
     /**
      *
      *
      */
      */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
     private Date createdAt;
     private Date createdAt;
 
 
     @TableField(exist = false)
     @TableField(exist = false)

+ 1 - 0
src/main/java/com/zhentao/moment/domain/MomentLikes.java

@@ -37,6 +37,7 @@ public class MomentLikes implements Serializable {
     /**
     /**
      *
      *
      */
      */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
     private Date createdAt;
     private Date createdAt;
 
 
     @TableField(exist = false)
     @TableField(exist = false)

+ 5 - 1
src/main/java/com/zhentao/moment/domain/MomentMedias.java

@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
 import java.io.Serializable;
 import java.io.Serializable;
 
 
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import lombok.Data;
 import lombok.Data;
 
 
 /**
 /**
@@ -25,7 +27,9 @@ public class MomentMedias implements Serializable {
     /**
     /**
      * 动态ID
      * 动态ID
      */
      */
-    @JsonFormat(shape = JsonFormat.Shape.STRING)
+//    @JsonFormat(shape = JsonFormat.Shape.STRING)
+    // 使用JsonSerialize指定序列化方式为字符串
+    @JsonSerialize(using = ToStringSerializer.class)
     private Long momentId;
     private Long momentId;
 
 
     /**
     /**

+ 2 - 0
src/main/java/com/zhentao/moment/domain/UserMoments.java

@@ -56,6 +56,8 @@ public class UserMoments implements Serializable {
     /**
     /**
      *
      *
      */
      */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
+
     private Date createdAt;
     private Date createdAt;
 
 
     /**
     /**

+ 0 - 1
src/main/java/com/zhentao/moment/dto/CommentsDto.java

@@ -10,7 +10,6 @@ public class CommentsDto {
 
 
     private Long commentId;
     private Long commentId;
     private Long userId;
     private Long userId;
-//    @JsonFormat(shape = JsonFormat.Shape.STRING)
     private String momentId;
     private String momentId;
     private String content;
     private String content;
     private Long replyTo;//回复的朋友圈id
     private Long replyTo;//回复的朋友圈id

+ 6 - 2
src/main/java/com/zhentao/moment/dto/MonmentDto.java

@@ -4,11 +4,15 @@ import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 import lombok.Data;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartFile;
 
 
+import java.io.Serializable;
 import java.util.List;
 import java.util.List;
 
 
 @Data
 @Data
-public class MonmentDto {
-//    @JsonFormat(shape = JsonFormat.Shape.STRING)
+public class MonmentDto  {
+
+//    private List<Long> momentIds;
+    private Integer currentPage;
+    private Integer pageSize;
     private String momentId;
     private String momentId;
     private Long uid;
     private Long uid;
     private Integer visible;//是否可见  1公开  2好友 3自己
     private Integer visible;//是否可见  1公开  2好友 3自己

+ 5 - 1
src/main/java/com/zhentao/moment/service/UserMomentsService.java

@@ -7,7 +7,9 @@ import com.zhentao.moment.dto.MonmentDto;
 import com.zhentao.vo.Result;
 import com.zhentao.vo.Result;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartFile;
 
 
+import java.io.IOException;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 /**
 /**
 * @author 86159
 * @author 86159
@@ -34,5 +36,7 @@ public interface UserMomentsService extends IService<UserMoments> {
     //  查询评论列表
     //  查询评论列表
     Result commentList(Long valueOf, CommentsDto commentsDto);
     Result commentList(Long valueOf, CommentsDto commentsDto);
     //    更改朋友圈背景图
     //    更改朋友圈背景图
-    Result updateBackground(Long valueOf, MultipartFile file);
+    Result updateBackground(Long userId, MultipartFile file) throws IOException;
+//    查询全部列表
+    Result allListPage(Long userId, MonmentDto monmentDto);
 }
 }

+ 253 - 6
src/main/java/com/zhentao/moment/service/impl/UserMomentsServiceImpl.java

@@ -4,6 +4,7 @@ import com.aliyun.oss.OSSClient;
 import com.aliyun.oss.model.ObjectMetadata;
 import com.aliyun.oss.model.ObjectMetadata;
 import com.aliyun.oss.model.PutObjectRequest;
 import com.aliyun.oss.model.PutObjectRequest;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zhentao.moment.domain.MomentComments;
 import com.zhentao.moment.domain.MomentComments;
 import com.zhentao.moment.domain.MomentLikes;
 import com.zhentao.moment.domain.MomentLikes;
@@ -35,8 +36,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartFile;
 
 
 import java.io.IOException;
 import java.io.IOException;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.*;
+import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 
 /**
 /**
 * @author 86159
 * @author 86159
@@ -53,8 +57,8 @@ public class UserMomentsServiceImpl extends ServiceImpl<UserMomentsMapper, UserM
     private UserLoginMapper userLoginMapper;
     private UserLoginMapper userLoginMapper;
     @Autowired
     @Autowired
     private MomentLikesMapper momentLikesMapper;
     private MomentLikesMapper momentLikesMapper;
-//    @Autowired
-//    private OSSClient ossClient;
+    @Autowired
+    private OssUtil ossUtil;
     @Autowired
     @Autowired
     private OssConfig ossConfig;
     private OssConfig ossConfig;
     @Autowired
     @Autowired
@@ -291,7 +295,7 @@ public class UserMomentsServiceImpl extends ServiceImpl<UserMomentsMapper, UserM
    //  点赞朋友圈
    //  点赞朋友圈
     @Override
     @Override
     public Result likeMonment(Long uid, MonmentDto monmentDto) {
     public Result likeMonment(Long uid, MonmentDto monmentDto) {
-
+        System.err.println("赞"+monmentDto.getMomentId());
         if (monmentDto.getMomentId()==null){
         if (monmentDto.getMomentId()==null){
             return Result.error(400,"请选择要点赞的朋友圈");
             return Result.error(400,"请选择要点赞的朋友圈");
         }
         }
@@ -317,7 +321,7 @@ public class UserMomentsServiceImpl extends ServiceImpl<UserMomentsMapper, UserM
     //  评论朋友圈
     //  评论朋友圈
     @Override
     @Override
     public Result commentsMonment(Long userId, CommentsDto commentsDto) {
     public Result commentsMonment(Long userId, CommentsDto commentsDto) {
-        System.err.println(commentsDto.getMomentId());
+        System.err.println("轮"+commentsDto.getMomentId());
         MomentComments momentComments = new MomentComments();
         MomentComments momentComments = new MomentComments();
         momentComments.setUserId(userId);
         momentComments.setUserId(userId);
         momentComments.setCommentId(SnowflakeUtil.nextId());
         momentComments.setCommentId(SnowflakeUtil.nextId());
@@ -416,12 +420,255 @@ public class UserMomentsServiceImpl extends ServiceImpl<UserMomentsMapper, UserM
     }
     }
     //    更改朋友圈背景图
     //    更改朋友圈背景图
     @Override
     @Override
-    public Result updateBackground(Long valueOf, MultipartFile file) {
+    public Result updateBackground(Long userId, MultipartFile file) throws IOException {
+        String ossUrl = ossUtil.uploadFile(file);
+        UserLogin userLogin=new UserLogin();
+        userLogin.setId(userId);
+        userLogin.setLabelList(ossUrl);
+        userLoginMapper.updateById(userLogin);
+        return Result.OK(ossUrl,"修改成功");
+    }
+
+
+    @Override
+    public Result allListPage(Long userId, MonmentDto monmentDto) {
+        try {
+            // 1. 校验用户ID
+            if (userId == null) {
+                return Result.error(400, "用户ID不能为空");
+            }
+
+            // 2. 查询个人信息
+            UserLogin userLogin = userLoginMapper.selectById(userId);
+            if (userLogin == null) {
+                return Result.error(404, "用户信息不存在");
+            }
 
 
-        return null;
+            // 3. 查询好友关系
+            QueryWrapper<UserRelationships> friendRelQuery = new QueryWrapper<>();
+            friendRelQuery.eq("user_id", userId)
+                    .eq("status", 1)
+                    .eq("is_blacklist", 0)
+                    .eq("is_del", 0)
+                    .eq("is_moments", 0)
+                    .orderByDesc("created_at");
+            List<UserRelationships> friendRelationships = userRelationshipsMapper.selectList(friendRelQuery);
+            List<Long> friendIds = friendRelationships.stream()
+                    .map(UserRelationships::getFriendId)
+                    .collect(Collectors.toList());
+
+            // 4. 合并查询当前用户和好友的动态(真正的分页实现)
+            Page<UserMoments> allMomentsPage = new Page<>(monmentDto.getCurrentPage(), monmentDto.getPageSize());
+            QueryWrapper<UserMoments> allMomentQuery = new QueryWrapper<>();
+
+            // 如果有好友,查询自己和好友的动态;否则只查询自己的
+            if (!friendIds.isEmpty()) {
+                allMomentQuery.in("user_id", Stream.concat(
+                        Stream.of(userId),
+                        friendIds.stream()
+                ).collect(Collectors.toList()));
+            } else {
+                allMomentQuery.eq("user_id", userId);
+            }
+
+            // 排除仅自己可见的动态(除了自己发布的)
+            allMomentQuery.and(wrapper ->
+                    wrapper.eq("user_id", userId)
+                            .or()
+                            .ne("visibility", 2)
+            );
+
+            // 按创建时间降序排列
+            allMomentQuery.orderByDesc("created_at");
+
+            // 执行分页查询
+            userMomentsMapper.selectPage(allMomentsPage, allMomentQuery);
+            List<UserMoments> allUserMoments = allMomentsPage.getRecords();
+
+            // 5. 提取所有动态相关用户ID
+            Set<Long> allUserIds = allUserMoments.stream()
+                    .map(UserMoments::getUserId)
+                    .collect(Collectors.toSet());
+
+            // 6. 批量查询所有动态相关用户信息
+            QueryWrapper<UserLogin> userQuery = new QueryWrapper<>();
+            userQuery.in("id", allUserIds);
+            List<UserLogin> users = userLoginMapper.selectList(userQuery);
+            Map<Long, UserLogin> userMap = users.stream()
+                    .collect(Collectors.toMap(UserLogin::getId, user -> user));
+
+            // 7. 处理动态数据,添加用户信息
+            List<Map<String, Object>> momentList = allUserMoments.stream()
+                    .map(moment -> wrapMomentWithUser(moment, userMap))
+                    .collect(Collectors.toList());
+
+            // 8. 提取所有动态ID,用于查询点赞和评论
+            List<Long> allMomentIds = allUserMoments.stream()
+                    .map(UserMoments::getMomentId)
+                    .collect(Collectors.toList());
+
+            if (allMomentIds.isEmpty()) {
+                // 没有动态时直接返回
+                Map<String, Object> resultMap = new HashMap<>();
+                resultMap.put("userInfo", userLogin);
+                resultMap.put("moments", momentList);
+                resultMap.put("allLikesAndComments", new HashMap<>());
+                resultMap.put("total", allMomentsPage.getTotal());
+                resultMap.put("currentPage", allMomentsPage.getCurrent());
+                resultMap.put("pageSize", allMomentsPage.getSize());
+                resultMap.put("totalPages", allMomentsPage.getPages());
+                return Result.OK(resultMap, "查询成功");
+            }
+
+            // 9. 批量查询所有动态的点赞和评论
+            Map<Long, Object> allLikesAndComments = new HashMap<>();
+            for (Long momentId : allMomentIds) {
+                Map<String, Object> momentInfo = new HashMap<>();
+
+                // 查询点赞
+                QueryWrapper<MomentLikes> likeQuery = new QueryWrapper<>();
+                likeQuery.eq("moment_id", momentId);
+                List<MomentLikes> likes = momentLikesMapper.selectList(likeQuery);
+
+                // 查询评论
+                QueryWrapper<MomentComments> commentQuery = new QueryWrapper<>();
+                commentQuery.eq("moment_id", momentId)
+                        .orderByDesc("created_at");
+                List<MomentComments> comments = momentCommentsMapper.selectList(commentQuery);
+
+                // 提取点赞和评论涉及的用户ID
+                Set<Long> likeCommentUserIds = new HashSet<>();
+                likes.forEach(like -> likeCommentUserIds.add(like.getUserId()));
+                comments.forEach(comment -> {
+                    likeCommentUserIds.add(comment.getUserId());
+                    if (comment.getReplyToUser() != null) {
+                        likeCommentUserIds.add(comment.getReplyToUser());
+                    }
+                });
+
+                // 批量查询用户信息
+                List<UserLogin> likeCommentUsers = new ArrayList<>();
+                if (!likeCommentUserIds.isEmpty()) {
+                    likeCommentUsers = userLoginMapper.selectBatchIds(likeCommentUserIds);
+                }
+                Map<Long, UserLogin> likeCommentUserMap = likeCommentUsers.stream()
+                        .collect(Collectors.toMap(UserLogin::getId, user -> user));
+
+                // 处理点赞数据,统一使用字符串格式的时间
+                List<Map<String, Object>> likeList = likes.stream()
+                        .map(like -> {
+                            Map<String, Object> likeInfo = new HashMap<>();
+                            likeInfo.put("id", like.getLikeId());
+                            likeInfo.put("userId", like.getUserId());
+
+                            if (like.getCreatedAt() != null) {
+                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                                likeInfo.put("createTime", sdf.format(like.getCreatedAt()));
+                            }
+
+                            // 手动构建用户信息,只包含必要字段
+                            UserLogin user = likeCommentUserMap.get(like.getUserId());
+                            if (user != null) {
+                                Map<String, Object> userInfo = new HashMap<>();
+                                userInfo.put("id", user.getId());
+                                userInfo.put("nickName", user.getNickName());
+                                userInfo.put("avatar", user.getAvatar());
+                                userInfo.put("username", user.getUserUsername());
+                                likeInfo.put("userInfo", userInfo);
+                            }
+                            return likeInfo;
+                        })
+                        .collect(Collectors.toList());
+
+                // 处理评论数据,统一使用字符串格式的时间
+                List<Map<String, Object>> commentList = comments.stream()
+                        .map(comment -> {
+                            Map<String, Object> commentInfo = new HashMap<>();
+                            commentInfo.put("id", comment.getCommentId());
+                            commentInfo.put("userId", comment.getUserId());
+                            commentInfo.put("content", comment.getContent());
+
+                            // 统一转换为字符串格式
+                            if (comment.getCreatedAt() != null) {
+                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                                commentInfo.put("createdAt", sdf.format(comment.getCreatedAt()));
+                            }
+
+                            commentInfo.put("replyTo", comment.getReplyTo());
+                            commentInfo.put("replyToUser", comment.getReplyToUser());
+
+                            UserLogin user = likeCommentUserMap.get(comment.getUserId());
+                            if (user != null) {
+                                Map<String, Object> userInfo = new HashMap<>();
+                                userInfo.put("id", user.getId());
+                                userInfo.put("username", user.getUserUsername());
+                                userInfo.put("avatar", user.getAvatar());
+                                commentInfo.put("userInfo", userInfo);
+                            }
+                            return commentInfo;
+                        })
+                        .collect(Collectors.toList());
+
+                // 封装点赞评论信息
+                momentInfo.put("likeList", likeList);
+                momentInfo.put("commentList", commentList);
+                momentInfo.put("likeCount", likeList.size());
+                momentInfo.put("commentCount", commentList.size());
+
+                allLikesAndComments.put(momentId, momentInfo);
+            }
+
+            // 10. 封装最终结果
+            Map<String, Object> resultMap = new HashMap<>();
+            resultMap.put("userInfo", userLogin);
+            resultMap.put("moments", momentList);
+            resultMap.put("allLikesAndComments", allLikesAndComments);
+            resultMap.put("total", allMomentsPage.getTotal());
+            resultMap.put("currentPage", allMomentsPage.getCurrent());
+            resultMap.put("pageSize", allMomentsPage.getSize());
+            resultMap.put("totalPages", allMomentsPage.getPages());
+
+            return Result.OK(resultMap, "查询成功");
+        } catch (Exception e) {
+            log.error("综合朋友圈查询异常: {}", e.getMessage(), e);
+            return Result.error(500, "查询失败");
+        }
     }
     }
 
 
+    /**
+     * 封装动态数据并关联用户信息,确保包含momentId
+     */
+    private Map<String, Object> wrapMomentWithUser(UserMoments moment, Map<Long, UserLogin> userMap) {
+        Map<String, Object> momentMap = new HashMap<>();
+
+        // 手动添加所有需要的字段,确保momentId存在
+        momentMap.put("momentId", moment.getMomentId().toString());
+        momentMap.put("contentType", moment.getContentType());
+        momentMap.put("url", moment.getUrl());
+        momentMap.put("content", moment.getContent());
+        momentMap.put("location", moment.getLocation());
+        momentMap.put("visibility", moment.getVisibility());
+
+        // 转换日期为字符串格式
+        if (moment.getCreatedAt() != null) {
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            momentMap.put("createdAt", sdf.format(moment.getCreatedAt()));
+        }
 
 
+        // 手动添加用户信息,只包含必要字段
+        UserLogin user = userMap.get(moment.getUserId());
+        if (user != null) {
+            Map<String, Object> userInfo = new HashMap<>();
+            userInfo.put("id", user.getId());
+            userInfo.put("nickName", user.getNickName());
+            userInfo.put("avatar", user.getAvatar());
+            userInfo.put("username", user.getUserUsername());
+            momentMap.put("userInfo", userInfo);
+        }
+
+        momentMap.put("isSelf", user != null && user.getId().equals(moment.getUserId()));
+        return momentMap;
+    }
     /**
     /**
     * 上传到oss
     * 上传到oss
     * */
     * */

+ 3 - 0
src/main/java/com/zhentao/user/domain/UserLogin.java

@@ -8,6 +8,7 @@ import java.io.Serializable;
 import java.util.Date;
 import java.util.Date;
 
 
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import lombok.Data;
 import lombok.Data;
 
 
 /**
 /**
@@ -32,11 +33,13 @@ public class UserLogin implements Serializable {
     /**
     /**
      * 密码
      * 密码
      */
      */
+    @JsonIgnore
     private String userPassword;
     private String userPassword;
 
 
     /**
     /**
      * 盐
      * 盐
      */
      */
+    @JsonIgnore
     private String salt;
     private String salt;
 
 
     /**
     /**

+ 10 - 3
src/main/resources/application.yml

@@ -7,13 +7,17 @@ netty:
 spring:
 spring:
   application:
   application:
     name: im-server
     name: im-server
+  servlet:
+    multipart:
+      max-file-size: 20971520
+      max-request-size: 20971520
 
 
   # MySQL配置
   # MySQL配置
   datasource:
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
     driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://47.110.46.22:3306/IM?useSSL=false&useServerTime=UTC
+    url: jdbc:mysql://101.200.59.170:3306/IM?useSSL=false&useServerTime=UTC
     username: root
     username: root
-    password: Fengjaijia0610
+    password: liziyang
 
 
   # JPA配置
   # JPA配置
   jpa:
   jpa:
@@ -32,7 +36,7 @@ spring:
       port: 27017
       port: 27017
       database: im_db
       database: im_db
   redis:
   redis:
-    host: 47.110.46.22
+    host: 101.200.59.170
     port: 6379
     port: 6379
     database: 0
     database: 0
 aliyun:
 aliyun:
@@ -48,3 +52,6 @@ aliyun:
       video:
       video:
         dir: moments/videos/                 # 视频上传目录
         dir: moments/videos/                 # 视频上传目录
         maxSize: 52428800
         maxSize: 52428800
+mybatis-plus:
+  configuration:
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl