|
@@ -1,5 +1,7 @@
|
|
|
package com.tzld.piaoquan.wecom.service.Impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.tzld.piaoquan.wecom.common.enums.MessageAttachmentTypeEnum;
|
|
|
import com.tzld.piaoquan.wecom.common.exception.CustomizeException;
|
|
|
import com.tzld.piaoquan.wecom.dao.mapper.MessageAttachmentMapper;
|
|
@@ -7,6 +9,8 @@ import com.tzld.piaoquan.wecom.model.po.MessageAttachment;
|
|
|
import com.tzld.piaoquan.wecom.model.po.MessageAttachmentExample;
|
|
|
import com.tzld.piaoquan.wecom.model.vo.MiniprogramVo;
|
|
|
import com.tzld.piaoquan.wecom.service.MessageAttachmentService;
|
|
|
+import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
|
|
|
+import com.tzld.piaoquan.wecom.utils.HttpPoolClient;
|
|
|
import com.tzld.piaoquan.wecom.utils.MessageUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -15,11 +19,11 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import static com.tzld.piaoquan.wecom.common.constant.MessageConstant.appid;
|
|
|
+import static com.tzld.piaoquan.wecom.common.constant.OtherServerURL.POST_VIDEO_DETAIL_URL;
|
|
|
import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.GUARANTEED_MINIPROGRAM_KEY;
|
|
|
import static com.tzld.piaoquan.wecom.common.enums.ExceptionCodeEnum.PARAMS_ERROR;
|
|
|
|
|
@@ -27,6 +31,7 @@ import static com.tzld.piaoquan.wecom.common.enums.ExceptionCodeEnum.PARAMS_ERRO
|
|
|
@Service
|
|
|
public class MessageAttachmentServiceImpl implements MessageAttachmentService {
|
|
|
|
|
|
+ private static final HttpPoolClient httpPoolClientDefault = HttpClientUtil.create(30000, 30000, 2000, 5000, 5, 30000);
|
|
|
|
|
|
@Autowired
|
|
|
private MessageAttachmentMapper messageAttachmentMapper;
|
|
@@ -60,9 +65,6 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
|
|
|
if (StringUtils.isEmpty(miniprogramVo.getPage())) {
|
|
|
throw new CustomizeException(PARAMS_ERROR);
|
|
|
}
|
|
|
- if (StringUtils.isEmpty(miniprogramVo.getCover())) {
|
|
|
- throw new CustomizeException(PARAMS_ERROR);
|
|
|
- }
|
|
|
if (StringUtils.isEmpty(miniprogramVo.getTitle())) {
|
|
|
throw new CustomizeException(PARAMS_ERROR);
|
|
|
}
|
|
@@ -70,9 +72,6 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
|
|
|
if (videoId == null) {
|
|
|
throw new CustomizeException(PARAMS_ERROR);
|
|
|
}
|
|
|
- if (StringUtils.isEmpty(miniprogramVo.getAppid())) {
|
|
|
- miniprogramVo.setAppid(appid);
|
|
|
- }
|
|
|
MessageAttachment messageAttachment = new MessageAttachment();
|
|
|
BeanUtils.copyProperties(miniprogramVo, messageAttachment);
|
|
|
messageAttachment.setMiniprogramVideoId(videoId);
|
|
@@ -80,9 +79,39 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
|
|
|
messageAttachmentList.add(messageAttachment);
|
|
|
videoList.add(videoId);
|
|
|
}
|
|
|
+ Map<Long, String> coverMap = getCover(videoList);
|
|
|
+ for (MessageAttachment messageAttachment : messageAttachmentList) {
|
|
|
+ String cover = coverMap.get(messageAttachment.getMiniprogramVideoId());
|
|
|
+ if (StringUtils.isEmpty(cover)) {
|
|
|
+ throw new RuntimeException("获取封面异常");
|
|
|
+ }
|
|
|
+ messageAttachment.setCover(cover);
|
|
|
+ messageAttachment.setAppid(appid);
|
|
|
+ }
|
|
|
addMiniprogram(messageAttachmentList);
|
|
|
for (Long video : videoList) {
|
|
|
redisTemplate.opsForList().rightPush(GUARANTEED_MINIPROGRAM_KEY, video);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public Map<Long, String> getCover(List<Long> videoIdList) {
|
|
|
+ try {
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("videoIdList", videoIdList);
|
|
|
+ String post = httpPoolClientDefault.post(POST_VIDEO_DETAIL_URL, params.toJSONString());
|
|
|
+ JSONObject res = JSONObject.parseObject(post);
|
|
|
+ JSONArray data = res.getJSONArray("data");
|
|
|
+ Map<Long, String> map = new HashMap<>();
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
+ JSONObject jsonObject = data.getJSONObject(i);
|
|
|
+ Long videoId = jsonObject.getLong("id");
|
|
|
+ JSONObject coverImg = jsonObject.getJSONObject("coverImg");
|
|
|
+ String coverImgPath = coverImg.getString("coverImgPath");
|
|
|
+ map.put(videoId, coverImgPath);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException("获取封面异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|