Search in sources :

Example 11 with BloggerPicture

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

the class ImageController method getBlogPicture.

/**
 * 输出公开图片,这些图片无需验证登录,如果数据库不存在指定图片,则返回默认图片
 */
@RequestMapping(value = "/type=public/{imageId}", method = RequestMethod.GET)
public void getBlogPicture(HttpServletRequest request, HttpServletResponse response, @PathVariable("bloggerId") Integer bloggerId, @PathVariable("imageId") Integer imageId, @RequestParam(value = "default", required = false) Integer category) {
    handleAccountCheck(request, bloggerId);
    // 检查default是否为默认类别
    if (category != null)
        handleBlogCategoryDefaultCheck(request, category);
    BloggerPicture picture = bloggerPictureService.getPicture(imageId, bloggerId);
    // 如果图片是私有的,不能访问
    if (picture != null && picture.getCategory().equals(BloggerPictureCategoryEnum.PRIVATE.getCode()))
        throw exceptionManager.getUnauthorizedException(new RequestContext(request));
    BloggerPicture backupPicture = bloggerPictureService.getDefaultPicture(category == null ? BloggerPictureCategoryEnum.DEFAULT_PICTURE : // 如果目标图片不存在,返回指定类别的默认图片
    BloggerPictureCategoryEnum.valueOf(category));
    // 输出图片
    outPutPicture(picture, backupPicture, request, response);
}
Also used : BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) RequestContext(org.springframework.web.servlet.support.RequestContext)

Example 12 with BloggerPicture

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

the class ImageController method getBloggerPicture.

/**
 * 获取博主的私有图片(任意图片),这些图片需要验证登录
 */
@RequestMapping(value = "/type=private/{imageId}", method = RequestMethod.GET)
public void getBloggerPicture(HttpServletRequest request, HttpServletResponse response, @PathVariable("bloggerId") Integer bloggerId, @PathVariable("imageId") Integer imageId, @RequestParam(value = "default", required = false) Integer category) {
    handleBloggerSignInCheck(request, bloggerId);
    // 检查默认图片类别是否为默认类别
    if (category != null)
        handleBlogCategoryDefaultCheck(request, category);
    BloggerPicture picture = bloggerPictureService.getPicture(imageId, bloggerId);
    BloggerPicture backupPicture = bloggerPictureService.getDefaultPicture(category == null ? BloggerPictureCategoryEnum.DEFAULT_PICTURE : // 如果目标图片不存在,返回指定类别的默认图片
    BloggerPictureCategoryEnum.valueOf(category));
    // 输出图片
    outPutPicture(picture, backupPicture, request, response);
}
Also used : BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture)

Example 13 with BloggerPicture

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

the class BloggerLinkServiceImpl method listBloggerLink.

@Override
public ResultBean<List<BloggerLinkDTO>> listBloggerLink(int bloggerId, int offset, int rows) {
    List<BloggerLink> list = linkDao.listBlogLinkByBloggerId(bloggerId, offset, rows);
    List<BloggerLinkDTO> result = new ArrayList<>();
    for (BloggerLink link : list) {
        Integer iconId = link.getIconId();
        BloggerPicture icon = iconId == null ? pictureDao.getBloggerUniquePicture(bloggerProperties.getPictureManagerBloggerId(), DEFAULT_BLOGGER_LINK_ICON.getCode()) : pictureDao.getPictureById(iconId);
        icon.setPath(constructorManager.constructPictureUrl(icon, DEFAULT_BLOGGER_LINK_ICON));
        BloggerLinkDTO dto = fillingManager.bloggerLinkToDTO(link, icon);
        result.add(dto);
    }
    return CollectionUtils.isEmpty(result) ? null : new ResultBean<>(result);
}
Also used : BloggerLink(com.duan.blogos.entity.blogger.BloggerLink) BloggerLinkDTO(com.duan.blogos.dto.blogger.BloggerLinkDTO) BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) ArrayList(java.util.ArrayList)

Example 14 with BloggerPicture

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

the class BloggerPictureServiceImpl method insertPicture.

@Override
public int insertPicture(int bloggerId, String path, String bewrite, BloggerPictureCategoryEnum category, String title) {
    BloggerPicture picture = new BloggerPicture();
    picture.setBewrite(bewrite);
    picture.setBloggerId(bloggerId);
    picture.setCategory(category.getCode());
    picture.setPath(path);
    picture.setTitle(title);
    int effect = pictureDao.insert(picture);
    if (effect <= 0)
        return -1;
    return picture.getId();
}
Also used : BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture)

Example 15 with BloggerPicture

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

the class BloggerPictureServiceImpl method deletePicture.

@Override
public boolean deletePicture(int bloggerId, int pictureId, boolean deleteOnDisk) {
    BloggerPicture picture = getPicture(pictureId);
    // 对默认图片,图片管理员只能以更新(上传)的方式删除图片,因为这些图片必须时刻存在
    int pictureManagerId = bloggerProperties.getPictureManagerBloggerId();
    int cate = picture.getCategory();
    if (bloggerId == pictureManagerId && BloggerPictureCategoryEnum.isDefaultPictureCategory(cate))
        return false;
    // 删除数据库记录
    String path = picture.getPath();
    int effect = pictureDao.delete(pictureId);
    if (effect <= 0)
        return false;
    if (deleteOnDisk) {
        // 删除磁盘文件
        boolean succ = imageManager.deleteImageFromDisk(path);
        // 删除失败时抛出异常,使数据库事务回滚
        if (!succ)
            throw new InternalIOException();
    }
    return true;
}
Also used : BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) InternalIOException(com.duan.blogos.exception.internal.InternalIOException)

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