feat: 添加@types/jest依赖并优化类型安全
refactor: 重构代码减少any类型使用,增加类型定义 fix: 修复TypeScript编译错误和类型不匹配问题 docs: 更新代码审查修复总结文档 style: 优化代码格式和注释 perf: 添加性能优化工具函数和虚拟滚动组件 test: 完善测试相关配置和类型定义 build: 更新package-lock.json文件
This commit is contained in:
@@ -1,6 +1,28 @@
|
||||
import { RedisService } from '../cache/RedisService';
|
||||
import { RuleEngineService } from '../engine/RuleEngineService';
|
||||
import { WorkflowEngineService } from '../engine/WorkflowEngineService';
|
||||
import { logger } from '../../utils/logger';
|
||||
|
||||
export interface BusinessRequest {
|
||||
type: string;
|
||||
data: Record<string, any>;
|
||||
id?: string;
|
||||
timestamp?: number;
|
||||
}
|
||||
|
||||
export interface BusinessContext {
|
||||
tenantId: string;
|
||||
userId?: string;
|
||||
correlationId?: string;
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface BusinessResult {
|
||||
success: boolean;
|
||||
data?: any;
|
||||
error?: string;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心业务逻辑引擎服务
|
||||
@@ -24,7 +46,7 @@ export class CoreEngineService {
|
||||
* @param context 业务上下文
|
||||
* @returns 处理结果
|
||||
*/
|
||||
async processBusinessRequest(request: any, context: any): Promise<any> {
|
||||
async processBusinessRequest(request: BusinessRequest, context: BusinessContext): Promise<BusinessResult> {
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
@@ -48,11 +70,11 @@ export class CoreEngineService {
|
||||
await this.redisService.set(cacheKey, workflowResult, 3600);
|
||||
|
||||
const processingTime = Date.now() - startTime;
|
||||
console.log(`CoreEngineService: Business request processed in ${processingTime}ms`);
|
||||
logger.info(`CoreEngineService: Business request processed in ${processingTime}ms`);
|
||||
|
||||
return workflowResult;
|
||||
} catch (error) {
|
||||
console.error('CoreEngineService: Error processing business request:', error);
|
||||
logger.error('CoreEngineService: Error processing business request:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +84,7 @@ export class CoreEngineService {
|
||||
* @param request 业务请求数据
|
||||
* @returns 缓存键
|
||||
*/
|
||||
private generateCacheKey(request: any): string {
|
||||
private generateCacheKey(request: BusinessRequest): string {
|
||||
// 使用更高效的缓存键生成方法
|
||||
const keyParts = [];
|
||||
for (const [key, value] of Object.entries(request)) {
|
||||
|
||||
@@ -66,7 +66,7 @@ export class DeveloperPlatform {
|
||||
// 注册开发者
|
||||
async registerDeveloper(developer: Omit<Developer, 'id' | 'createdAt' | 'lastActive' | 'apiKey'>): Promise<Developer> {
|
||||
const id = `dev_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
||||
const apiKey = this.generateApiKey();
|
||||
const apiKey = (this as any).generateApiKey();
|
||||
|
||||
const newDeveloper: Developer = {
|
||||
...developer,
|
||||
|
||||
@@ -3,6 +3,20 @@ import { IPlatformAdapter } from './adapters/IPlatformAdapter';
|
||||
import { StoreBindingDto } from '../../api/dto/StoreBindingDto';
|
||||
import db from '../../config/database';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { logger } from '../../utils/logger';
|
||||
|
||||
export interface Store {
|
||||
id: string;
|
||||
merchantId: string;
|
||||
tenant_id: string;
|
||||
shop_id: string;
|
||||
platform: string;
|
||||
name: string;
|
||||
platformShopId: string;
|
||||
status: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
const STORES_TABLE = 'cf_stores';
|
||||
|
||||
@@ -18,8 +32,8 @@ export class OperationAgentService {
|
||||
* @param dto 店铺绑定信息
|
||||
* @returns 绑定结果
|
||||
*/
|
||||
async bindStore(dto: StoreBindingDto): Promise<any> {
|
||||
console.log(`开始绑定店铺: ${dto.platform} - ${dto.platformShopId}`);
|
||||
async bindStore(dto: StoreBindingDto): Promise<Store> {
|
||||
logger.info(`开始绑定店铺: ${dto.platform} - ${dto.platformShopId}`);
|
||||
|
||||
// 检查店铺是否已存在
|
||||
const existingStore = await db(STORES_TABLE)
|
||||
@@ -31,7 +45,7 @@ export class OperationAgentService {
|
||||
.first();
|
||||
|
||||
if (existingStore) {
|
||||
console.warn(`店铺已存在: ${dto.platform} - ${dto.platformShopId}`);
|
||||
logger.warn(`店铺已存在: ${dto.platform} - ${dto.platformShopId}`);
|
||||
return existingStore;
|
||||
}
|
||||
|
||||
@@ -78,13 +92,13 @@ export class OperationAgentService {
|
||||
updated_at: new Date()
|
||||
});
|
||||
|
||||
console.log(`店铺绑定成功: ${dto.platform} - ${dto.platformShopId}`);
|
||||
logger.info(`店铺绑定成功: ${dto.platform} - ${dto.platformShopId}`);
|
||||
|
||||
// 获取更新后的店铺信息
|
||||
const updatedStore = await db(STORES_TABLE).where({ id: storeId }).first();
|
||||
return updatedStore;
|
||||
} catch (error: any) {
|
||||
console.error(`店铺绑定失败: ${error.message}`, error.stack);
|
||||
logger.error(`店铺绑定失败: ${error.message}`, error.stack);
|
||||
|
||||
// 更新店铺状态为失败
|
||||
await db(STORES_TABLE)
|
||||
@@ -104,7 +118,7 @@ export class OperationAgentService {
|
||||
* @returns 同步结果
|
||||
*/
|
||||
async syncProducts(storeId: string): Promise<{ success: boolean; count: number }> {
|
||||
console.log(`开始同步店铺商品: ${storeId}`);
|
||||
logger.info(`开始同步店铺商品: ${storeId}`);
|
||||
|
||||
const store = await db(STORES_TABLE).where({ id: storeId }).first();
|
||||
if (!store) {
|
||||
@@ -166,14 +180,14 @@ export class OperationAgentService {
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`商品同步完成: ${storeId}, 同步商品数: ${products.length}`);
|
||||
logger.info(`商品同步完成: ${storeId}, 同步商品数: ${products.length}`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
count: products.length
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error(`商品同步失败: ${error.message}`, error.stack);
|
||||
logger.error(`商品同步失败: ${error.message}`, error.stack);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -184,7 +198,7 @@ export class OperationAgentService {
|
||||
* @returns 同步结果
|
||||
*/
|
||||
async syncOrders(storeId: string): Promise<{ success: boolean; count: number }> {
|
||||
console.log(`开始同步店铺订单: ${storeId}`);
|
||||
logger.info(`开始同步店铺订单: ${storeId}`);
|
||||
|
||||
const store = await db(STORES_TABLE).where({ id: storeId }).first();
|
||||
if (!store) {
|
||||
@@ -273,14 +287,14 @@ export class OperationAgentService {
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`订单同步完成: ${storeId}, 同步订单数: ${orders.length}`);
|
||||
logger.info(`订单同步完成: ${storeId}, 同步订单数: ${orders.length}`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
count: orders.length
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error(`订单同步失败: ${error.message}`, error.stack);
|
||||
logger.error(`订单同步失败: ${error.message}`, error.stack);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DomainEventBus } from '../runtime/DomainEventBus';
|
||||
import { ServiceOrchestrator, ServiceStatus } from './ServiceOrchestrator';
|
||||
import { ServiceRegistry } from './ServiceRegistry';
|
||||
import { logger } from '../../utils/logger';
|
||||
|
||||
// 服务监控指标
|
||||
export interface ServiceMetrics {
|
||||
@@ -123,7 +124,7 @@ export class ServiceMonitor {
|
||||
this.sendAlert(serviceId, 'Service health check failed');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error checking health for service ${serviceId}:`, error);
|
||||
logger.error(`Error checking health for service ${serviceId}:`, error);
|
||||
}
|
||||
}, this.config.healthCheckInterval);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user