|
@@ -1,10 +1,12 @@
|
|
|
package com.tzld.piaoquan.longarticle.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.tzld.piaoquan.longarticle.common.enums.PublishGzhPushTypeEnum;
|
|
|
import com.tzld.piaoquan.longarticle.dao.mapper.PlanAccountMapper;
|
|
|
import com.tzld.piaoquan.longarticle.dao.mapper.PublishContentMapper;
|
|
|
import com.tzld.piaoquan.longarticle.dao.mapper.PublishMiniprogramMapper;
|
|
|
+import com.tzld.piaoquan.longarticle.dao.mapper.RootSourceMapper;
|
|
|
import com.tzld.piaoquan.longarticle.model.dto.*;
|
|
|
import com.tzld.piaoquan.longarticle.model.bo.*;
|
|
|
import com.tzld.piaoquan.longarticle.model.po.*;
|
|
@@ -61,6 +63,9 @@ public class CoreServiceImpl implements CoreService {
|
|
|
@Autowired
|
|
|
private PublishContentMapper publishContentMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RootSourceMapper rootSourceMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public void initPlanAccount() {
|
|
|
List<LongArticleSystemPlan> allLongArticleSystemPlans = planService.getAllLongArticleSystemPlan();
|
|
@@ -204,12 +209,13 @@ public class CoreServiceImpl implements CoreService {
|
|
|
}
|
|
|
|
|
|
private boolean checkPlanAccount(PlanAccount planAccount) {
|
|
|
-
|
|
|
+ boolean flag = true;
|
|
|
// 固定日期
|
|
|
if (planAccount.getPublishRate() == 1) {
|
|
|
List<Integer> weeks = JSON.parseArray(planAccount.getPublishDate(), Integer.class);
|
|
|
if (!weeks.contains(TimeZoneUtil.getTodayDayOfWeek(TimeZoneUtil.Timezone.china))) {
|
|
|
- //TODO 更新状态
|
|
|
+ planAccount.setStatus(2);
|
|
|
+ planAccountMapper.updateByPrimaryKeySelective(planAccount);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -227,38 +233,39 @@ public class CoreServiceImpl implements CoreService {
|
|
|
&& StringUtils.isNotEmpty(planAccount.getPublishWindowEnd())) {
|
|
|
if (!effectiveTime(planAccount.getPublishWindowStart(), planAccount.getPublishWindowEnd(),
|
|
|
TimeZoneUtil.Timezone.china)) {
|
|
|
- log.info("当前时间不在发布时间窗口内,不需要发布,planId:{}", planAccount.getPlanId());
|
|
|
return false;
|
|
|
}
|
|
|
- // TODO 找到该账号最近发布的内容,判断时间间隔
|
|
|
-// Long lastPushContentTimestamp = getAccountLatestPushTimestamp(plan.getId(), publishAccount.getId());
|
|
|
-// if (Objects.nonNull(lastPushContentTimestamp) && Objects.nonNull(planSetting.getPublishTimeInterval())
|
|
|
-// && (System.currentTimeMillis() - lastPushContentTimestamp) < planSetting.getPublishTimeInterval() * 60 * 1000L) {
|
|
|
-// log.info("距离上次发布的时间过短,planId:{},accountId:{},lastPushContentTimestamp:{}", plan.getId(),
|
|
|
-// publishAccount.getId(), lastPushContentTimestamp);
|
|
|
-// return;
|
|
|
-// }
|
|
|
+ if (planAccount.getPublishTimeInterval() != null) {
|
|
|
+ // 找到该账号最近发布的内容,判断时间间隔
|
|
|
+ PublishContentExample example = new PublishContentExample();
|
|
|
+ example.createCriteria().andStatusIn(Arrays.asList(1, 2)).andCreateTimeGreaterThan(DateUtil.getThatDayDate());
|
|
|
+ example.setOrderByClause("create_time desc");
|
|
|
+ List<PublishContent> publishContents = publishContentMapper.selectByExample(example);
|
|
|
+ if (!CollectionUtils.isEmpty(publishContents)) {
|
|
|
+ long time = System.currentTimeMillis() - publishContents.get(0).getCreateTime().getTime();
|
|
|
+ if (time < planAccount.getPublishTimeInterval() * 60 * 1000L) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ PublishContentExample example = new PublishContentExample();
|
|
|
+ example.createCriteria().andStatusIn(Arrays.asList(1, 2)).andCreateTimeGreaterThan(DateUtil.getThatDayDate());
|
|
|
+ long sendCount = publishContentMapper.countByExample(example);
|
|
|
Integer publishNum = planAccount.getPublishNum();
|
|
|
if (publishNum == null || publishNum == 0) {
|
|
|
return false;
|
|
|
}
|
|
|
- Integer sendCount = planAccount.getSendCount();
|
|
|
- if (sendCount == null) {
|
|
|
- sendCount = 0;
|
|
|
- }
|
|
|
- int needSentCount = sendCount - publishNum;
|
|
|
-
|
|
|
-
|
|
|
- if (needSentCount >= 0) {
|
|
|
- //TODO 修改状态
|
|
|
+ if (sendCount >= publishNum) {
|
|
|
return false;
|
|
|
}
|
|
|
- if (planAccount.getRetryCount() > 3) {
|
|
|
+ if (planAccount.getRetryCount() >= 3) {
|
|
|
+ planAccount.setStatus(3);
|
|
|
+ planAccountMapper.updateByPrimaryKeySelective(planAccount);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- return true;
|
|
|
+ return flag;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -279,35 +286,43 @@ public class CoreServiceImpl implements CoreService {
|
|
|
articleSortRequest.setStrategy("ArticleRankRandom");
|
|
|
//articleSortRequest.setStrategy(planAccount.getSortStrategy());
|
|
|
if (Objects.equals(planAccount.getPushType(), PublishGzhPushTypeEnum.manual_push.getVal())) {
|
|
|
- if (planAccount.getPublishPreNum() >= (planAccount.getPublishNum() - planAccount.getSendCount())) {
|
|
|
+ PublishContentExample publishContentExample = new PublishContentExample();
|
|
|
+ publishContentExample.createCriteria().andStatusIn(Arrays.asList(1, 2)).andCreateTimeGreaterThan(DateUtil.getThatDayDate());
|
|
|
+ long sendCount = publishContentMapper.countByExample(publishContentExample);
|
|
|
+ if (planAccount.getPublishPreNum() <= (planAccount.getPublishNum() - sendCount)) {
|
|
|
articleSortRequest.setPublishNum(planAccount.getPublishPreNum());
|
|
|
} else {
|
|
|
- articleSortRequest.setPublishNum(planAccount.getPublishNum() - planAccount.getSendCount());
|
|
|
+ articleSortRequest.setPublishNum((int) (planAccount.getPublishNum() - sendCount));
|
|
|
}
|
|
|
}
|
|
|
- articleSortRequest.setPublishNum(planAccount.getPublishNum());
|
|
|
+ if (Objects.equals(PublishGzhPushTypeEnum.auto_group_publish.getVal(), planAccount.getPushType())) {
|
|
|
+ articleSortRequest.setPublishNum(planAccount.getPublishNum());
|
|
|
+ }
|
|
|
articleSortRequest.setPlanId(planAccount.getPlanId());
|
|
|
articleSortRequest.setPushType(planAccount.getPushType());
|
|
|
|
|
|
ArticleSortResponse articleSortResponse = sortService.publishArticleSort(articleSortRequest);
|
|
|
- if (articleSortResponse == null
|
|
|
- || articleSortResponse.getData() == null
|
|
|
- || CollectionUtils.isEmpty(articleSortResponse.getData().getRank_list())) {
|
|
|
+ if (articleSortResponse == null || articleSortResponse.getData() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(articleSortResponse.getData().getRank_list())) {
|
|
|
+ planAccount.setRetryCount(planAccount.getRetryCount() + 1);
|
|
|
+ planAccountMapper.updateByPrimaryKeySelective(planAccount);
|
|
|
continue;
|
|
|
}
|
|
|
ArticleSortResponseData data = articleSortResponse.getData();
|
|
|
-// if (!CollectionUtils.isEmpty(data.getFilter_list())) {
|
|
|
-// List<FilterSortContentParam> list = new ArrayList<>();
|
|
|
-// for (PublishArticleData publishArticleData : data.getFilter_list()) {
|
|
|
-// FilterSortContentParam param = new FilterSortContentParam();
|
|
|
-// param.setFilterReason(publishArticleData.getFilterReason());
|
|
|
-// param.setPublishContentId(publishArticleData.getId());
|
|
|
-// list.add(param);
|
|
|
-// }
|
|
|
-// FilterSortParam param = new FilterSortParam();
|
|
|
-// param.setFilterSortContentList(list);
|
|
|
-// planService.filterSortContents(param);
|
|
|
-// }
|
|
|
+ if (!CollectionUtils.isEmpty(data.getFilter_list())) {
|
|
|
+ List<FilterSortContentParam> list = new ArrayList<>();
|
|
|
+ for (PublishArticleData publishArticleData : data.getFilter_list()) {
|
|
|
+ FilterSortContentParam param = new FilterSortContentParam();
|
|
|
+ param.setFilterReason(publishArticleData.getFilterReason());
|
|
|
+ param.setPublishContentId(publishArticleData.getId());
|
|
|
+ list.add(param);
|
|
|
+ }
|
|
|
+ FilterSortParam param = new FilterSortParam();
|
|
|
+ param.setFilterSortContentList(list);
|
|
|
+ planService.filterSortContents(param);
|
|
|
+ }
|
|
|
List<LongArticleSystemPushContentParam> pushContentList = new ArrayList<>();
|
|
|
//排序结束
|
|
|
List<PublishArticleData> rankList = data.getRank_list();
|
|
@@ -321,8 +336,8 @@ public class CoreServiceImpl implements CoreService {
|
|
|
publishContent.setSourceId(publishArticleData.getSourceId());
|
|
|
publishContent.setScore(publishArticleData.getScore());
|
|
|
publishContent.setContentPoolType(publishArticleData.getContentPoolType());
|
|
|
- long contentId = publishContentMapper.insertSelective(publishContent);
|
|
|
- sendIds.add(contentId);
|
|
|
+ publishContentMapper.insertSelective(publishContent);
|
|
|
+ sendIds.add(publishContent.getId());
|
|
|
//获取小程序
|
|
|
List<CrawlerVideo> contentVideos =
|
|
|
contentService.getContentVideo(publishArticleData.getSourceId(), publishArticleData.getContentPoolType(), planAccount.getGhId());
|
|
@@ -352,6 +367,12 @@ public class CoreServiceImpl implements CoreService {
|
|
|
statusParam.setPublishContentId(publishContentId);
|
|
|
statusParam.setErrorMsg("小程序视频数量不足");
|
|
|
planService.updateMatchMiniprogramStatus(statusParam);
|
|
|
+
|
|
|
+ PublishContent update = new PublishContent();
|
|
|
+ update.setId(publishContent.getId());
|
|
|
+ update.setStatus(3);
|
|
|
+ update.setReason("小程序数量不足");
|
|
|
+ publishContentMapper.updateByPrimaryKeySelective(update);
|
|
|
continue;
|
|
|
}
|
|
|
String ghId = planAccount.getGhId();
|
|
@@ -392,14 +413,31 @@ public class CoreServiceImpl implements CoreService {
|
|
|
}
|
|
|
param.setTraceId(publishMiniprogram.getTraceId());
|
|
|
publishCardList.add(param);
|
|
|
- publishMiniprogram.setContentId(contentId);
|
|
|
+ publishMiniprogram.setContentId(publishContent.getId());
|
|
|
+ RootSource rootSource = new RootSource();
|
|
|
+ rootSource.setAccountName(planAccount.getAccountName());
|
|
|
+ rootSource.setRootSourceId(publishMiniprogram.getRootSourceId());
|
|
|
+ rootSource.setGhId(planAccount.getGhId());
|
|
|
+ rootSource.setRequestTime(Integer.valueOf(String.valueOf(System.currentTimeMillis() / 1000)));
|
|
|
+ rootSource.setTraceId(publishMiniprogram.getTraceId());
|
|
|
+ rootSource.setPushType(planAccount.getPushType());
|
|
|
+ rootSource.setVideoId(publishMiniprogram.getVideoId());
|
|
|
+ rootSource.setContentId(publishArticleData.getSourceId());
|
|
|
+ rootSourceMapper.insertSelective(rootSource);
|
|
|
publishMiniprogramMapper.insertSelective(publishMiniprogram);
|
|
|
}
|
|
|
|
|
|
if (publishCardList.size() < 2) {
|
|
|
+ MatchMiniprogramStatusParam statusParam = new MatchMiniprogramStatusParam();
|
|
|
+ statusParam.setStatus(3);
|
|
|
+ statusParam.setPublishContentId(publishContentId);
|
|
|
+ statusParam.setErrorMsg("小程序视频数量不足");
|
|
|
+ planService.updateMatchMiniprogramStatus(statusParam);
|
|
|
+
|
|
|
PublishContent update = new PublishContent();
|
|
|
- update.setId(contentId);
|
|
|
+ update.setId(publishContent.getId());
|
|
|
update.setStatus(3);
|
|
|
+ update.setReason("小程序数量不足");
|
|
|
publishContentMapper.updateByPrimaryKeySelective(update);
|
|
|
continue;
|
|
|
}
|
|
@@ -419,19 +457,24 @@ public class CoreServiceImpl implements CoreService {
|
|
|
gzhPushParam.setPushScheduleTimestamp(System.currentTimeMillis());
|
|
|
}
|
|
|
gzhPushParam.setPushContentList(pushContentList);
|
|
|
- if (pushContentList.size() < planAccount.getPublishPreMinNum()) {
|
|
|
+ if (Objects.equals(planAccount.getPushType(), PublishGzhPushTypeEnum.auto_group_publish.getVal())
|
|
|
+ && pushContentList.size() < planAccount.getPublishPreMinNum()) {
|
|
|
continue;
|
|
|
}
|
|
|
String pushId = planService.createPushTask(gzhPushParam);
|
|
|
+ System.out.println(pushId);
|
|
|
if (StringUtils.isNotEmpty(pushId)) {
|
|
|
- //更新状态 发布完成
|
|
|
- PublishContent update = new PublishContent();
|
|
|
- //发布成功
|
|
|
- update.setStatus(1);
|
|
|
- update.setPushId(pushId);
|
|
|
- PublishContentExample updateExample = new PublishContentExample();
|
|
|
- updateExample.createCriteria().andStatusEqualTo(0).andIdIn(sendIds);
|
|
|
- publishContentMapper.updateByExample(update, updateExample);
|
|
|
+ for (Long id : sendIds) {
|
|
|
+ PublishContent publishContent = publishContentMapper.selectByPrimaryKey(id);
|
|
|
+ if (publishContent == null || publishContent.getStatus() != 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ PublishContent update = new PublishContent();
|
|
|
+ update.setId(id);
|
|
|
+ update.setPushId(pushId);
|
|
|
+ update.setStatus(1);
|
|
|
+ publishContentMapper.updateByPrimaryKeySelective(update);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -467,11 +510,30 @@ public class CoreServiceImpl implements CoreService {
|
|
|
}
|
|
|
//更新状态 2成功 3失败
|
|
|
if (updateStatus != 0) {
|
|
|
- PublishContentExample updateExample = new PublishContentExample();
|
|
|
- updateExample.createCriteria().andPushIdEqualTo(pushId);
|
|
|
+ PublishContentExample publishContentExample = new PublishContentExample();
|
|
|
+ publishContentExample.createCriteria().andPushIdEqualTo(pushId);
|
|
|
PublishContent update = new PublishContent();
|
|
|
update.setStatus(updateStatus);
|
|
|
- publishContentMapper.updateByExample(update, updateExample);
|
|
|
+ publishContentMapper.updateByExampleSelective(update, publishContentExample);
|
|
|
+
|
|
|
+ List<PublishContent> publishContentList = publishContentMapper.selectByExample(publishContentExample);
|
|
|
+ if (!CollectionUtils.isEmpty(publishContentList)) {
|
|
|
+ Long planAccountId = publishContentList.get(0).getPlanAccountId();
|
|
|
+ if (planAccountId == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ PlanAccount planAccount = planAccountMapper.selectByPrimaryKey(planAccountId);
|
|
|
+ if (Objects.equals(planAccount.getPushType(), PublishGzhPushTypeEnum.auto_group_publish.getVal())) {
|
|
|
+ if (updateStatus == 2) {
|
|
|
+ planAccount.setStatus(2);
|
|
|
+ planAccountMapper.updateByPrimaryKeySelective(planAccount);
|
|
|
+ }
|
|
|
+ if (updateStatus == 3) {
|
|
|
+ planAccount.setRetryCount(planAccount.getRetryCount() + 1);
|
|
|
+ planAccountMapper.updateByPrimaryKeySelective(planAccount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|