Bladeren bron

智能托管

yumeng 3 jaren geleden
bovenliggende
commit
f217ef5783

+ 17 - 7
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/hosting/controller/KuaishouHostingTaskController.java

@@ -34,6 +34,8 @@ import java.net.URLDecoder;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * 智能托管-任务详情
@@ -49,6 +51,7 @@ import java.util.Map;
 public class KuaishouHostingTaskController {
     @Autowired
     private IKuaishouHostingTaskService kuaishouHostingTaskService;
+    private static ExecutorService createExecutorService = Executors.newFixedThreadPool(5);
 
     @PostMapping(value = "/submitTask")
     public Result<Object> submitTask(@RequestBody JSONObject requestJson) {
@@ -65,6 +68,7 @@ public class KuaishouHostingTaskController {
             if (Check.isNull(videoArray)) {
                 throw new Exception("请传入需创建的素材");
             }
+
             kuaishouHostingTaskService.submitTask(templateId, videoArray);
 
             result.success("添加成功!");
@@ -77,21 +81,27 @@ public class KuaishouHostingTaskController {
 
 
     @GetMapping(value = "/createHosting")
-    public Result<Object> createHosting(Long id) {
-        Result<Object> result = new Result<>();
+    public JSONObject createHosting(Long id) {
+        JSONObject returnJson = new JSONObject();
         try {
             if (Check.isNull(id)) {
                 throw new Exception("入参不能为空");
             }
             kuaishouHostingTaskService.updateStatusById(id, 2, "智能托管计划创建中");
-            kuaishouHostingTaskService.createHosting(id);
-
-            result.success("添加成功!");
+            createExecutorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    kuaishouHostingTaskService.createHosting(id);
+                }
+            });
+            returnJson.put("code", 0);
+            returnJson.put("message", "提交成功");
         } catch (Exception e) {
             log.error(e.getMessage(), e);
-            result.error500(e.getMessage());
+            returnJson.put("code", -1);
+            returnJson.put("message", "提交失败");
         }
-        return result;
+        return returnJson;
     }
 
 

+ 49 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/hosting/controller/KuaishouHostingTemplateController.java

@@ -1,11 +1,15 @@
 package cn.com.ctop.kuaishou.modules.hosting.controller;
 
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import cn.com.ctop.kuaishou.modules.hosting.entity.KuaishouHostingTemplate;
 import cn.com.ctop.kuaishou.modules.hosting.service.IKuaishouHostingTemplateService;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xxl.job.core.util.DateUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -29,6 +33,7 @@ import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -46,6 +51,49 @@ import java.util.Map;
 public class KuaishouHostingTemplateController {
     @Autowired
     private IKuaishouHostingTemplateService kuaishouHostingTemplateService;
+    @Autowired
+    private IKuaiShouVideoGetService videoGetService;
+
+
+    /**
+     * 获取视频列表
+     *
+     * @return
+     */
+    @GetMapping(value = "/getVideoList")
+    public Result<IPage<KuaiShouVideoGet>> getVideoList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                        Long accountId,
+                                                        String startDate,
+                                                        String endDate, String name) {
+        Result<IPage<KuaiShouVideoGet>> result = new Result<>();
+        try {
+
+            QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("account_id", accountId);
+            queryWrapper.eq("status", 0);
+            if (!Check.isNull(startDate) && !Check.isNull(endDate)) {
+                Date start = DateUtil.parseDate(startDate + " :00:00:01");
+                Date end = DateUtil.parseDate(endDate + " :23:59:59");
+                queryWrapper.between("stat_date", start, end);
+            }
+            if (!Check.isNull(name)) {
+                queryWrapper.like("photo_name", name);
+            }
+            queryWrapper.orderByDesc("stat_date");
+            Page<KuaiShouVideoGet> page = new Page<>(pageNo, pageSize);
+            IPage<KuaiShouVideoGet> pageList = videoGetService.page(page, queryWrapper);
+            result.setSuccess(true);
+            result.setResult(pageList);
+            return result;
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+        }
+
+        return result;
+    }
+
 
     /**
      * 分页列表查询
@@ -99,7 +147,7 @@ public class KuaishouHostingTemplateController {
      * @return
      */
     @ApiOperation(value = "智能托管模板-编辑", notes = "智能托管模板-编辑")
-    @PutMapping(value = "/edit")
+    @PostMapping(value = "/edit")
     public Result<KuaishouHostingTemplate> edit(@RequestBody KuaishouHostingTemplate kuaishouHostingTemplate) {
         Result<KuaishouHostingTemplate> result = new Result<KuaishouHostingTemplate>();
         KuaishouHostingTemplate kuaishouHostingTemplateEntity = kuaishouHostingTemplateService.getById(kuaishouHostingTemplate.getId());

+ 43 - 9
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/hosting/service/impl/KuaishouHostingTaskServiceImpl.java

@@ -51,6 +51,27 @@ public class KuaishouHostingTaskServiceImpl extends ServiceImpl<KuaishouHostingT
         if (Check.isNull(template)) {
             throw new Exception("未匹配到模板信息");
         }
+
+        //  投放时段前端传值问题,需要单独处理
+        String schedule = template.getSchedule();
+        JSONArray scheduleArray = new JSONArray();
+        if (!Check.isNull(schedule)) {
+            JSONArray array = JSONArray.parseArray(schedule);
+            if (!Check.isNull(array)) {
+                for (int i = 0; i < array.size(); i++) {
+                    JSONArray jsonArray = array.getJSONArray(i);
+                    JSONArray addArray = new JSONArray();
+                    for (int j = 0; j < jsonArray.size(); j++) {
+                        Integer value = jsonArray.getInteger(j);
+                        if (Check.isNull(value)) {
+                            continue;
+                        }
+                        addArray.add(value);
+                    }
+                    scheduleArray.add(addArray);
+                }
+            }
+        }
         List<List<Object>> videoList = Lists.partition(videoArray, template.getVideoCount());
         List<KuaishouHostingTask> addList = new ArrayList<>();
         for (int i = 0; i < videoList.size(); i++) {
@@ -88,7 +109,7 @@ public class KuaishouHostingTaskServiceImpl extends ServiceImpl<KuaishouHostingT
             task.setClickUrl(template.getClickUrl());
             task.setActionbarClickUrl(template.getActionbarClickUrl());
             task.setAutoCreatePhoto(template.getAutoCreatePhoto());
-            task.setSchedule(template.getSchedule());
+            task.setSchedule(scheduleArray.toJSONString());
             task.setDayBudget(template.getDayBudget());
             task.setOcpxActionType(template.getOcpxActionType());
             task.setCpaBid(template.getCpaBid());
@@ -198,16 +219,21 @@ public class KuaishouHostingTaskServiceImpl extends ServiceImpl<KuaishouHostingT
             if (!Check.isNull(task.getActionbarClickUrl())) {
                 requestJson.put("actionbar_click_url", task.getActionbarClickUrl());
             }
-            if (task.getAutoCreatePhoto() == 1) {
-                requestJson.put("auto_create_photo", true);
+            if (!Check.isNull(task.getAutoCreatePhoto())) {
+                if (task.getAutoCreatePhoto() == 1) {
+                    requestJson.put("auto_create_photo", true);
+                } else {
+                    requestJson.put("auto_create_photo", false);
+                }
             } else {
                 requestJson.put("auto_create_photo", false);
             }
+
             Long begin_time = System.currentTimeMillis();
             requestJson.put("begin_time", begin_time);
             requestJson.put("end_time", 0);
             if (!Check.isNull(task.getSchedule())) {
-                requestJson.put("schedule", JSONArray.parseArray(task.getSchedule()));
+                requestJson.put("schedule", task.getSchedule());
             }
             requestJson.put("day_budget", task.getDayBudget());
             requestJson.put("ocpx_action_type", task.getOcpxActionType());
@@ -272,10 +298,18 @@ public class KuaishouHostingTaskServiceImpl extends ServiceImpl<KuaishouHostingT
             Integer maxAge = task.getMaxAge();
             JSONArray ageArray = new JSONArray();
             if (!Check.isNull(minAge) && !Check.isNull(maxAge)) {
-                JSONObject ageJson = new JSONObject();
-                ageJson.put("min", minAge);
-                ageJson.put("max", maxAge);
-                ageArray.add(ageJson);
+                if (maxAge != -1 && minAge != -1) {
+                    JSONObject ageJson = new JSONObject();
+                    ageJson.put("min", minAge);
+                    ageJson.put("max", maxAge);
+                    ageArray.add(ageJson);
+                } else {
+                    String agesRange = task.getAgesRange();
+                    JSONArray agesRangeArray = JSONArray.parseArray(agesRange);
+                    if (!Check.isNull(agesRangeArray)) {
+                        ageArray = getAgeArray(agesRangeArray);
+                    }
+                }
             } else {
                 String agesRange = task.getAgesRange();
                 JSONArray agesRangeArray = JSONArray.parseArray(agesRange);
@@ -360,7 +394,7 @@ public class KuaishouHostingTaskServiceImpl extends ServiceImpl<KuaishouHostingT
                     }
                     hostingTaskMapper.updateInfoById(task.getId(), projectId, campaignId, 3, "创建成功");
                 } else {
-                    log.error("智能托管创建失败,accountId:{},入参:{}返回:{}", task.getAccountId(), requestJson, hosting);
+                    log.error("智能托管创建失败,accountId:{},入参:{},返回:{}", task.getAccountId(), requestJson, hosting);
                     hostingTaskMapper.updateStatusById(task.getId(), 3, hosting.getString("message"));
                 }
             }