Search in sources :

Example 6 with BloggerAccount

use of com.duan.blogos.entity.blogger.BloggerAccount in project BlogSystem by DuanJiaNing.

the class ImageManager method moveImage.

/**
 * 移动设备上的图片
 *
 * @param picture   要移动的图片
 * @param bloggerId 移动到的目标博主
 * @param category  目标博主的类别
 * @return 新的图片保存路径
 */
public String moveImage(BloggerPicture picture, int bloggerId, BloggerPictureCategoryEnum category) throws IOException {
    BloggerAccount account = accountDao.getAccountById(bloggerId);
    String dirPath = constructorManager.constructImageDirPath(account.getUsername(), category.name());
    File newDir = new File(dirPath);
    if (!newDir.exists() || !newDir.isDirectory())
        newDir.mkdirs();
    File oldPicture = new File(picture.getPath());
    File newPicture = new File(newDir.getAbsolutePath() + File.separator + oldPicture.getName());
    if (oldPicture.equals(newPicture))
        return oldPicture.getAbsolutePath();
    FileUtils.moveFile(oldPicture, newPicture);
    return newPicture.getAbsolutePath();
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 7 with BloggerAccount

use of com.duan.blogos.entity.blogger.BloggerAccount in project BlogSystem by DuanJiaNing.

the class ImageManager method saveImageToDisk.

/**
 * 将图片保存到博主的对应文件夹下
 */
public String saveImageToDisk(byte[] bs, String name, int bloggerId, int category) throws IOException {
    String type = ImageUtils.getImageMimeType(name);
    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();
    // 文件名统一添加前缀 "时间-" 以避免覆盖
    name = System.currentTimeMillis() + "-" + handleImageName(name, type);
    File image = new File(specDir.getAbsolutePath() + File.separator + name);
    if (!image.exists() || image.isDirectory()) {
        FileOutputStream stream = new FileOutputStream(image);
        stream.write(bs);
        stream.close();
    }
    return image.getAbsolutePath();
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) FileOutputStream(java.io.FileOutputStream) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 8 with BloggerAccount

use of com.duan.blogos.entity.blogger.BloggerAccount in project BlogSystem by DuanJiaNing.

the class BlogBrowseServiceImpl method listBlogComment.

@Override
public ResultBean<List<BlogCommentDTO>> listBlogComment(int blogId, int offset, int rows) {
    List<BlogCommentDTO> result = new ArrayList<>();
    List<BlogComment> comments = commentDao.listCommentByBlogId(blogId, offset, rows, BlogCommentStatusEnum.RIGHTFUL.getCode());
    for (BlogComment comment : comments) {
        // 评论者数据
        int sid = comment.getSpokesmanId();
        BloggerAccount smAccount = accountDao.getAccountById(sid);
        BloggerProfile smProfile = getProfile(sid);
        BloggerDTO smDTO = dataFillingManager.bloggerAccountToDTO(smAccount, smProfile, getAvatar(smProfile.getAvatarId()));
        BlogCommentDTO dto = dataFillingManager.blogCommentToDTO(comment, smDTO);
        result.add(dto);
    }
    return CollectionUtils.isEmpty(result) ? null : new ResultBean<>(result);
}
Also used : BloggerDTO(com.duan.blogos.dto.blogger.BloggerDTO) BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) ArrayList(java.util.ArrayList) BlogComment(com.duan.blogos.entity.blog.BlogComment) BlogCommentDTO(com.duan.blogos.dto.blog.BlogCommentDTO) BloggerProfile(com.duan.blogos.entity.blogger.BloggerProfile)

Example 9 with BloggerAccount

use of com.duan.blogos.entity.blogger.BloggerAccount in project BlogSystem by DuanJiaNing.

the class BloggerAccountServiceImpl method updateAccountUserName.

@Override
public boolean updateAccountUserName(int bloggerId, String newUserName) {
    BloggerAccount account = new BloggerAccount();
    account.setId(bloggerId);
    account.setUsername(newUserName);
    int effect = accountDao.update(account);
    if (effect <= 0)
        return false;
    return true;
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount)

Example 10 with BloggerAccount

use of com.duan.blogos.entity.blogger.BloggerAccount in project BlogSystem by DuanJiaNing.

the class BloggerAccountServiceImpl method updateAccountPassword.

@Override
public boolean updateAccountPassword(int bloggerId, String oldPassword, String newPassword) {
    String oldSha;
    String newSha;
    try {
        oldSha = new BigInteger(StringUtils.toSha(oldPassword)).toString();
        newSha = new BigInteger(StringUtils.toSha(newPassword)).toString();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        throw new UnknownInternalException(e);
    }
    BloggerAccount account = accountDao.getAccountById(bloggerId);
    String oriSha = account.getPassword();
    // 旧密码正确,同时与新密码相同(并没有修改)
    if (!oriSha.equals(oldSha) || oldSha.equals(newSha))
        return false;
    BloggerAccount a = new BloggerAccount();
    a.setId(bloggerId);
    a.setPassword(newSha);
    int effect = accountDao.update(a);
    if (effect <= 0)
        return false;
    return true;
}
Also used : BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) UnknownInternalException(com.duan.blogos.exception.internal.UnknownInternalException) BigInteger(java.math.BigInteger) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

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