|
|
@@ -152,102 +152,107 @@ public class ThirdPartyPushMessageStrategyV1 implements ReplyStrategyService {
|
|
|
if (CollectionUtils.isEmpty(smallDataCgiReplyList)) {
|
|
|
return;
|
|
|
}
|
|
|
- for (String key : keyedSet) {
|
|
|
- if ("base".equals(key)) {
|
|
|
- continue;
|
|
|
+ // 循环获取锁,锁5s,每获取一次锁,未获取到锁,等待1s,最多等待10次
|
|
|
+ int tryCount = 0;
|
|
|
+ String LOCK_KEY = "insertSmallData:" + bucketDataParam.getGhId();
|
|
|
+ while (tryCount < 10) {
|
|
|
+ if (redisUtils.tryLock(LOCK_KEY, "1", 5)) {
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("ThirdPartyPushMessageStrategyV1 insertSmallData 尝试获取锁失败,ghId:" + bucketDataParam.getGhId() + ",tryCount:" + tryCount, e);
|
|
|
+ }
|
|
|
+ tryCount++;
|
|
|
}
|
|
|
- List<Long> videoIds = new ArrayList<>();
|
|
|
- List<CgiReplyBucketData> collect = new ArrayList<>();
|
|
|
- for (CgiReplyBucketData data : smallDataCgiReplyList) {
|
|
|
- if (!data.getStrategy().equals(key)) {
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ for (String key : keyedSet) {
|
|
|
+ if ("base".equals(key)) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (!data.getGhId().equals(bucketDataParam.getGhId())) {
|
|
|
- continue;
|
|
|
+ List<Long> videoIds = new ArrayList<>();
|
|
|
+ List<CgiReplyBucketData> collect = new ArrayList<>();
|
|
|
+ for (CgiReplyBucketData data : smallDataCgiReplyList) {
|
|
|
+ if (!data.getStrategy().equals(key)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!data.getGhId().equals(bucketDataParam.getGhId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (videoIds.contains(data.getMiniVideoId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ videoIds.add(data.getMiniVideoId());
|
|
|
+ collect.add(data);
|
|
|
}
|
|
|
- if (videoIds.contains(data.getMiniVideoId())) {
|
|
|
+ if (CollectionUtils.isEmpty(collect)) {
|
|
|
+ log.error("ThirdPartyPushMessageStrategyV1 insertSmallData 算法排序数据异常 ,key:" + key +
|
|
|
+ ",data:" + JSON.toJSONString(smallDataCgiReplyList) + ",ghId:" + bucketDataParam.getGhId());
|
|
|
continue;
|
|
|
}
|
|
|
- videoIds.add(data.getMiniVideoId());
|
|
|
- collect.add(data);
|
|
|
- }
|
|
|
- if (CollectionUtils.isEmpty(collect)) {
|
|
|
- log.error("ThirdPartyPushMessageStrategyV1 insertSmallData 算法排序数据异常 ,key:" + key +
|
|
|
- ",data:" + JSON.toJSONString(smallDataCgiReplyList) + ",ghId:" + bucketDataParam.getGhId());
|
|
|
- continue;
|
|
|
- }
|
|
|
- CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
|
|
|
- cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andMsgTypeEqualTo(1).andStrategyEqualTo(key).andGhIdEqualTo(bucketDataParam.getGhId());
|
|
|
- List<CgiReplyBucketData> cgiReplyBucketData1 = cgiReplyBucketDataMapper.selectByExample(cgiReplyBucketDataExample);
|
|
|
- Map<Long, CgiReplyBucketData> cgiReplyBucketDataMap = cgiReplyBucketData1.stream()
|
|
|
- .collect(Collectors.toMap(CgiReplyBucketData::getMiniVideoId, x -> x, (a, b) -> b));
|
|
|
- // 清上个版本的策略数据
|
|
|
- cgiReplyBucketDataMapperExt.updateDeleteStatus(bucketDataParam.getGhId(), key, 1, 1);
|
|
|
- List<ContentPlatformGzhPlanVideo> gzhPlanVideoList = contentPlatformPlanService.getGzhPlanVideoListByCooperateAccountId(bucketDataParam.getGhId());
|
|
|
- Map<Long, ContentPlatformGzhPlanVideo> gzhPlanVideoMap = gzhPlanVideoList.stream()
|
|
|
- .collect(Collectors.toMap(ContentPlatformGzhPlanVideo::getVideoId, x -> x, (a, b) -> b));
|
|
|
- // 入库
|
|
|
- for (CgiReplyBucketData cgiReplyBucketData : collect) {
|
|
|
- if (Objects.isNull(cgiReplyBucketData.getMiniVideoId())) {
|
|
|
- Long videoId = MessageUtil.getVideoId(cgiReplyBucketData.getMiniPagePath());
|
|
|
- cgiReplyBucketData.setMiniVideoId(videoId);
|
|
|
- }
|
|
|
- CgiReplyBucketData oldData = cgiReplyBucketDataMap.get(cgiReplyBucketData.getMiniVideoId());
|
|
|
- if (Objects.isNull(oldData)) {
|
|
|
- oldData = cgiReplyBucketDataMapperExt.getOldCgiReplyData(cgiReplyBucketData.getMiniVideoId());
|
|
|
- }
|
|
|
- if (Objects.nonNull(oldData)) {
|
|
|
- if (StringUtils.isEmpty(cgiReplyBucketData.getTitle())) {
|
|
|
- cgiReplyBucketData.setTitle(oldData.getTitle());
|
|
|
+ CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
|
|
|
+ cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andMsgTypeEqualTo(1).andStrategyEqualTo(key).andGhIdEqualTo(bucketDataParam.getGhId());
|
|
|
+ List<CgiReplyBucketData> cgiReplyBucketData1 = cgiReplyBucketDataMapper.selectByExample(cgiReplyBucketDataExample);
|
|
|
+ Map<Long, CgiReplyBucketData> cgiReplyBucketDataMap = cgiReplyBucketData1.stream()
|
|
|
+ .collect(Collectors.toMap(CgiReplyBucketData::getMiniVideoId, x -> x, (a, b) -> b));
|
|
|
+ // 清上个版本的策略数据
|
|
|
+ cgiReplyBucketDataMapperExt.updateDeleteStatus(bucketDataParam.getGhId(), key, 1, 1);
|
|
|
+ List<ContentPlatformGzhPlanVideo> gzhPlanVideoList = contentPlatformPlanService.getGzhPlanVideoListByCooperateAccountId(bucketDataParam.getGhId());
|
|
|
+ Map<Long, ContentPlatformGzhPlanVideo> gzhPlanVideoMap = gzhPlanVideoList.stream()
|
|
|
+ .collect(Collectors.toMap(ContentPlatformGzhPlanVideo::getVideoId, x -> x, (a, b) -> b));
|
|
|
+ // 入库
|
|
|
+ for (CgiReplyBucketData cgiReplyBucketData : collect) {
|
|
|
+ if (Objects.isNull(cgiReplyBucketData.getMiniVideoId())) {
|
|
|
+ Long videoId = MessageUtil.getVideoId(cgiReplyBucketData.getMiniPagePath());
|
|
|
+ cgiReplyBucketData.setMiniVideoId(videoId);
|
|
|
}
|
|
|
- if (StringUtils.isEmpty(cgiReplyBucketData.getCoverUrl())) {
|
|
|
- cgiReplyBucketData.setCoverUrl(oldData.getCoverUrl());
|
|
|
+ CgiReplyBucketData oldData = cgiReplyBucketDataMap.get(cgiReplyBucketData.getMiniVideoId());
|
|
|
+ if (Objects.isNull(oldData)) {
|
|
|
+ oldData = cgiReplyBucketDataMapperExt.getOldCgiReplyData(cgiReplyBucketData.getMiniVideoId());
|
|
|
}
|
|
|
- }
|
|
|
- ContentPlatformGzhPlanVideo gzhPlanVideo = gzhPlanVideoMap.get(cgiReplyBucketData.getMiniVideoId());
|
|
|
- String pageUrl = cgiReplyBucketData.getMiniPagePath();
|
|
|
- if (Objects.nonNull(gzhPlanVideo)) {
|
|
|
- try {
|
|
|
- //if (!pageUrl.contains("shareTitle")) {
|
|
|
- // if (StringUtils.isNotBlank(gzhPlanVideo.getCustomTitle())) {
|
|
|
- // pageUrl += URLEncoder.encode("&shareTitle=" + gzhPlanVideo.getCustomTitle(), "UTF-8");
|
|
|
- // } else {
|
|
|
- // pageUrl += URLEncoder.encode("&shareTitle=" + gzhPlanVideo.getTitle(), "UTF-8");
|
|
|
- // }
|
|
|
- //}
|
|
|
- if (Objects.nonNull(gzhPlanVideo.getCustomTitleId()) && !pageUrl.contains("shareTitleId")) {
|
|
|
- pageUrl += URLEncoder.encode("&shareTitleId=" + gzhPlanVideo.getCustomTitleId(), "UTF-8");
|
|
|
+ if (Objects.nonNull(oldData)) {
|
|
|
+ if (StringUtils.isEmpty(cgiReplyBucketData.getTitle())) {
|
|
|
+ cgiReplyBucketData.setTitle(oldData.getTitle());
|
|
|
}
|
|
|
- if (Objects.nonNull(gzhPlanVideo.getCustomCoverId()) && !pageUrl.contains("shareImageId")) {
|
|
|
- pageUrl += URLEncoder.encode("&shareImageId=" + gzhPlanVideo.getCustomCoverId(), "UTF-8");
|
|
|
+ if (StringUtils.isEmpty(cgiReplyBucketData.getCoverUrl())) {
|
|
|
+ cgiReplyBucketData.setCoverUrl(oldData.getCoverUrl());
|
|
|
}
|
|
|
- //if (!pageUrl.contains("shareImageUrl")) {
|
|
|
- // if (StringUtils.isNotEmpty(gzhPlanVideo.getCustomCover())) {
|
|
|
- // pageUrl += URLEncoder.encode("&shareImageUrl=" + URLEncoder.encode(gzhPlanVideo.getCustomCover(), "UTF-8"), "UTF-8");
|
|
|
- // } else {
|
|
|
- // pageUrl += URLEncoder.encode("&shareImageUrl=" + URLEncoder.encode(gzhPlanVideo.getCover(), "UTF-8"), "UTF-8");
|
|
|
- // }
|
|
|
- //}
|
|
|
+ }
|
|
|
+ ContentPlatformGzhPlanVideo gzhPlanVideo = gzhPlanVideoMap.get(cgiReplyBucketData.getMiniVideoId());
|
|
|
+ String pageUrl = cgiReplyBucketData.getMiniPagePath();
|
|
|
+ if (Objects.nonNull(gzhPlanVideo)) {
|
|
|
+ try {
|
|
|
+ if (Objects.nonNull(gzhPlanVideo.getCustomTitleId()) && !pageUrl.contains("shareTitleId")) {
|
|
|
+ pageUrl += URLEncoder.encode("&shareTitleId=" + gzhPlanVideo.getCustomTitleId(), "UTF-8");
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(gzhPlanVideo.getCustomCoverId()) && !pageUrl.contains("shareImageId")) {
|
|
|
+ pageUrl += URLEncoder.encode("&shareImageId=" + gzhPlanVideo.getCustomCoverId(), "UTF-8");
|
|
|
+ }
|
|
|
+ cgiReplyBucketData.setMiniPagePath(pageUrl);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("ThirdPartyPushMessageStrategyV1 insertSmallData setCustomerCoverTitleId Error,data:" + JSON.toJSONString(gzhPlanVideo), e);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ pageUrl = videoMultiService.setVideoMultiTitleCoverPagePath(cgiReplyBucketData.getMiniVideoId(),
|
|
|
+ pageUrl, cgiReplyBucketData.getTitle(), cgiReplyBucketData.getCoverUrl());
|
|
|
cgiReplyBucketData.setMiniPagePath(pageUrl);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("ThirdPartyPushMessageStrategyV1 insertSmallData setCustomerCoverTitleId Error,data:" + JSON.toJSONString(gzhPlanVideo), e);
|
|
|
}
|
|
|
- } else {
|
|
|
- pageUrl = videoMultiService.setVideoMultiTitleCoverPagePath(cgiReplyBucketData.getMiniVideoId(),
|
|
|
- pageUrl, cgiReplyBucketData.getTitle(), cgiReplyBucketData.getCoverUrl());
|
|
|
- cgiReplyBucketData.setMiniPagePath(pageUrl);
|
|
|
+ cgiReplyBucketData.setRootSourceId(MessageUtil.getRootSourceId(cgiReplyBucketData.getMiniPagePath()));
|
|
|
+ cgiReplyBucketDataMapper.insertSelective(cgiReplyBucketData);
|
|
|
+ String redisKey = "auto_reply_video_detail_" + cgiReplyBucketData.getRootSourceId();
|
|
|
+ VideoCharacteristicVO vo = new VideoCharacteristicVO();
|
|
|
+ vo.setGhId(cgiReplyBucketData.getGhId());
|
|
|
+ vo.setName(bucketDataParam.getAccountName());
|
|
|
+ vo.setVideoId(cgiReplyBucketData.getMiniVideoId());
|
|
|
+ vo.setTitle(cgiReplyBucketData.getTitle());
|
|
|
+ vo.setCover(cgiReplyBucketData.getCoverUrl());
|
|
|
+ redisUtils.set(redisKey, JSONObject.toJSONString(vo), 3L * 24 * 60 * 60);
|
|
|
}
|
|
|
- cgiReplyBucketData.setRootSourceId(MessageUtil.getRootSourceId(cgiReplyBucketData.getMiniPagePath()));
|
|
|
- cgiReplyBucketDataMapper.insertSelective(cgiReplyBucketData);
|
|
|
- String redisKey = "auto_reply_video_detail_" + cgiReplyBucketData.getRootSourceId();
|
|
|
- VideoCharacteristicVO vo = new VideoCharacteristicVO();
|
|
|
- vo.setGhId(cgiReplyBucketData.getGhId());
|
|
|
- vo.setName(bucketDataParam.getAccountName());
|
|
|
- vo.setVideoId(cgiReplyBucketData.getMiniVideoId());
|
|
|
- vo.setTitle(cgiReplyBucketData.getTitle());
|
|
|
- vo.setCover(cgiReplyBucketData.getCoverUrl());
|
|
|
- redisUtils.set(redisKey, JSONObject.toJSONString(vo), 3L * 24 * 60 * 60);
|
|
|
}
|
|
|
+ } finally {
|
|
|
+ redisUtils.del(LOCK_KEY);
|
|
|
}
|
|
|
}
|
|
|
|