ソースを参照

refactor(task): 重构 balanceStatistics 方法

- 将 balanceStatistics 方法改为支持单个平台的余额统计
- 优化了代码结构,提高了可读性和可维护性- 添加了对不支持平台的异常处理
- 调整了 API 调用逻辑,提高了性能
wui 6 ヶ月 前
コミット
30b35689a0
2 ファイル変更245 行追加428 行削除
  1. 4 4
      src/task/task.controller.ts
  2. 241 424
      src/task/task.service.ts

+ 4 - 4
src/task/task.controller.ts

@@ -1,4 +1,4 @@
-import { Body, Controller, Delete, Get, Param, Post, Put, Req } from '@nestjs/common'
+import { Body, Controller, Delete, Get, Param, Post, Put, Req, Query } from '@nestjs/common'
 import { PageRequest } from 'src/common/dto/page-request'
 import { Task } from './entities/task.entity'
 import { TaskService } from './task.service'
@@ -130,10 +130,10 @@ export class TaskController {
         return await this.taskService.codeStatistics()
     }
 
-    @Get('/balanceStatistics')
+    @Get('/balanceStatistics/:platform')
     @HasAnyRoles('admin')
-    async balanceStatistics() {
-        return await this.taskService.balanceStatistics()
+    async balanceStatistics(@Param('platform') platform: string) {
+        return await this.taskService.balanceStatistics(platform)
     }
 
     @Get('/hourSentStatistics')

+ 241 - 424
src/task/task.service.ts

@@ -607,7 +607,6 @@ export class TaskService implements OnModuleInit {
             }
         } else {
             where = {
-                // userId: Not(1),
                 createdAt: Between(sixDaysAgo, new Date())
             }
         }
@@ -696,341 +695,280 @@ export class TaskService implements OnModuleInit {
         return Object.values(groupedData)
     }
 
-    async balanceStatistics() {
-        const res = {
+    async balanceStatistics(platform: string) {
+        const supportedPlatforms = {
             durian: 0,
             durian02: 0,
-            cloud033: 0,
-            cloud034: 0,
-            cloud037: 0,
-            cloud041: 0,
-            cloud050: 0,
             xyz: 0,
-            cowboy: 0,
             usapanel: 0,
             dashboard: 0,
             smspva: 0,
             smspva02: 0,
             smstiger: 0
         }
-        // const cloudInstance = axios.create({
-        //     baseURL: 'http://52.77.17.214:9001/api/',
-        //     timeout: 5000 // 设置5秒超时
-        // })
-        const xyzInstance = axios.create({
-            baseURL: 'http://113.28.178.155:8003/api/'
-        })
-        const panelInstance = axios.create({
-            baseURL: 'https://panel.hellomeetyou.com/api/'
-        })
-        const dashboardInstance = axios.create({
-            baseURL: 'https://code.smscodes.io/api/sms/'
-        })
-        const smspvaInstance = axios.create({
-            baseURL: 'https://api.smspva.com/activation/'
-        })
-        const smstigerInstance = axios.create({
-            baseURL: 'https://api.tiger-sms.com/stubs/'
-        })
 
-        // 创建性能日志对象
+        // 验证平台是否支持
+        if (!supportedPlatforms.hasOwnProperty(platform)) {
+            throw new NotFoundException(`不支持的平台: ${platform}。`)
+        }
+
+        const res = { ...supportedPlatforms }
         const perfLogs = {}
+        const tasks = []
 
-        await Promise.all([
-            (async () => {
-                const startTime = Date.now()
-                perfLogs['durian'] = { startTime }
-                try {
-                    const durianRes = await axios
-                        .create({
-                            baseURL: 'http://8.218.211.187/out/ext_api/',
-                            headers: {
-                                uhost: 'api.durianrcs.com',
-                                uprotocol: 'http'
-                            }
-                        })
-                        .get('getUserInfo', {
+        // 根据需要创建相应的 axios 实例
+        let xyzInstance, panelInstance, dashboardInstance, smspvaInstance, smstigerInstance
+
+        switch (platform) {
+            case 'xyz':
+                xyzInstance = axios.create({
+                    baseURL: 'http://113.28.178.155:8003/api/'
+                })
+                break
+            case 'usapanel':
+                panelInstance = axios.create({
+                    baseURL: 'https://panel.hellomeetyou.com/api/'
+                })
+                break
+            case 'dashboard':
+                dashboardInstance = axios.create({
+                    baseURL: 'https://code.smscodes.io/api/sms/'
+                })
+                break
+            case 'smspva':
+            case 'smspva02':
+                smspvaInstance = axios.create({
+                    baseURL: 'https://api.smspva.com/activation/'
+                })
+                break
+            case 'smstiger':
+                smstigerInstance = axios.create({
+                    baseURL: 'https://api.tiger-sms.com/stubs/'
+                })
+                break
+        }
+
+        if (platform === 'durian') {
+            tasks.push(
+                (async () => {
+                    const startTime = Date.now()
+                    perfLogs['durian'] = { startTime }
+                    try {
+                        const durianRes = await axios
+                            .create({
+                                baseURL: 'http://8.218.211.187/out/ext_api/',
+                                headers: {
+                                    uhost: 'api.durianrcs.com',
+                                    uprotocol: 'http'
+                                }
+                            })
+                            .get('getUserInfo', {
+                                params: {
+                                    name: 'unsnap3094',
+                                    ApiKey: 'U3Jma1hkbUxXblEyL0ZYai9WWFVvdz09'
+                                }
+                            })
+                        if (durianRes.data.code === 200) {
+                            res.durian = durianRes.data.data.score
+                        }
+                    } catch (e) {
+                        Logger.warn(`durian API调用失败: ${e.message}`, this.TAG)
+                    }
+                    perfLogs['durian'].endTime = Date.now()
+                    perfLogs['durian'].duration = perfLogs['durian'].endTime - perfLogs['durian'].startTime
+                    Logger.log(`API调用性能统计 - durian: ${perfLogs['durian'].duration}ms`, this.TAG)
+                })()
+            )
+        }
+
+        if (platform === 'durian02') {
+            tasks.push(
+                (async () => {
+                    const startTime = Date.now()
+                    perfLogs['durian02'] = { startTime }
+                    try {
+                        const durianRes02 = await axios
+                            .create({
+                                baseURL: 'http://8.218.211.187/out/ext_api/',
+                                headers: {
+                                    uhost: 'api.durianrcs.com',
+                                    uprotocol: 'http'
+                                }
+                            })
+                            .get('getUserInfo', {
+                                params: {
+                                    name: 'unsnap30941',
+                                    ApiKey: 'RHJGV1paR1BFWjlFbCtnakUza2xJdz09'
+                                }
+                            })
+                        if (durianRes02.data.code === 200) {
+                            res.durian02 = durianRes02.data.data.score
+                        }
+                    } catch (e) {
+                        Logger.warn(`durian02 API调用失败: ${e.message}`, this.TAG)
+                    }
+                    perfLogs['durian02'].endTime = Date.now()
+                    perfLogs['durian02'].duration = perfLogs['durian02'].endTime - perfLogs['durian02'].startTime
+                    Logger.log(`API调用性能统计 - durian02: ${perfLogs['durian02'].duration}ms`, this.TAG)
+                })()
+            )
+        }
+
+        if (platform === 'xyz') {
+            tasks.push(
+                (async () => {
+                    const startTime = Date.now()
+                    perfLogs['xyz'] = { startTime }
+                    try {
+                        const xyz = await xyzInstance.get('v1', {
                             params: {
-                                name: 'unsnap3094',
-                                ApiKey: 'U3Jma1hkbUxXblEyL0ZYai9WWFVvdz09'
+                                act: 'myinfo',
+                                token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InVpZCI6MjUsInJvbGVfaWQiOjF9fQ.VU1tvG72YaXooUT-FUaQj-YWVXnVrYBad1AsoWUT4pw'
                             }
                         })
-                    if (durianRes.data.code === 200) {
-                        res.durian = durianRes.data.data.score
+                        const parts = xyz.data.split('|').map((part) => part.trim())
+                        if (parts[0] === '0') {
+                            res.xyz = parts[1] < 0 ? 0 : parts[1]
+                        }
+                    } catch (e) {
+                        Logger.warn(`xyz API调用失败: ${e.message}`, this.TAG)
                     }
-                } catch (e) {
-                    Logger.warn(`durian API调用失败: ${e.message}`, this.TAG)
-                }
-                perfLogs['durian'].endTime = Date.now()
-                perfLogs['durian'].duration = perfLogs['durian'].endTime - perfLogs['durian'].startTime
-                Logger.log(`API调用性能统计 - durian: ${perfLogs['durian'].duration}ms`, this.TAG)
-            })(),
-            (async () => {
-                const startTime = Date.now()
-                perfLogs['durian02'] = { startTime }
-                try {
-                    const durianRes02 = await axios
-                        .create({
-                            baseURL: 'http://8.218.211.187/out/ext_api/',
+                    perfLogs['xyz'].endTime = Date.now()
+                    perfLogs['xyz'].duration = perfLogs['xyz'].endTime - perfLogs['xyz'].startTime
+                    Logger.log(`API调用性能统计 - xyz: ${perfLogs['xyz'].duration}ms`, this.TAG)
+                })()
+            )
+        }
+
+        if (platform === 'usapanel') {
+            tasks.push(
+                (async () => {
+                    const startTime = Date.now()
+                    perfLogs['usapanel'] = { startTime }
+                    try {
+                        const panelRes = await panelInstance.get('account', {
                             headers: {
-                                uhost: 'api.durianrcs.com',
-                                uprotocol: 'http'
+                                'Content-Type': 'application/json',
+                                Accept: 'application/json',
+                                'X-API-Key': 'wpJohESEZsjW1LtlyoGwZw53'
                             }
                         })
-                        .get('getUserInfo', {
+                        if (panelRes.data) {
+                            res.usapanel = panelRes.data.balance
+                        }
+                    } catch (e) {
+                        Logger.warn(`usapanel API调用失败: ${e.message}`, this.TAG)
+                    }
+                    perfLogs['usapanel'].endTime = Date.now()
+                    perfLogs['usapanel'].duration = perfLogs['usapanel'].endTime - perfLogs['usapanel'].startTime
+                    Logger.log(`API调用性能统计 - usapanel: ${perfLogs['usapanel'].duration}ms`, this.TAG)
+                })()
+            )
+        }
+
+        if (platform === 'dashboard') {
+            tasks.push(
+                (async () => {
+                    const startTime = Date.now()
+                    perfLogs['dashboard'] = { startTime }
+                    try {
+                        const dashboardRes = await dashboardInstance.get('GetBalance', {
                             params: {
-                                name: 'unsnap30941',
-                                ApiKey: 'RHJGV1paR1BFWjlFbCtnakUza2xJdz09'
+                                key: '6619f084-363c-4518-b5b8-57b5e01a9c95'
                             }
                         })
-                    if (durianRes02.data.code === 200) {
-                        res.durian02 = durianRes02.data.data.score
-                    }
-                } catch (e) {
-                    Logger.warn(`durian02 API调用失败: ${e.message}`, this.TAG)
-                }
-                perfLogs['durian02'].endTime = Date.now()
-                perfLogs['durian02'].duration = perfLogs['durian02'].endTime - perfLogs['durian02'].startTime
-                Logger.log(`API调用性能统计 - durian02: ${perfLogs['durian02'].duration}ms`, this.TAG)
-            })(),
-            // (async () => {
-            //     const startTime = Date.now()
-            //     perfLogs['cowboy'] = { startTime }
-            //     try {
-            //         const cowboyRes = await axios
-            //             .create({
-            //                 baseURL: 'http://8.218.211.187/',
-            //                 headers: {
-            //                     uhost: 'api.cowboymsg.com',
-            //                     uprotocol: 'http'
-            //                 }
-            //             })
-            //             .get('getUserInfo', {
-            //                 params: {
-            //                     name: 'launch',
-            //                     ApiKey: 'NUdVcVMxelBQTXlpcTBwbk1XQUhzQT09'
-            //                 }
-            //             })
-            //         if (cowboyRes.data.code === 200) {
-            //             res.cowboy = cowboyRes.data.data.score
-            //         }
-            //     } catch (e) {
-            //         Logger.warn(`cowboy API调用失败: ${e.message}`, this.TAG)
-            //     }
-            //     perfLogs['cowboy'].endTime = Date.now()
-            //     perfLogs['cowboy'].duration = perfLogs['cowboy'].endTime - perfLogs['cowboy'].startTime
-            //     Logger.log(`API调用性能统计 - cowboy: ${perfLogs['cowboy'].duration}ms`, this.TAG)
-            // })(),
-            (async () => {
-                const startTime = Date.now()
-                perfLogs['xyz'] = { startTime }
-                try {
-                    const xyz = await xyzInstance.get('v1', {
-                        params: {
-                            act: 'myinfo',
-                            token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InVpZCI6MjUsInJvbGVfaWQiOjF9fQ.VU1tvG72YaXooUT-FUaQj-YWVXnVrYBad1AsoWUT4pw'
-                        }
-                    })
-                    const parts = xyz.data.split('|').map((part) => part.trim())
-                    if (parts[0] === '0') {
-                        res.xyz = parts[1] < 0 ? 0 : parts[1]
-                    }
-                } catch (e) {
-                    Logger.warn(`xyz API调用失败: ${e.message}`, this.TAG)
-                }
-                perfLogs['xyz'].endTime = Date.now()
-                perfLogs['xyz'].duration = perfLogs['xyz'].endTime - perfLogs['xyz'].startTime
-                Logger.log(`API调用性能统计 - xyz: ${perfLogs['xyz'].duration}ms`, this.TAG)
-            })(),
-            // (async () => {
-            //     const startTime = Date.now()
-            //     perfLogs['cloud033'] = { startTime }
-            //     try {
-            //         const cloud033Res = await cloudInstance.get('userBalance', {
-            //             params: {
-            //                 userid: '100033',
-            //                 token: '1e40ca9795b1fc038db76512175d59b5'
-            //             }
-            //         })
-            //         if (cloud033Res.data.code === '1001') {
-            //             res.cloud033 = cloud033Res.data.data.integral
-            //         }
-            //     } catch (e) {}
-            //     perfLogs['cloud033'].endTime = Date.now()
-            //     perfLogs['cloud033'].duration = perfLogs['cloud033'].endTime - perfLogs['cloud033'].startTime
-            // })(),
-            // (async () => {
-            //     const startTime = Date.now()
-            //     perfLogs['cloud034'] = { startTime }
-            //     try {
-            //         const cloud034Res = await cloudInstance.get('userBalance', {
-            //             params: {
-            //                 userid: '100034',
-            //                 token: '54bdd0d9dd6707b2b40d8deb5edb1385'
-            //             }
-            //         })
-            //         if (cloud034Res.data.code === '1001') {
-            //             res.cloud034 = cloud034Res.data.data.integral
-            //         }
-            //     } catch (e) {}
-            //     perfLogs['cloud034'].endTime = Date.now()
-            //     perfLogs['cloud034'].duration = perfLogs['cloud034'].endTime - perfLogs['cloud034'].startTime
-            // })(),
-            // (async () => {
-            //     const startTime = Date.now()
-            //     perfLogs['cloud037'] = { startTime }
-            //     try {
-            //         const cloud037Res = await cloudInstance.get('userBalance', {
-            //             params: {
-            //                 userid: '100037',
-            //                 token: 'aaec6c21e54dc53b92e472df21a95bb7'
-            //             }
-            //         })
-            //         if (cloud037Res.data.code === '1001') {
-            //             res.cloud037 = cloud037Res.data.data.integral
-            //         }
-            //     } catch (e) {}
-            //     perfLogs['cloud037'].endTime = Date.now()
-            //     perfLogs['cloud037'].duration = perfLogs['cloud037'].endTime - perfLogs['cloud037'].startTime
-            // })(),
-            // (async () => {
-            //     const startTime = Date.now()
-            //     perfLogs['cloud041'] = { startTime }
-            //     try {
-            //         const cloud041Res = await cloudInstance.get('userBalance', {
-            //             params: {
-            //                 userid: '100041',
-            //                 token: '8174f3107605645d17fd6c5edc0bfb7d'
-            //             }
-            //         })
-            //         if (cloud041Res.data.code === '1001') {
-            //             res.cloud041 = cloud041Res.data.data.integral
-            //         }
-            //     } catch (e) {}
-            //     perfLogs['cloud041'].endTime = Date.now()
-            //     perfLogs['cloud041'].duration = perfLogs['cloud041'].endTime - perfLogs['cloud041'].startTime
-            // })(),
-            // (async () => {
-            //     const startTime = Date.now()
-            //     perfLogs['cloud050'] = { startTime }
-            //     try {
-            //         const cloud050Res = await cloudInstance.get('userBalance', {
-            //             params: {
-            //                 userid: '100050',
-            //                 token: '6c0f25c802b82d2a5c78f01fb627be2c'
-            //             }
-            //         })
-            //         if (cloud050Res.data.code === '1001') {
-            //             res.cloud050 = cloud050Res.data.data.integral
-            //         }
-            //     } catch (e) {}
-            //     perfLogs['cloud050'].endTime = Date.now()
-            //     perfLogs['cloud050'].duration = perfLogs['cloud050'].endTime - perfLogs['cloud050'].startTime
-            // })(),
-            (async () => {
-                const startTime = Date.now()
-                perfLogs['usapanel'] = { startTime }
-                try {
-                    const panelRes = await panelInstance.get('account', {
-                        headers: {
-                            'Content-Type': 'application/json',
-                            Accept: 'application/json',
-                            'X-API-Key': 'wpJohESEZsjW1LtlyoGwZw53'
-                        }
-                    })
-                    if (panelRes.data) {
-                        res.usapanel = panelRes.data.balance
-                    }
-                } catch (e) {
-                    Logger.warn(`usapanel API调用失败: ${e.message}`, this.TAG)
-                }
-                perfLogs['usapanel'].endTime = Date.now()
-                perfLogs['usapanel'].duration = perfLogs['usapanel'].endTime - perfLogs['usapanel'].startTime
-                Logger.log(`API调用性能统计 - usapanel: ${perfLogs['usapanel'].duration}ms`, this.TAG)
-            })(),
-            (async () => {
-                const startTime = Date.now()
-                perfLogs['dashboard'] = { startTime }
-                try {
-                    const dashboardRes = await dashboardInstance.get('GetBalance', {
-                        params: {
-                            key: '6619f084-363c-4518-b5b8-57b5e01a9c95'
+                        if (dashboardRes.data.Status === 'Success') {
+                            res.dashboard = dashboardRes.data.Balance
                         }
-                    })
-                    if (dashboardRes.data.Status === 'Success') {
-                        res.dashboard = dashboardRes.data.Balance
+                    } catch (e) {
+                        Logger.warn(`dashboard API调用失败: ${e.message}`, this.TAG)
                     }
-                } catch (e) {
-                    Logger.warn(`dashboard API调用失败: ${e.message}`, this.TAG)
-                }
-                perfLogs['dashboard'].endTime = Date.now()
-                perfLogs['dashboard'].duration = perfLogs['dashboard'].endTime - perfLogs['dashboard'].startTime
-                Logger.log(`API调用性能统计 - dashboard: ${perfLogs['dashboard'].duration}ms`, this.TAG)
-            })(),
-            (async () => {
-                const startTime = Date.now()
-                perfLogs['smspva'] = { startTime }
-                try {
-                    const smspvaRes = await smspvaInstance.get('balance', {
-                        headers: {
-                            apikey: 'uNW56fGr0zstfs87Xn0e1l2gCYVnb1'
+                    perfLogs['dashboard'].endTime = Date.now()
+                    perfLogs['dashboard'].duration = perfLogs['dashboard'].endTime - perfLogs['dashboard'].startTime
+                    Logger.log(`API调用性能统计 - dashboard: ${perfLogs['dashboard'].duration}ms`, this.TAG)
+                })()
+            )
+        }
+
+        if (platform === 'smspva') {
+            tasks.push(
+                (async () => {
+                    const startTime = Date.now()
+                    perfLogs['smspva'] = { startTime }
+                    try {
+                        const smspvaRes = await smspvaInstance.get('balance', {
+                            headers: {
+                                apikey: 'uNW56fGr0zstfs87Xn0e1l2gCYVnb1'
+                            }
+                        })
+                        if (smspvaRes.data.statusCode === 200) {
+                            res.smspva = smspvaRes.data.data.balance
                         }
-                    })
-                    if (smspvaRes.data.statusCode === 200) {
-                        res.smspva = smspvaRes.data.data.balance
+                    } catch (e) {
+                        Logger.warn(`smspva API调用失败: ${e.message}`, this.TAG)
                     }
-                } catch (e) {
-                    Logger.warn(`smspva API调用失败: ${e.message}`, this.TAG)
-                }
-                perfLogs['smspva'].endTime = Date.now()
-                perfLogs['smspva'].duration = perfLogs['smspva'].endTime - perfLogs['smspva'].startTime
-                Logger.log(`API调用性能统计 - smspva: ${perfLogs['smspva'].duration}ms`, this.TAG)
-            })(),
-            (async () => {
-                const startTime = Date.now()
-                perfLogs['smspva02'] = { startTime }
-                try {
-                    const smspva02Res = await smspvaInstance.get('balance', {
-                        headers: {
-                            apikey: 'rTTL8pZtKkQ60zjU82bvbMEP7G6XGU'
+                    perfLogs['smspva'].endTime = Date.now()
+                    perfLogs['smspva'].duration = perfLogs['smspva'].endTime - perfLogs['smspva'].startTime
+                    Logger.log(`API调用性能统计 - smspva: ${perfLogs['smspva'].duration}ms`, this.TAG)
+                })()
+            )
+        }
+
+        if (platform === 'smspva02') {
+            tasks.push(
+                (async () => {
+                    const startTime = Date.now()
+                    perfLogs['smspva02'] = { startTime }
+                    try {
+                        const smspva02Res = await smspvaInstance.get('balance', {
+                            headers: {
+                                apikey: 'rTTL8pZtKkQ60zjU82bvbMEP7G6XGU'
+                            }
+                        })
+                        if (smspva02Res.data.statusCode === 200) {
+                            res.smspva02 = smspva02Res.data.data.balance
                         }
-                    })
-                    if (smspva02Res.data.statusCode === 200) {
-                        res.smspva02 = smspva02Res.data.data.balance
+                    } catch (e) {
+                        Logger.warn(`smspva02 API调用失败: ${e.message}`, this.TAG)
                     }
-                } catch (e) {
-                    Logger.warn(`smspva02 API调用失败: ${e.message}`, this.TAG)
-                }
-                perfLogs['smspva02'].endTime = Date.now()
-                perfLogs['smspva02'].duration = perfLogs['smspva02'].endTime - perfLogs['smspva02'].startTime
-                Logger.log(`API调用性能统计 - smspva02: ${perfLogs['smspva02'].duration}ms`, this.TAG)
-            })(),
-            (async () => {
-                const startTime = Date.now()
-                perfLogs['smstiger'] = { startTime }
-                try {
-                    const smstigerRes = await smstigerInstance.get('handler_api.php', {
-                        params: {
-                            api_key: 't6AV7f5KgwRmWsK9M5xN6uTTtHiog8EQ',
-                            action: 'getBalance'
+                    perfLogs['smspva02'].endTime = Date.now()
+                    perfLogs['smspva02'].duration = perfLogs['smspva02'].endTime - perfLogs['smspva02'].startTime
+                    Logger.log(`API调用性能统计 - smspva02: ${perfLogs['smspva02'].duration}ms`, this.TAG)
+                })()
+            )
+        }
+
+        if (platform === 'smstiger') {
+            tasks.push(
+                (async () => {
+                    const startTime = Date.now()
+                    perfLogs['smstiger'] = { startTime }
+                    try {
+                        const smstigerRes = await smstigerInstance.get('handler_api.php', {
+                            params: {
+                                api_key: 't6AV7f5KgwRmWsK9M5xN6uTTtHiog8EQ',
+                                action: 'getBalance'
+                            }
+                        })
+                        const data = smstigerRes.data.split(':')
+                        if (data[0] === 'ACCESS_BALANCE') {
+                            res.smstiger = data[1]
                         }
-                    })
-                    const data = smstigerRes.data.split(':')
-                    if (data[0] === 'ACCESS_BALANCE') {
-                        res.smstiger = data[1]
+                    } catch (e) {
+                        Logger.warn(`smstiger API调用失败: ${e.message}`, this.TAG)
                     }
-                } catch (e) {
-                    Logger.warn(`smstiger API调用失败: ${e.message}`, this.TAG)
-                }
-                perfLogs['smstiger'].endTime = Date.now()
-                perfLogs['smstiger'].duration = perfLogs['smstiger'].endTime - perfLogs['smstiger'].startTime
-                Logger.log(`API调用性能统计 - smstiger: ${perfLogs['smstiger'].duration}ms`, this.TAG)
-            })()
-        ])
+                    perfLogs['smstiger'].endTime = Date.now()
+                    perfLogs['smstiger'].duration = perfLogs['smstiger'].endTime - perfLogs['smstiger'].startTime
+                    Logger.log(`API调用性能统计 - smstiger: ${perfLogs['smstiger'].duration}ms`, this.TAG)
+                })()
+            )
+        }
+
+        await Promise.all(tasks)
 
         Logger.log(`API调用性能统计total: ${JSON.stringify(perfLogs)}`, this.TAG)
 
-        return res
+        return { [platform]: res[platform] }
     }
 
     async hourSentStatistics() {
@@ -1349,127 +1287,6 @@ export class TaskService implements OnModuleInit {
         return new Decimal(number).mul(parseInt(multiplier))
     }
 
-    // @Interval(2000)
-    // async scheduleTask() {
-    //     this.lock
-    //         .acquire(
-    //             'dispatchTask',
-    //             async () => {
-    //                 const maxParallel = await this.getConfig('max_parallel', 1)
-    //                 const batchSize = 200
-
-    //                 let tasks = await this.taskRepository.find({
-    //                     where: {
-    //                         status: TaskStatus.PENDING
-    //                     },
-    //                     order: {
-    //                         startedAt: 'ASC'
-    //                     },
-    //                     take: maxParallel
-    //                 })
-    //                 // 少补
-    //                 if (tasks.length < maxParallel) {
-    //                     const nextTasks = await this.taskRepository.find({
-    //                         where: {
-    //                             status: TaskStatus.QUEUED
-    //                         },
-    //                         order: {
-    //                             startedAt: 'ASC',
-    //                             id: 'ASC'
-    //                         }
-    //                     })
-
-    //                     if (nextTasks.length > 0) {
-    //                         const userIdMap = new Map()
-    //                         tasks.forEach((task) => {
-    //                             userIdMap.set(task.userId, (userIdMap.get(task.userId) || 0) + 1)
-    //                         })
-
-    //                         // nextTasks筛选,从排队任务中筛选出最多2个同用户下的任务
-    //                         let filteredTasks = []
-    //                         const userIds = {}
-    //                         const limit = maxParallel - tasks.length
-    //                         for (const task of nextTasks) {
-    //                             if (!userIds[task.userId]) {
-    //                                 userIds[task.userId] = 0
-    //                             }
-    //                             if ((userIdMap.get(task.userId) || 0) + userIds[task.userId] < 2) {
-    //                                 filteredTasks.push(task)
-    //                                 userIds[task.userId]++
-    //                             }
-    //                             if (filteredTasks.length >= limit) {
-    //                                 break
-    //                             }
-    //                         }
-
-    //                         const nextTasksIds = filteredTasks.map((t) => t.id)
-    //                         if (nextTasksIds.length === 0) {
-    //                             nextTasksIds.push(...nextTasks.map((t) => t.id).slice(0, limit))
-    //                         }
-    //                         await this.taskRepository.update({ id: In(nextTasksIds) }, { status: TaskStatus.PENDING })
-    //                         tasks.push(...filteredTasks)
-    //                     }
-    //                 }
-
-    //                 const pendingTasks = (await this.findPendingTasks()).sort(() => Math.random() - 0.5)
-    //                 if (pendingTasks.length === 0) return
-    //                 const devices = await this.deviceService.findAllAvailableDevices()
-    //                 if (devices.length === 0) return
-    //                 const countryMapping = await this.countryConfigService.getAllDestConfig(
-    //                     pendingTasks.map((t) => t.country)
-    //                 )
-
-    //                 const res = pendingTasks.map((task) => {
-    //                     return {
-    //                         task,
-    //                         useCountry: countryMapping.find((c) => c.id === task.country)?.useCountry || ['any'],
-    //                         exclude: countryMapping.find((c) => c.id === task.country)?.exclude || [],
-    //                         devices: []
-    //                     }
-    //                 })
-
-    //                 devices.forEach((device) => {
-    //                     let candidateTasks = res.filter(
-    //                         (r) => Math.ceil((r.task.total - r.task.sent) / batchSize) > r.devices.length
-    //                     )
-    //                     if (device.matchCountry && device.pinCountry) {
-    //                         candidateTasks = candidateTasks.filter((r) => {
-    //                             return (
-    //                                 r.useCountry.includes(device.pinCountry.toUpperCase()) &&
-    //                                 !r.exclude.includes(device.pinCountry.toUpperCase())
-    //                             )
-    //                         })
-    //                     } else {
-    //                         candidateTasks = candidateTasks.filter((r) => {
-    //                             return (
-    //                                 (r.useCountry.includes('any') ||
-    //                                     r.useCountry.includes(device.currentCountry?.toUpperCase())) &&
-    //                                 !r.exclude.includes(device.currentCountry?.toUpperCase())
-    //                             )
-    //                         })
-    //                     }
-    //                     if (candidateTasks.length > 0) {
-    //                         candidateTasks.sort((a, b) => {
-    //                             return a.devices.length - b.devices.length
-    //                         })
-    //                         candidateTasks[0].devices.push(device)
-    //                     }
-    //                 })
-    //                 for (let r of res) {
-    //                     if (r.devices.length > 0) {
-    //                         await this.dispatchTask(r.task, r.devices)
-    //                     }
-    //                 }
-    //             },
-    //             {
-    //                 timeout: 1
-    //             }
-    //         )
-    //         .catch((e) => {
-    //             if (e.message.includes('timed out')) return
-    //             Logger.error('Error dispatchTask', e.stack, this.TAG)
-    //         })
-    // }
     @Interval(2000)
     async scheduleTask() {
         this.lock