Quellcode durchsuchen

项目自动化调试,添加定时任务

zhaoxian vor 4 Jahren
Ursprung
Commit
0890fd402d

+ 61 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouAiProjectCreativeJob.java

@@ -0,0 +1,61 @@
+package cn.com.ctop.job.kuaishou.handler;
+
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils2;
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouProjectStrategy;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouProjectStrategyService;
+import com.alibaba.fastjson.JSONObject;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author syh
+ * 自动投放定时任务
+ */
+@Component
+@Slf4j
+public class KuaishouAiProjectCreativeJob {
+
+    @Value("${xxl-job.requestUrl}")
+    private String jobUrl;
+
+    @Autowired
+    private IKuaishouProjectStrategyService kuaishouProjectStrategyService;
+
+    /**
+     * 项目自动化
+     */
+    @XxlJob("kuaishouAiProjectCreativeJob")
+    public void execute() {
+        List<KuaishouProjectStrategy> strategies = kuaishouProjectStrategyService.getAllEffectStrategy();
+        if (null == strategies || strategies.isEmpty()) {
+            return;
+        }
+        String url = jobUrl + "/jeecg-boot/ai/projectCreate/projectAutomaticCreates";
+        for (KuaishouProjectStrategy strategy : strategies) {
+            Map<String, Object> requestMap = new HashMap<>();
+            requestMap.put("id", strategy.getId());
+            //  operationType 1检查反馈,2创建时信息
+            requestMap.put("operationType", 2);
+            String result = HttpUtils2.httpGet(url, requestMap, null);
+            JSONObject jsonObject = JSONObject.parseObject(result);
+            if (!Check.isNull(jsonObject)) {
+                Integer code = jsonObject.getInteger("code");
+                if (code == 200) {
+                    log.info("项目自动化创建执行中,projectId:{}", strategy.getProjectId());
+                } else {
+                    log.error("项目自动化创建执行失败,projectId:{}", strategy.getProjectId());
+                }
+            } else {
+                log.error("项目自动化创建返回结果为空,projectId:{}", strategy.getProjectId());
+            }
+        }
+    }
+}

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouProjectStrategyMapper.java

@@ -24,4 +24,6 @@ public interface KuaishouProjectStrategyMapper extends BaseMapper<KuaishouProjec
     JSONObject queryAccountAll(JSONObject data);
 
     Integer checkProjectisOpen(Long projectId);
+
+    List<KuaishouProjectStrategy> getAllEffectStrategy();
 }

+ 4 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouProjectStrategyMapper.xml

@@ -159,5 +159,9 @@
         LIMIT 1
     </select>
 
+    <select id="getAllEffectStrategy" resultType="cn.com.ctop.kuaishou.modules.ai.entity.KuaishouProjectStrategy">
+        SELECT id,project_id FROM ctop_ai_kuaishou_project_strategy WHERE data_status = 1
+    </select>
+
 
 </mapper>

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

@@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.common.api.vo.Result;
 
+import java.util.List;
+
 /**
  * 自动投放-项目策略表
  *
@@ -21,4 +23,6 @@ public interface IKuaishouProjectStrategyService extends IService<KuaishouProjec
     Result<Object> queryMatchResult(Long projectId,Integer pageNo, Integer pageSize);
 
     boolean checkProjectisOpen(Long projectId);
+
+    List<KuaishouProjectStrategy> getAllEffectStrategy();
 }

+ 9 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouProjectCreateCreativeServiceImpl.java

@@ -1257,8 +1257,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
     /**
      * @param wildcard 计划名称/组名称
      * @param strategy 账户id
-     * @return
-     * 通配符命名规则
+     * @return 通配符命名规则
      * 日期、渠道号、横竖版(视频素材的横版竖版)、时分、广告位置、素材名称、应用包名、创意制作方式(自定义、程序化)
      */
     private String getName(String wildcard, KuaishouProjectStrategy strategy, Integer createType, String materialName, String type, Long campaignId, Long appId, Integer materialType) {
@@ -1275,10 +1274,14 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
             }
         }
         if (wildcard.contains("{{横竖版}}")) {
-            if (materialType == 1) {
-                wildcard = wildcard.replace("{{横竖版}}", "竖版视频");
-            } else if (materialType == 2) {
-                wildcard = wildcard.replace("{{横竖版}}", "横版视频");
+            if (!Check.isNull(materialType)) {
+                if (materialType == 1) {
+                    wildcard = wildcard.replace("{{横竖版}}", "竖版视频");
+                } else if (materialType == 2) {
+                    wildcard = wildcard.replace("{{横竖版}}", "横版视频");
+                } else {
+                    wildcard = wildcard.replace("{{横竖版}}", "");
+                }
             } else {
                 wildcard = wildcard.replace("{{横竖版}}", "");
             }

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

@@ -2,11 +2,13 @@ package cn.com.ctop.kuaishou.modules.ai.service.impl;
 
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountLevelOperationRecord;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouProjectStrategy;
 import cn.com.ctop.kuaishou.modules.ai.mapper.AiKuaishouAccountLevelOperationRecordMapper;
 import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouProjectStrategyMapper;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouProjectStrategyService;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
@@ -68,4 +70,9 @@ public class KuaishouProjectStrategyServiceImpl extends ServiceImpl<KuaishouProj
         Integer num = kuaishouProjectStrategyMapper.checkProjectisOpen(projectId);
         return  num<=0;
     }
+
+    @Override
+    public List<KuaishouProjectStrategy> getAllEffectStrategy() {
+        return kuaishouProjectStrategyMapper.getAllEffectStrategy();
+    }
 }