|
@@ -1,15 +1,18 @@
|
|
|
package com.tzld.piaoquan.api.service.contentplatform.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
|
|
|
import com.tzld.piaoquan.api.common.enums.contentplatform.PublishStageEnum;
|
|
|
import com.tzld.piaoquan.api.common.enums.contentplatform.QwPlanTypeEnum;
|
|
|
import com.tzld.piaoquan.api.common.exception.CommonException;
|
|
|
+import com.tzld.piaoquan.api.component.AdApiService;
|
|
|
import com.tzld.piaoquan.api.component.AigcApiService;
|
|
|
import com.tzld.piaoquan.api.component.ManagerApiService;
|
|
|
import com.tzld.piaoquan.api.component.VlogApiService;
|
|
|
import com.tzld.piaoquan.api.dao.mapper.contentplatform.*;
|
|
|
import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformPlanMapperExt;
|
|
|
+import com.tzld.piaoquan.api.model.bo.AdPutFlowRecordTencent;
|
|
|
import com.tzld.piaoquan.api.model.config.LoginUserContext;
|
|
|
import com.tzld.piaoquan.api.model.param.contentplatform.*;
|
|
|
import com.tzld.piaoquan.api.model.po.contentplatform.*;
|
|
@@ -19,6 +22,7 @@ import com.tzld.piaoquan.api.model.vo.contentplatform.GzhPlanVideoContentItemVO;
|
|
|
import com.tzld.piaoquan.api.model.vo.contentplatform.QwPlanItemVO;
|
|
|
import com.tzld.piaoquan.api.model.vo.contentplatform.VideoContentItemVO;
|
|
|
import com.tzld.piaoquan.api.service.GhDetailService;
|
|
|
+import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformAccountService;
|
|
|
import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformCooperateAccountService;
|
|
|
import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformPlanService;
|
|
|
import com.tzld.piaoquan.growth.common.common.enums.GhTypeEnum;
|
|
@@ -76,6 +80,10 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
|
|
|
private MessageAttachmentService messageAttachmentService;
|
|
|
@Autowired
|
|
|
private VlogApiService vlogApiService;
|
|
|
+ @Autowired
|
|
|
+ private ContentPlatformAccountService accountService;
|
|
|
+ @Autowired
|
|
|
+ private AdApiService adApiService;
|
|
|
|
|
|
@Value("${vlog.share.appType:11}")
|
|
|
private String shareAppType;
|
|
@@ -187,6 +195,12 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
|
|
|
throw new CommonException(ExceptionEnum.GZH_PLAN_VIDEO_SIZE_EXCEED);
|
|
|
}
|
|
|
ContentPlatformGzhAccount account = cooperateAccountService.getById(param.getAccountId());
|
|
|
+ if (Objects.isNull(account)) {
|
|
|
+ throw new CommonException(ExceptionEnum.GZH_ACCOUNT_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(account.getExternalId()) && param.getPublishStage().equals(PublishStageEnum.PLATFORM.getVal())) {
|
|
|
+ throw new CommonException(ExceptionEnum.GZH_ACCOUNT_NOT_AUTH);
|
|
|
+ }
|
|
|
Long now = System.currentTimeMillis();
|
|
|
ContentPlatformGzhPlan gzhPlan = new ContentPlatformGzhPlan();
|
|
|
gzhPlan.setAccountId(param.getAccountId());
|
|
@@ -201,7 +215,7 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
|
|
|
if (Objects.isNull(param.getId())) {
|
|
|
// 调用aigc创建发布计划
|
|
|
if (PublishStageEnum.PLATFORM.getVal() == param.getPublishStage()) {
|
|
|
- String externalId = aigcApiService.createPublishPlan(account.getExternalId(), account.getName());
|
|
|
+ String externalId = aigcApiService.createPublishPlan(account.getExternalId(), account.getName(), loginAccount.getChannel());
|
|
|
gzhPlan.setExternalId(externalId);
|
|
|
}
|
|
|
gzhPlan.setCreateAccountId(loginAccount.getId());
|
|
@@ -217,7 +231,7 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
|
|
|
if (StringUtils.hasText(oldPlan.getExternalId())) {
|
|
|
aigcApiService.changePublishPlanStatus(oldPlan.getExternalId(), 1);
|
|
|
} else {
|
|
|
- String externalId = aigcApiService.createPublishPlan(account.getExternalId(), account.getName());
|
|
|
+ String externalId = aigcApiService.createPublishPlan(account.getExternalId(), account.getName(), loginAccount.getChannel());
|
|
|
gzhPlan.setExternalId(externalId);
|
|
|
}
|
|
|
}
|
|
@@ -322,6 +336,13 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
|
|
|
return gzhPlanMapper.selectByExample(example);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<ContentPlatformGzhPlan> getGzhPlanListByCreateAccountId(Long createAccountId) {
|
|
|
+ ContentPlatformGzhPlanExample example = new ContentPlatformGzhPlanExample();
|
|
|
+ example.createCriteria().andCreateAccountIdEqualTo(createAccountId).andStatusEqualTo(1);
|
|
|
+ return gzhPlanMapper.selectByExample(example);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<ContentPlatformGzhPlan> getGzhPlanListByCooperateAccountIds(List<Long> accountIds) {
|
|
|
ContentPlatformGzhPlanExample example = new ContentPlatformGzhPlanExample();
|
|
@@ -502,4 +523,121 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
|
|
|
return qwPlanVideoMapper.selectByExample(example);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void gzhPlanImport(List<String> channels) {
|
|
|
+ List<ContentPlatformAccount> accountList = accountService.getAccountListByChannels(channels);
|
|
|
+ for (ContentPlatformAccount account : accountList) {
|
|
|
+ Long now = System.currentTimeMillis();
|
|
|
+ List<GhDetail> ghDetailList = ghDetailService.getByChannel(account.getChannel());
|
|
|
+ ghDetailList = ghDetailList.stream()
|
|
|
+ .filter(o -> Objects.equals(o.getStrategyStatus(), StrategyStatusEnum.DEFAULT.status))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(ghDetailList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<String> ghIds = ghDetailList.stream().map(GhDetail::getGhId).collect(Collectors.toList());
|
|
|
+ List<ContentPlatformGzhAccount> gzhAccountList = cooperateAccountService.getCooperateAccountListByGhIds(account.getId(), ghIds);
|
|
|
+ List<ContentPlatformGzhPlan> existsPlanList = getGzhPlanListByCreateAccountId(account.getId());
|
|
|
+ List<Long> existsAccountIds = existsPlanList.stream().map(ContentPlatformGzhPlan::getAccountId).collect(Collectors.toList());
|
|
|
+ Map<String, ContentPlatformGzhAccount> gzhAccountMap = gzhAccountList.stream()
|
|
|
+ .collect(Collectors.toMap(ContentPlatformGzhAccount::getGhId, Function.identity()));
|
|
|
+ for (GhDetail ghDetail : ghDetailList) {
|
|
|
+ ContentPlatformGzhAccount gzhAccount = gzhAccountMap.get(ghDetail.getGhId());
|
|
|
+ ContentPlatformGzhPlan gzhPlan = new ContentPlatformGzhPlan();
|
|
|
+ if (existsAccountIds.contains(gzhAccount.getId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ gzhPlan.setAccountId(gzhAccount.getId());
|
|
|
+ gzhPlan.setScene(0);
|
|
|
+ gzhPlan.setPublishStage(PublishStageEnum.USER.getVal());
|
|
|
+ if (StringUtils.hasText(gzhAccount.getExternalId())) {
|
|
|
+ aigcApiService.closeAccountMessagePublishPlan(gzhAccount.getExternalId());
|
|
|
+ gzhPlan.setPublishStage(PublishStageEnum.PLATFORM.getVal());
|
|
|
+ String externalId = aigcApiService.createPublishPlan(gzhAccount.getExternalId(), gzhAccount.getName(), account.getChannel());
|
|
|
+ gzhPlan.setExternalId(externalId);
|
|
|
+ }
|
|
|
+ gzhPlan.setCreateAccountId(account.getId());
|
|
|
+ gzhPlan.setCreateTimestamp(now);
|
|
|
+ gzhPlan.setUpdateTimestamp(now);
|
|
|
+ planMapperExt.insertGzhPlanReturnId(gzhPlan);
|
|
|
+ List<Long> videoIds = JSONObject.parseArray(ghDetail.getVideoIds(), Long.class);
|
|
|
+ Map<Long, VideoDetail> videoMap = messageAttachmentService.getVideoDetail(new HashSet<>(videoIds));
|
|
|
+ for (Map.Entry<Long, VideoDetail> entry : videoMap.entrySet()) {
|
|
|
+ Long videoId = entry.getKey();
|
|
|
+ VideoDetail videoDetail = entry.getValue();
|
|
|
+ ContentPlatformGzhPlanVideo item = new ContentPlatformGzhPlanVideo();
|
|
|
+ item.setPlanId(gzhPlan.getId());
|
|
|
+ item.setVideoId(videoId);
|
|
|
+ item.setTitle(videoDetail.getTitle());
|
|
|
+ item.setCover(videoDetail.getCover());
|
|
|
+ item.setVideo(videoDetail.getVideoPath());
|
|
|
+ item.setCreateAccountId(account.getId());
|
|
|
+ item.setCreateTimestamp(System.currentTimeMillis());
|
|
|
+ gzhPlanVideoMapper.insertSelective(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void qwPlanImport(List<String> channels) {
|
|
|
+ List<AdPutFlowRecordTencent> list = new ArrayList<>();
|
|
|
+ for (String channel : channels) {
|
|
|
+ Integer count = adApiService.getPutFlowListTencentCount(channel, 1, 1);
|
|
|
+ if (count == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ int pageNum = 1000;
|
|
|
+ int totalPage = (count / pageNum) + 1;
|
|
|
+ for (int i = 1; i <= totalPage; i++) {
|
|
|
+ list.addAll(adApiService.getPutFlowListTencent(channel, i, pageNum));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> filterChannels = Arrays.asList("ml2025", "mj", "nh", "qc", "tczy", "wb", "xj", "wxm", "wxmx1", "wxmx", "xycsd", "xycsd1", "xycsd2", "xycsd3", "xycsd4", "xycsd5", "xycsd6", "xycsd7", "xycsd8", "xycsd9", "xycsd10", "xycsd11", "xycsd12", "xycsd13", "xycsd14", "xycsd15", "xycsd16", "xycsd17", "xycsd18", "shy");
|
|
|
+ Map<String, List<AdPutFlowRecordTencent>> channelMap = list.stream()
|
|
|
+ .filter(o -> filterChannels.contains(o.getChannel()))
|
|
|
+ .collect(Collectors.groupingBy(AdPutFlowRecordTencent::getChannel));
|
|
|
+ for (Map.Entry<String, List<AdPutFlowRecordTencent>> entry : channelMap.entrySet()) {
|
|
|
+ String channel = entry.getKey();
|
|
|
+ List<AdPutFlowRecordTencent> recordList = entry.getValue();
|
|
|
+ ContentPlatformAccount account = accountService.getAccountByChannel(channel);
|
|
|
+ List<String> rootSourceIds = recordList.stream().map(AdPutFlowRecordTencent::getRootSourceId).distinct().collect(Collectors.toList());
|
|
|
+ List<ContentPlatformQwPlan> existsPlanList = getQwPlanListByRootSourceIds(rootSourceIds);
|
|
|
+ List<String> existsRootSourceIds = existsPlanList.stream().map(ContentPlatformQwPlan::getRootSourceId).collect(Collectors.toList());
|
|
|
+ List<Long> videoIds = recordList.stream().filter(o -> !existsRootSourceIds.contains(o.getRootSourceId()))
|
|
|
+ .map(AdPutFlowRecordTencent::getVideoId).distinct().collect(Collectors.toList());
|
|
|
+ Map<Long, VideoDetail> videoMap = new HashMap<>();
|
|
|
+ for (List<Long> partition : Lists.partition(videoIds, 20)) {
|
|
|
+ Set<Long> ids = new HashSet<>(partition);
|
|
|
+ videoMap.putAll(messageAttachmentService.getVideoDetail(ids));
|
|
|
+ }
|
|
|
+ Long now = System.currentTimeMillis();
|
|
|
+ for (AdPutFlowRecordTencent record : recordList) {
|
|
|
+ if (existsRootSourceIds.contains(record.getRootSourceId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ ContentPlatformQwPlan qwPlan = new ContentPlatformQwPlan();
|
|
|
+ QwPlanTypeEnum typeEnum = QwPlanTypeEnum.from(record.getPutTypeTwo());
|
|
|
+ qwPlan.setType(typeEnum.getVal());
|
|
|
+ qwPlan.setScene(0);
|
|
|
+ qwPlan.setPageUrl(record.getUrl());
|
|
|
+ qwPlan.setRootSourceId(record.getRootSourceId());
|
|
|
+ qwPlan.setCreateAccountId(account.getId());
|
|
|
+ qwPlan.setCreateTimestamp(now);
|
|
|
+ // 保存视频内容
|
|
|
+ VideoDetail videoDetail = videoMap.get(record.getVideoId());
|
|
|
+ if (Objects.isNull(videoDetail)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ QwPlanSaveVideoParam videoParam = new QwPlanSaveVideoParam();
|
|
|
+ videoParam.setVideoId(record.getVideoId());
|
|
|
+ videoParam.setTitle(record.getVideoTitle());
|
|
|
+ videoParam.setCover(videoDetail.getCover());
|
|
|
+ videoParam.setVideo(videoDetail.getVideoPath());
|
|
|
+ planMapperExt.insertQwPlanReturnId(qwPlan);
|
|
|
+ saveQwPlanVideo(videoParam, qwPlan.getId(), account.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|