This commit is contained in:
oneao committed 2025-12-24 17:31:19 +08:00
1 parent e9ad523fcf
commit f310336188
39 files changed
+411 -303

No files matched your search

@@ -0,0 +1,27 @@
package cn.link56.post.controller;
import cn.link56.common.Result;
import cn.link56.post.model.vo.PostCategoryVO;
import cn.link56.post.model.vo.PostTagVO;
import cn.link56.post.service.PostCategoryService;
import cn.link56.post.service.PostTagService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/post/category")
public class PostCategoryController {
@Resource
private PostCategoryService postCategoryService;
@GetMapping
public Result<List<PostCategoryVO>> listCategories(){
List<PostCategoryVO> list = postCategoryService.listCategories();
return Result.success(list);
}
}
@@ -0,0 +1,9 @@
package cn.link56.post.mapper;
import cn.link56.post.model.po.PostCategory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PostCategoryMapper extends BaseMapper<PostCategory> {
}
@@ -1,9 +1,9 @@
package cn.link56.post.mapper;
import cn.link56.post.model.po.PostCommentPO;
import cn.link56.post.model.po.PostComment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PostCommentMapper extends BaseMapper<PostCommentPO> {
public interface PostCommentMapper extends BaseMapper<PostComment> {
}
@@ -1,9 +1,9 @@
package cn.link56.post.mapper;
import cn.link56.post.model.po.PostFavoritePO;
import cn.link56.post.model.po.PostFavorite;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PostFavoriteMapper extends BaseMapper<PostFavoritePO> {
public interface PostFavoriteMapper extends BaseMapper<PostFavorite> {
}
@@ -1,9 +1,9 @@
package cn.link56.post.mapper;
import cn.link56.post.model.po.PostLikePO;
import cn.link56.post.model.po.PostLike;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PostLikeMapper extends BaseMapper<PostLikePO> {
public interface PostLikeMapper extends BaseMapper<PostLike> {
}
@@ -1,6 +1,6 @@
package cn.link56.post.mapper;
import cn.link56.post.model.po.PostPO;
import cn.link56.post.model.po.Post;
import cn.link56.post.model.vo.DashboardVO;
import cn.link56.post.model.vo.QueryPostVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface PostMapper extends BaseMapper<PostPO> {
public interface PostMapper extends BaseMapper<Post> {
List<QueryPostVO> selectPostPage(
@Param("offset") int offset,
@Param("limit") int limit,
@@ -1,12 +1,9 @@
package cn.link56.post.mapper;
import cn.link56.post.model.po.PostTagPO;
import cn.link56.post.model.vo.PostTagVO;
import cn.link56.post.model.po.PostTag;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface PostTagMapper extends BaseMapper<PostTagPO> {
public interface PostTagMapper extends BaseMapper<PostTag> {
}
@@ -1,9 +1,9 @@
package cn.link56.post.mapper;
import cn.link56.post.model.po.PostViewPO;
import cn.link56.post.model.po.PostView;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PostViewMapper extends BaseMapper<PostViewPO> {
public interface PostViewMapper extends BaseMapper<PostView> {
}
@@ -18,9 +18,7 @@ public class UpdatePostDTO {
private String title;
@NotBlank(message = "帖子内容不能为空")
private String content;
@NotBlank(message = "帖子摘要不能为空")
private String summary;
private String cover;
private List<String> tags;
private Integer status;
@@ -4,11 +4,9 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import java.util.Date;
@@ -16,7 +14,7 @@ import java.util.Date;
@AllArgsConstructor
@NoArgsConstructor
@TableName("b_post")
public class PostPO {
public class Post {
@TableId(value = "b_id")
private Long id;
@@ -29,15 +27,9 @@ public class PostPO {
@TableField("b_content")
private String content;
@TableField("b_summary")
private String summary;
@TableField("b_tag")
private String tag;
@TableField("b_cover")
private String cover;
@TableField("b_publish_time")
private Date publishTime;
@@ -0,0 +1,23 @@
package cn.link56.post.model.po;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("b_post_category")
public class PostCategory {
@TableId(value = "b_id")
private Long id;
@TableField("b_name")
private String name;
@TableField("b_canuse")
private String canuse;
}
@@ -12,7 +12,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@TableName("b_post_comment")
public class PostCommentPO {
public class PostComment {
@TableId(value = "b_id")
private Long id;
@@ -12,7 +12,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@TableName("b_post_favorite")
public class PostFavoritePO {
public class PostFavorite {
@TableId(value = "b_id")
private Long id;
@@ -12,7 +12,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@TableName("b_post_like")
public class PostLikePO {
public class PostLike {
@TableId(value = "b_id")
private Long id;
@@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@TableName("b_post_tag")
public class PostTagPO {
public class PostTag {
@TableId(value = "b_id")
private Long id;
@@ -12,7 +12,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@TableName("b_post_view")
public class PostViewPO {
public class PostView {
@TableId(value = "b_id")
private Long id;
@@ -0,0 +1,13 @@
package cn.link56.post.model.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PostCategoryVO {
private Long id;
private String name;
}
@@ -0,0 +1,33 @@
package cn.link56.post.service;
import cn.link56.post.mapper.PostCategoryMapper;
import cn.link56.post.model.po.PostCategory;
import cn.link56.post.model.vo.PostCategoryVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class PostCategoryService extends ServiceImpl<PostCategoryMapper, PostCategory> {
@Resource
private PostCategoryMapper postCategoryMapper;
public List<PostCategoryVO> listCategories() {
LambdaQueryWrapper<PostCategory> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PostCategory::getCanuse,"1");
List<PostCategory> postCategories = postCategoryMapper.selectList(wrapper);
return postCategories.stream().map(postCategory -> {
PostCategoryVO postCategoryVO = new PostCategoryVO();
BeanUtils.copyProperties(postCategory, postCategoryVO);
return postCategoryVO;
}).collect(Collectors.toList());
}
}
@@ -1,14 +1,14 @@
package cn.link56.post.service;
import cn.link56.post.mapper.PostCommentMapper;
import cn.link56.post.model.po.PostCommentPO;
import cn.link56.post.model.po.PostComment;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class PostCommentService extends ServiceImpl<PostCommentMapper, PostCommentPO> {
public class PostCommentService extends ServiceImpl<PostCommentMapper, PostComment> {
@Resource
private PostCommentMapper postCommentMapper;
}
@@ -1,14 +1,14 @@
package cn.link56.post.service;
import cn.link56.post.mapper.PostFavoriteMapper;
import cn.link56.post.model.po.PostFavoritePO;
import cn.link56.post.model.po.PostFavorite;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class PostFavoriteService extends ServiceImpl<PostFavoriteMapper, PostFavoritePO> {
public class PostFavoriteService extends ServiceImpl<PostFavoriteMapper, PostFavorite> {
@Resource
private PostFavoriteMapper postFavoriteMapper;
}
@@ -1,14 +1,14 @@
package cn.link56.post.service;
import cn.link56.post.mapper.PostLikeMapper;
import cn.link56.post.model.po.PostLikePO;
import cn.link56.post.model.po.PostLike;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class PostLikeService extends ServiceImpl<PostLikeMapper, PostLikePO> {
public class PostLikeService extends ServiceImpl<PostLikeMapper, PostLike> {
@Resource
private PostLikeMapper postLikeMapper;
}
@@ -3,18 +3,15 @@ package cn.link56.post.service;
import cn.link56.common.BasePageVO;
import cn.link56.common.context.UserContext;
import cn.link56.common.utils.snowflake.idgen.IdGenerator;
import cn.link56.company.model.po.CompanyUserPO;
import cn.link56.post.mapper.PostMapper;
import cn.link56.post.model.dto.*;
import cn.link56.post.model.enums.PostStatusEnum;
import cn.link56.post.model.po.PostPO;
import cn.link56.post.model.po.Post;
import cn.link56.post.model.vo.DashboardVO;
import cn.link56.post.model.vo.EditPostVO;
import cn.link56.post.model.vo.QueryPostVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
@@ -27,48 +24,48 @@ import java.util.*;
import java.util.stream.Collectors;
@Service
public class PostService extends ServiceImpl<PostMapper, PostPO> {
public class PostService extends ServiceImpl<PostMapper, Post> {
@Resource
private PostMapper postMapper;
@Transactional
public EditPostVO addPost(AddPostDTO dto) {
PostPO postPO = new PostPO();
BeanUtils.copyProperties(dto, postPO);
Post post = new Post();
BeanUtils.copyProperties(dto, post);
postPO.setId(IdGenerator.nextId());
postPO.setCompanyId(UserContext.getCompanyId());
postPO.setTag(joinTags(dto.getTags()));
post.setId(IdGenerator.nextId());
post.setCompanyId(UserContext.getCompanyId());
post.setTag(joinTags(dto.getTags()));
handleUpdatePublishTime(postPO, dto.getStatus());
handleUpdatePublishTime(post, dto.getStatus());
postMapper.insert(postPO);
return buildEditPostVO(postPO);
postMapper.insert(post);
return buildEditPostVO(post);
}
public EditPostVO updatePost(UpdatePostDTO dto) {
PostPO postPO = postMapper.selectById(dto.getId());
if (postPO == null) {
Post post = postMapper.selectById(dto.getId());
if (post == null) {
return null;
}
BeanUtils.copyProperties(dto, postPO);
postPO.setTag(joinTags(dto.getTags()));
BeanUtils.copyProperties(dto, post);
post.setTag(joinTags(dto.getTags()));
handleUpdatePublishTime(postPO, dto.getStatus());
handleUpdatePublishTime(post, dto.getStatus());
postMapper.updateById(postPO);
return buildEditPostVO(postPO);
postMapper.updateById(post);
return buildEditPostVO(post);
}
public EditPostVO getDetail(Long id) {
PostPO postPO = postMapper.selectById(id);
if (postPO == null) {
Post post = postMapper.selectById(id);
if (post == null) {
return null;
}
return buildEditPostVO(postPO);
return buildEditPostVO(post);
}
public BasePageVO<QueryPostVO> queryPost(QueryPostDTO dto) {
@@ -101,14 +98,14 @@ public class PostService extends ServiceImpl<PostMapper, PostPO> {
/* ================= 私有方法 ================= */
private EditPostVO buildEditPostVO(PostPO postPO) {
private EditPostVO buildEditPostVO(Post post) {
EditPostVO vo = new EditPostVO();
BeanUtils.copyProperties(postPO, vo);
BeanUtils.copyProperties(post, vo);
vo.setTags(
StringUtils.isBlank(postPO.getTag())
StringUtils.isBlank(post.getTag())
? Collections.emptyList()
: Arrays.asList(StringUtils.split(postPO.getTag(), ","))
: Arrays.asList(StringUtils.split(post.getTag(), ","))
);
return vo;
}
@@ -119,10 +116,10 @@ public class PostService extends ServiceImpl<PostMapper, PostPO> {
: StringUtils.join(tags, ",");
}
private void handleUpdatePublishTime(PostPO postPO, Integer status) {
private void handleUpdatePublishTime(Post post, Integer status) {
if (PostStatusEnum.PUBLISHED.getCode() == status
&& postPO.getPublishTime() == null) {
postPO.setPublishTime(new Date());
&& post.getPublishTime() == null) {
post.setPublishTime(new Date());
}
}
@@ -136,13 +133,13 @@ public class PostService extends ServiceImpl<PostMapper, PostPO> {
Long id = updatePostStatusDTO.getId();
Integer status = updatePostStatusDTO.getStatus();
PostPO postPO = postMapper.selectById(id);
if (postPO == null) {
Post post = postMapper.selectById(id);
if (post == null) {
return;
}
postPO.setStatus(status);
postMapper.updateById(postPO);
post.setStatus(status);
postMapper.updateById(post);
}
public DashboardVO getDashboardData() {
@@ -184,21 +181,21 @@ public class PostService extends ServiceImpl<PostMapper, PostPO> {
}
private List<DashboardVO.Chart> getDashboardTypeStats(Long userId) {
LambdaQueryWrapper<PostPO> queryWrapper = new LambdaQueryWrapper<>();
LambdaQueryWrapper<Post> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
.select(PostPO::getTag)
.eq(PostPO::getStatus, PostStatusEnum.PUBLISHED.getCode())
.eq(PostPO::getCreateBy, userId);
.select(Post::getTag)
.eq(Post::getStatus, PostStatusEnum.PUBLISHED.getCode())
.eq(Post::getCreateBy, userId);
List<PostPO> postPOS = postMapper.selectList(queryWrapper);
List<Post> posts = postMapper.selectList(queryWrapper);
// 用 map 统计每个 tag 出现次数
Map<String, Integer> tagCountMap = new HashMap<>();
for (PostPO postPO : postPOS) {
if (postPO == null) continue;
for (Post post : posts) {
if (post == null) continue;
String tagsStr = postPO.getTag();
String tagsStr = post.getTag();
if (tagsStr == null || tagsStr.isEmpty()) continue;
// 分割逗号,并去掉空格
@@ -1,7 +1,7 @@
package cn.link56.post.service;
import cn.link56.post.mapper.PostTagMapper;
import cn.link56.post.model.po.PostTagPO;
import cn.link56.post.model.po.PostTag;
import cn.link56.post.model.vo.PostTagVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -13,19 +13,19 @@ import java.util.List;
import java.util.stream.Collectors;
@Service
public class PostTagService extends ServiceImpl<PostTagMapper, PostTagPO> {
public class PostTagService extends ServiceImpl<PostTagMapper, PostTag> {
@Resource
private PostTagMapper postTagMapper;
public List<PostTagVO> listTags() {
LambdaQueryWrapper<PostTagPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PostTagPO::getCanuse,"1");
LambdaQueryWrapper<PostTag> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PostTag::getCanuse,"1");
List<PostTagPO> postTagPOS = postTagMapper.selectList(wrapper);
List<PostTag> postTags = postTagMapper.selectList(wrapper);
return postTagPOS.stream().map(postTagPO -> {
return postTags.stream().map(postTag -> {
PostTagVO postTagVO = new PostTagVO();
BeanUtils.copyProperties(postTagPO, postTagVO);
BeanUtils.copyProperties(postTag, postTagVO);
return postTagVO;
}).collect(Collectors.toList());
@@ -1,14 +1,14 @@
package cn.link56.post.service;
import cn.link56.post.mapper.PostViewMapper;
import cn.link56.post.model.po.PostViewPO;
import cn.link56.post.model.po.PostView;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class PostViewService extends ServiceImpl<PostViewMapper, PostViewPO> {
public class PostViewService extends ServiceImpl<PostViewMapper, PostView> {
@Resource
private PostViewMapper postViewMapper;
}
@@ -8,7 +8,6 @@
type="cn.link56.post.model.vo.QueryPostVO">
<id property="id" column="id"/>
<result property="title" column="title"/>
<result property="cover" column="cover"/>
<!-- tags 字符串 → List<String> -->
<result
@@ -32,7 +31,6 @@
SELECT
p.b_id AS id,
p.b_title AS title,
p.b_cover AS cover,
p.b_tag AS tagsString,
p.b_update_time AS updateTime,
p.b_publish_time AS publishTime,