|
|
@ -19,6 +19,7 @@ package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.AppClientConstant; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
@ -1435,7 +1436,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 +1550,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 +1815,190 @@ 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()); |
|
|
|
if (null != articleContent) { |
|
|
|
articleContent.setContent(formDTO.getContent()); |
|
|
|
articleContentDao.updateById(articleContent); |
|
|
|
}else{ |
|
|
|
ArticleContentEntity articleContent1=new ArticleContentEntity(); |
|
|
|
articleContent1.setCustomerId(formDTO.getCustomerId()); |
|
|
|
articleContent1.setArticleId(formDTO.getArticleId()); |
|
|
|
articleContent1.setContent(formDTO.getContent()); |
|
|
|
articleContent1.setContentType("rich_text"); |
|
|
|
articleContent1.setOrderNum(NumConstant.ONE); |
|
|
|
articleContentDao.insert(articleContent1); |
|
|
|
} |
|
|
|
// 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(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"gridId:"+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(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"agencyId:"+gridInfoCache.getPid(),"发布范围:网格所属组织信息查询异常"); |
|
|
|
} |
|
|
|
//组织id的所有上级
|
|
|
|
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("updateArticle update redis exception", e); |
|
|
|
// throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg());
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 删除文章 |
|
|
|
* article 文章表 |
|
|
|
* article_content 文章内容表 |
|
|
|
* article_cover 文章封面表 |
|
|
|
* article_operate_record 文章操作记录表 |
|
|
|
* article_publish_range 文章发布范围表 |
|
|
|
* article_tags 文章标签表 |
|
|
|
* article_visit_record 文章访问记录表 |
|
|
|
* |
|
|
|
* @param articleIds |
|
|
|
* @param customerId |
|
|
|
* @param currentOperUserId |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public void delete(List<String> articleIds, String customerId, String currentOperUserId) { |
|
|
|
Date now=new Date(); |
|
|
|
for(String articleId:articleIds){ |
|
|
|
//文章表
|
|
|
|
LambdaUpdateWrapper<ArticleEntity> updateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
updateWrapper.set(ArticleEntity::getDelFlag, NumConstant.ONE_STR) |
|
|
|
.set(ArticleEntity::getUpdatedBy, currentOperUserId) |
|
|
|
.set(ArticleEntity::getUpdatedTime, now); |
|
|
|
updateWrapper.eq(ArticleEntity::getId, articleId); |
|
|
|
baseDao.update(null, updateWrapper); |
|
|
|
|
|
|
|
//文章内容表
|
|
|
|
LambdaUpdateWrapper<ArticleContentEntity> articleContentUpdate = new LambdaUpdateWrapper<>(); |
|
|
|
articleContentUpdate.set(ArticleContentEntity::getDelFlag, NumConstant.ONE_STR) |
|
|
|
.set(ArticleContentEntity::getUpdatedBy, currentOperUserId) |
|
|
|
.set(ArticleContentEntity::getUpdatedTime, now); |
|
|
|
articleContentUpdate.eq(ArticleContentEntity::getArticleId, articleId); |
|
|
|
articleContentDao.update(null,articleContentUpdate); |
|
|
|
//文章封面表
|
|
|
|
LambdaUpdateWrapper<ArticleCoverEntity> articleCoverUpdate = new LambdaUpdateWrapper<>(); |
|
|
|
articleCoverUpdate.set(ArticleCoverEntity::getDelFlag, NumConstant.ONE_STR) |
|
|
|
.set(ArticleCoverEntity::getUpdatedBy, currentOperUserId) |
|
|
|
.set(ArticleCoverEntity::getUpdatedTime, now); |
|
|
|
articleCoverUpdate.eq(ArticleCoverEntity::getArticleId, articleId); |
|
|
|
articleCoverDao.update(null,articleCoverUpdate); |
|
|
|
//文章操作记录表
|
|
|
|
articleOperateRecordService.deleteByArticleId(articleId,customerId,currentOperUserId); |
|
|
|
|
|
|
|
//文章发布范围表
|
|
|
|
LambdaUpdateWrapper<ArticlePublishRangeEntity> publishRangeUpdate = new LambdaUpdateWrapper<>(); |
|
|
|
publishRangeUpdate.set(ArticlePublishRangeEntity::getDelFlag, NumConstant.ONE_STR) |
|
|
|
.set(ArticlePublishRangeEntity::getUpdatedBy, currentOperUserId) |
|
|
|
.set(ArticlePublishRangeEntity::getUpdatedTime, now); |
|
|
|
publishRangeUpdate.eq(ArticlePublishRangeEntity::getArticleId, articleId); |
|
|
|
articlePublishRangeDao.update(null,publishRangeUpdate); |
|
|
|
//文章标签表
|
|
|
|
LambdaUpdateWrapper<ArticleTagsEntity> articleTagsUpdate = new LambdaUpdateWrapper<>(); |
|
|
|
articleTagsUpdate.set(ArticleTagsEntity::getDelFlag, NumConstant.ONE_STR) |
|
|
|
.set(ArticleTagsEntity::getUpdatedBy, currentOperUserId) |
|
|
|
.set(ArticleTagsEntity::getUpdatedTime, now); |
|
|
|
articleTagsUpdate.eq(ArticleTagsEntity::getArticleId, articleId); |
|
|
|
articleTagsDao.update(null,articleTagsUpdate); |
|
|
|
//文章访问记录表
|
|
|
|
articleVisitRecordService.deleteByArticleId(articleId,customerId,currentOperUserId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|