Przeglądaj źródła

批量2.0预览数据入库

zhaoxian 4 lat temu
rodzic
commit
450e23734f

+ 47 - 24
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaishouBatchCampaignPreviewController.java

@@ -1,43 +1,47 @@
 package cn.com.ctop.kuaishou.modules.batch.controller;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
 import cn.com.ctop.common.module.annotation.AutoLog;
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouBatchCampaignPreview;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouBatchCampaignPreviewService;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import org.jeecg.common.api.vo.Result;
-import org.jeecg.common.system.query.QueryGenerator;
-import org.jeecg.common.util.oConvertUtils;
-
-import java.util.Date;
-
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
 import org.jeecgframework.poi.excel.entity.ExportParams;
 import org.jeecgframework.poi.excel.entity.ImportParams;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
-
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
-import com.alibaba.fastjson.JSON;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 快手-广告计划预览信息
@@ -109,18 +113,37 @@ public class KuaishouBatchCampaignPreviewController {
     @AutoLog(value = "添加预览数据")
     @ApiOperation(value = "添加预览数据", notes = "添加预览数据")
     @PostMapping(value = "/addPreviewData")
-    public Result<KuaishouBatchCampaignPreview> addPreviewData(@RequestBody JSONObject data) {
-        Result<KuaishouBatchCampaignPreview> result = new Result<>();
+    public Result<Object> addPreviewData(@RequestBody JSONObject data) {
+        Result<Object> result = new Result<>();
         try {
             kuaishouBatchCampaignPreviewService.addPreviewData(data);
             result.success("添加成功!");
         } catch (Exception e) {
             log.error(e.getMessage(), e);
-            result.error500("操作失败");
+            result.error500("操作失败" + e.getMessage());
         }
         return result;
     }
 
+    @AutoLog(value = "通过账户和批次标识查询预览数据")
+    @ApiOperation(value = "通过账户和批次标识查询预览数据", notes = "通过账户和批次标识查询预览数据")
+    @GetMapping(value = "/queryByBatchId")
+    public Result<Object> queryByBatchId(String batchId, String accountId) {
+        try {
+            if (Check.isNull(batchId)) {
+                return Result.error("批次号为空");
+            }
+            if (Check.isNull(accountId)) {
+                return Result.error("请选择账户");
+            }
+            JSONObject obj = kuaishouBatchCampaignPreviewService.queryByBatchId(batchId, accountId);
+            return Result.ok(obj);
+        } catch (Exception e) {
+            log.error("queryByBatchId is error", e);
+            return Result.error(e.getMessage());
+        }
+    }
+
     /**
      * 编辑
      *

+ 6 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouBatchGroupTemplate.java

@@ -113,6 +113,12 @@ public class KuaiShouBatchGroupTemplate {
     @ApiModelProperty(value = "出价")
     private Integer bid;
     /**
+     * OCPC出价
+     */
+    @Excel(name = "OCPC出价", width = 15)
+    @ApiModelProperty(value = "OCPC出价")
+    private Integer cpaBid;
+    /**
      * OCPX行为类型   1: CPM, 2: CPC,
      */
     @Excel(name = "OCPX行为类型   1: CPM, 2: CPC,", width = 15)

+ 2 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaishouBatchGroupPreview.java

@@ -126,13 +126,13 @@ public class KuaishouBatchGroupPreview {
      */
     @Excel(name = "投放时段", width = 15)
     @ApiModelProperty(value = "投放时段")
-    private Object scheduleTime;
+    private String scheduleTime;
     /**
      * 广告位 1:优选广告位;
      */
     @Excel(name = "广告位 1:优选广告位;", width = 15)
     @ApiModelProperty(value = "广告位 1:优选广告位;")
-    private Object sceneId;
+    private String sceneId;
     /**
      * 创意展现方式  0:未知, 1:轮播,
      */

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouBatchCampaignPreviewService.java

@@ -13,4 +13,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
 public interface IKuaishouBatchCampaignPreviewService extends IService<KuaishouBatchCampaignPreview> {
 
     void addPreviewData(JSONObject data) throws Exception;
+
+    JSONObject queryByBatchId(String batchId, String accountId);
 }

+ 149 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouBatchCampaignPreviewServiceImpl.java

@@ -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;
     }