use of com.duan.blogos.entity.blogger.BloggerPicture 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);
}
use of com.duan.blogos.entity.blogger.BloggerPicture in project BlogSystem by DuanJiaNing.
the class BloggerPictureServiceImpl method removeDefaultPictureIfNecessary.
/*
* 腾地方
* 移到默认图片到私有图片文件夹,同时修改数据库记录
* @param bloggerId 博主id
*/
private void removeDefaultPictureIfNecessary(int bloggerId, BloggerPictureCategoryEnum defaultCate) {
BloggerPicture unique = pictureDao.getBloggerUniquePicture(bloggerId, defaultCate.getCode());
if (unique != null) {
try {
// 移动默认图片到私有类别图片所在文件夹
String newPath = imageManager.moveImage(unique, bloggerId, BloggerPictureCategoryEnum.PRIVATE);
// 更新数据库记录
unique.setCategory(BloggerPictureCategoryEnum.PRIVATE.getCode());
unique.setPath(newPath);
pictureDao.update(unique);
} catch (IOException e) {
e.printStackTrace();
// MAYBUG 回滚数据库操作,但磁盘操作无法预料,也无法处理
throw new InternalIOException(e);
}
}
}
use of com.duan.blogos.entity.blogger.BloggerPicture in project BlogSystem by DuanJiaNing.
the class BloggerPictureServiceImpl method updatePicture.
@Override
public boolean updatePicture(int pictureId, BloggerPictureCategoryEnum category, String bewrite, String title) {
BloggerPicture oldPicture = pictureDao.getPictureById(pictureId);
// 修改设备上图片路径,如果需要的话
String newPath = null;
if (category != null && category.getCode() != oldPicture.getCategory()) {
// 修改了类别
int bloggerId = oldPicture.getBloggerId();
try {
int pictureManagerId = bloggerProperties.getPictureManagerBloggerId();
// 如果为图片管理员在操作
if (pictureManagerId == bloggerId) {
// 以下两种情况将更新失败,对于默认图片,且图片管理员在操作的情况下,要修改类别或删除图片,只能
// 以 普通 -> 默认 的修改方向替换图片,因为这些图片必须时刻存在
// 1 目标类别是默认类别,原先类别也为默认类别 默认 -> 默认
// 2 目标类别为普通类别,原先类别为默认类别 默认 -> 普通
int oldCategory = oldPicture.getCategory();
if ((BloggerPictureCategoryEnum.isDefaultPictureCategory(oldCategory) && BloggerPictureCategoryEnum.isDefaultPictureCategory(category.getCode())) || (BloggerPictureCategoryEnum.isDefaultPictureCategory(oldCategory) && !BloggerPictureCategoryEnum.isDefaultPictureCategory(category.getCode()))) {
return false;
} else {
// 腾位置,如果需要的话
removeDefaultPictureIfNecessary(bloggerId, category);
// 移动到目标目录
newPath = imageManager.moveImage(oldPicture, bloggerId, category);
}
} else {
// 不是图片管理员则只需移动文件即可
newPath = imageManager.moveImage(oldPicture, bloggerId, category);
}
} catch (IOException e) {
e.printStackTrace();
throw new InternalIOException(e);
}
}
BloggerPicture newPicture = new BloggerPicture();
newPicture.setBewrite(bewrite);
newPicture.setBloggerId(oldPicture.getBloggerId());
newPicture.setCategory(category == null ? oldPicture.getCategory() : category.getCode());
newPicture.setId(oldPicture.getId());
newPicture.setTitle(title);
newPicture.setPath(newPath == null ? oldPicture.getPath() : newPath);
int effect = pictureDao.update(newPicture);
if (effect <= 0)
return false;
return true;
}
use of com.duan.blogos.entity.blogger.BloggerPicture 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);
}
use of com.duan.blogos.entity.blogger.BloggerPicture in project BlogSystem by DuanJiaNing.
the class BloggerCategoryServiceImpl method getBloggerCategoryDTO.
// 获得单个类别
private BloggerCategoryDTO getBloggerCategoryDTO(int bloggerId, BlogCategory category) {
Integer iconId = category.getIconId();
BloggerPicture icon;
if (iconId == null) {
// 默认图片
int pictureManagerId = bloggerProperties.getPictureManagerBloggerId();
icon = pictureDao.getBloggerUniquePicture(pictureManagerId, DEFAULT_BLOGGER_BLOG_CATEGORY_ICON.getCode());
} else {
icon = pictureDao.getPictureById(iconId);
}
if (icon != null)
icon.setPath(constructorManager.constructPictureUrl(icon, DEFAULT_BLOGGER_BLOG_CATEGORY_ICON));
int count = blogDao.countBlogByCategory(bloggerId, category.getId(), BlogStatusEnum.PUBLIC.getCode());
return fillingManager.blogCategoryToDTO(category, icon, count);
}
Aggregations