博客系统服务层接口编写与实现

服务层接口

BlogColumnService

public interface BlogColumnService {
    void add(BlogColumn blogColumn);

    void update(BlogColumn blogColumn);

    void delete(Integer id);

    BlogColumn findById(Integer id);

    List findAll();

    Page search(String search, int page, int size);

    //根据用户id分页查询专栏
    Page searchByUserId(Integer userId, int page, int size);
}

BlogCommentService

public interface BlogCommentService {
    void add(BlogComment blogComment);

    void update(BlogComment blogComment);

    void delete(Integer id);

    BlogComment findById(Integer id);

    List findAll();

    Page search(String search, int page, int size);

    //根据博客id分页查询
    Page searchByBlogId(Integer blogId, int page, int size);
}

BlogService

public interface BlogService {
    void add(Blog blog);

    void update(Blog blog);

    void delete(Integer id);

    Blog findById(Integer id);

    List findAll();

    Page search(String search, int page, int size);

    //分页查询状态为发布的博客
    Page searchForStatus(String search, int page, int size);

    //更新博客状态
    void updateStatus(Integer id);

    //根据用户名分页查找博客文章
    Page searchByUserId(Integer userId, int page, int size);

    //添加博客_专栏中间表的数据
    void addBlog_column(Integer blogId, Integer blogColumnId);

    //删除博客_专栏中间表的数据
    void deleteBlog_column(Integer blogId, Integer blogColumnId);

    //根据博客id查询博客_专栏中间表的专栏数据
    List findColumnByBlogId(Integer blogId);

    //添加博客_标签中间表的数据
    void addBlog_tag(Integer blogId, Integer blogTagId);

    //删除博客_标签中间表的数据
    void deleteBlog_tag(Integer blogId, Integer blogTagId);

    //根据博客id查询博客_标签中间表的标签数据
    List findTagByBlogId(Integer blogId);
}

BlogTagService

public interface BlogTagService {
    void add(BlogTag blogTag);

    void update(BlogTag blogTag);

    void delete(Integer id);

    BlogTag findById(Integer id);

    List findAll();

    Page search(String search, int page, int size);
}

BlogTypeService

public interface BlogTypeService {
    void add(BlogType blogType);

    void update(BlogType blogType);

    void delete(Integer id);

    BlogType findById(Integer id);

    List findAll();

    Page search(String search, int page, int size);
}

BlogVisibilityService

public interface BlogVisibilityService {
    void add(BlogVisibility blogVisibility);

    void update(BlogVisibility blogVisibility);

    void delete(Integer id);

    BlogVisibility findById(Integer id);

    List findAll();

    Page search(String search, int page, int size);
}

服务层实现

BlogColumnServiceImpl

@Service
@Transactional
public class BlogColumnServiceImpl implements BlogColumnService {
    @Autowired
    private BlogColumnMapper blogColumnMapper;

    @Override
    public void add(BlogColumn blogColumn) {
        blogColumnMapper.insert(blogColumn);
    }

    @Override
    public void update(BlogColumn blogColumn) {
        blogColumnMapper.updateById(blogColumn);
    }

    @Override
    public void delete(Integer id) {
        //删除博客_专栏关联表的数据
        blogColumnMapper.deleteBlog_columnByBlogColumnId(id);
        //删除关联表的数据
        blogColumnMapper.deleteById(id);
    }

    @Override
    public BlogColumn findById(Integer id) {
        return blogColumnMapper.selectById(id);
    }

    @Override
    public List findAll() {
        return blogColumnMapper.selectList(null);
    }

    @Override
    public Page search(String search, int page, int size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (search != null) {

        }
        return blogColumnMapper.selectPage(new Page<>(page, size), queryWrapper);
    }

    @Override
    public Page searchByUserId(Integer userId, int page, int size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("userId", userId);
        return blogColumnMapper.selectPage(new Page<>(page, size), queryWrapper);
    }
}

BlogCommentServiceImpl

@Service
@Transactional
public class BlogCommentServiceImpl implements BlogCommentService {
    @Autowired
    private BlogCommentMapper blogCommentMapper;

    @Override
    public void add(BlogComment blogComment) {
        blogCommentMapper.insert(blogComment);
    }

    @Override
    public void update(BlogComment blogComment) {
        blogCommentMapper.updateById(blogComment);
    }

    @Override
    public void delete(Integer id) {
        blogCommentMapper.deleteById(id);
    }

    @Override
    public BlogComment findById(Integer id) {
        return blogCommentMapper.selectById(id);
    }

    @Override
    public List findAll() {
        return blogCommentMapper.selectList(null);
    }

    @Override
    public Page search(String search, int page, int size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (search != null) {

        }
        return blogCommentMapper.selectPage(new Page<>(page, size), queryWrapper);
    }

    @Override
    public Page searchByBlogId(Integer blogId, int page, int size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("blogId", blogId);
        return blogCommentMapper.selectPage(new Page<>(page, size), queryWrapper);
    }
}

BlogServiceImpl

@Service
@Transactional
public class BlogServiceImpl implements BlogService {
    @Autowired
    private BlogMapper blogMapper;

    @Override
    public void add(Blog blog) {
        blogMapper.insert(blog);
    }

    @Override
    public void update(Blog blog) {
        blogMapper.updateById(blog);
    }

    @Override
    public void delete(Integer id) {
        //删除博客_专栏中间表的数据
        blogMapper.deleteBlog_columnByBlogId(id);
        //删除博客_标签中间表的数据
        blogMapper.deleteBlog_tagByBlogId(id);
        //删除博客对应的所有评论
        blogMapper.deleteAllComments(id);
        blogMapper.deleteById(id);
    }

    @Override
    public Blog findById(Integer id) {
        return blogMapper.findById(id);
    }

    @Override
    public List findAll() {
        return blogMapper.selectList(null);
    }

    @Override
    public Page search(String search, int page, int size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (search != null) {
            queryWrapper.like("blogTitle", search);
        }
        return blogMapper.search(new Page<>(page, size), queryWrapper);
    }

    @Override
    public Page searchForStatus(String search, int page, int size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (search != null) {

        }
        return blogMapper.searchWhenStatus(new Page<>(page, size), queryWrapper);
    }


    @Override
    public Page searchByUserId(Integer userId, int page, int size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("userId", userId);
        return blogMapper.search(new Page<>(page, size), queryWrapper);
    }

    @Override
    public void updateStatus(Integer id) {
        Blog blog = blogMapper.selectById(id);
        if (blog.getBlogStatus().equals("1")) {
            blog.setBlogStatus("0");
            blogMapper.updateById(blog);
        } else {
            blog.setBlogStatus("1");
            blogMapper.updateById(blog);
        }
    }

    @Override
    public void addBlog_column(Integer blogId, Integer blogColumnId) {
        blogMapper.addBlog_column(blogId, blogColumnId);
    }

    @Override
    public void deleteBlog_column(Integer blogId, Integer blogColumnId) {
        blogMapper.deleteBlog_column(blogId, blogColumnId);
    }

    @Override
    public List findColumnByBlogId(Integer blogId) {
        return blogMapper.findColumnByBlogId(blogId);
    }

    @Override
    public void addBlog_tag(Integer blogId, Integer blogTagId) {
        blogMapper.addBlog_tag(blogId, blogTagId);
    }

    @Override
    public void deleteBlog_tag(Integer blogId, Integer blogTagId) {
        blogMapper.deleteBlog_tag(blogId, blogTagId);
    }

    @Override
    public List findTagByBlogId(Integer blogId) {
        return blogMapper.findTagByBlogId(blogId);
    }
}

BlogTagServiceImpl

@Service
@Transactional
public class BlogTagServiceImpl implements BlogTagService {
    @Autowired
    private BlogTagMapper blogTagMapper;

    @Override
    public void add(BlogTag blogTag) {
        blogTagMapper.insert(blogTag);
    }

    @Override
    public void update(BlogTag blogTag) {
        blogTagMapper.updateById(blogTag);
    }

    @Override
    public void delete(Integer id) {
        //删除博客_标签关联表的数据
        blogTagMapper.deleteBlog_tagByBlogTagId(id);
        //删除标签
        blogTagMapper.deleteById(id);
    }

    @Override
    public BlogTag findById(Integer id) {
       return blogTagMapper.selectById(id);
    }

    @Override
    public List findAll() {
        return blogTagMapper.selectList(null);
    }

    @Override
    public Page search(String search, int page, int size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (search != null) {

        }
        return blogTagMapper.selectPage(new Page<>(page, size), queryWrapper);
    }
}

BlogTypeServiceImpl

@Service
@Transactional
public class BlogTypeServiceImpl implements BlogTypeService {
    @Autowired
    private BlogTypeMapper blogTypeMapper;

    @Override
    public void add(BlogType blogType) {
        blogTypeMapper.insert(blogType);
    }

    @Override
    public void update(BlogType blogType) {
        blogTypeMapper.updateById(blogType);
    }

    @Override
    public void delete(Integer id) {
        blogTypeMapper.deleteById(id);
    }

    @Override
    public BlogType findById(Integer id) {
       return blogTypeMapper.selectById(id);
    }

    @Override
    public List findAll() {
        return blogTypeMapper.selectList(null);
    }

    @Override
    public Page search(String search, int page, int size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (search != null) {

        }
        return blogTypeMapper.selectPage(new Page<>(page, size), queryWrapper);
    }
}

BlogVisibilityServiceImpl

@Service
@Transactional
public class BlogVisibilityServiceImpl implements BlogVisibilityService {
    @Autowired
    private BlogVisibilityMapper blogVisibilityMapper;

    @Override
    public void add(BlogVisibility blogVisibility) {
        blogVisibilityMapper.insert(blogVisibility);
    }

    @Override
    public void update(BlogVisibility blogVisibility) {
        blogVisibilityMapper.updateById(blogVisibility);
    }

    @Override
    public void delete(Integer id) {
        blogVisibilityMapper.deleteById(id);
    }

    @Override
    public BlogVisibility findById(Integer id) {
        return blogVisibilityMapper.selectById(id);
    }

    @Override
    public List findAll() {
        return blogVisibilityMapper.selectList(null);
    }

    @Override
    public Page search(String search, int page, int size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (search != null) {

        }
        return blogVisibilityMapper.selectPage(new Page<>(page, size), queryWrapper);
    }
}

你可能感兴趣的:(博客系统,linux,java)