Browse Source

保存草稿接口拆开 分别校验

master
jianjun 5 years ago
parent
commit
781db9865f
  1. 5
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/DraftContentFromDTO.java
  2. 15
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java
  3. 11
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java
  4. 40
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java
  5. 3
      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/DraftContentFromDTO.java

@ -34,9 +34,7 @@ import java.util.List;
public class DraftContentFromDTO implements Serializable {
private static final long serialVersionUID = -4206020151361420221L;
private static final long serialVersionUID = -5699594328218833256L;
/**
* 草稿ID
*/
@ -51,6 +49,7 @@ public class DraftContentFromDTO implements Serializable {
/**
* 内容列表
*/
@NotBlank(message = "文章内容不能为空")
private List<DraftContentDTO> contentList;
@Data

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

@ -70,6 +70,18 @@ public class ArticleController {
return new Result<ArticleAgencyGridListResultDTO>().ok(agencyGridList);
}
/**
* desc:政府端-点击返回按钮时点击保存草稿 无需校验参数
* @param fromDTO
* @throws Exception
*/
@PostMapping("savedraft")
@RequirePermission(requirePermission = RequirePermissionEnum.WORK_PARTY_VOICE_PUBLISH)
public Result<DraftContentSaveResultDTO> savedraft(@LoginUser TokenDto tokenDto,@RequestBody DraftContentFromDTO fromDTO) throws Exception {
DraftContentSaveResultDTO draftDTO = articleService.saveDraft(tokenDto, fromDTO);
return new Result<DraftContentSaveResultDTO>().ok(draftDTO);
}
/**
* desc:保存或修改草稿内容
* @param fromDTO
@ -78,8 +90,7 @@ public class ArticleController {
@PostMapping("savecontent")
@RequirePermission(requirePermission = RequirePermissionEnum.WORK_PARTY_VOICE_PUBLISH)
public Result<DraftContentSaveResultDTO> saveOrUpdateContent(@LoginUser TokenDto tokenDto,@RequestBody DraftContentFromDTO fromDTO) throws Exception {
String draftId = articleService.saveOrUpdateContent(tokenDto, fromDTO);
DraftContentSaveResultDTO resultDTO = new DraftContentSaveResultDTO(draftId);
DraftContentSaveResultDTO resultDTO = articleService.saveOrUpdateContent(tokenDto, fromDTO, true);
return new Result<DraftContentSaveResultDTO>().ok(resultDTO);
}

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

@ -48,9 +48,10 @@ public interface ArticleService extends BaseService<ArticleEntity> {
*
* @param tokenDto
* @param fromDTO
* @param required
* @return
*/
String saveOrUpdateContent(TokenDto tokenDto, DraftContentFromDTO fromDTO);
DraftContentSaveResultDTO saveOrUpdateContent(TokenDto tokenDto, DraftContentFromDTO fromDTO, boolean required);
/**
* 政府端已发布已下线文章详情
@ -183,4 +184,12 @@ public interface ArticleService extends BaseService<ArticleEntity> {
* @param syncScanResult
*/
void updateAuditStatusFailById(String draftId, SyncScanResult syncScanResult);
/**
* desc:政府端点击返回时点击保存草稿
* @param tokenDto
* @param fromDTO
* @return
*/
DraftContentSaveResultDTO saveDraft(TokenDto tokenDto, DraftContentFromDTO fromDTO);
}

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

@ -166,9 +166,11 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
@Override
@Transactional(rollbackFor = Exception.class)
public String saveOrUpdateContent(TokenDto tokenDto, DraftContentFromDTO fromDTO) {
public DraftContentSaveResultDTO saveOrUpdateContent(TokenDto tokenDto, DraftContentFromDTO fromDTO, boolean required) {
log.debug("saveOrUpdateContent param:{}", JSON.toJSONString(fromDTO));
ValidatorUtils.validateEntity(fromDTO, AddGroup.class, DefaultGroup.class);
if (required) {
ValidatorUtils.validateEntity(fromDTO, AddGroup.class, DefaultGroup.class);
}
DraftEntity draftEntity = null;
List<DraftContentEntity> draftContentList = null;
@ -178,20 +180,18 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
log.warn("saveOrUpdateContent draftId is not exist in db");
throw new RenException("参数错误");
}
draftEntity.setTitle(draftEntity.getTitle());
draftEntity.setPreviewContent("");
draftEntity.setTitle(StringUtils.isBlank(draftEntity.getTitle()) ? "" : draftEntity.getTitle());
buildPreviewContent(fromDTO, draftEntity);
draftDao.updateById(draftEntity);
} else {
LoginUserDetailsFormDTO detailsFormDTO = new LoginUserDetailsFormDTO();
detailsFormDTO.setUserId(loginUserUtil.getLoginUserId());
detailsFormDTO.setApp(loginUserUtil.getLoginUserApp());
detailsFormDTO.setClient(loginUserUtil.getLoginUserClient());
Result<LoginUserDetailsResultDTO> loginUserDetails = epmetUserOpenFeignClient.getLoginUserDetails(detailsFormDTO);
if (loginUserDetails == null || loginUserDetails.getData() == null){
if (loginUserDetails == null || loginUserDetails.getData() == null) {
log.warn("saveOrUpdateContent getloginUserDetails return null");
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(),EpmetErrorCode.SERVER_ERROR.getMsg());
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg());
}
draftEntity = new DraftEntity();
draftEntity.setTitle(fromDTO.getTitle());
@ -203,7 +203,6 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
draftEntity.setGridId("");
draftEntity.setDepartmentId(loginUserDetails.getData().getCustomerId());
draftEntity.setDelFlag(NumConstant.ZERO_STR);
draftEntity.setPreviewContent("");
buildPreviewContent(fromDTO, draftEntity);
draftDao.insert(draftEntity);
}
@ -211,19 +210,21 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
String draftId = draftEntity.getId();
fromDTO.setDraftId(draftId);
draftContentList = buildDraftContent(tokenDto, fromDTO);
if (CollectionUtils.isEmpty(draftContentList)) {
log.warn("saveOrUpdateContent contentList is empty");
throw new RenException("参数错误");
}
Map<String, Object> draftIdMap = new HashMap<>();
draftIdMap.put(ModuleConstant.FIELD_DRAFT_ID, fromDTO.getDraftId());
draftContentDao.deleteByMap(draftIdMap);
draftContentService.insertBatch(draftContentList);
return draftId;
if (!CollectionUtils.isEmpty(draftContentList)) {
draftContentService.insertBatch(draftContentList);
}
return new DraftContentSaveResultDTO(draftId);
}
private void buildPreviewContent(DraftContentFromDTO fromDTO, DraftEntity draftEntity) {
if (CollectionUtils.isEmpty(fromDTO.getContentList())){
draftEntity.setPreviewContent("");
return;
}
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();
@ -444,9 +445,12 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
* @return
*/
private List<DraftContentEntity> buildDraftContent(TokenDto tokenDto, DraftContentFromDTO fromDTO) {
List<DraftContentFromDTO.DraftContentDTO> contentList = fromDTO.getContentList();
if (CollectionUtils.isEmpty(contentList)) {
return null;
}
List<DraftContentEntity> newContentList = new ArrayList<>();
List<DraftContentFromDTO.DraftContentDTO> contentList = fromDTO.getContentList();
for (int i = 0; i < contentList.size(); i++) {
DraftContentFromDTO.DraftContentDTO content = contentList.get(i);
@ -460,6 +464,7 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
newContentList.add(entity);
}
return newContentList;
}
@ -999,6 +1004,11 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
});
}
@Override
public DraftContentSaveResultDTO saveDraft(TokenDto tokenDto, DraftContentFromDTO fromDTO) {
return this.saveOrUpdateContent(tokenDto, fromDTO, false);
}
public Result sendMsg(String title,String content) {
UserMessageFormDTO formDTO = new UserMessageFormDTO();
formDTO.setCustomerId(loginUserUtil.getLoginUserApp());

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

@ -3,6 +3,7 @@ import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.constant.DraftConstant;
import com.epmet.dto.form.DraftAttrFromDTO;
import com.epmet.dto.form.DraftContentFromDTO;
import com.epmet.dto.result.DraftContentSaveResultDTO;
import com.epmet.service.ArticleService;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -41,7 +42,7 @@ public class ArticleServiceTest {
list.add(contentDTO);
}
draftContentFromDTO.setContentList(list);
String s = articleService.saveOrUpdateContent(tokenDto, draftContentFromDTO);
DraftContentSaveResultDTO s = articleService.saveOrUpdateContent(tokenDto, draftContentFromDTO, false);
System.out.println(s);
}

Loading…
Cancel
Save