feat: 完成券商和用户管理

This commit is contained in:
R524809
2026-01-07 16:21:16 +08:00
parent 712f66b725
commit 457ba6d765
33 changed files with 2851 additions and 177 deletions

View File

@@ -10,6 +10,7 @@ import { CreateBrokerDto } from './dto/create-broker.dto';
import { UpdateBrokerDto } from './dto/update-broker.dto';
import { QueryBrokerDto } from './dto/query-broker.dto';
import { BatchCreateBrokerDto } from './dto/batch-create-broker.dto';
import { PaginationInfo } from '@/common/dto/pagination.dto';
@Injectable()
export class BrokerService {
@@ -109,9 +110,12 @@ export class BrokerService {
}
/**
* 查询 broker支持多种查询条件
* 查询 broker支持多种查询条件和分页
*/
async findAll(queryDto: QueryBrokerDto): Promise<Broker[]> {
async findAll(queryDto: QueryBrokerDto): Promise<{
list: Broker[];
pagination: PaginationInfo;
}> {
const where: FindOptionsWhere<Broker> = {};
if (queryDto.brokerId) {
@@ -134,13 +138,53 @@ export class BrokerService {
where.isActive = queryDto.isActive;
}
return this.brokerRepository.find({
// 分页参数
const page = queryDto.page || 1;
const limit = queryDto.limit || 10;
const skip = (page - 1) * limit;
// 排序字段映射
const sortBy = queryDto.sortBy || 'createdAt';
const sortOrder = queryDto.sortOrder || 'DESC';
// 构建排序对象
const order: Record<string, 'ASC' | 'DESC'> = {};
if (sortBy === 'createdAt') {
order.createdAt = sortOrder;
} else if (sortBy === 'sortOrder') {
order.sortOrder = sortOrder;
} else {
order.createdAt = 'DESC';
}
// 添加默认排序
if (sortBy !== 'sortOrder') {
order.sortOrder = 'ASC';
}
order.brokerId = 'ASC';
// 查询总数
const total = await this.brokerRepository.count({ where });
// 查询分页数据
const list = await this.brokerRepository.find({
where,
order: {
sortOrder: 'ASC',
brokerId: 'ASC',
},
order,
skip,
take: limit,
});
// 计算总页数
const total_page = Math.ceil(total / limit);
return {
list,
pagination: {
total,
total_page,
page_size: limit,
current_page: page,
},
};
}
/**