|
@@ -10,11 +10,14 @@ import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouBatchGroupPreviewMapper
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouBatchCampaignPreviewService;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xxl.job.core.enums.NoEn;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* 快手-广告计划预览信息
|
|
|
*
|
|
@@ -34,8 +37,29 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
|
|
|
KuaishouBatchCreativePreviewMapper creativePreviewMapper;
|
|
|
|
|
|
@Override
|
|
|
+ public JSONObject queryByBatchId(String batchId, String accountId) {
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ QueryWrapper<KuaishouBatchCampaignPreview> campaignWrapper = new QueryWrapper<>();
|
|
|
+ campaignWrapper.eq("batch_id", batchId).eq("account_id", accountId).orderByDesc("create_time");
|
|
|
+ List<KuaishouBatchCampaignPreview> campaignPreviewList = campaignPreviewMapper.selectList(campaignWrapper);
|
|
|
+ obj.put("campaignList", campaignPreviewList);
|
|
|
+ QueryWrapper<KuaishouBatchGroupPreview> groupWrapper = new QueryWrapper<>();
|
|
|
+ groupWrapper.eq("batch_id", batchId).eq("account_id", accountId).orderByDesc("create_time");
|
|
|
+ List<KuaishouBatchGroupPreview> groupPreviewList = groupPreviewMapper.selectList(groupWrapper);
|
|
|
+ obj.put("groupList", groupPreviewList);
|
|
|
+ QueryWrapper<KuaishouBatchCreativePreview> creativeWrapper = new QueryWrapper<>();
|
|
|
+ creativeWrapper.eq("batch_id", batchId).eq("account_id", accountId).orderByDesc("create_time");
|
|
|
+ List<KuaishouBatchCreativePreview> creativePreviewList = creativePreviewMapper.selectList(creativeWrapper);
|
|
|
+ obj.put("creativeList", creativePreviewList);
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void addPreviewData(JSONObject data) throws Exception {
|
|
|
String batchId = data.getString("batchId");
|
|
|
+ if (Check.isNull(batchId)) {
|
|
|
+ throw new Exception("数据异常,未获取到批次标识");
|
|
|
+ }
|
|
|
//计划
|
|
|
JSONObject campaignJson = data.getJSONObject("campaignJson");
|
|
|
if (Check.isNull(campaignJson)) {
|
|
@@ -76,10 +100,43 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
|
|
|
}
|
|
|
//分组规则 1 定向 2 创意 3 落地页
|
|
|
Integer type = campaignJson.getInteger("groupRule");
|
|
|
- insertCampaignsAndGroups(type, targetIds, materialArray, campaignPreview, groupPreview, creativePreview);
|
|
|
+ insertCampaignsAndGroups(type, data, campaignPreview, groupPreview, creativePreview);
|
|
|
}
|
|
|
|
|
|
- private JSONObject insertCampaignsAndGroups(Integer type, JSONArray targetIds, JSONObject materialArray, KuaishouBatchCampaignPreview campaignPreview, KuaishouBatchGroupPreview groupPreview, KuaishouBatchCreativePreview creativePreview) {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 插入预览信息
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return com.alibaba.fastjson.JSONObject
|
|
|
+ * @throws
|
|
|
+ * @author ZHAOXA
|
|
|
+ */
|
|
|
+ private void insertCampaignsAndGroups(Integer type, JSONObject data, KuaishouBatchCampaignPreview campaignPreview, KuaishouBatchGroupPreview groupPreview, KuaishouBatchCreativePreview creativePreview) throws Exception {
|
|
|
+ //定向包
|
|
|
+ JSONArray targetIds = data.getJSONArray("targetIds");
|
|
|
+ //应用数据
|
|
|
+ JSONObject appList = data.getJSONObject("appList");
|
|
|
+ //应用分配方式 1 按账户,2按广告计划,3按广告组
|
|
|
+ Integer appAllocation = appList.getInteger("appAllocation");
|
|
|
+ JSONArray appArr = appList.getJSONArray("appArr");
|
|
|
+ //监测链接分配方式 1 按账户,2按广告计划,3按广告组
|
|
|
+ Integer linkAllocation = appList.getInteger("linkAllocation");
|
|
|
+ JSONArray clickUrlList = appList.getJSONArray("clickUrlList");
|
|
|
+ Integer appId = null;
|
|
|
+ Integer siteId = null;
|
|
|
+ String actionbarClickUrl = null;
|
|
|
+ //按账户
|
|
|
+ if (appAllocation == 1) {
|
|
|
+ appId = appArr.getJSONObject(0).getInteger("appId");
|
|
|
+ siteId = appArr.getJSONObject(0).getInteger("siteId");
|
|
|
+ }
|
|
|
+ if (linkAllocation == 1) {
|
|
|
+ actionbarClickUrl = clickUrlList.getString(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ //素材数据
|
|
|
+ JSONObject materialArray = data.getJSONObject("materialArray");
|
|
|
//创意组
|
|
|
JSONArray materialList = materialArray.getJSONArray("materialList");
|
|
|
|
|
@@ -93,10 +150,36 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
|
|
|
}
|
|
|
creativePreview.setAccountId(campaignPreview.getAccountId());
|
|
|
//分组规则 1定向,2创意组
|
|
|
+ int count = targetIds.size() * materialList.size();
|
|
|
+ int appCount = targetIds.size() * materialList.size();
|
|
|
if (NoEn.NO1.valueInt() == type) {
|
|
|
+ /**
|
|
|
+ *按照 定向包 分组
|
|
|
+ * 计划总数 = 定向包数(targetIds)
|
|
|
+ * 同一计划下广告组的定向包一样,创意不同
|
|
|
+ */
|
|
|
for (int i = 0; i < targetIds.size(); i++) {
|
|
|
+ if (appAllocation == 2) {
|
|
|
+ appId = appArr.getJSONObject(i).getInteger("appId");
|
|
|
+ siteId = appArr.getJSONObject(i).getInteger("siteId");
|
|
|
+ }
|
|
|
+ if (linkAllocation == 2) {
|
|
|
+ actionbarClickUrl = clickUrlList.getString(i);
|
|
|
+ }
|
|
|
+ campaignPreview.setId(null);
|
|
|
campaignPreviewMapper.insert(campaignPreview);
|
|
|
for (int j = 0; j < materialList.size(); j++) {
|
|
|
+ if (appAllocation == 3) {
|
|
|
+ appCount--;
|
|
|
+ appId = appArr.getJSONObject(appCount).getInteger("appId");
|
|
|
+ siteId = appArr.getJSONObject(appCount).getInteger("siteId");
|
|
|
+ }
|
|
|
+ if (linkAllocation == 3) {
|
|
|
+ count--;
|
|
|
+ actionbarClickUrl = clickUrlList.getString(count);
|
|
|
+ }
|
|
|
+ groupPreview.setId(null);
|
|
|
+ groupPreview.setAppId(appId);
|
|
|
groupPreview.setPlanId(campaignPreview.getId());
|
|
|
groupPreview.setTemplateId(targetIds.getLong(i));
|
|
|
groupPreviewMapper.insert(groupPreview);
|
|
@@ -107,6 +190,9 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
|
|
|
descriptionList = advertisingSlogan(descriptionList, photoArr);
|
|
|
}
|
|
|
for (int k = 0; k < photoArr.size(); k++) {
|
|
|
+ creativePreview.setId(null);
|
|
|
+ creativePreview.setSiteId(siteId);
|
|
|
+ creativePreview.setActionbarClickUrl(actionbarClickUrl);
|
|
|
JSONObject photo = photoArr.getJSONObject(k);
|
|
|
JSONObject image = photo.getJSONObject("image");
|
|
|
creativePreview.setPlanId(campaignPreview.getId());
|
|
@@ -127,11 +213,69 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
|
|
|
}
|
|
|
}
|
|
|
} else if (NoEn.NO2.valueInt() == type) {
|
|
|
-
|
|
|
+ /**
|
|
|
+ *按照 创意组 分组
|
|
|
+ * 计划总数 = 创意组数
|
|
|
+ * 则同一广告计划内的创意完全相同,定向包不同
|
|
|
+ */
|
|
|
+ for (int i = 0; i < materialList.size(); i++) {
|
|
|
+ if (appAllocation == 2) {
|
|
|
+ appId = appArr.getJSONObject(i).getInteger("appId");
|
|
|
+ siteId = appArr.getJSONObject(i).getInteger("siteId");
|
|
|
+ }
|
|
|
+ if (linkAllocation == 2) {
|
|
|
+ actionbarClickUrl = clickUrlList.getString(i);
|
|
|
+ }
|
|
|
+ campaignPreview.setId(null);
|
|
|
+ campaignPreviewMapper.insert(campaignPreview);
|
|
|
+ JSONObject material = materialList.getJSONObject(i);
|
|
|
+ JSONArray photoArr = material.getJSONArray("photoArr");
|
|
|
+ if (matchingMethod == 2) {
|
|
|
+ //创意匹配
|
|
|
+ descriptionList = advertisingSlogan(descriptionList, photoArr);
|
|
|
+ }
|
|
|
+ for (int j = 0; j < targetIds.size(); j++) {
|
|
|
+ if (appAllocation == 3) {
|
|
|
+ appCount--;
|
|
|
+ appId = appArr.getJSONObject(appCount).getInteger("appId");
|
|
|
+ siteId = appArr.getJSONObject(appCount).getInteger("siteId");
|
|
|
+ }
|
|
|
+ if (linkAllocation == 3) {
|
|
|
+ count--;
|
|
|
+ actionbarClickUrl = clickUrlList.getString(count);
|
|
|
+ }
|
|
|
+ groupPreview.setId(null);
|
|
|
+ groupPreview.setAppId(appId);
|
|
|
+ groupPreview.setPlanId(campaignPreview.getId());
|
|
|
+ groupPreview.setTemplateId(targetIds.getLong(j));
|
|
|
+ groupPreviewMapper.insert(groupPreview);
|
|
|
+ for (int k = 0; k < photoArr.size(); k++) {
|
|
|
+ creativePreview.setId(null);
|
|
|
+ creativePreview.setSiteId(siteId);
|
|
|
+ creativePreview.setActionbarClickUrl(actionbarClickUrl);
|
|
|
+ JSONObject photo = photoArr.getJSONObject(k);
|
|
|
+ JSONObject image = photo.getJSONObject("image");
|
|
|
+ creativePreview.setPlanId(campaignPreview.getId());
|
|
|
+ creativePreview.setGroupId(groupPreview.getId());
|
|
|
+ creativePreview.setPhotoId(photo.getString("photoId"));
|
|
|
+ creativePreview.setCreativeName(photo.getString("creativeName"));
|
|
|
+ creativePreview.setImageUrl(image.getString("url"));
|
|
|
+ creativePreview.setImageSignature(image.getString("signature"));
|
|
|
+ if (matchingMethod == 1) {
|
|
|
+ creativePreview.setDescription(photo.getString("description"));
|
|
|
+ } else if (matchingMethod == 2) {
|
|
|
+ creativePreview.setDescription(descriptionList.getString(k));
|
|
|
+ } else if (matchingMethod == 3) {
|
|
|
+ creativePreview.setDescription(descriptionList.getString(i));
|
|
|
+ }
|
|
|
+ creativePreviewMapper.insert(creativePreview);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 广告语整理
|
|
|
*
|
|
@@ -163,7 +307,6 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
|
|
|
* @author ZHAOXA
|
|
|
*/
|
|
|
private KuaishouBatchCampaignPreview commonCampaign(JSONObject campaignJson, String batchId) {
|
|
|
-// KuaishouBatchCampaignPreview sd =JSONObject.toJavaObject(campaignJson, KuaishouBatchCampaignPreview.class);
|
|
|
KuaishouBatchCampaignPreview campaignPreview = new KuaishouBatchCampaignPreview();
|
|
|
campaignPreview.setAccountId(campaignJson.getLong("accountId"));
|
|
|
campaignPreview.setCampaignName(campaignJson.getString("campaignName"));
|
|
@@ -248,6 +391,7 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
|
|
|
creativePreview.setOverlayType(creativeJson.getString("overlayType"));
|
|
|
creativePreview.setStickerTitle(creativeJson.getString("stickerTitle"));
|
|
|
creativePreview.setCreativeTag(creativeJson.getString("creativeTag"));
|
|
|
+ creativePreview.setCreativeCategory(creativeJson.getInteger("creativeCategory"));
|
|
|
creativePreview.setBatchId(batchId);
|
|
|
return creativePreview;
|
|
|
}
|