|
@@ -1,8 +1,10 @@
|
|
|
-import { forwardRef, Inject, Injectable } from '@nestjs/common'
|
|
|
|
|
|
|
+import { Injectable } from '@nestjs/common'
|
|
|
import { InjectRepository } from '@nestjs/typeorm'
|
|
import { InjectRepository } from '@nestjs/typeorm'
|
|
|
import { TaskItem } from '../task/entities/task-item.entity'
|
|
import { TaskItem } from '../task/entities/task-item.entity'
|
|
|
import { Repository } from 'typeorm'
|
|
import { Repository } from 'typeorm'
|
|
|
import { Task } from '../task/entities/task.entity'
|
|
import { Task } from '../task/entities/task.entity'
|
|
|
|
|
+import { Balance } from '../balance/entities/balance.entities'
|
|
|
|
|
+import { Users } from '../users/entities/users.entity'
|
|
|
|
|
|
|
|
@Injectable()
|
|
@Injectable()
|
|
|
export class StatisticsService {
|
|
export class StatisticsService {
|
|
@@ -10,8 +12,89 @@ export class StatisticsService {
|
|
|
@InjectRepository(Task)
|
|
@InjectRepository(Task)
|
|
|
private taskRepository: Repository<Task>,
|
|
private taskRepository: Repository<Task>,
|
|
|
@InjectRepository(TaskItem)
|
|
@InjectRepository(TaskItem)
|
|
|
- private taskItemRepository: Repository<TaskItem>
|
|
|
|
|
|
|
+ private taskItemRepository: Repository<TaskItem>,
|
|
|
|
|
+ @InjectRepository(Balance)
|
|
|
|
|
+ private balanceRepository: Repository<Balance>,
|
|
|
|
|
+ @InjectRepository(Users)
|
|
|
|
|
+ private usersRepository: Repository<Users>
|
|
|
) {
|
|
) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ async getTotalStatistics(): Promise<{ totalTopUp: number, totalSend: number, totalSendSuccess: number }> {
|
|
|
|
|
+ // 获取所有总充值金额
|
|
|
|
|
+ const topUp = await this.balanceRepository.createQueryBuilder('balance')
|
|
|
|
|
+ .select('SUM(totalBalance)', 'topUp')
|
|
|
|
|
+ .getRawOne()
|
|
|
|
|
+
|
|
|
|
|
+ // 获取总发送条数
|
|
|
|
|
+ const send = await this.taskItemRepository.createQueryBuilder('taskItem')
|
|
|
|
|
+ .select('count(1)', 'send')
|
|
|
|
|
+ .getRawOne()
|
|
|
|
|
+ // 获取总发送成功条数 status = success
|
|
|
|
|
+ const sendSuccess = await this.taskItemRepository.createQueryBuilder('taskItem')
|
|
|
|
|
+ .select('count(1)', 'sendSuccess')
|
|
|
|
|
+ .where('status = :status', { status: 'success' })
|
|
|
|
|
+ .getRawOne()
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ totalTopUp: topUp.totalTopUp,
|
|
|
|
|
+ totalSend: send.send,
|
|
|
|
|
+ totalSendSuccess: sendSuccess.sendSuccess
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async getTotalStatisticsByMonth(): Promise<{ totalTopUp: number, totalSend: number, totalSendSuccess: number }> {
|
|
|
|
|
+ // 查询当月充值
|
|
|
|
|
+ const topUp = await this.taskItemRepository.createQueryBuilder('taskItem')
|
|
|
|
|
+ .select('SUM(amount)', 'totalTopUp')
|
|
|
|
|
+ .where('MONTH(createDate) = MONTH(current_date)')
|
|
|
|
|
+ .getRawOne()
|
|
|
|
|
+
|
|
|
|
|
+ // 获取当月总发送条数
|
|
|
|
|
+ const send = await this.taskItemRepository.createQueryBuilder('taskItem')
|
|
|
|
|
+ .select('count(1)', 'send')
|
|
|
|
|
+ .where('MONTH(createdAt) = MONTH(current_date)')
|
|
|
|
|
+ .getRawOne()
|
|
|
|
|
+ // 获取当月总发送成功条数 status = success
|
|
|
|
|
+ const sendSuccess = await this.taskItemRepository.createQueryBuilder('taskItem')
|
|
|
|
|
+ .select('count(1)', 'sendSuccess')
|
|
|
|
|
+ .where('status = :status', { status: 'success' })
|
|
|
|
|
+ .where('MONTH(createdAt) = MONTH(current_date)')
|
|
|
|
|
+ .getRawOne()
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ totalTopUp: topUp.totalTopUp,
|
|
|
|
|
+ totalSend: send.send,
|
|
|
|
|
+ totalSendSuccess: sendSuccess.sendSuccess
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ async getTotalStatisticsByDay(): Promise<{ totalTopUp: number, totalSend: number, totalSendSuccess: number }> {
|
|
|
|
|
+ // 查询当日充值
|
|
|
|
|
+ const topUp = await this.taskItemRepository.createQueryBuilder('taskItem')
|
|
|
|
|
+ .select('SUM(amount)', 'totalTopUp')
|
|
|
|
|
+ .where('DATE(createDate) = DATE(current_date)')
|
|
|
|
|
+ .getRawOne()
|
|
|
|
|
+
|
|
|
|
|
+ // 获取当日总发送条数
|
|
|
|
|
+ const send = await this.taskItemRepository.createQueryBuilder('taskItem')
|
|
|
|
|
+ .select('count(1)', 'send')
|
|
|
|
|
+ .where('DATE(createdAt) = DATE(current_date)')
|
|
|
|
|
+ .getRawOne()
|
|
|
|
|
+ // 获取当日总发送成功条数 status = success
|
|
|
|
|
+ const sendSuccess = await this.taskItemRepository.createQueryBuilder('taskItem')
|
|
|
|
|
+ .select('count(1)', 'sendSuccess')
|
|
|
|
|
+ .where('status = :status', { status: 'success' })
|
|
|
|
|
+ .where('DATE(createdAt) = DATE(current_date)')
|
|
|
|
|
+ .getRawOne()
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ totalTopUp: topUp.totalTopUp,
|
|
|
|
|
+ totalSend: send.send,
|
|
|
|
|
+ totalSendSuccess: sendSuccess.sendSuccess
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|