Просмотр исходного кода

Merge remote-tracking branch 'origin/master'

syh 4 лет назад
Родитель
Сommit
b0d7ea1cad

+ 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);

+ 3 - 3
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouDailyAudienceReportJob.java

@@ -38,8 +38,6 @@ public class KuaishouDailyAudienceReportJob {
 
     @XxlJob("kuaishouDailyAudienceReportJob")
     public void execute() throws Exception {
-        //查询两天前数据  策略
-        String date = DateUtils.getLastDay(DateUtils.date2Str(), 2);
         List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
         if (null == tokens || tokens.isEmpty()) {
             XxlJobHelper.log("定时获取人群分析报表数据异常:未获取到可用的token");
@@ -49,7 +47,7 @@ public class KuaishouDailyAudienceReportJob {
         //查询有效策略的账户ID
         List<Long> accountIds = kuaishouStrategyService.queryActiveAccount();
         if (Check.isNull(accountIds) || accountIds.size() == 0) {
-            XxlJobHelper.log("定时获取人群分析报表数据异常:获取到有效策略账户信息");
+            XxlJobHelper.log("定时获取人群分析报表数据异常:获取到有效策略账户信息");
             XxlJobHelper.handleFail();
             return;
         }
@@ -65,6 +63,8 @@ public class KuaishouDailyAudienceReportJob {
         if (!Check.isNull(activeTokens) && activeTokens.size() > 0) {
             int page = 1;
             int pageSize = 2000;
+            //查询两天前日期
+            String date = DateUtils.getLastDay(DateUtils.date2Str(), 2);
             activeTokens.forEach(token -> executorService.submit(() -> {
                 getAudienceReportData(token, date, "province", page, pageSize);
                 getAudienceReportData(token, date, "city", page, pageSize);

+ 31 - 3
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouVideoRelateCreativesJob.java

@@ -5,12 +5,15 @@ import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 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.batch.service.IKuaishouStrategyService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouVideoRelateCreativesService;
 import com.alibaba.fastjson.JSONArray;
+import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -30,15 +33,40 @@ public class KuaishouVideoRelateCreativesJob {
     private ICtopOauthTokenService tokenService;
     @Autowired
     private IKuaiShouVideoGetService videoGetService;
+    @Autowired
+    private IKuaishouStrategyService kuaishouStrategyService;
 
     static ExecutorService executorService = Executors.newFixedThreadPool(5);
 
     @XxlJob("kuaishouVideoRelateCreativesJob")
     public void execute() throws Exception {
         List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
-        tokens.forEach(token -> executorService.submit(() -> {
-            videoRelateCreatives(token.getAccountId());
-        }));
+        if (null == tokens || tokens.isEmpty()) {
+            XxlJobHelper.log("定时获取人群分析报表数据异常:未获取到可用的token");
+            XxlJobHelper.handleFail();
+            return;
+        }
+        //查询有效策略的账户ID
+        List<Long> accountIds = kuaishouStrategyService.queryActiveAccount();
+        if (Check.isNull(accountIds) || accountIds.size() == 0) {
+            XxlJobHelper.log("定时获取人群分析报表数据异常:未获取到有效策略账户信息");
+            XxlJobHelper.handleFail();
+            return;
+        }
+        //筛选出有效账户,获取该账户的组级人群报表数据
+        List<CtopOauthToken> activeTokens = new ArrayList<>();
+        for (Long accountId : accountIds) {
+            for (CtopOauthToken token : tokens) {
+                if (token.getAccountId() - accountId == 0) {
+                    activeTokens.add(token);
+                }
+            }
+        }
+        if (!Check.isNull(activeTokens) && activeTokens.size() > 0) {
+            activeTokens.forEach(token -> executorService.submit(() -> {
+                videoRelateCreatives(token.getAccountId());
+            }));
+        }
     }
 
     /**

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

@@ -0,0 +1,137 @@
+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;
+
+@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;
+
+    /**
+     * 创建计划
+     *
+     * @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("请填写需要创建的组信息");
+            }
+            kuaiShouCreateService.createUnitAndCreative(oauthToken, campaign_id, group_list);
+
+        } 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);
+}

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

@@ -0,0 +1,31 @@
+package cn.com.ctop.kuaishou.modules.ai.service.impl;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouCreateService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+@Service
+@Slf4j
+public class KuaiShouCreateServiceImpl implements IKuaiShouCreateService {
+    @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);
+
+
+            }
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+
+    }
+}

+ 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);
 }

+ 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;
+    }
+
 }

+ 2 - 12
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);

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

@@ -6,10 +6,8 @@ import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouVideoRelateCreatives;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouVideoRelateCreativesMapper;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouVideoRelateCreativesService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -84,6 +82,7 @@ public class KuaishouVideoRelateCreativesServiceImpl extends ServiceImpl<Kuaisho
                     return Result.ok(resultJson.getJSONObject("data"));
                 } else {
                     log.info("视频库-推送视频失败,accountId:{},返回信息:{}", accountId, resultJson);
+                    return Result.error("视频库-推送视频失败," + resultJson.getString("message"));
                 }
             }
         } catch (Exception e) {