Browse Source

快手加速探索代码合并

syh 4 năm trước cách đây
mục cha
commit
4c0e491921
15 tập tin đã thay đổi với 238 bổ sung7 xóa
  1. 6 1
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/KuaishouAccountSpeedExploreLogController.java
  2. 4 2
      jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
  3. 3 0
      module-common/src/main/java/cn/com/ctop/common/module/utils/StatusCode.java
  4. 37 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouGroupSpeedExploreLog.java
  5. 9 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouAccountSpeedExploreLogMapper.java
  6. 14 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouGroupSpeedExploreLogMapper.java
  7. 44 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouAccountSpeedExploreLogMapper.xml
  8. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouGroupSpeedExploreLogMapper.xml
  9. 14 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouGroupSpeedExploreLogService.java
  10. 21 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouAccountSpeedExploreLogServiceImpl.java
  11. 18 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouGroupSpeedExploreLogServiceImpl.java
  12. 18 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/vo/SpeedExploreGroupVO.java
  13. 3 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java
  14. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IKuaishouGroupExploreService.java
  15. 37 4
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouGroupExploreServiceImpl.java

+ 6 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/KuaishouAccountSpeedExploreLogController.java

@@ -67,7 +67,12 @@ public class KuaishouAccountSpeedExploreLogController {
 			LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
 			kuaishouAccountSpeedExploreLog.setUserId(user.getId());
 			//1:查询此账户当前是否存在正在加速探索的账户
-			return kuaishouAccountSpeedExploreLogService.openSpeedExplore(kuaishouAccountSpeedExploreLog);
+			if(null!=kuaishouAccountSpeedExploreLog.getConvertType()&&(kuaishouAccountSpeedExploreLog.getConvertType()==2||kuaishouAccountSpeedExploreLog.getConvertType()==180||kuaishouAccountSpeedExploreLog.getConvertType()==53||kuaishouAccountSpeedExploreLog.getConvertType()==190)){
+				return kuaishouAccountSpeedExploreLogService.openSpeedExplore(kuaishouAccountSpeedExploreLog);
+			}else {
+				ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_SPEED_EXPLORE_ACTION_TYPE_NOT_CONFIG);
+				return result;
+			}
 		} catch (Exception e) {
 			log.error(e.getMessage(),e);
 			ResultMapUtils.setResultMap(result, StatusCode.COMMON_SERVER_ERROR);

+ 4 - 2
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -583,7 +583,9 @@ public class SampleTest {
     private IEtlKuaishouVideoInfoService videoEtlInfoService;
     @Test
     public void etlKuaishouVideoInfo(){
-        CtopOauthToken token = tokenService.getTokenByAccountId(9792538L);
-        kuaishouInterfaceService.getGroupList(token,new Date(),new Date());
+        String startDate = "2021-01-01";
+        String endDate = "2021-01-31";
+        CtopOauthToken token = tokenService.getTokenByAccountId(9556227L);
+        kuaishouInterfaceService.getAdvertiserReportDaily(token, DateUtils.parseDate(startDate,"yyyy-MM-dd"), DateUtils.parseDate(endDate,"yyyy-MM-dd"));
     }
 }

+ 3 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/StatusCode.java

@@ -59,6 +59,9 @@ public enum StatusCode {
 
     KUAISHOU_API_ACCOUNT_SPEED_EXPLORING("此账户加速探索尚未完成",-5001,false),
 
+    KUAISHOU_SPEED_EXPLORE_ACTION_TYPE_NOT_CONFIG("加速探索尚不支持此类优化目标",-6001,false),
+    KUAISHOU_SPEED_EXPLORE_FAIL("加速探索失败",-6002,false),
+
     KUAISHOU_CRAWLER_APP_SUCCESS("爬虫运行正常", 0, true),
     KUAISHOU_CRAWLER_APP_TASK_END("爬虫任务运行结束", 1, true),
     KUAISHOU_CRAWLER_APP_JOB_StART("任务开始执行开始", 0, true),

+ 37 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouGroupSpeedExploreLog.java

@@ -0,0 +1,37 @@
+package cn.com.ctop.kuaishou.modules.ai.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 快手组级别加速探索执行记录
+ * @author jeecg-boot
+ * @date   2021-03-10
+ * @version V1.0
+ */
+@Data
+@TableName("ctop_kuaishou_group_speed_explore_log")
+public class KuaishouGroupSpeedExploreLog {
+
+	/**id*/
+	@TableId(type = IdType.AUTO)
+	private Long id;
+	/**accountId*/
+	private Long accountId;
+	/**accountExploreId*/
+	private Long accountExploreId;
+	/**unitId*/
+	private Long unitId;
+	/**status*/
+	private Integer status;
+	/**message*/
+	private String message;
+	/**createTime*/
+	private Date createTime;
+	/**updateTime*/
+	private Date updateTime;
+}

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

@@ -1,7 +1,11 @@
 package cn.com.ctop.kuaishou.modules.ai.mapper;
 
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouAccountSpeedExploreLog;
+import cn.com.ctop.kuaishou.modules.ai.vo.SpeedExploreGroupVO;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * 快手账户加速探索触发记录信息
@@ -11,4 +15,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface KuaishouAccountSpeedExploreLogMapper extends BaseMapper<KuaishouAccountSpeedExploreLog> {
 
+    List<SpeedExploreGroupVO> getSpeedExploreGroupVosByParams(@Param(value = "date") String date,
+                                                              @Param(value = "accountId")Long accountId,
+                                                              @Param(value = "convertType")Integer convertType,
+                                                              @Param(value = "convertCount")Integer convertCount,
+                                                              @Param(value = "groupCount")Integer groupCount);
 }

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

@@ -0,0 +1,14 @@
+package cn.com.ctop.kuaishou.modules.ai.mapper;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouGroupSpeedExploreLog;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 快手组级别加速探索执行记录
+ * @author: jeecg-boot
+ * @date:   2021-03-10
+ * @cersion: V1.0
+ */
+public interface KuaishouGroupSpeedExploreLogMapper extends BaseMapper<KuaishouGroupSpeedExploreLog> {
+
+}

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

@@ -2,4 +2,48 @@
 <!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.ai.mapper.KuaishouAccountSpeedExploreLogMapper">
 
+    <select id="getSpeedExploreGroupVosByParams"
+            resultType="cn.com.ctop.kuaishou.modules.ai.vo.SpeedExploreGroupVO">
+        select *from (select report.account_id,
+                report.unit_id,
+                report.campaign_id,
+                report.charge,
+                report.activation,
+                report.bclick,
+                report.form_count,
+                report.event_pay,
+        <if test="convertType=180">
+            (case when activation=0 then 0 else round(report.charge/report.activation,2) end)as account,
+        </if>
+        <if test="convertType=2">
+            (case when bclick=0 then 0 else round(report.charge/report.bclick,2) end)as account,
+        </if>
+        <if test="convertType=53">
+            (case when form_count=0 then 0 else round(report.charge/report.form_count,2) end)as account,
+        </if>
+        <if test="convertType=190">
+            (case when event_pay=0 then 0 else round(report.charge/report.event_pay,2) end)as account,
+        </if>
+        round(g.cpa_bid/1000,2) as cpaBid
+         from ctop_kuaishou_group g
+                  left join ctop_kuaishou_report_daily_group report
+                            on report.unit_id = g.unit_id and report.stat_date = #{date}
+         where g.study_status = 1
+           and g.group_create_time like '2021-03-10%'
+           and g.account_id = #{accountId}
+           and report.account_id is not null
+        <if test="convertType=180">
+            and report.activation >= #{convertCount}
+        </if>
+        <if test="convertType=2">
+            and report.bclick >= #{convertCount}
+        </if>
+        <if test="convertType=53">
+            and report.form_count >= #{convertCount}
+        </if>
+        <if test="convertType=190">
+            and report.event_pay >= #{convertCount}
+        </if>) a
+where a.cpaBid>a.activation_account order by a.account limit #{groupCount}
+    </select>
 </mapper>

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

@@ -0,0 +1,5 @@
+<?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">
+<mapper namespace="cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouGroupSpeedExploreLogMapper">
+
+</mapper>

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

@@ -0,0 +1,14 @@
+package cn.com.ctop.kuaishou.modules.ai.service;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouGroupSpeedExploreLog;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @Description: 快手组级别加速探索执行记录
+ * @Author: jeecg-boot
+ * @Date:   2021-03-10
+ * @Version: V1.0
+ */
+public interface IKuaishouGroupSpeedExploreLogService extends IService<KuaishouGroupSpeedExploreLog> {
+
+}

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

@@ -7,16 +7,20 @@ import cn.com.ctop.common.module.utils.StatusCode;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouAccountSpeedExploreLog;
 import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouAccountSpeedExploreLogMapper;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAccountSpeedExploreLogService;
+import cn.com.ctop.kuaishou.modules.ai.vo.SpeedExploreGroupVO;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaishouGroupExploreService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -31,6 +35,10 @@ public class KuaishouAccountSpeedExploreLogServiceImpl extends ServiceImpl<Kuais
     private ICtopOauthTokenService tokenService;
     @Autowired
     private IKuaishouInterfaceService kuaishouInterfaceService;
+    @Autowired
+    private IKuaishouGroupExploreService kuaishouGroupExploreService;
+    @Resource
+    private KuaishouAccountSpeedExploreLogMapper kuaishouAccountSpeedExploreLogMapper;
     @Override
     public Map<String, Object> openSpeedExplore(KuaishouAccountSpeedExploreLog kuaishouAccountSpeedExploreLog) throws Exception{
         Map<String,Object> result = new HashMap<>();
@@ -61,9 +69,22 @@ public class KuaishouAccountSpeedExploreLogServiceImpl extends ServiceImpl<Kuais
         //3:根据转化目标查询相应的符合条件的广告组数据
         //优化目标 2 行为数 180 激活数 53 表单数 190 付费 191 首日ROI
         Integer convertType = kuaishouAccountSpeedExploreLog.getConvertType();
+        //查询相关符合条件的广告组数据
+        List<SpeedExploreGroupVO> speedExploreGroupVos = this.getSpeedExploreGroupVOSByParams(DateUtils.formatDate(endDate),kuaishouAccountSpeedExploreLog.getAccountId(),kuaishouAccountSpeedExploreLog.getConvertType(),kuaishouAccountSpeedExploreLog.getConvertCount(),kuaishouAccountSpeedExploreLog.getGroupCount());
+        if(null==speedExploreGroupVos||speedExploreGroupVos.isEmpty()){
+            speedExploreGroupVos.forEach(speedExploreGroupVO -> {
+                //触发加速探索逻辑
+                kuaishouGroupExploreService.unitOpenSpeedExplore(speedExploreGroupVO.getAccountId(),speedExploreGroupVO.getUnitId(),kuaishouAccountSpeedExploreLog.getGroupAccount(),kuaishouAccountSpeedExploreLog.getId());
+                //缺广告组加速探索记录数据表
+
+            });
+        }
 
 
+    }
 
+    private List<SpeedExploreGroupVO> getSpeedExploreGroupVOSByParams(String date, Long accountId, Integer convertType, Integer convertCount,Integer groupCount) {
+        return kuaishouAccountSpeedExploreLogMapper.getSpeedExploreGroupVosByParams(date,accountId,convertType,convertCount,groupCount);
     }
 
     @Override

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

@@ -0,0 +1,18 @@
+package cn.com.ctop.kuaishou.modules.ai.service.impl;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouGroupSpeedExploreLog;
+import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouGroupSpeedExploreLogMapper;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouGroupSpeedExploreLogService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * 快手组级别加速探索执行记录
+ * @author jeecg-boot
+ * @date   2021-03-10
+ * @version V1.0
+ */
+@Service
+public class KuaishouGroupSpeedExploreLogServiceImpl extends ServiceImpl<KuaishouGroupSpeedExploreLogMapper, KuaishouGroupSpeedExploreLog> implements IKuaishouGroupSpeedExploreLogService {
+
+}

+ 18 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/vo/SpeedExploreGroupVO.java

@@ -0,0 +1,18 @@
+package cn.com.ctop.kuaishou.modules.ai.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class SpeedExploreGroupVO {
+    private Long accountId;
+    private Long unitId;
+    private Long campaignId;
+    private BigDecimal charge;
+    private Long activation;
+    private Long bclick;
+    private Long formCount;
+    private Long eventPay;
+    private BigDecimal account;
+}

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

@@ -295,10 +295,12 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         param.put("temporal_granularity", "DAILY");
         param.put("page_size", 500);
         param.put("page", page);
+        System.out.println(param);
         String result = HttpUtils.httpPostRequest(url, param, headers);
         JSONObject resultJson = JSONObject.parseObject(result);
         Integer code = resultJson.getInteger("code");
         String message = resultJson.getString("message");
+        System.out.println(resultJson.toJSONString());
         if (null == code || code != 0) {
             log.error("获取快手广告主报表异常:{},accountId:{}", message, token.getAccountId());
             return;
@@ -1419,6 +1421,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     }
 
 
+    @Override
     public JSONArray getCreativeList(CtopOauthToken token, Long unitId, Date startDate, Date endDate, int timeFilterType) {
         Long advertiserId = token.getAccountId();
         String accessToken = token.getAccessToken();

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IKuaishouGroupExploreService.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.math.BigDecimal;
+
 /**
  * @Description: 广告组的加速探索报表
  * @Author: jeecg-boot
@@ -20,4 +22,7 @@ public interface IKuaishouGroupExploreService extends IService<KuaishouGroupExpl
     Result<Object> unitExploreStatusPause(JSONObject data);
 
     Result<Object> querySpeedExploreReport(JSONObject data);
+
+
+    void unitOpenSpeedExplore(Long accountId, Long unitId, BigDecimal groupAccount,Long accountExploreId);
 }

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

@@ -2,10 +2,8 @@ package cn.com.ctop.kuaishou.modules.report.service.impl;
 
 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.common.module.utils.HttpUtils;
-import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
-import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.common.module.utils.*;
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouGroupSpeedExploreLog;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouGroupExplore;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouGroupExploreMapper;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouGroupExploreService;
@@ -17,6 +15,7 @@ import org.jeecg.common.api.vo.Result;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -224,5 +223,39 @@ public class KuaishouGroupExploreServiceImpl extends ServiceImpl<KuaishouGroupEx
         return Result.error("查询广告组的加速探索报表失败");
     }
 
+    @Override
+    public void unitOpenSpeedExplore(Long accountId, Long unitId, BigDecimal groupAccount,Long accountExploreId) {
+        KuaishouGroupSpeedExploreLog groupSpeedExploreLog = new KuaishouGroupSpeedExploreLog();
+        groupSpeedExploreLog.setAccountExploreId(accountExploreId);
+        groupSpeedExploreLog.setAccountId(accountId);
+        try {
+            CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.UNIT_EXPLORE_BUDGET_UPDATE;
+            Map<String, String> header = new HashMap<>();
+            header.put("Access-Token", token.getAccessToken());
+            header.put("Content-Type", "application/json");
+            JSONObject params = new JSONObject();
+            params.put("advertiser_id", accountId);
+            params.put("unit_id", unitId);
+            params.put("explore_budget", groupAccount.longValue());
+            String result = HttpUtils.httpPostRequest(url, params, header);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            if (!Check.isNull(resultJson)) {
+                Integer code = resultJson.getInteger("code");
+                String message = resultJson.getString("message");
+                groupSpeedExploreLog.setStatus(code);
+                groupSpeedExploreLog.setMessage(message);
+            }else{
+                groupSpeedExploreLog.setStatus(StatusCode.KUAISHOU_SPEED_EXPLORE_FAIL.getCode());
+                groupSpeedExploreLog.setMessage(StatusCode.KUAISHOU_SPEED_EXPLORE_FAIL.getDesc());
+            }
+        } catch (Exception e) {
+            log.error("广告组的加速探索预算设置失败", e);
+            groupSpeedExploreLog.setStatus(StatusCode.COMMON_SERVER_ERROR.getCode());
+            groupSpeedExploreLog.setMessage(StatusCode.COMMON_SERVER_ERROR.getDesc());
+        }
+
+    }
+
 
 }