Search in sources :

Example 6 with BloggerProfile

use of com.duan.blogos.entity.blogger.BloggerProfile in project BlogSystem by DuanJiaNing.

the class BloggerSettingPageController method pageSetting.

@RequestMapping
public ModelAndView pageSetting(HttpServletRequest request, @ModelAttribute @PathVariable String bloggerName) {
    ModelAndView mv = new ModelAndView();
    mv.setViewName("/blogger/setting");
    BloggerAccount account = accountService.getAccount(bloggerName);
    int bloggerId;
    if (account == null) {
        request.setAttribute("code", UnknownBloggerException.code);
        mv.setViewName("/blogger/register");
        return mv;
    } else if (!bloggerValidateManager.checkBloggerSignIn(request, bloggerId = account.getId())) {
        return new ModelAndView("redirect:/login");
    }
    BloggerProfile profile = profileService.getBloggerProfile(bloggerId);
    if (profile.getAvatarId() == null) {
        BloggerPicture picture = pictureService.getDefaultPicture(BloggerPictureCategoryEnum.DEFAULT_BLOGGER_AVATAR);
        profile.setAvatarId(picture.getId());
    }
    mv.addObject("profile", profile);
    BloggerSetting setting = settingService.getSetting(bloggerId);
    mv.addObject("setting", setting);
    return mv;
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) BloggerSetting(com.duan.blogos.entity.blogger.BloggerSetting) ModelAndView(org.springframework.web.servlet.ModelAndView) BloggerProfile(com.duan.blogos.entity.blogger.BloggerProfile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with BloggerProfile

use of com.duan.blogos.entity.blogger.BloggerProfile in project BlogSystem by DuanJiaNing.

the class BloggerCollectBlogServiceImpl method listCollectBlog.

@Override
public ResultBean<List<FavouriteBlogListItemDTO>> listCollectBlog(int bloggerId, int categoryId, int offset, int rows, BlogSortRule sortRule) {
    List<BlogCollect> collects = collectDao.listCollectBlog(bloggerId, categoryId, offset, rows);
    if (CollectionUtils.isEmpty(collects))
        return null;
    // 排序
    List<BlogStatistics> temp = new ArrayList<>();
    // 方便排序后的重组
    Map<Integer, BlogCollect> blogCollectMap = new HashMap<>();
    for (BlogCollect collect : collects) {
        int blogId = collect.getBlogId();
        BlogStatistics statistics = statisticsDao.getStatistics(blogId);
        temp.add(statistics);
        blogCollectMap.put(blogId, collect);
    }
    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);
        // 结果
        BlogCollect collect = blogCollectMap.get(blogId);
        FavouriteBlogListItemDTO dto = fillingManager.collectBlogListItemToDTO(bloggerId, collect, 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 8 with BloggerProfile

use of com.duan.blogos.entity.blogger.BloggerProfile in project BlogSystem by DuanJiaNing.

the class BlogBrowseServiceImpl method listBlogComment.

@Override
public ResultBean<List<BlogCommentDTO>> listBlogComment(int blogId, int offset, int rows) {
    List<BlogCommentDTO> result = new ArrayList<>();
    List<BlogComment> comments = commentDao.listCommentByBlogId(blogId, offset, rows, BlogCommentStatusEnum.RIGHTFUL.getCode());
    for (BlogComment comment : comments) {
        // 评论者数据
        int sid = comment.getSpokesmanId();
        BloggerAccount smAccount = accountDao.getAccountById(sid);
        BloggerProfile smProfile = getProfile(sid);
        BloggerDTO smDTO = dataFillingManager.bloggerAccountToDTO(smAccount, smProfile, getAvatar(smProfile.getAvatarId()));
        BlogCommentDTO dto = dataFillingManager.blogCommentToDTO(comment, smDTO);
        result.add(dto);
    }
    return CollectionUtils.isEmpty(result) ? null : new ResultBean<>(result);
}
Also used : BloggerDTO(com.duan.blogos.dto.blogger.BloggerDTO) BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) ArrayList(java.util.ArrayList) BlogComment(com.duan.blogos.entity.blog.BlogComment) BlogCommentDTO(com.duan.blogos.dto.blog.BlogCommentDTO) BloggerProfile(com.duan.blogos.entity.blogger.BloggerProfile)

Example 9 with BloggerProfile

use of com.duan.blogos.entity.blogger.BloggerProfile in project BlogSystem by DuanJiaNing.

the class BloggerProfileServiceImpl method insertBloggerProfile.

@Override
public int insertBloggerProfile(int bloggerId, int avatarId, String phone, String email, String aboutMe, String intro) {
    BloggerProfile profile = new BloggerProfile();
    profile.setAboutMe(aboutMe);
    profile.setBloggerId(bloggerId);
    profile.setAvatarId(avatarId < 0 ? null : avatarId);
    profile.setEmail(email);
    profile.setIntro(intro);
    profile.setPhone(phone);
    int effect = profileDao.insert(profile);
    if (effect <= 0)
        return -1;
    if (avatarId > 0)
        imageManager.imageInsertHandle(bloggerId, avatarId);
    return profile.getId();
}
Also used : BloggerProfile(com.duan.blogos.entity.blogger.BloggerProfile)

Example 10 with BloggerProfile

use of com.duan.blogos.entity.blogger.BloggerProfile in project BlogSystem by DuanJiaNing.

the class BloggerStatisticsServiceImpl method listBloggerDTO.

// 获得博主dto
@Override
public BloggerDTO[] listBloggerDTO(int... ids) {
    if (CollectionUtils.isEmpty(ids))
        return null;
    BloggerDTO[] dtos = new BloggerDTO[ids.length];
    int c = 0;
    for (int id : ids) {
        BloggerAccount account = accountDao.getAccountById(id);
        BloggerProfile profile = profileDao.getProfileByBloggerId(id);
        BloggerPicture avatar = null;
        Integer avatarId = profile.getAvatarId();
        if (avatarId != null)
            avatar = pictureDao.getPictureById(avatarId);
        if (avatar != null)
            avatar.setPath(stringConstructorManager.constructPictureUrl(avatar, BloggerPictureCategoryEnum.DEFAULT_BLOGGER_AVATAR));
        // 设置默认头像
        if (avatar == null) {
            avatar = new BloggerPicture();
            avatar.setBloggerId(id);
            avatar.setCategory(BloggerPictureCategoryEnum.PUBLIC.getCode());
            avatar.setId(-1);
            avatar.setPath(stringConstructorManager.constructPictureUrl(avatar, BloggerPictureCategoryEnum.DEFAULT_BLOGGER_AVATAR));
        }
        BloggerDTO dto = dataFillingManager.bloggerAccountToDTO(account, profile, avatar);
        dtos[c++] = dto;
    }
    return Arrays.copyOf(dtos, c);
}
Also used : BloggerDTO(com.duan.blogos.dto.blogger.BloggerDTO) BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) BloggerProfile(com.duan.blogos.entity.blogger.BloggerProfile)

Aggregations

BloggerProfile (com.duan.blogos.entity.blogger.BloggerProfile)12 BloggerAccount (com.duan.blogos.entity.blogger.BloggerAccount)8 BloggerPicture (com.duan.blogos.entity.blogger.BloggerPicture)6 BloggerDTO (com.duan.blogos.dto.blogger.BloggerDTO)5 BloggerSetting (com.duan.blogos.entity.blogger.BloggerSetting)3 ResultBean (com.duan.blogos.restful.ResultBean)3 ArrayList (java.util.ArrayList)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 BlogListItemDTO (com.duan.blogos.dto.blog.BlogListItemDTO)2 FavouriteBlogListItemDTO (com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO)2 BlogListItemComparatorFactory (com.duan.blogos.manager.comparator.BlogListItemComparatorFactory)2 HashMap (java.util.HashMap)2 BlogCommentDTO (com.duan.blogos.dto.blog.BlogCommentDTO)1 BloggerStatisticsDTO (com.duan.blogos.dto.blogger.BloggerStatisticsDTO)1 BlogComment (com.duan.blogos.entity.blog.BlogComment)1