Browse Source

Merge branch 'master' into kuaishou-ai-advertising

syh 4 years ago
parent
commit
f275154301

+ 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-优化评估策略表-编辑")
     @AutoLog(value = "kuaishou.modules.batch-优化评估策略表-编辑")
     @ApiOperation(value = "kuaishou.modules.batch-优化评估策略表-编辑", notes = "kuaishou.modules.batch-优化评估策略表-编辑")
     @ApiOperation(value = "kuaishou.modules.batch-优化评估策略表-编辑", notes = "kuaishou.modules.batch-优化评估策略表-编辑")
     @PostMapping(value = "/edit")
     @PostMapping(value = "/edit")
-    public Result<Object> edit(@RequestBody JSONArray ids) {
+    public Result<?> edit(@RequestBody JSONArray ids) {
         try {
         try {
             return kuaishouStrategyService.shutDownPlan(ids);
             return kuaishouStrategyService.shutDownPlan(ids);
         } catch (Exception e) {
         } 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;
 package cn.com.ctop.kuaishou.modules.batch.mapper;
 
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 
+import java.util.List;
+
 /**
 /**
  * kuaishou.modules.batch-优化评估策略表
  * kuaishou.modules.batch-优化评估策略表
  *
  *
@@ -12,4 +15,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
  */
 public interface KuaishouStrategyMapper extends BaseMapper<KuaishouStrategy> {
 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"?>
 <?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">
 <!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">
 <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>
 </mapper>

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

@@ -24,7 +24,7 @@ public interface IKuaishouStrategyService extends IService<KuaishouStrategy> {
      * @throws
      * @throws
      * @author ZHAOXA
      * @author ZHAOXA
      */
      */
-    Result<Object> shutDownPlan(JSONArray ids);
+    Result<?> shutDownPlan(JSONArray ids);
 
 
     /**
     /**
      * 创建快手广告计划
      * 创建快手广告计划

+ 33 - 6
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.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.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
@@ -40,6 +39,8 @@ import java.util.Map;
 @Service
 @Service
 public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMapper, KuaishouStrategy> implements IKuaishouStrategyService {
 public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMapper, KuaishouStrategy> implements IKuaishouStrategyService {
     @Autowired
     @Autowired
+    private KuaishouStrategyMapper kuaishouStrategyMapper;
+    @Autowired
     private IKuaishouInterfaceService kuaishouInterfaceService;
     private IKuaishouInterfaceService kuaishouInterfaceService;
     @Autowired
     @Autowired
     private IKuaiShouImageGetService imageGetService;
     private IKuaiShouImageGetService imageGetService;
@@ -52,17 +53,43 @@ public class KuaishouStrategyServiceImpl extends ServiceImpl<KuaishouStrategyMap
 
 
     //TODO
     //TODO
     @Override
     @Override
-    public Result<Object> shutDownPlan(JSONArray ids) {
+    public Result<?> shutDownPlan(JSONArray ids) {
+        JSONObject obj = new JSONObject();
         LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         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) {
         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"));
             CtopOauthToken token = tokenService.getTokenByAccountId(list.get(0).getLong("accountId"));
             for (JSONObject object : list) {
             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;
     }
     }
 
 
     /**
     /**