Search in sources :

Example 1 with BloggerAccount

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

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

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

the class BloggerAccountController method checkUsernameUsed.

/**
 * 检查用户名是否存在
 */
@RequestMapping(value = "/check=username", method = RequestMethod.GET)
public ResultBean checkUsernameUsed(HttpServletRequest request, @RequestParam("username") String username) {
    handleNameCheck(request, username);
    BloggerAccount account = accountService.getAccount(username);
    if (account != null) {
        return new ResultBean(exceptionManager.getDuplicationDataException(new RequestContext(request)));
    } else {
        return new ResultBean<>("");
    }
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) RequestContext(org.springframework.web.servlet.support.RequestContext) ResultBean(com.duan.blogos.restful.ResultBean)

Example 4 with BloggerAccount

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

the class MyAuthorizingRealm method doGetAuthenticationInfo.

/**
 * 首先执行登录验证
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    // 获取用户账号
    String username = token.getPrincipal().toString();
    BloggerAccount account = accountService.getAccount(username);
    if (account != null) {
        // 将查询到的用户账号和密码存放到 authenticationInfo用于后面的权限判断。第三个参数随便放一个就行了。
        return new SimpleAuthenticationInfo(account.getUsername(), account.getPassword(), "");
    } else {
        return null;
    }
}
Also used : SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount)

Example 5 with BloggerAccount

use of com.duan.blogos.entity.blogger.BloggerAccount 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)

Aggregations

BloggerAccount (com.duan.blogos.entity.blogger.BloggerAccount)18 BloggerProfile (com.duan.blogos.entity.blogger.BloggerProfile)6 ResultBean (com.duan.blogos.restful.ResultBean)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 BloggerDTO (com.duan.blogos.dto.blogger.BloggerDTO)4 BloggerPicture (com.duan.blogos.entity.blogger.BloggerPicture)4 BloggerStatisticsDTO (com.duan.blogos.dto.blogger.BloggerStatisticsDTO)3 BloggerSetting (com.duan.blogos.entity.blogger.BloggerSetting)3 File (java.io.File)3 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 MultipartFile (org.springframework.web.multipart.MultipartFile)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 BlogListItemDTO (com.duan.blogos.dto.blog.BlogListItemDTO)2 FavouriteBlogListItemDTO (com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO)2 UnknownInternalException (com.duan.blogos.exception.internal.UnknownInternalException)2 BlogListItemComparatorFactory (com.duan.blogos.manager.comparator.BlogListItemComparatorFactory)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 HashMap (java.util.HashMap)2 HttpSession (javax.servlet.http.HttpSession)2