refactor(frontend): 删除我的页面中的支付密码功能
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
76d6c30a20
commit
725fb80f80
|
|
@ -6,6 +6,7 @@ import { PriceSnapshotRepository } from '../../infrastructure/persistence/reposi
|
||||||
import { OutboxRepository } from '../../infrastructure/persistence/repositories/outbox.repository';
|
import { OutboxRepository } from '../../infrastructure/persistence/repositories/outbox.repository';
|
||||||
import { SystemMiningAccountRepository } from '../../infrastructure/persistence/repositories/system-mining-account.repository';
|
import { SystemMiningAccountRepository } from '../../infrastructure/persistence/repositories/system-mining-account.repository';
|
||||||
import { PrismaService } from '../../infrastructure/persistence/prisma/prisma.service';
|
import { PrismaService } from '../../infrastructure/persistence/prisma/prisma.service';
|
||||||
|
import { UnitOfWork, TransactionClient } from '../../infrastructure/persistence/unit-of-work/unit-of-work';
|
||||||
import { RedisService } from '../../infrastructure/redis/redis.service';
|
import { RedisService } from '../../infrastructure/redis/redis.service';
|
||||||
import { MiningCalculatorService } from '../../domain/services/mining-calculator.service';
|
import { MiningCalculatorService } from '../../domain/services/mining-calculator.service';
|
||||||
import { ShareAmount } from '../../domain/value-objects/share-amount.vo';
|
import { ShareAmount } from '../../domain/value-objects/share-amount.vo';
|
||||||
|
|
@ -36,6 +37,7 @@ export class MiningDistributionService {
|
||||||
private readonly outboxRepository: OutboxRepository,
|
private readonly outboxRepository: OutboxRepository,
|
||||||
private readonly systemMiningAccountRepository: SystemMiningAccountRepository,
|
private readonly systemMiningAccountRepository: SystemMiningAccountRepository,
|
||||||
private readonly prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
|
private readonly unitOfWork: UnitOfWork,
|
||||||
private readonly redis: RedisService,
|
private readonly redis: RedisService,
|
||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
) {}
|
) {}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import { Global, Module } from '@nestjs/common';
|
import { Global, Module } from '@nestjs/common';
|
||||||
import { PrismaService } from './prisma.service';
|
import { PrismaService } from './prisma.service';
|
||||||
|
import { UnitOfWork } from '../unit-of-work/unit-of-work';
|
||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@Module({
|
@Module({
|
||||||
providers: [PrismaService],
|
providers: [PrismaService, UnitOfWork],
|
||||||
exports: [PrismaService],
|
exports: [PrismaService, UnitOfWork],
|
||||||
})
|
})
|
||||||
export class PrismaModule {}
|
export class PrismaModule {}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
|
||||||
import { PrismaService } from '../prisma/prisma.service';
|
import { PrismaService } from '../prisma/prisma.service';
|
||||||
import { MiningAccountAggregate, MiningTransactionType } from '../../../domain/aggregates/mining-account.aggregate';
|
import { MiningAccountAggregate, MiningTransactionType } from '../../../domain/aggregates/mining-account.aggregate';
|
||||||
import { ShareAmount } from '../../../domain/value-objects/share-amount.vo';
|
import { ShareAmount } from '../../../domain/value-objects/share-amount.vo';
|
||||||
|
import { TransactionClient } from '../unit-of-work/unit-of-work';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MiningAccountRepository {
|
export class MiningAccountRepository {
|
||||||
|
|
@ -32,13 +33,18 @@ export class MiningAccountRepository {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async save(aggregate: MiningAccountAggregate): Promise<void> {
|
/**
|
||||||
|
* 保存账户(带外部事务支持)
|
||||||
|
* @param aggregate 账户聚合
|
||||||
|
* @param tx 可选的外部事务客户端,如果不传则自动创建事务
|
||||||
|
*/
|
||||||
|
async save(aggregate: MiningAccountAggregate, tx?: TransactionClient): Promise<void> {
|
||||||
const snapshot = aggregate.toSnapshot();
|
const snapshot = aggregate.toSnapshot();
|
||||||
const transactions = aggregate.pendingTransactions;
|
const transactions = aggregate.pendingTransactions;
|
||||||
|
|
||||||
await this.prisma.$transaction(async (tx) => {
|
const executeInTx = async (client: TransactionClient) => {
|
||||||
// 保存账户
|
// 保存账户
|
||||||
await tx.miningAccount.upsert({
|
await client.miningAccount.upsert({
|
||||||
where: { accountSequence: snapshot.accountSequence },
|
where: { accountSequence: snapshot.accountSequence },
|
||||||
create: {
|
create: {
|
||||||
accountSequence: snapshot.accountSequence,
|
accountSequence: snapshot.accountSequence,
|
||||||
|
|
@ -59,7 +65,7 @@ export class MiningAccountRepository {
|
||||||
|
|
||||||
// 保存交易流水
|
// 保存交易流水
|
||||||
if (transactions.length > 0) {
|
if (transactions.length > 0) {
|
||||||
await tx.miningTransaction.createMany({
|
await client.miningTransaction.createMany({
|
||||||
data: transactions.map((t) => ({
|
data: transactions.map((t) => ({
|
||||||
accountSequence: snapshot.accountSequence,
|
accountSequence: snapshot.accountSequence,
|
||||||
type: t.type,
|
type: t.type,
|
||||||
|
|
@ -72,7 +78,15 @@ export class MiningAccountRepository {
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (tx) {
|
||||||
|
// 使用外部事务
|
||||||
|
await executeInTx(tx);
|
||||||
|
} else {
|
||||||
|
// 自动创建事务(向后兼容)
|
||||||
|
await this.prisma.$transaction(executeInTx);
|
||||||
|
}
|
||||||
|
|
||||||
aggregate.clearPendingTransactions();
|
aggregate.clearPendingTransactions();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { PrismaService } from '../prisma/prisma.service';
|
import { PrismaService } from '../prisma/prisma.service';
|
||||||
import { ShareAmount } from '../../../domain/value-objects/share-amount.vo';
|
import { ShareAmount } from '../../../domain/value-objects/share-amount.vo';
|
||||||
import { SystemAccountType, Prisma } from '@prisma/client';
|
import { SystemAccountType } from '@prisma/client';
|
||||||
|
import { TransactionClient } from '../unit-of-work/unit-of-work';
|
||||||
// 事务客户端类型
|
|
||||||
type TransactionClient = Prisma.TransactionClient;
|
|
||||||
|
|
||||||
export interface SystemMiningAccountSnapshot {
|
export interface SystemMiningAccountSnapshot {
|
||||||
accountType: SystemAccountType;
|
accountType: SystemAccountType;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { PrismaService } from '../prisma/prisma.service';
|
||||||
|
import { Prisma } from '@prisma/client';
|
||||||
|
|
||||||
|
export type TransactionClient = Omit<
|
||||||
|
PrismaService,
|
||||||
|
'$connect' | '$disconnect' | '$on' | '$transaction' | '$use' | '$extends'
|
||||||
|
>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工作单元模式
|
||||||
|
* 用于管理事务边界,确保多个仓库操作在同一事务中执行
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class UnitOfWork {
|
||||||
|
private transactionClient: TransactionClient | null = null;
|
||||||
|
|
||||||
|
constructor(private readonly prisma: PrismaService) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前事务客户端,如果没有活跃事务则返回普通客户端
|
||||||
|
*/
|
||||||
|
getClient(): TransactionClient {
|
||||||
|
return this.transactionClient || this.prisma;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在事务中执行操作
|
||||||
|
* 使用较长的超时时间以支持挖矿分配等大批量操作
|
||||||
|
*/
|
||||||
|
async executeInTransaction<T>(
|
||||||
|
operation: (client: TransactionClient) => Promise<T>,
|
||||||
|
options?: {
|
||||||
|
maxWait?: number;
|
||||||
|
timeout?: number;
|
||||||
|
isolationLevel?: Prisma.TransactionIsolationLevel;
|
||||||
|
},
|
||||||
|
): Promise<T> {
|
||||||
|
return this.prisma.$transaction(
|
||||||
|
async (tx) => {
|
||||||
|
this.transactionClient = tx as TransactionClient;
|
||||||
|
try {
|
||||||
|
return await operation(tx as TransactionClient);
|
||||||
|
} finally {
|
||||||
|
this.transactionClient = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
maxWait: options?.maxWait ?? 10000, // 默认10秒等待获取事务
|
||||||
|
timeout: options?.timeout ?? 60000, // 默认60秒事务超时(挖矿分配可能需要较长时间)
|
||||||
|
isolationLevel: options?.isolationLevel ?? Prisma.TransactionIsolationLevel.ReadCommitted,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否在事务中
|
||||||
|
*/
|
||||||
|
isInTransaction(): boolean {
|
||||||
|
return this.transactionClient !== null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -313,18 +313,6 @@ class ProfilePage extends ConsumerWidget {
|
||||||
icon: Icons.security,
|
icon: Icons.security,
|
||||||
label: '账户安全',
|
label: '账户安全',
|
||||||
onTap: () => context.push(Routes.changePassword),
|
onTap: () => context.push(Routes.changePassword),
|
||||||
),
|
|
||||||
_buildSettingItem(
|
|
||||||
icon: Icons.lock_outline,
|
|
||||||
label: '支付密码',
|
|
||||||
trailing: const Text(
|
|
||||||
'已设置',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: _green,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onTap: () {},
|
|
||||||
showDivider: false,
|
showDivider: false,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue