|
@@ -3,12 +3,16 @@ package com.tzld.piaoquan.wecom.service.Impl;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.tzld.piaoquan.wecom.common.enums.MessageAttachmentTypeEnum;
|
|
import com.tzld.piaoquan.wecom.common.enums.MessageAttachmentTypeEnum;
|
|
|
|
+import com.tzld.piaoquan.wecom.common.enums.StaffExtEnum;
|
|
import com.tzld.piaoquan.wecom.common.exception.CustomizeException;
|
|
import com.tzld.piaoquan.wecom.common.exception.CustomizeException;
|
|
import com.tzld.piaoquan.wecom.dao.mapper.MessageAttachmentMapper;
|
|
import com.tzld.piaoquan.wecom.dao.mapper.MessageAttachmentMapper;
|
|
|
|
+import com.tzld.piaoquan.wecom.model.bo.AdPutFlowParam;
|
|
|
|
+import com.tzld.piaoquan.wecom.model.bo.VideoDetail;
|
|
import com.tzld.piaoquan.wecom.model.po.MessageAttachment;
|
|
import com.tzld.piaoquan.wecom.model.po.MessageAttachment;
|
|
import com.tzld.piaoquan.wecom.model.po.MessageAttachmentExample;
|
|
import com.tzld.piaoquan.wecom.model.po.MessageAttachmentExample;
|
|
import com.tzld.piaoquan.wecom.model.vo.MiniprogramVo;
|
|
import com.tzld.piaoquan.wecom.model.vo.MiniprogramVo;
|
|
import com.tzld.piaoquan.wecom.service.MessageAttachmentService;
|
|
import com.tzld.piaoquan.wecom.service.MessageAttachmentService;
|
|
|
|
+import com.tzld.piaoquan.wecom.utils.DateUtil;
|
|
import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
|
|
import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
|
|
import com.tzld.piaoquan.wecom.utils.HttpPoolClient;
|
|
import com.tzld.piaoquan.wecom.utils.HttpPoolClient;
|
|
import com.tzld.piaoquan.wecom.utils.MessageUtil;
|
|
import com.tzld.piaoquan.wecom.utils.MessageUtil;
|
|
@@ -23,6 +27,8 @@ import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
import static com.tzld.piaoquan.wecom.common.constant.MessageConstant.appid;
|
|
import static com.tzld.piaoquan.wecom.common.constant.MessageConstant.appid;
|
|
|
|
+import static com.tzld.piaoquan.wecom.common.constant.MessageConstant.carrierIdMap;
|
|
|
|
+import static com.tzld.piaoquan.wecom.common.constant.OtherServerURL.POST_ADD_TENCENT;
|
|
import static com.tzld.piaoquan.wecom.common.constant.OtherServerURL.POST_VIDEO_DETAIL_URL;
|
|
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.constant.RedisConstant.GUARANTEED_MINIPROGRAM_KEY;
|
|
import static com.tzld.piaoquan.wecom.common.enums.ExceptionCodeEnum.PARAMS_ERROR;
|
|
import static com.tzld.piaoquan.wecom.common.enums.ExceptionCodeEnum.PARAMS_ERROR;
|
|
@@ -62,30 +68,24 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
|
|
List<MessageAttachment> messageAttachmentList = new ArrayList<>();
|
|
List<MessageAttachment> messageAttachmentList = new ArrayList<>();
|
|
List<Long> videoList = new ArrayList<>();
|
|
List<Long> videoList = new ArrayList<>();
|
|
for (MiniprogramVo miniprogramVo : miniprogramVoList) {
|
|
for (MiniprogramVo miniprogramVo : miniprogramVoList) {
|
|
- if (StringUtils.isEmpty(miniprogramVo.getPage())) {
|
|
|
|
- throw new CustomizeException(PARAMS_ERROR);
|
|
|
|
- }
|
|
|
|
- if (StringUtils.isEmpty(miniprogramVo.getTitle())) {
|
|
|
|
- throw new CustomizeException(PARAMS_ERROR);
|
|
|
|
- }
|
|
|
|
- Long videoId = MessageUtil.getVideoId(miniprogramVo.getPage());
|
|
|
|
- if (videoId == null) {
|
|
|
|
|
|
+ if (miniprogramVo.getVideoId() == null) {
|
|
throw new CustomizeException(PARAMS_ERROR);
|
|
throw new CustomizeException(PARAMS_ERROR);
|
|
}
|
|
}
|
|
MessageAttachment messageAttachment = new MessageAttachment();
|
|
MessageAttachment messageAttachment = new MessageAttachment();
|
|
BeanUtils.copyProperties(miniprogramVo, messageAttachment);
|
|
BeanUtils.copyProperties(miniprogramVo, messageAttachment);
|
|
- messageAttachment.setMiniprogramVideoId(videoId);
|
|
|
|
|
|
+ messageAttachment.setMiniprogramVideoId(miniprogramVo.getVideoId());
|
|
messageAttachment.setType(MessageAttachmentTypeEnum.MINIPROGRAM.getType());
|
|
messageAttachment.setType(MessageAttachmentTypeEnum.MINIPROGRAM.getType());
|
|
messageAttachmentList.add(messageAttachment);
|
|
messageAttachmentList.add(messageAttachment);
|
|
- videoList.add(videoId);
|
|
|
|
|
|
+ videoList.add(miniprogramVo.getVideoId());
|
|
}
|
|
}
|
|
- Map<Long, String> coverMap = getCover(videoList);
|
|
|
|
|
|
+ Map<Long, VideoDetail> coverMap = getVideoDetail(videoList);
|
|
for (MessageAttachment messageAttachment : messageAttachmentList) {
|
|
for (MessageAttachment messageAttachment : messageAttachmentList) {
|
|
- String cover = coverMap.get(messageAttachment.getMiniprogramVideoId());
|
|
|
|
- if (StringUtils.isEmpty(cover)) {
|
|
|
|
- throw new RuntimeException("获取封面异常");
|
|
|
|
|
|
+ VideoDetail videoDetail = coverMap.get(messageAttachment.getMiniprogramVideoId());
|
|
|
|
+ if (videoDetail == null || StringUtils.isEmpty(videoDetail.getCover()) || StringUtils.isEmpty(videoDetail.getTitle())) {
|
|
|
|
+ throw new RuntimeException("获取视频详情异常");
|
|
}
|
|
}
|
|
- messageAttachment.setCover(cover);
|
|
|
|
|
|
+ messageAttachment.setCover(videoDetail.getCover());
|
|
|
|
+ messageAttachment.setTitle(videoDetail.getTitle());
|
|
messageAttachment.setAppid(appid);
|
|
messageAttachment.setAppid(appid);
|
|
}
|
|
}
|
|
addMiniprogram(messageAttachmentList);
|
|
addMiniprogram(messageAttachmentList);
|
|
@@ -94,24 +94,91 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public Map<Long, String> getCover(List<Long> videoIdList) {
|
|
|
|
|
|
+ public Map<Long, VideoDetail> getVideoDetail(List<Long> videoIdList) {
|
|
try {
|
|
try {
|
|
|
|
+ Map<Long, VideoDetail> map = new HashMap<>();
|
|
JSONObject params = new JSONObject();
|
|
JSONObject params = new JSONObject();
|
|
params.put("videoIdList", videoIdList);
|
|
params.put("videoIdList", videoIdList);
|
|
String post = httpPoolClientDefault.post(POST_VIDEO_DETAIL_URL, params.toJSONString());
|
|
String post = httpPoolClientDefault.post(POST_VIDEO_DETAIL_URL, params.toJSONString());
|
|
JSONObject res = JSONObject.parseObject(post);
|
|
JSONObject res = JSONObject.parseObject(post);
|
|
JSONArray data = res.getJSONArray("data");
|
|
JSONArray data = res.getJSONArray("data");
|
|
- Map<Long, String> map = new HashMap<>();
|
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
|
+ VideoDetail videoDetail = new VideoDetail();
|
|
JSONObject jsonObject = data.getJSONObject(i);
|
|
JSONObject jsonObject = data.getJSONObject(i);
|
|
Long videoId = jsonObject.getLong("id");
|
|
Long videoId = jsonObject.getLong("id");
|
|
- JSONObject coverImg = jsonObject.getJSONObject("coverImg");
|
|
|
|
- String coverImgPath = coverImg.getString("coverImgPath");
|
|
|
|
- map.put(videoId, coverImgPath);
|
|
|
|
|
|
+ String shareImgPath = jsonObject.getString("shareImgPath");
|
|
|
|
+ String title = jsonObject.getString("title");
|
|
|
|
+ videoDetail.setCover(shareImgPath);
|
|
|
|
+ videoDetail.setTitle(title);
|
|
|
|
+ map.put(videoId, videoDetail);
|
|
}
|
|
}
|
|
return map;
|
|
return map;
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- throw new RuntimeException("获取封面异常");
|
|
|
|
|
|
+ throw new RuntimeException("获取详情异常");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getPage(String staffExtId, Long videoId) {
|
|
|
|
+ try {
|
|
|
|
+ StaffExtEnum staffExtEnum = StaffExtEnum.find(staffExtId);
|
|
|
|
+ if (staffExtEnum == null || videoId == null) {
|
|
|
|
+ //TODO 枚举里少数据 或者 video为空
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+ String carrierId = staffExtEnum.getCarrierId();
|
|
|
|
+ String page = selectPage(carrierId, videoId);
|
|
|
|
+ if (StringUtils.isNotEmpty(page)) {
|
|
|
|
+ return page;
|
|
|
|
+ }
|
|
|
|
+ return insertPage(carrierId, videoId, staffExtEnum.getRemark());
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String insertPage(String carrierId, Long videoId, String remark) throws IOException {
|
|
|
|
+ AdPutFlowParam param = new AdPutFlowParam();
|
|
|
|
+ param.setChannel("tencentqw");
|
|
|
|
+ param.setPath("pages/category");
|
|
|
|
+ param.setPutCarrierId(carrierId);
|
|
|
|
+ param.setPutScene("touliu");
|
|
|
|
+ param.setPutStartDate(DateUtil.getDayDateString("yyyy-MM-dd"));
|
|
|
|
+ param.setPutTypeOne("企微");
|
|
|
|
+ param.setPutTypeTwo("日常推送");
|
|
|
|
+ param.setPutTypeThree("位置X");
|
|
|
|
+ param.setRemark(remark);
|
|
|
|
+ param.setVideoId(videoId);
|
|
|
|
+ Map<String, String> requestParam = new HashMap<>();
|
|
|
|
+ String jumpPage = "pages/user-videos?id=${videoId}&fromGzh=1&rootShareId=${uuid}&shareId=${uuid}&rootSourceId=[rootSourceId]"
|
|
|
|
+ .replace("${videoId}", "" + videoId)
|
|
|
|
+ .replace("${uuid}", "" + UUID.randomUUID());
|
|
|
|
+ requestParam.put("jumpPage", jumpPage);
|
|
|
|
+ param.setRequestParam(requestParam);
|
|
|
|
+ String res = httpPoolClientDefault.post(POST_ADD_TENCENT, JSONObject.toJSONString(param));
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
|
+ return data.getString("url");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String selectPage(String carrierId, Long videoId) throws IOException {
|
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
|
+ String url = "https://api.piaoquantv.com/ad/put/flow/list/tencent?videoId=${videoId}&putScene=touliu&channel=tencentqw¤tPage=1&pageSize=20"
|
|
|
|
+ .replace("${videoId}", "" + videoId);
|
|
|
|
+ String res = httpPoolClientDefault.get(url);
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
|
+ JSONArray objs = data.getJSONArray("objs");
|
|
|
|
+ for (int i = 0; i < objs.size(); i++) {
|
|
|
|
+ JSONObject obj = objs.getJSONObject(i);
|
|
|
|
+ String putCarrierId = obj.getString("putCarrierId");
|
|
|
|
+ String page = obj.getString("url");
|
|
|
|
+ if (StringUtils.isEmpty(putCarrierId) || StringUtils.isEmpty(page)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ map.put(putCarrierId, page);
|
|
}
|
|
}
|
|
|
|
+ return map.get(carrierId);
|
|
}
|
|
}
|
|
}
|
|
}
|