Search in sources :

Example 6 with BloggerPicture

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

the class BloggerGalleryController method update.

/**
 * 更新图片信息
 */
@RequestMapping(value = "/{pictureId}", method = RequestMethod.PUT)
public ResultBean update(HttpServletRequest request, @PathVariable("bloggerId") Integer bloggerId, @PathVariable("pictureId") Integer pictureId, @RequestParam(value = "category", required = false) Integer newCategory, @RequestParam(value = "bewrite", required = false) String newBeWrite, @RequestParam(value = "title", required = false) String newTitle) {
    handleBloggerSignInCheck(request, bloggerId);
    RequestContext context = new RequestContext(request);
    // 检查博主是否有指定图片
    BloggerPicture picture = bloggerPictureService.getPicture(pictureId);
    if (picture == null || !bloggerId.equals(picture.getBloggerId())) {
        throw exceptionManager.getParameterIllegalException(context);
    }
    if (newCategory == null && newBeWrite == null && newTitle == null) {
        throw exceptionManager.getParameterIllegalException(context);
    }
    // 更新图片类别只适用于图片管理员,普通博主没有修改类别的必要
    if (newCategory != null) {
        // 检查类别是否存在
        if (BloggerPictureCategoryEnum.valueOf(newCategory) == null) {
            throw exceptionManager.getParameterIllegalException(context);
        }
        // 检查权限
        if (!validateManager.checkBloggerPictureLegal(bloggerId, newCategory))
            throw exceptionManager.getUnauthorizedException(context);
    }
    boolean result = bloggerPictureService.updatePicture(pictureId, newCategory == null ? null : BloggerPictureCategoryEnum.valueOf(newCategory), newBeWrite, newTitle);
    if (!result)
        handlerOperateFail(request);
    return new ResultBean<>("");
}
Also used : BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) RequestContext(org.springframework.web.servlet.support.RequestContext) ResultBean(com.duan.blogos.restful.ResultBean)

Example 7 with BloggerPicture

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

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

the class ImageManager method moveImageAndUpdateDbIfNecessary.

/**
 * 修改图片类别,并移动到对应类别
 *
 * @param bloggerId 博主id
 * @param pictureId 图片id
 * @param category  类别
 * @return 移动了返回true
 */
public boolean moveImageAndUpdateDbIfNecessary(int bloggerId, int pictureId, BloggerPictureCategoryEnum category) throws IOException {
    if (pictureId <= 0 || category == null)
        return false;
    BloggerPicture picture = pictureDao.getPictureById(pictureId);
    if (picture == null || picture.getCategory() == category.getCode())
        return false;
    String newPath = moveImage(picture, bloggerId, category);
    picture.setPath(newPath);
    picture.setCategory(category.getCode());
    return pictureDao.update(picture) > 0;
}
Also used : BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture)

Example 9 with BloggerPicture

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

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

the class ImageManager method moveImageAndUpdateDbAndUseCountIfNecessary.

/**
 * 检查图片类别,如果新的图片为PRIVATE,则修改为PUBLIC,并移动文件,同时将其useCount++,旧图片的useCount--
 *
 * @param bloggerId    博主id
 * @param newPictureId 新图片id
 * @param oldPictureId 旧图片id
 * @return 操作成功返回true
 */
public boolean moveImageAndUpdateDbAndUseCountIfNecessary(int bloggerId, int newPictureId, int oldPictureId) throws IOException {
    if (newPictureId == oldPictureId)
        return false;
    // 将新图片指向图片修改为公开并移动目录(需要的话)
    if (newPictureId > 0) {
        // UPDATE: 2018/1/28 更新 是否“公开”图片由 Service 决定,而不是方法最终调用处
        BloggerPicture picture = pictureDao.getPictureById(newPictureId);
        // 私有图片才有必要对齐进行“公开”处理
        if (picture.getCategory().equals(BloggerPictureCategoryEnum.PRIVATE.getCode()))
            moveImageAndUpdateDbIfNecessary(bloggerId, newPictureId, PUBLIC);
        // 新图片useCount++
        pictureDao.updateUseCountPlus(newPictureId);
    }
    // 旧图片useCount--
    if (oldPictureId > 0) {
        pictureDao.updateUseCountMinus(oldPictureId);
    }
    return true;
}
Also used : BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture)

Aggregations

BloggerPicture (com.duan.blogos.entity.blogger.BloggerPicture)18 ResultBean (com.duan.blogos.restful.ResultBean)5 RequestContext (org.springframework.web.servlet.support.RequestContext)5 BloggerAccount (com.duan.blogos.entity.blogger.BloggerAccount)4 BloggerProfile (com.duan.blogos.entity.blogger.BloggerProfile)4 BloggerDTO (com.duan.blogos.dto.blogger.BloggerDTO)3 InternalIOException (com.duan.blogos.exception.internal.InternalIOException)3 ArrayList (java.util.ArrayList)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 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 BloggerLinkDTO (com.duan.blogos.dto.blogger.BloggerLinkDTO)1 BloggerLink (com.duan.blogos.entity.blogger.BloggerLink)1 BloggerSetting (com.duan.blogos.entity.blogger.BloggerSetting)1 List (java.util.List)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1