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 {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user