@ -18,15 +18,22 @@
package com.epmet.service.impl ;
import com.alibaba.fastjson.JSON ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl ;
import com.epmet.commons.tools.constant.AppClientConstant ;
import com.epmet.commons.tools.constant.FieldConstant ;
import com.epmet.commons.tools.constant.NumConstant ;
import com.epmet.commons.tools.constant.StrConstant ;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult ;
import com.epmet.commons.tools.exception.EpmetErrorCode ;
import com.epmet.commons.tools.exception.EpmetException ;
import com.epmet.commons.tools.exception.RenException ;
import com.epmet.commons.tools.page.PageData ;
import com.epmet.commons.tools.redis.RedisKeys ;
import com.epmet.commons.tools.redis.common.CustomerOrgRedis ;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis ;
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache ;
import com.epmet.commons.tools.redis.common.bean.GridInfoCache ;
import com.epmet.commons.tools.scan.param.ImgScanParamDTO ;
import com.epmet.commons.tools.scan.param.ImgTaskDTO ;
import com.epmet.commons.tools.scan.param.TextScanParamDTO ;
@ -41,10 +48,7 @@ import com.epmet.commons.tools.utils.ScanContentUtils;
import com.epmet.commons.tools.validator.ValidatorUtils ;
import com.epmet.constant.* ;
import com.epmet.dao.* ;
import com.epmet.dto.ArticleVisitRecordDTO ;
import com.epmet.dto.CustomerStaffDTO ;
import com.epmet.dto.DraftCoverDTO ;
import com.epmet.dto.DraftDTO ;
import com.epmet.dto.* ;
import com.epmet.dto.form.* ;
import com.epmet.dto.result.* ;
import com.epmet.entity.* ;
@ -70,6 +74,8 @@ import org.springframework.util.CollectionUtils;
import java.util.* ;
import java.util.concurrent.atomic.AtomicBoolean ;
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
import java.util.stream.Collectors ;
/ * *
@ -122,6 +128,10 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
private ArticleTagsDao articleTagsDao ;
@Autowired
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient ;
@Autowired
private ArticleTagsService articleTagsService ;
@Autowired
private DraftPublishRangeService draftPublishRangeService ;
@Value ( "${openapi.scan.server.url}" )
private String scanApiUrl ;
@ -489,9 +499,11 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
if ( null = = articleEntity ) {
throw new RenException ( ArticleConstant . SELECT_ARTICLE_EXCEPTION ) ;
}
/ *
//2022.7.4 pc端下线文章不再限制自己下自己的
if ( ! formDTO . getStaffId ( ) . equals ( articleEntity . getCreatedBy ( ) ) ) {
throw new RenException ( ArticleConstant . SHIRO_EXCEPTION ) ;
}
} * /
//1:根据文章Id查询全部(已发布、已下线)发布范围数据
ArticlePublishRangeEntity rangeEntity = new ArticlePublishRangeEntity ( ) ;
@ -724,12 +736,17 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
return new ArticleGridResultDTO ( ) ;
}
//2:查询当前工作人员的所属组织,以此作为根节点的起始位置
LoginUserDetailsFormDTO loginUserDetailsFormDTO = new LoginUserDetailsFormDTO ( ) ;
/ * LoginUserDetailsFormDTO loginUserDetailsFormDTO = new LoginUserDetailsFormDTO ( ) ;
loginUserDetailsFormDTO . setApp ( "gov" ) ;
loginUserDetailsFormDTO . setClient ( "wxmp" ) ;
loginUserDetailsFormDTO . setUserId ( formDTO . getStaffId ( ) ) ;
Result < LoginUserDetailsResultDTO > resultDTOResult = epmetUserOpenFeignClient . getLoginUserDetails ( loginUserDetailsFormDTO ) ;
String agencyId = resultDTOResult . getData ( ) . getOrgIdPath ( ) . substring ( resultDTOResult . getData ( ) . getOrgIdPath ( ) . lastIndexOf ( ":" ) + NumConstant . ONE ) ;
String agencyId = resultDTOResult . getData ( ) . getOrgIdPath ( ) . substring ( resultDTOResult . getData ( ) . getOrgIdPath ( ) . lastIndexOf ( ":" ) + NumConstant . ONE ) ; * /
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis . getStaffInfo ( formDTO . getCustomerId ( ) , formDTO . getStaffId ( ) ) ;
if ( null = = staffInfo ) {
throw new EpmetException ( "获取工作人员信息失败" ) ;
}
String agencyId = staffInfo . getAgencyId ( ) ;
//存放树的每一个节点对象,用于将同一节点下的网格列表合并(主键:agencyId 值:节点对象)
Map < String , ArticleGridResultDTO > map = new HashMap < > ( ) ;
//3:循环可下线网格列表,根据pids组织每一个树节点对象信息
@ -1258,9 +1275,18 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
public UpdateCustomerTagCacheDTO updateCustomerTag ( TokenDto tokenDto , String draftId ) {
//获取草稿基本信息
DraftDTO draft = draftService . get ( draftId ) ;
String tags = draft . getTags ( ) ;
String customerId = draft . getCustomerId ( ) ;
String userId = tokenDto . getUserId ( ) ;
return updateCustomerTagV2 ( tokenDto . getUserId ( ) , draft . getCustomerId ( ) , draft . getTags ( ) ) ;
}
/ * *
* Desc :
* @param userId
* @param customerId
* @param tags eg : aa | bb | cc
* @author zxc
* @date 2022 / 6 / 30 16 : 14
* /
public UpdateCustomerTagCacheDTO updateCustomerTagV2 ( String userId , String customerId , String tags ) {
UpdateCustomerTagCacheDTO result = null ;
if ( StringUtils . isNotBlank ( tags ) ) {
result = new UpdateCustomerTagCacheDTO ( ) ;
@ -1274,8 +1300,6 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
result . setCustomerId ( customerId ) ;
result . setTagsInfo ( tagsInfo ) ;
}
return result ;
}
@ -1285,6 +1309,9 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
* @author zxc
* /
public void updateCacheCustomerTag ( UpdateCustomerTagCacheDTO formDto ) {
if ( null = = formDto ) {
return ;
}
List < UpdateTagUseCountsResultDTO > tagsInfo = formDto . getTagsInfo ( ) ;
String customerId = formDto . getCustomerId ( ) ;
//更新缓存标签使用数量
@ -1314,13 +1341,20 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
//获取草稿基本信息
DraftDTO draft = draftService . get ( draftId ) ;
String customerId = draft . getCustomerId ( ) ;
List < UpdateTagUseCountsResultDTO > tagsInfo = formDto . getTagsInfo ( ) ;
String userId = tokenDto . getUserId ( ) ;
//根据草稿id查询发布范围id集合
List < String > gridIds = draftPublishRangeDao . selectGridIdByDraftId ( draftId ) ;
if ( gridIds . size ( ) = = NumConstant . ZERO ) {
throw new RenException ( TagConstant . SELECT_GRIDIDLIST_FAILURE ) ;
}
return updateGridTagV2 ( formDto , customerId , gridIds , userId ) ;
}
public List < UpdateGridTagCacheDTO > updateGridTagV2 ( UpdateCustomerTagCacheDTO formDto , String customerId , List < String > gridIds , String userId ) {
if ( null = = formDto | | CollectionUtils . isEmpty ( formDto . getTagsInfo ( ) ) | | CollectionUtils . isEmpty ( gridIds ) ) {
return new ArrayList < > ( ) ;
}
List < UpdateTagUseCountsResultDTO > tagsInfo = formDto . getTagsInfo ( ) ;
List < UpdateGridTagsFormDTO > gridTags = new ArrayList < > ( ) ;
List < UpdateGridTagCacheDTO > gridTagCache = new ArrayList < > ( ) ;
gridIds . forEach ( gridId - > {
@ -1348,6 +1382,9 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
* @author zxc
* /
public void updateCacheGridTag ( List < UpdateGridTagCacheDTO > gridTagCache ) {
if ( CollectionUtils . isEmpty ( gridTagCache ) ) {
return ;
}
//更新 网格下 标签使用数量
List < UpdateTagUseCountsResultDTO > gridTagCacheCopy = new ArrayList < > ( ) ;
gridTagCache . forEach ( cacheDTO - > {
@ -1376,23 +1413,26 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
* @author zxc
* /
public void addArticleTags ( UpdateCustomerTagCacheDTO formDto , String draftId , TokenDto tokenDto , Date createdTime ) {
List < AddArticleTagsFormDTO > addArticleTags = new ArrayList < > ( ) ;
List < UpdateTagUseCountsResultDTO > tagsInfo = formDto . getTagsInfo ( ) ;
DraftDTO draft = draftService . get ( draftId ) ;
String customerId = draft . getCustomerId ( ) ;
String userId = tokenDto . getUserId ( ) ;
String articleId = articleDao . getArticleIdByDraftId ( draftId ) ;
addArticleTagsV2 ( formDto , customerId , articleId ) ;
}
public void addArticleTagsV2 ( UpdateCustomerTagCacheDTO formDto , String customerId , String articleId ) {
List < ArticleTagsEntity > articleTags = new ArrayList < > ( ) ;
if ( null = = formDto | | CollectionUtils . isEmpty ( formDto . getTagsInfo ( ) ) ) {
return ;
}
List < UpdateTagUseCountsResultDTO > tagsInfo = formDto . getTagsInfo ( ) ;
tagsInfo . forEach ( resultDTO - > {
AddArticleTagsFormDTO addArticleTag = new AddArticleTagsFormDTO ( ) ;
addArticleTag . setCreatedBy ( userId ) ;
addArticleTag . setUpdatedBy ( userId ) ;
addArticleTag . setCustomerId ( customerId ) ;
addArticleTag . setArticleId ( articleId ) ;
BeanUtils . copyProperties ( resultDTO , addArticleTag ) ;
addArticleTag . setCreatedTime ( createdTime ) ;
addArticleTags . add ( addArticleTag ) ;
ArticleTagsEntity e = ConvertUtils . sourceToTarget ( resultDTO , ArticleTagsEntity . class ) ;
e . setCustomerId ( customerId ) ;
e . setArticleId ( articleId ) ;
articleTags . add ( e ) ;
} ) ;
articleTagsDao . addArticleTags ( addA rticleTags ) ;
articleTagsService . insertBatch ( articleTags ) ;
}
/ * *
@ -1449,4 +1489,290 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
public List < ArticleListResultDTO > getArticleListByTag ( String tagId , Integer pageNo , Integer pageSize ) {
return baseDao . selectArticleListByTag ( tagId , pageNo , pageSize ) ;
}
/ * *
* Desc : 发布文章 / 存草稿
* @param formDTO
* @author zxc
* @date 2022 / 6 / 30 14 : 03
* /
@Override
@Transactional ( rollbackFor = Exception . class )
public void addOrSaveDraft ( AddOrSaveDraftFormDTO formDTO ) {
if ( StringUtils . isNotBlank ( formDTO . getDraftId ( ) ) ) {
// 删除草稿,草稿内容,草稿发布范围,封面图
draftDao . deleteDraft ( formDTO . getDraftId ( ) ) ;
draftContentDao . deleteByDraftId ( formDTO . getDraftId ( ) ) ;
draftPublishRangeDao . deleteByDraftId ( formDTO . getDraftId ( ) ) ;
draftCoverDao . deleteByDraftId ( formDTO . getDraftId ( ) ) ;
}
String customerId = formDTO . getCustomerId ( ) ;
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis . getStaffInfo ( customerId , formDTO . getUserId ( ) ) ;
if ( null = = staffInfo ) {
throw new EpmetException ( "未查询到当前工作人员信息:" + formDTO . getUserId ( ) ) ;
}
AgencyInfoCache agencyInfo = CustomerOrgRedis . getAgencyInfo ( staffInfo . getAgencyId ( ) ) ;
if ( null = = agencyInfo ) {
throw new EpmetException ( "未查询到组织信息:" + staffInfo . getAgencyId ( ) ) ;
}
// 发文章
if ( formDTO . getType ( ) . equals ( ArticleConstant . SAVE_TYPE_ARTICLE ) ) {
// 1.文章
ArticleEntity article = ConvertUtils . sourceToTarget ( formDTO , ArticleEntity . class ) ;
// 按照之前逻辑存成客户ID
article . setDepartmentId ( customerId ) ;
article . setStatusFlag ( DraftConstant . PUBLISHED ) ;
article . setPublishWay ( ArticleConstant . PUBLISH_WAY_MANUAL ) ;
if ( formDTO . getPublisherType ( ) . equals ( DraftConstant . GRID ) ) {
article . setGridId ( formDTO . getPublisher ( ) ) ;
}
article . setPreviewContent ( getPreviewContent ( formDTO . getContent ( ) ) . length ( ) > DraftConstant . PREVIEW_CONTENT_MAX_LENGTH ? getPreviewContent ( formDTO . getContent ( ) ) . substring ( NumConstant . ZERO , DraftConstant . PREVIEW_CONTENT_MAX_LENGTH ) : getPreviewContent ( formDTO . getContent ( ) ) ) ;
article . setPublishDate ( DateUtils . stringToDate ( formDTO . getPublishDate ( ) , DateUtils . DATE_PATTERN ) ) ;
article . setPublisherId ( formDTO . getPublisher ( ) ) ;
article . setTags ( CollectionUtils . isEmpty ( formDTO . getTagNameList ( ) ) ? "" : formDTO . getTagNameList ( ) . stream ( ) . collect ( Collectors . joining ( "|" ) ) ) ;
article . setOrgId ( staffInfo . getAgencyId ( ) ) ;
article . setOrgIdPath ( StringUtils . isBlank ( agencyInfo . getPids ( ) ) | | agencyInfo . getPids ( ) . equals ( NumConstant . ZERO_STR ) ? agencyInfo . getId ( ) : agencyInfo . getPids ( ) . concat ( ":" ) . concat ( agencyInfo . getId ( ) ) ) ;
article . setRichTextFlag ( NumConstant . ONE_STR ) ;
baseDao . insert ( article ) ;
// 2.内容
ArticleContentEntity articleContent = ConvertUtils . sourceToTarget ( article , ArticleContentEntity . class ) ;
articleContent . setCustomerId ( customerId ) ;
articleContent . setArticleId ( article . getId ( ) ) ;
articleContent . setContent ( formDTO . getContent ( ) ) ;
articleContent . setContentType ( "rich_text" ) ;
articleContent . setOrderNum ( NumConstant . ZERO ) ;
articleContentDao . insert ( articleContent ) ;
// 3.操作记录
ArticleOperateRecordEntity articleOperateRecord = new ArticleOperateRecordEntity ( ) ;
articleOperateRecord . setCustomerId ( customerId ) ;
articleOperateRecord . setArticleId ( article . getId ( ) ) ;
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 . PUBLISH ) ;
articleOperateRecord . setOpTime ( new Date ( ) ) ;
articleOperateRecordService . insert ( articleOperateRecord ) ;
// 4.发布范围
if ( ! CollectionUtils . isEmpty ( formDTO . getGridIdList ( ) ) ) {
List < ArticlePublishRangeEntity > rangeList = new ArrayList < > ( ) ;
formDTO . getGridIdList ( ) . forEach ( g - > {
GridInfoCache gridInfo = CustomerOrgRedis . getGridInfo ( g ) ;
if ( null = = gridInfo ) {
throw new EpmetException ( "未查询到网格信息:" + g ) ;
}
ArticlePublishRangeEntity articlePublishRange = ConvertUtils . sourceToTarget ( gridInfo , ArticlePublishRangeEntity . class ) ;
articlePublishRange . setCustomerId ( customerId ) ;
articlePublishRange . setArticleId ( article . getId ( ) ) ;
articlePublishRange . setGridId ( g ) ;
articlePublishRange . setAgencyGridName ( gridInfo . getGridNamePath ( ) ) ;
articlePublishRange . setAgencyId ( gridInfo . getPid ( ) ) ;
AgencyInfoCache info = CustomerOrgRedis . getAgencyInfo ( gridInfo . getPid ( ) ) ;
if ( null = = info ) {
throw new EpmetException ( "未查询到组织信息:" + gridInfo . getPid ( ) ) ;
}
articlePublishRange . setPids ( info . getPids ( ) ) ;
articlePublishRange . setPublishStatus ( ArticleConstant . PUBLISHED ) ;
articlePublishRange . setId ( null ) ;
rangeList . add ( articlePublishRange ) ;
} ) ;
articlePublishRangeService . insertBatch ( rangeList ) ;
}
// 5.文章标签
UpdateCustomerTagCacheDTO updateCustomerTagCacheDTO = updateCustomerTagV2 ( formDTO . getUserId ( ) , formDTO . getCustomerId ( ) , StringUtils . isBlank ( article . getTags ( ) ) ? "" : article . getTags ( ) ) ;
if ( null ! = updateCustomerTagCacheDTO ) {
addArticleTagsV2 ( updateCustomerTagCacheDTO , customerId , article . getId ( ) ) ;
}
// 6.更新网格tag
List < UpdateGridTagCacheDTO > updateGridTagCacheDTOS = updateGridTagV2 ( updateCustomerTagCacheDTO , customerId , formDTO . getGridIdList ( ) , formDTO . getUserId ( ) ) ;
// 7.文章封面
if ( StringUtils . isNotBlank ( formDTO . getImgUrl ( ) ) ) {
ArticleCoverEntity articleCover = new ArticleCoverEntity ( ) ;
articleCover . setCustomerId ( customerId ) ;
articleCover . setArticleId ( article . getId ( ) ) ;
articleCover . setImgUrl ( formDTO . getImgUrl ( ) ) ;
articleCover . setAuditStatus ( "pass" ) ;
articleCoverDao . insert ( articleCover ) ;
}
// 8.更新redis
try {
this . updateCacheCustomerTag ( updateCustomerTagCacheDTO ) ;
this . updateCacheGridTag ( updateGridTagCacheDTOS ) ;
} catch ( Exception e ) {
log . error ( "scanAllPassPublishArticle update redis exception" , e ) ;
throw new RenException ( EpmetErrorCode . SERVER_ERROR . getCode ( ) , EpmetErrorCode . SERVER_ERROR . getMsg ( ) ) ;
}
} else { // 存草稿
// 1.草稿
DraftEntity draft = ConvertUtils . sourceToTarget ( formDTO , DraftEntity . class ) ;
draft . setDepartmentId ( customerId ) ;
draft . setPreviewContent ( StringUtils . isBlank ( formDTO . getContent ( ) ) ? "" : getPreviewContent ( formDTO . getContent ( ) ) . length ( ) > DraftConstant . PREVIEW_CONTENT_MAX_LENGTH ? getPreviewContent ( formDTO . getContent ( ) ) . substring ( NumConstant . ZERO , DraftConstant . PREVIEW_CONTENT_MAX_LENGTH ) : getPreviewContent ( formDTO . getContent ( ) ) ) ;
draft . setPublisherId ( StringUtils . isBlank ( formDTO . getPublisher ( ) ) ? "" : formDTO . getPublisher ( ) ) ;
draft . setPublishDate ( StringUtils . isBlank ( formDTO . getPublishDate ( ) ) ? null : DateUtils . stringToDate ( formDTO . getPublishDate ( ) , DateUtils . DATE_PATTERN ) ) ;
draft . setTags ( CollectionUtils . isEmpty ( formDTO . getTagNameList ( ) ) ? "" : formDTO . getTagNameList ( ) . stream ( ) . collect ( Collectors . joining ( "|" ) ) ) ;
draft . setOrgId ( staffInfo . getAgencyId ( ) ) ;
draft . setOrgIdPath ( StringUtils . isBlank ( agencyInfo . getPids ( ) ) | | agencyInfo . getPids ( ) . equals ( NumConstant . ZERO_STR ) ? agencyInfo . getId ( ) : agencyInfo . getPids ( ) . concat ( ":" ) . concat ( agencyInfo . getId ( ) ) ) ;
if ( formDTO . getPublisherType ( ) . equals ( DraftConstant . GRID ) ) {
draft . setGridId ( formDTO . getPublisher ( ) ) ;
}
draft . setStatusFlag ( DraftConstant . UNPUBLISH ) ;
draft . setRichTextFlag ( NumConstant . ONE_STR ) ;
draftDao . insert ( draft ) ;
// 2.内容
if ( StringUtils . isNotBlank ( formDTO . getContent ( ) ) ) {
DraftContentEntity draftContent = ConvertUtils . sourceToTarget ( draft , DraftContentEntity . class ) ;
draftContent . setCustomerId ( customerId ) ;
draftContent . setDraftId ( draft . getId ( ) ) ;
draftContent . setContent ( formDTO . getContent ( ) ) ;
draftContent . setContentType ( "rich_text" ) ;
draftContent . setOrderNum ( NumConstant . ZERO ) ;
draftContentDao . insert ( draftContent ) ;
}
// 3.发布范围
if ( ! CollectionUtils . isEmpty ( formDTO . getGridIdList ( ) ) ) {
List < DraftPublishRangeEntity > rangeList = new ArrayList < > ( ) ;
formDTO . getGridIdList ( ) . forEach ( g - > {
GridInfoCache gridInfo = CustomerOrgRedis . getGridInfo ( g ) ;
if ( null = = gridInfo ) {
throw new EpmetException ( "未查询到网格信息:" + g ) ;
}
DraftPublishRangeEntity draftPublishRange = ConvertUtils . sourceToTarget ( gridInfo , DraftPublishRangeEntity . class ) ;
draftPublishRange . setCustomerId ( customerId ) ;
draftPublishRange . setDraftId ( draft . getId ( ) ) ;
draftPublishRange . setGridId ( g ) ;
draftPublishRange . setAgencyGridName ( gridInfo . getGridNamePath ( ) ) ;
draftPublishRange . setAgencyId ( gridInfo . getPid ( ) ) ;
AgencyInfoCache info = CustomerOrgRedis . getAgencyInfo ( gridInfo . getPid ( ) ) ;
if ( null = = info ) {
throw new EpmetException ( "未查询到组织信息:" + gridInfo . getPid ( ) ) ;
}
draftPublishRange . setPids ( info . getPids ( ) ) ;
draftPublishRange . setPublishStatus ( DraftConstant . UNPUBLISH ) ;
draftPublishRange . setId ( null ) ;
rangeList . add ( draftPublishRange ) ;
} ) ;
draftPublishRangeService . insertBatch ( rangeList ) ;
}
// 4.草稿封面
if ( StringUtils . isNotBlank ( formDTO . getImgUrl ( ) ) ) {
DraftCoverEntity draftCover = new DraftCoverEntity ( ) ;
draftCover . setCustomerId ( customerId ) ;
draftCover . setDraftId ( draft . getId ( ) ) ;
draftCover . setImgUrl ( formDTO . getImgUrl ( ) ) ;
draftCover . setAuditStatus ( "pass" ) ;
draftCoverDao . insert ( draftCover ) ;
}
}
}
/ * *
* Desc : 获取内容中的汉字
* @param content
* @author zxc
* @date 2022 / 7 / 1 10 : 32
* /
public String getPreviewContent ( String content ) {
// 定义script的正则表达式
String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>" ;
// 定义style的正则表达式
String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>" ;
// 定义HTML标签的正则表达式
String regEx_html = "<[^>]+>" ;
//定义空格回车换行符
String regEx_space = "\\s*|\t|\r|\n" ;
Pattern p_script = Pattern . compile ( regEx_script , Pattern . CASE_INSENSITIVE ) ;
Matcher m_script = p_script . matcher ( content ) ;
// 过滤script标签
content = m_script . replaceAll ( "" ) ;
Pattern p_style = Pattern . compile ( regEx_style , Pattern . CASE_INSENSITIVE ) ;
Matcher m_style = p_style . matcher ( content ) ;
// 过滤style标签
content = m_style . replaceAll ( "" ) ;
Pattern p_html = Pattern . compile ( regEx_html , Pattern . CASE_INSENSITIVE ) ;
Matcher m_html = p_html . matcher ( content ) ;
// 过滤html标签
content = m_html . replaceAll ( "" ) ;
Pattern p_space = Pattern . compile ( regEx_space , Pattern . CASE_INSENSITIVE ) ;
Matcher m_space = p_space . matcher ( content ) ;
// 过滤空格回车标签
content = m_space . replaceAll ( "" ) ;
//去空格
content = content . replaceAll ( " " , "" ) ;
return content . trim ( ) ;
}
@Override
public PageData < PublishedListResultDTO > articleListV2 ( ArticleListFormDTO formDTO ) {
//1.获取工作人员缓存信息
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis . getStaffInfo ( formDTO . getCustomerId ( ) , formDTO . getStaffId ( ) ) ;
if ( null = = staffInfo ) {
throw new EpmetException ( "获取工作人员信息失败" ) ;
}
//查询当前组织及下级数据
formDTO . setAgencyId ( staffInfo . getAgencyId ( ) ) ;
//列表查询
PageHelper . startPage ( formDTO . getPageNo ( ) , formDTO . getPageSize ( ) , formDTO . getIsPage ( ) ) ;
List < PublishedListResultDTO > list = baseDao . selectAllArticle ( formDTO ) ;
PageInfo < PublishedListResultDTO > pageInfo = new PageInfo < > ( list ) ;
//封装数据
if ( ! CollectionUtils . isEmpty ( list ) ) {
list . forEach ( l - > {
l . setTagNameList ( StringUtils . isNotBlank ( l . getTags ( ) ) ? Arrays . asList ( l . getTags ( ) . split ( "[|]" ) ) : new ArrayList < > ( ) ) ;
l . setIsMePublished ( l . getCreatedBy ( ) . equals ( formDTO . getStaffId ( ) ) ? true : false ) ;
} ) ;
}
return new PageData < > ( list , pageInfo . getTotal ( ) ) ;
}
@Override
public PublishedListResultDTO detailV2 ( ArticleListFormDTO formDTO ) {
PublishedListResultDTO resultDTO = new PublishedListResultDTO ( ) ;
//1.查询文章主表信息
List < PublishedListResultDTO > list = baseDao . selectAllArticle ( formDTO ) ;
if ( ! CollectionUtils . isEmpty ( list ) ) {
resultDTO = list . get ( NumConstant . ZERO ) ;
resultDTO . setTagNameList ( StringUtils . isNotBlank ( resultDTO . getTags ( ) ) ? Arrays . asList ( resultDTO . getTags ( ) . split ( "[|]" ) ) : new ArrayList < > ( ) ) ;
resultDTO . setIsMePublished ( resultDTO . getCreatedBy ( ) . equals ( formDTO . getStaffId ( ) ) ? true : false ) ;
//查询文章涉及的发布范围网络Id列表
LambdaQueryWrapper < ArticlePublishRangeEntity > tWrapper = new LambdaQueryWrapper < > ( ) ;
tWrapper . eq ( ArticlePublishRangeEntity : : getArticleId , formDTO . getArticleId ( ) ) ;
tWrapper . eq ( ArticlePublishRangeEntity : : getDelFlag , NumConstant . ZERO_STR ) ;
//【文章下线的查所有发布范围,文章没下线的只查还没下线的发布范围】
if ( "offline" . equals ( resultDTO . getStatusFlag ( ) ) ) {
tWrapper . eq ( ArticlePublishRangeEntity : : getPublishStatus , "offline" ) ;
} else {
tWrapper . eq ( ArticlePublishRangeEntity : : getPublishStatus , "published" ) ;
}
List < ArticlePublishRangeEntity > entityList = articlePublishRangeDao . selectList ( tWrapper ) ;
if ( ! CollectionUtils . isEmpty ( entityList ) ) {
List < String > contentList = entityList . stream ( ) . map ( ArticlePublishRangeEntity : : getGridId ) . collect ( Collectors . toList ( ) ) ;
resultDTO . setGridIdList ( contentList ) ;
}
//查询文章内容
LambdaQueryWrapper < ArticleContentEntity > tWrapper1 = new LambdaQueryWrapper < > ( ) ;
tWrapper1 . eq ( ArticleContentEntity : : getArticleId , formDTO . getArticleId ( ) ) ;
tWrapper1 . eq ( ArticleContentEntity : : getDelFlag , NumConstant . ZERO_STR ) ;
tWrapper1 . orderByDesc ( ArticleContentEntity : : getOrderNum ) ;
List < ArticleContentEntity > contentEntityList = articleContentDao . selectList ( tWrapper1 ) ;
if ( ! CollectionUtils . isEmpty ( contentEntityList ) ) {
List < PublishedListResultDTO . Content > contentList = ConvertUtils . sourceToTarget ( contentEntityList , PublishedListResultDTO . Content . class ) ;
resultDTO . setContentList ( contentList ) ;
}
//标签列表
LambdaQueryWrapper < ArticleTagsEntity > tWrapper2 = new LambdaQueryWrapper < > ( ) ;
tWrapper2 . eq ( ArticleTagsEntity : : getArticleId , formDTO . getArticleId ( ) ) ;
tWrapper2 . eq ( ArticleTagsEntity : : getDelFlag , NumConstant . ZERO_STR ) ;
List < ArticleTagsEntity > tagsEntityList = articleTagsDao . selectList ( tWrapper2 ) ;
if ( ! CollectionUtils . isEmpty ( tagsEntityList ) ) {
List < String > contentList = tagsEntityList . stream ( ) . map ( ArticleTagsEntity : : getTagId ) . collect ( Collectors . toList ( ) ) ;
resultDTO . setTagIdList ( contentList ) ;
}
}
return resultDTO ;
}
}