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();
}
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();
}
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);
}
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;
}
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;
}
Aggregations