package com.test.ssm.blog.service;
import com.github.pagehelper.PageInfo;
import com.test.ssm.blog.entity.Article;
import java.util.HashMap;
import java.util.List;
public interface ArticleService {
//获得文章总数
Integer countArticle(Integer status);
//获得评论总数
Integer countArticleComment();
//获得浏览总数
Integer countArticleView();
//统计有这个分类的文章数
Integer countArticleByCategoryId(Integer categoryId);
//统计有这个标签的
Integer countArticleByTagId(Integer tagId);
//获得所有文章不分页
List<Article> listArticle(HashMap<String,Object> criteria);
//获得最新文章
List<Article> listRecentArticle(Integer limit);
//修改文章详细信息
void updateArticleDetail(Article article);
//修改文章
void updateArticle(Article article);
//批量删除文章
void deleteArticleBatch(List<Integer> ids);
//删除文章
void deleteArticle(Integer id);
/**
* 分页显示
*
* @param pageIndex 第几页开始
* @param pageSize 一页显示多少
* @param criteria 查询条件
* @return 文章列表
*/
PageInfo<Article> pageArticle(Integer pageIndex,
Integer pageSize,
HashMap<String, Object> criteria);
/**
* 文章详情页面显示
*
* @param status 状态
* @param id 文章ID
* @return 文章
*/
Article getArticleByStatusAndId(Integer status, Integer id);
/**
* 获取访问量较多的文章
*
* @param limit 查询数量
* @return 列表
*/
List<Article> listArticleByViewCount(Integer limit);
/**
* 获得上一篇文章
*
* @param id 文章ID
* @return 文章
*/
Article getAfterArticle(Integer id);
/**
* 获得下一篇文章
*
* @param id 文章ID
* @return 文章
*/
Article getPreArticle(Integer id);
/**
* 获得随机文章
*
* @param limit 查询数量
* @return 列表
*/
List<Article> listRandomArticle(Integer limit);
/**
* 获得评论数较多的文章
*
* @param limit 查询数量
* @return 列表
*/
List<Article> listArticleByCommentCount(Integer limit);
/**
* 添加文章
*
* @param article 文章
*/
void insertArticle(Article article);
/**
* 更新文章的评论数
*
* @param articleId 文章ID
*/
void updateCommentCount(Integer articleId);
/**
* 获得最后更新记录
*
* @return 文章
*/
Article getLastUpdateArticle();
/**
* 获得相关文章
*
* @param cateId 分类ID
* @param limit 查询数量
* @return 列表
*/
List<Article> listArticleByCategoryId(Integer cateId, Integer limit);
/**
* 获得相关文章
*
* @param cateIds 分类ID集合
* @param limit 数量
* @return 列表
*/
List<Article> listArticleByCategoryIds(List<Integer> cateIds, Integer limit);
/**
* 根据文章ID获得分类ID列表
*
* @param articleId 文章Id
* @return 列表
*/
List<Integer> listCategoryIdByArticleId(Integer articleId);
/**
* 获得所有的文章
*
* @return 列表
*/
List<Article> listAllNotWithContent();
List<Integer> listArticleIdByUserId(Integer articleUserId);
}
package com.test.ssm.blog.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.test.ssm.blog.entity.*;
import com.test.ssm.blog.enums.ArticleCommentStatus;
import com.test.ssm.blog.mapper.ArticleCategoryRefMapper;
import com.test.ssm.blog.mapper.ArticleMapper;
import com.test.ssm.blog.mapper.ArticleTagRefMapper;
import com.test.ssm.blog.service.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@Service
@Slf4j
public class ArticleServiceImpl implements ArticleService {
@Autowired(required = false)
private ArticleMapper articleMapper;
@Autowired(required = false)
private ArticleCategoryRefMapper articleCategoryRefMapper;
@Autowired(required = false)
private ArticleTagRefMapper articleTagRefMapper;
@Override
public Integer countArticle(Integer status) {
Integer count = 0;
try {
count = articleMapper.countArticle(status);
} catch (Exception e) {
e.printStackTrace();
log.error("根据状态统计文章数, status:{}, cause:{}", status, e);
}
return count;
}
@Override
public Integer countArticleComment() {
Integer count = 0;
try {
count = articleMapper.countArticleComment();
} catch (Exception e) {
e.printStackTrace();
log.error("统计文章评论数失败, cause:{}", e);
}
return count;
}
@Override
public Integer countArticleView() {
Integer count = 0;
try {
count = articleMapper.countArticleView();
} catch (Exception e) {
e.printStackTrace();
log.error("统计文章访问量失败, cause:{}", e);
}
return count;
}
@Override
public Integer countArticleByCategoryId(Integer categoryId) {
Integer count = 0;
try {
count = articleCategoryRefMapper.countArticleByCategoryId(categoryId);
} catch (Exception e) {
e.printStackTrace();
log.error("根据分类统计文章数量失败, categoryId:{}, cause:{}", categoryId, e);
}
return count;
}
@Override
public Integer countArticleByTagId(Integer tagId) {
return articleTagRefMapper.countArticleByTagId(tagId);
}
@Override
public List<Article> listArticle(HashMap<String, Object> criteria) {
return articleMapper.findAll(criteria);
}
@Override
public List<Article> listRecentArticle(Integer limit) {
return articleMapper.listArticleByLimit(limit);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateArticleDetail(Article article) {
article.setArticleUpdateTime(new Date());
articleMapper.update(article);
if (article.getTagList() != null) {
//删除标签和文章关联
articleTagRefMapper.deleteByArticleId(article.getArticleId());
//添加标签和文章关联
for (int i = 0; i < article.getTagList().size(); i++) {
ArticleTagRef articleTagRef = new ArticleTagRef(article.getArticleId(), article.getTagList().get(i).getTagId());
articleTagRefMapper.insert(articleTagRef);
}
}
if (article.getCategoryList() != null) {
//添加分类和文章关联
articleCategoryRefMapper.deleteByArticleId(article.getArticleId());
//删除分类和文章关联
for (int i = 0; i < article.getCategoryList().size(); i++) {
ArticleCategoryRef articleCategoryRef = new ArticleCategoryRef(article.getArticleId(), article.getCategoryList().get(i).getCategoryId());
articleCategoryRefMapper.insert(articleCategoryRef);
}
}
}
@Override
public void updateArticle(Article article) {
articleMapper.update(article);
}
@Override
public void deleteArticleBatch(List<Integer> ids) {
articleMapper.deleteBatch(ids);
}
@Override
public void deleteArticle(Integer id) {
System.out.println("into");
Article article=articleMapper.getArticleById(id);
if(articleTagRefMapper.listTagByArticleId(article.getArticleId())!=null){
System.out.println("into Tag");
//删除标签和文章关联
articleTagRefMapper.deleteByArticleId(article.getArticleId());
}
if(articleCategoryRefMapper.listCategoryByArticleId(article.getArticleId())!=null)
{
System.out.println("into Category");
articleCategoryRefMapper.deleteByArticleId(id);
}
articleMapper.deleteById(id);
}
@Override
public PageInfo<Article> pageArticle(Integer pageIndex,
Integer pageSize,
HashMap<String, Object> criteria) {
PageHelper.startPage(pageIndex, pageSize);
List<Article> articleList = articleMapper.findAll(criteria);
for (int i = 0; i < articleList.size(); i++) {
//封装CategoryList
List<Category> categoryList = articleCategoryRefMapper.listCategoryByArticleId(articleList.get(i).getArticleId());
if (categoryList == null || categoryList.size() == 0) {
categoryList = new ArrayList<>();
categoryList.add(Category.Default());
}
articleList.get(i).setCategoryList(categoryList);
// //封装TagList
// List<Tag> tagList = articleTagRefMapper.listTagByArticleId(articleList.get(i).getArticleId());
// articleList.get(i).setTagList(tagList);
}
return new PageInfo<>(articleList);
}
@Override
public Article getArticleByStatusAndId(Integer status, Integer id) {
Article article = articleMapper.getArticleByStatusAndId(status, id);
if (article != null) {
List<Category> categoryList = articleCategoryRefMapper.listCategoryByArticleId(article.getArticleId());
List<Tag> tagList = articleTagRefMapper.listTagByArticleId(article.getArticleId());
article.setCategoryList(categoryList);
article.setTagList(tagList);
}
return article;
}
@Override
public List<Article> listArticleByViewCount(Integer limit) {
return articleMapper.listArticleByViewCount(limit);
}
@Override
public Article getAfterArticle(Integer id) {
return articleMapper.getAfterArticle(id);
}
@Override
public Article getPreArticle(Integer id) {
return articleMapper.getPreArticle(id);
}
@Override
public List<Article> listRandomArticle(Integer limit) {
return articleMapper.listRandomArticle(limit);
}
@Override
public List<Article> listArticleByCommentCount(Integer limit) {
return articleMapper.listArticleByCommentCount(limit);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void insertArticle(Article article) {
//添加文章
article.setArticleCreateTime(new Date());
article.setArticleUpdateTime(new Date());
article.setArticleIsComment(ArticleCommentStatus.ALLOW.getValue());
article.setArticleViewCount(0);
article.setArticleLikeCount(0);
article.setArticleCommentCount(0);
article.setArticleOrder(1);
articleMapper.insert(article);
//添加分类和文章关联
for (int i = 0; i < article.getCategoryList().size(); i++) {
ArticleCategoryRef articleCategoryRef = new ArticleCategoryRef(article.getArticleId(), article.getCategoryList().get(i).getCategoryId());
articleCategoryRefMapper.insert(articleCategoryRef);
}
//添加标签和文章关联
for (int i = 0; i < article.getTagList().size(); i++) {
ArticleTagRef articleTagRef = new ArticleTagRef(article.getArticleId(), article.getTagList().get(i).getTagId());
articleTagRefMapper.insert(articleTagRef);
}
}
@Override
public void updateCommentCount(Integer articleId) {
articleMapper.updateCommentCount(articleId);
}
@Override
public Article getLastUpdateArticle() {
return articleMapper.getLastUpdateArticle();
}
@Override
public List<Article> listArticleByCategoryId(Integer cateId, Integer limit) {
return articleMapper.findArticleByCategoryId(cateId, limit);
}
@Override
public List<Article> listArticleByCategoryIds(List<Integer> cateIds, Integer limit) {
if (cateIds == null || cateIds.size() == 0) {
return null;
}
return articleMapper.findArticleByCategoryIds(cateIds, limit);
}
@Override
public List<Integer> listCategoryIdByArticleId(Integer articleId) {
return articleCategoryRefMapper.selectCategoryIdByArticleId(articleId);
}
@Override
public List<Article> listAllNotWithContent() {
return articleMapper.listAllNotWithContent();
}
@Override
public List<Integer> listArticleIdByUserId(Integer articleUserId) {
return articleMapper.selectArticleIdByUserId(articleUserId);
}
}
package com.test.ssm.blog.service;
import com.test.ssm.blog.entity.Category;
import java.util.List;
public interface CategoryService {
//获得分类总数
Integer countCategory();
//获得分类列表
List<Category> listCategory();
//获得分类列表
List<Category> listCategoryWithCount();
//根据用户ID获得分类列表
List<Category> listCategoryWithCountByUserId(Integer categoryUserId);
//删除分类
void deleteCategory(Integer id);
//根据ID查询分类信息
Category getCategoryById(Integer id);
//添加分类
Category insertCategory(Category category);
//更新
void updateCategory(Category category);
//根据名称查询
Category getCategoryByName(String name);
}
package com.test.ssm.blog.service.impl;
import com.test.ssm.blog.entity.Category;
import com.test.ssm.blog.mapper.ArticleCategoryRefMapper;
import com.test.ssm.blog.mapper.CategoryMapper;
import com.test.ssm.blog.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.List;
@Service
@Slf4j
public class CategoryServiceImpl implements CategoryService {
@Autowired(required = false)
CategoryMapper categoryMapper;
@Autowired(required = false)
ArticleCategoryRefMapper articleCategoryRefMapper;
@Override
public Integer countCategory() {
Integer count = 0;
try {
count = categoryMapper.countCategory();
} catch (Exception e) {
e.printStackTrace();
log.error("统计分类失败, cause:{}", e);
}
return count;
}
@Override
public List<Category> listCategory() {
List<Category> categoryList = null;
try {
categoryList = categoryMapper.listCategory();
} catch (Exception e) {
e.printStackTrace();
log.error("根据文章获得分类列表失败, cause:{}", e);
}
return categoryList;
}
//获得分类列表的时候,设置了和这个分类有关的文章数
@Override
public List<Category> listCategoryWithCount() {
List<Category> categoryList=null;
try{
categoryList=categoryMapper.listCategory();
for(int i=0;i<categoryList.size();i++)
{
//根据分类的ID去查找这个分类下的文章数
Integer count=articleCategoryRefMapper.countArticleByCategoryId(categoryList.get(i).getCategoryId());
categoryList.get(i).setArticleCount(count);
}
}catch (Exception e) {
e.printStackTrace();
log.error("根据文章获得分类列表失败, cause:{}", e);
}
return categoryList;
}
@Override
public List<Category> listCategoryWithCountByUserId(Integer categoryUserId) {
List<Category> categoryList=null;
try
{
categoryList=categoryMapper.listCategoryByUserId(categoryUserId);
for(int i=0;i<categoryList.size();i++){
Integer count=articleCategoryRefMapper.countArticleByCategoryId(categoryList.get(i).getCategoryId());
categoryList.get(i).setArticleCount(count);
}
}catch (Exception e){
e.printStackTrace();
}
return categoryList;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteCategory(Integer id) {
try{
//因为文章和分类有关,所以在分类中删除,也要在文章和分类关联的表里删除
categoryMapper.deleteCategory(id);
articleCategoryRefMapper.deleteByCategoryId(id);
}catch (Exception e){
e.printStackTrace();
log.error("删除分类失败, id:{}, cause:{}", id, e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
}
@Override
public Category getCategoryById(Integer id) {
return categoryMapper.getCategoryById(id);
}
@Override
public Category insertCategory(Category category) {
categoryMapper.insert(category);
return category;
}
@Override
public void updateCategory(Category category) {
categoryMapper.update(category);
}
@Override
public Category getCategoryByName(String name) {
Category category = null;
try {
category = categoryMapper.getCategoryByName(name);
} catch (Exception e) {
e.printStackTrace();
log.error("更新分类失败, category:{}, cause:{}", category, e);
}
return category;
}
}
package com.test.ssm.blog.service;
import com.test.ssm.blog.entity.Tag;
import javafx.scene.control.TableFocusModel;
import java.util.List;
public interface TagService {
//获得总数
Integer countTag();
//获得标签列表
List<Tag> listTag();
//获得标签列表,及文章数目
List<Tag> listTagWithCount();
//根据ID
Tag getTagById(Integer id);
//添加
Tag insertTag(Tag tag);
//更新
void updateTag(Tag tag);
//删除
void deleteTag(Integer id);
//根据名称
Tag getTagByName(String name);
//根据文章ID获得标签
List<Tag> listTagByArticleId(Integer articleId);
List<Tag> listTagByUserId(Integer tagUserId);
}
package com.test.ssm.blog.service.impl;
import com.test.ssm.blog.entity.Tag;
import com.test.ssm.blog.mapper.ArticleTagRefMapper;
import com.test.ssm.blog.mapper.TagMapper;
import com.test.ssm.blog.service.TagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.List;
@Service
@Slf4j
public class TagServiceImpl implements TagService {
@Autowired(required = false)
TagMapper tagMapper;
@Autowired(required = false)
ArticleTagRefMapper articleTagRefMapper;
@Override
public Integer countTag() {
return tagMapper.countTag();
}
@Override
public List<Tag> listTag() {
List<Tag> tagList = null;
try {
tagList = tagMapper.listTag();
} catch (Exception e) {
e.printStackTrace();
log.error("获得所有标签失败, cause:{}", e);
}
return tagList;
}
@Override
public List<Tag> listTagWithCount() {
List<Tag> tagList = null;
try {
tagList = tagMapper.listTag();
for (int i = 0; i < tagList.size(); i++) {
Integer count = articleTagRefMapper.countArticleByTagId(tagList.get(i).getTagId());
tagList.get(i).setArticleCount(count);
}
} catch (Exception e) {
e.printStackTrace();
log.error("获得所有标签失败, cause:{}", e);
}
return tagList;
}
@Override
public Tag getTagById(Integer id) {
return tagMapper.getTagById(id);
}
@Override
public Tag insertTag(Tag tag) {
tagMapper.insert(tag);
return tag;
}
@Override
public void updateTag(Tag tag) {
tagMapper.insert(tag);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteTag(Integer id) {
try {
tagMapper.deleteById(id);
articleTagRefMapper.deleteByTagId(id);
} catch (Exception e) {
e.printStackTrace();
log.error("删除标签失败, id:{}, cause:{}", id, e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
}
@Override
public Tag getTagByName(String name) {
Tag tag = null;
try {
tag = tagMapper.getTagByName(name);
} catch (Exception e) { e.printStackTrace();
log.error("根据名称获得标签, name:{}, cause:{}", name, e);
}
return tag;
}
@Override
public List<Tag> listTagByArticleId(Integer articleId) {
List<Tag> tagList = null;
try {
tagList = articleTagRefMapper.listTagByArticleId(articleId);
} catch (Exception e) {
e.printStackTrace();
log.error("根据文章ID获得标签失败,articleId:{}, cause:{}", articleId, e);
}
return tagList;
}
@Override
public List<Tag> listTagByUserId(Integer tagUserId) {
List<Tag> tagList=null;
try
{
tagList=tagMapper.listTagByUserId(tagUserId);
for(int i=0;i<tagList.size();i++)
{
Integer count=articleTagRefMapper.countArticleByTagId(tagList.get(i).getTagId());
tagList.get(i).setArticleCount(count);
}
}catch (Exception e) {
e.printStackTrace();
}
return tagList;
}
}
package com.test.ssm.blog.service;
import com.github.pagehelper.PageInfo;
import com.test.ssm.blog.entity.Article;
import com.test.ssm.blog.entity.Comment;
import java.util.List;
public interface CommentService {
//添加
void insertComment(Comment comment);
//根据文章ID获取评论列表
List<Comment> listCommentByArticleId(Integer articleId);
//根据ID获取
Comment getCommentById(Integer id);
/**
* 获得所有评论
* pageIndex 第几页开始
* pageSize 一页显示的数量
*/
PageInfo<Comment> listCommentByPage(Integer pageIndex,Integer pageSize);
//获得评论列表
List<Comment> listComment();
//删除评论
void deleteComment(Integer id);
//更新
void updateComment(Comment comment);
//统计评论数
Integer countComment();
//获得最新评论
List<Comment> listRecentComment(Integer limit);
//获得评论的子评论
List<Comment> listChildComment(Integer id);
PageInfo<Comment> listCommentByArticleIds(Integer pageIndex,Integer pageSize,List<Integer> articleIds);
}
package com.test.ssm.blog.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.test.ssm.blog.entity.Article;
import com.test.ssm.blog.entity.Comment;
import com.test.ssm.blog.entity.Page;
import com.test.ssm.blog.enums.ArticleStatus;
import com.test.ssm.blog.mapper.ArticleMapper;
import com.test.ssm.blog.mapper.CommentMapper;
import com.test.ssm.blog.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@Slf4j
public class CommentServiceImpl implements CommentService {
@Autowired(required = false)
private CommentMapper commentMapper;
@Autowired(required = false)
private ArticleMapper articleMapper;
@Override
public void insertComment(Comment comment) {
try
{
commentMapper.insert(comment);
}catch (Exception e)
{
e.printStackTrace();
log.error("创建评论失败:comment:{},cause:{}",comment,e);
}
}
@Override
public List<Comment> listCommentByArticleId(Integer articleId) {
List<Comment> commentList=null;
try {
commentList=commentMapper.listCommentByArticleId(articleId);
}catch (Exception e) {
e.printStackTrace();
log.error("根据文章ID获得评论列表失败,articleId:{},cause:{}", articleId, e);
}
return commentList;
}
@Override
public Comment getCommentById(Integer id) {
Comment comment=null;
try{
comment=commentMapper.getCommentById(id);
}catch (Exception e){
e.printStackTrace();
log.error("根据评论ID获得评论,id:{}, cause:{}", id, e);
}
return comment;
}
@Override
public PageInfo<Comment> listCommentByPage(Integer pageIndex, Integer pageSize) {
PageHelper.startPage(pageIndex,pageSize);
List<Comment> commentList=null;
try{
commentList=commentMapper.listComment();
for(int i=0;i<commentList.size();i++)
{
//根据文章状态(已发布)和评论中的文章ID获得文章
Article article=articleMapper.getArticleByStatusAndId(ArticleStatus.PUBLISH.getValue(),commentList.get(i).getCommentArticleId());
//comment中有一个这样的属性 private Article article; //非数据库字段。评论的文章
commentList.get(i).setArticle(article);
}
}catch (Exception e) {
e.printStackTrace();
log.error("分页获得评论失败,pageIndex:{}, pageSize:{}, cause:{}", pageIndex, pageSize, e);
}
return new PageInfo<>(commentList);
}
@Override
public List<Comment> listComment() {
List<Comment> commentList=null;
try
{
commentList=commentMapper.listComment();
} catch (Exception e) {
e.printStackTrace();
log.error("获得评论列表失败:cause:{}", e);
}
return commentList;
}
@Override
public void deleteComment(Integer id) {
commentMapper.deleteById(id);
}
@Override
public void updateComment(Comment comment) {
commentMapper.update(comment);
}
@Override
public Integer countComment() {
Integer commentCount = null;
try {
commentCount = commentMapper.countComment();
} catch (Exception e) {
e.printStackTrace();
log.error("统计评论数量失败, cause:{}", e);
}
return commentCount;
}
@Override
public List<Comment> listRecentComment(Integer limit) {
List<Comment> commentList=null;
try{
commentList=commentMapper.listRecentComment(limit);
for(int i=0;i<commentList.size();i++)
{
Article article = articleMapper.getArticleByStatusAndId(ArticleStatus.PUBLISH.getValue(), commentList.get(i).getCommentArticleId());
commentList.get(i).setArticle(article);
}
}catch (Exception e){
e.printStackTrace();
log.error("获得最新评论失败, limit:{}, cause:{}", limit, e);
}
return commentList;
}
@Override
public List<Comment> listChildComment(Integer id) {
List<Comment> childCommentList=null;
try
{
childCommentList=commentMapper.listChildComment(id);
}catch (Exception e) {
e.printStackTrace();
log.error("获得子评论失败, id:{}, cause:{}", id, e);
}
return childCommentList;
}
@Override
public PageInfo<Comment> listCommentByArticleIds(Integer pageIndex, Integer pageSize,List<Integer> articleIds) {
PageHelper.startPage(pageIndex,pageSize);
System.out.println(articleIds.size());
List<Comment> commentList=null;
try{
commentList=commentMapper.listCommentByArticleIds(articleIds);
for(int i=0;i<commentList.size();i++){
Article article = articleMapper.getArticleByStatusAndId(ArticleStatus.PUBLISH.getValue(), commentList.get(i).getCommentArticleId());
commentList.get(i).setArticle(article);
}
}catch (Exception e)
{
e.printStackTrace();
}
return new PageInfo<>(commentList);
}
}
package com.test.ssm.blog.service;
import com.test.ssm.blog.entity.Link;
import java.util.List;
public interface LinkService {
//获得链接总数
Integer countLink(Integer status);
//获得链接列表
List<Link> listLink(Integer status);
//添加
void insertLink(Link link);
//删除
void deleteLink(Integer id);
//更新
void updateLink(Link link);
//根据ID查询
Link getLinkById(Integer id);
}
package com.test.ssm.blog.service.impl;
import com.test.ssm.blog.entity.Link;
import com.test.ssm.blog.mapper.LinkMapper;
import com.test.ssm.blog.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class LinkServiceImpl implements LinkService {
@Autowired(required = false)
LinkMapper linkMapper;
@Override
public Integer countLink(Integer status) {
return linkMapper.countLink(status);
}
@Override
public List<Link> listLink(Integer status) {
return linkMapper.listLink(status);
}
@Override
public void insertLink(Link link) {
linkMapper.insert(link);
}
@Override
public void deleteLink(Integer id) {
linkMapper.deleteById(id);
}
@Override
public void updateLink(Link link) {
linkMapper.update(link);
}
@Override
public Link getLinkById(Integer id) {
return linkMapper.getLinkById(id);
}
}
package com.test.ssm.blog.service;
import com.test.ssm.blog.entity.Menu;
import java.util.List;
public interface MenuService {
//获得菜单列表
List<Menu> listMenu();
//添加菜单项目
Menu insertMenu(Menu menu);
//删除菜单项目
void deleteMenu(Integer id);
//更新
void updateMenu(Menu menu);
//根据ID获取菜单项目信息
Menu getMenuById(Integer id);
}
package com.test.ssm.blog.service.impl;
import com.test.ssm.blog.entity.Menu;
import com.test.ssm.blog.mapper.MenuMapper;
import com.test.ssm.blog.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class MenuServiceImpl implements MenuService {
@Autowired(required = false)
MenuMapper menuMapper;
@Override
public List<Menu> listMenu() {
List<Menu> menuList=menuMapper.listMenu();
return menuList;
}
@Override
public Menu insertMenu(Menu menu) {
menuMapper.insert(menu);
return menu;
}
@Override
public void deleteMenu(Integer id) {
menuMapper.deleteById(id);
}
@Override
public void updateMenu(Menu menu) {
menuMapper.update(menu);
}
@Override
public Menu getMenuById(Integer id) {
return menuMapper.getMenuById(id);
}
}
package com.test.ssm.blog.service;
import com.test.ssm.blog.entity.Notice;
import java.util.List;
public interface NoticeService {
//获得公告列表
List<Notice> listNotice(Integer status);
//添加公告
void insertNotice(Notice notice);
//删除
void deleteNotice(Integer id);
//更新
void updateNotice(Notice notice);
//根据ID查询
Notice getNoticeById(Integer id);
}
package com.test.ssm.blog.service.impl;
import com.test.ssm.blog.entity.Notice;
import com.test.ssm.blog.mapper.NoticeMapper;
import com.test.ssm.blog.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class NoticeServiceImpl implements NoticeService {
@Autowired(required = false)
NoticeMapper noticeMapper;
@Override
public List<Notice> listNotice(Integer status) {
return noticeMapper.listNotice(status);
}
@Override
public void insertNotice(Notice notice) {
noticeMapper.insert(notice);
}
@Override
public void deleteNotice(Integer id) {
noticeMapper.deleteById(id);
}
@Override
public void updateNotice(Notice notice) {
noticeMapper.update(notice);
}
@Override
public Notice getNoticeById(Integer id) {
return noticeMapper.getNoticeById(id);
}
}
package com.test.ssm.blog.service;
import com.test.ssm.blog.entity.Options;
public interface OptionsService {
//获得基本信息
Options getOptions();
//新建基本信息
void insertOptions(Options options);
//更新基本信息
void updateOptions(Options options);
}
package com.test.ssm.blog.service.impl;
import com.test.ssm.blog.entity.Options;
import com.test.ssm.blog.mapper.OptionsMapper;
import com.test.ssm.blog.service.OptionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@Service
public class OptionsServiceImpl implements OptionsService {
@Autowired(required = false)
OptionsMapper optionsMapper;
@Override
@Cacheable(value = "default", key = "'options'")
public Options getOptions() {
return optionsMapper.getOptions();
}
/**
* @Cacheable : 主要针对方法配置,能够根据方法的请求参数对结果进行缓存
* 参数值:
* value 缓存的名称
* key 缓存的key(如果指定要按照SpEL表达式编写,如果不指定,则缺省按照方法的所有参数进行组合
* condition 缓存的条件,可以为空
* 加这个注解的意思,当调用这个方法时,会从一个名叫value值的缓存中查询,如果没有,则执行实际方法(即查询数据库),并将执行结果保存在缓存中
* 否则返回缓存中的对象
* @param options
*/
@Override
@Cacheable(value = "default", key = "'options'")
public void insertOptions(Options options) {
optionsMapper.insert(options);
}
@Override
@Cacheable(value = "default", key = "'options'")
public void updateOptions(Options options) {
optionsMapper.update(options);
}
}
package com.test.ssm.blog.service;
import com.test.ssm.blog.entity.User;
import java.util.List;
public interface UserService {
/**
* 获得用户列表
*/
List<User> listUser();
/**
* 根据ID查询信息
*/
User getUserById(Integer id);
/**
* 修改用户信息
*/
void updateUser(User user);
/**
* 删除用户
*/
void deleteUser(Integer id);
/**
* 添加用户
*/
User insertUser(User user);
/**
* 根据用户名或邮箱查询用户
*/
User getUserByNameOrEmail(String str);
/**
* 根据用户名查询用户
*/
User getUserByName(String name);
/**
* 根据邮箱查询用户
*/
User getUserByEmail(String email);
}
package com.test.ssm.blog.service.impl;
import com.test.ssm.blog.entity.User;
import com.test.ssm.blog.mapper.ArticleMapper;
import com.test.ssm.blog.mapper.UserMapper;
import com.test.ssm.blog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
@Autowired(required = false)
private UserMapper userMapper;
@Autowired(required = false)
private ArticleMapper articleMapper;
@Override
public List<User> listUser() {
List<User> userList=userMapper.listUser();
for (int i=0;i<userList.size();i++)
{
Integer articleCount=articleMapper.countArticleByUser(userList.get(i).getUserId());
userList.get(i).setArticleCount(articleCount);
}
return userList;
}
@Override
public User getUserById(Integer id) {
return userMapper.getUserById(id);
}
@Override
public void updateUser(User user) {
userMapper.update(user);
}
@Override
public void deleteUser(Integer id) {
userMapper.deleteById(id);
}
@Override
public User insertUser(User user) {
user.setUserRegisterTime(new Date());
userMapper.insert(user);
return user;
}
@Override
public User getUserByNameOrEmail(String str) {
return userMapper.getUserByNameOrEmail(str);
}
@Override
public User getUserByName(String name) {
return userMapper.getUserByName(name);
}
@Override
public User getUserByEmail(String email) {
return userMapper.getUserByEmail(email);
}
}
package com.test.ssm.blog.service;
import com.test.ssm.blog.entity.Page;
import java.util.List;
public interface PageService {
//获得页面列表
List<Page> listPage(Integer status);
//根据页面key获得页面
Page getPageByKey(Integer status,String key);
//根据ID获取页面
Page getPageById(Integer id);
//添加页面
void insertPage(Page page);
//删除页面
void deletePage(Integer id);
//编辑页面
void updatePage(Page page);
}
package com.test.ssm.blog.service.impl;
import com.test.ssm.blog.entity.Page;
import com.test.ssm.blog.mapper.PageMapper;
import com.test.ssm.blog.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class PageServiceImpl implements PageService {
@Autowired(required = false)
PageMapper pageMapper;
@Override
public List<Page> listPage(Integer status) {
return pageMapper.listPage(status);
}
@Override
public Page getPageByKey(Integer status, String key) {
return pageMapper.getPageByKey(status,key);
}
@Override
public Page getPageById(Integer id) {
return pageMapper.getPageById(id);
}
@Override
public void insertPage(Page page) {
pageMapper.insert(page);
}
@Override
public void deletePage(Integer id) {
pageMapper.deleteById(id);
}
@Override
public void updatePage(Page page) {
pageMapper.update(page);
}
}