فهرست منبع

Merge branch 'master' of http://git.tjyourong.com.cn/ctop/adsp-boot

zhaoxian 4 سال پیش
والد
کامیت
aeaa5025a5
15فایلهای تغییر یافته به همراه639 افزوده شده و 52 حذف شده
  1. 2 1
      jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java
  2. 4 6
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/UserAllocationController.java
  3. 2 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IMaterialCutFrameService.java
  4. 10 1
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialCutFrameServiceImpl.java
  5. 135 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaiShouCreateController.java
  6. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaiShouMaterialControer.java
  7. 15 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaiShouCreateService.java
  8. 2 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouNewCreateCampaignServiceImpl.java
  9. 421 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaiShouCreateServiceImpl.java
  10. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouCampaignService.java
  11. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouGroupService.java
  12. 11 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouCampaignServiceImpl.java
  13. 11 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouGroupServiceImpl.java
  14. 5 28
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java
  15. 16 12
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/RuleKuaiShouPlanServiceImpl.java

+ 2 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

@@ -181,7 +181,8 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/shiwan/shiwanFileUpload/*", "anon");
         filterChainDefinitionMap.put("/oa/wechatNoList/*", "anon");
         filterChainDefinitionMap.put("/ruleGroup/*", "anon");
-        filterChainDefinitionMap.put("/kuaishou/Ai/*", "anon");
+        filterChainDefinitionMap.put("/kuaishou/material/*", "anon");
+        filterChainDefinitionMap.put("/kuaishou/create/*", "anon");
 
         // 添加自己的过滤器并且取名为jwt
         Map<String, Filter> filterMap = new HashMap<>(1);

+ 4 - 6
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/UserAllocationController.java

@@ -137,13 +137,11 @@ public class UserAllocationController {
         try {
 
             QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
-            queryWrapper.eq("user_id", userId);
             queryWrapper.eq("project_id", projectId);
-           /*  Project project = projectService.getById(projectId);
-                if (!Check.isNull(project)) {
-                queryWrapper.eq("media_id", project.getMediaId());
-            }*/
-
+            String roleCode = sysRoleService.getRoleCodeByUserId(userId);
+            if (!CtopRoleCodeConstant.COMMON_ROLE_CODE_ADMIN.equals(roleCode)) {
+                queryWrapper.eq("user_id", userId);
+            }
             List<UserAllocation> userAllocations = userAllocationMapper.selectList(queryWrapper);
             result.setSuccess(true);
             result.setResult(userAllocations);

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IMaterialCutFrameService.java

@@ -33,4 +33,6 @@ public interface IMaterialCutFrameService extends IService<MaterialCutFrame> {
     MaterialCutFrame getCutFrameByCode(String code);
 
     List<JSONObject> getProgramCreativeCover(String signature);
+
+    MaterialCutFrame selectByMd5(String md5);
 }

+ 10 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialCutFrameServiceImpl.java

@@ -424,9 +424,18 @@ public class MaterialCutFrameServiceImpl extends ServiceImpl<MaterialCutFrameMap
     }
 
     @Override
-    public  List<JSONObject>  getProgramCreativeCover(String signature) {
+    public List<JSONObject> getProgramCreativeCover(String signature) {
         return materialCutFrameMapper.getProgramCreativeCover(signature);
     }
 
+    @Override
+    public MaterialCutFrame selectByMd5(String md5) {
+        QueryWrapper<MaterialCutFrame> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("signature", md5);
+        queryWrapper.last("limit 1");
+        return this.getOne(queryWrapper);
+
+    }
+
 
 }

+ 135 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaiShouCreateController.java

@@ -0,0 +1,135 @@
+package cn.com.ctop.kuaishou.modules.ai.controller;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouCreateService;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCampaignService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Slf4j
+@Api(tags = "快手-批量工具")
+@RestController
+@RequestMapping("/kuaishou/create")
+public class KuaiShouCreateController {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IKuaishouInterfaceService iKuaishouInterfaceService;
+    @Autowired
+    private IKuaiShouCampaignService campaignService;
+    @Autowired
+    private IKuaiShouCreateService kuaiShouCreateService;
+    static ExecutorService executorService = Executors.newFixedThreadPool(10);
+
+    /**
+     * 创建计划
+     *
+     * @param requestJson
+     * @return
+     */
+    @PostMapping(value = "/campaignCreate")
+    public JSONObject campaignCreate(@RequestBody JSONObject requestJson) {
+        JSONObject result = new JSONObject();
+        try {
+            Long accountId = requestJson.getLong("account_id");
+            CtopOauthToken oauthToken = tokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+            JSONObject campaignJson = new JSONObject();
+            campaignJson.put("campaign_name", requestJson.getString("campaign_name"));
+            campaignJson.put("type", requestJson.getInteger("type"));
+            if (!Check.isNull(requestJson.getLong("day_budget"))) {
+                campaignJson.put("day_budget", requestJson.getLong("day_budget"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("day_budget_schedule"))) {
+                campaignJson.put("day_budget_schedule", requestJson.getJSONArray("day_budget_schedule"));
+            }
+            Map<String, Object> campaignMap = iKuaishouInterfaceService.campaignCreate(oauthToken.getAccessToken(), accountId, campaignJson);
+            Integer code = (Integer) campaignMap.get("code");
+            if (code != 0) {
+                throw new Exception((String) campaignMap.get("message"));
+            }
+            Long campaignId = (Long) campaignMap.get("campaignId");
+            result.put("code", 0);
+            result.put("message", "SUCCESS");
+            JSONObject data = new JSONObject();
+            data.put("campaign_id", campaignId);
+            data.put("account_id", accountId);
+            KuaiShouCampaign campaign = campaignService.getCampaignByAccountAndCampaign(accountId, campaignId);
+            if (!Check.isNull(campaign)) {
+                data.put("campaign_create_time", campaign.getPutCreateTime());
+            }
+            result.put("data", data);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.put("code", -1);
+            result.put("message", e.getMessage());
+            JSONObject data = new JSONObject();
+            data.put("account_id", requestJson.getLong("account_id"));
+            result.put("data", data);
+
+        }
+        return result;
+    }
+
+
+    /**
+     * 创建组 创意
+     *
+     * @param requestJson
+     * @return
+     */
+    @PostMapping(value = "/createUnitAndCreative")
+    public JSONObject createUnitAndCreative(@RequestBody JSONObject requestJson) {
+        JSONObject result = new JSONObject();
+        try {
+            Long accountId = requestJson.getLong("account_id");
+            if (Check.isNull(accountId)) {
+                throw new Exception("请填写账户id进行创建");
+            }
+            CtopOauthToken oauthToken = tokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+            Long campaign_id = requestJson.getLong("campaign_id");
+            if (Check.isNull(campaign_id)) {
+                throw new Exception("请填写需要创建的计划id");
+            }
+            JSONArray group_list = requestJson.getJSONArray("group_list");
+            if (Check.isNull(group_list)) {
+                throw new Exception("请填写需要创建的组信息");
+            }
+            executorService.submit(() -> kuaiShouCreateService.createUnitAndCreative(oauthToken, campaign_id, group_list));
+            result.put("code", 0);
+            result.put("message", "异步执行中,等待回调...");
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.put("code", -1);
+            result.put("message", e.getMessage());
+            JSONObject data = new JSONObject();
+            data.put("account_id", requestJson.getLong("account_id"));
+            result.put("data", data);
+
+        }
+        return result;
+
+    }
+
+
+}

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaiShouMaterialControer.java

@@ -27,7 +27,7 @@ import java.util.Map;
 @Slf4j
 @Api(tags = "快手-批量工具")
 @RestController
-@RequestMapping("/kuaishou/Ai")
+@RequestMapping("/kuaishou/material")
 public class KuaiShouMaterialControer {
     @Autowired
     private ICtopOauthTokenService tokenService;

+ 15 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaiShouCreateService.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.kuaishou.modules.ai.service;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import com.alibaba.fastjson.JSONArray;
+
+public interface IKuaiShouCreateService {
+    /**
+     * 创建组和计划
+     *
+     * @param oauthToken
+     * @param campaign_id
+     * @param group_list
+     */
+    void createUnitAndCreative(CtopOauthToken oauthToken, Long campaign_id, JSONArray group_list);
+}

+ 2 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouNewCreateCampaignServiceImpl.java

@@ -68,8 +68,8 @@ public class AiKuaishouNewCreateCampaignServiceImpl implements IAiKuaishouNewCre
 
         // 2.2 执行 素造的 视频拉取服务,时间过滤执行 yyyy-MM-dd HH:mm:ss
         // 时间差,单位为分钟
-        int timeStart = -10;
-        int timeEnd = -5;
+        int timeStart = -25;
+        int timeEnd = -20;
         Long now = System.currentTimeMillis();
         String startTime = DateUtils.formatDate(new Date(now + timeStart*60*1000),"yyyy-MM-dd HH:mm:ss");
         String endTime = DateUtils.formatDate(new Date(now + timeEnd*60*1000),"yyyy-MM-dd HH:mm:ss");

+ 421 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaiShouCreateServiceImpl.java

@@ -0,0 +1,421 @@
+package cn.com.ctop.kuaishou.modules.ai.service.impl;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.MaterialCutFrame;
+import cn.com.ctop.common.module.service.IMaterialCutFrameService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils2;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouCreateService;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
+import cn.com.ctop.kuaishou.modules.batch.service.*;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Map;
+
+@Service
+@Slf4j
+public class KuaiShouCreateServiceImpl implements IKuaiShouCreateService {
+    @Autowired
+    private IKuaishouInterfaceService iKuaishouInterfaceService;
+    @Autowired
+    private IKuaiShouGroupService groupService;
+    @Autowired
+    private IKuaiShouImageGetService imageGetService;
+    @Autowired
+    private IMaterialCutFrameService cutFrameService;
+    @Autowired
+    private IKuaiShouMaterialUploadService uploadService;
+
+    @Override
+    public void createUnitAndCreative(CtopOauthToken oauthToken, Long campaign_id, JSONArray group_list) {
+
+        JSONArray returnArr = new JSONArray();
+        try {
+            for (int i = 0; i < group_list.size(); i++) {
+                JSONObject groupCreateJson = group_list.getJSONObject(i);
+                if (Check.isNull(groupCreateJson)) {
+                    continue;
+                }
+                JSONObject createJson = new JSONObject();
+                createJson.put("advertiser_id", oauthToken.getAccountId());
+                createJson.put("campaign_id", campaign_id);
+                createJson.put("unit_name", groupCreateJson.getString("unit_name")); // 组名称
+                createJson.put("bid_type", groupCreateJson.getString("bid_type")); // 组名称
+                if (!Check.isNull(groupCreateJson.getInteger("use_app_market"))) {
+                    createJson.put("use_app_market", groupCreateJson.getInteger("use_app_market")); // 优先从系统应用商店下载
+                }
+
+                if (!Check.isNull(groupCreateJson.getJSONArray("app_store"))) {
+                    createJson.put("app_store", groupCreateJson.getJSONArray("app_store")); //应用商店列表
+                }
+                if (!Check.isNull(groupCreateJson.getLong("bid"))) {
+                    createJson.put("bid", groupCreateJson.getLong("bid")); //出价
+                }
+                if (!Check.isNull(groupCreateJson.getLong("cpa_bid"))) {
+                    createJson.put("cpa_bid", groupCreateJson.getLong("cpa_bid")); //出价
+                }
+                if (!Check.isNull(groupCreateJson.getInteger("smart_bid"))) {
+                    createJson.put("smart_bid", groupCreateJson.getInteger("smart_bid")); //优先低成本
+                }
+                if (!Check.isNull(groupCreateJson.getInteger("ocpx_action_type"))) {
+                    createJson.put("ocpx_action_type", groupCreateJson.getInteger("ocpx_action_type")); //优化目标
+                }
+                if (!Check.isNull(groupCreateJson.getInteger("deep_conversion_type"))) {
+                    createJson.put("deep_conversion_type", groupCreateJson.getInteger("deep_conversion_type")); //深度转化目标
+                }
+                if (!Check.isNull(groupCreateJson.getDouble("roi_ratio"))) {
+                    createJson.put("roi_ratio", groupCreateJson.getDouble("roi_ratio")); //付费ROI系数
+                }
+                if (!Check.isNull(groupCreateJson.getLong("deep_conversion_bid"))) {
+                    createJson.put("deep_conversion_bid", groupCreateJson.getLong("deep_conversion_bid")); //深度转化目标出价
+                }
+                if (!Check.isNull(groupCreateJson.getJSONArray("scene_id"))) {
+                    createJson.put("scene_id", groupCreateJson.getJSONArray("scene_id")); //资源位置
+                }
+                if (!Check.isNull(groupCreateJson.getInteger("unit_type"))) {
+                    createJson.put("unit_type", groupCreateJson.getInteger("unit_type")); //创意制作方式
+                }
+                if (!Check.isNull(groupCreateJson.getString("begin_time"))) {
+                    createJson.put("begin_time", groupCreateJson.getString("begin_time")); //投放开始时间
+                }
+                if (!Check.isNull(groupCreateJson.getString("end_time"))) {
+                    createJson.put("end_time", groupCreateJson.getString("end_time")); //投放结束时间
+                }
+                if (!Check.isNull(groupCreateJson.getString("schedule_time"))) {
+                    createJson.put("schedule_time", groupCreateJson.getString("schedule_time")); //投放时间段
+                }
+                if (!Check.isNull(groupCreateJson.getLong("day_budget"))) {
+                    createJson.put("day_budget", groupCreateJson.getLong("day_budget")); //投放时间段
+                }
+                if (!Check.isNull(groupCreateJson.getInteger("convert_id"))) {
+                    createJson.put("convert_id", groupCreateJson.getInteger("convert_id")); //投放时间段
+                }
+                if (!Check.isNull(groupCreateJson.getInteger("url_type"))) {
+                    createJson.put("url_type", groupCreateJson.getInteger("url_type")); //url类型
+                }
+                if (!Check.isNull(groupCreateJson.getInteger("web_uri_type"))) {
+                    createJson.put("web_uri_type", groupCreateJson.getInteger("web_uri_type")); //url类型
+                }
+                if (!Check.isNull(groupCreateJson.getString("url"))) {
+                    createJson.put("url", groupCreateJson.getString("url")); //url类型
+                }
+                if (!Check.isNull(groupCreateJson.getString("schema_uri"))) {
+                    createJson.put("schema_uri", groupCreateJson.getString("schema_uri")); //调起链接
+                }
+                if (!Check.isNull(groupCreateJson.getLong("app_id"))) {
+                    createJson.put("app_id", groupCreateJson.getLong("app_id")); //应用ID
+                }
+                if (!Check.isNull(groupCreateJson.getInteger("show_mode"))) {
+                    createJson.put("show_mode", groupCreateJson.getInteger("show_mode")); //创意展现方式
+                }
+                if (!Check.isNull(groupCreateJson.getInteger("speed"))) {
+                    createJson.put("speed", groupCreateJson.getInteger("speed")); //投放方式
+                }
+                if (!Check.isNull(groupCreateJson.getInteger("site_type"))) {
+                    createJson.put("site_type", groupCreateJson.getInteger("site_type")); //预约广告
+                }
+                if (!Check.isNull(groupCreateJson.getInteger("target_action_type")) || !Check.isNull(groupCreateJson.getString("code"))) {
+                    JSONObject gift_data = new JSONObject();
+                    if (!Check.isNull(groupCreateJson.getInteger("target_action_type"))) {
+                        gift_data.put("target_action_type", groupCreateJson.getInteger("target_action_type"));
+                    }
+                    if (!Check.isNull(groupCreateJson.getString("code"))) {
+                        gift_data.put("code", groupCreateJson.getString("code"));
+                    }
+                    createJson.put("gift_data", gift_data); //游戏礼包码
+                }
+                if (!Check.isNull(groupCreateJson.getBoolean("video_landing_page"))) {
+                    createJson.put("video_landing_page", groupCreateJson.getBoolean("video_landing_page")); //是否使用落地页前置功能
+                }
+                if (!Check.isNull(groupCreateJson.getBoolean("auto_target"))) {
+                    createJson.put("auto_target", groupCreateJson.getBoolean("auto_target")); //智能定向
+                }
+                if (!Check.isNull(groupCreateJson.getBoolean("auto_create_photo"))) {
+                    createJson.put("auto_create_photo", groupCreateJson.getBoolean("auto_create_photo")); //是否开启自动生成视频
+                }
+
+                if (!Check.isNull(groupCreateJson.getLong("item_id"))) {
+                    createJson.put("item_id", groupCreateJson.getLong("item_id")); //电商关联Id (小店通)
+                }
+                if (!Check.isNull(groupCreateJson.getLong("merchant_item_put_type"))) {
+                    createJson.put("merchant_item_put_type", groupCreateJson.getLong("merchant_item_put_type")); //电商广告投放类型(小店通)
+                }
+                if (!Check.isNull(groupCreateJson.getLong("fiction_id"))) {
+                    createJson.put("fiction_id", groupCreateJson.getLong("fiction_id")); //小说ID
+                }
+                if (!Check.isNull(groupCreateJson.getLong("template_id"))) {
+                    createJson.put("template_id", groupCreateJson.getLong("template_id")); //定向模板id
+                } else {
+                    JSONObject target = getTarget(groupCreateJson);
+                    if (!Check.isNull(target)) {
+                        createJson.put("getTarget", target); // 定向数据
+                    }
+                }
+                Map<String, Object> unitMap = iKuaishouInterfaceService.adUnitCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), createJson, 1);
+                JSONObject returnJson = new JSONObject();
+                returnJson.put("table_id", groupCreateJson.getLong("table_id"));
+                if ((Integer) unitMap.get("code") == 0) {
+                    Long unitId = (Long) unitMap.get("unitId");
+                    returnJson.put("unit_id", unitId);
+                    returnJson.put("code", 0);
+                    returnJson.put("message", "广告组创建成功");
+                    KuaiShouGroup group = groupService.selectGroupByUnitId(oauthToken.getAccountId(), unitId);
+                    if (!Check.isNull(group)) {
+                        returnJson.put("group_create_time", group.getGroupCreateTime());
+                    }
+                    Thread thread = new Thread() {
+                        @Override
+                        public void run() {
+                            createCreative(oauthToken, unitId, groupCreateJson.getJSONArray("creative_list"));
+                        }
+                    };
+                    thread.start();
+                } else {
+                    returnJson.put("code", -1);
+                    returnJson.put("message", unitMap.get("message"));
+                }
+                returnArr.add(returnJson);
+            }
+            callback("url", returnArr);
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("创建组错误!!!!!");
+        }
+    }
+
+
+    @Autowired
+    private IKuaiShouVideoGetService videoGetService;
+
+    /**
+     * 创建广告创意
+     *
+     * @param oauthToken
+     * @param unit_id
+     * @param creative_list
+     */
+    private void createCreative(CtopOauthToken oauthToken, Long unit_id, JSONArray creative_list) {
+        JSONArray returnArr = new JSONArray();
+        try {
+            for (int i = 0; i < creative_list.size(); i++) {
+                JSONObject creativeJson = creative_list.getJSONObject(i);
+                if (Check.isNull(creativeJson)) {
+                    continue;
+                }
+                JSONObject createJson = new JSONObject();
+                createJson.put("advertiser_id", oauthToken.getAccountId());
+                createJson.put("unit_id", unit_id);
+                createJson.put("creative_name", creativeJson.getString("creative_name")); // 创意名称
+                if (!Check.isNull(creativeJson.getLong("photo_id"))) {
+                    createJson.put("photo_id", creativeJson.getLong("photo_id"));  // 视频ID
+                }
+                KuaiShouVideoGet video = videoGetService.getVideoByPhotoId(creativeJson.getLong("photo_id"));
+                if (!Check.isNull(video)) {
+                    createJson.put("creative_material_type", video.getMaterialType());  // 素材类型
+                }
+                if (!Check.isNull(creativeJson.getString("action_bar_text"))) {
+                    createJson.put("action_bar_text", creativeJson.getString("action_bar_text"));  // 行动号召按钮文案
+                }
+                if (!Check.isNull(creativeJson.getString("description"))) {
+                    createJson.put("description", creativeJson.getString("description"));  // 广告语
+                }
+                if (!Check.isNull(creativeJson.getString("sticker_title"))) {
+                    createJson.put("sticker_title", creativeJson.getString("sticker_title"));  // 封面广告语标题
+                }
+                if (!Check.isNull(creativeJson.getString("overlay_type"))) {
+                    createJson.put("overlay_type", creativeJson.getString("overlay_type"));  // 贴纸样式类型
+                }
+                if (!Check.isNull(creativeJson.getString("expose_tag"))) {
+                    createJson.put("expose_tag", creativeJson.getString("expose_tag"));  // 广告标签
+                }
+                if (!Check.isNull(creativeJson.getJSONArray("new_expose_tag"))) {
+                    createJson.put("new_expose_tag", creativeJson.getJSONArray("new_expose_tag"));  // 广告标签2期
+                }
+                if (!Check.isNull(creativeJson.getLong("site_id"))) {
+                    createJson.put("site_id", creativeJson.getLong("site_id"));  // 安卓下载中间页ID
+                }
+                if (!Check.isNull(creativeJson.getString("click_track_url"))) {
+                    createJson.put("click_track_url", creativeJson.getString("click_track_url"));  // 第三方点击检测链接
+                }
+                if (!Check.isNull(creativeJson.getString("impression_url"))) {
+                    createJson.put("impression_url", creativeJson.getString("impression_url"));  // 第三方开始播放监测链接
+                }
+                if (!Check.isNull(creativeJson.getString("ad_photo_played_t3s_url"))) {
+                    createJson.put("ad_photo_played_t3s_url", creativeJson.getString("ad_photo_played_t3s_url"));  // 第三方有效播放监测链接
+                }
+                if (!Check.isNull(creativeJson.getString("actionbar_click_url"))) {
+                    createJson.put("actionbar_click_url", creativeJson.getString("actionbar_click_url"));  // 第三方点击按钮监测链接
+                }
+                if (!Check.isNull(creativeJson.getInteger("creative_category"))) {
+                    createJson.put("creative_category", creativeJson.getInteger("creative_category"));  // 创意分类
+                }
+                if (!Check.isNull(creativeJson.getJSONArray("creative_tag"))) {
+                    createJson.put("creative_tag", creativeJson.getJSONArray("creative_tag"));  // 创意标签
+                }
+                String image_md5 = creativeJson.getString("image_md5");
+                String imageToken = null;
+                if (!Check.isNull(image_md5)) {
+                    imageToken = getImageToken(image_md5, oauthToken.getAccountId(), oauthToken.getAccessToken());
+                }
+                if (!Check.isNull(imageToken)) {
+                    Integer is_sticky = creativeJson.getInteger("is_sticky"); // 是否便利贴
+                    if (is_sticky != 1) {
+                        createJson.put("image_token", imageToken); // 自定义创意封面token
+                    } else {
+                        JSONArray image_tokens = new JSONArray();
+                        image_tokens.add(imageToken);
+                        createJson.put("image_tokens", image_tokens); // 便利贴图片素材token
+                        if (!Check.isNull(creativeJson.getString("short_slogan"))) {
+                            createJson.put("short_slogan", creativeJson.getString("short_slogan"));  // 便利贴创意短广告语
+                        }
+                    }
+                }
+                Map<String, Object> creativeMap = iKuaishouInterfaceService.creativeCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), createJson, 1);
+                JSONObject returnJson = new JSONObject();
+                returnJson.put("table_id", creativeJson.getLong("table_id"));
+                if ((Integer) creativeMap.get("code") == 0) {
+                    Long creativeId = (Long) creativeMap.get("creativeId");
+                    returnJson.put("creative_id", creativeId);
+                    returnJson.put("unit_id", unit_id);
+                    returnJson.put("code", 0);
+                    returnJson.put("message", "广告创意创建成功");
+                } else {
+                    returnJson.put("code", -1);
+                    returnJson.put("message", creativeMap.get("message"));
+                }
+                returnArr.add(returnJson);
+            }
+            callback("url", returnArr);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void callback(String url, JSONArray requestArr) {
+        JSONObject requestJson = new JSONObject();
+        requestJson.put("callbackData", requestArr);
+        String s = HttpUtils2.httpPostRequest(url, requestJson, null);
+        JSONObject jsonObject = JSONObject.parseObject(s);
+        log.info("回调数据返回结果:{}", jsonObject);
+    }
+
+    private String getImageToken(String md5, Long accountId, String accessToken) {
+        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 {
+            MaterialCutFrame cutFrame = cutFrameService.selectByMd5(md5);
+            if (!Check.isNull(cutFrame)) {
+                imageToken = uploadService.kuauiShouImageUpload(cutFrame.getUrl(), md5, accountId, accessToken);
+            }
+
+        }
+        return imageToken;
+    }
+
+
+    private JSONObject getTarget(JSONObject unitJson) {
+        JSONObject target = new JSONObject();
+        if (!Check.isNull(unitJson.getJSONArray("region"))) {
+            target.put("region", unitJson.getJSONArray("region")); // 地域
+        }
+        if (!Check.isNull(unitJson.getJSONArray("district_ids"))) {
+            target.put("district_ids", unitJson.getJSONArray("district_ids")); // 商圈定向
+        }
+        if (!Check.isNull(unitJson.getInteger("user_type"))) {
+            target.put("user_type", unitJson.getInteger("user_type")); // 用户类型
+        }
+        if (!Check.isNull(unitJson.getInteger("age_min")) || !Check.isNull(unitJson.getInteger("age_max"))) {
+            JSONObject age = new JSONObject();
+            age.put("min", unitJson.getInteger("age_min"));
+            age.put("max", unitJson.getInteger("age_max"));
+            target.put("age", age); //自定义年龄段
+        }
+        if (!Check.isNull(unitJson.getJSONArray("ages_range"))) {
+            target.put("ages_range", unitJson.getInteger("ages_range")); // 固定年龄段
+        }
+        if (!Check.isNull(unitJson.getInteger("gender"))) {
+            target.put("gender", unitJson.getInteger("gender")); // 性别
+        }
+        if (!Check.isNull(unitJson.getInteger("platform_os"))) {
+            target.put("platform_os", unitJson.getInteger("platform_os")); // 操作系统
+        }
+        if (!Check.isNull(unitJson.getInteger("android_osv"))) {
+            target.put("android_osv", unitJson.getInteger("android_osv")); // Android版本
+        }
+        if (!Check.isNull(unitJson.getInteger("ios_osv"))) {
+            target.put("ios_osv", unitJson.getInteger("ios_osv")); // Android版本
+        }
+        if (!Check.isNull(unitJson.getInteger("network"))) {
+            target.put("network", unitJson.getInteger("network")); // 网络环境
+        }
+        if (!Check.isNull(unitJson.getJSONArray("device_brand"))) {
+            target.put("device_brand", unitJson.getJSONArray("device_brand")); // 设备品牌
+        }
+        if (!Check.isNull(unitJson.getJSONArray("device_price"))) {
+            target.put("device_price", unitJson.getJSONArray("device_price")); // 设备价格
+        }
+        if (!Check.isNull(unitJson.getInteger("business_interest_type"))) {
+            target.put("business_interest_type", unitJson.getInteger("business_interest_type")); // 商业兴趣类型
+        }
+        if (!Check.isNull(unitJson.getJSONArray("business_interest"))) {
+            target.put("business_interest", unitJson.getJSONArray("business_interest")); // 商业兴趣
+        }
+        if (!Check.isNull(unitJson.getJSONArray("fans_star"))) {
+            target.put("fans_star", unitJson.getJSONArray("fans_star")); // 网红粉丝
+        }
+        if (!Check.isNull(unitJson.getJSONArray("interest_video"))) {
+            target.put("interest_video", unitJson.getJSONArray("interest_video")); // 兴趣视频用户
+        }
+        if (!Check.isNull(unitJson.getJSONArray("app_interest"))) {
+            target.put("app_interest", unitJson.getJSONArray("app_interest")); // APP行为-按分类
+        }
+        if (!Check.isNull(unitJson.getJSONArray("app_ids"))) {
+            target.put("app_ids", unitJson.getJSONArray("app_ids")); // APP行为-按APP名称
+        }
+        if (!Check.isNull(unitJson.getInteger("filter_converted_level"))) {
+            target.put("filter_converted_level", unitJson.getInteger("filter_converted_level")); // APP行为-按APP名称
+        }
+        if (!Check.isNull(unitJson.getJSONArray("population"))) {
+            target.put("population", unitJson.getJSONArray("population")); // 人群包定向
+        }
+        if (!Check.isNull(unitJson.getJSONArray("exclude_population"))) {
+            target.put("exclude_population", unitJson.getJSONArray("exclude_population")); // 人群包排除
+        }
+        if (!Check.isNull(unitJson.getJSONArray("paid_audience"))) {
+            target.put("paid_audience", unitJson.getJSONArray("paid_audience")); // 付费人群包id
+        }
+        if (!Check.isNull(unitJson.getInteger("is_open")) && unitJson.getInteger("is_open") == 1) {
+            JSONObject intelli_extend = new JSONObject();
+            intelli_extend.put("is_open", unitJson.getInteger("is_open")); // 开启智能扩量
+            if (!Check.isNull(unitJson.getInteger("no_age_break"))) {
+                intelli_extend.put("no_age_break", unitJson.getInteger("no_age_break")); //  不可突破年龄
+            }
+            if (!Check.isNull(unitJson.getInteger("no_gender_break"))) {
+                intelli_extend.put("no_gender_break", unitJson.getInteger("no_gender_break")); //  不可突破性别
+            }
+            if (!Check.isNull(unitJson.getInteger("no_area_break"))) {
+                intelli_extend.put("no_area_break", unitJson.getInteger("no_area_break")); //  不可突破地域
+            }
+            target.put("intelli_extend", intelli_extend); // 智能扩量
+
+        }
+        if (Check.isNull(unitJson.getJSONObject("behavior_interest"))) {
+            // TODO 只是单独结构体 后续需要优化
+            target.put("behavior_interest", unitJson.getJSONObject("behavior_interest")); // 智能扩量
+        }
+        return target;
+    }
+}

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

@@ -19,4 +19,6 @@ public interface IKuaiShouCampaignService extends IService<KuaiShouCampaign> {
     List<JSONArray> getJsonArrByAccount(Long accountId, int idSize);
 
     JSONArray queryCampaignIdByAccountId(Long accountId);
+
+    KuaiShouCampaign getCampaignByAccountAndCampaign(Long accountId, Long campaignId);
 }

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

@@ -34,4 +34,6 @@ public interface IKuaiShouGroupService extends IService<KuaiShouGroup> {
     void getGroupListByPage(String accessToken, Long accountId, Long campaignId, int page);
 
     List<KuaiShouGroup> queryUnitInfoByCampaignId(Long accountId, Long campaignId);
+
+    KuaiShouGroup selectGroupByUnitId(Long accountId, Long unitId);
 }

+ 11 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouCampaignServiceImpl.java

@@ -30,7 +30,6 @@ public class KuaiShouCampaignServiceImpl extends ServiceImpl<KuaiShouCampaignMap
     }
 
 
-
     /**
      * 获取创意
      *
@@ -66,4 +65,15 @@ public class KuaiShouCampaignServiceImpl extends ServiceImpl<KuaiShouCampaignMap
         return campaignMapper.queryCampaignIdByAccountId(accountId);
     }
 
+    @Override
+    public KuaiShouCampaign getCampaignByAccountAndCampaign(Long accountId, Long campaignId) {
+        QueryWrapper<KuaiShouCampaign> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("account_id", accountId);
+        queryWrapper.eq("campaign_id", campaignId);
+        queryWrapper.orderByDesc("create_time");
+        queryWrapper.last("limit 1");
+        KuaiShouCampaign campaign = campaignMapper.selectOne(queryWrapper);
+        return campaign;
+    }
+
 }

+ 11 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouGroupServiceImpl.java

@@ -117,6 +117,17 @@ public class KuaiShouGroupServiceImpl extends ServiceImpl<KuaiShouGroupMapper, K
         return groupMapper.queryUnitInfoByCampaignId(accountId, campaignId);
     }
 
+    @Override
+    public KuaiShouGroup selectGroupByUnitId(Long accountId, Long unitId) {
+        QueryWrapper<KuaiShouGroup> groupQueryWrapper = new QueryWrapper<>();
+        groupQueryWrapper.eq("account_id", accountId);
+        groupQueryWrapper.eq("unit_id", unitId);
+        groupQueryWrapper.orderByDesc("create_time");
+        groupQueryWrapper.last("limit 1");
+        KuaiShouGroup group = groupMapper.selectOne(groupQueryWrapper);
+        return group;
+    }
+
 
     @Override
     public void getGroupByUnitId(String accessToken, Long accountId, Long unitId) {

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

@@ -959,19 +959,9 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     returnMap.put("campaignId", campaignId);
                     returnMap.put("success", true);
                     // 创建成功 拉取广告组信息
+                    Thread.sleep(100);
+                    getCampaign(accessToken, advertiserId, campaignId);
 
-                    Thread thread = new Thread() {
-                        @Override
-                        public void run() {
-                            try {
-                                Thread.sleep(500);
-                            } catch (InterruptedException e) {
-                                e.printStackTrace();
-                            }
-                            getCampaign(accessToken, advertiserId, campaignId);
-                        }
-                    };
-                    thread.start();
 
                 } else {
                     log.error("创建广告计划失败,advertiser_id:{},返回信息:{}", advertiserId, resultJson);
@@ -1028,21 +1018,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     JSONObject dataJson = resultJson.getJSONObject("data");
                     if (!Check.isNull(dataJson)) {
                         Long unitId = dataJson.getLong("unit_id");
-
-                        Thread thread = new Thread() {
-                            @Override
-                            public void run() {
-                                try {
-                                    Thread.sleep(500);
-                                    getKuaiShouGroupService.getGroupByUnitId(accessToken, advertiserId, unitId);
-                                } catch (InterruptedException e) {
-                                    e.printStackTrace();
-                                }
-
-                            }
-
-                        };
-                        thread.start();
+                        Thread.sleep(100);
+                        getKuaiShouGroupService.getGroupByUnitId(accessToken, advertiserId, unitId);
                         returnMap.put("code", 0);
                         returnMap.put("message", "success");
                         returnMap.put("unitId", unitId);
@@ -2124,7 +2101,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
                 log.error("快手创建广告创意返回内容为空,advertiser_id:{},入参:{}", advertiserId, requestJson);
                 returnMap.put("code", -1);
-                returnMap.put("message", "上传图片异常");
+                returnMap.put("message", "result is null");
                 returnMap.put("desc", "result is null");
                 returnMap.put("success", false);
             }

+ 16 - 12
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/RuleKuaiShouPlanServiceImpl.java

@@ -166,20 +166,24 @@ public class RuleKuaiShouPlanServiceImpl extends ServiceImpl<RuleDatePlanKuaisho
             wrapper.eq("unit_id",unitDetail.getLong("unit_id"));
             KuaiShouGroup group = kuaiShouGroupService.getOne(wrapper);
             if(group!=null){
-                unit.setId(unitDetail.getLong("unit_id"));
-                unit.setAccountId(accountId);
-                unit.setPlanId(unitDetail.getLong("campaign_id"));
-                unit.setUnitId(unitDetail.getLong("unit_id"));
-                unit.setUnitName(unitDetail.getString("unit_name"));
-                unit.setCharge(unitDetail.getBigDecimal("charge"));
-                //未知优化目标数据存空
-                if(group.getOcpxActionType()!=0){
-                    unit.setConvertNum(handleConvertNum(group.getOcpxActionType(),unitDetail));
-                    if(null!=unit.getConvertNum()&&unit.getConvertNum()!=0){
-                        unit.setConvertCost(unitDetail.getBigDecimal("charge").divide(BigDecimal.valueOf(unit.getConvertNum()), 2, RoundingMode.HALF_UP));
+                Integer status = group.getStatus();
+                Integer putStatus = group.getPutStatus();
+                if((status == 20 || status == 19) && putStatus == 1){
+                    unit.setId(unitDetail.getLong("unit_id"));
+                    unit.setAccountId(accountId);
+                    unit.setPlanId(unitDetail.getLong("campaign_id"));
+                    unit.setUnitId(unitDetail.getLong("unit_id"));
+                    unit.setUnitName(unitDetail.getString("unit_name"));
+                    unit.setCharge(unitDetail.getBigDecimal("charge"));
+                    //未知优化目标数据存空
+                    if(group.getOcpxActionType()!=0){
+                        unit.setConvertNum(handleConvertNum(group.getOcpxActionType(),unitDetail));
+                        if(null!=unit.getConvertNum()&&unit.getConvertNum()!=0){
+                            unit.setConvertCost(unitDetail.getBigDecimal("charge").divide(BigDecimal.valueOf(unit.getConvertNum()), 2, RoundingMode.HALF_UP));
+                        }
                     }
+                    batch.add(unit);
                 }
-                batch.add(unit);
             }
 
         });