forked from iVMiku/guidance-backend
新增获赞收藏发布
This commit is contained in:
24
.idea/mybatisx/templates.xml
generated
24
.idea/mybatisx/templates.xml
generated
@@ -39,6 +39,26 @@
|
|||||||
<option name="modulePath" value="$PROJECT_DIR$/community-8073" />
|
<option name="modulePath" value="$PROJECT_DIR$/community-8073" />
|
||||||
<option name="packageName" value="mapper" />
|
<option name="packageName" value="mapper" />
|
||||||
</ModuleInfoGo>
|
</ModuleInfoGo>
|
||||||
|
<ModuleInfoGo>
|
||||||
|
<option name="basePath" value="${domain.basePath}" />
|
||||||
|
<option name="configFileName" value="serviceImpl.ftl" />
|
||||||
|
<option name="configName" value="serviceImpl" />
|
||||||
|
<option name="encoding" value="${domain.encoding}" />
|
||||||
|
<option name="fileName" value="${domain.fileName}ServiceImpl" />
|
||||||
|
<option name="fileNameWithSuffix" value="${domain.fileName}ServiceImpl.java" />
|
||||||
|
<option name="modulePath" value="$PROJECT_DIR$/community-8073" />
|
||||||
|
<option name="packageName" value="${domain.basePackage}.service.impl" />
|
||||||
|
</ModuleInfoGo>
|
||||||
|
<ModuleInfoGo>
|
||||||
|
<option name="basePath" value="${domain.basePath}" />
|
||||||
|
<option name="configFileName" value="serviceInterface.ftl" />
|
||||||
|
<option name="configName" value="serviceInterface" />
|
||||||
|
<option name="encoding" value="${domain.encoding}" />
|
||||||
|
<option name="fileName" value="${domain.fileName}Service" />
|
||||||
|
<option name="fileNameWithSuffix" value="${domain.fileName}Service.java" />
|
||||||
|
<option name="modulePath" value="$PROJECT_DIR$/community-8073" />
|
||||||
|
<option name="packageName" value="${domain.basePackage}.service" />
|
||||||
|
</ModuleInfoGo>
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
<option name="needsModel" value="true" />
|
<option name="needsModel" value="true" />
|
||||||
@@ -47,8 +67,8 @@
|
|||||||
<option name="tableUIInfoList">
|
<option name="tableUIInfoList">
|
||||||
<list>
|
<list>
|
||||||
<TableUIInfo>
|
<TableUIInfo>
|
||||||
<option name="className" value="Usercommunity" />
|
<option name="className" value="BrowingHistory" />
|
||||||
<option name="tableName" value="usercommunity" />
|
<option name="tableName" value="browing_history" />
|
||||||
</TableUIInfo>
|
</TableUIInfo>
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
|
|||||||
@@ -210,7 +210,6 @@ public class CommentController {
|
|||||||
public Result getPostComments(@PathVariable("postId") Long postId, @RequestBody Pages pages) {
|
public Result getPostComments(@PathVariable("postId") Long postId, @RequestBody Pages pages) {
|
||||||
logger.info("获取帖子ID:{}的评论列表", postId);
|
logger.info("获取帖子ID:{}的评论列表", postId);
|
||||||
logger.info("获取pageSize:{}", pages.getPageSize());
|
logger.info("获取pageSize:{}", pages.getPageSize());
|
||||||
System.out.println("aaaaaa" + pages.getPageSize());
|
|
||||||
IPage<Comment> comments = commentService.getPostComments(postId, pages.getPageNum(), pages.getPageSize());
|
IPage<Comment> comments = commentService.getPostComments(postId, pages.getPageNum(), pages.getPageSize());
|
||||||
return Result.ok(comments);
|
return Result.ok(comments);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.dev33.satoken.annotation.SaCheckLogin;
|
|||||||
import com.ivmiku.tutorial.entity.Community;
|
import com.ivmiku.tutorial.entity.Community;
|
||||||
import com.ivmiku.tutorial.response.Result;
|
import com.ivmiku.tutorial.response.Result;
|
||||||
import com.ivmiku.tutorial.service.CommunityService;
|
import com.ivmiku.tutorial.service.CommunityService;
|
||||||
|
import com.ivmiku.tutorial.service.CommunitytagService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.models.annotations.OpenAPI30;
|
import io.swagger.v3.oas.models.annotations.OpenAPI30;
|
||||||
import org.apiguardian.api.API;
|
import org.apiguardian.api.API;
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.ivmiku.tutorial.controller;
|
||||||
|
|
||||||
|
import com.ivmiku.tutorial.entity.Communitytag;
|
||||||
|
import com.ivmiku.tutorial.response.Result;
|
||||||
|
import com.ivmiku.tutorial.service.CommunitytagService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/communityTags")
|
||||||
|
public class CommunitytagController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CommunitytagService communitytagService;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
public Result createCommunityTag(@RequestBody Communitytag communityTag) {
|
||||||
|
communitytagService.createCommunityTag(communityTag);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update/{id}")
|
||||||
|
public Result updateCommunityTag(@PathVariable Long id, @RequestBody Communitytag communityTag) {
|
||||||
|
communitytagService.updateCommunityTag(id, communityTag);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
public Result deleteCommunityTag(@PathVariable Long id) {
|
||||||
|
communitytagService.deleteCommunityTag(id);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get/{id}")
|
||||||
|
public Result getCommunityTag(@PathVariable Long id) {
|
||||||
|
Communitytag communityTag = communitytagService.getCommunityTagById(id);
|
||||||
|
return Result.ok(communityTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list/{communityId}")
|
||||||
|
public Result getCommunityTagListByCommunityId(@PathVariable Long communityId) {
|
||||||
|
List<Communitytag> tags = communitytagService.getCommunityTagListByCommunityId(communityId);
|
||||||
|
return Result.ok(tags);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,12 +2,17 @@ package com.ivmiku.tutorial.controller;
|
|||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import cn.hutool.core.lang.hash.Hash;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.ivmiku.tutorial.entity.Post;
|
||||||
import com.ivmiku.tutorial.response.Result;
|
import com.ivmiku.tutorial.response.Result;
|
||||||
import com.ivmiku.tutorial.service.InteractionService;
|
import com.ivmiku.tutorial.service.InteractionService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* InteractionController 是处理用户与帖子的收藏、点赞以及对评论的点赞功能的控制器类。
|
* InteractionController 是处理用户与帖子的收藏、点赞以及对评论的点赞功能的控制器类。
|
||||||
@@ -104,4 +109,35 @@ public class InteractionController {
|
|||||||
interactionService.unlikeComment(userOpenid, commentId);
|
interactionService.unlikeComment(userOpenid, commentId);
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 我的收藏接口
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/getFavoritePosts")
|
||||||
|
public Result getFavoritePosts() {
|
||||||
|
String userOpenid = StpUtil.getLoginIdAsString();
|
||||||
|
log.info("用户 {} 正在获取收藏的帖子", userOpenid);
|
||||||
|
IPage<Post> favoritePost = interactionService.getFavoritePosts(userOpenid);
|
||||||
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
|
if (favoritePost != null) {
|
||||||
|
log.info("用户 {} 收藏的帖子获取成功", userOpenid);
|
||||||
|
data.put("total", favoritePost.getTotal());
|
||||||
|
data.put("list", favoritePost.getRecords());
|
||||||
|
return Result.ok(data);
|
||||||
|
}
|
||||||
|
return Result.ok("用户未发表帖子");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计我的获赞数量 笔记数量 收藏数量
|
||||||
|
*/
|
||||||
|
@GetMapping("/getLikeCount")
|
||||||
|
public Result getLikeCount() {
|
||||||
|
String userOpenid = StpUtil.getLoginIdAsString();
|
||||||
|
log.info("用户 {} 正在获取用户获赞的数量", userOpenid);
|
||||||
|
HashMap<String, Object> res = interactionService.getLikeCount(userOpenid);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 帖子控制器,用于处理帖子相关的HTTP请求。
|
* 帖子控制器,用于处理帖子相关的HTTP请求。
|
||||||
@@ -82,7 +84,8 @@ public class PostController {
|
|||||||
@GetMapping("/get/{id}")
|
@GetMapping("/get/{id}")
|
||||||
public Result getPost(@PathVariable Long id) {
|
public Result getPost(@PathVariable Long id) {
|
||||||
logger.info("开始获取帖子ID:{}的详细信息", id);
|
logger.info("开始获取帖子ID:{}的详细信息", id);
|
||||||
Post post = postService.getPostById(id); // 调用服务层根据ID查询帖子
|
String userId = StpUtil.getLoginIdAsString();
|
||||||
|
Post post = postService.getPostById(id, userId); // 调用服务层根据ID查询帖子
|
||||||
if (post != null) {
|
if (post != null) {
|
||||||
logger.info("帖子ID:{}的详细信息获取成功", id);
|
logger.info("帖子ID:{}的详细信息获取成功", id);
|
||||||
} else {
|
} else {
|
||||||
@@ -111,21 +114,24 @@ public class PostController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户获取自己所有帖子的信息
|
* 用户获取自己所有帖子的信息
|
||||||
* @return 当前用户帖子列表
|
* @return 当前用户帖子列表与该用户的总发布数量
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getPostList")
|
@GetMapping("/getPostList")
|
||||||
public Result getPostList(@RequestBody Pages pages) {
|
public Result getPostList(@RequestBody Pages pages) {
|
||||||
logger.info("开始获取帖子列表");
|
logger.info("开始获取帖子列表");
|
||||||
String userId = StpUtil.getLoginIdAsString(); // 获取当前登录用户的ID
|
String userId = StpUtil.getLoginIdAsString(); // 获取当前登录用户的ID
|
||||||
IPage<Post> posts = postService.getPostList(userId, pages.getPageNum(), pages.getPageSize());
|
IPage<Post> posts = postService.getPostList(userId, pages.getPageNum(), pages.getPageSize());
|
||||||
return Result.ok(posts); // 调用服务层获取帖子列表
|
Map<String, Object> data = new HashMap<>();
|
||||||
|
data.put("total", posts.getTotal());
|
||||||
|
data.put("posts", posts);
|
||||||
|
return Result.ok(data); // 调用服务层获取帖子列表
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 社区获取自己所有帖子的信息
|
* 社区获取自己所有帖子的信息
|
||||||
* @return 当前用户帖子列表
|
* @return 当前用户帖子列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getCommunityPostList{communityId}")
|
@GetMapping("/getCommunityPostList/{communityId}")
|
||||||
public Result getCommunityPostList(@PathVariable("communityId") Long communityId, @RequestBody Pages pages) {
|
public Result getCommunityPostList(@PathVariable("communityId") Long communityId, @RequestBody Pages pages) {
|
||||||
logger.info("开始获取帖子列表");
|
logger.info("开始获取帖子列表");
|
||||||
IPage<Post> posts = postService.getCommunityPostList(communityId, pages.getPageNum(), pages.getPageSize());
|
IPage<Post> posts = postService.getCommunityPostList(communityId, pages.getPageNum(), pages.getPageSize());
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.ivmiku.tutorial.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @TableName browing_history
|
||||||
|
*/
|
||||||
|
@TableName(value ="browing_history")
|
||||||
|
@Data
|
||||||
|
public class BrowingHistory implements Serializable {
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long browingId;
|
||||||
|
|
||||||
|
private String userOpenid;
|
||||||
|
|
||||||
|
|
||||||
|
private Long postId;
|
||||||
|
|
||||||
|
|
||||||
|
private Date createAt;
|
||||||
|
|
||||||
|
@TableLogic
|
||||||
|
private Integer isDelete;
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.ivmiku.tutorial.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @TableName communitytag
|
||||||
|
*/
|
||||||
|
@TableName(value ="communitytag")
|
||||||
|
@Data
|
||||||
|
public class Communitytag implements Serializable {
|
||||||
|
|
||||||
|
@TableId
|
||||||
|
private Long smallCTagId;
|
||||||
|
|
||||||
|
private String cTagName;
|
||||||
|
|
||||||
|
private Long cId;
|
||||||
|
|
||||||
|
private Integer isDelete;
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.ivmiku.tutorial.mapper;
|
||||||
|
|
||||||
|
import com.ivmiku.tutorial.entity.BrowingHistory;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author rog
|
||||||
|
* @description 针对表【browing_history】的数据库操作Mapper
|
||||||
|
* @createDate 2024-08-23 11:29:33
|
||||||
|
* @Entity com.ivmiku.tutorial.entity.BrowingHistory
|
||||||
|
*/
|
||||||
|
public interface BrowingHistoryMapper extends BaseMapper<BrowingHistory> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.ivmiku.tutorial.mapper;
|
||||||
|
|
||||||
|
import com.ivmiku.tutorial.entity.Communitytag;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author rog
|
||||||
|
* @description 针对表【communitytag】的数据库操作Mapper
|
||||||
|
* @createDate 2024-08-16 09:40:06
|
||||||
|
* @Entity com.ivmiku.tutorial.entity.Communitytag
|
||||||
|
*/
|
||||||
|
public interface CommunitytagMapper extends BaseMapper<Communitytag> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -2,6 +2,8 @@ package com.ivmiku.tutorial.mapper;
|
|||||||
|
|
||||||
import com.ivmiku.tutorial.entity.Likee;
|
import com.ivmiku.tutorial.entity.Likee;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author rog
|
* @author rog
|
||||||
@@ -11,6 +13,14 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||||||
*/
|
*/
|
||||||
public interface LikeMapper extends BaseMapper<Likee> {
|
public interface LikeMapper extends BaseMapper<Likee> {
|
||||||
|
|
||||||
|
// 获取帖子获赞数
|
||||||
|
@Select("SELECT SUM(like_count) FROM posts WHERE user_openid = #{userOpenid}")
|
||||||
|
Long getPostLikeCount(@Param("userOpenid") String userOpenid);
|
||||||
|
|
||||||
|
// 获取评论获赞数
|
||||||
|
@Select("SELECT SUM(like_count) FROM comments WHERE user_openid = #{userOpenid}")
|
||||||
|
Long getCommentLikeCount(@Param("userOpenid") String userOpenid);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.ivmiku.tutorial.service;
|
||||||
|
|
||||||
|
import com.ivmiku.tutorial.entity.BrowingHistory;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author rog
|
||||||
|
* @description 针对表【browing_history】的数据库操作Service
|
||||||
|
* @createDate 2024-08-23 11:29:33
|
||||||
|
*/
|
||||||
|
public interface BrowingHistoryService extends IService<BrowingHistory> {
|
||||||
|
|
||||||
|
void deleteBrowingRecordById(Long browingId);
|
||||||
|
|
||||||
|
void deleteBrowingRecordsByIds(List<Long> browingIds);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.ivmiku.tutorial.service;
|
||||||
|
|
||||||
|
import com.ivmiku.tutorial.entity.Communitytag;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author rog
|
||||||
|
* @description 针对表【communitytag】的数据库操作Service
|
||||||
|
* @createDate 2024-08-16 09:40:06
|
||||||
|
*/
|
||||||
|
public interface CommunitytagService extends IService<Communitytag> {
|
||||||
|
|
||||||
|
void createCommunityTag(Communitytag communityTag);
|
||||||
|
|
||||||
|
void updateCommunityTag(Long id, Communitytag communityTag);
|
||||||
|
|
||||||
|
void deleteCommunityTag(Long id);
|
||||||
|
|
||||||
|
Communitytag getCommunityTagById(Long id);
|
||||||
|
|
||||||
|
List<Communitytag> getCommunityTagListByCommunityId(Long communityId);
|
||||||
|
}
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
package com.ivmiku.tutorial.service;
|
package com.ivmiku.tutorial.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.ivmiku.tutorial.entity.Post;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* InteractionService接口定义用户对帖子和评论的收藏与点赞操作。
|
* InteractionService接口定义用户对帖子和评论的收藏与点赞操作。
|
||||||
*/
|
*/
|
||||||
@@ -10,4 +16,8 @@ public interface InteractionService {
|
|||||||
void unlikePost(String userOpenid, Long postId);
|
void unlikePost(String userOpenid, Long postId);
|
||||||
void likeComment(String userOpenid, Long commentId);
|
void likeComment(String userOpenid, Long commentId);
|
||||||
void unlikeComment(String userOpenid, Long commentId);
|
void unlikeComment(String userOpenid, Long commentId);
|
||||||
|
|
||||||
|
IPage<Post> getFavoritePosts(String userOpenid);
|
||||||
|
|
||||||
|
HashMap<String, Object> getLikeCount(String userOpenid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface PostService extends IService<Post> {
|
public interface PostService extends IService<Post> {
|
||||||
void createPost(Post post);
|
void createPost(Post post);
|
||||||
Post getPostById(Long postId);
|
Post getPostById(Long postId, String userOpenid);
|
||||||
|
|
||||||
void updatePost(Long postId, String userId, Post post);
|
void updatePost(Long postId, String userId, Post post);
|
||||||
void deletePost(Long postId, String userId);
|
void deletePost(Long postId, String userId);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.ivmiku.tutorial.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ivmiku.tutorial.entity.BrowingHistory;
|
||||||
|
import com.ivmiku.tutorial.service.BrowingHistoryService;
|
||||||
|
import com.ivmiku.tutorial.mapper.BrowingHistoryMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author rog
|
||||||
|
* @description 针对表【browing_history】的数据库操作Service实现
|
||||||
|
* @createDate 2024-08-23 11:29:33
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class BrowingHistoryServiceImpl extends ServiceImpl<BrowingHistoryMapper, BrowingHistory>
|
||||||
|
implements BrowingHistoryService{
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(BrowingHistoryServiceImpl.class);
|
||||||
|
@Override
|
||||||
|
public void deleteBrowingRecordById(Long browingId) {
|
||||||
|
logger.info("开始删除浏览记录,浏览记录ID:{}", browingId);
|
||||||
|
BrowingHistory browingHistory = getById(browingId);
|
||||||
|
if (browingHistory != null) {
|
||||||
|
browingHistory.setIsDelete(1); // 标记为已删除
|
||||||
|
updateById(browingHistory);
|
||||||
|
logger.info("浏览记录ID:{} 删除成功", browingId);
|
||||||
|
} else {
|
||||||
|
logger.warn("浏览记录ID:{} 不存在", browingId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteBrowingRecordsByIds(List<Long> browingIds) {
|
||||||
|
logger.info("开始批量删除浏览记录,浏览记录ID列表:{}", browingIds);
|
||||||
|
if (browingIds != null && !browingIds.isEmpty()) {
|
||||||
|
List<BrowingHistory> browingHistories = listByIds(browingIds);
|
||||||
|
if (!browingHistories.isEmpty()) {
|
||||||
|
for (BrowingHistory browingHistory : browingHistories) {
|
||||||
|
browingHistory.setIsDelete(1); // 标记为已删除
|
||||||
|
}
|
||||||
|
updateBatchById(browingHistories); // 批量更新删除状态
|
||||||
|
logger.info("批量删除浏览记录成功");
|
||||||
|
} else {
|
||||||
|
logger.warn("提供的浏览记录ID列表中没有找到匹配的记录");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.warn("浏览记录ID列表为空,无法删除");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.ivmiku.tutorial.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ivmiku.tutorial.entity.Communitytag;
|
||||||
|
import com.ivmiku.tutorial.service.CommunitytagService;
|
||||||
|
import com.ivmiku.tutorial.mapper.CommunitytagMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author rog
|
||||||
|
* @description 针对表【communitytag】的数据库操作Service实现
|
||||||
|
* @createDate 2024-08-16 09:40:06
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CommunitytagServiceImpl extends ServiceImpl<CommunitytagMapper, Communitytag>
|
||||||
|
implements CommunitytagService{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createCommunityTag(Communitytag communityTag) {
|
||||||
|
this.save(communityTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateCommunityTag(Long id, Communitytag communityTag) {
|
||||||
|
communityTag.setSmallCTagId(id);
|
||||||
|
this.updateById(communityTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteCommunityTag(Long id) {
|
||||||
|
this.removeById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Communitytag getCommunityTagById(Long id) {
|
||||||
|
return this.getById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Communitytag> getCommunityTagListByCommunityId(Long communityId) {
|
||||||
|
return this.lambdaQuery().eq(Communitytag::getCId, communityId).list();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,15 +1,22 @@
|
|||||||
package com.ivmiku.tutorial.service.impl;
|
package com.ivmiku.tutorial.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.hash.Hash;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.ivmiku.tutorial.entity.Favorite;
|
import com.ivmiku.tutorial.entity.Favorite;
|
||||||
import com.ivmiku.tutorial.entity.Likee;
|
import com.ivmiku.tutorial.entity.Likee;
|
||||||
|
import com.ivmiku.tutorial.entity.Post;
|
||||||
import com.ivmiku.tutorial.mapper.FavoriteMapper;
|
import com.ivmiku.tutorial.mapper.FavoriteMapper;
|
||||||
import com.ivmiku.tutorial.mapper.LikeMapper;
|
import com.ivmiku.tutorial.mapper.LikeMapper;
|
||||||
import com.ivmiku.tutorial.service.InteractionService;
|
import com.ivmiku.tutorial.service.InteractionService;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.ivmiku.tutorial.service.PostService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* InteractionServiceImpl 实现了 InteractionService 接口,处理用户对帖子和评论的收藏与点赞操作。
|
* InteractionServiceImpl 实现了 InteractionService 接口,处理用户对帖子和评论的收藏与点赞操作。
|
||||||
@@ -24,6 +31,9 @@ public class InteractionServiceImpl implements InteractionService {
|
|||||||
@Resource
|
@Resource
|
||||||
private LikeMapper likeMapper;
|
private LikeMapper likeMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PostService postService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void favoritePost(String userOpenid, Long postId) {
|
public void favoritePost(String userOpenid, Long postId) {
|
||||||
log.info("User {} is favoriting post {}", userOpenid, postId);
|
log.info("User {} is favoriting post {}", userOpenid, postId);
|
||||||
@@ -95,4 +105,60 @@ public class InteractionServiceImpl implements InteractionService {
|
|||||||
likeMapper.updateById(likee);
|
likeMapper.updateById(likee);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<Post> getFavoritePosts(String userOpenid) {
|
||||||
|
LambdaQueryWrapper<Favorite> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(Favorite::getUserOpenid, userOpenid);
|
||||||
|
List<Favorite> favorites = favoriteMapper.selectList(wrapper);
|
||||||
|
if (favorites != null && !favorites.isEmpty()) {
|
||||||
|
List<Long> postIds = favorites.stream().map(Favorite::getPostId).toList();
|
||||||
|
return postService.getPostList(userOpenid, 1, 10);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Object> getLikeCount(String userOpenid) {
|
||||||
|
HashMap<String, Object> res = new HashMap<>();
|
||||||
|
|
||||||
|
// 获取帖子获赞数
|
||||||
|
Long postLikeCount = likeMapper.getPostLikeCount(userOpenid);
|
||||||
|
// 获取评论获赞数
|
||||||
|
Long commentLikeCount = likeMapper.getCommentLikeCount(userOpenid);
|
||||||
|
|
||||||
|
// 如果帖子获赞数不为空,加入结果
|
||||||
|
if (postLikeCount != null) {
|
||||||
|
res.put("postLikeCount", postLikeCount);
|
||||||
|
} else {
|
||||||
|
res.put("postLikeCount", 0L); // 如果为空,设置为0
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果评论获赞数不为空,加入结果
|
||||||
|
if (commentLikeCount != null) {
|
||||||
|
res.put("commentLikeCount", commentLikeCount);
|
||||||
|
} else {
|
||||||
|
res.put("commentLikeCount", 0L); // 如果为空,设置为0
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算总的获赞数
|
||||||
|
Long totalLikeCount = (postLikeCount == null ? 0 : postLikeCount) +
|
||||||
|
(commentLikeCount == null ? 0 : commentLikeCount);
|
||||||
|
|
||||||
|
res.put("totalLikeCount", totalLikeCount);
|
||||||
|
|
||||||
|
// 获取收藏数量
|
||||||
|
LambdaQueryWrapper<Favorite> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(Favorite::getUserOpenid, userOpenid);
|
||||||
|
Long favoriteCount = favoriteMapper.selectCount(wrapper);
|
||||||
|
|
||||||
|
if (favoriteCount != null) {
|
||||||
|
res.put("favoriteCount", favoriteCount);
|
||||||
|
} else {
|
||||||
|
res.put("favoriteCount", 0L); // 如果为空,设置为0
|
||||||
|
}
|
||||||
|
Long myTotalPost = getFavoritePosts(userOpenid).getTotal();
|
||||||
|
res.put("myTotalPost", myTotalPost);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,20 +3,18 @@ package com.ivmiku.tutorial.service.impl;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.ivmiku.tutorial.entity.BrowingHistory;
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
import com.ivmiku.tutorial.entity.Comment;
|
|
||||||
import com.ivmiku.tutorial.entity.Post;
|
import com.ivmiku.tutorial.entity.Post;
|
||||||
import com.ivmiku.tutorial.mapper.PostMapper;
|
import com.ivmiku.tutorial.mapper.PostMapper;
|
||||||
|
import com.ivmiku.tutorial.service.BrowingHistoryService;
|
||||||
import com.ivmiku.tutorial.service.PostService;
|
import com.ivmiku.tutorial.service.PostService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.List;
|
import java.util.Date;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements PostService {
|
public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements PostService {
|
||||||
@@ -26,6 +24,9 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements Po
|
|||||||
@Autowired
|
@Autowired
|
||||||
private PostMapper postMapper;
|
private PostMapper postMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BrowingHistoryService browingHistoryService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPost(Post post) {
|
public void createPost(Post post) {
|
||||||
logger.info("开始创建帖子");
|
logger.info("开始创建帖子");
|
||||||
@@ -37,15 +38,24 @@ public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements Po
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Post getPostById(Long postId) {
|
public Post getPostById(Long postId, String userOpenid) {
|
||||||
logger.info("开始根据ID获取帖子详情,帖子ID:{}", postId);
|
logger.info("用户openid:{} 开始根据ID获取帖子详情,帖子ID:{}", userOpenid, postId);
|
||||||
LambdaQueryWrapper<Post> wrapper = new LambdaQueryWrapper<>();
|
|
||||||
wrapper.eq(Post::getIsPublic, 1);
|
// 查找帖子信息
|
||||||
Post post = postMapper.selectById(wrapper);
|
Post post = postMapper.selectById(postId);
|
||||||
if (post == null) {
|
if (post == null || post.getIsDeleted() == 1) {
|
||||||
logger.warn("帖子ID:{}不存在", postId);
|
logger.warn("帖子ID:{}不存在或已删除", postId);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建浏览记录
|
||||||
|
BrowingHistory browingHistory = new BrowingHistory();
|
||||||
|
browingHistory.setUserOpenid(userOpenid);
|
||||||
|
browingHistory.setPostId(postId);
|
||||||
|
browingHistory.setCreateAt(new Date());
|
||||||
|
browingHistory.setIsDelete(0); // 未删除标记
|
||||||
|
browingHistoryService.save(browingHistory);
|
||||||
|
logger.info("用户openid:{}的浏览记录创建成功", userOpenid);
|
||||||
return post;
|
return post;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,3 +27,7 @@ minio.accessKey=minio_root
|
|||||||
minio.secretKey=minio_123456
|
minio.secretKey=minio_123456
|
||||||
minio.bucketName=haixia
|
minio.bucketName=haixia
|
||||||
|
|
||||||
|
## Nacos??
|
||||||
|
#spring.cloud.nacos.discovery.server-addr=/192.168.146.1:8848
|
||||||
|
#dubbo.registry.address=nacos:///192.168.146.1:8848
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ivmiku.tutorial.mapper.BrowingHistoryMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.ivmiku.tutorial.entity.BrowingHistory">
|
||||||
|
<id property="browingId" column="browing_id" jdbcType="BIGINT"/>
|
||||||
|
<result property="userOpenid" column="user_openid" jdbcType="VARCHAR"/>
|
||||||
|
<result property="postId" column="post_id" jdbcType="BIGINT"/>
|
||||||
|
<result property="createAt" column="create_at" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="isDelete" column="is_delete" jdbcType="TINYINT"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
browing_id,user_openid,post_id,
|
||||||
|
create_at,is_delete
|
||||||
|
</sql>
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ivmiku.tutorial.mapper.CommunitytagMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.ivmiku.tutorial.entity.Communitytag">
|
||||||
|
<id property="smallCTagId" column="small_c_tag_id" jdbcType="BIGINT"/>
|
||||||
|
<result property="cTagName" column="c_tag_name" jdbcType="VARCHAR"/>
|
||||||
|
<result property="cId" column="c_id" jdbcType="BIGINT"/>
|
||||||
|
<result property="isDelete" column="is_delete" jdbcType="TINYINT"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
small_c_tag_id,c_tag_name,c_id,
|
||||||
|
is_delete
|
||||||
|
</sql>
|
||||||
|
</mapper>
|
||||||
@@ -18,6 +18,11 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.5.7</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
@@ -26,10 +31,10 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.baomidou</groupId>
|
<!-- <groupId>com.baomidou</groupId>-->
|
||||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
<!-- <artifactId>mybatis-plus-spring-boot3-starter</artifactId>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
|||||||
Reference in New Issue
Block a user