Commit 9a1acb92 authored by 刘基明's avatar 刘基明

同步专栏

parent 83b257e0
package com.tanpu.community.manager; package com.tanpu.community.manager;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.tanpu.biz.common.enums.RelTypeEnum; import com.tanpu.biz.common.enums.RelTypeEnum;
...@@ -31,7 +30,11 @@ import com.tanpu.community.api.beans.vo.ImagesDTO; ...@@ -31,7 +30,11 @@ import com.tanpu.community.api.beans.vo.ImagesDTO;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp; import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedResReq; import com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedResReq;
import com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedSave4NewCommReq; import com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedSave4NewCommReq;
import com.tanpu.community.api.enums.*; import com.tanpu.community.api.enums.BlockTypeEnum;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.OperationTypeEnum;
import com.tanpu.community.api.enums.ThemeListTypeEnum;
import com.tanpu.community.api.enums.ThemeTypeEnum;
import com.tanpu.community.cache.RedisCache; import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.dao.entity.community.BlackListEntity; import com.tanpu.community.dao.entity.community.BlackListEntity;
import com.tanpu.community.dao.entity.community.CollectionEntity; import com.tanpu.community.dao.entity.community.CollectionEntity;
...@@ -269,16 +272,15 @@ public class ThemeManager { ...@@ -269,16 +272,15 @@ public class ThemeManager {
private NewsFeedResReq convertImg(ImagesDTO img, String userId) { private NewsFeedResReq convertImg(ImagesDTO img, String userId) {
String imgUrl = img.getRemark();
String[] arr = StringUtils.split(img.getRemark(), "."); String[] arr = StringUtils.split(imgUrl, ".");
String suffix = arr[arr.length - 1]; String suffix = arr[arr.length - 1];
String fileName = imgUrl.substring(imgUrl.lastIndexOf('/') + 1);
ResponseEntity<byte[]> resp = restTemplate.getForEntity(img.getRemark(), byte[].class); ResponseEntity<byte[]> resp = restTemplate.getForEntity(img.getRemark(), byte[].class);
byte[] rst = resp.getBody(); byte[] rst = resp.getBody();
// todo
String fileName = tmpDir + System.currentTimeMillis() + ".jpg";
File f = new File(fileName); File f = new File(fileName);
try { try {
FileUtils.writeByteArrayToFile(f, rst); FileUtils.writeByteArrayToFile(f, rst);
...@@ -303,17 +305,15 @@ public class ThemeManager { ...@@ -303,17 +305,15 @@ public class ThemeManager {
if (StringUtils.isBlank(response.getBody())) { if (StringUtils.isBlank(response.getBody())) {
throw new RuntimeException("response body is blank"); throw new RuntimeException("response body is blank");
} }
CommonResp<JSONObject> ret = JSON.parseObject(response.getBody(), CommonResp.class); CommonResp<LinkedHashMap<String, String>> responseBody = JsonUtil.toBean(response.getBody(), CommonResp.class);
if (!ret.isSuccess()) { if (!responseBody.isSuccess()) {
throw new RuntimeException("reponse is not success"); throw new RuntimeException("reponse is not success");
} }
JSONObject data = ret.getData(); HashMap<String, String> data = responseBody.getData();
NewsFeedResReq newsFeedResReq = new NewsFeedResReq(); return NewsFeedResReq.builder().relId(data.get("fileId"))
newsFeedResReq.setRelId(data.getString("fileId")); .relType(Integer.parseInt(RelTypeEnum.IMAGE_FILE.type))
newsFeedResReq.setRelType(Integer.parseInt(RelTypeEnum.IMAGE_FILE.type)); .remark(data.get("fileurl")).build();
newsFeedResReq.setRemark(data.getString("fileurl"));
return newsFeedResReq;
} catch (Exception e) { } catch (Exception e) {
log.error("error in handleSyncImg for imgUrl: {}", img.getRemark(), e); log.error("error in handleSyncImg for imgUrl: {}", img.getRemark(), e);
......
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