|
@@ -653,92 +653,7 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
.collect(Collectors.toSet());
|
|
.collect(Collectors.toSet());
|
|
|
log.info("收集到 {} 个账户ID", accountIds.size());
|
|
log.info("收集到 {} 个账户ID", accountIds.size());
|
|
|
|
|
|
|
|
- // 收集创意文件的 fileMd5(区分图片和视频)
|
|
|
|
|
- List<String> imageFileMd5List = creativeOssFile.stream()
|
|
|
|
|
- .filter(f -> "image".equalsIgnoreCase(f.getFileType()))
|
|
|
|
|
- .map(OssFile::getFileMd5)
|
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
|
- .distinct()
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- List<String> videoFileMd5List = creativeOssFile.stream()
|
|
|
|
|
- .filter(f -> "video".equalsIgnoreCase(f.getFileType()))
|
|
|
|
|
- .map(OssFile::getFileMd5)
|
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
|
- .distinct()
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- // 批量查询已上传的图片记录,构建双 key map: accountId -> fileMd5 -> imageId
|
|
|
|
|
- Map<Long, Map<String, Long>> imageIdMap = new HashMap<>();
|
|
|
|
|
- if (!imageFileMd5List.isEmpty()) {
|
|
|
|
|
- List<TencentAccountIdImage> existingImages = tencentAccountIdImageService
|
|
|
|
|
- .batchGetByAccountIdsAndMd5s(new ArrayList<>(accountIds), imageFileMd5List);
|
|
|
|
|
- for (TencentAccountIdImage image : existingImages) {
|
|
|
|
|
- imageIdMap.computeIfAbsent(image.getAccountId(), k -> new HashMap<>())
|
|
|
|
|
- .put(image.getFileMd5(), image.getImageId());
|
|
|
|
|
- }
|
|
|
|
|
- log.info("从数据库查询到 {} 条已上传图片记录", existingImages.size());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 批量查询已上传的视频记录
|
|
|
|
|
- Map<Long, Map<String, Long>> videoIdMap = new HashMap<>();
|
|
|
|
|
- if (!videoFileMd5List.isEmpty()) {
|
|
|
|
|
- List<TencentAccountIdVideoId> existingVideos = tencentAccountIdVideoIdService
|
|
|
|
|
- .batchGetByAccountIdsAndMd5s(new ArrayList<>(accountIds), videoFileMd5List);
|
|
|
|
|
- for (TencentAccountIdVideoId video : existingVideos) {
|
|
|
|
|
- videoIdMap.computeIfAbsent(video.getAccountId(), k -> new HashMap<>())
|
|
|
|
|
- .put(video.getFileMd5(), video.getVideoId());
|
|
|
|
|
- }
|
|
|
|
|
- log.info("从数据库查询到 {} 条已上传视频记录", existingVideos.size());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 第二步:处理未上传的创意文件
|
|
|
|
|
- for (OssFile ossFile : creativeOssFile) {
|
|
|
|
|
- String fileMd5 = ossFile.getFileMd5();
|
|
|
|
|
- String fileUrl = ossFile.getFileUrl();
|
|
|
|
|
- String fileType = ossFile.getFileType();
|
|
|
|
|
-
|
|
|
|
|
- if (fileMd5 == null || fileUrl == null || fileType == null) {
|
|
|
|
|
- log.warn("跳过无效的创意文件: {}", ossFile.getFileName());
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if ("image".equalsIgnoreCase(fileType)) {
|
|
|
|
|
- // 处理图片类型
|
|
|
|
|
- List<Long> needUploadAccountIds = accountIds.stream()
|
|
|
|
|
- .filter(accId -> !imageIdMap.getOrDefault(accId, Collections.emptyMap()).containsKey(fileMd5))
|
|
|
|
|
- .toList();
|
|
|
|
|
-
|
|
|
|
|
- if (!needUploadAccountIds.isEmpty()) {
|
|
|
|
|
- log.info("图片 {} 需要上传到 {} 个账户", ossFile.getFileName(), needUploadAccountIds.size());
|
|
|
|
|
- // 下载图片一次
|
|
|
|
|
- byte[] fileBytes = tencentAssetService.downloadFileToBytes(fileUrl);
|
|
|
|
|
- for (Long accountId : needUploadAccountIds) {
|
|
|
|
|
- TencentAssetService.ImageUploadResult result = tencentAssetService.uploadImageFromBytes(tencentAds, fileBytes, fileMd5, "创意图片-" + ossFile.getFileName());
|
|
|
|
|
- tencentAccountIdImageService.saveImageId(accountId, fileMd5, Long.valueOf(result.imageId()) , fileUrl);
|
|
|
|
|
- imageIdMap.computeIfAbsent(accountId, k -> new HashMap<>()).put(fileMd5, Long.valueOf(result.imageId()));
|
|
|
|
|
- log.info("图片上传成功,accountId={}, fileMd5={}, imageId={}", accountId, fileMd5, result.imageId());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else if ("video".equalsIgnoreCase(fileType)) {
|
|
|
|
|
- // 处理视频类型
|
|
|
|
|
- List<Long> needUploadAccountIds = accountIds.stream()
|
|
|
|
|
- .filter(accId -> !videoIdMap.getOrDefault(accId, Collections.emptyMap()).containsKey(fileMd5))
|
|
|
|
|
- .toList();
|
|
|
|
|
-
|
|
|
|
|
- if (!needUploadAccountIds.isEmpty()) {
|
|
|
|
|
- log.info("视频 {} 需要上传到 {} 个账户", ossFile.getFileName(), needUploadAccountIds.size());
|
|
|
|
|
- for (Long accountId : needUploadAccountIds) {
|
|
|
|
|
- TencentAssetService.VideoUploadResult videoResult = tencentAssetService.uploadVideoFromUrl(tencentAds, fileUrl, fileMd5, "创意视频-" + ossFile.getFileName());
|
|
|
|
|
- tencentAccountIdVideoIdService.saveVideoId(accountId, fileMd5, videoResult.videoId(), fileUrl, videoResult.coverImageId());
|
|
|
|
|
- videoIdMap.computeIfAbsent(accountId, k -> new HashMap<>()).put(fileMd5, videoResult.videoId());
|
|
|
|
|
- log.info("视频上传成功,accountId={}, fileMd5={}, videoId={}", accountId, fileMd5, videoResult.videoId());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 第三步:处理 brandFile(品牌形象图片)
|
|
|
|
|
|
|
+ // 第二步:处理 brandFile(品牌形象图片)
|
|
|
Map<Long, Map<String, Long>> brandImageIdMap = new HashMap<>();
|
|
Map<Long, Map<String, Long>> brandImageIdMap = new HashMap<>();
|
|
|
if (brandFile != null && brandFile.getFileMd5() != null && brandFile.getFileUrl() != null) {
|
|
if (brandFile != null && brandFile.getFileMd5() != null && brandFile.getFileUrl() != null) {
|
|
|
String brandFileMd5 = brandFile.getFileMd5();
|
|
String brandFileMd5 = brandFile.getFileMd5();
|
|
@@ -771,31 +686,16 @@ public class AdPlanConfServiceImpl extends ServiceImpl<AdPlanConfMapper, AdPlanC
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 第四步:给 plan.getAdCreatives() 下的创意填充 imageId/videoId/brandImageId
|
|
|
|
|
|
|
+ // 第三步 给 plan.getAdCreatives() 下的创意填充 brandImageId
|
|
|
for (AdPlan plan : plans) {
|
|
for (AdPlan plan : plans) {
|
|
|
Long accountId = plan.getAccountId();
|
|
Long accountId = plan.getAccountId();
|
|
|
List<AdPlanCreative> creatives = plan.getAdCreatives();
|
|
List<AdPlanCreative> creatives = plan.getAdCreatives();
|
|
|
if (creatives == null) continue;
|
|
if (creatives == null) continue;
|
|
|
|
|
|
|
|
for (AdPlanCreative creative : creatives) {
|
|
for (AdPlanCreative creative : creatives) {
|
|
|
- String creativeFileMd5 = creative.getCreativeFileMd5();
|
|
|
|
|
- String creativeFileType = creative.getCreativeFileType();
|
|
|
|
|
-
|
|
|
|
|
- // 填充创意文件的 imageId 或 videoId
|
|
|
|
|
- if (creativeFileMd5 != null && creativeFileType != null) {
|
|
|
|
|
- if ("image".equalsIgnoreCase(creativeFileType)) {
|
|
|
|
|
- Long imageId = imageIdMap.getOrDefault(accountId, Collections.emptyMap()).get(creativeFileMd5);
|
|
|
|
|
- if (imageId != null) {
|
|
|
|
|
- creative.setImageId(imageId);
|
|
|
|
|
- }
|
|
|
|
|
- } else if ("video".equalsIgnoreCase(creativeFileType)) {
|
|
|
|
|
- Long videoId = videoIdMap.getOrDefault(accountId, Collections.emptyMap()).get(creativeFileMd5);
|
|
|
|
|
- if (videoId != null) {
|
|
|
|
|
- creative.setVideoId(videoId);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (creative.getBrandImageId() > 0) {
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 填充品牌形象的 brandImageId
|
|
// 填充品牌形象的 brandImageId
|
|
|
if (brandFile != null && brandFile.getFileMd5() != null) {
|
|
if (brandFile != null && brandFile.getFileMd5() != null) {
|
|
|
Long brandImageId = brandImageIdMap.getOrDefault(accountId, Collections.emptyMap()).get(brandFile.getFileMd5());
|
|
Long brandImageId = brandImageIdMap.getOrDefault(accountId, Collections.emptyMap()).get(brandFile.getFileMd5());
|