use of com.duan.blogos.entity.blogger.BloggerProfile 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.BloggerProfile 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;
}
use of com.duan.blogos.entity.blogger.BloggerProfile 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.BloggerProfile in project BlogSystem by DuanJiaNing.
the class BloggerProfileServiceImpl method updateBloggerProfile.
@Override
public boolean updateBloggerProfile(int bloggerId, int avatarId, String newPhone, String newEmail, String newAboutMe, String newIntro) {
BloggerProfile profile = profileDao.getProfileByBloggerId(bloggerId);
if (profile == null)
return false;
Integer oldAvatarId = profile.getAvatarId();
profile.setAvatarId(avatarId == -1 ? null : avatarId);
profile.setPhone(newPhone);
profile.setEmail(newEmail);
profile.setAboutMe(newAboutMe);
profile.setIntro(newIntro);
int effect = profileDao.update(profile);
if (effect <= 0)
return false;
if (avatarId > 0)
imageManager.imageUpdateHandle(bloggerId, avatarId, oldAvatarId);
return true;
}
use of com.duan.blogos.entity.blogger.BloggerProfile in project BlogSystem by DuanJiaNing.
the class BloggerProfileServiceImpl method deleteBloggerProfile.
@Override
public boolean deleteBloggerProfile(int bloggerId) {
BloggerProfile profile = profileDao.getProfileByBloggerId(bloggerId);
int effect = profileDao.delete(bloggerId);
if (effect <= 0)
return false;
Integer id;
if ((id = profile.getAvatarId()) != null)
pictureDao.updateUseCountMinus(id);
return true;
}
Aggregations