瀏覽代碼

快手广告组出价预警,发送内容优化

zhaoxian 3 年之前
父節點
當前提交
89170d9fb7

+ 2 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/KuaiShouOcpxActionTypeConfigMapper.java

@@ -18,4 +18,6 @@ import java.util.List;
 public interface KuaiShouOcpxActionTypeConfigMapper extends BaseMapper<KuaiShouOcpxActionTypeConfig> {
 
     List<JSONObject> bytedanceList(@Param("level") Integer level);
+
+    List<JSONObject> getKuaiShouOcpxTypeList();
 }

+ 7 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/xml/KuaiShouOcpxActionTypeConfigMapper.xml

@@ -11,4 +11,11 @@
         from ctop_bytedance_ocpx_action_type_config
         where `level` = #{level}
     </select>
+
+    <select id="getKuaiShouOcpxTypeList" resultType="com.alibaba.fastjson.JSONObject">
+        select
+            ocpx_action_type as 'ocpxActionType',
+            ocpx_action_name as 'ocpxActionName'
+        from ctop_kuaishou_ocpx_action_type_config
+    </select>
 </mapper>

+ 2 - 2
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/IMessageTemplate.java

@@ -68,7 +68,7 @@ public interface IMessageTemplate {
      * @return
      */
 
-    String getKuaiShouBidTypeMessage(String projectName, Long advertiserId, Long unitId, String unit_name);
+    String getKuaiShouBidTypeMessage(String projectName, Long advertiserId, Long unitId, String unit_name,String msgType);
 
 
     /**
@@ -80,7 +80,7 @@ public interface IMessageTemplate {
      * @param unit_name
      * @return
      */
-    String getKuaiShouBidMessage(String projectName, Long advertiserId, Long unitId, String unit_name);
+    String getKuaiShouBidMessage(String projectName, Long advertiserId, Long unitId, String unit_name,String msgBid);
 
     String getCopyCampaignMessage(String oldName, String state);
 

+ 4 - 2
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/MessageTemplateImpl.java

@@ -168,7 +168,7 @@ public class MessageTemplateImpl implements IMessageTemplate {
      */
 
     @Override
-    public String getKuaiShouBidTypeMessage(String projectName, Long advertiserId, Long unitId, String unit_name) {
+    public String getKuaiShouBidTypeMessage(String projectName, Long advertiserId, Long unitId, String unit_name,String msgType) {
         StringBuilder text = new StringBuilder();
         text.append("出价方式错误预警").append("<br/>")
                 .append("您的项目:").append(projectName + ",").append("<br/>")
@@ -176,12 +176,13 @@ public class MessageTemplateImpl implements IMessageTemplate {
                 .append("广告组id为:").append(unitId).append("<br/>")
                 .append("广告组名称为:").append(unit_name).append("<br/>")
                 .append("出价方式设置错误。").append("<br/>")
+                .append(msgType).append("<br/>")
                 .append("系统已执行暂停此组操作,请您及时查看!");
         return text.toString();
     }
 
     @Override
-    public String getKuaiShouBidMessage(String projectName, Long advertiserId, Long unitId, String unit_name) {
+    public String getKuaiShouBidMessage(String projectName, Long advertiserId, Long unitId, String unit_name,String msgBid) {
         StringBuilder text = new StringBuilder();
         text.append("出价过高预警").append("<br/>")
                 .append("您的项目:").append(projectName + ",").append("<br/>")
@@ -189,6 +190,7 @@ public class MessageTemplateImpl implements IMessageTemplate {
                 .append("广告组id为:").append(unitId).append("<br/>")
                 .append("广告组名称为:").append(unit_name).append("<br/>")
                 .append("出价设置过高。").append("<br/>")
+                .append(msgBid).append("<br/>")
                 .append("系统已执行暂停此组操作,请您及时查看!");
         return text.toString();
     }

+ 43 - 8
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouGroupServiceImpl.java

@@ -1,10 +1,17 @@
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
+import cn.com.ctop.common.module.mapper.KuaiShouOcpxActionTypeConfigMapper;
+import cn.com.ctop.common.module.service.IMessageTemplate;
 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.*;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAppInfo;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
+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.entity.KuaiShouSchedule;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouAppInfoMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupTargetMapper;
@@ -22,7 +29,11 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -49,7 +60,10 @@ public class KuaiShouGroupServiceImpl extends ServiceImpl<KuaiShouGroupMapper, K
     private static ExecutorService executorService = Executors.newFixedThreadPool(10);
     @Autowired
     private IKuaiShouCreativeService creativeService;
-
+    @Autowired
+    private KuaiShouOcpxActionTypeConfigMapper ocpxActionTypeConfigMapper;
+    @Autowired
+    private IMessageTemplate messageTemplate;
 
     /**
      * 获取广告组
@@ -86,7 +100,7 @@ public class KuaiShouGroupServiceImpl extends ServiceImpl<KuaiShouGroupMapper, K
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GROUP_LIST;
         JSONObject param = new JSONObject();
         param.put("advertiser_id", accountId);
-        if(!Check.isNull(campaignId)){
+        if (!Check.isNull(campaignId)) {
             param.put("campaign_id", campaignId);
         }
         param.put("page_size", 500);
@@ -132,9 +146,9 @@ public class KuaiShouGroupServiceImpl extends ServiceImpl<KuaiShouGroupMapper, K
     }
 
     @Override
-    public Integer queryToDayBuiltCount(Long accountId,Integer unitType) {
+    public Integer queryToDayBuiltCount(Long accountId, Integer unitType) {
         String date = DateUtil.formatDate(new Date());
-        return groupMapper.queryToDayBuiltCount(accountId, date,unitType);
+        return groupMapper.queryToDayBuiltCount(accountId, date, unitType);
     }
 
     @Override
@@ -368,6 +382,12 @@ public class KuaiShouGroupServiceImpl extends ServiceImpl<KuaiShouGroupMapper, K
             }
         }
         if (!Check.isNull(details)) {
+            Map<Integer, String> textMap = new HashMap<>();
+            List<JSONObject> lists = ocpxActionTypeConfigMapper.getKuaiShouOcpxTypeList();
+            for (JSONObject da : lists) {
+                textMap.put(da.getInteger("ocpxActionType"), da.getString("ocpxActionName"));
+            }
+
             List<KuaiShouGroup> groups = new ArrayList<>();
             List<KuaiShouAppInfo> appInfos = new ArrayList<>();
             List<KuaiShouSchedule> schedules = new ArrayList<>();
@@ -398,6 +418,9 @@ public class KuaiShouGroupServiceImpl extends ServiceImpl<KuaiShouGroupMapper, K
                     //投放状态
                     Integer putStatus = detail.getInteger("put_status");
                     if (putStatus == 1 && status != 15) { // 组状态为 投放中的 and 广告组状态为非暂停
+                        String msgType = "";
+                        String msgBid = "";
+
                         Boolean typeFalg = true;
                         Boolean bidFalg = true;
 
@@ -405,14 +428,18 @@ public class KuaiShouGroupServiceImpl extends ServiceImpl<KuaiShouGroupMapper, K
                         if (!bidList.isEmpty()) {
                             if (!bidList.contains(bidType)) {
                                 //项目不包含该优化目标,则关停
+                                String msg = Check.isNull(textMap.get(bidType)) ? String.valueOf(bidType) : textMap.get(bidType);
+                                msgType = "组优化目标:" + msg;
                                 typeFalg = false;
                             } else if (bidType == 2 && bid > maxBid) {
                                 //若优化目标为2点击数,并且广告组出价大于项目设置最大出价,则关停
                                 bidFalg = false;
+                                msgBid = "优化为点击且优化出价:" + bid + " > 项目最大出价:" + maxBid;
                             }
                         }
                         //转化目标
                         if (!Check.isNull(ocpxActionType) && ocpxActionType != 0) {
+                            String msg = Check.isNull(textMap.get(ocpxActionType)) ? String.valueOf(ocpxActionType) : textMap.get(ocpxActionType);
                             //!=0是设置过转化目标
                             if (!Check.isNullMap(ocpxMap)) {
                                 Long ocpxBid = ocpxMap.get(ocpxActionType);
@@ -420,35 +447,43 @@ public class KuaiShouGroupServiceImpl extends ServiceImpl<KuaiShouGroupMapper, K
                                     if (ocpxActionType == 2 && dayBudget != 0 && dayBudget <= 500 * 1000) {
                                         // 转化目标为2行为数,并且预算小于等于500且不是不限,则允许启动
                                         typeFalg = true;
-                                    }else{
+                                    } else {
                                         //通过key未获取值,说明不包含该目标,进行关停
                                         typeFalg = false;
+                                        msgType = "组转化目标:" + msg + ",日预算为:" + dayBudget;
                                     }
                                 } else {
                                     if (cpaBid > ocpxBid) {
                                         //组转化出价 大于 项目设置最大转化出价,则关停
                                         bidFalg = false;
+                                        msgBid = "转化出价:" + cpaBid + " > 项目出价:" + ocpxBid;
                                     }
                                 }
-                            }else if (ocpxActionType == 2 && (dayBudget == 0 || dayBudget > 500 * 1000)) {
+                            } else if (ocpxActionType == 2 && (dayBudget == 0 || dayBudget > 500 * 1000)) {
                                 // 转化目标为2行为数,并且预算大于500 或者不限,则关停
                                 typeFalg = false;
+                                msgType = "组转化目标:" + msg + ",日预算为:" + dayBudget;
                             }
                         }
 
                         //转化目标
                         if (!Check.isNull(deepConversionType) && deepConversionType != 0 && !deepMap.isEmpty()) {
+                            String msg = Check.isNull(textMap.get(deepConversionType)) ? String.valueOf(deepConversionType) : textMap.get(deepConversionType);
                             Long deepBid = deepMap.get(deepConversionType);
                             if (Check.isNull(deepBid)) {
                                 //通过key未获取值,说明不包含该目标,进行关停
                                 typeFalg = false;
+                                msgType = "组深度转化目标:" + msg;
                             } else {
                                 if (deepConversionBid > deepBid) {
                                     //组深度转化出价 大于 项目设置最大转化出价,则关停
                                     bidFalg = false;
+                                    msgBid = "深度转化出价:" + deepConversionBid + " > 项目出价:" + deepBid;
                                 }
                             }
                         }
+                        String typeText = messageTemplate.getKuaiShouBidTypeMessage(json.getString("projectName"), advertiserId, unitId, unitName, msgType);
+                        String bidText = messageTemplate.getKuaiShouBidMessage(json.getString("projectName"), advertiserId, unitId, unitName, msgBid);
 
                         if (!typeFalg) { // 出价方式设置非法
                             executorBidTypeService.submit(new Runnable() {

+ 36 - 8
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -4,8 +4,10 @@ import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.entity.OauthConfig;
 import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.enums.MaterialEnum;
+import cn.com.ctop.common.module.mapper.KuaiShouOcpxActionTypeConfigMapper;
 import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.service.IMaterialCutFrameService;
+import cn.com.ctop.common.module.service.IMessageTemplate;
 import cn.com.ctop.common.module.service.IOauthConfigService;
 import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.Check;
@@ -184,6 +186,11 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     private IKuaishouAppPackageService appPackageService;
     @Autowired
     private UserAllocationMapper allocationMapper;
+    @Autowired
+    private KuaiShouOcpxActionTypeConfigMapper ocpxActionTypeConfigMapper;
+    @Autowired
+    private IMessageTemplate messageTemplate;
+
     private static ExecutorService cutExecutorService = Executors.newFixedThreadPool(10);
 
     @Override
@@ -1332,6 +1339,13 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 ocpxMap.put(obj.getInteger("deepCode"), obj.getLong("deepValue"));
             }
         }
+
+        Map<Integer, String> textMap = new HashMap<>();
+        List<JSONObject> lists = ocpxActionTypeConfigMapper.getKuaiShouOcpxTypeList();
+        for (JSONObject da : lists) {
+            textMap.put(da.getInteger("ocpxActionType"), da.getString("ocpxActionName"));
+        }
+
         List<KuaiShouGroup> groups = new ArrayList<>();
         for (int i = 0; i < details.size(); i++) {
             JSONObject detail = JSONObject.parseObject(details.get(i).toString());
@@ -1359,6 +1373,9 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 //投放状态
                 Integer putStatus = detail.getInteger("put_status");
                 if (putStatus == 1 && status != 15) { // 组状态为 投放中的 and 广告组状态为非暂停
+                    String msgType = "";
+                    String msgBid = "";
+
                     Boolean typeFalg = true;
                     Boolean bidFalg = true;
 
@@ -1366,14 +1383,18 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     if (!bidList.isEmpty()) {
                         if (!bidList.contains(bidType)) {
                             //项目不包含该优化目标,则关停
+                            String msg = Check.isNull(textMap.get(bidType)) ? String.valueOf(bidType) : textMap.get(bidType);
+                            msgType = "组优化目标:" + msg;
                             typeFalg = false;
                         } else if (bidType == 2 && bid > maxBid) {
                             //若优化目标为2点击数,并且广告组出价大于项目设置最大出价,则关停
                             bidFalg = false;
+                            msgBid = "优化为点击且优化出价:" + bid + " > 项目最大出价:" + maxBid;
                         }
                     }
                     //转化目标
                     if (!Check.isNull(ocpxActionType) && ocpxActionType != 0) {
+                        String msg = Check.isNull(textMap.get(ocpxActionType)) ? String.valueOf(ocpxActionType) : textMap.get(ocpxActionType);
                         //!=0是设置过转化目标
                         if (!Check.isNullMap(ocpxMap)) {
                             Long ocpxBid = ocpxMap.get(ocpxActionType);
@@ -1381,41 +1402,48 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                                 if (ocpxActionType == 2 && dayBudget != 0 && dayBudget <= 500 * 1000) {
                                     // 转化目标为2行为数,并且预算小于等于500且不是不限,则允许启动
                                     typeFalg = true;
-                                }else{
-                                //通过key未获取值,说明不包含该目标,进行关停
-                                typeFalg = false;
+                                } else {
+                                    //通过key未获取值,说明不包含该目标,进行关停
+                                    typeFalg = false;
+                                    msgType = "组转化目标:" + msg + ",日预算为:" + dayBudget;
                                 }
                             } else {
                                 if (cpaBid > ocpxBid) {
                                     //组转化出价 大于 项目设置最大转化出价,则关停
                                     bidFalg = false;
+                                    msgBid = "转化出价:" + cpaBid + " > 项目出价:" + ocpxBid;
                                 }
                             }
-                        }else if (ocpxActionType == 2 && (dayBudget == 0 || dayBudget > 500 * 1000)) {
+                        } else if (ocpxActionType == 2 && (dayBudget == 0 || dayBudget > 500 * 1000)) {
                             // 转化目标为2行为数,并且预算大于500 或者不限,则关停
                             typeFalg = false;
+                            msgType = "组转化目标:" + msg + ",日预算为:" + dayBudget;
                         }
                     }
 
                     //转化目标
                     if (!Check.isNull(deepConversionType) && deepConversionType != 0 && !deepMap.isEmpty()) {
+                        String msg = Check.isNull(textMap.get(deepConversionType)) ? String.valueOf(deepConversionType) : textMap.get(deepConversionType);
                         Long deepBid = deepMap.get(deepConversionType);
                         if (Check.isNull(deepBid)) {
                             //通过key未获取值,说明不包含该目标,进行关停
                             typeFalg = false;
+                            msgType = "组深度转化目标:" + msg;
                         } else {
                             if (deepConversionBid > deepBid) {
                                 //组深度转化出价 大于 项目设置最大转化出价,则关停
                                 bidFalg = false;
+                                msgBid = "深度转化出价:" + deepConversionBid + " > 项目出价:" + deepBid;
                             }
                         }
                     }
-
+                    String typeText = messageTemplate.getKuaiShouBidTypeMessage(project.getString("projectName"), accountId, unitId, unitName, msgType);
+                    String bidText = messageTemplate.getKuaiShouBidMessage(project.getString("projectName"), accountId, unitId, unitName, msgBid);
                     if (!typeFalg) { // 出价方式设置非法
                         executorBidTypeService.submit(new Runnable() {
                             @Override
                             public void run() {
-                                warningOperationService.kuaiShouWarningOperation(project.getLong("projectId"), project.getString("projectName"), accountId, unitId, unitName);
+                                warningOperationService.kuaiShouWarningOperation(project.getLong("projectId"), typeText, accountId, unitId, unitName);
                             }
                         });
                     }
@@ -1423,7 +1451,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                         executorMaxBidService.submit(new Runnable() {
                             @Override
                             public void run() {
-                                warningOperationService.kuaiShouBidWarningOperation(project.getLong("projectId"), project.getString("projectName"), accountId, unitId, unitName);
+                                warningOperationService.kuaiShouBidWarningOperation(project.getLong("projectId"), bidText, accountId, unitId, unitName);
                             }
                         });
                     }
@@ -2835,7 +2863,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     if (!Check.isNull(addList)) {
                         populationService.replaceBatch(addList);
                     }
-                 //   getPopulationList(accountId, accessToken, page + 1);
+                    //   getPopulationList(accountId, accessToken, page + 1);
                 } else {
                     log.error("获取人群包管理返回数据为空,accountId:{}", accountId);
 

+ 7 - 14
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/WarningOperationServiceImpl.java

@@ -57,7 +57,7 @@ public class WarningOperationServiceImpl implements IWarningOperationService {
      */
 
     @Override
-    public void kuaiShouWarningOperation(Long projectId, String projectName, Long advertiserId, Long unitId, String unit_name) {
+    public void kuaiShouWarningOperation(Long projectId, String text, Long advertiserId, Long unitId, String unit_name) {
         String userId = userAllocationMapper.queryUserIdByAccountId(advertiserId);
         CtopOauthToken token = oauthTokenService.getTokenByAccountId(advertiserId);
         updateService.updateUnitStatus(token.getAccessToken(), advertiserId, unitId, 2, "admin");
@@ -70,8 +70,6 @@ public class WarningOperationServiceImpl implements IWarningOperationService {
         warningOperationLogService.save(warningOperationLog);
         log.info("出价方式预警,暂停组成功,accountId:{},unitId:{}", advertiserId, unitId);
         try {
-            String text = messageTemplate.getKuaiShouBidTypeMessage(projectName, advertiserId, unitId, unit_name);
-
             sendMessageService.sendMessage(userId, text);
         } catch (Exception e) {
             e.printStackTrace();
@@ -92,19 +90,10 @@ public class WarningOperationServiceImpl implements IWarningOperationService {
      */
 
     @Override
-    public void kuaiShouBidWarningOperation(Long projectId, String projectName, Long advertiserId, Long unitId, String unit_name) {
+    public void kuaiShouBidWarningOperation(Long projectId, String text, Long advertiserId, Long unitId, String unit_name) {
         String userId = userAllocationMapper.queryUserIdByAccountId(advertiserId);
-        try {
-            String text = messageTemplate.getKuaiShouBidMessage(projectName, advertiserId, unitId, unit_name);
-            sendMessageService.sendMessage(userId, text);
-
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
         CtopOauthToken token = oauthTokenService.getTokenByAccountId(advertiserId);
         updateService.updateUnitStatus(token.getAccessToken(), advertiserId, unitId, 2, "admin");
-
         WarningOperationLog warningOperationLog = new WarningOperationLog();
         warningOperationLog.setAccountId(advertiserId);
         warningOperationLog.setSubject("出价过高预警");
@@ -113,6 +102,10 @@ public class WarningOperationServiceImpl implements IWarningOperationService {
         warningOperationLog.setWarningType(2);
         warningOperationLogService.save(warningOperationLog);
         log.info("出价过高预警,暂停组成功,accountId:{},unitId:{}", advertiserId, unitId);
-
+        try {
+            sendMessageService.sendMessage(userId, text);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 }