Browse Source

feat(task): 添加任务送达率统计

- 在任务实体中增加 deliveryRate 和 deliveryCount 字段
- 在任务服务中计算并更新任务的送达率和送达数
wui 1 year ago
parent
commit
695bef2f27
2 changed files with 14 additions and 1 deletions
  1. 6 0
      src/task/entities/task.entity.ts
  2. 8 1
      src/task/task.service.ts

+ 6 - 0
src/task/entities/task.entity.ts

@@ -66,6 +66,9 @@ export class Task {
     @Column({ nullable: true })
     successRate: string
 
+    @Column({ nullable: true })
+    deliveryRate: string
+
     @Column({ default: 0 })
     total: number
 
@@ -75,6 +78,9 @@ export class Task {
     @Column({ default: 0 })
     successCount: number
 
+    @Column({ default: 0 })
+    deliveryCount: number
+
     @Column({ default: 0 })
     requestNumberInterval: number
 

+ 8 - 1
src/task/task.service.ts

@@ -1436,13 +1436,20 @@ export class TaskService implements OnModuleInit {
             const pendingCount = counts.pending || 0
             const idleCount = counts.idle || 0
             const finish = pendingCount === 0 && idleCount === 0
+
+            // 送达率
+            const deliveryCount = await this.taskItemRepository.countBy({ taskId: task.id, delivery: 1 })
+
             const data: Partial<Task> = {
                 sent: successCount + failCount,
                 successCount: successCount,
                 successRate:
                     successCount + failCount > 0
                         ? ((successCount / (successCount + failCount)) * 100).toFixed(1) + '%'
-                        : '0%'
+                        : '0%',
+                deliveryCount: deliveryCount,
+                deliveryRate:
+                    deliveryCount > 0 ? ((deliveryCount / (successCount + failCount)) * 100).toFixed(1) + '%' : '0%'
             }
             if (finish) {
                 data.status = TaskStatus.COMPLETED