Browse Source

新上监控BUG解决

zhouzeyu@c-top.com.cn 4 years ago
parent
commit
f44f70dd7f

+ 5 - 3
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/NewMonitorMapper.java

@@ -11,11 +11,13 @@ import java.util.Map;
 @Mapper
 public interface NewMonitorMapper {
 
-    List<Map> getKuaiShouGroup(@Param("date")String date);
+    List<Long> getAllAccountId();
 
-    List<Map> getKuaiShouCampaign(@Param("date")String date);
+    List<Map> getKuaiShouGroup(@Param("date")String date,@Param("accountId")String accountId);
 
-    List<Map> getTouTiaoCampaign(@Param("date")String date);
+    List<Map> getKuaiShouCampaign(@Param("date")String date,@Param("accountId")String accountId);
+
+    List<Map> getTouTiaoCampaign(@Param("date")String date,@Param("accountId")String accountId);
 
     String getGroupCharge(@Param("unitId")String unitId,@Param("afterDate")String afterDate);
 

+ 6 - 3
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/NewMonitorMapper.xml

@@ -2,9 +2,12 @@
 <!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.report.mapper.NewMonitorMapper">
 
+    <select id="getAllAccountId" resultType="Long">
+        SELECT DISTINCT t.account_id  as 'accountId' from ctop_user_allocation t
+    </select>
     <select id="getKuaiShouGroup" resultType="Map">
     SELECT t1.account_id as 'accountId',t1.auth_name as 'accountName',t1.user_name as 'userName',t.unit_id as 'unitId',t.group_create_time as 'groupCreatTime',DATE_FORMAT(DATE_ADD(t.group_create_time,INTERVAL 7 DAY),'%Y-%m-%d') as 'afterTime'
-     from ctop_user_allocation t1 LEFT JOIN  ctop_kuaishou_group t on t1.account_id=t.account_id
+     from ctop_user_allocation t1 LEFT JOIN  ctop_kuaishou_group t on t1.account_id=t.account_id and t.account_id=#{accountId}
      <where>
          <choose>
              <when test="date!= null and date!=''">
@@ -19,7 +22,7 @@
 
     <select id="getKuaiShouCampaign" resultType="Map">
         SELECT t1.account_id as 'accountId',t1.auth_name as 'accountName',t1.user_name as 'userName',t.campaign_id as 'campaignId',t.put_create_time as 'campaignCreatTime',DATE_FORMAT(DATE_ADD(t.put_create_time,INTERVAL 7 DAY),'%Y-%m-%d') as 'afterTime'
-        from ctop_user_allocation t1 LEFT JOIN  ctop_kuaishou_campaign t on t1.account_id=t.account_id
+        from ctop_user_allocation t1 LEFT JOIN  ctop_kuaishou_campaign t on t1.account_id=t.account_id and t.account_id=#{accountId}
         <where>
             <choose>
                 <when test="date != null and date !=''">
@@ -34,7 +37,7 @@
 
     <select id="getTouTiaoCampaign" resultType="Map">
         SELECT t1.account_id as 'accountId',t1.auth_name as 'accountName',t1.user_name as 'userName',t.id as 'campaignId',t.ad_create_time as 'campaignCreatTime',DATE_FORMAT(DATE_ADD(t.ad_create_time,INTERVAL 7 DAY),'%Y-%m-%d') as 'afterTime'
-        from ctop_user_allocation t1 LEFT JOIN  ctop_bytedance_advertise_plan t on t1.account_id=t.account_id
+        from ctop_user_allocation t1 LEFT JOIN  ctop_bytedance_advertise_plan t on t1.account_id=t.account_id and t.account_id=#{accountId}
         <where>
             <choose>
                 <when test="date != null and date !=''">

+ 145 - 134
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/NewMonitorServiceImpl.java

@@ -35,134 +35,142 @@ public class NewMonitorServiceImpl implements NewMonitorService {
         List<Map> kuaiShouCampaign = new ArrayList<>();
         List<Map> TouTiaoCampaign = new ArrayList<>();
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-        /*--------------------快手广告组-----------------------*/
-        if (type.equals("0")) {
-            //查询创建不满7天的快手组信息
-            kuaiShouGroup = newMonitorMapper.getKuaiShouGroup(sdf.format(new Date()));
-        } else {
-            //查询全量快手组信息
-            kuaiShouGroup = newMonitorMapper.getKuaiShouGroup(null);
-        }
-        //处理快手组数据
-        if (!kuaiShouGroup.isEmpty()) {
-            kuaiShouGroup.stream().forEach(obj -> {
-                if (obj != null) {
-                    String unitId = obj.get("unitId") == null ? null : String.valueOf(obj.get("unitId"));
-                    String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
-                    String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
-                    String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
-                    String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
-                    String groupCreatTime = obj.get("groupCreatTime") == null ? null : (String) obj.get("groupCreatTime");
-                    if (unitId != null && afterTime != null) {
-                        String groupCharge = newMonitorMapper.getGroupCharge(unitId, afterTime);
-                        //大于500为有效广告组
-                        String effective = "0";
-                        if (groupCharge != null && Long.parseLong(groupCharge) > 500) {
-                            //有效
-                            effective = "1";
-                        }
-                        String effectiveResult = newMonitorMapper.getMonitorGroupByUnitId(unitId);
-                        //判断是否存在
-                        if (effectiveResult != null) {
-                            if (!effectiveResult.equals(effective)) {
-                                //存在更新
-                                newMonitorMapper.updateMonitorGroupByUnitId(unitId, effective);
+        List<Long> allAccountId = newMonitorMapper.getAllAccountId();
+        if (!allAccountId.isEmpty()) {
+            for (Long accId : allAccountId) {
+                if (accId != null) {
+                    /*--------------------快手广告组-----------------------*/
+                    if (type.equals("0")) {
+                        //查询创建不满7天的快手组信息
+                        kuaiShouGroup = newMonitorMapper.getKuaiShouGroup(sdf.format(new Date()), String.valueOf(accId));
+                    } else {
+                        //查询全量快手组信息
+                        kuaiShouGroup = newMonitorMapper.getKuaiShouGroup(null, String.valueOf(accId));
+                    }
+                    //处理快手组数据
+                    if (!kuaiShouGroup.isEmpty()) {
+                        kuaiShouGroup.stream().forEach(obj -> {
+                            if (obj != null) {
+                                String unitId = obj.get("unitId") == null ? null : String.valueOf(obj.get("unitId"));
+                                String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
+                                String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
+                                String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
+                                String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
+                                String groupCreatTime = obj.get("groupCreatTime") == null ? null : (String) obj.get("groupCreatTime");
+                                if (unitId != null && afterTime != null) {
+                                    String groupCharge = newMonitorMapper.getGroupCharge(unitId, afterTime);
+                                    //大于500为有效广告组
+                                    String effective = "0";
+                                    if (groupCharge != null && Long.parseLong(groupCharge) > 500) {
+                                        //有效
+                                        effective = "1";
+                                    }
+                                    String effectiveResult = newMonitorMapper.getMonitorGroupByUnitId(unitId);
+                                    //判断是否存在
+                                    if (effectiveResult != null) {
+                                        if (!effectiveResult.equals(effective)) {
+                                            //存在更新
+                                            newMonitorMapper.updateMonitorGroupByUnitId(unitId, effective);
+                                        }
+
+                                    } else {
+                                        //不存在插入
+                                        newMonitorMapper.saveMonitorGroup(accountId, accountName, userName, unitId, groupCreatTime, "1", effective);
+                                    }
+                                }
                             }
-
-                        } else {
-                            //不存在插入
-                            newMonitorMapper.saveMonitorGroup(accountId, accountName, userName, unitId, groupCreatTime, "1", effective);
-                        }
+                        });
                     }
-                }
-            });
-        }
 
 
-        /*---------------快手广告计划------------------*/
-        if (type.equals("0")) {
-            //查询创建不满7天的快手广告计划
-            kuaiShouCampaign = newMonitorMapper.getKuaiShouCampaign(sdf.format(new Date()));
-        } else {
-            //查询全量快手广告计划
-            kuaiShouCampaign = newMonitorMapper.getKuaiShouCampaign(null);
-        }
-        //处理快手广告计划数据
-        if (!kuaiShouCampaign.isEmpty()) {
-            kuaiShouCampaign.stream().forEach(obj -> {
-                if (obj != null) {
-                    String campaignId = obj.get("campaignId") == null ? null : String.valueOf(obj.get("campaignId"));
-                    String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
-                    String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
-                    String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
-                    String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
-                    String campaignCreatTime = obj.get("campaignCreatTime") == null ? null : (String) obj.get("campaignCreatTime");
-                    if (campaignId != null && afterTime != null) {
-                        String campaignCharge = newMonitorMapper.getCampaignCharge(campaignId, afterTime);
-                        //大于500为有效广告计划
-                        String effective = "0";
-                        if (campaignCharge != null && Long.parseLong(campaignCharge) > 500) {
-                            //有效
-                            effective = "1";
-                        }
-                        String effectiveResult = newMonitorMapper.getMonitorPlanByCampaignId(campaignId);
-                        //判断是否存在
-                        if (effectiveResult != null) {
-                            if (!effectiveResult.equals(effective)) {
-                                //存在更新
-                                newMonitorMapper.updateMonitorPlanByCampaignId(campaignId, effective);
+                    /*---------------快手广告计划------------------*/
+                    if (type.equals("0")) {
+                        //查询创建不满7天的快手广告计划
+                        kuaiShouCampaign = newMonitorMapper.getKuaiShouCampaign(sdf.format(new Date()), String.valueOf(accId));
+                    } else {
+                        //查询全量快手广告计划
+                        kuaiShouCampaign = newMonitorMapper.getKuaiShouCampaign(null, String.valueOf(accId));
+                    }
+                    //处理快手广告计划数据
+                    if (!kuaiShouCampaign.isEmpty()) {
+                        kuaiShouCampaign.stream().forEach(obj -> {
+                            if (obj != null) {
+                                String campaignId = obj.get("campaignId") == null ? null : String.valueOf(obj.get("campaignId"));
+                                String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
+                                String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
+                                String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
+                                String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
+                                String campaignCreatTime = obj.get("campaignCreatTime") == null ? null : (String) obj.get("campaignCreatTime");
+                                if (campaignId != null && afterTime != null) {
+                                    String campaignCharge = newMonitorMapper.getCampaignCharge(campaignId, afterTime);
+                                    //大于500为有效广告计划
+                                    String effective = "0";
+                                    if (campaignCharge != null && Long.parseLong(campaignCharge) > 500) {
+                                        //有效
+                                        effective = "1";
+                                    }
+                                    String effectiveResult = newMonitorMapper.getMonitorPlanByCampaignId(campaignId);
+                                    //判断是否存在
+                                    if (effectiveResult != null) {
+                                        if (!effectiveResult.equals(effective)) {
+                                            //存在更新
+                                            newMonitorMapper.updateMonitorPlanByCampaignId(campaignId, effective);
+                                        }
+                                    } else {
+                                        //不存在插入
+                                        newMonitorMapper.saveMonitorCampaign(accountId, accountName, userName, campaignId, campaignCreatTime, "1", effective);
+                                    }
+                                }
                             }
-                        } else {
-                            //不存在插入
-                            newMonitorMapper.saveMonitorCampaign(accountId, accountName, userName, campaignId, campaignCreatTime, "1", effective);
-                        }
+                        });
                     }
-                }
-            });
-        }
 
-        /*---------------头条广告计划------------------*/
-        if (type.equals("0")) {
-            //查询创建不满7天的头条广告计划
-            TouTiaoCampaign = newMonitorMapper.getTouTiaoCampaign(sdf.format(new Date()));
-        } else {
-            //查询全量头条广告计划
-            TouTiaoCampaign = newMonitorMapper.getTouTiaoCampaign(null);
-        }
-        //处理快手广告计划数据
-        if (!TouTiaoCampaign.isEmpty()) {
-            TouTiaoCampaign.stream().forEach(obj -> {
-                if (obj != null) {
-                    String campaignId = obj.get("campaignId") == null ? null : String.valueOf(obj.get("campaignId"));
-                    String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
-                    String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
-                    String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
-                    String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
-                    String campaignCreatTime = obj.get("campaignCreatTime") == null ? null : (String) obj.get("campaignCreatTime");
-                    if (campaignId != null && afterTime != null) {
-                        String campaignCharge = newMonitorMapper.getCampaignChargeTouTiao(campaignId, afterTime);
-                        //大于500为有效广告计划
-                        String effective = "0";
-                        if (campaignCharge != null && Long.parseLong(campaignCharge) > 500) {
-                            //有效
-                            effective = "1";
-                        }
-                        String effectiveResult = newMonitorMapper.getMonitorPlanByCampaignId(campaignId);
-                        //判断是否存在
-                        if (effectiveResult != null) {
-                            if (!effectiveResult.equals(effective)) {
-                                //存在更新
-                                newMonitorMapper.updateMonitorPlanByCampaignId(campaignId, effective);
+                    /*---------------头条广告计划------------------*/
+                    if (type.equals("0")) {
+                        //查询创建不满7天的头条广告计划
+                        TouTiaoCampaign = newMonitorMapper.getTouTiaoCampaign(sdf.format(new Date()), String.valueOf(accId));
+                    } else {
+                        //查询全量头条广告计划
+                        TouTiaoCampaign = newMonitorMapper.getTouTiaoCampaign(null, String.valueOf(accId));
+                    }
+                    //处理快手广告计划数据
+                    if (!TouTiaoCampaign.isEmpty()) {
+                        TouTiaoCampaign.stream().forEach(obj -> {
+                            if (obj != null) {
+                                String campaignId = obj.get("campaignId") == null ? null : String.valueOf(obj.get("campaignId"));
+                                String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
+                                String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
+                                String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
+                                String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
+                                String campaignCreatTime = obj.get("campaignCreatTime") == null ? null : (String) obj.get("campaignCreatTime");
+                                if (campaignId != null && afterTime != null) {
+                                    String campaignCharge = newMonitorMapper.getCampaignChargeTouTiao(campaignId, afterTime);
+                                    //大于500为有效广告计划
+                                    String effective = "0";
+                                    if (campaignCharge != null && Long.parseLong(campaignCharge) > 500) {
+                                        //有效
+                                        effective = "1";
+                                    }
+                                    String effectiveResult = newMonitorMapper.getMonitorPlanByCampaignId(campaignId);
+                                    //判断是否存在
+                                    if (effectiveResult != null) {
+                                        if (!effectiveResult.equals(effective)) {
+                                            //存在更新
+                                            newMonitorMapper.updateMonitorPlanByCampaignId(campaignId, effective);
+                                        }
+                                    } else {
+                                        //不存在插入
+                                        newMonitorMapper.saveMonitorCampaign(accountId, accountName, userName, campaignId, campaignCreatTime, "0", effective);
+                                    }
+                                }
                             }
-                        } else {
-                            //不存在插入
-                            newMonitorMapper.saveMonitorCampaign(accountId, accountName, userName, campaignId, campaignCreatTime, "0", effective);
-                        }
+                        });
                     }
                 }
-            });
+            }
         }
 
+
         return result;
     }
 
@@ -175,8 +183,9 @@ public class NewMonitorServiceImpl implements NewMonitorService {
      */
     @Override
     public List<JSONObject> getKuaiShouGroupMessage(JSONArray array, String startDate, String endDate, String target) {
-        return  newMonitorMapper.getKuaiShouGroupMessage(array,startDate,endDate);
+        return newMonitorMapper.getKuaiShouGroupMessage(array, startDate, endDate);
     }
+
     /**
      * 查询快手组新上和有效数量
      *
@@ -185,8 +194,9 @@ public class NewMonitorServiceImpl implements NewMonitorService {
      */
     @Override
     public JSONObject getKuaiShouGroupSum(JSONArray array, String startDate, String endDate) {
-        return newMonitorMapper.getKuaiShouGroupSum(array,startDate,endDate);
+        return newMonitorMapper.getKuaiShouGroupSum(array, startDate, endDate);
     }
+
     /**
      * 查询快手组时间轴数据
      *
@@ -195,15 +205,15 @@ public class NewMonitorServiceImpl implements NewMonitorService {
      */
     @Override
     public List<JSONObject> getKuaiShouGroupMessageGroup(JSONArray array, String startDate, String endDate) {
-        String group="0";
-        List<JSONObject> kuaiShouGroupMessageGroup=new ArrayList<>();
+        String group = "0";
+        List<JSONObject> kuaiShouGroupMessageGroup = new ArrayList<>();
         try {
-            if(DateUtils.isMoreSixMonth(startDate,endDate)){
-                group="1";
+            if (DateUtils.isMoreSixMonth(startDate, endDate)) {
+                group = "1";
             }
-            kuaiShouGroupMessageGroup= newMonitorMapper.getKuaiShouGroupMessageGroup(array, startDate, endDate, group);
-        }catch (Exception e){
-            log.info("查询数据错误:{}",e.toString());
+            kuaiShouGroupMessageGroup = newMonitorMapper.getKuaiShouGroupMessageGroup(array, startDate, endDate, group);
+        } catch (Exception e) {
+            log.info("查询数据错误:{}", e.toString());
         }
 
         return kuaiShouGroupMessageGroup;
@@ -211,8 +221,9 @@ public class NewMonitorServiceImpl implements NewMonitorService {
 
     @Override
     public List<JSONObject> getPlanMessage(JSONArray array, String startDate, String endDate, String target, String project) {
-        return newMonitorMapper.getPlanMessage(array,startDate,endDate,project);
+        return newMonitorMapper.getPlanMessage(array, startDate, endDate, project);
     }
+
     /**
      * 查询快手广告计划 新上和有效数量
      *
@@ -221,20 +232,20 @@ public class NewMonitorServiceImpl implements NewMonitorService {
      */
     @Override
     public JSONObject getPlanSum(JSONArray array, String startDate, String endDate, String project) {
-        return newMonitorMapper.getPlanSum(array,startDate,endDate,project);
+        return newMonitorMapper.getPlanSum(array, startDate, endDate, project);
     }
 
     @Override
     public List<JSONObject> getPlanMessageGroup(JSONArray array, String startDate, String endDate, String project) {
-        String group="0";
-        List<JSONObject> planGroupMessageGroup=new ArrayList<>();
+        String group = "0";
+        List<JSONObject> planGroupMessageGroup = new ArrayList<>();
         try {
-            if(DateUtils.isMoreSixMonth(startDate,endDate)){
-                group="1";
+            if (DateUtils.isMoreSixMonth(startDate, endDate)) {
+                group = "1";
             }
-            planGroupMessageGroup= newMonitorMapper.getPlanMessageGroup(array, startDate, endDate, group,project);
-        }catch (Exception e){
-            log.info("查询数据错误:{}",e.toString());
+            planGroupMessageGroup = newMonitorMapper.getPlanMessageGroup(array, startDate, endDate, group, project);
+        } catch (Exception e) {
+            log.info("查询数据错误:{}", e.toString());
         }
 
         return planGroupMessageGroup;