Browse Source

添加文章内容空值;保存内容时返回对象

master
jianjun 5 years ago
parent
commit
f0c722f203
  1. 23
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/DraftContentSaveResultDTO.java
  2. 5
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/DraftConstant.java
  3. 5
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java
  4. 43
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java
  5. 5
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/ModuleConstant.java

23
epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/result/DraftContentSaveResultDTO.java

@ -0,0 +1,23 @@
package com.epmet.dto.result;
import lombok.Data;
import java.io.Serializable;
/**
* 政府端保存文章内容 返回结果
*/
@Data
public class DraftContentSaveResultDTO implements Serializable {
public DraftContentSaveResultDTO() {
super();
}
public DraftContentSaveResultDTO(String draftId) {
this.draftId = draftId;
}
/**
*草稿Id
*/
private String draftId;
}

5
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/DraftConstant.java

@ -61,4 +61,9 @@ public interface DraftConstant {
* 内容类型-文字
*/
String TEXT = "text";
/**
* 草稿预览内容大小长度
*/
Integer PREVIEW_CONTENT_MAX_LENGTH = 50;
}

5
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java

@ -75,9 +75,10 @@ public class ArticleController {
*/
@PostMapping("savecontent")
@RequirePermission(requirePermission = RequirePermissionEnum.WORK_PARTY_VOICE_PUBLISH)
public Result<String> saveOrUpdateContent(@LoginUser TokenDto tokenDto,@RequestBody DraftContentFromDTO fromDTO) throws Exception {
public Result<DraftContentSaveResultDTO> saveOrUpdateContent(@LoginUser TokenDto tokenDto,@RequestBody DraftContentFromDTO fromDTO) throws Exception {
String draftId = articleService.saveOrUpdateContent(tokenDto, fromDTO);
return new Result<String>().ok(draftId);
DraftContentSaveResultDTO resultDTO = new DraftContentSaveResultDTO(draftId);
return new Result<DraftContentSaveResultDTO>().ok(resultDTO);
}
/**

43
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java

@ -179,16 +179,8 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
throw new RenException("参数错误");
}
draftEntity.setTitle(draftEntity.getTitle());
for (int i = 0; i < fromDTO.getContentList().size(); i++) {
if(DraftConstant.TEXT.equals(fromDTO.getContentList().get(i).getContentType())) {
String content = fromDTO.getContentList().get(i).getContent();
if(content.length() > 50) {
content = content.substring(0, 50);
}
draftEntity.setPreviewContent(content);
break;
}
}
draftEntity.setPreviewContent("");
buildPreviewContent(fromDTO, draftEntity);
draftDao.updateById(draftEntity);
} else {
@ -211,16 +203,8 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
draftEntity.setGridId("");
draftEntity.setDepartmentId(loginUserDetails.getData().getCustomerId());
draftEntity.setDelFlag(NumConstant.ZERO_STR);
for (int i = 0; i < fromDTO.getContentList().size(); i++) {
if(DraftConstant.TEXT.equals(fromDTO.getContentList().get(i).getContentType())) {
String content = fromDTO.getContentList().get(i).getContent();
if(content.length() > 50) {
content = content.substring(0, 50);
}
draftEntity.setPreviewContent(content);
break;
}
}
draftEntity.setPreviewContent("");
buildPreviewContent(fromDTO, draftEntity);
draftDao.insert(draftEntity);
}
@ -233,12 +217,25 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
}
Map<String, Object> draftIdMap = new HashMap<>();
draftIdMap.put("DRAFT_ID", fromDTO.getDraftId());
draftIdMap.put(ModuleConstant.FIELD_DRAFT_ID, fromDTO.getDraftId());
draftContentDao.deleteByMap(draftIdMap);
draftContentService.insertBatch(draftContentList);
return draftId;
}
private void buildPreviewContent(DraftContentFromDTO fromDTO, DraftEntity draftEntity) {
for (int i = 0; i < fromDTO.getContentList().size(); i++) {
if (DraftConstant.TEXT.equals(fromDTO.getContentList().get(i).getContentType())) {
String content = fromDTO.getContentList().get(i).getContent();
if (content.length() > DraftConstant.PREVIEW_CONTENT_MAX_LENGTH) {
content = content.substring(NumConstant.ZERO, DraftConstant.PREVIEW_CONTENT_MAX_LENGTH);
}
draftEntity.setPreviewContent(content);
break;
}
}
}
@Override
public GovArticleDetailResultDTO queryGovArticleDetail(String articleId) {
GovArticleDetailResultDTO articleDetail = baseDao.queryGovArticleDetail(articleId);
@ -323,7 +320,7 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
@Override
public Boolean previewSaveDraftAttr(TokenDto tokenDto, DraftAttrFromDTO fromDTO) {
//校验参数
if (fromDTO.getIsTop() == 1 && StringUtils.isBlank(fromDTO.getCoverImg())) {
if (DraftConstant.TOP.equals(fromDTO.getIsTop()) && StringUtils.isBlank(fromDTO.getCoverImg())) {
log.warn("saveOrUpdateAttr isTop=1 but coverImg is blank");
throw new RenException("文章封面不能为空");
}
@ -354,7 +351,7 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
@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());
draftIdMap.put(ModuleConstant.FIELD_DRAFT_ID, draftEntity.getId());
draftCoverDao.deleteByMap(draftIdMap);
if (coverEntity != null){
draftCoverDao.insert(coverEntity);

5
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/utils/ModuleConstant.java

@ -39,6 +39,11 @@ public interface ModuleConstant {
* */
String FIELD_ARTICLE_ID = "ARTICLE_ID";
/**
* 数据库列名 - 草稿ID
* */
String FIELD_DRAFT_ID = "DRAFT_ID";
/**
* 实体属性名 - 文章ID
* */

Loading…
Cancel
Save