Commit 01503896 authored by 刘基明's avatar 刘基明

同步专栏

parent 26264f8b
......@@ -117,9 +117,10 @@ public class ThemeController {
@ApiOperation("专栏同步主题")
@PostMapping(value = "/convertFromNewsFeed")
@ResponseBody
public CommonResp<CreateThemeResp> convertFromNewsFeed(@Validated @RequestBody CreateThemeReq req) {
public CommonResp<Void> convertFromNewsFeed(@Validated @RequestBody CreateThemeReq req) {
String userId = userHolder.getUserId();
return CommonResp.success(themeManager.publishTheme(req, userId));
themeManager.convertFromNewsFeed(req, userId);
return CommonResp.success();
}
......
......@@ -150,14 +150,13 @@ public class ThemeManager {
}
/**
* 发表主题(修改)
*/
@Transactional
public CreateThemeResp publishTheme(CreateThemeReq req, String userId) {
if (CollectionUtils.isEmpty(req.getContent())) {
throw new BizException("正文内容不能为空");
}
// 校验参数
checkAttachment(req.getContent());
// 转播权限校验
......@@ -236,6 +235,8 @@ public class ThemeManager {
}
private void convertImg(ImagesDTO img,String userId){
HashMap map = new HashMap<>();
// todo 图片类型
......@@ -246,12 +247,18 @@ public class ThemeManager {
}
/**
* 参数校验
*
* @param themeAttachments
*/
private void checkAttachment(List<ThemeContentReq> themeAttachments) {
if (CollectionUtils.isEmpty(themeAttachments)) {
throw new BizException("正文内容不能为空");
}
for (ThemeContentReq content : themeAttachments) {
if (content.getType() == null) {
throw new IllegalArgumentException("主题内容ThemeContentReq缺少类型");
......@@ -592,6 +599,33 @@ public class ThemeManager {
this.evictThemeCache(themeId);
}
// 从专栏同步
public void convertFromNewsFeed(CreateThemeReq req, String userId) {
// 校验参数
checkAttachment(req.getContent());
// 转播权限校验
liveRelayCheck(userId,req.getContent());
// 保存主题表
ThemeEntity themeEntity = new ThemeEntity();
BeanUtils.copyProperties(req, themeEntity);
themeEntity.setAuthorId(userId);
themeEntity.setContent(JsonUtil.toJson(req.getContent()));
themeEntity.setThemeId(CommunityConstant.THEME_PREFIX+req.getEditThemeId());
themeService.insertTheme(themeEntity);
// 保存附件表
List<ThemeAttachmentEntity> themeAttachments = ConvertUtil.themeReqToAttachmentList(req, themeEntity.getThemeId());
themeAttachmentService.insertList(themeAttachments);
try {
esService.insertOrUpdateTheme(ConvertUtil.convert(themeEntity));
} catch (Exception e) {
log.error("error in save theme to ES. themeId:{}, error:{}", themeEntity.getThemeId(), ExceptionUtils.getStackTrace(e));
}
}
/**
* 腾讯云-内容检测
......@@ -743,4 +777,5 @@ public class ThemeManager {
redisCache.evict(StringUtils.joinWith("_", CACHE_THEME_ID, themeId));
}
}
......@@ -40,7 +40,10 @@ public class ThemeService {
@Transactional
public void insertTheme(ThemeEntity themeEntity) {
if (StringUtils.isBlank(themeEntity.getThemeId())){
themeEntity.setThemeId(uuidGenHelper.getUuidStr());
}
themeMapper.insert(themeEntity);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment