refactor(types): 重构类型系统,统一共享类型定义

feat(types): 新增共享类型中心,包含用户、产品、订单等核心领域类型
fix(types): 修复类型定义错误,统一各模块类型引用
style(types): 优化类型文件格式和注释
docs(types): 更新类型文档和变更日志
test(types): 添加类型测试用例
build(types): 配置类型共享路径
chore(types): 清理重复类型定义文件
This commit is contained in:
2026-03-20 17:53:46 +08:00
parent 989c4b13a6
commit 427becbc8f
222 changed files with 25676 additions and 6328 deletions

View File

@@ -1,12 +1,12 @@
import { Request, Response } from 'express';
import { WinNodeService } from '../services/WinNodeService';
import { TaskCenterService } from '../services/TaskCenterService';
import { IndependentSiteService } from '../services/IndependentSiteService';
import { CostTemplateService } from '../services/CostTemplateService';
import { PlatformAccountService } from '../services/PlatformAccountService';
import { ReturnService } from '../services/ReturnService';
import { AuditService } from '../services/AuditService';
import { logger } from '../utils/logger';
import { WinNodeService } from '../../services/WinNodeService';
import { TaskCenterService } from '../../services/TaskCenterService';
import { IndependentSiteService } from '../../services/IndependentSiteService';
import { CostTemplateService } from '../../services/CostTemplateService';
import { PlatformAccountService } from '../../services/PlatformAccountService';
import { ReturnService } from '../../services/ReturnService';
import { AuditService } from '../../services/AuditService';
import { logger } from '../../utils/logger';
export class WinNodeController {
static async list(req: Request, res: Response) {
@@ -14,7 +14,10 @@ export class WinNodeController {
const { tenantId } = (req as any).traceContext;
try {
const nodes = await WinNodeService.list(tenantId, { status: status as string, shopId: shopId as string });
const statusStr = Array.isArray(status) ? status[0] : status;
const shopIdStr = Array.isArray(shopId) ? shopId[0] : shopId;
const nodes = await WinNodeService.list(tenantId, { status: statusStr as string, shopId: shopIdStr as string });
res.json({ success: true, data: nodes });
} catch (err: any) {
logger.error(`[WinNodeController] List failed: ${err.message}`);
@@ -23,7 +26,7 @@ export class WinNodeController {
}
static async getById(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const node = await WinNodeService.getById(id);
@@ -64,7 +67,7 @@ export class WinNodeController {
}
static async update(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
const { tenantId, userId, traceId } = (req as any).traceContext;
try {
@@ -90,7 +93,7 @@ export class WinNodeController {
}
static async delete(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
const { tenantId, userId, traceId } = (req as any).traceContext;
try {
@@ -116,7 +119,7 @@ export class WinNodeController {
}
static async testConnection(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const result = await WinNodeService.testConnection(id);
@@ -128,7 +131,7 @@ export class WinNodeController {
}
static async restart(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const result = await WinNodeService.restart(id);
@@ -140,7 +143,7 @@ export class WinNodeController {
}
static async heartbeat(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
await WinNodeService.heartbeat(id, req.body);
@@ -170,10 +173,14 @@ export class TaskCenterController {
const { tenantId } = (req as any).traceContext;
try {
const statusStr = Array.isArray(status) ? status[0] : status;
const taskTypeStr = Array.isArray(taskType) ? taskType[0] : taskType;
const shopIdStr = Array.isArray(shopId) ? shopId[0] : shopId;
const tasks = await TaskCenterService.list(tenantId, {
status: status as string,
taskType: taskType as string,
shopId: shopId as string,
status: statusStr as string,
taskType: taskTypeStr as string,
shopId: shopIdStr as string,
});
res.json({ success: true, data: tasks });
} catch (err: any) {
@@ -183,7 +190,7 @@ export class TaskCenterController {
}
static async getById(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const task = await TaskCenterService.getById(id);
@@ -224,7 +231,7 @@ export class TaskCenterController {
}
static async updateStatus(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
const { status, progress, output, error } = req.body;
try {
@@ -237,7 +244,7 @@ export class TaskCenterController {
}
static async cancel(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
await TaskCenterService.cancel(id);
@@ -249,7 +256,7 @@ export class TaskCenterController {
}
static async retry(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const task = await TaskCenterService.retry(id);
@@ -287,7 +294,7 @@ export class IndependentSiteController {
}
static async getSiteById(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const site = await IndependentSiteService.getSiteById(id);
@@ -328,7 +335,7 @@ export class IndependentSiteController {
}
static async updateSite(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
const { tenantId, userId, traceId } = (req as any).traceContext;
try {
@@ -354,7 +361,7 @@ export class IndependentSiteController {
}
static async deleteSite(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
const { tenantId, userId, traceId } = (req as any).traceContext;
try {
@@ -380,7 +387,7 @@ export class IndependentSiteController {
}
static async syncProducts(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
const { productIds } = req.body;
try {
@@ -393,7 +400,7 @@ export class IndependentSiteController {
}
static async getSiteProducts(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const products = await IndependentSiteService.getSiteProducts(id);
@@ -405,11 +412,12 @@ export class IndependentSiteController {
}
static async getSiteOrders(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
const { status } = req.query;
try {
const orders = await IndependentSiteService.getSiteOrders(id, { status: status as string });
const statusStr = Array.isArray(status) ? status[0] : status;
const orders = await IndependentSiteService.getSiteOrders(id, { status: statusStr as string });
res.json({ success: true, data: orders });
} catch (err: any) {
logger.error(`[IndependentSiteController] Get orders failed: ${err.message}`);
@@ -418,13 +426,16 @@ export class IndependentSiteController {
}
static async getSiteAnalytics(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
const { start, end } = req.query;
try {
const startStr = Array.isArray(start) ? start[0] : start;
const endStr = Array.isArray(end) ? end[0] : end;
const analytics = await IndependentSiteService.getSiteAnalytics(id, {
start: start as string,
end: end as string,
start: startStr as string,
end: endStr as string,
});
res.json({ success: true, data: analytics });
} catch (err: any) {
@@ -440,9 +451,12 @@ export class CostTemplateController {
const { tenantId } = (req as any).traceContext;
try {
const platformStr = Array.isArray(platform) ? platform[0] : platform;
const categoryStr = Array.isArray(category) ? category[0] : category;
const templates = await CostTemplateService.list(tenantId, {
platform: platform as string,
category: category as string,
platform: platformStr as string,
category: categoryStr as string,
});
res.json({ success: true, data: templates });
} catch (err: any) {
@@ -452,7 +466,7 @@ export class CostTemplateController {
}
static async getById(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const template = await CostTemplateService.getById(id);
@@ -493,7 +507,7 @@ export class CostTemplateController {
}
static async update(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const template = await CostTemplateService.update(id, req.body);
@@ -505,7 +519,7 @@ export class CostTemplateController {
}
static async delete(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
await CostTemplateService.delete(id);
@@ -517,7 +531,7 @@ export class CostTemplateController {
}
static async duplicate(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const template = await CostTemplateService.duplicate(id);
@@ -529,7 +543,7 @@ export class CostTemplateController {
}
static async calculateCost(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
const { basePrice, quantity } = req.body;
try {
@@ -548,10 +562,14 @@ export class PlatformAccountController {
const { tenantId } = (req as any).traceContext;
try {
const platformStr = Array.isArray(platform) ? platform[0] : platform;
const statusStr = Array.isArray(status) ? status[0] : status;
const shopIdStr = Array.isArray(shopId) ? shopId[0] : shopId;
const accounts = await PlatformAccountService.list(tenantId, {
platform: platform as string,
status: status as string,
shopId: shopId as string,
platform: platformStr as string,
status: statusStr as string,
shopId: shopIdStr as string,
});
res.json({ success: true, data: accounts });
} catch (err: any) {
@@ -561,7 +579,7 @@ export class PlatformAccountController {
}
static async getById(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const account = await PlatformAccountService.getById(id);
@@ -602,7 +620,7 @@ export class PlatformAccountController {
}
static async update(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const account = await PlatformAccountService.update(id, req.body);
@@ -614,7 +632,7 @@ export class PlatformAccountController {
}
static async delete(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
await PlatformAccountService.delete(id);
@@ -626,7 +644,7 @@ export class PlatformAccountController {
}
static async refreshToken(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const result = await PlatformAccountService.refreshToken(id);
@@ -638,7 +656,7 @@ export class PlatformAccountController {
}
static async testConnection(req: Request, res: Response) {
const { id } = req.params;
const id = req.params.id as string;
try {
const result = await PlatformAccountService.testConnection(id);
@@ -680,9 +698,12 @@ export class ReturnController {
const { tenantId } = (req as any).traceContext;
try {
const statusStr = Array.isArray(status) ? status[0] : status;
const shopIdStr = Array.isArray(shopId) ? shopId[0] : shopId;
const data = await ReturnService.fetchSKUData(tenantId, {
status: status as string,
shopId: shopId as string,
status: statusStr as string,
shopId: shopIdStr as string,
});
res.json({ success: true, data });
} catch (err: any) {
@@ -709,10 +730,14 @@ export class ReturnController {
const { tenantId } = (req as any).traceContext;
try {
const statusStr = Array.isArray(status) ? status[0] : status;
const shopIdStr = Array.isArray(shopId) ? shopId[0] : shopId;
const skuIdStr = Array.isArray(skuId) ? skuId[0] : skuId;
const data = await ReturnService.fetchReturns(tenantId, {
status: status as string,
shopId: shopId as string,
skuId: skuId as string,
status: statusStr as string,
shopId: shopIdStr as string,
skuId: skuIdStr as string,
});
res.json({ success: true, data });
} catch (err: any) {
@@ -764,10 +789,14 @@ export class ReturnController {
const { tenantId } = (req as any).traceContext;
try {
const shopIdStr = Array.isArray(shopId) ? shopId[0] : shopId;
const startDateStr = Array.isArray(startDate) ? startDate[0] : startDate;
const endDateStr = Array.isArray(endDate) ? endDate[0] : endDate;
const trend = await ReturnService.getReturnTrend(tenantId, {
shopId: shopId as string,
startDate: startDate as string,
endDate: endDate as string,
shopId: shopIdStr as string,
startDate: startDateStr as string,
endDate: endDateStr as string,
});
res.json({ success: true, data: trend });
} catch (err: any) {
@@ -781,7 +810,9 @@ export class ReturnController {
const { tenantId } = (req as any).traceContext;
try {
const stats = await ReturnService.getReturnStats(tenantId, { shopId: shopId as string });
const shopIdStr = Array.isArray(shopId) ? shopId[0] : shopId;
const stats = await ReturnService.getReturnStats(tenantId, { shopId: shopIdStr as string });
res.json({ success: true, data: stats });
} catch (err: any) {
logger.error(`[ReturnController] Get stats failed: ${err.message}`);