Пример #1
0
 /**
  * @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());
 }