From 96c95c8f33aec65f1df6afdae544506f6447976e Mon Sep 17 00:00:00 2001 From: jianjun Date: Wed, 3 Jun 2020 16:11:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E9=A2=84=E8=A7=88=E6=97=B6?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E8=8D=89=E7=A8=BF=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/dto/form/DraftAttrFromDTO.java | 5 ++ .../epmet/controller/ArticleController.java | 18 +++++-- .../com/epmet/service/ArticleService.java | 12 ++++- .../service/impl/ArticleServiceImpl.java | 47 +++++++++++++++---- .../java/com/epmet/ArticleServiceTest.java | 2 +- 5 files changed, 70 insertions(+), 14 deletions(-) diff --git a/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/DraftAttrFromDTO.java b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/DraftAttrFromDTO.java index a2640f520c..42d31c7475 100644 --- a/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/DraftAttrFromDTO.java +++ b/epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/DraftAttrFromDTO.java @@ -19,6 +19,8 @@ package com.epmet.dto.form; import lombok.Data; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.List; @@ -37,6 +39,7 @@ public class DraftAttrFromDTO implements Serializable { /** * 草稿ID */ + @NotBlank(message = "草稿ID不能为空") private String draftId; /** @@ -52,6 +55,7 @@ public class DraftAttrFromDTO implements Serializable { /** * 是否置顶 */ + @NotNull(message = "是否置顶不能为空") private Integer isTop; /** @@ -67,6 +71,7 @@ public class DraftAttrFromDTO implements Serializable { /** * 发布日期 */ + @NotBlank(message = "发布时间不能为空") private String publishDate; /** diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java index 98d1a0411c..3a95514f39 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java @@ -35,7 +35,6 @@ import com.epmet.dto.result.*; import com.epmet.dto.result.ArticleGridResultDTO; import com.epmet.dto.result.ArticleOperationResultDTO; import com.epmet.dto.result.GovArticleDetailResultDTO; -import com.epmet.dto.result.LatestListResultDTO; import com.epmet.dto.result.PublishAgencyListResultDTO; import com.epmet.excel.ArticleExcel; import com.epmet.service.ArticleOperateRecordService; @@ -222,8 +221,21 @@ public class ArticleController { * @throws Exception */ @GetMapping("saveattr") - public Result saveOrUpdateAttr(@LoginUser TokenDto tokenDto,@RequestBody DraftAttrFromDTO fromDTO) throws Exception { - Boolean isSuccess = articleService.saveOrUpdateAttr(tokenDto, fromDTO); + public Result saveDraftAttr(@LoginUser TokenDto tokenDto,@RequestBody DraftAttrFromDTO fromDTO) throws Exception { + ValidatorUtils.validateEntity(fromDTO, DefaultGroup.class); + Boolean isSuccess = articleService.saveDraftAttr(tokenDto, fromDTO); + return new Result().ok(isSuccess); + } + + /** + * desc:预览保存草稿属性 + * @param fromDTO + * @throws Exception + */ + @GetMapping("previewsaveattr") + public Result previewSaveDraftAttr(@LoginUser TokenDto tokenDto,@RequestBody DraftAttrFromDTO fromDTO) throws Exception { + ValidatorUtils.validateEntity(fromDTO, DefaultGroup.class); + Boolean isSuccess = articleService.previewSaveDraftAttr(tokenDto, fromDTO); return new Result().ok(isSuccess); } diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java index e4c6ea9451..8494824e7f 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java @@ -144,10 +144,18 @@ public interface ArticleService extends BaseService { void offLineArticle(OffLineArticleFormDTO formDTO); /** - * desc:保存或修改文章属性 + * desc:点击保存草稿时,保存文章属性 * @param tokenDto * @param fromDTO * @return */ - Boolean saveOrUpdateAttr(TokenDto tokenDto, DraftAttrFromDTO fromDTO); + Boolean saveDraftAttr(TokenDto tokenDto, DraftAttrFromDTO fromDTO); + + /** + * desc:预览时修改文章属性 + * @param tokenDto + * @param fromDTO + * @return + */ + Boolean previewSaveDraftAttr(TokenDto tokenDto, DraftAttrFromDTO fromDTO); } \ No newline at end of file diff --git a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java index 0fd775e6e0..37527b02e4 100644 --- a/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java +++ b/epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java @@ -235,10 +235,11 @@ public class ArticleServiceImpl extends BaseServiceImpl publishRangeEntityList) { Map draftIdMap = new HashMap<>(); draftIdMap.put("DRAFT_ID", draftEntity.getId()); draftCoverDao.deleteByMap(draftIdMap); - draftCoverDao.insert(coverEntity); + if (coverEntity != null){ + draftCoverDao.insert(coverEntity); + } draftPublishRangeDao.deleteByMap(draftIdMap); if (CollectionUtils.isEmpty(publishRangeEntityList)){ log.warn("saveOrUpdateAttr publishRangeEntityList is empty"); throw new RenException("参数错误"); } - publishRangeEntityList.forEach(publishRange->draftPublishRangeDao.insert(publishRange)); + if (!CollectionUtils.isEmpty(publishRangeEntityList)){ + publishRangeEntityList.forEach(publishRange->draftPublishRangeDao.insert(publishRange)); + } draftDao.updateById(draftEntity); } private List buildDraftPublishRange(DraftEntity draftEntity, TokenDto tokenDto, DraftAttrFromDTO fromDTO) { + if (CollectionUtils.isEmpty(fromDTO.getGridIdList())){ + return null; + } List publishRangeEntityList = new ArrayList<>(); List agencyGridNameList = new ArrayList<>(); ArticleGridResultDTO articleGridResultDTO = agencyGridList(tokenDto); if (articleGridResultDTO == null) { - log.warn("saveOrUpdateAttr userId:{} have not right access publishRange", tokenDto.getUserId()); + log.warn("saveDraftAttr userId:{} have not right access publishRange", tokenDto.getUserId()); throw new RenException("参数错误"); } buildName(tokenDto,agencyGridNameList,publishRangeEntityList, fromDTO, articleGridResultDTO); @@ -304,6 +332,9 @@ public class ArticleServiceImpl extends BaseServiceImpl