|
@@ -72,11 +72,21 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
|
|
|
if (Check.isNull(photoArr)) {
|
|
|
throw new Exception("请选择需要创建的视频");
|
|
|
}
|
|
|
- if (createCount != photoArr.size()) {
|
|
|
- throw new Exception("视频数量必须和创建数量保持一致");
|
|
|
+
|
|
|
+ Integer createType = requestJson.getInteger("createType"); // 创建类型 0 单品 1 混搭
|
|
|
+ if (Check.isNull(createType)) {
|
|
|
+ throw new Exception("请选择创意创建方式混搭、单品");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (createType == 0 && createCount != photoArr.size()) {
|
|
|
+ throw new Exception("单品视频数量必须和创建数量保持一致");
|
|
|
}
|
|
|
- JSONObject returnJson = new JSONObject();
|
|
|
|
|
|
+ if (createType == 1 && createCount * 15 != photoArr.size()) {
|
|
|
+ throw new Exception("混搭视频数量必须和创建数量保持倍数关系");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
String userId = requestJson.getString("userId");
|
|
|
String unitName = requestJson.getString("unitName");
|
|
|
Long template_id = requestJson.getLong("templateId");
|
|
@@ -109,16 +119,27 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
|
|
|
String description = requestJson.getString("description");
|
|
|
Long site_id = requestJson.getLong("siteId");
|
|
|
|
|
|
+
|
|
|
List<KuaiShouGroupTemplate> templates = new ArrayList<>();
|
|
|
for (int i = 0; i < createCount; i++) {
|
|
|
- Long photoId = photoArr.getLong(i);
|
|
|
- String name = unitName + "_" + i;
|
|
|
KuaiShouGroupTemplate template = new KuaiShouGroupTemplate();
|
|
|
+ template.setCreateType(createType);
|
|
|
+ if (createType == 0) { // 创建方式为单品
|
|
|
+ Long photoId = photoArr.getLong(i);
|
|
|
+ template.setPhotoId(photoId);
|
|
|
+ } else if (createType == 1) { // 创建方式为混搭
|
|
|
+ JSONArray photoIds = getPhotoIds(photoArr, i);
|
|
|
+ if (Check.isNull(photoIds)) {
|
|
|
+ log.error("根据下标未获取到详细信息");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ template.setPhotoIds(photoIds.toJSONString());
|
|
|
+ }
|
|
|
+ String name = unitName + "_" + i;
|
|
|
template.setAccountId(accountId);
|
|
|
template.setUserId(userId);
|
|
|
template.setCampaignId(campaignId);
|
|
|
template.setUnitName(name);
|
|
|
- template.setPhotoId(photoId);
|
|
|
if (!Check.isNull(template_id)) {
|
|
|
template.setTemplateId(template_id);
|
|
|
}
|
|
@@ -227,6 +248,29 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private JSONArray getPhotoIds(JSONArray photoArr, Integer index) {
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
+ Integer minIndex;
|
|
|
+ Integer maxIndex;
|
|
|
+ if (index == 0) {
|
|
|
+ maxIndex = (index + 1) * 15 - 1;
|
|
|
+ minIndex = index;
|
|
|
+ } else {
|
|
|
+ maxIndex = (index + 1) * 15 - 1;
|
|
|
+ minIndex = index * 15;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < photoArr.size(); i++) {
|
|
|
+ if (minIndex > maxIndex) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ Long photoId = photoArr.getLong(minIndex);
|
|
|
+ array.add(photoId);
|
|
|
+ minIndex++;
|
|
|
+ }
|
|
|
+ return array;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 创建组
|
|
|
*/
|
|
@@ -235,7 +279,7 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
|
|
|
QueryWrapper<KuaiShouGroupTemplate> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("task_status", 0);
|
|
|
queryWrapper.orderByAsc("create_time");
|
|
|
- queryWrapper.last("limit 30");
|
|
|
+ queryWrapper.last("limit 45");
|
|
|
List<KuaiShouGroupTemplate> list = this.list(queryWrapper);
|
|
|
if (Check.isNull(list)) {
|
|
|
log.error("暂未未创建的组");
|
|
@@ -384,7 +428,8 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- private JSONObject getUnionJson(Long templateId) {
|
|
|
+ @Override
|
|
|
+ public JSONObject getUnionJson(Long templateId) {
|
|
|
JSONObject returnJson = new JSONObject();
|
|
|
QueryWrapper<KuaishouTemplateTarget> targetQueryWrapper = new QueryWrapper<>();
|
|
|
targetQueryWrapper.eq("template_id", templateId);
|
|
@@ -489,7 +534,6 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
|
|
|
return groupTemplateMapper.getUrlByPhotoId(photoId);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 创建创意
|
|
|
*
|
|
@@ -504,17 +548,6 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
|
|
|
updateTemplate.setCreativeStatus(1);
|
|
|
updateTemplate.setCreativeReviewDetail("创意创建中");
|
|
|
this.updateById(updateTemplate);
|
|
|
- Long photoId = template.getPhotoId();
|
|
|
- JSONObject md5Json = groupTemplateMapper.getMd5ByPhotoId(photoId);
|
|
|
- if (Check.isNull(md5Json)) {
|
|
|
- log.error("未获取到素材详细信息,accountId:{},unitId:{}", template.getAccountId(), unitId);
|
|
|
- updateTemplate.setCreativeStatus(3);
|
|
|
- updateTemplate.setCreativeReviewDetail("未获取到素材信息");
|
|
|
- this.updateById(updateTemplate);
|
|
|
- return;
|
|
|
- }
|
|
|
- String md5 = md5Json.getString("md5");
|
|
|
- List<JSONObject> imageList = groupTemplateMapper.getImageListByMd5(md5);
|
|
|
JSONObject createJson = new JSONObject();
|
|
|
createJson.put("unit_id", unitId);
|
|
|
if (!Check.isNull(template.getClickTrackUrl())) {
|
|
@@ -529,51 +562,91 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
|
|
|
if (!Check.isNull(template.getCreativeTag())) {
|
|
|
createJson.put("creative_tag", JSONArray.parseArray(template.getCreativeTag()));
|
|
|
}
|
|
|
- Integer materialType = md5Json.getInteger("materialType");
|
|
|
+
|
|
|
JSONArray creatives = new JSONArray();
|
|
|
- if (Check.isNull(imageList)) {
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- json.put("creative_name", template.getCreativeName());
|
|
|
- json.put("photo_id", template.getPhotoId());
|
|
|
- json.put("creative_material_type", materialType);
|
|
|
- json.put("action_bar_text", template.getActionBarText());
|
|
|
- json.put("description", template.getDescription());
|
|
|
- if (Check.isNull(template.getSiteId())) {
|
|
|
- json.put("site_id", template.getSiteId());
|
|
|
- }
|
|
|
- creatives.add(json);
|
|
|
- } else {
|
|
|
- for (int i = 0; i < imageList.size(); i++) {
|
|
|
- JSONObject imageJson = imageList.get(i);
|
|
|
- if (Check.isNull(imageJson)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ Integer createType = template.getCreateType();
|
|
|
+ if (createType == 0) { // 单品
|
|
|
+ Long photoId = template.getPhotoId();
|
|
|
+ JSONObject videoMd5Json = groupTemplateMapper.getMd5ByPhotoId(photoId);
|
|
|
+ if (Check.isNull(videoMd5Json)) {
|
|
|
+ log.error("未获取到素材详细信息,accountId:{},unitId:{}", template.getAccountId(), unitId);
|
|
|
+ updateTemplate.setCreativeStatus(3);
|
|
|
+ updateTemplate.setCreativeReviewDetail("未获取到素材信息");
|
|
|
+ this.updateById(updateTemplate);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer materialType = videoMd5Json.getInteger("materialType");
|
|
|
+ String videoMd5 = videoMd5Json.getString("md5");
|
|
|
+ List<JSONObject> imageList = groupTemplateMapper.getImageListByMd5(videoMd5);
|
|
|
+ if (Check.isNull(imageList)) {
|
|
|
JSONObject json = new JSONObject();
|
|
|
- String signature = imageJson.getString("md5");
|
|
|
- String imageToken = null;
|
|
|
- if (!Check.isNull(signature)) {
|
|
|
- QueryWrapper<KuaiShouImageGet> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("account_id", template.getAccountId());
|
|
|
- queryWrapper.eq("signature", signature);
|
|
|
- queryWrapper.last("limit 1");
|
|
|
- KuaiShouImageGet imageGet = imageGetService.getOne(queryWrapper);
|
|
|
- if (!Check.isNull(imageGet)) {
|
|
|
- imageToken = imageGet.getImageToken();
|
|
|
- } else {
|
|
|
- String url = imageJson.getString("url");
|
|
|
- imageToken = uploadService.kuauiShouImageUpload(url, signature, template.getAccountId(), accessToken);
|
|
|
+ json.put("creative_name", template.getCreativeName());
|
|
|
+ json.put("photo_id", template.getPhotoId());
|
|
|
+ json.put("creative_material_type", materialType);
|
|
|
+ json.put("action_bar_text", template.getActionBarText());
|
|
|
+ json.put("description", template.getDescription());
|
|
|
+ if (!Check.isNull(template.getSiteId())) {
|
|
|
+ json.put("site_id", template.getSiteId());
|
|
|
+ }
|
|
|
+ creatives.add(json);
|
|
|
+ } else {
|
|
|
+ for (int i = 0; i < imageList.size(); i++) {
|
|
|
+ JSONObject imageJson = imageList.get(i);
|
|
|
+ if (Check.isNull(imageJson)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ String imageMd5 = imageJson.getString("md5");
|
|
|
+ String imageToken = getImageToken(imageMd5, template.getAccountId(), accessToken, imageJson.getString("url"));
|
|
|
+ if (Check.isNull(imageToken)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
+ json.put("image_token", imageToken);
|
|
|
+ json.put("creative_name", template.getCreativeName() + "_" + i);
|
|
|
+ json.put("photo_id", template.getPhotoId());
|
|
|
+ json.put("creative_material_type", materialType);
|
|
|
+ json.put("action_bar_text", template.getActionBarText());
|
|
|
+ json.put("description", template.getDescription());
|
|
|
+ if (!Check.isNull(template.getSiteId())) {
|
|
|
+ json.put("site_id", template.getSiteId());
|
|
|
+ }
|
|
|
+ creatives.add(json);
|
|
|
}
|
|
|
- if (Check.isNull(imageToken)) {
|
|
|
- continue;
|
|
|
+ }
|
|
|
+ } else if (createType == 1) { // 混搭
|
|
|
+ JSONArray array = JSONArray.parseArray(template.getPhotoIds());
|
|
|
+ if (Check.isNull(array)) {
|
|
|
+ updateTemplate.setCreativeStatus(3);
|
|
|
+ updateTemplate.setCreativeReviewDetail("未获取到混搭素材信息");
|
|
|
+ this.updateById(updateTemplate);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ Long photoId = array.getLong(i);
|
|
|
+ JSONObject videoJson = groupTemplateMapper.getMd5ByPhotoId(photoId);
|
|
|
+ if (Check.isNull(videoJson)) {
|
|
|
+ log.error("未获取到素材详细信息,accountId:{},unitId:{}", template.getAccountId(), unitId);
|
|
|
+ updateTemplate.setCreativeStatus(3);
|
|
|
+ updateTemplate.setCreativeReviewDetail("未获取到素材信息");
|
|
|
+ this.updateById(updateTemplate);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String videoMd5 = videoJson.getString("md5");
|
|
|
+ Integer materialType = videoJson.getInteger("materialType");
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ JSONObject imageJson = groupTemplateMapper.getImageJsonByMd5(videoMd5);
|
|
|
+ if (!Check.isNull(imageJson)) {
|
|
|
+ String imageToken = getImageToken(imageJson.getString("md5"), template.getAccountId(), accessToken, imageJson.getString("url"));
|
|
|
+ if (!Check.isNull(imageToken)) {
|
|
|
+ json.put("image_token", imageToken);
|
|
|
+ }
|
|
|
}
|
|
|
- json.put("image_token", imageToken);
|
|
|
json.put("creative_name", template.getCreativeName() + "_" + i);
|
|
|
- json.put("photo_id", template.getPhotoId());
|
|
|
+ json.put("photo_id", photoId);
|
|
|
json.put("creative_material_type", materialType);
|
|
|
json.put("action_bar_text", template.getActionBarText());
|
|
|
json.put("description", template.getDescription());
|
|
|
- if (Check.isNull(template.getSiteId())) {
|
|
|
+ if (!Check.isNull(template.getSiteId())) {
|
|
|
json.put("site_id", template.getSiteId());
|
|
|
}
|
|
|
creatives.add(json);
|
|
@@ -592,4 +665,24 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
|
|
|
}
|
|
|
this.updateById(updateTemplate);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private String getImageToken(String md5, Long accountId, String accessToken, String url) {
|
|
|
+
|
|
|
+ String imageToken = null;
|
|
|
+ QueryWrapper<KuaiShouImageGet> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("account_id", accountId);
|
|
|
+ queryWrapper.eq("signature", md5);
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
+ KuaiShouImageGet imageGet = imageGetService.getOne(queryWrapper);
|
|
|
+ if (!Check.isNull(imageGet)) {
|
|
|
+ imageToken = imageGet.getImageToken();
|
|
|
+ } else {
|
|
|
+ imageToken = uploadService.kuauiShouImageUpload(url, md5, accountId, accessToken);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return imageToken;
|
|
|
+
|
|
|
+ }
|
|
|
}
|