Search in sources :

Example 11 with BloggerAccount

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;
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) UnknownInternalException(com.duan.blogos.exception.internal.UnknownInternalException) BloggerSetting(com.duan.blogos.entity.blogger.BloggerSetting) BigInteger(java.math.BigInteger) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 12 with BloggerAccount

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlogListItemComparatorFactory(com.duan.blogos.manager.comparator.BlogListItemComparatorFactory) BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) BloggerProfile(com.duan.blogos.entity.blogger.BloggerProfile) FavouriteBlogListItemDTO(com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO) BloggerDTO(com.duan.blogos.dto.blogger.BloggerDTO) FavouriteBlogListItemDTO(com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO) BlogListItemDTO(com.duan.blogos.dto.blog.BlogListItemDTO) ResultBean(com.duan.blogos.restful.ResultBean)

Example 13 with BloggerAccount

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();
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 14 with BloggerAccount

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;
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) BlogStatisticsCountDTO(com.duan.blogos.dto.blog.BlogStatisticsCountDTO) ModelAndView(org.springframework.web.servlet.ModelAndView) BloggerStatisticsDTO(com.duan.blogos.dto.blogger.BloggerStatisticsDTO) BlogMainContentDTO(com.duan.blogos.dto.blog.BlogMainContentDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with BloggerAccount

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;
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) BloggerSetting(com.duan.blogos.entity.blogger.BloggerSetting) ModelAndView(org.springframework.web.servlet.ModelAndView) BloggerStatisticsDTO(com.duan.blogos.dto.blogger.BloggerStatisticsDTO) BloggerProfile(com.duan.blogos.entity.blogger.BloggerProfile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

BloggerAccount (com.duan.blogos.entity.blogger.BloggerAccount)18 BloggerProfile (com.duan.blogos.entity.blogger.BloggerProfile)6 ResultBean (com.duan.blogos.restful.ResultBean)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 BloggerDTO (com.duan.blogos.dto.blogger.BloggerDTO)4 BloggerPicture (com.duan.blogos.entity.blogger.BloggerPicture)4 BloggerStatisticsDTO (com.duan.blogos.dto.blogger.BloggerStatisticsDTO)3 BloggerSetting (com.duan.blogos.entity.blogger.BloggerSetting)3 File (java.io.File)3 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 MultipartFile (org.springframework.web.multipart.MultipartFile)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 BlogListItemDTO (com.duan.blogos.dto.blog.BlogListItemDTO)2 FavouriteBlogListItemDTO (com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO)2 UnknownInternalException (com.duan.blogos.exception.internal.UnknownInternalException)2 BlogListItemComparatorFactory (com.duan.blogos.manager.comparator.BlogListItemComparatorFactory)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 HashMap (java.util.HashMap)2 HttpSession (javax.servlet.http.HttpSession)2