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);
}
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);
}
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);
}
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();
}
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;
}
Aggregations