diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/algorithm/PostSelector.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/algorithm/PostSelector.java index 0fef6aa..1e65b2d 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/algorithm/PostSelector.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/algorithm/PostSelector.java @@ -35,7 +35,8 @@ public class PostSelector { double newScore = (1 + likes + comments*0.7 + favorites*0.5) / Math.pow(1 + hours/24.0, 1.8); - redisUtil.zAdd("post:hot:", post.getId(), newScore); + redisUtil.zAdd("post:hot:"+post.getCategoryId(), post.getId(), newScore); + redisUtil.zAdd("post:hot:all", post.getId(), newScore); } public void calculateCommentScore(Comment comment){ diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/req/PostPageQueryDTO.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/req/PostPageQueryDTO.java index e2ef571..75d6f19 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/req/PostPageQueryDTO.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/req/PostPageQueryDTO.java @@ -14,4 +14,6 @@ public class PostPageQueryDTO extends ScrollPageRequest { @Schema(title = "排序类型,0表示按时间,1表示按热度,2表示自定义的推荐算法(暂未实现)") private Integer type = 0; + + private Long categoryId; } diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/resp/PostBasicInfoDTO.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/resp/PostBasicInfoDTO.java index 6b819ac..7c3d95a 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/resp/PostBasicInfoDTO.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/resp/PostBasicInfoDTO.java @@ -77,5 +77,8 @@ public class PostBasicInfoDTO { @Schema( description = "帖子创建时间" ) + + private Long categoryId; + private LocalDateTime createTime; } diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/resp/PostInfoDTO.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/resp/PostInfoDTO.java index d0f8d90..1203b40 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/resp/PostInfoDTO.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/resp/PostInfoDTO.java @@ -82,5 +82,8 @@ public class PostInfoDTO { @Schema( description = "帖子创建时间" ) + + private Long categoryId; + private LocalDateTime createTime; } diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/PostServiceImpl.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/PostServiceImpl.java index 6e5a71b..b2ec4ab 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/PostServiceImpl.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/PostServiceImpl.java @@ -91,7 +91,8 @@ public class PostServiceImpl extends ServiceImpl implements Po // TODO 消息通知? } postSelector.calculatePostScore(post); - redisUtil.zAdd("post:time:", post.getId(), System.currentTimeMillis()); + redisUtil.zAdd("post:time:"+post.getCategoryId(), post.getId(), System.currentTimeMillis()); + redisUtil.zAdd("post:time:"+"all", post.getId(), System.currentTimeMillis()); redisUtil.zAdd("post:user:" + userId, post.getId(), System.currentTimeMillis()); return post.getId(); } @@ -119,6 +120,7 @@ public class PostServiceImpl extends ServiceImpl implements Po public void deletePost(Long id) { validatePostUtil.validatePostOwnership(id); Long userId = UserContext.getUserId(); + Post post = postMapper.selectById(id); int delete = postMapper.deleteById(id); if(delete <= 0){ throw new PostException("删除帖子失败"); @@ -126,8 +128,10 @@ public class PostServiceImpl extends ServiceImpl implements Po // redisUtil.delete("post:detail:" + id.toString()); // redisUtil.delete("post:of:user:" + UserContext.getUserId()); redisUtil.delete("post:detail:" + id); - redisUtil.zRemove("post:time:", id); - redisUtil.zRemove("post:hot:", id); + redisUtil.zRemove("post:time:"+post.getCategoryId(), id); + redisUtil.zRemove("post:hot:"+post.getCategoryId(), id); + redisUtil.zRemove("post:time:"+"all", id); + redisUtil.zRemove("post:hot:"+"all", id); redisUtil.zRemove("post:user:" + userId, id); } @@ -184,7 +188,12 @@ public class PostServiceImpl extends ServiceImpl implements Po return postBasicInfoDTO; }); */ - String key = postPageQueryDTO.getType().equals(0) ? "post:time:" : "post:hot:"; + String key; + if(postPageQueryDTO.getCategoryId() == null || postPageQueryDTO.getCategoryId().equals(0L)){ + key = (postPageQueryDTO.getType().equals(0) ? "post:time:" : "post:hot:") + "all"; + }else { + key = (postPageQueryDTO.getType().equals(0) ? "post:time:" : "post:hot:") + postPageQueryDTO.getCategoryId(); + } return redisUtil.scrollPageQuery(key, PostBasicInfoDTO.class, postPageQueryDTO, (postIds) -> { List userIds = new ArrayList<>(); diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application-local.yaml b/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application-local.yaml index 00a8f8c..bf3ca89 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application-local.yaml +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application-local.yaml @@ -1,21 +1,20 @@ -##本地开发环境 -#lj: -# db: -# host: 192.168.59.129 -# password: Forely123! -# redis: -# host: 192.168.59.129 -# port: 6379 -# password: Forely123! -# rabbitmq: -# host: 192.168.59.129 -# port: 5672 -# username: admin -# password: Forely123! -# minio: -# endpoint: http://192.168.59.129:9000 -# accessKey: forely -# secretKey: Forely123! +lj: + db: + host: 192.168.59.129 + password: Forely123! + redis: + host: 192.168.59.129 + port: 6379 + password: Forely123! + rabbitmq: + host: 192.168.59.129 + port: 5672 + username: admin + password: Forely123! + minio: + endpoint: http://192.168.59.129:9000 + accessKey: forely + secretKey: Forely123! #lj: # db: @@ -35,20 +34,20 @@ # accessKey: minio_admin # secretKey: Minio@1234 -lj: - db: - host: localhost - password: 123456 - redis: - host: localhost - port: 6379 - password: 123456 - rabbitmq: - host: localhost - port: 5672 - username: guest - password: guest - minio: - endpoint: http://localhost:9005 - accessKey: leezt - secretKey: lzt264610 +#lj: +# db: +# host: localhost +# password: 123456 +# redis: +# host: localhost +# port: 6379 +# password: 123456 +# rabbitmq: +# host: localhost +# port: 5672 +# username: guest +# password: guest +# minio: +# endpoint: http://localhost:9005 +# accessKey: leezt +# secretKey: lzt264610 diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application.yaml b/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application.yaml index 4ac786d..190763d 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application.yaml +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application.yaml @@ -49,6 +49,10 @@ spring: concurrency: 5 max-concurrency: 10 prefetch: 1 + servlet: + multipart: + max-file-size: 10MB + max-request-size: 10MB # minio配置 minio: endpoint: ${lj.minio.endpoint}