浏览代码

规则引擎迭代,添加安卓版本、深度转化目标出价预警

zhaoxian 4 年之前
父节点
当前提交
947fa74449

+ 76 - 35
module-common/src/main/java/cn/com/ctop/common/module/entity/RuleDateUnitKuaishou.java

@@ -1,51 +1,92 @@
 package cn.com.ctop.common.module.entity;
 
-import java.math.BigDecimal;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 
+import java.math.BigDecimal;
+
 /**
  * 快手预警组数据
  */
 @Data
 @TableName("ctop_rule_data_unit_kuaishou")
 public class RuleDateUnitKuaishou {
-    
-	/**id*/
-	private Long id;
-	/**accountId*/
-	private Long accountId;
-    /**planId*/
+
+    /**
+     * id
+     */
+    private Long id;
+    /**
+     * accountId
+     */
+    private Long accountId;
+    /**
+     * planId
+     */
     private Long planId;
-	/**unitId*/
-	private Long unitId;
-	/**unitName*/
-	private String unitName;
-	/**消耗*/
-	private BigDecimal charge;
-
-	private Long convertNum;
-
-	private BigDecimal convertCost;
-
-	/**activation*/
-	private Long activation;
-	/**激活单价*/
-	private BigDecimal activationCost;
-	/**注册数*/
-	private Long eventRegister;
-	/**表单*/
-	private BigDecimal registerCost;
-	/**表单*/
-	private Long formCount;
-	/**表单提交单价*/
-	private BigDecimal formCost;
-	/**付费*/
-	private Long eventPay;
-	/**付费单价*/
-	private BigDecimal payCost;
+    /**
+     * unitId
+     */
+    private Long unitId;
+    /**
+     * unitName
+     */
+    private String unitName;
+    /**
+     * 消耗
+     */
+    private BigDecimal charge;
+
+    private Long convertNum;
+
+    private BigDecimal convertCost;
+
+    /**
+     * activation
+     */
+    private Long activation;
+    /**
+     * 激活单价
+     */
+    private BigDecimal activationCost;
+    /**
+     * 注册数
+     */
+    private Long eventRegister;
+    /**
+     * 表单
+     */
+    private BigDecimal registerCost;
+    /**
+     * 表单
+     */
+    private Long formCount;
+    /**
+     * 表单提交单价
+     */
+    private BigDecimal formCost;
+    /**
+     * 付费
+     */
+    private Long eventPay;
+    /**
+     * 深度转化目标出价
+     */
+    private Long deepConversionBid;
+    /**
+     * 深度转化目标 3: 付费,7: 次日留存,10: 完件, 11: 授信 ,0:无
+     */
+    private Integer deepConversionType;
+    /**
+     * 安卓版本  3:不限, 4: 4.x+, 5: 5.x+, 6: 6.x+, 7: 7.x+;
+     */
+    private Integer androidOsv;
+    /**
+     * 付费单价
+     */
+    private BigDecimal payCost;
 
     private Integer status;
 
-	private java.util.Date createTime;
+    private java.util.Date createTime;
 }

+ 56 - 41
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/RuleKuaiShouPlanServiceImpl.java

@@ -11,7 +11,9 @@ import cn.com.ctop.common.module.service.IRuleDatePlanKuaishouService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroupTarget;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupTargetService;
 import cn.com.ctop.kuaishou.modules.report.service.IRuleKuaiShouPlanService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -29,7 +31,7 @@ import java.util.List;
 import java.util.Map;
 
 @Service
-public class RuleKuaiShouPlanServiceImpl extends ServiceImpl<RuleDatePlanKuaishouMapper, RuleDatePlanKuaishou>  implements IRuleKuaiShouPlanService {
+public class RuleKuaiShouPlanServiceImpl extends ServiceImpl<RuleDatePlanKuaishouMapper, RuleDatePlanKuaishou> implements IRuleKuaiShouPlanService {
 
     @Autowired
     ICtopOauthTokenService oauthTokenService;
@@ -46,6 +48,9 @@ public class RuleKuaiShouPlanServiceImpl extends ServiceImpl<RuleDatePlanKuaisho
     @Autowired
     IKuaiShouGroupService kuaiShouGroupService;
 
+    @Autowired
+    private IKuaiShouGroupTargetService kuaiShouGroupTargetService;
+
     @Override
     public void cleanRuleDataPlan(Long accountId, int page) {
         JSONObject param = new JSONObject();
@@ -82,8 +87,8 @@ public class RuleKuaiShouPlanServiceImpl extends ServiceImpl<RuleDatePlanKuaisho
         param.put("advertiser_id", accountId);
         param.put("page_size", 500);
         param.put("page", page);
-        param.put("start_date",startDate);
-        param.put("end_date",endDate);
+        param.put("start_date", startDate);
+        param.put("end_date", endDate);
 
         Map<String, String> headers = new HashMap<>();
         headers.put("Access-Token", oauthTokenService.getTokenByAccountId(accountId).getAccessToken());
@@ -152,7 +157,7 @@ public class RuleKuaiShouPlanServiceImpl extends ServiceImpl<RuleDatePlanKuaisho
                 batch.add(plan);
             }
         });
-        if(!batch.isEmpty()) {
+        if (!batch.isEmpty()) {
             planKuaishouService.saveOrUpdateBatch(batch);
         }
     }
@@ -162,23 +167,32 @@ public class RuleKuaiShouPlanServiceImpl extends ServiceImpl<RuleDatePlanKuaisho
         details.forEach(detail -> {
             JSONObject unitDetail = (JSONObject) detail;
             RuleDateUnitKuaishou unit = new RuleDateUnitKuaishou();
-            QueryWrapper<KuaiShouGroup> wrapper=new QueryWrapper<>();
-            wrapper.eq("unit_id",unitDetail.getLong("unit_id"));
+            QueryWrapper<KuaiShouGroup> wrapper = new QueryWrapper<>();
+            wrapper.eq("unit_id", unitDetail.getLong("unit_id"));
             KuaiShouGroup group = kuaiShouGroupService.getOne(wrapper);
-            if(group!=null){
+            if (group != null) {
                 Integer status = group.getStatus();
                 Integer putStatus = group.getPutStatus();
-                if((status == 20 || status == 19) && putStatus == 1){
+                if ((status == 20 || status == 19) && putStatus == 1) {
+                    QueryWrapper<KuaiShouGroupTarget> targetWrapper = new QueryWrapper<>();
+                    targetWrapper.eq("unit_id", unitDetail.getLong("unit_id"));
+                    KuaiShouGroupTarget groupTarget = kuaiShouGroupTargetService.getOne(targetWrapper);
+                    if (!Check.isNull(groupTarget)) {
+                        unit.setAndroidOsv(groupTarget.getAndroidOsv());
+                    }
                     unit.setId(unitDetail.getLong("unit_id"));
                     unit.setAccountId(accountId);
                     unit.setPlanId(unitDetail.getLong("campaign_id"));
                     unit.setUnitId(unitDetail.getLong("unit_id"));
                     unit.setUnitName(unitDetail.getString("unit_name"));
                     unit.setCharge(unitDetail.getBigDecimal("charge"));
+                    unit.setDeepConversionBid(group.getDeepConversionBid());
+                    unit.setDeepConversionType(group.getDeepConversionType());
+
                     //未知优化目标数据存空
-                    if(group.getOcpxActionType()!=0){
-                        unit.setConvertNum(handleConvertNum(group.getOcpxActionType(),unitDetail));
-                        if(null!=unit.getConvertNum()&&unit.getConvertNum()!=0){
+                    if (group.getOcpxActionType() != 0) {
+                        unit.setConvertNum(handleConvertNum(group.getOcpxActionType(), unitDetail));
+                        if (null != unit.getConvertNum() && unit.getConvertNum() != 0) {
                             unit.setConvertCost(unitDetail.getBigDecimal("charge").divide(BigDecimal.valueOf(unit.getConvertNum()), 2, RoundingMode.HALF_UP));
                         }
                     }
@@ -187,7 +201,7 @@ public class RuleKuaiShouPlanServiceImpl extends ServiceImpl<RuleDatePlanKuaisho
             }
 
         });
-        if(!batch.isEmpty()){
+        if (!batch.isEmpty()) {
             unitKuaishouService.saveOrUpdateBatch(batch);
         }
     }
@@ -204,49 +218,49 @@ public class RuleKuaiShouPlanServiceImpl extends ServiceImpl<RuleDatePlanKuaisho
                 target.setAccountId(accountId);
                 target.setPlanId(unitDetail.getLong("campaign_id"));
                 target.setUnitId(unitDetail.getLong("unit_id"));
-                target.setSceneId(unitDetail.getJSONArray("scene_id")==null?"":unitDetail.getJSONArray("scene_id").toString());
+                target.setSceneId(unitDetail.getJSONArray("scene_id") == null ? "" : unitDetail.getJSONArray("scene_id").toString());
                 //获取组定向信息
                 JSONObject unitTarget = unitDetail.getJSONObject("target");
                 //地域
                 JSONArray region = unitTarget.getJSONArray("region");
-                target.setRegion(region==null?"":region.toJSONString());
+                target.setRegion(region == null ? "" : region.toJSONString());
                 //性别
                 Integer gender = unitDetail.getJSONObject("target").getInteger("gender");
-                target.setGender(gender==null?0:gender);
+                target.setGender(gender == null ? 0 : gender);
                 //年龄
                 JSONArray agesRange = unitTarget.getJSONArray("ages_range");
-                target.setAgesRange(agesRange==null?"":agesRange.toJSONString());
+                target.setAgesRange(agesRange == null ? "" : agesRange.toJSONString());
                 //操作系统
                 Integer platformOs = unitTarget.getInteger("platform_os");
-                target.setPlatformOs(platformOs==null?0:platformOs);
+                target.setPlatformOs(platformOs == null ? 0 : platformOs);
                 //设类类型
                 JSONArray deviceBrand = unitTarget.getJSONArray("device_brand");
-                target.setDeviceBrand(deviceBrand==null?"":deviceBrand.toJSONString());
+                target.setDeviceBrand(deviceBrand == null ? "" : deviceBrand.toJSONString());
                 //设备价格
                 JSONArray devicePrice = unitTarget.getJSONArray("device_price");
-                target.setDevicePrice(devicePrice==null?"":devicePrice.toJSONString());
+                target.setDevicePrice(devicePrice == null ? "" : devicePrice.toJSONString());
                 //过滤已转化人群
                 Integer filterConvertedLevel = unitTarget.getInteger("filter_converted_level");
                 target.setFilterConvertedLevel(filterConvertedLevel);
                 //人群包定向
                 JSONArray population = unitTarget.getJSONArray("population");
-                target.setPopulation(population==null?"":population.toJSONString());
+                target.setPopulation(population == null ? "" : population.toJSONString());
                 //人群包排除
                 JSONArray excludePopulation = unitTarget.getJSONArray("exclude_population");
-                target.setExcludePopulation(excludePopulation==null?"":excludePopulation.toJSONString());
+                target.setExcludePopulation(excludePopulation == null ? "" : excludePopulation.toJSONString());
                 //应用商店
                 JSONArray appStore = unitDetail.getJSONArray("app_store");
-                target.setAppStore(appStore==null?"":appStore.toJSONString());
+                target.setAppStore(appStore == null ? "" : appStore.toJSONString());
                 //商业兴趣
                 JSONArray businessInterest = unitTarget.getJSONArray("business_interest");
-                target.setBusinessInterest(businessInterest==null?"":businessInterest.toJSONString());
+                target.setBusinessInterest(businessInterest == null ? "" : businessInterest.toJSONString());
                 //网络环境
                 Integer network = unitTarget.getInteger("network");
-                target.setNetwork(network==null?0:network);
+                target.setNetwork(network == null ? 0 : network);
 
                 Integer isOpen = unitDetail.getJSONObject("target").getJSONObject("intelli_extend").getInteger("is_open");
-                target.setIsOpen(isOpen==null?0:isOpen);
-                target.setScheduleTime(unitDetail.getString("schedule_time")==null?"":unitDetail.getString("schedule_time"));
+                target.setIsOpen(isOpen == null ? 0 : isOpen);
+                target.setScheduleTime(unitDetail.getString("schedule_time") == null ? "" : unitDetail.getString("schedule_time"));
 
                 batch.add(target);
             }
@@ -265,48 +279,49 @@ public class RuleKuaiShouPlanServiceImpl extends ServiceImpl<RuleDatePlanKuaisho
      * 383: 授信,event_credit_grant_app
      * 384: 完件 event_jin_jian_app
      * 715:微信复制 event_add_wechat
+     *
      * @param ocpxActionType
      * @param detail
      * @return
      */
-    private Long handleConvertNum(int ocpxActionType,JSONObject detail){
-        Long convertNum=null;
-        switch (ocpxActionType){
+    private Long handleConvertNum(int ocpxActionType, JSONObject detail) {
+        Long convertNum = null;
+        switch (ocpxActionType) {
             case 2:
-                convertNum=detail.getLong("bclick");
+                convertNum = detail.getLong("bclick");
                 break;
             case 10:
-                convertNum=detail.getLong("aclick");
+                convertNum = detail.getLong("aclick");
                 break;
             case 11:
-                convertNum=detail.getLong("photo_click");
+                convertNum = detail.getLong("photo_click");
                 break;
             case 31:
-                convertNum=detail.getLong("download_completed");
+                convertNum = detail.getLong("download_completed");
                 break;
             case 53:
-                convertNum=detail.getLong("form_count");
+                convertNum = detail.getLong("form_count");
                 break;
             case 180:
-                convertNum=detail.getLong("activation");
+                convertNum = detail.getLong("activation");
                 break;
             case 190:
-                convertNum=detail.getLong("event_pay");
+                convertNum = detail.getLong("event_pay");
                 break;
             case 191:
-                convertNum=detail.getDouble("event_pay_first_day_roi").longValue();
+                convertNum = detail.getDouble("event_pay_first_day_roi").longValue();
                 break;
             case 348:
-                convertNum=detail.getLong("event_valid_clues");
+                convertNum = detail.getLong("event_valid_clues");
                 break;
             case 383:
-                convertNum=detail.getLong("event_credit_grant_app");
+                convertNum = detail.getLong("event_credit_grant_app");
                 break;
             case 384:
-                convertNum=detail.getLong("event_jin_jian_app");
+                convertNum = detail.getLong("event_jin_jian_app");
                 break;
             case 715:
-                convertNum=detail.getLong("event_add_wechat");
+                convertNum = detail.getLong("event_add_wechat");
                 break;
         }
         return convertNum;