Explorar o código

新上监控提交

zhouzeyu@c-top.com.cn %!s(int64=3) %!d(string=hai) anos
pai
achega
f4b367e70e

+ 13 - 2
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/NewMonitorJob.java

@@ -1,12 +1,15 @@
 package cn.com.ctop.job.kuaishou.handler;
 
 import cn.com.ctop.kuaishou.modules.clean.service.KuaiShouAccountCleanService;
+import cn.com.ctop.kuaishou.modules.report.mapper.NewMonitorMapper;
 import cn.com.ctop.kuaishou.modules.report.service.NewMonitorService;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 @Component
 @Slf4j
@@ -14,7 +17,8 @@ public class NewMonitorJob {
 
     @Resource
     NewMonitorService newMonitorService;
-
+    @Resource
+    NewMonitorMapper newMonitorMapper;
     /**
      * 账户清理
      *
@@ -26,7 +30,14 @@ public class NewMonitorJob {
     @XxlJob("synchronousMonitor")
     public void execute() throws Exception {
         try {
-            newMonitorService.synchronousMonitor("0");
+            List<Long> kuaiShouallAccountId = newMonitorMapper.getAllAccountId("2");
+            List<Long> touTiaoAccountId = newMonitorMapper.getAllAccountId("1");
+            for (Long aLong : kuaiShouallAccountId) {
+                newMonitorService.synchronousKuaiShouMonitor("0", aLong);
+            }
+            for (Long aLong : touTiaoAccountId) {
+                newMonitorService.synchronousKuaiShouMonitor("0", aLong);
+            }
         } catch (Exception e) {
             log.info("清理完成完成");
         }

+ 52 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/config/ThreadExecutorConfig.java

@@ -0,0 +1,52 @@
+package cn.com.ctop.kuaishou.modules.report.config;
+
+import com.itextpdf.text.log.Logger;
+import com.itextpdf.text.log.LoggerFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadPoolExecutor;
+
+/**
+ * @description: 线程池配置
+ * @author: zzy
+ * @create: 2021-09-02
+ * EnableAsync : 开启异步调用
+ **/
+@Configuration
+@EnableAsync
+public class ThreadExecutorConfig {
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+    /**
+     * 核心线程数
+     */
+    private int corePoolSize = 10;
+    /**
+     * 最大线程数
+     */
+    private int maxPoolSize = 25;
+    /**
+     * 队列数
+     */
+    private int queueCapacity = 15;
+
+    @Bean
+    public ExecutorService calcThreadExecutor() {
+        logger.info("start build threadPoolTaskExecutor");
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(corePoolSize);
+        executor.setMaxPoolSize(maxPoolSize);
+        executor.setQueueCapacity(queueCapacity);
+        executor.setThreadNamePrefix("calc-thread");
+
+        // rejection-policy:当pool已经达到max size的时候,如何处理新任务
+        // CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        // 执行初始化
+        executor.initialize();
+        return executor.getThreadPoolExecutor();
+    }
+}

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/NewMonitorMapper.java

@@ -13,7 +13,7 @@ import java.util.Map;
 @Mapper
 public interface NewMonitorMapper {
 
-    List<Long> getAllAccountId();
+    List<Long> getAllAccountId(@Param("type") String type);
 
     List<Map> getKuaiShouGroup(@Param("date") String date, @Param("accountId") String accountId);
 

+ 37 - 12
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/NewMonitorMapper.xml

@@ -9,6 +9,7 @@
                     select="cn.com.ctop.kuaishou.modules.report.mapper.NewMonitorMapper.getOperator" column="id">
         </collection>
     </resultMap>
+
     <select id="getOperator" resultMap="BaseResultMap"  parameterType="String">
         SELECT id,realname,leader_id
         FROM sys_user
@@ -16,18 +17,19 @@
     </select>
 
     <select id="getAllAccountId" resultType="Long">
-        SELECT DISTINCT t.account_id  as 'accountId' from ctop_user_allocation t where  account_status=0
+        SELECT DISTINCT t.account_id  as 'accountId' from ctop_user_allocation t where  account_status=0 and media_id=#{type}
     </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 and t.account_id=#{accountId}
+        from ctop_user_allocation t1 LEFT JOIN  ctop_kuaishou_group t on t1.account_id=t.account_id
         <where>
+            and t.account_id=#{accountId}
             <choose>
                 <when test="date!= null and date!=''">
                     and  t.group_create_time &gt;= DATE_SUB(#{date},INTERVAL 7 DAY)
                 </when>
                 <otherwise>
-                    t.group_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
+                    and  t.group_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
                 </otherwise>
             </choose>
         </where>
@@ -35,14 +37,15 @@
 
     <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 and t.account_id=#{accountId}
+        from ctop_user_allocation t1 LEFT JOIN  ctop_kuaishou_campaign t on t1.account_id=t.account_id
         <where>
+            and t.account_id=#{accountId}
             <choose>
                 <when test="date != null and date !=''">
                     and  t.put_create_time &gt;= DATE_SUB(#{date},INTERVAL 7 DAY)
                 </when>
                 <otherwise>
-                    t.put_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
+                    and  t.put_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
                 </otherwise>
             </choose>
         </where>
@@ -50,30 +53,31 @@
 
     <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 and t.account_id=#{accountId}
+        from ctop_user_allocation t1 LEFT JOIN  ctop_bytedance_advertise_plan t on t1.account_id=t.account_id
         <where>
+            and t.account_id=#{accountId}
             <choose>
                 <when test="date != null and date !=''">
                     and  t.ad_create_time &gt;= DATE_SUB(#{date},INTERVAL 7 DAY)
                 </when>
                 <otherwise>
-                    t.ad_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
+                    and  t.ad_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
                 </otherwise>
             </choose>
         </where>
     </select>
 
-    <select id="getGroupCharge" resultType="BigDecimal">
+    <select id="getGroupCharge" resultType="java.math.BigDecimal">
 
         select sum(charge) from ctop_kuaishou_report_daily_group t where t.stat_date &lt; #{afterDate} and t.unit_id=#{unitId}
     </select>
 
-    <select id="getCampaignCharge" resultType="BigDecimal">
+    <select id="getCampaignCharge" resultType="java.math.BigDecimal">
 
         select sum(charge) from ctop_kuaishou_report_daily_campaign t where t.stat_date &lt; #{afterDate} and t.campaign_id=#{campaignId}
     </select>
 
-    <select id="getCampaignChargeTouTiao" resultType="BigDecimal">
+    <select id="getCampaignChargeTouTiao" resultType="java.math.BigDecimal">
 
         select sum(cost) from ctop_bytedance_report_plan_daily t where t.stat_datetime &lt; #{afterDate} and t.ad_id=#{campaignId}
     </select>
@@ -146,7 +150,16 @@
     </select>
 
     <select id="getKuaiShouGroupMessageGroup" resultType="com.alibaba.fastjson.JSONObject" >
-        SELECT DATE_FORMAT(t.create_time,'%Y-%m-%d') as 'statDate',COUNT(t.effective) as 'new',COUNT(IF(t.effective ='1', TRUE, NULL))  as 'valid' from ctop_new_monitor_group t
+        SELECT
+        <choose>
+            <when test='group=="1"'>
+                DATE_FORMAT(t.create_time,'%Y-%m') as 'statDate',
+            </when>
+            <otherwise>
+                DATE_FORMAT(t.create_time,'%Y-%m-%d') as 'statDate',
+            </otherwise>
+        </choose>
+        COUNT(t.effective) as 'new',COUNT(IF(t.effective ='1', TRUE, NULL))  as 'valid' from ctop_new_monitor_group t
         where  (create_time between #{startDate}  and #{endDate}) and t.account_id in
         <foreach item="item" collection="array" separator="," open="(" close=")" index="">
             #{item}
@@ -159,10 +172,20 @@
                 GROUP BY  DATE_FORMAT(t.create_time,'%Y-%m-%d')
             </otherwise>
         </choose>
+        order by t.create_time asc
     </select>
 
     <select id="getPlanMessageGroup" resultType="com.alibaba.fastjson.JSONObject" >
-        SELECT DATE_FORMAT(t.create_time,'%Y-%m-%d') as 'statDate',COUNT(t.effective) as 'new',COUNT(IF(t.effective ='1', TRUE, NULL))  as 'valid' from ctop_new_monitor_campaign t
+        SELECT
+        <choose>
+            <when test='group=="1"'>
+                DATE_FORMAT(t.create_time,'%Y-%m') as 'statDate',
+            </when>
+            <otherwise>
+                DATE_FORMAT(t.create_time,'%Y-%m-%d') as 'statDate',
+            </otherwise>
+        </choose>
+        COUNT(t.effective) as 'new',COUNT(IF(t.effective ='1', TRUE, NULL))  as 'valid' from ctop_new_monitor_campaign t
         where project_type=#{project} and  (create_time between #{startDate}  and #{endDate}) and t.account_id in
         <foreach item="item" collection="array" separator="," open="(" close=")" index="">
             #{item}
@@ -175,7 +198,9 @@
                 GROUP BY  DATE_FORMAT(t.create_time,'%Y-%m-%d')
             </otherwise>
         </choose>
+        order by t.create_time asc
     </select>
 
 
+
 </mapper>

+ 3 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/NewMonitorService.java

@@ -7,7 +7,9 @@ import org.jeecg.common.api.vo.Result;
 import java.util.List;
 
 public interface NewMonitorService {
-    public Result synchronousMonitor(String type);
+    public Result synchronousKuaiShouMonitor(String type, Long accId);
+
+    public Result synchronousTouTiaoMonitor(String type, Long accId);
 
     List<JSONObject> getKuaiShouGroupMessage(JSONArray array, String startDate, String endDate, String target);
 

+ 140 - 123
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/NewMonitorServiceImpl.java

@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.util.DateUtils;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -26,153 +27,169 @@ public class NewMonitorServiceImpl implements NewMonitorService {
     NewMonitorMapper newMonitorMapper;
 
     /**
-     * 同步新上监控数据
+     * 同步快手新上监控数据
      *
      * @param
      * @return
      */
-    public Result synchronousMonitor(String type) {
+    @Async("calcThreadExecutor")
+    public Result synchronousKuaiShouMonitor(String type, Long accId) {
+        log.info("同步快手新上数据:{}", accId);
         Result result = new Result();
         List<Map> kuaiShouGroup = new ArrayList<>();
         List<Map> kuaiShouCampaign = new ArrayList<>();
         List<Map> TouTiaoCampaign = new ArrayList<>();
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-        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) {
-                                    BigDecimal groupCharge = newMonitorMapper.getGroupCharge(unitId, afterTime);
-                                    //大于500为有效广告组
-                                    String effective = "0";
-                                    if (groupCharge != null && groupCharge.compareTo(new BigDecimal(500)) == 1) {
-                                        //有效
-                                        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);
-                                    }
+        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) {
+                            BigDecimal groupCharge = newMonitorMapper.getGroupCharge(unitId, afterTime);
+                            //大于500为有效广告组
+                            String effective = "0";
+                            if (groupCharge != null && groupCharge.compareTo(new BigDecimal(500)) == 1) {
+                                //有效
+                                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);
                             }
-                        });
+                        }
                     }
+                });
+            }
 
 
-                    /*---------------快手广告计划------------------*/
-                    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) {
-                                    BigDecimal campaignCharge = newMonitorMapper.getCampaignCharge(campaignId, afterTime);
-                                    //大于500为有效广告计划
-                                    String effective = "0";
-                                    if (campaignCharge != null && campaignCharge.compareTo(new BigDecimal(500)) == 1) {
-                                        //有效
-                                        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);
-                                    }
+            /*---------------快手广告计划------------------*/
+            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) {
+                            BigDecimal campaignCharge = newMonitorMapper.getCampaignCharge(campaignId, afterTime);
+                            //大于500为有效广告计划
+                            String effective = "0";
+                            if (campaignCharge != null && campaignCharge.compareTo(new BigDecimal(500)) == 1) {
+                                //有效
+                                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);
                             }
-                        });
+                        }
                     }
+                });
+            }
+        }
 
-                    /*---------------头条广告计划------------------*/
-                    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) {
-                                    BigDecimal campaignCharge = newMonitorMapper.getCampaignChargeTouTiao(campaignId, afterTime);
-                                    //大于500为有效广告计划
-                                    String effective = "0";
-                                    if (campaignCharge != null && campaignCharge.compareTo(new BigDecimal(500)) == 1) {
-                                        //有效
-                                        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);
-                                    }
+
+        return result;
+    }
+
+
+    /**
+     * 同步头条新上监控数据
+     *
+     * @param
+     * @return
+     */
+    public Result synchronousTouTiaoMonitor(String type, Long accId) {
+        log.info("同步头条新上数据:{}", accId);
+        Result result = new Result();
+        List<Map> kuaiShouGroup = new ArrayList<>();
+        List<Map> kuaiShouCampaign = new ArrayList<>();
+        List<Map> TouTiaoCampaign = new ArrayList<>();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        if (accId != null) {
+            /*---------------头条广告计划------------------*/
+            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) {
+                            BigDecimal campaignCharge = newMonitorMapper.getCampaignChargeTouTiao(campaignId, afterTime);
+                            //大于500为有效广告计划
+                            String effective = "0";
+                            if (campaignCharge != null && campaignCharge.compareTo(new BigDecimal(500)) == 1) {
+                                //有效
+                                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);
                             }
-                        });
+                        }
                     }
-                }
+                });
             }
         }
 
-
         return result;
     }