Commit 83b257e0 authored by 刘基明's avatar 刘基明

同步专栏

parent 44abacfc
......@@ -30,7 +30,7 @@ public class CreateThemeReq {
@ApiModelProperty(value = "修改,则传入正在编辑的ThemeId")
private String editThemeId = "";
@ApiModelProperty("是否同步到社区 0为同步 1为不同步 不传也为同步")
@ApiModelProperty("是否同步到社区 0为不同步 1为同步 不传也为同步")
private Integer syncToNewComm = 0;
}
......@@ -3,6 +3,7 @@ package com.tanpu.community.config;
import feign.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
/**
* @description:
......@@ -16,4 +17,9 @@ public class FeignConfiguration {
//这里记录所有,根据实际情况选择合适的日志level
return Logger.Level.FULL;
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
......@@ -38,6 +38,7 @@ import com.tanpu.community.dao.entity.community.CollectionEntity;
import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.dao.entity.community.ThemeAttachmentEntity;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.feign.community.FeignClientForCommunity;
import com.tanpu.community.feign.fatools.FeignClientForFatools;
import com.tanpu.community.service.*;
import com.tanpu.community.service.base.ESService;
......@@ -50,6 +51,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.BeanUtils;
......@@ -126,6 +128,10 @@ public class ThemeManager {
@Resource
private RestTemplate restTemplate;
// 专栏
@Autowired
private FeignClientForCommunity feignClientForCommunity;
public ThemeFullSearchResp themeFullSearch(String keyword, Integer pageNo, Integer pageSize, String ident, String userId) {
List<String> excludeIds;
if (pageNo > 1) {
......@@ -195,7 +201,7 @@ public class ThemeManager {
// 新建
themeService.insertTheme(themeEntity);
// 同步到专栏
if (0 == req.getSyncToNewComm()) {
if (1 == req.getSyncToNewComm()) {
convertToNewsFeed(req, themeEntity.getThemeId(), userId);
}
......@@ -230,7 +236,7 @@ public class ThemeManager {
throw new BizException("长文类型无法同步专栏");
}
NewsFeedSave4NewCommReq convertReq = new NewsFeedSave4NewCommReq();
convertReq.setNewsFeedId(CommunityConstant.THEME_PREFIX + themeId);
convertReq.setNewsFeedId(themeId);
ArrayList<NewsFeedResReq> feedList = new ArrayList<>();
for (ThemeContentReq themeContentReq : req.getContent()) {
// 文字内容添加到content
......@@ -252,16 +258,26 @@ public class ThemeManager {
}
}
convertReq.setNewsFeedResList(feedList);
CommonResp restResponse = feignClientForCommunity.saveNewsFeed4NewComm(convertReq);
if (restResponse.isNotSuccess() || !ObjectUtils.anyNotNull(restResponse.getData())) {
throw new BizException("同步圈子调用失败");
}
}
private NewsFeedResReq convertImg(ImagesDTO img, String userId) {
String[] arr = StringUtils.split(img.getRemark(), ".");
String suffix = arr[arr.length - 1];
ResponseEntity<byte[]> resp = restTemplate.getForEntity(img.getRemark(), byte[].class);
byte[] rst = resp.getBody();
String fileName = tmpDir + System.currentTimeMillis() + ".tmp";
// todo
String fileName = tmpDir + System.currentTimeMillis() + ".jpg";
File f = new File(fileName);
try {
FileUtils.writeByteArrayToFile(f, rst);
......@@ -272,8 +288,7 @@ public class ThemeManager {
headers.set("uid", userId);
MultiValueMap<String, Object> params = new LinkedMultiValueMap<String, Object>();
HashMap<String, Object> item = new HashMap<>();
// todo 图片类型
item.put("filetype", "jpg");
item.put("filetype", suffix);
item.put("refid", img.getRelId());
item.put("mode", 0);
item.put("userId", userId);
......@@ -292,13 +307,11 @@ public class ThemeManager {
if (!ret.isSuccess()) {
throw new RuntimeException("reponse is not success");
}
JSONObject commonResult = ret.getData();
JSONObject data = ret.getData();
NewsFeedResReq newsFeedResReq = new NewsFeedResReq();
newsFeedResReq.setRelId(commonResult.getString("fileId"));
newsFeedResReq.setRelId(data.getString("fileId"));
newsFeedResReq.setRelType(Integer.parseInt(RelTypeEnum.IMAGE_FILE.type));
newsFeedResReq.setRemark(commonResult.getString("fileurl"));
newsFeedResReq.setRemark(data.getString("fileurl"));
return newsFeedResReq;
......
......@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
......@@ -40,6 +41,9 @@ public class RecommendService {
private ThemeService themeService;
@Resource
private RestTemplate restTemplate;
// 最新
private List<ThemeAnalysDO> recentThemeList = new ArrayList<>();
// 推荐
......@@ -101,7 +105,6 @@ public class RecommendService {
if (!"true".equals(enablePython)) {
return Collections.emptyList();
}
RestTemplate restTemplate = new RestTemplate();
HashMap<String, String> param = new HashMap<>();
param.put("user_id", userId);
try {
......
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