Browse Source

党建声音暂存一波

dev
zxc 3 years ago
parent
commit
b22c87134d
  1. 72
      epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/AddOrSaveDraftFormDTO.java
  2. 10
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/constant/ArticleConstant.java
  3. 14
      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/service/ArticleService.java
  5. 146
      epmet-module/gov-voice/gov-voice-server/src/main/java/com/epmet/service/impl/ArticleServiceImpl.java

72
epmet-module/gov-voice/gov-voice-client/src/main/java/com/epmet/dto/form/AddOrSaveDraftFormDTO.java

@ -0,0 +1,72 @@
package com.epmet.dto.form;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* @Author zxc
* @DateTime 2022/6/30 13:41
* @DESC
*/
@Data
public class AddOrSaveDraftFormDTO implements Serializable {
public interface AddOrSaveDraftForm{}
/**
* 类型 发布文章article存草稿draft
*/
@NotBlank(message = "类型不能为空",groups = AddOrSaveDraftForm.class)
private String type;
@NotBlank(message = "标题不能为空",groups = AddOrSaveDraftForm.class)
@Length(max = 50, message = "标题最长为50个字")
private String title;
/**
* 发布范围IDs
*/
private List<String> gridIdList;
/**
* 发布范围Names
*/
private List<String> publishRangeDesc;
/**
* 文章标签
*/
private List<String> tagNameList;
@NotBlank(message = "发布单位不能为空",groups = AddOrSaveDraftForm.class)
private String publisher;
@NotBlank(message = "发布单位名称不能为空",groups = AddOrSaveDraftForm.class)
private String publisherName;
/**
* 发布单位类型 机关:agency部门department网格grid
*/
@NotBlank(message = "发布单位类型不能为空",groups = AddOrSaveDraftForm.class)
private String publisherType;
@NotNull(message = "发布时间不能为空",groups = AddOrSaveDraftForm.class)
private Date publishDate;
@NotBlank(message = "文章内容不能为空",groups = AddOrSaveDraftForm.class)
private String content;
/**
* 是否置顶 1是0否
*/
private Integer isTop;
private String userId;
private String customerId;
}

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

@ -19,6 +19,8 @@ public interface ArticleConstant {
* 发布状态-已发布
*/
String PUBLISHED = "published";
String PUBLISH = "publish";
String PUBLISH_CONTENT = "发布文章";
/**
* 发布状态-已下线
*/
@ -66,4 +68,12 @@ public interface ArticleConstant {
* 发布方式 api审核后自动发布
*/
String PUBLISH_WAY_AUTO_AUDIT = "autoAudit";
/**
* 未审核
*/
String AUDIT_WAY_NO_AUDIT = "noAudit";
String SAVE_TYPE_ARTICLE = "article";
String SAVE_TYPE_DRAFT = "draft";
}

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

@ -431,4 +431,18 @@ public class ArticleController {
return new Result<PublishedListResultDTO>().ok(articleService.detailV2(formDTO));
}
/**
* Desc: 发布文章/存草稿
* @param formDTO
* @author zxc
* @date 2022/6/30 14:03
*/
@PostMapping("addOrSaveDraft")
public Result addOrSaveDraft(@LoginUser TokenDto tokenDto,@RequestBody AddOrSaveDraftFormDTO formDTO){
ValidatorUtils.validateEntity(formDTO, AddOrSaveDraftFormDTO.AddOrSaveDraftForm.class);
formDTO.setCustomerId(tokenDto.getCustomerId());
formDTO.setUserId(tokenDto.getUserId());
articleService.addOrSaveDraft(formDTO);
return new Result();
}
}

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

@ -244,6 +244,14 @@ public interface ArticleService extends BaseService<ArticleEntity> {
*/
List<ArticleListResultDTO> getArticleListByTag(String tagId, Integer pageNo, Integer pageSize);
/**
* Desc: 发布文章/存草稿
* @param formDTO
* @author zxc
* @date 2022/6/30 14:03
*/
void addOrSaveDraft(AddOrSaveDraftFormDTO formDTO);
PageData<PublishedListResultDTO> articleListV2(ArticleListFormDTO formDTO);
PublishedListResultDTO detailV2(ArticleListFormDTO formDTO);

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

@ -30,6 +30,10 @@ 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.redis.common.CustomerStaffRedis;
import com.epmet.commons.tools.scan.param.ImgScanParamDTO;
import com.epmet.commons.tools.scan.param.ImgTaskDTO;
@ -126,6 +130,8 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
private ArticleTagsDao articleTagsDao;
@Autowired
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient;
@Autowired
private ArticleTagsService articleTagsService;
@Value("${openapi.scan.server.url}")
private String scanApiUrl;
@ -1262,9 +1268,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();
@ -1278,8 +1293,6 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
result.setCustomerId(customerId);
result.setTagsInfo(tagsInfo);
}
return result;
}
@ -1318,13 +1331,17 @@ 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){
List<UpdateTagUseCountsResultDTO> tagsInfo = formDto.getTagsInfo();
List<UpdateGridTagsFormDTO> gridTags = new ArrayList<>();
List<UpdateGridTagCacheDTO> gridTagCache = new ArrayList<>();
gridIds.forEach(gridId -> {
@ -1380,23 +1397,22 @@ 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<>();
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(addArticleTags);
articleTagsService.insertBatch(articleTags);
}
/**
@ -1454,6 +1470,100 @@ public class ArticleServiceImpl extends BaseServiceImpl<ArticleDao, ArticleEntit
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) {
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);
article.setCustomerId(customerId);
// 按照之前逻辑存成客户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.setTitleAuditStatus(ArticleConstant.AUDIT_WAY_NO_AUDIT);
article.setPreviewContent(formDTO.getContent().length() > DraftConstant.PREVIEW_CONTENT_MAX_LENGTH ? formDTO.getContent().substring(NumConstant.ZERO,DraftConstant.PREVIEW_CONTENT_MAX_LENGTH) : formDTO.getContent());
article.setPublisherId(formDTO.getPublisher());
article.setPublishRangeDesc(formDTO.getPublishRangeDesc().stream().collect(Collectors.joining("、")));
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()));
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.setAuditStatus(ArticleConstant.AUDIT_WAY_NO_AUDIT);
articleContent.setOrderNum(NumConstant.ZERO);
articleContentDao.insert(articleContent);
// 3.操作记录
ArticleOperateRecordEntity articleOperateRecord = new ArticleOperateRecordEntity();
articleOperateRecord.setCustomerId(customerId);
articleOperateRecord.setArticleId(article.getId());
articleOperateRecord.setGridIds(formDTO.getGridIdList().stream().collect(Collectors.joining(":")));
articleOperateRecord.setOpUser(staffInfo.getAgencyName().concat("-").concat(staffInfo.getRealName()));
articleOperateRecord.setContent(formDTO.getContent());
articleOperateRecord.setOpType(ArticleConstant.PUBLISH);
articleOperateRecord.setOpTime(new Date());
articleOperateRecordService.insert(articleOperateRecord);
// 4.发布范围
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());
articlePublishRange.setPublishStatus(ArticleConstant.PUBLISHED);
articlePublishRange.setId(null);
rangeList.add(articlePublishRange);
});
articlePublishRangeService.insertBatch(rangeList);
// 5.文章标签
UpdateCustomerTagCacheDTO updateCustomerTagCacheDTO = updateCustomerTagV2(formDTO.getUserId(), formDTO.getCustomerId(), article.getTags());
addArticleTagsV2(updateCustomerTagCacheDTO,customerId,article.getId());
// 6.更新网格tag
List<UpdateGridTagCacheDTO> updateGridTagCacheDTOS = updateGridTagV2(updateCustomerTagCacheDTO, customerId, formDTO.getGridIdList(), formDTO.getUserId());
// 7.更新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 {// 存草稿
}
}
@Override
public PageData<PublishedListResultDTO> articleListV2(ArticleListFormDTO formDTO) {
//1.获取工作人员缓存信息

Loading…
Cancel
Save