Browse Source

Merge branch 'master' of http://git.tjyourong.com.cn/ctop/adsp-boot

yumeng 3 years ago
parent
commit
7c05342a32
22 changed files with 632 additions and 14 deletions
  1. 2 0
      jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java
  2. 35 0
      module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/ExternalMaterialCollectionJob.java
  3. 1 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/AiKuaishouAdvertiserStrategyMapper.xml
  4. 276 6
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouRealTimeController.java
  5. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouAccountBudgetService.java
  6. 1 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java
  7. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouRealTimeDataService.java
  8. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/IKuaiShouCommentServiceImpl.java
  9. 1 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouHistoryReportTaskServiceImpl.java
  10. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouReportDailyMaterialServiceImpl.java
  11. 6 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouAccountBudgetServiceImpl.java
  12. 69 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java
  13. 49 5
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouRealTimeDataServiceImpl.java
  14. 32 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouReportHourlyGroup.java
  15. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/EtlKuaiShouGroupDailyReportServiceImpl.java
  16. 1 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouAudienceReportDailyServiceImpl.java
  17. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouGroupExploreServiceImpl.java
  18. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouReportDailyGroupServiceImpl.java
  19. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouReportDailyImageServiceImpl.java
  20. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouReportHourlyGroupServiceImpl.java
  21. 120 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/utils/LinkUtils.java
  22. 1 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceAdvertiserDataServiceImpl.java

+ 2 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

@@ -202,6 +202,8 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/kuaishou/batch/*", "anon");
         filterChainDefinitionMap.put("/dimension/kuaiShouDimensionAccount/*", "anon");
         filterChainDefinitionMap.put("/ai/projectCreate/*", "anon");
+        //获取快手实时组数据信息
+        filterChainDefinitionMap.put("/kuaishou/realTime/*", "anon");
 
         // 添加自己的过滤器并且取名为jwt
         Map<String, Filter> filterMap = new HashMap<>(1);

+ 35 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/ExternalMaterialCollectionJob.java

@@ -0,0 +1,35 @@
+package cn.com.ctop.job.kuaishou.handler;
+
+import cn.com.ctop.common.module.utils.HttpUtils2;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupTemplateService;
+import com.xxl.job.core.context.XxlJobHelper;
+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;
+
+/**
+ * 清洗外部素材集信息表
+ */
+@Component
+@Slf4j
+public class ExternalMaterialCollectionJob {
+
+    @Value("${xxl-job.requestUrl}")
+    private String jobUrl;
+
+    /**
+     * 快手自动创建组
+     */
+    @XxlJob("externalMaterialCollectionJob")
+    public void execute() {
+        String url = jobUrl + "/jeecg-boot/external/materialCollection/createInternalMaterial";
+        log.info("请求地址:{}", url);
+        try {
+            HttpUtils2.httpGet(url, null, null);
+        } catch (Exception e) {
+            XxlJobHelper.log(e.getMessage());
+        }
+    }
+}

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

@@ -5,6 +5,7 @@
     <select id="getKuaishouAccountAutoStrategy" resultType="java.lang.Long">
         SELECT account_id
         FROM ctop_ai_kuaishou_account_auto_strategy
+        WHERE status = 1
         GROUP BY account_id
     </select>
 

+ 276 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouRealTimeController.java

@@ -1,19 +1,36 @@
 package cn.com.ctop.kuaishou.modules.batch.controller;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.material.entity.MaterialVideoAuthor;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouRealTimeDataService;
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportHourlyGroup;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportHourlyGroupService;
+import cn.com.ctop.kuaishou.modules.utils.LinkUtils;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+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.google.gson.JsonObject;
 import io.swagger.annotations.Api;
 import lombok.extern.slf4j.Slf4j;
+import org.checkerframework.checker.units.qual.A;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DateUtils;
 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 org.springframework.web.bind.annotation.*;
+
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 广告组-app信息
@@ -30,7 +47,24 @@ public class KuaiShouRealTimeController {
     @Autowired
     private ICtopOauthTokenService oauthTokenService;
 
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+
+    @Autowired
+    IKuaishouReportHourlyGroupService kuaishouReportHourlyGroupService;
+
+
+    @Autowired
+    IKuaishouInterfaceService kuaishouInterfaceService;
+
+
 
+
+    /**
+     *  快手- 获取实时数据 计划
+     * @param requestJson
+     * @return
+     */
     @PostMapping(value = "/getCampaignDate")
     public Result<JSONArray> getCampaignDate(@RequestBody JSONObject requestJson) {
         Result<JSONArray> result = new Result<>();
@@ -64,6 +98,13 @@ public class KuaiShouRealTimeController {
     }
 
 
+
+
+    /**
+     *  快手- 获取实时数据 组
+     * @param requestJson
+     * @return
+     */
     @PostMapping(value = "/getUnitDate")
     public Result<JSONArray> getUnitDate(@RequestBody JSONObject requestJson) {
         Result<JSONArray> result = new Result<>();
@@ -77,9 +118,9 @@ public class KuaiShouRealTimeController {
                 throw new Exception("未获取到账户信息");
             }
             Long unitId = requestJson.getLong("unitId");
-            if (Check.isNull(unitId)) {
+            /*if (Check.isNull(unitId)) {
                 throw new Exception("请传入组id");
-            }
+            }*/
             String startDate = requestJson.getString("startDate");
             String endDate = requestJson.getString("endDate");
             if (Check.isNull(startDate) || Check.isNull(endDate)) {
@@ -96,4 +137,233 @@ public class KuaiShouRealTimeController {
         return result;
     }
 
+
+    /**
+     * 盯盘-快手 组实时数据信息
+     * @param accountId
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    @GetMapping(value = "/getUnitDateInfo")
+    public Result getUnitDate(@RequestParam("accountId") Long accountId,
+                                         @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
+                                         @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize) {
+
+        DecimalFormat df = new DecimalFormat("#.000");
+
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+
+
+        List<KuaishouReportHourlyGroup> unitList = new ArrayList<>();
+
+
+        //优化目标
+        Integer conver = 0;
+        //获取广告组的出价
+        Map unitPrice = kuaishouInterfaceService.getKuaishouUnitList(token, null,new Date(), new Date() , 1,pageNum,pageSize);
+
+        JSONArray array = JSONArray.parseArray(unitPrice.get("details").toString());
+
+        for (Object obj : array) {
+
+            KuaishouReportHourlyGroup unitInfo = new KuaishouReportHourlyGroup();
+            //获取组id
+            List<Long> unitIdList = new ArrayList<>();
+            JSONObject vo = JSONObject.parseObject(obj.toString());
+            unitIdList.add(vo.getLong("unit_id"));
+
+            //广告主 当天 实时 组 数据信息
+            JSONArray unitData = realTimeDataService.getUnitDatePage(accountId, unitIdList, token.getAccessToken(), nowDate, nowDate, pageNum, pageSize);
+            List<KuaishouReportHourlyGroup> k = JSONArray.parseArray(unitData.toString(),KuaishouReportHourlyGroup.class);
+            if (!Check.isNull(k)){
+                unitInfo  = k.get(0);
+            }
+
+            unitInfo.setTotalCount(Integer.valueOf(unitPrice.get("totalCount").toString()));
+
+
+
+            unitInfo.setUnitName(vo.getString("unit_name"));
+
+            //出价
+            unitInfo.setBid(vo.getLong("bid"));
+            unitInfo.setCpaBid(vo.getLong("cpa_bid"));
+            unitInfo.setBidType(vo.getInteger("bid_type"));
+            //优化目标
+            conver = vo.getInteger("ocpx_action_type");
+            unitInfo.setConverType(conver);
+            //计划id
+            unitInfo.setCampaignId(vo.getLong("campaign_id"));
+            //组id
+            unitInfo.setUnitId(vo.getLong("unit_id"));
+            unitInfo.setUnitName(vo.getString("unit_name"));
+
+            //投放状态 1:投放中;2:暂停 3:删除
+            unitInfo.setPutStatus(vo.getInteger("put_status"));
+
+            //激活成本 = 花费  / 激活数
+            String activationCost = "0";
+
+            if (!Check.isNull(k)){
+                if (unitInfo.getCharge().doubleValue() != new Double(0) && unitInfo.getActivation() != 0l) {
+                    Double activation_cost = unitInfo.getCharge().doubleValue() / unitInfo.getActivation();
+                    activationCost = df.format(activation_cost);
+                }
+
+            unitInfo.setActivationCost(activationCost);
+
+
+                //优化目标: 激活,  付费,  行为,  表单提交,  注册,  唤起应用,  关键行为
+                //对应转化数 激活数,付费数,行为数,表单提交数,注册数,唤起应用次数,关键行为数
+                //优化目标id 来源---ctop_kuaishou_ocpx_action_type_config
+                //激活
+                if (conver == 180) {
+                    unitInfo.setConverNum(unitInfo.getActivation().intValue());
+                }
+                //付费
+                if (conver == 190) {
+                    unitInfo.setConverNum(unitInfo.getEventPay().intValue());
+                }
+                //行为
+                if (conver == 2) {
+                    unitInfo.setConverNum(unitInfo.getBclick().intValue());
+                }
+                //表单提交
+                if (conver == 53) {
+                    unitInfo.setConverNum(unitInfo.getFormCount().intValue());
+                }
+                //注册
+                if (conver == 396) {
+                    unitInfo.setConverNum(unitInfo.getEventRegister().intValue());
+                }
+                //唤起应用
+                if (conver == 324) {
+                    unitInfo.setConverNum(unitInfo.getEventAppInvoked().intValue());
+                }
+                //关键行为
+                if (conver == 773) {
+                    unitInfo.setConverNum(unitInfo.getKeyAction().intValue());
+                }
+                //转化成本 = 花费 / 转化数
+                unitInfo.setConverCost(Check.isNull(unitInfo.getCharge()) || Check.isNull(unitInfo.getConverNum()) ? 0 : unitInfo.getCharge().doubleValue() / unitInfo.getConverNum().doubleValue());
+                if (unitInfo.getConverCost().isNaN() || unitInfo.getConverCost().isInfinite()) {
+                    unitInfo.setConverCost(new Double(0));
+                }
+
+                //操作建议
+                //消耗
+                Double charge = unitInfo.getCharge().doubleValue();
+                //出价 单位:厘
+                long bid = new Long("1000");
+                //2:CPC
+                if (unitInfo.getBidType() == 2){
+                    bid = unitInfo.getBid();
+                //10:OCPM
+                }else if(unitInfo.getBidType() == 10){
+                    bid = unitInfo.getCpaBid();
+                }
+                Double price = new Double(bid/1000).doubleValue();
+
+                //转化数量
+                Integer converNum = unitInfo.getConverNum();
+                //转化成本
+                Double converCost = unitInfo.getConverCost();
+
+                //1. 转化成本大于出价×120%,消耗大于500元:
+                if ((converCost > price * 1.2) && (charge > 500)) {
+                    unitInfo.setOperationAgree("高成本 | 有消耗");
+                    unitInfo.setOperationAgreeContent("建议限制预算");
+                    unitInfo.setOperationAgreeInfo("当前广告组转化成本偏高且消耗大于500,建议限制预算;");
+                }
+                //2.  转化成本大于出价×120%,转化数大于10小于等于50:
+                if (converCost > price * 1.2 && LinkUtils.isInTheInterval(String.valueOf(converNum), "(10,50)")) {
+                    unitInfo.setOperationAgree("高成本 | 有转化");
+                    unitInfo.setOperationAgreeContent("建议限制预算");
+                    unitInfo.setOperationAgreeInfo("当前广告组成本大于出价×120%且转化数介于10-50之间;");
+                }
+                //3. 转化成本大于出价×120%,转化数大于50
+                if (converCost > price * 1.2 && LinkUtils.isInTheInterval(String.valueOf(converNum), "(50,∞)")) {
+                    unitInfo.setOperationAgree("高成本 | 有转化");
+                    unitInfo.setOperationAgreeContent("建议降低出价;");
+                    unitInfo.setOperationAgreeInfo("当前转化成本大于出价×120%,转化数大于50,建议降低出价;");
+                }
+                //4.  转化成本小于等于出价×120%,转化数大于10小于等于50
+                if (converCost <= price * 1.2 && LinkUtils.isInTheInterval(String.valueOf(converNum), "(10,50]")) {
+                    unitInfo.setOperationAgree("成本合理 | 有转化");
+                    unitInfo.setOperationAgreeContent("建议复制推广组或放开预算");
+                    unitInfo.setOperationAgreeInfo("当前转化成本小于等于出价×120%,转化数大于10小于等于50,建议复制推广组或放开预算;");
+                }
+                //5.  消耗大于0小于等于100,转化数大于0小于等于10:
+                if (LinkUtils.isInTheInterval(String.valueOf(charge), "(0,100]") && LinkUtils.isInTheInterval(String.valueOf(converNum), "(0,10]")) {
+                    unitInfo.setOperationAgree("消耗少 | 转化少");
+                    unitInfo.setOperationAgreeContent("建议启用加速探索");
+                    unitInfo.setOperationAgreeInfo("当前广告组消耗大于0小于等于100,转化数大于0小于等于10,建议加速探索;");
+                }
+                //6.  消耗大于等于500,转化数等于0:
+                if (charge >= 500 && converNum == 0) {
+                    unitInfo.setOperationAgree("有消耗 | 无转化");
+                    unitInfo.setOperationAgreeContent("建议暂停广告组");
+                    unitInfo.setOperationAgreeInfo("当前广告组消耗大于等于500且转化数等于0,建议暂停推广组;");
+                }
+                //7.   消耗大于100小于等于500
+                if (LinkUtils.isInTheInterval(String.valueOf(charge), "(100,500]")) {
+                    unitInfo.setOperationAgree("有一定消耗");
+                    unitInfo.setOperationAgreeContent("建议继续观察");
+                    unitInfo.setOperationAgreeInfo("当前广告组消耗大于100小于等于500,建议继续观察;");
+                }
+
+
+            }
+            unitInfo.setOperationAgree("暂无");
+            unitInfo.setOperationAgreeContent("暂无");
+            unitInfo.setOperationAgreeInfo("暂无");
+
+
+            setFeidValueNotNull(unitInfo);
+
+            unitList.add(unitInfo);
+
+        }
+        return Result.ok(unitList);
+    }
+
+
+
+
+
+
+
+
+
+    private void setFeidValueNotNull (Object obj){
+        try {
+            for (Field field: obj.getClass().getDeclaredFields()) {
+            field.setAccessible(true);
+            if (field.get(obj) == null){
+                if (field.getGenericType().toString().equals("class java.lang.String")) {
+                    field.set(obj, "0");
+                }else if (field.getGenericType().toString().equals("class java.lang.Integer")) {
+                    field.set(obj, 0);
+                }else if (field.getGenericType().toString().equals("class java.lang.Double")) {
+                    field.set(obj, 0.0);
+                }else if (field.getGenericType().toString().equals("class java.lang.Long")) {
+                    field.set(obj, 0L);
+                }else if(field.getGenericType().toString().equals("class java.math.BigDecimal")){
+                    field.set(obj, new BigDecimal(0));
+                }
+            }
+        }
+
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+
+    }
+
+
+
+
 }

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

@@ -21,7 +21,7 @@ public interface IKuaishouAccountBudgetService extends IService<KuaishouAccountB
      * @param advertiserId
      * @param accessToken
      */
-    JSONObject getAccountBudget(CtopOauthToken oauthToken);
+    JSONObject getAccountBudget(CtopOauthToken oauthToken) ;
 
     void insertAccountBudget(Long advertiserId, String accessToken);
 

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

@@ -363,6 +363,7 @@ public interface IKuaishouInterfaceService {
      * @param time_filter_type
      */
     JSONArray getGroupList(CtopOauthToken token, Long campaignId, Date startDate, Date endDate, int time_filter_type);
+    Map getKuaishouUnitList(CtopOauthToken token, Long unidId, Date startDate, Date endDate, int time_filter_type,Integer pageNum, Integer pageSize);
 
 
     /**

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouRealTimeDataService.java

@@ -2,8 +2,13 @@ package cn.com.ctop.kuaishou.modules.batch.service;
 
 import com.alibaba.fastjson.JSONArray;
 
+import java.util.List;
+import java.util.Map;
+
 public interface IKuaishouRealTimeDataService {
     JSONArray getCampaignDate(Long accountId, String token, Long campaignId, String startDate, String endDate);
 
     JSONArray getUnitDate(Long accountId, String token, Long unitId, String startDate, String endDate);
+
+    JSONArray getUnitDatePage(Long accountId, List<Long> campaignIds, String token, String startDate, String endDate, Integer pageNum, Integer pageSize);
 }

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/IKuaiShouCommentServiceImpl.java

@@ -146,6 +146,11 @@ public class IKuaiShouCommentServiceImpl implements IKuaiShouCommentService {
         params.put("advertiser_id", accountId);
         params.put("shield_list", comments);
         String result = HttpUtils.httpPostRequest(url, params, header);
+        try {
+            Thread.sleep(500);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
         JSONObject resultJson = JSONObject.parseObject(result);
         if (!Check.isNull(resultJson)) {
             Integer code = resultJson.getInteger("code");

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

@@ -101,6 +101,7 @@ public class KuaiShouHistoryReportTaskServiceImpl extends ServiceImpl<KuaiShouHi
                     param.put("task_params", taskParams);
 
                     String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
+                    Thread.sleep(500);
                     JSONObject resultJson = JSONObject.parseObject(result);
                     if (!Check.isNull(resultJson)) {
                         Integer code = resultJson.getInteger("code");

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouReportDailyMaterialServiceImpl.java

@@ -66,6 +66,11 @@ public class KuaiShouReportDailyMaterialServiceImpl extends ServiceImpl<KuaiShou
         param.put("page_size", 2000);
         param.put("page", page);
         String result = HttpUtils.httpPostRequest(url, param, headers);
+        try {
+            Thread.sleep(500);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
         JSONObject resultJson = JSONObject.parseObject(result);
         if (Check.isNull(resultJson)) {
             return;

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

@@ -86,7 +86,7 @@ public class KuaishouAccountBudgetServiceImpl extends ServiceImpl<KuaishouAccoun
     }
 
     @Override
-    public JSONObject getAccountBudget(CtopOauthToken oauthToken) {
+    public JSONObject getAccountBudget(CtopOauthToken oauthToken)  {
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.ACCOUNT_BUDGET;
         Map<String, String> headers = new HashMap<>();
         headers.put("Access-Token", oauthToken.getAccessToken());
@@ -94,6 +94,11 @@ public class KuaishouAccountBudgetServiceImpl extends ServiceImpl<KuaishouAccoun
         JSONObject json = new JSONObject();
         json.put("advertiser_id", oauthToken.getAccountId());
         String result = HttpUtils.kuaiShouhttpPostRequest(url, json.toJSONString(), headers);
+        try {
+            Thread.sleep(500);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
         JSONObject resultJson = JSONObject.parseObject(result);
         if (!Check.isNull(resultJson)) {
             Integer code = resultJson.getInteger("code");

+ 69 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -210,6 +210,11 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         param.put("page_size", 2000);
         param.put("page", page);
         String result = HttpUtils.httpPostRequest(url, param, headers);
+        try {
+            Thread.sleep(500);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
         JSONObject resultJson = JSONObject.parseObject(result);
         Integer code = resultJson.getInteger("code");
         String message = resultJson.getString("message");
@@ -384,6 +389,11 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         param.put("page_size", 2000);
         param.put("page", page);
         String result = HttpUtils.httpPostRequest(url, param, headers);
+        try {
+            Thread.sleep(500);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
         JSONObject resultJson = JSONObject.parseObject(result);
         Integer code = resultJson.getInteger("code");
         String message = resultJson.getString("message");
@@ -441,6 +451,11 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         param.put("page", page);
 
         String result = HttpUtils.httpPostRequest(url, param, headers);
+        try {
+            Thread.sleep(500);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
         JSONObject resultJson = JSONObject.parseObject(result);
         Integer code = resultJson.getInteger("code");
         String message = resultJson.getString("message");
@@ -1249,6 +1264,60 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     }
 
 
+  @Override
+    public Map getKuaishouUnitList(CtopOauthToken token, Long unitId, Date startDate,
+                                  Date endDate, int time_filter_type,Integer pageNum, Integer pageSize) {
+        String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GROUP_LIST;
+        JSONObject param = new JSONObject();
+        param.put("advertiser_id", token.getAccountId());
+        if (startDate != null && endDate != null) {
+            param.put("start_date", DateUtils.formatDate(startDate));
+            param.put("end_date", DateUtils.formatDate(endDate));
+        }
+
+        if (!Check.isNull(unitId)){
+            param.put("unit_id", unitId);
+        }
+          param.put("page_size", pageSize);
+          param.put("page", pageNum);
+          param.put("time_filter_type", time_filter_type);
+
+
+
+      Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", token.getAccessToken());
+        headers.put("Content-Type", "application/json");
+
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (Check.isNull(resultJson)) {
+            log.error("获取广告组接口异常,advertiserId:{}", token.getAccountId());
+            return null;
+        }
+        Integer code = resultJson.getInteger("code");
+        if (null == code || code != 0) {
+            log.error("获取广告组返回结果异常,advertiserId:{},异常信息:{}", token.getAccountId(), resultJson);
+            return null;
+        }
+        Map resultMap = new HashMap();
+        JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
+        Integer totalCount = resultJson.getJSONObject("data").getInteger("total_count");
+      resultMap.put("details",details );
+      resultMap.put("totalCount",totalCount );
+
+      if (!Check.isNull(resultMap)){
+          return resultMap;
+      }
+
+
+        if (Check.isNull(details)) {
+            return null;
+        }
+
+        return resultMap;
+    }
+
+
     @Override
     public void getGroupList(CtopOauthToken token, Date startDate, Date endDate) {
         getGroupListByPage(token, startDate, endDate, 1);

+ 49 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouRealTimeDataServiceImpl.java

@@ -7,10 +7,11 @@ import cn.com.ctop.common.module.utils.PropertiesUtils;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouRealTimeDataService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.google.gson.JsonArray;
+import com.rabbitmq.client.LongString;
 import org.springframework.stereotype.Service;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 
 @Service
 public class KuaishouRealTimeDataServiceImpl implements IKuaishouRealTimeDataService {
@@ -86,9 +87,50 @@ public class KuaishouRealTimeDataServiceImpl implements IKuaishouRealTimeDataSer
         param.put("page_size", 2000);
         param.put("page", 1);
 
-        JSONArray array = new JSONArray();
-        array.add(unitId);
-        param.put("unit_ids", array);
+        if (!Check.isNull(unitId)){
+            JSONArray array = new JSONArray();
+            array.add(unitId);
+            param.put("unit_ids", array);
+        }
+
+        try {
+            String result = HttpUtils.httpPostRequest(url, param, headers);
+            JSONObject jsonObject = JSONObject.parseObject(result);
+            if (!Check.isNull(jsonObject)) {
+                Integer code = jsonObject.getInteger("code");
+                if (code == 0) {
+                    JSONObject data = jsonObject.getJSONObject("data");
+                    if (!Check.isNull(data)) {
+                        return data.getJSONArray("details");
+                    }
+                }
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+
+    @Override
+    public JSONArray getUnitDatePage(Long accountId, List<Long> unitIdList ,String token, String startDate, String endDate, Integer pageNum, Integer pageSize) {
+        Map map = new HashMap();
+        String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GTOUP_REPORT;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", token);
+        Map<String, Object> param = new HashMap<>();
+        param.put("start_date", startDate);
+        param.put("end_date", endDate);
+        param.put("advertiser_id", accountId);
+        param.put("temporal_granularity", "DAILY");
+        param.put("page_size", pageSize);
+        param.put("page", pageNum);
+
+        param.put("unit_ids",unitIdList);
+
         try {
             String result = HttpUtils.httpPostRequest(url, param, headers);
             JSONObject jsonObject = JSONObject.parseObject(result);
@@ -97,6 +139,8 @@ public class KuaishouRealTimeDataServiceImpl implements IKuaishouRealTimeDataSer
                 if (code == 0) {
                     JSONObject data = jsonObject.getJSONObject("data");
                     if (!Check.isNull(data)) {
+                        //map.put("totalCount",data.getInteger("total_count"));
+                        //map.put("details",data.getJSONArray("details"));
                         return data.getJSONArray("details");
                     }
                 }

+ 32 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouReportHourlyGroup.java

@@ -127,4 +127,36 @@ public class KuaishouReportHourlyGroup implements Serializable {
     private Date createTime;
     @JsonProperty
     private Date updateTime;
+
+    @JsonProperty
+    private Long eventAppInvoked;
+
+    @JsonProperty
+    private Long keyAction;
+
+    @JsonProperty
+    private Integer totalCount;
+
+
+    @JsonProperty
+    private Integer putStatus; //1:投放中;2:暂停 3:删除
+
+    //出价
+    private Long bid;
+    private Long cpaBid;
+    //出价类型 1:CPM,2:CPC,6:OCPC(使用 OCPC 代表 OCPX),10:OCPM,20:eCPC
+    private Integer bidType;
+    //转化类型
+    private Integer converType;
+    //转化数
+    private Integer converNum;
+    //转化成本
+    private Double converCost;
+    //激活成本
+    private String activationCost;
+    //操作建议
+    private String operationAgree;
+    private String operationAgreeContent;
+    private String operationAgreeInfo;
+
 }

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/EtlKuaiShouGroupDailyReportServiceImpl.java

@@ -58,6 +58,11 @@ public class EtlKuaiShouGroupDailyReportServiceImpl extends ServiceImpl<EtlKuaiS
         param.put("page_size", 2000);
         param.put("page", page);
         String result = HttpUtils.httpPostRequest(url, param, headers);
+        try {
+            Thread.sleep(500);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
         JSONObject resultJson = JSONObject.parseObject(result);
         Integer code = resultJson.getInteger("code");
         String message = resultJson.getString("message");

+ 1 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouAudienceReportDailyServiceImpl.java

@@ -124,6 +124,7 @@ public class KuaishouAudienceReportDailyServiceImpl extends ServiceImpl<Kuaishou
                 requestJson.put("unit_ids", units);
             }
             String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+            Thread.sleep(500);
             JSONObject resultJson = JSONObject.parseObject(result);
             if (!Check.isNull(resultJson)) {
                 Integer code = resultJson.getInteger("code");

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouGroupExploreServiceImpl.java

@@ -71,6 +71,7 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
             params.put("advertiser_id", accountId);
             params.put("unit_id", unitId);
             String result = HttpUtils.httpPostRequest(url, params, header);
+            Thread.sleep(500);
             JSONObject resultJson = JSONObject.parseObject(result);
             if (!Check.isNull(resultJson)) {
                 Integer code = resultJson.getInteger("code");
@@ -201,6 +202,7 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
             params.put("advertiser_id", accountId);
             params.put("unit_id", unitId);
             String result = HttpUtils.httpPostRequest(url, params, header);
+            Thread.sleep(500);
             JSONObject resultJson = JSONObject.parseObject(result);
             if (!Check.isNull(resultJson)) {
                 Integer code = resultJson.getInteger("code");

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouReportDailyGroupServiceImpl.java

@@ -55,6 +55,11 @@ public class KuaishouReportDailyGroupServiceImpl extends ServiceImpl<KuaishouRep
         param.put("page_size", 2000);
         param.put("page", page);
         String result = HttpUtils.httpPostRequest(url, param, headers);
+        try {
+            Thread.sleep(500);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
         JSONObject resultJson = JSONObject.parseObject(result);
         Integer code = resultJson.getInteger("code");
         String message = resultJson.getString("message");

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouReportDailyImageServiceImpl.java

@@ -51,6 +51,11 @@ public class KuaishouReportDailyImageServiceImpl extends ServiceImpl<KuaishouRep
         param.put("page", page);
 
         JSONObject resultJson = JSONObject.parseObject(HttpUtils.kuaiShouhttpPostRequest("https://ad.e.kuaishou.com/rest/openapi/v1/report/material_report", param.toJSONString(), headers));
+        try {
+            Thread.sleep(500);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
         if (Check.isNull(resultJson)) {
             log.error("获取素材图片报表返回结果为空,advertiserId:{}", accountId);
             return;

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouReportHourlyGroupServiceImpl.java

@@ -42,6 +42,11 @@ public class KuaishouReportHourlyGroupServiceImpl extends ServiceImpl<KuaishouRe
         param.put("page", page);
 
         String result = HttpUtils.httpPostRequest(url, param, headers);
+        try {
+            Thread.sleep(500);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
         JSONObject resultJson = JSONObject.parseObject(result);
         Integer code = resultJson.getInteger("code");
         String message = resultJson.getString("message");

+ 120 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/utils/LinkUtils.java

@@ -2,6 +2,8 @@ package cn.com.ctop.kuaishou.modules.utils;
 
 import com.alibaba.fastjson.JSONObject;
 
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.ArrayList;
@@ -46,4 +48,122 @@ public class LinkUtils {
         return link;
     }
 
+
+
+    /**
+     * 判断data_value是否在interval区间范围内
+     * @param data_value 数值类型的
+     * @param interval 正常的数学区间,包括无穷大等,如:(1,3)、>5%、(-∞,6]、(125%,135%)U(70%,80%)
+     * @return true:表示data_value在区间interval范围内,false:表示data_value不在区间interval范围内
+     */
+    public static boolean isInTheInterval(String data_value,String interval) {
+        //将区间和data_value转化为可计算的表达式
+        String formula = getFormulaByAllInterval(data_value,interval,"||");
+        ScriptEngine jse = new ScriptEngineManager().getEngineByName("JavaScript");
+        try {
+            //计算表达式
+            return (Boolean) jse.eval(formula);
+        } catch (Exception t) {
+            return false;
+        }
+    }
+
+
+
+    /**
+     * 将所有阀值区间转化为公式:如
+     * [75,80) =》 date_value < 80 && date_value >= 75
+     * (125%,135%)U(70%,80%) =》 (date_value < 1.35 && date_value > 1.25) || (date_value < 0.8 && date_value > 0.7)
+     * @param date_value
+     * @param interval 形式如:(125%,135%)U(70%,80%)
+     * @param connector 连接符 如:") || ("
+     */
+    private static String getFormulaByAllInterval(String date_value, String interval, String connector) {
+        StringBuffer buff = new StringBuffer();
+        for(String limit:interval.split("U")){//如:(125%,135%)U (70%,80%)
+            buff.append("(").append(getFormulaByInterval(date_value, limit," && ")).append(")").append(connector);
+        }
+        String allLimitInvel = buff.toString();
+        int index = allLimitInvel.lastIndexOf(connector);
+        allLimitInvel = allLimitInvel.substring(0,index);
+        return allLimitInvel;
+    }
+
+    /**
+     * 将整个阀值区间转化为公式:如
+     * 145) =》 date_value < 145
+     * [75,80) =》 date_value < 80 && date_value >= 75
+     * @param date_value
+     * @param interval 形式如:145)、[75,80)
+     * @param connector 连接符 如:&&
+     */
+    private static String getFormulaByInterval(String date_value, String interval, String connector) {
+        StringBuffer buff = new StringBuffer();
+        for(String halfInterval:interval.split(",")){//如:[75,80)、≥80
+            buff.append(getFormulaByHalfInterval(halfInterval, date_value)).append(connector);
+        }
+        String limitInvel = buff.toString();
+        int index = limitInvel.lastIndexOf(connector);
+        limitInvel = limitInvel.substring(0,index);
+        return limitInvel;
+    }
+
+
+    /**
+     * 将半个阀值区间转化为公式:如
+     * 145) =》 date_value < 145
+     * ≥80% =》 date_value >= 0.8
+     * [130 =》 date_value >= 130
+     * <80% =》 date_value < 0.8
+     * @param halfInterval 形式如:145)、≥80%、[130、<80%
+     * @param date_value
+     * @return date_value < 145
+     */
+    private static String getFormulaByHalfInterval(String halfInterval, String date_value) {
+        halfInterval = halfInterval.trim();
+        if(halfInterval.contains("∞")){//包含无穷大则不需要公式
+            return "1 == 1";
+        }
+        StringBuffer formula = new StringBuffer();
+        String data = "";
+        String opera = "";
+        if(halfInterval.matches("^([<>≤≥\\[\\(]{1}(-?\\d+.?\\d*\\%?))$")){//表示判断方向(如>)在前面 如:≥80%
+            opera = halfInterval.substring(0,1);
+            data = halfInterval.substring(1);
+        }else{//[130、145)
+            opera = halfInterval.substring(halfInterval.length()-1);
+            data = halfInterval.substring(0,halfInterval.length()-1);
+        }
+        double value = dealPercent(data);
+        formula.append(date_value).append(" ").append(opera).append(" ").append(value);
+        String a = formula.toString();
+        //转化特定字符
+        return a.replace("[", ">=").replace("(", ">").replace("]", "<=").replace(")", "<").replace("≤", "<=").replace("≥", ">=");
+    }
+
+
+    /**
+     * 去除百分号,转为小数
+     * @param str 可能含百分号的数字
+     * @return
+     */
+    private static double dealPercent(String str){
+        double d = 0.0;
+        if(str.contains("%")){
+            str = str.substring(0,str.length()-1);
+            d = Double.parseDouble(str)/100;
+        }else{
+            d = Double.parseDouble(str);
+        }
+        return d;
+    }
+
+
+    public static void main(String[] args) {
+
+        System.out.println(LinkUtils.isInTheInterval("7", "(-1,9]"));
+    }
+
+
+
 }

+ 1 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -242,7 +242,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
                 advertisePlan.setDeepCpaBid(deepCpabid);
             }
             advertisePlanService.saveOrUpdate(advertisePlan);
-            log.info("============保存头条计划=================");
+            //log.info("============保存头条计划=================");
         }
         getAd(token, pageNum + 1, ids, date, updateDate);
     }