x1ongzhu hace 1 año
padre
commit
b9a8a348f7

+ 3 - 1
src/rcs-number/entities/rcs-number.entity.ts

@@ -41,6 +41,7 @@ export class RcsNumber {
     expiryTime: Date
 
     @Column({ type: 'enum', enum: RcsNumberSource, nullable: false })
+    @Index('idx_from')
     from: string
 
     @Column()
@@ -52,7 +53,8 @@ export class RcsNumber {
     @Column()
     areaCode: string
 
-    @Column()
+    @Column({ length: 50 })
+    @Index('idx_country')
     country: string
 
     @Column({ nullable: false, length: 50 })

+ 0 - 3
src/task/entities/task-item.entity.ts

@@ -23,9 +23,6 @@ export class TaskItem {
     @Column()
     number: string
 
-    @Column({ type: 'text' })
-    message: string
-
     @Column({ type: 'enum', enum: TaskItemStatus, nullable: false, default: TaskItemStatus.IDLE })
     @Index()
     status: string

+ 4 - 15
src/task/task.service.ts

@@ -147,15 +147,6 @@ export class TaskService implements OnModuleInit {
                     const taskItem = new TaskItem()
                     taskItem.taskId = task.id
                     taskItem.number = phone.number
-                    taskItem.message = task.message
-                    task.dynamicMessage?.forEach((dm) => {
-                        if (dm.key && dm.values?.length > 0) {
-                            taskItem.message = taskItem.message.replaceAll(
-                                `${dm.key}`,
-                                dm.values[Math.floor(Math.random() * dm.values.length)]
-                            )
-                        }
-                    })
                     taskItem.embed = extraNumbers.includes(phone.number)
                     taskItem.status = TaskStatus.IDLE
                     return taskItem
@@ -222,7 +213,7 @@ export class TaskService implements OnModuleInit {
 
     async delTask(id: number): Promise<void> {
         const task = await this.taskRepository.findOneBy({ id })
-        if (task.status !== TaskStatus.IDLE){
+        if (task.status !== TaskStatus.IDLE) {
             throw new Error('当前任务状态无法删除!')
         }
         await this.taskRepository.delete(id)
@@ -848,10 +839,6 @@ export class TaskService implements OnModuleInit {
             return
         }
 
-        taskItems.forEach((item) => {
-            item.message = this.getMessage(task)
-        })
-
         devices = devices.splice(0, Math.ceil(taskItems.length / 5))
         const taskConfig = {
             rcsWait: task.rcsWait || (await this.getConfig('rcs_wait', 2000)),
@@ -872,7 +859,9 @@ export class TaskService implements OnModuleInit {
         )
         Promise.all(
             devices.map(async (device, i) => {
-                const items = taskItems.slice(i * 5, i * 5 + 5)
+                const items = taskItems
+                    .slice(i * 5, i * 5 + 5)
+                    .map((item) => ({ ...item, message: this.getMessage(task) }))
                 try {
                     const res: any = await Promise.race([
                         this.eventsGateway.sendForResult(