/**
  * @param folderId
  * @param adminId
  * @param title
  * @param summary
  * @param status
  * @param content
  * @param file
  * @param createTime
  * @return
  * @throws FolderNotFoundException
  * @throws UploadException
  * @throws IOException
  */
 @CacheEvict(value = "article", allEntries = true)
 public Article addArticle(
     long folderId,
     long adminId,
     String title,
     String summary,
     ArticleConstant.Status status,
     String content,
     MultipartFile file,
     String createTime)
     throws FolderNotFoundException, UploadException, IOException {
   FolderVo folder = folderService.getFolderById(folderId);
   Article article = new Article();
   Date now = new Date();
   String picture = "";
   if (file != null && !file.isEmpty()) {
     picture = MediaUtils.saveImage(file, folder.getWidth(), folder.getHeight());
   }
   if (folder.getCheck().equals(FolderConstant.check.yes)) {
     article.setCheck(ArticleConstant.check.init);
   } else {
     article.setCheck(ArticleConstant.check.yes);
   }
   article.setFolderId(folder.getFolderId());
   article.setPath(folder.getPath());
   article.setAdminId(adminId);
   article.setTitle(title);
   article.setSummary(summary);
   article.setContent(content);
   article.setViewCount(0);
   article.setCommentCount(0);
   article.setPicture(picture);
   article.setStatus(status);
   if (StringUtils.isBlank(createTime)) {
     article.setCreateTime(now);
   } else {
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
     Date date;
     try {
       date = sdf.parse(createTime);
     } catch (ParseException e) {
       date = now;
     }
     article.setCreateTime(date);
   }
   article.setUpdateTime(now);
   articleDao.addArticle(article);
   return articleDao.getArticleById(article.getArticleId());
 }
 /**
  * 得到目录的显示的文件分页
  *
  * @param folderId
  * @return pageVo
  * @throws FolderNotFoundException
  */
 @Cacheable(value = "article")
 public PageVo<ArticleVo> getArticlePageByFolderId(long folderId, int pageNum, int rows)
     throws FolderNotFoundException {
   PageVo<ArticleVo> pageVo = new PageVo<ArticleVo>(pageNum);
   FolderVo folder = folderService.getFolderById(folderId);
   pageVo.setRows(rows);
   pageVo.setCount(articleDao.getArticleCountOfDisplayByPath(folder.getPath()));
   List<ArticleVo> articlelist =
       articleDao.getArticleListOfDisplayByPath(
           folder.getPath(), pageVo.getOffset(), pageVo.getRows());
   for (ArticleVo artcle : articlelist) {
     FolderVo artcleFolder = folderService.getFolderById(artcle.getFolderId());
     artcle.setFolder(artcleFolder);
   }
   pageVo.setList(articlelist);
   return pageVo;
 }
 /**
  * @param adminId
  * @param folderId
  * @return
  * @throws FolderNotFoundException
  */
 public int getArticleCountByAdminIdAndFolderId(
     long adminId, long folderId, ArticleConstant.check check) throws FolderNotFoundException {
   String path = "";
   if (folderId != 0) {
     Folder folder = folderService.getFolderById(folderId);
     path = folder.getPath();
   }
   return articleDao.getArticleCountByAdminIdAndPath(adminId, path, check);
 }
 /**
  * 得到文件
  *
  * @param articleId
  * @return
  * @throws ArticleNotFoundException
  */
 @Cacheable(value = "article", key = "'getArticleById_'+#articleId")
 public ArticleVo getArticleById(long articleId) throws ArticleNotFoundException {
   ArticleVo articleVo = articleDao.getArticleById(articleId);
   if (articleVo == null) {
     throw new ArticleNotFoundException(articleId + " 文件,不存在");
   } else {
     return articleVo;
   }
 }
 /**
  * @param adminId
  * @param folderId
  * @param offset
  * @param rows
  * @return
  * @throws FolderNotFoundException
  */
 public List<ArticleVo> getArticleListByAdminIdAndFolderId(
     long adminId, long folderId, ArticleConstant.check check, long offset, long rows)
     throws FolderNotFoundException {
   String path = "";
   if (folderId != 0) {
     Folder folder = folderService.getFolderById(folderId);
     path = folder.getPath();
   }
   List<ArticleVo> articleList =
       articleDao.getArticleListByAdminIdAndPath(adminId, path, check, offset, rows);
   return articleList;
 }
 /**
  * @param path
  * @param offset
  * @param rows
  * @return
  */
 public List<ArticleVo> getArticleListOfDisplayByPath(String path, int offset, int rows) {
   List<ArticleVo> articlelist = articleDao.getArticleListOfDisplayByPath(path, offset, rows);
   return articlelist;
 }
 @CacheEvict(value = "article", allEntries = true)
 public void updateCheck(long articleId, ArticleConstant.check check) {
   articleDao.updateCheck(articleId, check);
 }
 /**
  * @param folderId
  * @return
  * @throws FolderNotFoundException
  */
 public int getArticleCountByFolderId(long folderId) throws FolderNotFoundException {
   return articleDao.getArticleCountByFolderId(folderId);
 }
 /**
  * 更新浏览人数
  *
  * @param articleId
  * @param nowViewCount
  */
 public void updateViewCount(long articleId, int nowViewCount) {
   articleDao.updateViewCount(articleId, nowViewCount + 1);
 }
Example #10
0
 /**
  * 删除文件
  *
  * @param articleId
  * @return
  */
 @CacheEvict(value = "article", allEntries = true)
 public boolean deleteArticleById(long articleId) {
   return articleDao.deleteArticleById(articleId);
 }