rwadurian/backend/services/admin-service/src/pre-planting/pre-planting-config.control...

145 lines
4.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {
Controller,
Get,
Post,
Put,
Body,
Query,
HttpCode,
HttpStatus,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiQuery } from '@nestjs/swagger';
import { IsBoolean, IsOptional, IsString } from 'class-validator';
import { PrePlantingConfigService } from './pre-planting-config.service';
import { PrePlantingProxyService } from './pre-planting-proxy.service';
class UpdatePrePlantingConfigDto {
@IsBoolean()
isActive: boolean;
@IsOptional()
@IsString()
updatedBy?: string;
}
class TogglePrePlantingConfigDto {
@IsBoolean()
isActive: boolean;
}
@ApiTags('预种计划配置')
@Controller('admin/pre-planting')
export class PrePlantingConfigController {
constructor(
private readonly configService: PrePlantingConfigService,
private readonly proxyService: PrePlantingProxyService,
) {}
@Get('config')
@ApiOperation({ summary: '获取预种计划开关状态' })
@ApiResponse({ status: HttpStatus.OK, description: '开关状态' })
async getConfig() {
return this.configService.getConfig();
}
@Post('config')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: '更新预种计划开关状态' })
@ApiResponse({ status: HttpStatus.OK, description: '更新成功' })
async updateConfig(@Body() dto: UpdatePrePlantingConfigDto) {
return this.configService.updateConfig(dto.isActive, dto.updatedBy);
}
// ============================================
// [2026-02-27] 新增预种管理端点toggle + 数据查询代理)
// ============================================
@Put('config/toggle')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: '切换预种计划开关' })
@ApiResponse({ status: HttpStatus.OK, description: '切换成功' })
async toggleConfig(@Body() dto: TogglePrePlantingConfigDto) {
return this.configService.updateConfig(dto.isActive);
}
@Get('orders')
@ApiOperation({ summary: '预种订单列表(管理员视角)' })
@ApiQuery({ name: 'page', required: false })
@ApiQuery({ name: 'pageSize', required: false })
@ApiQuery({ name: 'keyword', required: false })
@ApiQuery({ name: 'status', required: false })
async getOrders(
@Query('page') page?: string,
@Query('pageSize') pageSize?: string,
@Query('keyword') keyword?: string,
@Query('status') status?: string,
) {
return this.proxyService.getOrders({
page: page ? parseInt(page, 10) : undefined,
pageSize: pageSize ? parseInt(pageSize, 10) : undefined,
keyword: keyword || undefined,
status: status || undefined,
});
}
@Get('positions')
@ApiOperation({ summary: '预种持仓列表(管理员视角)' })
@ApiQuery({ name: 'page', required: false })
@ApiQuery({ name: 'pageSize', required: false })
@ApiQuery({ name: 'keyword', required: false })
async getPositions(
@Query('page') page?: string,
@Query('pageSize') pageSize?: string,
@Query('keyword') keyword?: string,
) {
return this.proxyService.getPositions({
page: page ? parseInt(page, 10) : undefined,
pageSize: pageSize ? parseInt(pageSize, 10) : undefined,
keyword: keyword || undefined,
});
}
@Get('merges')
@ApiOperation({ summary: '预种合并记录列表(管理员视角)' })
@ApiQuery({ name: 'page', required: false })
@ApiQuery({ name: 'pageSize', required: false })
@ApiQuery({ name: 'keyword', required: false })
@ApiQuery({ name: 'status', required: false })
async getMerges(
@Query('page') page?: string,
@Query('pageSize') pageSize?: string,
@Query('keyword') keyword?: string,
@Query('status') status?: string,
) {
return this.proxyService.getMerges({
page: page ? parseInt(page, 10) : undefined,
pageSize: pageSize ? parseInt(pageSize, 10) : undefined,
keyword: keyword || undefined,
status: status || undefined,
});
}
@Get('stats')
@ApiOperation({ summary: '预种统计汇总' })
async getStats() {
return this.proxyService.getStats();
}
}
/**
* 公开 API供 planting-service 调用)
*/
@ApiTags('预种计划配置-内部API')
@Controller('api/v1/admin/pre-planting')
export class PublicPrePlantingConfigController {
constructor(
private readonly configService: PrePlantingConfigService,
) {}
@Get('config')
@ApiOperation({ summary: '获取预种计划开关状态内部API' })
async getConfig() {
return this.configService.getConfig();
}
}