yumeng пре 4 недеља
родитељ
комит
23b6f39dfc

+ 5 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java

@@ -62,4 +62,9 @@ public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
     List<Long> queryAutomaticAccounts(@Param("projectId") Long projectId);
 
     List<Long> getIdList();
+
+    int closeExpiredByteDanceAccounts(@Param("createTimeLimit") String createTimeLimit,
+                                      @Param("statDatetimeLimit") Integer statDatetimeLimit);
+
+    int closeExpiredKuaiShouAccounts(@Param("createTimeLimit") String createTimeLimit, @Param("statDatetimeLimit") Integer statDatetimeLimit);
 }

+ 41 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml

@@ -244,4 +244,45 @@
 
     </select>
 
+    <update id="closeExpiredByteDanceAccounts">
+        update `jeecg-boot`.ctop_user_allocation
+        set account_status = 1
+        where account_id in (select t.accountId
+                             from (select cast(t1.account_id as char) as accountId,
+                                          t2.cost                     as cost
+                                   from (select account_id, auth_name, user_name
+                                         from `jeecg-boot`.ctop_user_allocation
+                                         where media_id in (1, 3)
+                                           and account_status = 0
+                                           and create_time &lt;= #{createTimeLimit}) t1
+                                            left join (select account_id, sum(cost) as cost
+                                                       from application.bytedance_advertiser_report_daily_dw
+                                                       where bytedance_advertiser_report_daily_dw.stat_datetime &gt;=
+                                                             #{statDatetimeLimit}
+                                                       group by account_id) t2 on t1.account_id = t2.account_id) t
+                             where t.cost is null
+                                or t.cost = 0)
+          and media_id in (1, 3)
+    </update>
+    <update id="closeExpiredKuaiShouAccounts">
+        update `jeecg-boot`.ctop_user_allocation
+        set account_status = 1
+        where account_id in (select t.accountId
+                             from (select cast(t1.account_id as char) as accountId,
+                                          t2.cost                     as cost
+                                   from (select account_id, auth_name, user_name
+                                         from `jeecg-boot`.ctop_user_allocation
+                                         where media_id in (2, 4)
+                                           and account_status = 0
+                                           and create_time &lt;= #{createTimeLimit}) t1
+                                            left join (select account_id, sum(charge) as cost
+                                                       from application.kuaishou_account_report_daily_dw
+                                                       where kuaishou_account_report_daily_dw.stat_date &gt;= #{statDatetimeLimit}
+                                                       group by account_id) t2 on t1.account_id = t2.account_id) t
+                             where t.cost is null
+                                or t.cost = 0)
+          and media_id in (2, 4)
+
+    </update>
+
 </mapper>

+ 4 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java

@@ -69,4 +69,8 @@ public interface IUserAllocationService extends IService<UserAllocation> {
     List<Long> queryAutomaticAccounts(Long projectId);
 
     List<Long> getIdList();
+
+    int closeExpiredByteDanceAccounts(String createTimeLimit, Integer statDatetimeLimit);
+
+    int closeExpiredKuaiShouAccounts(String createTimeLimit, Integer statDatetimeLimit);
 }

+ 10 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java

@@ -225,4 +225,14 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
     public List<Long> getIdList() {
         return userAllocationMapper.getIdList();
     }
+
+    @Override
+    public int closeExpiredByteDanceAccounts(String createTimeLimit, Integer statDatetimeLimit) {
+        return userAllocationMapper.closeExpiredByteDanceAccounts(createTimeLimit, statDatetimeLimit);
+    }
+
+    @Override
+    public int closeExpiredKuaiShouAccounts(String createTimeLimit, Integer statDatetimeLimit) {
+        return userAllocationMapper.closeExpiredKuaiShouAccounts(createTimeLimit, statDatetimeLimit);
+    }
 }

+ 37 - 6
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/ByteDanceRefreshTokenJob.java

@@ -5,12 +5,16 @@ import cn.com.ctop.common.module.service.IRefreshTokenService;
 import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.HttpUtils;
 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 java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.HashMap;
 import java.util.List;
 
+@Slf4j
 @Component
 public class ByteDanceRefreshTokenJob {
 
@@ -54,15 +58,42 @@ public class ByteDanceRefreshTokenJob {
         }
     }
 
+    /**
+     * 定时关停头条账户
+     */
+    @XxlJob("closeExpiredByteDanceAccountJob")
+    public void closeExpiredByteDanceAccountJob() {
+        LocalDateTime now = LocalDateTime.now();
+        String createTimeLimit = now.minusDays(3).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        int statDatetimeLimit = Integer.parseInt(now.minusDays(7).format(DateTimeFormatter.ofPattern("yyyyMMdd")));
+        int i = userAllocationService.closeExpiredByteDanceAccounts(createTimeLimit, statDatetimeLimit);
+        log.info("关停头条账户数:{}",i);
+    }
+
+
 
     /**
-     * 刷新token  千川
-     * 待上线
+     * 定时关停头条账户
      */
-   /* @XxlJob("qianChuanRefreshTokenJob")
-    public void qianChuanRefresh() throws Exception {
-        refreshTokenService.qianChuanRefresh(null);
-    }*/
+    @XxlJob("closeExpiredKuaiShouAccountJob")
+    public void closeExpiredKuaiShouAccountJob() {
+        LocalDateTime now = LocalDateTime.now();
+        String createTimeLimit = now.minusDays(7).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        int statDatetimeLimit = Integer.parseInt(now.minusDays(15).format(DateTimeFormatter.ofPattern("yyyyMMdd")));
+        int i = userAllocationService.closeExpiredKuaiShouAccounts(createTimeLimit, statDatetimeLimit);
+        log.info("关停快手账户数:{}",i);
+    }
+
+
+    public static void main(String[] args) {
+        LocalDateTime now = LocalDateTime.now();
+        String createTimeLimit = now.minusDays(7).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        int statDatetimeLimit = Integer.parseInt(now.minusDays(15).format(DateTimeFormatter.ofPattern("yyyyMMdd")));
+        System.err.println(createTimeLimit);
+        System.err.println(statDatetimeLimit);
+    }
+
+
 
 
 }