Kaynağa Gözat

Merge remote-tracking branch 'origin/master'

zhaoxian 3 yıl önce
ebeveyn
işleme
71dc9629fb

+ 38 - 0
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/CwjsPolicyApprovedNoticeJob.java

@@ -20,4 +20,42 @@ public class CwjsPolicyApprovedNoticeJob {
             XxlJobHelper.log(e.getMessage());
         }
     }
+
+
+    /**
+     * 财务结算中 给运营发送微信通知 每月1号 早上9点
+     * @throws Exception
+     */
+    @XxlJob("sendMessageToOperate")
+    public void sendMessageToOperate() throws Exception {
+        try {
+//            String url = "http://gateway.tjyourong.com.cn/finance/cwjsPolicyInfo/weiXinNotice";
+            String url = "http://api.tjyourong.com.cn/finance/exportReportController/sendMessageToOperate";
+            HttpUtils2.httpGet(url, null, null);
+            XxlJobHelper.log("send CWJS-operate weixin message success");
+        } catch (Exception e) {
+            XxlJobHelper.log(e.getMessage());
+        }
+    }
+
+    /**
+     * demo
+     * @throws Exception
+     */
+    @XxlJob("sendMessageToOperateDemo")
+    public void sendMessageToOperateDemo() throws Exception {
+        try {
+            String url = "http://api.tjyourong.com.cn/finance/exportReportController/sendMessageToOperateDemo";
+            HttpUtils2.httpGet(url, null, null);
+            XxlJobHelper.log("send CWJS-operate weixin message success");
+        } catch (Exception e) {
+            XxlJobHelper.log(e.getMessage());
+        }
+    }
+
+
+
+
+
+
 }

+ 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);
 

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

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!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">
-    <resultMap id="BaseResultMap" type="cn.com.ctop.kuaishou.modules.report.mapper.NewMonitorMapper">
+    <resultMap id="BaseResultMap" type="cn.com.ctop.kuaishou.modules.report.entity.NewMonitorInfo">
         <id  column="id"  property="user_id" />
         <result column="realname" property="user_name"/>
         <result column="leader_id" property="parent_id"/>
@@ -17,33 +17,35 @@
     </select>
 
     <select id="getAllAccountId" resultType="Long">
-        SELECT DISTINCT t.account_id  as 'accountId' from ctop_user_allocation t
+        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}
-     <where>
-         <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')
-             </otherwise>
-         </choose>
-     </where>
+        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
+        <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>
+                    and  t.group_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
+                </otherwise>
+            </choose>
+        </where>
     </select>
 
     <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>
@@ -51,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>
@@ -107,13 +110,13 @@
 
     <select id="getKuaiShouGroupMessage" resultType="com.alibaba.fastjson.JSONObject">
         select account_id as 'accountId',account_name as 'authName',MAX(create_time) as 'maxCreateTime',COUNT(IF(effective ='1', TRUE, NULL))  as 'valid',count(effective) as 'new',operating_name as 'userName','' as 'projectName'
-         from ctop_new_monitor_group  where ( create_time between #{startDate}  and #{endDate})
+        from ctop_new_monitor_group  where ( create_time between #{startDate}  and #{endDate})
         and account_id in
         <foreach item="item" collection="array" separator="," open="(" close=")" index="">
-               #{item}
+            #{item}
         </foreach>
         GROUP BY account_id
-
+        order by account_id desc
     </select>
 
 
@@ -125,7 +128,7 @@
             #{item}
         </foreach>
         GROUP BY account_id
-
+        order by account_id desc
     </select>
 
     <select id="getKuaiShouGroupSum" resultType="com.alibaba.fastjson.JSONObject">
@@ -147,8 +150,17 @@
     </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
-     where  (create_time between #{startDate}  and #{endDate}) and t.account_id in
+        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}
         </foreach>
@@ -160,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}
@@ -176,6 +198,7 @@
                 GROUP BY  DATE_FORMAT(t.create_time,'%Y-%m-%d')
             </otherwise>
         </choose>
+        order by t.create_time asc
     </select>
 
 

+ 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;
     }
 

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

@@ -195,6 +195,7 @@ public class RuleKuaiShouPlanServiceImpl extends ServiceImpl<RuleDatePlanKuaisho
                         }
                     }
                     unit.setCreateTime(new Date());
+                    unit.setStatus(1);
                     batch.add(unit);
                 }
             }
@@ -262,7 +263,7 @@ public class RuleKuaiShouPlanServiceImpl extends ServiceImpl<RuleDatePlanKuaisho
                 target.setIsOpen(isOpen == null ? 0 : isOpen);
 
                 target.setDeepConversionBid(new BigDecimal(unitDetail.getLong("deep_conversion_bid")).divide(new BigDecimal("1000")));
-                target.setDeepConversionType(unitDetail.getInteger("deep_conversion_bid"));
+                target.setDeepConversionType(unitDetail.getInteger("deep_conversion_type"));
                 target.setOcpxActionType(unitDetail.getInteger("ocpx_action_type"));
                 target.setCpaBid(new BigDecimal(unitDetail.getLong("cpa_bid")).divide(new BigDecimal("1000"), 2, RoundingMode.HALF_UP));
                 target.setScheduleTime(unitDetail.getString("schedule_time") == null ? "" : unitDetail.getString("schedule_time"));

+ 1 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/agent/service/AgentManagementService.java

@@ -8,7 +8,7 @@ public interface AgentManagementService {
     public String getToken();
 
     //查询代理商下账户
-    public  JSONObject selectAgentAdvertiser(int pageNum, int pageSize);
+    public  JSONObject selectAgentAdvertiser(int pageNum, int pageSize,String account);
 
 
     //查询账号流水

+ 44 - 35
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/agent/service/impl/AgentManagementServiceImpl.java

@@ -56,6 +56,8 @@ public class AgentManagementServiceImpl implements AgentManagementService {
     @Resource
     CtopAccountTransactionDayMapper ctopAccountTransactionDayMapper;
 
+    private String accountList = "1651537304110087;1640370875427848;73970348172";
+
     /**
      * 同步代理商下账号
      *
@@ -70,43 +72,50 @@ public class AgentManagementServiceImpl implements AgentManagementService {
         List<String> dataList = new ArrayList();
         Result result = new Result();
         try {
-            //分页查询第一页数据
-            JSONObject agentAccountList = selectAgentAdvertiser(1, 2000);
-            JSONObject data = (JSONObject) agentAccountList.get("data");
-            //dataList.addAll((List) data.get("list"));
-            if (data.size() > 0) {
-                JSONObject page_info = (JSONObject) data.get("page_info");
-                int total_page = (int) page_info.get("total_page");
-                //查询其他页数据
-                for (int i = 0; i < total_page; i++) {
-                    JSONObject agenttList = selectAgentAdvertiser(i + 1, 2000);
-                    JSONObject agentData = (JSONObject) agenttList.get("data");
-                    List<Long> list = (List<Long>) agentData.get("list");
-                    list.stream().forEach(str -> {
-                        dataList.add(str.toString());
-                    });
+            if (accountList != null) {
+                String[] split = accountList.split(";");
+                for (String account : split) {
+                    //分页查询第一页数据
+                    JSONObject agentAccountList = selectAgentAdvertiser(1, 2000, account);
+                    JSONObject data = (JSONObject) agentAccountList.get("data");
+                    //dataList.addAll((List) data.get("list"));
+                    if (data.size() > 0) {
+                        JSONObject page_info = (JSONObject) data.get("page_info");
+                        int total_page = (int) page_info.get("total_page");
+                        //查询其他页数据
+                        for (int i = 0; i < total_page; i++) {
+                            JSONObject agenttList = selectAgentAdvertiser(i + 1, 2000, account);
+                            JSONObject agentData = (JSONObject) agenttList.get("data");
+                            List<Long> list = (List<Long>) agentData.get("list");
+                            list.stream().forEach(str -> {
+                                dataList.add(str.toString());
+                            });
+
+                        }
+                        log.info("拉取" + account + "下账户数量:{}", dataList.size());
+                        //查询数据库已存在id
+                        List<String> accountIdList = ctopAgentAccountMapper.getAllAccountId();
+                        if (!accountIdList.isEmpty()) {
+                            //筛选巨量引擎剔除的用户
+                            List<String> removeList = accountIdList.stream().filter(item -> !dataList.contains(item)).collect(toList());
+                            //筛选巨量引擎新增的用户
+                            List<String> addList = dataList.stream().filter(item -> !accountIdList.contains(item)).collect(toList());
+                            //修改剔除的用户状态
+                            if (!removeList.isEmpty()) {
+                                ctopAgentAccountMapper.updateAccountState(removeList, 1);
+                            }
+                            //保存新增的用户
+                            if (!addList.isEmpty()) {
+                                ctopAgentAccountMapper.insertAccountData(addList, ADVERTISER_ID, df.format(new Date()));
+                            }
+                        } else {
+                            ctopAgentAccountMapper.insertAccountData(dataList, ADVERTISER_ID, df.format(new Date()));
+                        }
 
-                }
-                //查询数据库已存在id
-                List<String> accountIdList = ctopAgentAccountMapper.getAllAccountId();
-                if (!accountIdList.isEmpty()) {
-                    //筛选巨量引擎剔除的用户
-                    List<String> removeList = accountIdList.stream().filter(item -> !dataList.contains(item)).collect(toList());
-                    //筛选巨量引擎新增的用户
-                    List<String> addList = dataList.stream().filter(item -> !accountIdList.contains(item)).collect(toList());
-                    //修改剔除的用户状态
-                    if (!removeList.isEmpty()) {
-                        ctopAgentAccountMapper.updateAccountState(removeList, 1);
-                    }
-                    //保存新增的用户
-                    if (!addList.isEmpty()) {
-                        ctopAgentAccountMapper.insertAccountData(addList, ADVERTISER_ID, df.format(new Date()));
                     }
-                } else {
-                    ctopAgentAccountMapper.insertAccountData(dataList, ADVERTISER_ID, df.format(new Date()));
                 }
-
             }
+
             result.setSuccess(true);
             result.setMessage("success");
             return result;
@@ -409,11 +418,11 @@ public class AgentManagementServiceImpl implements AgentManagementService {
      * @create: 2021-07-14
      */
     @Override
-    public JSONObject selectAgentAdvertiser(int pageNum, int pageSize) {
+    public JSONObject selectAgentAdvertiser(int pageNum, int pageSize, String account) {
         // 请求参数
         Map data = new HashMap() {
             {
-                put("advertiser_id", ADVERTISER_ID);
+                put("advertiser_id", account);
                 put("page", pageNum);
                 put("page_size", pageSize);
             }