feat: 实现Operation-Agent核心功能及电商平台适配器
refactor: 重构项目结构,分离server和dashboard代码 style: 统一代码风格,修复lint警告 test: 添加平台适配器工厂测试用例 ci: 更新CI/CD流程,增加语义验证和性能测试 docs: 添加语义中心文档,定义统一数据模型和状态机
This commit is contained in:
61
server/src/api/controllers/AISelfImprovementController.ts
Normal file
61
server/src/api/controllers/AISelfImprovementController.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { Controller, Get, Put, Param, UseGuards } from '@nestjs/common';
|
||||
import { AISelfImprovementService } from '../../core/ai/AISelfImprovementService';
|
||||
import { RbacGuard } from '../../core/guards/rbac.guard';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('AI Self-Improvement')
|
||||
@ApiBearerAuth()
|
||||
@Controller('api/ai/self-improvement')
|
||||
export class AISelfImprovementController {
|
||||
constructor(private aiSelfImprovementService: AISelfImprovementService) {}
|
||||
|
||||
/**
|
||||
* 生成改进建议
|
||||
*/
|
||||
@Get('suggestions/generate')
|
||||
@UseGuards(RbacGuard)
|
||||
async generateSuggestions() {
|
||||
const suggestions = await this.aiSelfImprovementService.generateImprovementSuggestions();
|
||||
return { success: true, suggestions };
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有改进建议
|
||||
*/
|
||||
@Get('suggestions')
|
||||
@UseGuards(RbacGuard)
|
||||
async getSuggestions() {
|
||||
const suggestions = await this.aiSelfImprovementService.getImprovementSuggestions();
|
||||
return { success: true, suggestions };
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新建议状态
|
||||
*/
|
||||
@Put('suggestions/:id/status')
|
||||
@UseGuards(RbacGuard)
|
||||
async updateSuggestionStatus(@Param('id') id: string, @Param('status') status: 'implemented' | 'dismissed') {
|
||||
const result = await this.aiSelfImprovementService.updateSuggestionStatus(id, status);
|
||||
return { success: result };
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动应用改进建议
|
||||
*/
|
||||
@Get('suggestions/apply')
|
||||
@UseGuards(RbacGuard)
|
||||
async applySuggestions() {
|
||||
const result = await this.aiSelfImprovementService.applyImprovementSuggestions();
|
||||
return { success: true, ...result };
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行定期优化
|
||||
*/
|
||||
@Get('optimize')
|
||||
@UseGuards(RbacGuard)
|
||||
async performOptimization() {
|
||||
await this.aiSelfImprovementService.performRegularOptimization();
|
||||
return { success: true, message: '定期优化执行完成' };
|
||||
}
|
||||
}
|
||||
30
server/src/api/controllers/MonitoringController.ts
Normal file
30
server/src/api/controllers/MonitoringController.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { MonitoringService } from '../../core/monitoring/MonitoringService';
|
||||
import { RbacGuard } from '../../core/guards/rbac.guard';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Monitoring')
|
||||
@ApiBearerAuth()
|
||||
@Controller('api/monitoring')
|
||||
export class MonitoringController {
|
||||
constructor(private monitoringService: MonitoringService) {}
|
||||
|
||||
/**
|
||||
* 获取当前监控指标
|
||||
*/
|
||||
@Get('metrics')
|
||||
@UseGuards(RbacGuard)
|
||||
async getMetrics() {
|
||||
return this.monitoringService.getMetrics();
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动收集和记录指标
|
||||
*/
|
||||
@Get('collect')
|
||||
@UseGuards(RbacGuard)
|
||||
async collectMetrics() {
|
||||
await this.monitoringService.collectAndRecordMetrics();
|
||||
return { success: true, message: '指标收集成功' };
|
||||
}
|
||||
}
|
||||
89
server/src/api/controllers/OperationAgentController.ts
Normal file
89
server/src/api/controllers/OperationAgentController.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { Controller, Post, Get, Put, Delete, Param, Body, UseGuards } from '@nestjs/common';
|
||||
import { OperationAgentService } from '../../core/operation/OperationAgentService';
|
||||
import { StoreBindingDto } from '../dto/StoreBindingDto';
|
||||
import { Store } from '../../entities/Store';
|
||||
import { RbacGuard } from '../../core/guards/rbac.guard';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Operation-Agent')
|
||||
@ApiBearerAuth()
|
||||
@Controller('api/operation-agent')
|
||||
export class OperationAgentController {
|
||||
constructor(private operationAgentService: OperationAgentService) {}
|
||||
|
||||
/**
|
||||
* 绑定店铺
|
||||
*/
|
||||
@Post('stores')
|
||||
@UseGuards(RbacGuard)
|
||||
async bindStore(@Body() dto: StoreBindingDto): Promise<Store> {
|
||||
return this.operationAgentService.bindStore(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商户的店铺列表
|
||||
*/
|
||||
@Get('stores/:merchantId')
|
||||
@UseGuards(RbacGuard)
|
||||
async getStores(@Param('merchantId') merchantId: string): Promise<Store[]> {
|
||||
return this.operationAgentService.getStores(merchantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺详情
|
||||
*/
|
||||
@Get('stores/detail/:storeId')
|
||||
@UseGuards(RbacGuard)
|
||||
async getStore(@Param('storeId') storeId: string): Promise<Store> {
|
||||
return this.operationAgentService.getStore(storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步店铺商品
|
||||
*/
|
||||
@Post('stores/:storeId/products/sync')
|
||||
@UseGuards(RbacGuard)
|
||||
async syncProducts(@Param('storeId') storeId: string): Promise<{ success: boolean; count: number }> {
|
||||
return this.operationAgentService.syncProducts(storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步店铺订单
|
||||
*/
|
||||
@Post('stores/:storeId/orders/sync')
|
||||
@UseGuards(RbacGuard)
|
||||
async syncOrders(@Param('storeId') storeId: string): Promise<{ success: boolean; count: number }> {
|
||||
return this.operationAgentService.syncOrders(storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品价格
|
||||
*/
|
||||
@Put('stores/:storeId/products/:productId/price')
|
||||
@UseGuards(RbacGuard)
|
||||
async updateProductPrice(
|
||||
@Param('storeId') storeId: string,
|
||||
@Param('productId') productId: string,
|
||||
@Body('price') price: number
|
||||
): Promise<boolean> {
|
||||
return this.operationAgentService.updateProductPrice(storeId, productId, price);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停用店铺
|
||||
*/
|
||||
@Put('stores/:storeId/deactivate')
|
||||
@UseGuards(RbacGuard)
|
||||
async deactivateStore(@Param('storeId') storeId: string): Promise<Store> {
|
||||
return this.operationAgentService.deactivateStore(storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新激活店铺
|
||||
*/
|
||||
@Put('stores/:storeId/reactivate')
|
||||
@UseGuards(RbacGuard)
|
||||
async reactivateStore(@Param('storeId') storeId: string): Promise<Store> {
|
||||
return this.operationAgentService.reactivateStore(storeId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user