use of com.duan.blogos.entity.blogger.BloggerAccount in project BlogSystem by DuanJiaNing.
the class BloggerAccountServiceImpl method insertAccount.
@Override
public int insertAccount(String userName, String password) {
String shaPwd;
try {
// 将密码通过sha的方式保存
shaPwd = new BigInteger(StringUtils.toSha(password)).toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new UnknownInternalException(e);
}
BloggerAccount account = new BloggerAccount();
account.setUsername(userName);
account.setPassword(shaPwd);
int effect = accountDao.insert(account);
if (effect <= 0)
return -1;
int bloggerId = account.getId();
// 生成博主设置数据
BloggerSetting setting = new BloggerSetting();
setting.setBloggerId(bloggerId);
settingDao.insert(setting);
return bloggerId;
}
use of com.duan.blogos.entity.blogger.BloggerAccount 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);
}
use of com.duan.blogos.entity.blogger.BloggerAccount in project BlogSystem by DuanJiaNing.
the class ImageManager method saveImageToDisk.
/**
* 将图片保存到博主的对应文件夹下
*
* @param file 图片
* @param bloggerId 博主id
* @param category 图片类别
* @return 路径
*/
public String saveImageToDisk(MultipartFile file, int bloggerId, int category) throws IOException {
// 后缀一定要为图片类型
String type = ImageUtils.getImageType(file);
if (type == null)
return null;
BloggerAccount account = accountDao.getAccountById(bloggerId);
String dirPath = constructorManager.constructImageDirPath(account.getUsername(), BloggerPictureCategoryEnum.valueOf(category).name());
File specDir = new File(dirPath);
if (!specDir.exists() || !specDir.isDirectory())
specDir.mkdirs();
// 页面使用 <%@ page pageEncoding="utf-8" %> 指令,否则会出现文件名中文乱码
// 文件名统一添加前缀 "时间-" 以避免覆盖
String name = System.currentTimeMillis() + "-" + handleImageName(file.getOriginalFilename(), type);
File image = new File(specDir.getAbsolutePath() + File.separator + name);
if (!image.exists() || image.isDirectory())
file.transferTo(image);
return image.getAbsolutePath();
}
use of com.duan.blogos.entity.blogger.BloggerAccount in project BlogSystem by DuanJiaNing.
the class BlogReadPageController method page.
@RequestMapping
public ModelAndView page(HttpServletRequest request, @PathVariable String bloggerName, @PathVariable String blogName) {
ModelAndView mv = new ModelAndView();
// 博文作者博主账户
BloggerAccount account = accountService.getAccount(bloggerName);
if (account == null) {
mv.setViewName("error/error");
mv.addObject("code", 6);
mv.addObject(bloggerProperties.getSessionNameOfErrorMsg(), "博主不存在!");
return mv;
}
int blogId = blogService.getBlogId(account.getId(), blogName);
if (blogId == -1) {
mv.setViewName("error/error");
mv.addObject("code", 5);
mv.addObject(bloggerProperties.getSessionNameOfErrorMsg(), "博文不存在!");
return mv;
}
// 博文浏览次数自增1
statisticsService.updateBlogViewCountPlus(blogId);
ResultBean<BlogMainContentDTO> mainContent = blogBrowseService.getBlogMainContent(blogId);
ResultBean<BlogStatisticsCountDTO> statistics = statisticsService.getBlogStatisticsCount(blogId);
mv.addObject("blogOwnerBloggerId", account.getId());
mv.addObject("main", mainContent.getData());
mv.addObject("stat", statistics.getData());
// 登陆博主 id
int loginBloggerId = sessionManager.getLoginBloggerId(request);
ResultBean<BloggerStatisticsDTO> loginBgStat = bloggerStatisticsService.getBloggerStatistics(loginBloggerId);
mv.addObject("loginBgStat", loginBgStat.getData());
if (loginBloggerId != -1) {
if (likeService.getLikeState(loginBloggerId, blogId))
mv.addObject("likeState", true);
if (collectBlogService.getCollectState(loginBloggerId, blogId))
mv.addObject("collectState", true);
}
mv.setViewName("blogger/read_blog");
return mv;
}
use of com.duan.blogos.entity.blogger.BloggerAccount in project BlogSystem by DuanJiaNing.
the class BloggerPageController method mainPage.
@RequestMapping("/archives")
public ModelAndView mainPage(HttpServletRequest request, @PathVariable String bloggerName) {
ModelAndView mv = new ModelAndView();
mv.setViewName("blogger/main");
BloggerAccount account = accountService.getAccount(bloggerName);
if (account == null) {
mv.addObject("code", 6);
mv.addObject(bloggerProperties.getSessionNameOfErrorMsg(), "博主不存在!");
mv.setViewName("error/error");
return mv;
}
mv.addObject(bloggerProperties.getNameOfPageOwnerBloggerId(), account.getId());
mv.addObject(bloggerProperties.getNameOfPageOwnerBloggerName(), account.getUsername());
int ownerId = account.getId();
BloggerProfile profile = bloggerProfileService.getBloggerProfile(ownerId);
mv.addObject("blogName", profile.getIntro());
mv.addObject("aboutMe", profile.getAboutMe());
mv.addObject("avatarId", Optional.ofNullable(profile.getAvatarId()).orElse(bloggerPictureService.getDefaultPicture(BloggerPictureCategoryEnum.DEFAULT_BLOGGER_AVATAR).getId()));
ResultBean<BloggerStatisticsDTO> ownerBgStat = statisticsService.getBloggerStatistics(ownerId);
mv.addObject("ownerBgStat", ownerBgStat.getData());
int loginBgId;
if ((loginBgId = sessionManager.getLoginBloggerId(request)) != -1) {
ResultBean<BloggerStatisticsDTO> loginBgStat = statisticsService.getBloggerStatistics(loginBgId);
mv.addObject("loginBgStat", loginBgStat.getData());
}
BloggerSetting setting = settingService.getSetting(ownerId);
mv.addObject("setting", setting);
return mv;
}
Aggregations