Browse Source

文章预览时保存草稿属性

dev_shibei_match
jianjun 5 years ago
parent
commit
96c95c8f33
  1. 5
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/DraftAttrFromDTO.java
  2. 18
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java
  3. 12
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java
  4. 47
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java
  5. 2
      epmet-module/gov-voice/gov-voice-server/src/test/java/com/epmet/ArticleServiceTest.java

5
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;
/**

18
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<Boolean> saveOrUpdateAttr(@LoginUser TokenDto tokenDto,@RequestBody DraftAttrFromDTO fromDTO) throws Exception {
Boolean isSuccess = articleService.saveOrUpdateAttr(tokenDto, fromDTO);
public Result<Boolean> saveDraftAttr(@LoginUser TokenDto tokenDto,@RequestBody DraftAttrFromDTO fromDTO) throws Exception {
ValidatorUtils.validateEntity(fromDTO, DefaultGroup.class);
Boolean isSuccess = articleService.saveDraftAttr(tokenDto, fromDTO);
return new Result<Boolean>().ok(isSuccess);
}
/**
* desc:预览保存草稿属性
* @param fromDTO
* @throws Exception
*/
@GetMapping("previewsaveattr")
public Result<Boolean> previewSaveDraftAttr(@LoginUser TokenDto tokenDto,@RequestBody DraftAttrFromDTO fromDTO) throws Exception {
ValidatorUtils.validateEntity(fromDTO, DefaultGroup.class);
Boolean isSuccess = articleService.previewSaveDraftAttr(tokenDto, fromDTO);
return new Result<Boolean>().ok(isSuccess);
}

12
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java

@ -144,10 +144,18 @@ public interface ArticleService extends BaseService<ArticleEntity> {
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);
}

47
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<ArticleDao, ArticleEntit
}
@Override
public Boolean saveOrUpdateAttr(TokenDto tokenDto, DraftAttrFromDTO fromDTO) {
public Boolean saveDraftAttr(TokenDto tokenDto, DraftAttrFromDTO fromDTO) {
log.debug("saveDraftAttr param:{}",JSON.toJSONString(fromDTO));
DraftEntity draftEntity = draftDao.selectById(fromDTO.getDraftId());
if (draftEntity == null) {
log.warn("saveOrUpdateAttr draftId is not exist in db");
log.warn("saveDraftAttr draftId is not exist in db");
throw new RenException("参数错误");
}
@ -256,10 +257,11 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
//发布单位
String publisher = fromDTO.getPublisher();
String publisherType = fromDTO.getPublisherType();
//TODO 根据布类型 获取对应的名称
//TODO 根据布类型 获取对应的名称
draftEntity.setPublishDate(DateUtils.stringToDate(fromDTO.getPublishDate(),DateUtils.DATE_PATTERN));
if(StringUtils.isNotBlank(fromDTO.getPublishDate())){
draftEntity.setPublishDate(DateUtils.stringToDate(fromDTO.getPublishDate(),DateUtils.DATE_PATTERN));
}
//封面
DraftCoverEntity coverEntity = buildCoverEntity(tokenDto, fromDTO);
@ -271,29 +273,55 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
return true;
}
@Override
public Boolean previewSaveDraftAttr(TokenDto tokenDto, DraftAttrFromDTO fromDTO) {
//校验参数
if (fromDTO.getIsTop() == 1 && StringUtils.isBlank(fromDTO.getCoverImg())) {
log.warn("saveOrUpdateAttr isTop=1 but coverImg is blank");
throw new RenException("文章封面不能为空");
}
if (CollectionUtils.isEmpty(fromDTO.getGridIdList())) {
log.warn("saveOrUpdateAttr gridIdList is empty");
throw new RenException("发布范围不能为空");
}
if (StringUtils.isBlank(fromDTO.getPublisher())) {
log.warn("saveOrUpdateAttr publisher is blank");
throw new RenException("发布单位不能为空");
}
return saveDraftAttr(tokenDto, fromDTO);
}
@Transactional(rollbackFor = Exception.class)
public void executeSaveDraftAttr(DraftEntity draftEntity, DraftCoverEntity coverEntity, List<DraftPublishRangeEntity> publishRangeEntityList) {
Map<String,Object> 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<DraftPublishRangeEntity> buildDraftPublishRange(DraftEntity draftEntity, TokenDto tokenDto, DraftAttrFromDTO fromDTO) {
if (CollectionUtils.isEmpty(fromDTO.getGridIdList())){
return null;
}
List<DraftPublishRangeEntity> publishRangeEntityList = new ArrayList<>();
List<String> 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<ArticleDao, ArticleEntit
private DraftCoverEntity buildCoverEntity(TokenDto tokenDto, DraftAttrFromDTO fromDTO) {
String coverImg = fromDTO.getCoverImg();
if (StringUtils.isBlank(coverImg)){
return null;
}
DraftCoverEntity coverEntity = new DraftCoverEntity();
coverEntity.setCustomerId(tokenDto.getCustomerId());
coverEntity.setDraftId(fromDTO.getDraftId());

2
epmet-module/gov-voice/gov-voice-server/src/test/java/com/epmet/ArticleServiceTest.java

@ -59,7 +59,7 @@ public class ArticleServiceTest {
draftAttrFromDTO.setPublishDate("2020-06-03");
draftAttrFromDTO.setPublisherType("agency");
Boolean aBoolean = articleService.saveOrUpdateAttr(tokenDto, draftAttrFromDTO);
Boolean aBoolean = articleService.saveDraftAttr(tokenDto, draftAttrFromDTO);
System.out.println(aBoolean);
}
}

Loading…
Cancel
Save