Ver Fonte

Merge branch 'kuaishou-ai-advertising' of http://git.tjyourong.com.cn/ctop/adsp-boot into kuaishou-ai-advertising

liyuyi@c-top.com.cn há 4 anos atrás
pai
commit
a33ac68e6d

+ 0 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiStrategyServiceImpl.java

@@ -16,7 +16,6 @@ import org.jeecg.modules.ads.service.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.io.Serializable;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaishouStrategyController.java

@@ -117,7 +117,7 @@ public class KuaishouStrategyController {
     @AutoLog(value = "kuaishou.modules.batch-优化评估策略表-编辑")
     @ApiOperation(value = "kuaishou.modules.batch-优化评估策略表-编辑", notes = "kuaishou.modules.batch-优化评估策略表-编辑")
     @PostMapping(value = "/edit")
-    public Result<Object> edit(@RequestBody JSONArray ids) {
+    public Result<?> edit(@RequestBody JSONArray ids) {
         try {
             return kuaishouStrategyService.shutDownPlan(ids);
         } catch (Exception e) {

+ 4 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaishouStrategyMapper.java

@@ -1,8 +1,11 @@
 package cn.com.ctop.kuaishou.modules.batch.mapper;
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
+import java.util.List;
+
 /**
  * kuaishou.modules.batch-优化评估策略表
  *
@@ -12,4 +15,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface KuaishouStrategyMapper extends BaseMapper<KuaishouStrategy> {
 
+    List<JSONObject> queryPlanIdsByStrategyId(Long id);
 }

+ 9 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouStrategyMapper.xml

@@ -1,5 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouStrategyMapper">
-
+    <select id="queryPlanIdsByStrategyId" parameterType="java.util.Map" resultType="com.alibaba.fastjson.JSONObject">
+         select
+          account_id as accountId,
+          campaign_id as campaignId,
+          unit_id as unitId,
+          creative_id as creativeId
+          from ctop_ai_kuaishou_strategy_map_creative
+         where strategy_id = #{id}
+    </select>
 </mapper>

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

@@ -24,16 +24,18 @@ public interface IKuaishouStrategyService extends IService<KuaishouStrategy> {
      * @throws
      * @author ZHAOXA
      */
-    Result<Object> shutDownPlan(JSONArray ids);
+    Result<?> shutDownPlan(JSONArray ids);
 
     /**
      * 创建快手广告计划
      *
      * @param oauthToken token签名
-     * @param groupJson  广告计划
+     * @param data  广告计划
      * @return void
      * @throws
      * @author ZHAOXA
      */
     Map<String, Object> createPlanLevelStrategy(CtopOauthToken oauthToken, JSONObject data);
+
+    JSONArray createGroupLevelStrategy(CtopOauthToken oauthToken, JSONObject data);
 }

+ 38 - 10
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouStrategyServiceImpl.java

@@ -24,7 +24,6 @@ import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -40,6 +39,8 @@ import java.util.Map;
 @Service
 public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMapper, KuaishouStrategy> implements IKuaishouStrategyService {
     @Autowired
+    private KuaishouStrategyMapper kuaishouStrategyMapper;
+    @Autowired
     private IKuaishouInterfaceService kuaishouInterfaceService;
     @Autowired
     private IKuaiShouImageGetService imageGetService;
@@ -52,26 +53,53 @@ public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMap
 
     //TODO
     @Override
-    public Result<Object> shutDownPlan(JSONArray ids) {
+    public Result<?> shutDownPlan(JSONArray ids) {
+        JSONObject obj = new JSONObject();
         LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
-        String userId = sysUser.getId();
+        String userId = null;
+        if (!Check.isNull(sysUser)) {
+            userId = sysUser.getId();
+        }
+        userId = "test";
         for (Object id : ids) {
-            List<JSONObject> list = new ArrayList<>();
+            boolean flag = true;
+            List<JSONObject> list = kuaishouStrategyMapper.queryPlanIdsByStrategyId(Long.valueOf(id.toString()));
             CtopOauthToken token = tokenService.getTokenByAccountId(list.get(0).getLong("accountId"));
             for (JSONObject object : list) {
-                kuaiShouUpdateService.updateCampaignStatus(token.getAccessToken(), token.getAccountId(), object.getLong("campaignId"), NoEn.NO2.valueInt(), userId);
+                if (flag) {
+                    flag = EditAdvertisingPlanStatus(token.getAccessToken(), token.getAccountId(), object.getLong("campaignId"), NoEn.NO2.valueInt(), userId, NoEn.NO1.valueInt());
+                } else {
+                    EditAdvertisingPlanStatus(token.getAccessToken(), token.getAccountId(), object.getLong("campaignId"), NoEn.NO2.valueInt(), userId, NoEn.NO1.valueInt());
+                }
+            }
+            if (flag) {
+                obj.put(id.toString(), true);
+            } else {
+                obj.put(id.toString(), false);
+            }
+        }
+        return Result.ok(obj);
+    }
+
+    private boolean EditAdvertisingPlanStatus(String token, Long accountId, Long campaignId, Integer state, String userId, int count) {
+        Map<String, Object> map = kuaiShouUpdateService.updateCampaignStatus(token, accountId, campaignId, state, userId);
+        boolean success = (boolean) map.get("success");
+        if (!success) {
+            if (count < 3) {
+                return EditAdvertisingPlanStatus(token, accountId, campaignId, state, userId, ++count);
             }
         }
-        return null;
+        return success;
     }
 
     /**
      * @param oauthToken token签名
-     * @param groupJson  广告计划
+     * @param data  广告计划
      * @return void
      * @throws
      * @author ZHAOXA
      */
+    @Override
     public Map<String, Object> createPlanLevelStrategy(CtopOauthToken oauthToken, JSONObject data) {
         JSONObject planJson = new JSONObject();
         /**计划类型
@@ -97,6 +125,7 @@ public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMap
         return kuaishouInterfaceService.campaignCreate(oauthToken.getAccessToken(), oauthToken.getAccountId(), planJson);
     }
 
+    @Override
     public JSONArray createGroupLevelStrategy(CtopOauthToken oauthToken, JSONObject data) {
         JSONArray resultArr = new JSONArray();
         JSONArray groupInfo = data.getJSONArray("groupInfo");
@@ -379,9 +408,8 @@ public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMap
             if (!Check.isNull(groupJson.getInteger("noAreaBreak"))) {
                 intelliExtendJson.put("no_area_break", groupJson.getInteger("noAreaBreak"));
             }
-            if (!Check.isNull(intelliExtendJson)) {
-                targetJson.put("intelli_extend", intelliExtendJson);
-            }
+            targetJson.put("intelli_extend", intelliExtendJson);
+
         }
         // APP行为-按分类
         if (!Check.isNull(groupJson.getJSONArray("appInterest"))) {