|
|
@@ -2,7 +2,7 @@ import { PhoneListService } from './../phone-list/phone-list.service'
|
|
|
import { forwardRef, Inject, Injectable, Logger, OnModuleInit } from '@nestjs/common'
|
|
|
import { InjectRepository } from '@nestjs/typeorm'
|
|
|
import { Task, TaskStatus } from './entities/task.entity'
|
|
|
-import { Repository } from 'typeorm'
|
|
|
+import { In, Repository } from 'typeorm'
|
|
|
import { TaskItem, TaskItemStatus } from './entities/task-item.entity'
|
|
|
import { PageRequest } from '../common/dto/page-request'
|
|
|
import { paginate, Pagination } from 'nestjs-typeorm-paginate'
|
|
|
@@ -91,7 +91,11 @@ export class TaskService implements OnModuleInit {
|
|
|
// 计算成功率
|
|
|
const successRate = ((successCount / totalCount) * 100).toFixed(1) + '%'
|
|
|
newTask.successRate = String(successRate)
|
|
|
- newTask.sent = successCount
|
|
|
+ const sendCount = await this.taskItemRepository.countBy({
|
|
|
+ taskId: id,
|
|
|
+ status: In(['success', 'fail'])
|
|
|
+ })
|
|
|
+ newTask.sent = sendCount
|
|
|
await this.taskRepository.save(newTask)
|
|
|
|
|
|
// 获取用户信息
|
|
|
@@ -115,7 +119,6 @@ export class TaskService implements OnModuleInit {
|
|
|
}
|
|
|
})
|
|
|
balance.currentBalance = latestBalance
|
|
|
-
|
|
|
await this.balanceRepository.save(balance)
|
|
|
await this.userRepository.save(user)
|
|
|
} catch (e) {
|
|
|
@@ -128,7 +131,7 @@ export class TaskService implements OnModuleInit {
|
|
|
const task = await this.taskRepository.findOneBy({ id })
|
|
|
const successCount = await this.taskItemRepository.countBy({
|
|
|
taskId: id,
|
|
|
- status: 'success'
|
|
|
+ status: In(['success', 'fail'])
|
|
|
})
|
|
|
if (task && task.status === TaskStatus.PENDING) {
|
|
|
task.status = TaskStatus.PAUSE
|
|
|
@@ -168,7 +171,7 @@ export class TaskService implements OnModuleInit {
|
|
|
let valid = '有效'
|
|
|
let status = '发送成功'
|
|
|
const sendAt: Date = item.sendAt
|
|
|
- const formattedSendAt = moment(sendAt).format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ const formattedSendAt = moment(sendAt).format('YYYY-MM-DD HH:mm:ss')
|
|
|
if (item.status === TaskItemStatus.FAIL) {
|
|
|
valid = '无效'
|
|
|
status = ''
|