Browse Source

修改文章

master
yinzuomei 3 years ago
parent
commit
fc1992863d
  1. 92
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/UpdateArticleFormDTO.java
  2. 1
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/ArticleConstant.java
  3. 10
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/controller/ArticleController.java
  4. 8
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/ArticleContentDao.java
  5. 3
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/ArticleCoverDao.java
  6. 2
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/ArticlePublishRangeDao.java
  7. 1
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/ArticleOperateRecordEntity.java
  8. 6
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/ArticleService.java
  9. 119
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java
  10. 10
      epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/ArticleContentDao.xml
  11. 6
      epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/ArticleCoverDao.xml
  12. 8
      epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/ArticlePublishRangeDao.xml

92
epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/UpdateArticleFormDTO.java

@ -0,0 +1,92 @@
package com.epmet.dto.form;
import com.epmet.commons.tools.validator.group.CustomerClientShowGroup;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @Description 修改文章
* @Author yzm
* @Date 2022/10/24 14:12
*/
@Data
public class UpdateArticleFormDTO {
public interface AddUserInternalGroup {
}
public interface AddUserShowGroup extends CustomerClientShowGroup {
}
/**
* 文章id
*/
@NotBlank(message = "articleId不能为空", groups = {AddUserInternalGroup.class})
private String articleId;
@NotBlank(message = "文章标题不能为空", groups = {AddUserShowGroup.class})
@Length(max = 50, message = "文章标题最长为50个字")
private String title;
/**
* 发布范围IDs
*/
@NotEmpty(message = "发布范围不能为空", groups = AddUserShowGroup.class)
private List<String> gridIdList;
/**
* 发布范围Names
*/
@NotBlank(message = "发布范围名称不能为空", groups = AddUserShowGroup.class)
private String publishRangeDesc;
@NotBlank(message = "发布单位不能为空", groups = AddUserShowGroup.class)
private String publisher;
@NotBlank(message = "发布单位名称不能为空", groups = AddUserShowGroup.class)
private String publisherName;
/**
* 发布单位类型 机关:agency部门department网格grid
*/
@NotBlank(message = "发布单位类型不能为空", groups = AddUserShowGroup.class)
private String publisherType;
/**
* 封面图地址
*/
private String imgUrl;
@NotBlank(message = "发布时间不能为空", groups = AddUserShowGroup.class)
private String publishDate;
/**
* 文章标签
*/
private List<String> tagNameList;
@NotBlank(message = "文章内容不能为空", groups = {AddUserShowGroup.class})
private String content;
/**
* 是否置顶 1是0否
*/
@NotNull(message = "请选择是否置顶", groups = AddUserShowGroup.class)
private Integer isTop;
/**
* token中获取
*/
@NotBlank(message = "userId不能为空", groups = AddUserInternalGroup.class)
private String userId;
/**
* token中获取
*/
@NotBlank(message = "customerId不能为空", groups = AddUserInternalGroup.class)
private String customerId;
}

1
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/ArticleConstant.java

@ -20,6 +20,7 @@ public interface ArticleConstant {
*/
String PUBLISHED = "published";
String PUBLISH = "publish";
String UPDATE_ARTICEL="update";
String PUBLISH_CONTENT = "发布文章";
/**
* 发布状态-已下线

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

@ -471,13 +471,19 @@ public class ArticleController {
/**
* 已发布的文章可以编辑
*
* @param tokenDto
* @param formDTO
* @return
*/
@PostMapping("updateArticle")
public Result updateArticleId(@LoginUser TokenDto tokenDto,@RequestBody AddOrSaveDraftFormDTO formDTO){
// todo
public Result updateArticle(@LoginUser TokenDto tokenDto, @RequestBody UpdateArticleFormDTO formDTO) {
formDTO.setUserId(tokenDto.getUserId());
formDTO.setCustomerId(tokenDto.getCustomerId());
ValidatorUtils.validateEntity(formDTO, UpdateArticleFormDTO.AddUserShowGroup.class, UpdateArticleFormDTO.AddUserInternalGroup.class);
articleService.updateArticle(formDTO);
return new Result();
}
}

8
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/ArticleContentDao.java

@ -29,5 +29,11 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface ArticleContentDao extends BaseDao<ArticleContentEntity> {
/**
* 只支持富文本的文章
* 如果是最开始一段文字一个图片那种文章在article_content表会有多条
* @param articleId
* @return
*/
ArticleContentEntity selectByArticleId(String articleId);
}

3
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/ArticleCoverDao.java

@ -29,5 +29,6 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface ArticleCoverDao extends BaseDao<ArticleCoverEntity> {
ArticleCoverEntity selectByArticleId(String articleId);
}

2
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/dao/ArticlePublishRangeDao.java

@ -47,4 +47,6 @@ public interface ArticlePublishRangeDao extends BaseDao<ArticlePublishRangeEntit
* @return
*/
List<ArticlePublishRangeEntity> selectInitData(@Param("customerIdList") List<String> customerIdList);
int deleteByArticleId(@Param("articleId") String articleId,@Param("operUserId")String operUserId);
}

1
epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/entity/ArticleOperateRecordEntity.java

@ -64,6 +64,7 @@ public class ArticleOperateRecordEntity extends BaseEpmetEntity {
/**
* 操作类型 发布文章publish取消文章置顶canceltop设置置顶settom下线文章offline修改文章发布范围updatepublishrange
* 修改文章update
*/
private String opType;

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

@ -257,4 +257,10 @@ public interface ArticleService extends BaseService<ArticleEntity> {
PublishedListResultDTO detailV2(ArticleListFormDTO formDTO);
void topArticle(String articleId, String type,String imgUrl);
/**
* 修改文章
* @param formDTO
*/
void updateArticle(UpdateArticleFormDTO formDTO);
}

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

@ -1435,7 +1435,13 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
e.setArticleId(articleId);
articleTags.add(e);
});
articleTagsService.insertBatch(articleTags);
if(!CollectionUtils.isEmpty(articleTags)){
LambdaQueryWrapper<ArticleTagsEntity> queryWrapper=new LambdaQueryWrapper();
queryWrapper.eq(ArticleTagsEntity::getCustomerId,customerId)
.eq(ArticleTagsEntity::getArticleId,articleId);
articleTagsDao.delete(queryWrapper);
articleTagsService.insertBatch(articleTags);
}
}
/**
@ -1543,7 +1549,7 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
articleContent.setArticleId(article.getId());
articleContent.setContent(formDTO.getContent());
articleContent.setContentType("rich_text");
articleContent.setOrderNum(NumConstant.ZERO);
articleContent.setOrderNum(NumConstant.ONE);
articleContentDao.insert(articleContent);
// 3.操作记录
ArticleOperateRecordEntity articleOperateRecord = new ArticleOperateRecordEntity();
@ -1808,4 +1814,113 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
baseDao.updateById(articleEntity);
}
}
/**
* 修改文章
*
* @param formDTO
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void updateArticle(UpdateArticleFormDTO formDTO) {
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getUserId());
AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(staffInfo.getAgencyId());
if (null == agencyInfo){
throw new EpmetException("未查询到组织信息:"+staffInfo.getAgencyId());
}
// 1.文章
ArticleEntity articleEntity = baseDao.selectById(formDTO.getArticleId());
if (ArticleConstant.OFFLINE.equals(articleEntity.getStatusFlag())) {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "已下线的文章不能编辑", "已下线的文章不能编辑");
}
articleEntity.setPublishWay(ArticleConstant.PUBLISH_WAY_MANUAL);
if (formDTO.getPublisherType().equals(DraftConstant.GRID)){
articleEntity.setGridId(formDTO.getPublisher());
}
articleEntity.setPreviewContent(getPreviewContent(formDTO.getContent()).length() > DraftConstant.PREVIEW_CONTENT_MAX_LENGTH ? getPreviewContent(formDTO.getContent()).substring(NumConstant.ZERO,DraftConstant.PREVIEW_CONTENT_MAX_LENGTH) : getPreviewContent(formDTO.getContent()));
articleEntity.setPublishDate(DateUtils.stringToDate(formDTO.getPublishDate(),DateUtils.DATE_PATTERN));
articleEntity.setPublisherId(formDTO.getPublisher());
articleEntity.setTags(CollectionUtils.isEmpty(formDTO.getTagNameList()) ? "" : formDTO.getTagNameList().stream().collect(Collectors.joining("|")));
articleEntity.setOrgId(staffInfo.getAgencyId());
articleEntity.setOrgIdPath(StringUtils.isBlank(agencyInfo.getPids()) || agencyInfo.getPids().equals(NumConstant.ZERO_STR) ? agencyInfo.getId() : agencyInfo.getPids().concat(":").concat(agencyInfo.getId()));
articleEntity.setRichTextFlag(NumConstant.ONE_STR);
baseDao.updateById(articleEntity);
// 2.内容
ArticleContentEntity articleContent = articleContentDao.selectByArticleId(formDTO.getArticleId());
articleContent.setContent(formDTO.getContent());
articleContentDao.updateById(articleContent);
// 3.操作记录
ArticleOperateRecordEntity articleOperateRecord = new ArticleOperateRecordEntity();
articleOperateRecord.setCustomerId(formDTO.getCustomerId());
articleOperateRecord.setArticleId(formDTO.getArticleId());
articleOperateRecord.setGridIds(CollectionUtils.isEmpty(formDTO.getGridIdList()) ? "" : formDTO.getGridIdList().stream().collect(Collectors.joining(":")));
articleOperateRecord.setOpUser(staffInfo.getAgencyName().concat("-").concat(staffInfo.getRealName()));
articleOperateRecord.setContent(articleOperateRecord.getOpUser() + "发布文章【" +formDTO.getTitle() + "】");
articleOperateRecord.setOpType(ArticleConstant.UPDATE_ARTICEL);
articleOperateRecord.setOpTime(new Date());
articleOperateRecordService.insert(articleOperateRecord);
// 4.发布范围
if (!CollectionUtils.isEmpty(formDTO.getGridIdList())){
List<ArticlePublishRangeEntity> rangeList = new ArrayList<>();
formDTO.getGridIdList().forEach(g -> {
GridInfoCache gridInfoCache = CustomerOrgRedis.getGridInfo(g);
if (null == gridInfoCache){
throw new EpmetException("未查询到网格信息:"+g);
}
ArticlePublishRangeEntity articlePublishRange = ConvertUtils.sourceToTarget(gridInfoCache,ArticlePublishRangeEntity.class);
articlePublishRange.setCustomerId(formDTO.getCustomerId());
articlePublishRange.setArticleId(formDTO.getArticleId());
articlePublishRange.setGridId(g);
articlePublishRange.setAgencyGridName(gridInfoCache.getGridNamePath());
articlePublishRange.setAgencyId(gridInfoCache.getPid());
AgencyInfoCache agencyInfoCache = CustomerOrgRedis.getAgencyInfo(gridInfoCache.getPid());
if (null == agencyInfoCache){
throw new EpmetException("未查询到组织信息:"+gridInfoCache.getPid());
}
articlePublishRange.setPids(agencyInfoCache.getPids());
articlePublishRange.setPublishStatus(ArticleConstant.PUBLISHED);
articlePublishRange.setId(null);
rangeList.add(articlePublishRange);
});
if(org.apache.commons.collections4.CollectionUtils.isNotEmpty(rangeList)){
//先删除,后插入
articlePublishRangeDao.deleteByArticleId(formDTO.getArticleId(),formDTO.getUserId());
articlePublishRangeService.insertBatch(rangeList);
}
}
// 5.文章标签
UpdateCustomerTagCacheDTO updateCustomerTagCacheDTO = updateCustomerTagV2(formDTO.getUserId(), formDTO.getCustomerId(), StringUtils.isBlank(articleEntity.getTags()) ? "" : articleEntity.getTags());
if (null != updateCustomerTagCacheDTO){
addArticleTagsV2(updateCustomerTagCacheDTO,formDTO.getCustomerId(),articleEntity.getId());
}
// 6.更新网格tag
List<UpdateGridTagCacheDTO> updateGridTagCacheDTOS = updateGridTagV2(updateCustomerTagCacheDTO, formDTO.getCustomerId(), formDTO.getGridIdList(), formDTO.getUserId());
// 7.文章封面
if (StringUtils.isNotBlank(formDTO.getImgUrl())){
ArticleCoverEntity articleCoverEntity = articleCoverDao.selectByArticleId(formDTO.getArticleId());
if (null != articleCoverEntity) {
articleCoverEntity.setImgUrl(formDTO.getImgUrl());
articleCoverEntity.setAuditStatus("pass");
articleCoverDao.updateById(articleCoverEntity);
}else{
ArticleCoverEntity articleCover = new ArticleCoverEntity();
articleCover.setCustomerId(formDTO.getCustomerId());
articleCover.setArticleId(formDTO.getArticleId());
articleCover.setImgUrl(formDTO.getImgUrl());
articleCover.setAuditStatus("pass");
articleCoverDao.insert(articleCover);
}
}
// 8.更新redis
try {
this.updateCacheCustomerTag(updateCustomerTagCacheDTO);
this.updateCacheGridTag(updateGridTagCacheDTOS);
} catch (Exception e) {
//我觉着没必要抛出异常吧,日志打印一下吧
log.warn("scanAllPassPublishArticle update redis exception", e);
// throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg());
}
}
}

10
epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/ArticleContentDao.xml

@ -4,4 +4,14 @@
<mapper namespace="com.epmet.dao.ArticleContentDao">
<select id="selectByArticleId" parameterType="java.lang.String" resultType="com.epmet.entity.ArticleContentEntity">
SELECT
ac.*
FROM
article_content ac
WHERE
ac.DEL_FLAG = '0'
AND ac.ID = #{articleId}
</select>
</mapper>

6
epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/ArticleCoverDao.xml

@ -3,5 +3,9 @@
<mapper namespace="com.epmet.dao.ArticleCoverDao">
<select id="selectByArticleId" parameterType="java.lang.String" resultType="com.epmet.entity.ArticleCoverEntity">
select ac.* from article_cover ac
where ac.DEL_FLAG='0'
and ac.ARTICLE_ID=#{articleId}
</select>
</mapper>

8
epmet-module/gov-voice/gov-voice-server/src/main/resources/mapper/ArticlePublishRangeDao.xml

@ -35,5 +35,11 @@
ORDER BY GRID_ID
</select>
<update id="deleteByArticleId" parameterType="java.lang.String">
update article_publish_range r
set r.del_flag='1',
r.UPDATED_BY = #{operUserId},
r.UPDATED_TIME = now()
where r.ARTICLE_ID = #{articleId}
</update>
</mapper>
Loading…
Cancel
Save