use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.
the class BloggerStatisticsServiceImpl method getBloggerStatistics.
@Override
public ResultBean<BloggerStatisticsDTO> getBloggerStatistics(int bloggerId) {
int blogCount = blogDao.countBlogByBloggerId(bloggerId, BlogStatusEnum.PUBLIC.getCode());
List<Blog> blogs = blogDao.listAllWordCountByBloggerId(bloggerId, BlogStatusEnum.PUBLIC.getCode());
int wordCountSum = blogs.stream().mapToInt(Blog::getWordCount).sum();
int likeCount = blogs.stream().mapToInt(Blog::getId).map(statisticsDao::getLikeCount).sum();
int likeGiveCount = likeDao.countLikeByLikerId(bloggerId);
int categoryCount = categoryDao.countByBloggerId(bloggerId);
int labelCount = labelDao.countByBloggerId(bloggerId);
int collectCount = collectDao.countByCollectorId(bloggerId);
int collectedCount = blogs.stream().mapToInt(Blog::getId).map(statisticsDao::getCollectCount).sum();
int linkCount = linkDao.countLinkByBloggerId(bloggerId);
BloggerStatisticsDTO dto = dataFillingManager.bloggerStatisticToDTO(blogCount, wordCountSum, likeCount, likeGiveCount, categoryCount, labelCount, collectCount, collectedCount, linkCount);
return new ResultBean<>(dto);
}
use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.
the class BlogStatisticsServiceImpl method getBlogStatisticsCount.
@Override
public ResultBean<BlogStatisticsCountDTO> getBlogStatisticsCount(int blogId) {
BlogStatistics statistics = statisticsDao.getStatistics(blogId);
if (statistics == null)
return null;
BlogStatisticsCountDTO dto = dataFillingManager.blogStatisticsCountToDTO(statistics);
return new ResultBean<>(dto);
}
use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.
the class BloggerAccountController method modifyUsername.
/**
* 修改用户名
*/
@RequestMapping(value = "/{bloggerId}/item=name", method = RequestMethod.PUT)
public ResultBean modifyUsername(HttpServletRequest request, @PathVariable Integer bloggerId, @RequestParam(value = "username") String newUserName) {
handleBloggerSignInCheck(request, bloggerId);
handleNameCheck(request, newUserName);
boolean result = accountService.updateAccountUserName(bloggerId, newUserName);
if (!result)
handlerOperateFail(request);
// 更新session信息
HttpSession session = request.getSession();
session.setAttribute(bloggerProperties.getSessionNameOfBloggerName(), newUserName);
return new ResultBean<>("");
}
use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.
the class BloggerBlogController method update.
/**
* 更新博文
*/
@RequestMapping(value = "/{blogId}", method = RequestMethod.PUT)
public ResultBean update(HttpServletRequest request, @PathVariable Integer bloggerId, @PathVariable Integer blogId, @RequestParam(value = "title", required = false) String newTitle, @RequestParam(value = "content", required = false) String newContent, @RequestParam(value = "contentMd", required = false) String newContentMd, @RequestParam(value = "summary", required = false) String newSummary, @RequestParam(value = "cids", required = false) String newCategoryIds, @RequestParam(value = "lids", required = false) String newLabelIds, @RequestParam(value = "kword", required = false) String newKeyWord, @RequestParam(value = "status", required = false) Integer newStatus) {
// 所有参数都为null,则不更新。
if (Stream.of(newTitle, newContent, newSummary, newCategoryIds, newLabelIds, newKeyWord, newStatus).filter(Objects::nonNull).count() <= 0)
throw exceptionManager.getParameterIllegalException(new RequestContext(request));
// 检查修改到的博文状态是否允许
if (newStatus != null && !blogValidateManager.isBlogStatusAllow(newStatus))
throw exceptionManager.getParameterIllegalException(new RequestContext(request));
handleBloggerSignInCheck(request, bloggerId);
handleBlogExistAndCreatorCheck(request, bloggerId, blogId);
// 将 Unicode 解码
newContent = StringUtils.unicodeToString(newContent);
newContentMd = StringUtils.unicodeToString(newContentMd);
handleBlogContentCheck(request, newTitle, newContent, newContentMd, newSummary, newKeyWord);
String sp = websiteProperties.getUrlConditionSplitCharacter();
int[] cids = newCategoryIds == null ? null : StringUtils.intStringDistinctToArray(newCategoryIds, sp);
int[] lids = newLabelIds == null ? null : StringUtils.intStringDistinctToArray(newLabelIds, sp);
// 检查博文类别和标签
handleCategoryAndLabelCheck(request, bloggerId, cids, lids);
String[] kw = newKeyWord == null ? null : StringUtils.stringArrayToArray(newKeyWord, sp);
BlogStatusEnum stat = newStatus == null ? null : BlogStatusEnum.valueOf(newStatus);
// 执行更新
if (!bloggerBlogService.updateBlog(bloggerId, blogId, cids, lids, stat, newTitle, newContent, newContentMd, newSummary, kw))
handlerOperateFail(request);
return new ResultBean<>("");
}
use of com.duan.blogos.restful.ResultBean in project BlogSystem by DuanJiaNing.
the class BloggerGalleryController method get.
/**
* 根据id获取图片
*/
@RequestMapping(value = "/{pictureId}", method = RequestMethod.GET)
public ResultBean<BloggerPicture> get(HttpServletRequest request, @PathVariable("bloggerId") Integer bloggerId, @PathVariable("pictureId") Integer pictureId) {
handleBloggerSignInCheck(request, bloggerId);
RequestContext context = new RequestContext(request);
if (pictureId <= 0)
throw exceptionManager.getParameterIllegalException(context);
BloggerPicture picture = bloggerPictureService.getPicture(pictureId, bloggerId);
if (picture == null)
handlerEmptyResult(request);
String url = stringConstructorManager.constructPictureUrl(picture, DEFAULT_PICTURE);
picture.setPath(url);
return new ResultBean<>(picture);
}
Aggregations