package com.nav.service.imp; import com.nav.common.api.CommonResult; import com.nav.common.utils.PackageUtils; import com.nav.dao.CommentDao; import com.nav.dao.PostDao; import com.nav.pojo.Comment; import com.nav.pojo.Post; import com.nav.service.PostService; import com.nav.vo.result.LifePostResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.PathVariable; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.TimeZone; /** * 类说明 * * @author zyx * @date 2022/4/28 20:41 */ @Service public class PostServiceImpl implements PostService { @Autowired PostDao postDao; @Autowired CommentDao commentDao; @Override public CommonResult getLifePostList(long userId) { List list=postDao.selectLifePostList(); for(int i=0;i temp= Arrays.asList(lifePostResult.getPostCover().split(" ")); lifePostResult.setPostCoverList(temp); } return CommonResult.success(list,"请求成功"); } @Override public CommonResult getLifePostById(long id) { return CommonResult.success(postDao.selectLifePostById(id),"请求成功"); } @Override public CommonResult getLifePostByUserIdPostId(long userId, long postId) { List list=postDao.selectLifePostById(postId); for(int i=0;i temp= Arrays.asList(lifePostResult.getPostCover().split(" ")); lifePostResult.setPostCoverList(temp); } return CommonResult.success(list,"请求成功"); } @Override public CommonResult updateLikeCountById(long userId,long postId) { return CommonResult.success(postDao.updateLikeCountById(userId,postId,new Date(),new Date()),"请求成功"); } @Override public CommonResult updateViewCountById(long id) { return CommonResult.success(postDao.updateViewCountById(id),"请求成功"); } @Override public CommonResult getLifePostByKeyword(String keyword,long userId) { List list=postDao.selectLifePostByKeyword(keyword); for(int i=0;i temp= Arrays.asList(lifePostResult.getPostCover().split(" ")); lifePostResult.setPostCoverList(temp); } return CommonResult.success(list,"请求成功"); } @Override public CommonResult getCommentByPostId(long id) { List commentList=commentDao.selectCommentByPostId(id); PackageUtils> packageUtils=new PackageUtils>(commentList.size(),commentList); return CommonResult.success(packageUtils,"请求成功"); } @Override public CommonResult getLifePostByTag(String tag,long userId) { List list=postDao.selectLifePostByTag(tag); for(int i=0;i temp= Arrays.asList(lifePostResult.getPostCover().split(" ")); lifePostResult.setPostCoverList(temp); } return CommonResult.success(list,"请求成功"); } @Override public int getLikeById(long userId, long postId) { return postDao.selectLikeById(userId,postId); } @Override public int getCollectById(long userId, long postId) { return postDao.selectCollectionById(userId,postId); } @Override public CommonResult updateDownLikeCountById(long userId, long postId) { return CommonResult.success(postDao.updateDownLikeCountById(userId,postId),"请求成功"); } @Override public CommonResult updateLikeCount(long userId, long postId) { int isLike=getLikeById(userId,postId); if(isLike>=1){ //取消点赞 return updateDownLikeCountById(userId,postId); } else{ //点赞 return updateLikeCountById(userId,postId); } } @Override public CommonResult updateCollectionCountById(long userId, long postId) { int isCollect=postDao.selectCollectionById(userId,postId); if(isCollect>=1){ //取消收藏 return CommonResult.success(postDao.updateDownCollectionCountById(userId,postId),"请求成功"); } else{ //收藏 return CommonResult.success(postDao.updateCollectionCountById(userId,postId,new Date(),new Date()),"请求成功"); } } @Override public CommonResult addPost(Post post,String tag) { //添加文章 postDao.insertPost(post); long postId=post.getId(); //关联文章标签 long tagId=postDao.selectTagIdByTagContent(tag); postDao.insertPostTag(postId,tagId,new Date(),new Date()); return CommonResult.success(postId,"请求成功"); } @Override public void addCommentByPostId(Comment comment) { postDao.insertCommentByPostId(comment); } }