|
@@ -1,23 +1,34 @@
|
|
package cn.com.ctop.kuaishou.modules.batch.service.impl;
|
|
package cn.com.ctop.kuaishou.modules.batch.service.impl;
|
|
|
|
|
|
|
|
+import cn.com.ctop.common.module.enums.SceneIdEnum;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAppList;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchCampaignPreview;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchCampaignPreview;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchCreativePreview;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchCreativePreview;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchGroupPreview;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchGroupPreview;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplate;
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouBatchCampaignPreviewMapper;
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouBatchCampaignPreviewMapper;
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouBatchCreativePreviewMapper;
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouBatchCreativePreviewMapper;
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouBatchGroupPreviewMapper;
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouBatchGroupPreviewMapper;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouAppListService;
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouBatchCampaignPreviewService;
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouBatchCampaignPreviewService;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateService;
|
|
import com.alibaba.excel.util.CollectionUtils;
|
|
import com.alibaba.excel.util.CollectionUtils;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.xxl.job.core.enums.NoEn;
|
|
import com.xxl.job.core.enums.NoEn;
|
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 快手-广告计划预览信息
|
|
* 快手-广告计划预览信息
|
|
@@ -36,6 +47,10 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
|
|
KuaishouBatchGroupPreviewMapper groupPreviewMapper;
|
|
KuaishouBatchGroupPreviewMapper groupPreviewMapper;
|
|
@Autowired
|
|
@Autowired
|
|
KuaishouBatchCreativePreviewMapper creativePreviewMapper;
|
|
KuaishouBatchCreativePreviewMapper creativePreviewMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaishouTemplateService kuaishouTemplateService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouAppListService kuaiShouAppListService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public JSONObject queryByBatchId(String batchId, String accountId) {
|
|
public JSONObject queryByBatchId(String batchId, String accountId) {
|
|
@@ -197,7 +212,7 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
|
|
}
|
|
}
|
|
}
|
|
}
|
|
campaignPreview.setId(null);
|
|
campaignPreview.setId(null);
|
|
- campaignPreview.setCampaignName(campaignPreview.getCampaignName() + i);
|
|
|
|
|
|
+ campaignPreview.setCampaignName(getName(campaignPreview.getCampaignName(), null, null, appId, null) + i);
|
|
campaignPreviewMapper.insert(campaignPreview);
|
|
campaignPreviewMapper.insert(campaignPreview);
|
|
for (int j = 0; j < materialList.size(); j++) {
|
|
for (int j = 0; j < materialList.size(); j++) {
|
|
if (appAllocation == 3) {
|
|
if (appAllocation == 3) {
|
|
@@ -223,7 +238,7 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
|
|
groupPreview.setAppId(appId);
|
|
groupPreview.setAppId(appId);
|
|
groupPreview.setPlanId(campaignPreview.getId());
|
|
groupPreview.setPlanId(campaignPreview.getId());
|
|
groupPreview.setTemplateId(targetIds.getLong(i));
|
|
groupPreview.setTemplateId(targetIds.getLong(i));
|
|
- groupPreview.setUnitName(groupPreview.getUnitName() + j);
|
|
|
|
|
|
+ groupPreview.setUnitName(getName(groupPreview.getUnitName(), targetIds.getLong(i), groupPreview.getSceneId(), appId, groupPreview.getUnitType()) + j);
|
|
groupPreview.setUrl(url);
|
|
groupPreview.setUrl(url);
|
|
groupPreviewMapper.insert(groupPreview);
|
|
groupPreviewMapper.insert(groupPreview);
|
|
JSONObject material = materialList.getJSONObject(j);
|
|
JSONObject material = materialList.getJSONObject(j);
|
|
@@ -281,7 +296,7 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
|
|
}
|
|
}
|
|
}
|
|
}
|
|
campaignPreview.setId(null);
|
|
campaignPreview.setId(null);
|
|
- campaignPreview.setCampaignName(campaignPreview.getCampaignName() + i);
|
|
|
|
|
|
+ campaignPreview.setCampaignName(getName(campaignPreview.getCampaignName(), null, null, appId, null) + i);
|
|
campaignPreviewMapper.insert(campaignPreview);
|
|
campaignPreviewMapper.insert(campaignPreview);
|
|
JSONObject material = materialList.getJSONObject(i);
|
|
JSONObject material = materialList.getJSONObject(i);
|
|
JSONArray photoArr = material.getJSONArray("photoArr");
|
|
JSONArray photoArr = material.getJSONArray("photoArr");
|
|
@@ -313,7 +328,7 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
|
|
groupPreview.setAppId(appId);
|
|
groupPreview.setAppId(appId);
|
|
groupPreview.setPlanId(campaignPreview.getId());
|
|
groupPreview.setPlanId(campaignPreview.getId());
|
|
groupPreview.setTemplateId(targetIds.getLong(j));
|
|
groupPreview.setTemplateId(targetIds.getLong(j));
|
|
- groupPreview.setUnitName(groupPreview.getUnitName() + j);
|
|
|
|
|
|
+ groupPreview.setUnitName(getName(groupPreview.getUnitName(), targetIds.getLong(i), groupPreview.getSceneId(), appId, groupPreview.getUnitType()) + j);
|
|
groupPreview.setUrl(url);
|
|
groupPreview.setUrl(url);
|
|
groupPreviewMapper.insert(groupPreview);
|
|
groupPreviewMapper.insert(groupPreview);
|
|
for (int k = 0; k < photoArr.size(); k++) {
|
|
for (int k = 0; k < photoArr.size(); k++) {
|
|
@@ -472,4 +487,97 @@ public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<Kuaisho
|
|
return creativePreview;
|
|
return creativePreview;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param content 通配符String
|
|
|
|
+ * @param templateId 定向模板ID
|
|
|
|
+ * @param sceneId 广告位置ID
|
|
|
|
+ * @param appId 应用包id、渠道号
|
|
|
|
+ * @param unitType 创意制作方式
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private String getName(String content, Long templateId, String sceneId, Integer appId, Integer unitType) {
|
|
|
|
+ String reg = "\\{\\{(.+?)\\}\\}";
|
|
|
|
+ List<String> params = getParams(reg, content);
|
|
|
|
+ if (Check.isNull(params)) {
|
|
|
|
+ return content;
|
|
|
|
+ }
|
|
|
|
+ Map<String, String> data = new HashMap<>();
|
|
|
|
+ for (int i = 0; i < params.size(); i++) {
|
|
|
|
+ String regName = params.get(i);
|
|
|
|
+ if ("日期".equals(regName)) {
|
|
|
|
+ data.put(regName, DateUtils.getNowDate("yyyy-MM-dd"));
|
|
|
|
+ } else if ("定向包".equals(regName)) {
|
|
|
|
+ if (!Check.isNull(templateId)) {
|
|
|
|
+ QueryWrapper<KuaishouTemplate> queryWrapper = new QueryWrapper();
|
|
|
|
+ queryWrapper.eq("template_id", templateId);
|
|
|
|
+ KuaishouTemplate template = kuaishouTemplateService.getOne(queryWrapper);
|
|
|
|
+ data.put(regName, template.getTemplateName());
|
|
|
|
+ }
|
|
|
|
+ } else if ("广告位置".equals(regName)) {
|
|
|
|
+ if (!Check.isNull(sceneId)) {
|
|
|
|
+ Integer sceneid = JSONObject.parseArray(sceneId).getInteger(0);
|
|
|
|
+ if (sceneid == 1 || sceneid == 5) {
|
|
|
|
+ data.put(regName, SceneIdEnum.getEnumById(sceneid).getName());
|
|
|
|
+ } else {
|
|
|
|
+ data.put(regName, "场景广告位");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if ("应用名称".equals(regName)) {
|
|
|
|
+ if (!Check.isNull(appId)) {
|
|
|
|
+ QueryWrapper<KuaiShouAppList> queryWrapper = new QueryWrapper();
|
|
|
|
+ queryWrapper.eq("app_id", appId);
|
|
|
|
+ KuaiShouAppList one = kuaiShouAppListService.getOne(queryWrapper);
|
|
|
|
+ data.put(regName, one.getAppName());
|
|
|
|
+ }
|
|
|
|
+ } else if ("渠道号".equals(regName)) {
|
|
|
|
+ if (!Check.isNull(appId)) {
|
|
|
|
+ QueryWrapper<KuaiShouAppList> queryWrapper = new QueryWrapper();
|
|
|
|
+ queryWrapper.eq("app_id", appId);
|
|
|
|
+ KuaiShouAppList one = kuaiShouAppListService.getOne(queryWrapper);
|
|
|
|
+ data.put(regName, one.getAppVersion());
|
|
|
|
+ }
|
|
|
|
+ } else if ("创意制作方式".equals(regName)) {
|
|
|
|
+ if (!Check.isNull(unitType)) {
|
|
|
|
+ data.put(regName, unitType == 4 ? "自定义" : "程序化创意2.0");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String text = parse(reg, content, data);
|
|
|
|
+ return text;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static String parse(String pattern, String content, Map<String, String> data) {
|
|
|
|
+ Pattern p = Pattern.compile(pattern);
|
|
|
|
+ Matcher m = p.matcher(content);
|
|
|
|
+
|
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
|
+ while (m.find()) {
|
|
|
|
+ String key = m.group(1);
|
|
|
|
+ String value = data.get(key);
|
|
|
|
+ m.appendReplacement(sb, value == null ? "" : value);
|
|
|
|
+ }
|
|
|
|
+ m.appendTail(sb);
|
|
|
|
+ return sb.toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据正则表达式获取文本中的变量名列表
|
|
|
|
+ *
|
|
|
|
+ * @param pattern
|
|
|
|
+ * @param content
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static List<String> getParams(String pattern, String content) {
|
|
|
|
+ Pattern p = Pattern.compile(pattern);
|
|
|
|
+ Matcher m = p.matcher(content);
|
|
|
|
+
|
|
|
|
+ List<String> result = new ArrayList<String>();
|
|
|
|
+ while (m.find()) {
|
|
|
|
+ result.add(m.group(1));
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|