Search in sources :

Example 1 with BloggerProfile

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

the class BlogStatisticsServiceImpl method getBlogger.

// 获得博主dto
private BloggerDTO[] getBlogger(int[] ids, int bloggerId) {
    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(bloggerId);
            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)

Example 2 with BloggerProfile

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

the class BloggerSettingPageController method pageLike.

@RequestMapping
public ModelAndView pageLike(HttpServletRequest request, @ModelAttribute @PathVariable String bloggerName) {
    ModelAndView mv = new ModelAndView();
    mv.setViewName("/blogger/setting");
    BloggerAccount account = accountService.getAccount(bloggerName);
    int bloggerId;
    if (account == null) {
        mv.addObject("code", UnknownBloggerException.code);
        mv.addObject(bloggerProperties.getSessionNameOfErrorMsg(), "博主不存在!");
        mv.setViewName("error/error");
        return mv;
    } else if (!bloggerValidateManager.checkBloggerSignIn(request, bloggerId = account.getId())) {
        mv.addObject("code", BloggerNotLoggedInException.code);
        mv.addObject(bloggerProperties.getSessionNameOfErrorMsg(), "博主未登录!");
        mv.setViewName("error/error");
        return mv;
    }
    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 3 with BloggerProfile

use of com.duan.blogos.entity.blogger.BloggerProfile 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 4 with BloggerProfile

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

the class BloggerProfileServiceImpl method updateBloggerProfile.

@Override
public boolean updateBloggerProfile(int bloggerId, int avatarId, String newPhone, String newEmail, String newAboutMe, String newIntro) {
    BloggerProfile profile = profileDao.getProfileByBloggerId(bloggerId);
    if (profile == null)
        return false;
    Integer oldAvatarId = profile.getAvatarId();
    profile.setAvatarId(avatarId == -1 ? null : avatarId);
    profile.setPhone(newPhone);
    profile.setEmail(newEmail);
    profile.setAboutMe(newAboutMe);
    profile.setIntro(newIntro);
    int effect = profileDao.update(profile);
    if (effect <= 0)
        return false;
    if (avatarId > 0)
        imageManager.imageUpdateHandle(bloggerId, avatarId, oldAvatarId);
    return true;
}
Also used : BloggerProfile(com.duan.blogos.entity.blogger.BloggerProfile)

Example 5 with BloggerProfile

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

the class BloggerProfileServiceImpl method deleteBloggerProfile.

@Override
public boolean deleteBloggerProfile(int bloggerId) {
    BloggerProfile profile = profileDao.getProfileByBloggerId(bloggerId);
    int effect = profileDao.delete(bloggerId);
    if (effect <= 0)
        return false;
    Integer id;
    if ((id = profile.getAvatarId()) != null)
        pictureDao.updateUseCountMinus(id);
    return true;
}
Also used : 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