refactor: 重构项目结构并优化代码
- 删除无用的文件和错误日志 - 创建统一的 imports 模块集中管理依赖 - 重构组件使用新的 imports 方式 - 修复文档路径大小写问题 - 优化类型定义和接口导出 - 更新依赖版本 - 改进错误处理和API配置 - 统一组件导出方式
This commit is contained in:
@@ -12,14 +12,18 @@ export class AuditController {
|
||||
static async getTimeline(req: Request, res: Response) {
|
||||
try {
|
||||
const { tenantId, shopId } = (req as any).traceContext;
|
||||
const { module, action, limit = 50, offset = 0 } = req.query;
|
||||
const { loop, stage, actor, action, limit = 50, offset = 0, startDate, endDate } = req.query;
|
||||
|
||||
const query = db('cf_operation_log')
|
||||
.where({ tenant_id: tenantId });
|
||||
|
||||
if (shopId) query.andWhere({ shop_id: shopId });
|
||||
if (module) query.andWhere({ module });
|
||||
if (loop) query.andWhere({ loop });
|
||||
if (stage) query.andWhere({ stage });
|
||||
if (actor) query.andWhere({ actor });
|
||||
if (action) query.andWhere({ action });
|
||||
if (startDate) query.andWhere('created_at', '>=', startDate);
|
||||
if (endDate) query.andWhere('created_at', '<=', endDate);
|
||||
|
||||
const logs = await query
|
||||
.orderBy('created_at', 'desc')
|
||||
|
||||
127
server/src/api/controllers/DataAbstractionController.ts
Normal file
127
server/src/api/controllers/DataAbstractionController.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
import { Request, Response } from 'express';
|
||||
import { dataAbstractionLayerService } from '../../services/DataAbstractionLayerService';
|
||||
import { dataSyncService } from '../../services/DataSyncService';
|
||||
import { actionDataService } from '../../services/ActionDataService';
|
||||
|
||||
export class DataAbstractionController {
|
||||
// 获取优先级数据
|
||||
async getPrioritizedData(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const { actionType, taskId } = req.params;
|
||||
const params = req.query;
|
||||
|
||||
if (!actionType || !taskId) {
|
||||
res.status(400).json({ error: 'actionType and taskId are required' });
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await dataAbstractionLayerService.getPrioritizedData(actionType, taskId, params as Record<string, any>);
|
||||
res.json(data);
|
||||
} catch (error) {
|
||||
console.error('Error getting prioritized data:', error);
|
||||
res.status(500).json({ error: 'Failed to get prioritized data' });
|
||||
}
|
||||
}
|
||||
|
||||
// 获取动作数据
|
||||
async getActionData(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const { actionType, taskId } = req.params;
|
||||
const { dataSource, priority, startDate, endDate } = req.query;
|
||||
|
||||
if (!actionType || !taskId) {
|
||||
res.status(400).json({ error: 'actionType and taskId are required' });
|
||||
return;
|
||||
}
|
||||
|
||||
let data;
|
||||
if (priority) {
|
||||
data = await actionDataService.getActionDataByPriority(actionType, taskId, priority as string);
|
||||
} else {
|
||||
data = await actionDataService.getActionData(actionType, taskId, dataSource as string);
|
||||
}
|
||||
|
||||
// 转换数据格式
|
||||
const formattedData = data.map(item => ({
|
||||
...item.toJSON(),
|
||||
data: JSON.parse(item.data),
|
||||
metadata: JSON.parse(item.metadata),
|
||||
}));
|
||||
|
||||
res.json(formattedData);
|
||||
} catch (error) {
|
||||
console.error('Error getting action data:', error);
|
||||
res.status(500).json({ error: 'Failed to get action data' });
|
||||
}
|
||||
}
|
||||
|
||||
// 手动触发数据同步
|
||||
async triggerSync(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const { dataSource } = req.params;
|
||||
|
||||
if (!dataSource) {
|
||||
res.status(400).json({ error: 'dataSource is required' });
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await dataSyncService.manuallyTriggerSync(dataSource);
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
console.error('Error triggering sync:', error);
|
||||
res.status(500).json({ error: 'Failed to trigger sync' });
|
||||
}
|
||||
}
|
||||
|
||||
// 获取同步状态
|
||||
async getSyncStatus(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const { dataSource } = req.query;
|
||||
|
||||
const status = await dataSyncService.getSyncStatus(dataSource as string);
|
||||
res.json(status);
|
||||
} catch (error) {
|
||||
console.error('Error getting sync status:', error);
|
||||
res.status(500).json({ error: 'Failed to get sync status' });
|
||||
}
|
||||
}
|
||||
|
||||
// 清理过期数据
|
||||
async cleanupExpiredData(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const deleted = await actionDataService.cleanupExpiredData();
|
||||
res.json({ deleted });
|
||||
} catch (error) {
|
||||
console.error('Error cleaning up expired data:', error);
|
||||
res.status(500).json({ error: 'Failed to clean up expired data' });
|
||||
}
|
||||
}
|
||||
|
||||
// 获取动作数据统计
|
||||
async getActionDataStats(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const { actionType } = req.query;
|
||||
|
||||
const stats = await actionDataService.getActionDataStats(actionType as string);
|
||||
res.json(stats);
|
||||
} catch (error) {
|
||||
console.error('Error getting action data stats:', error);
|
||||
res.status(500).json({ error: 'Failed to get action data stats' });
|
||||
}
|
||||
}
|
||||
|
||||
// 清除缓存
|
||||
async clearCache(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const { dataSource } = req.query;
|
||||
|
||||
await dataAbstractionLayerService.clearCache(dataSource as string);
|
||||
res.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('Error clearing cache:', error);
|
||||
res.status(500).json({ error: 'Failed to clear cache' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const dataAbstractionController = new DataAbstractionController();
|
||||
@@ -18,6 +18,20 @@ import { SupplyChainService } from '../../services/integration/SupplyChainServic
|
||||
import { CrawlerWorker } from '../../workers/CrawlerWorker';
|
||||
import { logger } from '../../utils/logger';
|
||||
|
||||
declare module 'express' {
|
||||
interface Request {
|
||||
traceContext?: {
|
||||
tenantId: string;
|
||||
shopId: string;
|
||||
taskId: string;
|
||||
traceId: string;
|
||||
userId: string;
|
||||
roleCode: string;
|
||||
businessType: 'TOC' | 'TOB';
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class ProductController {
|
||||
/**
|
||||
|
||||
27
server/src/api/routes/data-abstraction.ts
Normal file
27
server/src/api/routes/data-abstraction.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Router } from 'express';
|
||||
import { dataAbstractionController } from '../controllers/DataAbstractionController';
|
||||
|
||||
const router = Router();
|
||||
|
||||
// 获取优先级数据
|
||||
router.get('/prioritized-data/:actionType/:taskId', dataAbstractionController.getPrioritizedData);
|
||||
|
||||
// 获取动作数据
|
||||
router.get('/action-data/:actionType/:taskId', dataAbstractionController.getActionData);
|
||||
|
||||
// 手动触发数据同步
|
||||
router.post('/sync/:dataSource', dataAbstractionController.triggerSync);
|
||||
|
||||
// 获取同步状态
|
||||
router.get('/sync-status', dataAbstractionController.getSyncStatus);
|
||||
|
||||
// 清理过期数据
|
||||
router.delete('/cleanup-expired', dataAbstractionController.cleanupExpiredData);
|
||||
|
||||
// 获取动作数据统计
|
||||
router.get('/stats', dataAbstractionController.getActionDataStats);
|
||||
|
||||
// 清除缓存
|
||||
router.delete('/clear-cache', dataAbstractionController.clearCache);
|
||||
|
||||
export default router;
|
||||
82
server/src/api/routes/index.ts
Normal file
82
server/src/api/routes/index.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import express from 'express';
|
||||
import authRoutes from './auth';
|
||||
import productRoutes from './product';
|
||||
import orderRoutes from './order';
|
||||
import financeRoutes from './finance';
|
||||
import syncRoutes from './sync';
|
||||
// import monitoringRoutes from './monitoring';
|
||||
// import operationAgentRoutes from './operation-agent';
|
||||
// import aiSelfImprovementRoutes from './ai-self-improvement';
|
||||
// import aiBatchRoutes from './ai-batch';
|
||||
// import batchRoutes from './batch';
|
||||
import serviceManagerRoutes from './service-manager';
|
||||
import saasTenantRoutes from './saas-tenant';
|
||||
import consoleLiteRoutes from './console_lite';
|
||||
import currencyRoutes from './currency';
|
||||
import leaderboardRoutes from './leaderboard';
|
||||
import traceRoutes from './trace';
|
||||
import tradeRoutes from './trade';
|
||||
import vaultRoutes from './vault';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// 注册所有路由
|
||||
router.use('/auth', authRoutes);
|
||||
router.use('/products', productRoutes);
|
||||
router.use('/orders', orderRoutes);
|
||||
router.use('/finance', financeRoutes);
|
||||
router.use('/sync', syncRoutes);
|
||||
// router.use('/monitoring', monitoringRoutes);
|
||||
// router.use('/telemetry', telemetryRoutes);
|
||||
// router.use('/ai', aiRoutes);
|
||||
// router.use('/chatbot', chatbotRoutes);
|
||||
// router.use('/recommendation', recommendationRoutes);
|
||||
// router.use('/image-recognition', imageRecognitionRoutes);
|
||||
// router.use('/nlp', nlpRoutes);
|
||||
// router.use('/operation-agent', operationAgentRoutes);
|
||||
// router.use('/batch', batchRoutes);
|
||||
// router.use('/after-sales', afterSalesRoutes);
|
||||
// router.use('/pricing', pricingRoutes);
|
||||
// router.use('/inventory', inventoryRoutes);
|
||||
// router.use('/logistics', logisticsRoutes);
|
||||
// router.use('/risk-control', riskControlRoutes);
|
||||
// router.use('/governance', governanceRoutes);
|
||||
// router.use('/settings', settingsRoutes);
|
||||
// router.use('/tenant', tenantRoutes);
|
||||
// router.use('/webhook', webhookRoutes);
|
||||
// router.use('/command', commandRoutes);
|
||||
// router.use('/certificate', certificateRoutes);
|
||||
// router.use('/platform-auth', platformAuthRoutes);
|
||||
// router.use('/shop-report', shopReportRoutes);
|
||||
// router.use('/data-abstraction', dataAbstractionRoutes);
|
||||
// router.use('/dynamic-pricing', dynamicPricingRoutes);
|
||||
// router.use('/marketing', marketingRoutes);
|
||||
// router.use('/creative', creativeRoutes);
|
||||
// router.use('/customer', customerRoutes);
|
||||
// router.use('/billing', billingRoutes);
|
||||
// router.use('/arbitrage', arbitrageRoutes);
|
||||
// router.use('/report', reportRoutes);
|
||||
// router.use('/publish', publishRoutes);
|
||||
// router.use('/node', nodeRoutes);
|
||||
// router.use('/omnichannel', omnichannelRoutes);
|
||||
// router.use('/auto-execution', autoExecutionRoutes);
|
||||
// router.use('/autopilot', autopilotRoutes);
|
||||
// router.use('/strategy', strategyRoutes);
|
||||
// router.use('/biz', bizRoutes);
|
||||
// router.use('/ai-batch', aiBatchRoutes);
|
||||
// router.use('/ai-self-improvement', aiSelfImprovementRoutes);
|
||||
// router.use('/after-sales-decision', afterSalesDecisionRoutes);
|
||||
// router.use('/order-central', orderCentralRoutes);
|
||||
// router.use('/order-fulfillment', orderFulfillmentRoutes);
|
||||
// router.use('/smart-pricing', smartPricingRoutes);
|
||||
// router.use('/sovereignty', sovereigntyRoutes);
|
||||
router.use('/service-manager', serviceManagerRoutes);
|
||||
router.use('/saas-tenant', saasTenantRoutes);
|
||||
router.use('/console-lite', consoleLiteRoutes);
|
||||
router.use('/currency', currencyRoutes);
|
||||
router.use('/leaderboard', leaderboardRoutes);
|
||||
router.use('/trace', traceRoutes);
|
||||
router.use('/trade', tradeRoutes);
|
||||
router.use('/vault', vaultRoutes);
|
||||
|
||||
export default router;
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Router } from 'express';
|
||||
import { ReputationZKPService } from '../../core/ai/ReputationZKPService';
|
||||
import { BehavioralRiskService } from '../../core/governance/BehavioralRiskService';
|
||||
import { BehavioralRiskService } from '../../services/security/BehavioralRiskService';
|
||||
import { requirePermission } from '../../core/guards/rbac.guard';
|
||||
import { requireTraceContext } from '../../core/guards/trace-context.guard';
|
||||
import { DIDHandshakeService } from '../../core/security/DIDHandshakeService';
|
||||
|
||||
Reference in New Issue
Block a user