Browse Source

根据广告ID过滤发送次数

zhaoxian 1 year ago
parent
commit
21502caefd

+ 2 - 2
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/controller/BytedanceController.java

@@ -96,7 +96,7 @@ public class BytedanceController {
 //        List<Long> accountIds = tokenService.getAllToutiaoAccountIds();
 //        List<Long> accountIds = tokenService.getAllToutiaoAccountIds();
         List<JSONObject> accountIds = tokenService.getByProjectId(18450885L);
         List<JSONObject> accountIds = tokenService.getByProjectId(18450885L);
 
 
-        for (JSONObject obj : accountIds) {
+    /*    for (JSONObject obj : accountIds) {
 //            String token = tokenService.getByAccountId(id);
 //            String token = tokenService.getByAccountId(id);
             OauthToken oauthToken = new OauthToken();
             OauthToken oauthToken = new OauthToken();
             oauthToken.setAccessToken(obj.getString("accessToken"));
             oauthToken.setAccessToken(obj.getString("accessToken"));
@@ -116,7 +116,7 @@ public class BytedanceController {
                         }
                         }
                     });
                     });
 
 
-        }
+        }*/
         return "ok";
         return "ok";
     }
     }
 
 

+ 3 - 3
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/BytedanceProjectMapper.java

@@ -18,11 +18,11 @@ public interface BytedanceProjectMapper {
 
 
     void insertSendRecord(MediaSendAlarmRecord record);
     void insertSendRecord(MediaSendAlarmRecord record);
 
 
-    List<Long> getBytedanceRefusalSend();
+    List<Long> getBytedanceRefusalSend(@Param("accountId") Long accountId);
 
 
     List<Long> getSpecialProject();
     List<Long> getSpecialProject();
 
 
-    void insertSendAccountId(@Param("accountId") Long accountId, @Param("counts") Integer counts);
+    void insertSendAccountId(@Param("accountId") Long accountId, @Param("adId") Long adId, @Param("counts") Integer counts);
 
 
-    Integer getrefusalAccountCounts(@Param("accountId") Long accountId);
+    Integer getrefusalAccountCounts(@Param("accountId") Long accountId, @Param("adId") Long adId);
 }
 }

+ 5 - 2
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/BytedanceProjectMapper.xml

@@ -121,11 +121,12 @@
     <insert id="insertSendAccountId">
     <insert id="insertSendAccountId">
         replace
         replace
         into `jeecg-boot`.bytedance_refusal_send
         into `jeecg-boot`.bytedance_refusal_send
-        (account_id,
+        (account_id,ad_id,
          counts,
          counts,
          stat_date)
          stat_date)
         values (
         values (
         #{accountId},
         #{accountId},
+        #{adId},
         #{counts},
         #{counts},
         (DATE_FORMAT(now(),'%Y%m%d-%H'))
         (DATE_FORMAT(now(),'%Y%m%d-%H'))
         )
         )
@@ -133,9 +134,10 @@
 
 
 
 
     <select id="getBytedanceRefusalSend" resultType="Long">
     <select id="getBytedanceRefusalSend" resultType="Long">
-        SELECT account_id
+        SELECT ad_id
         FROM `jeecg-boot`.bytedance_refusal_send
         FROM `jeecg-boot`.bytedance_refusal_send
         WHERE stat_date = DATE_FORMAT(now(), '%Y%m%d-%H')
         WHERE stat_date = DATE_FORMAT(now(), '%Y%m%d-%H')
+          AND account_id =#{accountId}
           AND counts >= 2
           AND counts >= 2
     </select>
     </select>
 
 
@@ -153,6 +155,7 @@
         SELECT ifNUll(counts, 0)
         SELECT ifNUll(counts, 0)
         FROM `jeecg-boot`.bytedance_refusal_send
         FROM `jeecg-boot`.bytedance_refusal_send
         WHERE account_id = #{accountId}
         WHERE account_id = #{accountId}
+          AND ad_id = #{adId}
           AND stat_date = DATE_FORMAT(now(), '%Y%m%d-%H')
           AND stat_date = DATE_FORMAT(now(), '%Y%m%d-%H')
     </select>
     </select>
 
 

+ 38 - 15
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/BytedanceProjectServiceImpl.java

@@ -193,7 +193,7 @@ public class BytedanceProjectServiceImpl implements IBytedanceProjectService {
     }
     }
 
 
 
 
-    //检查 发送3次以后拒绝发送
+    //检查过滤账户和项目 flag为1 过滤掉
     private boolean checkThreeRejections(Long accountId) {
     private boolean checkThreeRejections(Long accountId) {
         Long projectId = projectListMapper.getProjectId(accountId);
         Long projectId = projectListMapper.getProjectId(accountId);
         List<Long> ids = projectListMapper.getSpecialProject();
         List<Long> ids = projectListMapper.getSpecialProject();
@@ -201,9 +201,14 @@ public class BytedanceProjectServiceImpl implements IBytedanceProjectService {
             //过滤标记 都不发送
             //过滤标记 都不发送
             return false;
             return false;
         }
         }
-        List<Long> accountIds = projectListMapper.getBytedanceRefusalSend();
-        if (!Check.isNull(accountIds)) {
-            return !accountIds.contains(accountId);
+        return true;
+    }
+
+    //检查广告ID 发送2次以后拒绝发送
+    private boolean checkAdSendCounts(Long accountId, Long adId) {
+        List<Long> adIds = projectListMapper.getBytedanceRefusalSend(accountId);
+        if (!Check.isNull(adIds)) {
+            return !adIds.contains(adId);
         }
         }
         return true;
         return true;
     }
     }
@@ -267,6 +272,7 @@ public class BytedanceProjectServiceImpl implements IBytedanceProjectService {
             //深度转化目标出价
             //深度转化目标出价
             String deepConversionBid = detail.getJSONObject("delivery_setting").getString("deep_cpabid");
             String deepConversionBid = detail.getJSONObject("delivery_setting").getString("deep_cpabid");
 
 
+            String pricing = detail.getString("pricing");
             List<JSONObject> advertiserList = new ArrayList<>();
             List<JSONObject> advertiserList = new ArrayList<>();
             if (Check.isNull(cpaBid) && Check.isNull(deepConversionBid)) {
             if (Check.isNull(cpaBid) && Check.isNull(deepConversionBid)) {
                 this.checkAdvertiserList(oauthToken, projectId, date, 1, advertiserList);
                 this.checkAdvertiserList(oauthToken, projectId, date, 1, advertiserList);
@@ -275,13 +281,27 @@ public class BytedanceProjectServiceImpl implements IBytedanceProjectService {
                         String statusFirst = adObj.getString("status_first");
                         String statusFirst = adObj.getString("status_first");
                         //一级状态:PROMOTION_STATUS_ENABLE 投放中
                         //一级状态:PROMOTION_STATUS_ENABLE 投放中
                         if ("PROMOTION_STATUS_ENABLE".equals(statusFirst)) {
                         if ("PROMOTION_STATUS_ENABLE".equals(statusFirst)) {
-                            checkLogic("ad", detail, ocpxMap, textMap, deepMap, adObj.getString("cpa_bid"),
+                            if (!checkAdSendCounts(detail.getLong("advertiser_id"), adObj.getLong("promotion_id"))) {
+                                continue;
+                            }
+                            String bid = adObj.getString("cpa_bid");
+                            if ("PRICING_CPM".equals(pricing)) {
+                                bid = adObj.getString("bid");
+                            }
+                            checkLogic("ad", detail, ocpxMap, textMap, deepMap, bid,
                                     adObj.getString("deep_cpabid"), json.getString("projectName"), adObj);
                                     adObj.getString("deep_cpabid"), json.getString("projectName"), adObj);
                         } else if ("PROMOTION_STATUS_DISABLE".equals(statusFirst)) {
                         } else if ("PROMOTION_STATUS_DISABLE".equals(statusFirst)) {
                             String statusSecond = adObj.getString("status_second");
                             String statusSecond = adObj.getString("status_second");
                             //除了广告二级状态 已暂停的状态,其他状态都需要预警
                             //除了广告二级状态 已暂停的状态,其他状态都需要预警
                             if (!"DISABLE_BY_QUOTA".equals(statusSecond)) {
                             if (!"DISABLE_BY_QUOTA".equals(statusSecond)) {
-                                checkLogic("ad", detail, ocpxMap, textMap, deepMap, adObj.getString("cpa_bid"),
+                                if (!checkAdSendCounts(detail.getLong("advertiser_id"), adObj.getLong("promotion_id"))) {
+                                    continue;
+                                }
+                                String bid = adObj.getString("cpa_bid");
+                                if ("PRICING_CPM".equals(pricing)) {
+                                    bid = adObj.getString("bid");
+                                }
+                                checkLogic("ad", detail, ocpxMap, textMap, deepMap, bid,
                                         adObj.getString("deep_cpabid"), json.getString("projectName"), adObj);
                                         adObj.getString("deep_cpabid"), json.getString("projectName"), adObj);
                             }
                             }
                         }
                         }
@@ -302,6 +322,9 @@ public class BytedanceProjectServiceImpl implements IBytedanceProjectService {
         Long projectId = detail.getLong("project_id");
         Long projectId = detail.getLong("project_id");
         //广告项目名称
         //广告项目名称
         String projectName = detail.getString("name");
         String projectName = detail.getString("name");
+        //广告ID
+        Long adId = adObj.getLong("promotion_id");
+
         JSONObject data = new JSONObject();
         JSONObject data = new JSONObject();
         //转化目标
         //转化目标
         String ocpxActionType = detail.getJSONObject("optimize_goal").getString("external_action");
         String ocpxActionType = detail.getJSONObject("optimize_goal").getString("external_action");
@@ -330,9 +353,9 @@ public class BytedanceProjectServiceImpl implements IBytedanceProjectService {
                 } else {
                 } else {
                     //未查询到转化出价,说明出价不一致,触发出价关停。
                     //未查询到转化出价,说明出价不一致,触发出价关停。
                     if (!Check.isNull(cpaBid)) {
                     if (!Check.isNull(cpaBid)) {
-                       /* bidFalg = false;
+                        bidFalg = false;
                         msgBid.append("[").append(octypeName).append("]目标出价为空");
                         msgBid.append("[").append(octypeName).append("]目标出价为空");
-                    } else {*/
+                    } else {
                         BigDecimal cpa = new BigDecimal(cpaBid).multiply(new BigDecimal("1000"));
                         BigDecimal cpa = new BigDecimal(cpaBid).multiply(new BigDecimal("1000"));
                         BigDecimal ocpx = new BigDecimal(ocpxBid);//本地设置
                         BigDecimal ocpx = new BigDecimal(ocpxBid);//本地设置
                         if (cpa.compareTo(ocpx) == 1) {
                         if (cpa.compareTo(ocpx) == 1) {
@@ -377,16 +400,16 @@ public class BytedanceProjectServiceImpl implements IBytedanceProjectService {
         }
         }
 
 
         if (!typeFalg) { // 出价方式设置非法
         if (!typeFalg) { // 出价方式设置非法
-            String text = getProjectBidTypeText(localProject, accountId, projectId, projectName, adObj.getLong("promotion_id"), adObj.getString("promotion_name"), msgType.toString());
-            sendMsg(accountId, projectId, text);
+            String text = getProjectBidTypeText(localProject, accountId, projectId, projectName, adId, adObj.getString("promotion_name"), msgType.toString());
+            sendMsg(accountId, projectId,adId, text);
         }
         }
         if (!bidFalg) {
         if (!bidFalg) {
-            String text = getProjectOverBidMessage(localProject, accountId, projectId, projectName, adObj.getLong("promotion_id"), adObj.getString("promotion_name"), msgBid.toString());
-            sendMsg(accountId, projectId, text);
+            String text = getProjectOverBidMessage(localProject, accountId, projectId, projectName, adId, adObj.getString("promotion_name"), msgBid.toString());
+            sendMsg(accountId, projectId,adId, text);
         }
         }
     }
     }
 
 
-    private void sendMsg(Long accountId, Long projectId, String text) {
+    private void sendMsg(Long accountId, Long projectId,Long adId, String text) {
         try {
         try {
             MediaSendAlarmRecord record = new MediaSendAlarmRecord(accountId, "1", text);
             MediaSendAlarmRecord record = new MediaSendAlarmRecord(accountId, "1", text);
             record.setProjectId(projectId);
             record.setProjectId(projectId);
@@ -402,9 +425,9 @@ public class BytedanceProjectServiceImpl implements IBytedanceProjectService {
             projectListMapper.insertSendRecord(record);
             projectListMapper.insertSendRecord(record);
             //当前已发送次数
             //当前已发送次数
 
 
-            Integer i = projectListMapper.getrefusalAccountCounts(accountId);
+            Integer i = projectListMapper.getrefusalAccountCounts(accountId,adId);
             //更新计数
             //更新计数
-            projectListMapper.insertSendAccountId(accountId, (Check.isNull(i) ? 0 : i) + 1);
+            projectListMapper.insertSendAccountId(accountId, adId,(Check.isNull(i) ? 0 : i) + 1);
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();
         }
         }