Search in sources :

Example 1 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BloggerLikeBlogServiceImpl method listLikeBlog.

@Override
public ResultBean<List<FavouriteBlogListItemDTO>> listLikeBlog(int bloggerId, int offset, int rows, BlogSortRule sortRule) {
    List<BlogLike> likes = likeDao.listLikeBlog(bloggerId, offset, rows);
    if (CollectionUtils.isEmpty(likes))
        return null;
    // 排序
    List<BlogStatistics> temp = new ArrayList<>();
    // 方便排序后的重组
    Map<Integer, BlogLike> blogLikeMap = new HashMap<>();
    for (BlogLike like : likes) {
        int blogId = like.getBlogId();
        BlogStatistics statistics = statisticsDao.getStatistics(blogId);
        temp.add(statistics);
        blogLikeMap.put(blogId, like);
    }
    BlogListItemComparatorFactory factory = new BlogListItemComparatorFactory();
    temp.sort(factory.get(sortRule.getRule(), sortRule.getOrder()));
    // 构造结果
    List<FavouriteBlogListItemDTO> result = new ArrayList<>();
    for (BlogStatistics statistics : temp) {
        int blogId = statistics.getBlogId();
        // BlogListItemDTO
        Blog blog = blogDao.getBlogById(blogId);
        String ch = dbProperties.getStringFiledSplitCharacterForNumber();
        // category
        int[] cids = StringUtils.intStringDistinctToArray(blog.getCategoryIds(), ch);
        List<BlogCategory> categories = null;
        if (!CollectionUtils.isEmpty(cids)) {
            categories = categoryDao.listCategoryById(cids);
        }
        // label
        int[] lids = StringUtils.intStringDistinctToArray(blog.getLabelIds(), ch);
        List<BlogLabel> labels = null;
        if (!CollectionUtils.isEmpty(lids)) {
            labels = labelDao.listLabelById(lids);
        }
        BlogListItemDTO listItemDTO = fillingManager.blogListItemToDTO(statistics, CollectionUtils.isEmpty(categories) ? null : categories.toArray(new BlogCategory[categories.size()]), CollectionUtils.isEmpty(labels) ? null : labels.toArray(new BlogLabel[labels.size()]), blog, null);
        // BloggerDTO
        int authorId = blog.getBloggerId();
        BloggerAccount account = accountDao.getAccountById(authorId);
        BloggerProfile profile = profileDao.getProfileByBloggerId(authorId);
        BloggerPicture avatar = profile.getAvatarId() == null ? null : pictureDao.getPictureById(profile.getAvatarId());
        // 使使用默认的博主头像
        if (avatar == null) {
            avatar = new BloggerPicture();
            avatar.setCategory(BloggerPictureCategoryEnum.PUBLIC.getCode());
            avatar.setBloggerId(authorId);
            avatar.setId(-1);
        }
        String url = constructorManager.constructPictureUrl(avatar, BloggerPictureCategoryEnum.DEFAULT_BLOGGER_AVATAR);
        avatar.setPath(url);
        BloggerDTO bloggerDTO = fillingManager.bloggerAccountToDTO(account, profile, avatar);
        // 结果
        BlogLike like = blogLikeMap.get(blogId);
        FavouriteBlogListItemDTO dto = fillingManager.likeBlogListItemToDTO(bloggerId, like, listItemDTO, bloggerDTO);
        result.add(dto);
    }
    return new ResultBean<>(result);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlogListItemComparatorFactory(com.duan.blogos.manager.comparator.BlogListItemComparatorFactory) BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) BloggerProfile(com.duan.blogos.entity.blogger.BloggerProfile) FavouriteBlogListItemDTO(com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO) BloggerDTO(com.duan.blogos.dto.blogger.BloggerDTO) FavouriteBlogListItemDTO(com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO) BlogListItemDTO(com.duan.blogos.dto.blog.BlogListItemDTO) ResultBean(com.duan.blogos.restful.ResultBean)

Example 2 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BlogStatisticsServiceImpl method getBlogStatistics.

@Override
public ResultBean<BlogStatisticsDTO> getBlogStatistics(int blogId) {
    Blog blog = blogDao.getBlogById(blogId);
    if (blog == null)
        return null;
    int bloggerId = blog.getBloggerId();
    // 统计信息
    BlogStatistics statistics = statisticsDao.getStatistics(blogId);
    if (statistics == null)
        return null;
    // 类别
    BlogCategory[] categories = null;
    String sn = dbProperties.getStringFiledSplitCharacterForNumber();
    int[] cids = StringUtils.intStringDistinctToArray(blog.getCategoryIds(), sn);
    if (!CollectionUtils.isEmpty(cids)) {
        categories = categoryDao.listCategoryById(cids).toArray(new BlogCategory[cids.length]);
    }
    // 标签
    BlogLabel[] labels = null;
    int[] lids = StringUtils.intStringDistinctToArray(blog.getLabelIds(), sn);
    if (!CollectionUtils.isEmpty(lids)) {
        labels = labelDao.listLabelById(lids).toArray(new BlogLabel[lids.length]);
    }
    int c = 0;
    // 喜欢该篇文章的人
    BloggerDTO[] likes = null;
    List<BlogLike> likeList = likeDao.listAllLikeByBlogId(blogId);
    if (!CollectionUtils.isEmpty(likeList)) {
        int[] ids = new int[likeList.size()];
        for (BlogLike like : likeList) {
            ids[c++] = like.getLikerId();
        }
        likes = getBlogger(ids, bloggerId);
    }
    // 收藏了该篇文章的人
    BloggerDTO[] collects = null;
    c = 0;
    List<BlogCollect> collectList = collectDao.listAllCollectByBlogId(blogId);
    if (!CollectionUtils.isEmpty(collectList)) {
        int[] ids = new int[collectList.size()];
        for (BlogCollect collect : collectList) {
            ids[c++] = collect.getCollectorId();
        }
        collects = getBlogger(ids, bloggerId);
    }
    // 评论过该篇文章的人
    BloggerDTO[] commenter = null;
    c = 0;
    List<BlogComment> commentList = commentDao.listAllCommentByBlogId(blogId);
    if (!CollectionUtils.isEmpty(commentList)) {
        int[] ids = new int[commentList.size()];
        for (BlogComment comment : commentList) {
            // 评论者注销,但其评论将保存(匿名)
            Integer id = comment.getSpokesmanId();
            if (id != null)
                ids[c++] = id;
        }
        // ids 需要去重
        commenter = getBlogger(IntStream.of(Arrays.copyOf(ids, c)).distinct().toArray(), bloggerId);
    }
    BlogStatisticsDTO dto = dataFillingManager.blogStatisticsToDTO(blog, statistics, categories, labels, likes, collects, commenter, dbProperties.getStringFiledSplitCharacterForString());
    return new ResultBean<>(dto);
}
Also used : BlogStatisticsDTO(com.duan.blogos.dto.blog.BlogStatisticsDTO) BloggerDTO(com.duan.blogos.dto.blogger.BloggerDTO) ResultBean(com.duan.blogos.restful.ResultBean)

Example 3 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BlogBrowseServiceImpl method getBlogMainContent.

@Override
public ResultBean<BlogMainContentDTO> getBlogMainContent(int blogId) {
    // 查询数据
    Blog blog = blogDao.getBlogById(blogId);
    if (blog == null)
        return null;
    String ch = dbProperties.getStringFiledSplitCharacterForNumber();
    int[] cids = StringUtils.intStringDistinctToArray(blog.getCategoryIds(), ch);
    int[] lids = StringUtils.intStringDistinctToArray(blog.getLabelIds(), ch);
    List<BlogCategory> categories = cids == null ? null : categoryDao.listCategoryById(cids);
    List<BlogLabel> labels = lids == null ? null : labelDao.listLabelById(lids);
    // 填充数据
    String sc = dbProperties.getStringFiledSplitCharacterForString();
    BlogMainContentDTO dto = dataFillingManager.blogMainContentToDTO(blog, categories, labels, sc);
    return new ResultBean<>(dto);
}
Also used : BlogLabel(com.duan.blogos.entity.blog.BlogLabel) BlogCategory(com.duan.blogos.entity.blog.BlogCategory) Blog(com.duan.blogos.entity.blog.Blog) BlogMainContentDTO(com.duan.blogos.dto.blog.BlogMainContentDTO) ResultBean(com.duan.blogos.restful.ResultBean)

Example 4 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BloggerBlogServiceImpl method constructResult.

@Override
protected ResultBean<List<BlogListItemDTO>> constructResult(Map<Integer, Blog> blogHashMap, List<BlogStatistics> statistics, Map<Integer, int[]> blogIdMapCategoryIds, Map<Integer, String> blogImgs) {
    // 重组结果
    List<BlogListItemDTO> result = new ArrayList<>();
    for (BlogStatistics s : statistics) {
        Integer blogId = s.getBlogId();
        int[] ids = blogIdMapCategoryIds.get(blogId);
        List<BlogCategory> categories = CollectionUtils.isEmpty(ids) ? null : categoryDao.listCategoryById(ids);
        Blog blog = blogHashMap.get(blogId);
        BlogListItemDTO dto = dataFillingManager.bloggerBlogListItemToDTO(blog, s, categories);
        result.add(dto);
    }
    return new ResultBean<>(result);
}
Also used : BlogCategory(com.duan.blogos.entity.blog.BlogCategory) BlogStatistics(com.duan.blogos.entity.blog.BlogStatistics) BlogListItemDTO(com.duan.blogos.dto.blogger.BlogListItemDTO) Blog(com.duan.blogos.entity.blog.Blog) ResultBean(com.duan.blogos.restful.ResultBean)

Example 5 with ResultBean

use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.

the class BloggerAccountController method modifyPassword.

/**
 * 修改密码
 */
@RequestMapping(value = "/{bloggerId}/item=pwd", method = RequestMethod.PUT)
public ResultBean modifyPassword(HttpServletRequest request, @PathVariable Integer bloggerId, @RequestParam(value = "old") String oldPassword, @RequestParam(value = "new") String newPassword) {
    handleBloggerSignInCheck(request, bloggerId);
    handlePwdCheck(request, newPassword);
    boolean result = accountService.updateAccountPassword(bloggerId, oldPassword, newPassword);
    if (!result)
        handlerOperateFail(request);
    // session 失效,重新登录
    HttpSession session = request.getSession();
    session.invalidate();
    return new ResultBean<>("");
}
Also used : HttpSession(javax.servlet.http.HttpSession) ResultBean(com.duan.blogos.restful.ResultBean)

Aggregations

ResultBean (com.duan.blogos.restful.ResultBean)28 RequestContext (org.springframework.web.servlet.support.RequestContext)12 Blog (com.duan.blogos.entity.blog.Blog)5 BloggerAccount (com.duan.blogos.entity.blogger.BloggerAccount)5 BloggerPicture (com.duan.blogos.entity.blogger.BloggerPicture)5 HttpSession (javax.servlet.http.HttpSession)5 BlogCategory (com.duan.blogos.entity.blog.BlogCategory)4 ArrayList (java.util.ArrayList)4 BlogListItemDTO (com.duan.blogos.dto.blog.BlogListItemDTO)3 BloggerDTO (com.duan.blogos.dto.blogger.BloggerDTO)3 BloggerProfile (com.duan.blogos.entity.blogger.BloggerProfile)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 BloggerCategoryDTO (com.duan.blogos.dto.blogger.BloggerCategoryDTO)2 FavouriteBlogListItemDTO (com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO)2 BlogLabel (com.duan.blogos.entity.blog.BlogLabel)2 BlogStatistics (com.duan.blogos.entity.blog.BlogStatistics)2 BlogListItemComparatorFactory (com.duan.blogos.manager.comparator.BlogListItemComparatorFactory)2 HashMap (java.util.HashMap)2 JSONObject (com.alibaba.fastjson.JSONObject)1 BlogMainContentDTO (com.duan.blogos.dto.blog.BlogMainContentDTO)1