|
|
@@ -12,6 +12,8 @@ import { FeieApiConfig } from '../types/feie.types';
|
|
|
*/
|
|
|
async function getFeieApiConfig(tenantId: number, dataSource: DataSource): Promise<FeieApiConfig | null> {
|
|
|
try {
|
|
|
+ console.debug(`开始获取租户 ${tenantId} 的飞鹅API配置`);
|
|
|
+
|
|
|
// 从 system_config_mt 表获取飞鹅API配置
|
|
|
const configKeys = [
|
|
|
'feie.api.user', // 飞鹅API用户
|
|
|
@@ -23,6 +25,8 @@ async function getFeieApiConfig(tenantId: number, dataSource: DataSource): Promi
|
|
|
|
|
|
// 直接查询数据库
|
|
|
const configRepository = dataSource.getRepository('system_config_mt');
|
|
|
+ console.debug(`查询数据库,租户ID: ${tenantId}, 配置键: ${configKeys.join(', ')}`);
|
|
|
+
|
|
|
const configs = await configRepository.find({
|
|
|
where: {
|
|
|
tenantId,
|
|
|
@@ -30,10 +34,13 @@ async function getFeieApiConfig(tenantId: number, dataSource: DataSource): Promi
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ console.debug(`找到 ${configs.length} 条配置记录`);
|
|
|
+
|
|
|
// 转换为键值对
|
|
|
const configMap: Record<string, string> = {};
|
|
|
configs.forEach((config: any) => {
|
|
|
configMap[config.configKey] = config.configValue;
|
|
|
+ console.debug(`配置键: ${config.configKey}, 值: ${config.configValue}`);
|
|
|
});
|
|
|
|
|
|
// 检查必要的配置项
|
|
|
@@ -42,17 +49,21 @@ async function getFeieApiConfig(tenantId: number, dataSource: DataSource): Promi
|
|
|
|
|
|
if (!user || !ukey) {
|
|
|
console.warn(`[租户${tenantId}] 飞鹅API配置不完整,缺少user或ukey`);
|
|
|
+ console.debug(`当前配置映射:`, JSON.stringify(configMap, null, 2));
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
// 返回配置结构
|
|
|
- return {
|
|
|
+ const feieConfig = {
|
|
|
user,
|
|
|
ukey,
|
|
|
- baseUrl: configMap['feie.api.base_url'] || 'http://api.feieyun.cn/Api/Open/',
|
|
|
+ baseUrl: configMap['feie.api.base_url'] || 'https://api.feieyun.cn/Api/Open/',
|
|
|
timeout: parseInt(configMap['feie.api.timeout'] || '10000', 10),
|
|
|
maxRetries: parseInt(configMap['feie.api.max_retries'] || '3', 10)
|
|
|
};
|
|
|
+
|
|
|
+ console.debug(`租户 ${tenantId} 的飞鹅API配置获取成功:`, JSON.stringify(feieConfig, null, 2));
|
|
|
+ return feieConfig;
|
|
|
} catch (error) {
|
|
|
console.warn(`[租户${tenantId}] 获取飞鹅API配置失败:`, error);
|
|
|
return null;
|
|
|
@@ -63,22 +74,8 @@ export function createFeieRoutes(dataSource: DataSource) {
|
|
|
const app = new OpenAPIHono<AuthContext>();
|
|
|
|
|
|
// 初始化服务(使用空配置,实际配置在路由处理中动态获取)
|
|
|
- const printerService = new PrinterService(dataSource, {
|
|
|
- baseUrl: 'http://api.feieyun.cn/Api/Open/',
|
|
|
- user: '',
|
|
|
- ukey: '',
|
|
|
- timeout: 10000,
|
|
|
- maxRetries: 3
|
|
|
- });
|
|
|
const printTaskService = new PrintTaskService(dataSource, {
|
|
|
- baseUrl: 'http://api.feieyun.cn/Api/Open/',
|
|
|
- user: '',
|
|
|
- ukey: '',
|
|
|
- timeout: 10000,
|
|
|
- maxRetries: 3
|
|
|
- });
|
|
|
- const delaySchedulerService = new DelaySchedulerService(dataSource, {
|
|
|
- baseUrl: 'http://api.feieyun.cn/Api/Open/',
|
|
|
+ baseUrl: 'https://api.feieyun.cn/Api/Open/',
|
|
|
user: '',
|
|
|
ukey: '',
|
|
|
timeout: 10000,
|
|
|
@@ -89,34 +86,116 @@ export function createFeieRoutes(dataSource: DataSource) {
|
|
|
// 打印机管理路由
|
|
|
app.get('/printers', async (c) => {
|
|
|
const user = c.get('user');
|
|
|
+ console.debug('获取打印机列表 - 用户对象:', JSON.stringify(user, null, 2));
|
|
|
const tenantId = user?.tenantId || 1; // 从认证中间件获取
|
|
|
+ console.debug(`获取打印机列表 - 租户ID: ${tenantId}`);
|
|
|
+
|
|
|
+ // 获取查询参数
|
|
|
+ const query = c.req.query();
|
|
|
+ const page = query.page ? parseInt(query.page, 10) : 1;
|
|
|
+ const pageSize = query.pageSize ? parseInt(query.pageSize, 10) : 10;
|
|
|
+ const search = query.search;
|
|
|
+ const status = query.status as any;
|
|
|
+ const printerType = query.printerType as any;
|
|
|
+ const isDefault = query.isDefault === 'true';
|
|
|
|
|
|
// 获取飞鹅API配置
|
|
|
const feieConfig = await getFeieApiConfig(tenantId, dataSource);
|
|
|
if (!feieConfig) {
|
|
|
+ console.error(`租户 ${tenantId} 的飞鹅API配置未找到或配置不完整`);
|
|
|
return c.json({ success: false, message: '飞鹅API配置未找到或配置不完整' }, 400);
|
|
|
}
|
|
|
|
|
|
+ console.debug(`租户 ${tenantId} 的飞鹅API配置获取成功`);
|
|
|
+
|
|
|
// 创建带配置的服务实例
|
|
|
const tenantPrinterService = new PrinterService(dataSource, feieConfig);
|
|
|
const printers = await tenantPrinterService.getPrinters(tenantId);
|
|
|
- return c.json({ success: true, data: printers });
|
|
|
+
|
|
|
+ // 应用筛选逻辑
|
|
|
+ let filteredPrinters = printers;
|
|
|
+
|
|
|
+ // 搜索筛选
|
|
|
+ if (search) {
|
|
|
+ filteredPrinters = filteredPrinters.filter(p =>
|
|
|
+ (p.printerName && p.printerName.includes(search)) ||
|
|
|
+ p.printerSn.includes(search)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // 状态筛选
|
|
|
+ if (status && status !== 'ALL') {
|
|
|
+ filteredPrinters = filteredPrinters.filter(p => p.printerStatus === status);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 类型筛选
|
|
|
+ if (printerType && printerType !== 'ALL') {
|
|
|
+ filteredPrinters = filteredPrinters.filter(p => p.printerType === printerType);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 默认打印机筛选
|
|
|
+ if (isDefault) {
|
|
|
+ filteredPrinters = filteredPrinters.filter(p => p.isDefault === 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分页逻辑
|
|
|
+ const total = filteredPrinters.length;
|
|
|
+ const startIndex = (page - 1) * pageSize;
|
|
|
+ const endIndex = Math.min(startIndex + pageSize, total);
|
|
|
+ const paginatedPrinters = filteredPrinters.slice(startIndex, endIndex);
|
|
|
+
|
|
|
+ console.debug(`返回打印机列表,总数: ${total}, 分页: ${page}/${Math.ceil(total/pageSize)}, 数量: ${paginatedPrinters.length}`);
|
|
|
+
|
|
|
+ return c.json({
|
|
|
+ success: true,
|
|
|
+ data: {
|
|
|
+ data: paginatedPrinters,
|
|
|
+ total,
|
|
|
+ page,
|
|
|
+ pageSize
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
app.post('/printers', async (c) => {
|
|
|
const user = c.get('user');
|
|
|
const tenantId = user?.tenantId || 1;
|
|
|
- const body = await c.req.json();
|
|
|
- const printer = await printerService.addPrinter(tenantId, body);
|
|
|
- return c.json({ success: true, data: printer });
|
|
|
+
|
|
|
+ try {
|
|
|
+ const body = await c.req.json();
|
|
|
+
|
|
|
+ // 获取飞鹅API配置
|
|
|
+ const feieConfig = await getFeieApiConfig(tenantId, dataSource);
|
|
|
+ if (!feieConfig) {
|
|
|
+ return c.json({ success: false, message: '飞鹅API配置未找到或配置不完整' }, 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建带配置的服务实例
|
|
|
+ const tenantPrinterService = new PrinterService(dataSource, feieConfig);
|
|
|
+ const printer = await tenantPrinterService.addPrinter(tenantId, body);
|
|
|
+ return c.json({ success: true, data: printer });
|
|
|
+ } catch (error) {
|
|
|
+ console.error(`[租户${tenantId}] 添加打印机失败:`, error);
|
|
|
+ const errorMessage = error instanceof Error ? error.message : '添加打印机失败';
|
|
|
+ return c.json({ success: false, message: errorMessage }, 500);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
app.get('/printers/:printerSn', async (c) => {
|
|
|
const user = c.get('user');
|
|
|
const tenantId = user?.tenantId || 1;
|
|
|
const printerSn = c.req.param('printerSn');
|
|
|
- const printer = await (printerService as any).findOne({
|
|
|
- where: { tenantId, printerSn }
|
|
|
+
|
|
|
+ // 获取飞鹅API配置
|
|
|
+ const feieConfig = await getFeieApiConfig(tenantId, dataSource);
|
|
|
+ if (!feieConfig) {
|
|
|
+ return c.json({ success: false, message: '飞鹅API配置未找到或配置不完整' }, 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建带配置的服务实例
|
|
|
+ const tenantPrinterService = new PrinterService(dataSource, feieConfig);
|
|
|
+ const printer = await tenantPrinterService.repository.findOne({
|
|
|
+ where: { tenantId, printerSn } as any
|
|
|
});
|
|
|
|
|
|
if (!printer) {
|
|
|
@@ -130,69 +209,170 @@ export function createFeieRoutes(dataSource: DataSource) {
|
|
|
const user = c.get('user');
|
|
|
const tenantId = user?.tenantId || 1;
|
|
|
const printerSn = c.req.param('printerSn');
|
|
|
- const body = await c.req.json();
|
|
|
- const printer = await printerService.updatePrinter(tenantId, printerSn, body);
|
|
|
- return c.json({ success: true, data: printer });
|
|
|
+
|
|
|
+ try {
|
|
|
+ const body = await c.req.json();
|
|
|
+
|
|
|
+ // 获取飞鹅API配置
|
|
|
+ const feieConfig = await getFeieApiConfig(tenantId, dataSource);
|
|
|
+ if (!feieConfig) {
|
|
|
+ return c.json({ success: false, message: '飞鹅API配置未找到或配置不完整' }, 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建带配置的服务实例
|
|
|
+ const tenantPrinterService = new PrinterService(dataSource, feieConfig);
|
|
|
+ const printer = await tenantPrinterService.updatePrinter(tenantId, printerSn, body);
|
|
|
+ return c.json({ success: true, data: printer });
|
|
|
+ } catch (error) {
|
|
|
+ console.error(`[租户${tenantId}] 更新打印机失败,打印机SN: ${printerSn}:`, error);
|
|
|
+ const errorMessage = error instanceof Error ? error.message : '更新打印机失败';
|
|
|
+ return c.json({ success: false, message: errorMessage }, 500);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
app.delete('/printers/:printerSn', async (c) => {
|
|
|
const user = c.get('user');
|
|
|
const tenantId = user?.tenantId || 1;
|
|
|
const printerSn = c.req.param('printerSn');
|
|
|
- await printerService.deletePrinter(tenantId, printerSn);
|
|
|
- return c.json({ success: true, message: '打印机删除成功' });
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 获取飞鹅API配置
|
|
|
+ const feieConfig = await getFeieApiConfig(tenantId, dataSource);
|
|
|
+ if (!feieConfig) {
|
|
|
+ return c.json({ success: false, message: '飞鹅API配置未找到或配置不完整' }, 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建带配置的服务实例
|
|
|
+ const tenantPrinterService = new PrinterService(dataSource, feieConfig);
|
|
|
+ await tenantPrinterService.deletePrinter(tenantId, printerSn);
|
|
|
+ return c.json({ success: true, message: '打印机删除成功' });
|
|
|
+ } catch (error) {
|
|
|
+ console.error(`[租户${tenantId}] 删除打印机失败,打印机SN: ${printerSn}:`, error);
|
|
|
+ const errorMessage = error instanceof Error ? error.message : '删除打印机失败';
|
|
|
+ return c.json({ success: false, message: errorMessage }, 500);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
app.get('/printers/:printerSn/status', async (c) => {
|
|
|
const user = c.get('user');
|
|
|
const tenantId = user?.tenantId || 1;
|
|
|
const printerSn = c.req.param('printerSn');
|
|
|
- const status = await printerService.getPrinterStatus(tenantId, printerSn);
|
|
|
- return c.json({ success: true, data: status });
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 获取飞鹅API配置
|
|
|
+ const feieConfig = await getFeieApiConfig(tenantId, dataSource);
|
|
|
+ if (!feieConfig) {
|
|
|
+ return c.json({ success: false, message: '飞鹅API配置未找到或配置不完整' }, 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建带配置的服务实例
|
|
|
+ const tenantPrinterService = new PrinterService(dataSource, feieConfig);
|
|
|
+ const status = await tenantPrinterService.getPrinterStatus(tenantId, printerSn);
|
|
|
+ return c.json({ success: true, data: status });
|
|
|
+ } catch (error) {
|
|
|
+ console.error(`[租户${tenantId}] 查询打印机状态失败,打印机SN: ${printerSn}:`, error);
|
|
|
+ const errorMessage = error instanceof Error ? error.message : '查询打印机状态失败';
|
|
|
+ return c.json({ success: false, message: errorMessage }, 500);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
app.post('/printers/:printerSn/set-default', async (c) => {
|
|
|
const user = c.get('user');
|
|
|
const tenantId = user?.tenantId || 1;
|
|
|
const printerSn = c.req.param('printerSn');
|
|
|
- const printer = await printerService.setDefaultPrinter(tenantId, printerSn);
|
|
|
- return c.json({ success: true, data: printer });
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 获取飞鹅API配置
|
|
|
+ const feieConfig = await getFeieApiConfig(tenantId, dataSource);
|
|
|
+ if (!feieConfig) {
|
|
|
+ return c.json({ success: false, message: '飞鹅API配置未找到或配置不完整' }, 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建带配置的服务实例
|
|
|
+ const tenantPrinterService = new PrinterService(dataSource, feieConfig);
|
|
|
+ const printer = await tenantPrinterService.setDefaultPrinter(tenantId, printerSn);
|
|
|
+ return c.json({ success: true, data: printer });
|
|
|
+ } catch (error) {
|
|
|
+ console.error(`[租户${tenantId}] 设置默认打印机失败,打印机SN: ${printerSn}:`, error);
|
|
|
+ const errorMessage = error instanceof Error ? error.message : '设置默认打印机失败';
|
|
|
+ return c.json({ success: false, message: errorMessage }, 500);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
// 打印任务管理路由
|
|
|
app.post('/tasks', async (c) => {
|
|
|
const user = c.get('user');
|
|
|
const tenantId = user?.tenantId || 1;
|
|
|
- const body = await c.req.json();
|
|
|
- const task = await printTaskService.createPrintTask(tenantId, body);
|
|
|
- return c.json({ success: true, data: task });
|
|
|
+
|
|
|
+ try {
|
|
|
+ const body = await c.req.json();
|
|
|
+
|
|
|
+ // 获取飞鹅API配置
|
|
|
+ const feieConfig = await getFeieApiConfig(tenantId, dataSource);
|
|
|
+ if (!feieConfig) {
|
|
|
+ return c.json({ success: false, message: '飞鹅API配置未找到或配置不完整' }, 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建带配置的打印任务服务实例
|
|
|
+ const tenantPrintTaskService = new PrintTaskService(dataSource, feieConfig);
|
|
|
+ const task = await tenantPrintTaskService.createPrintTask(tenantId, body);
|
|
|
+ return c.json({ success: true, data: task });
|
|
|
+ } catch (error) {
|
|
|
+ console.error(`[租户${tenantId}] 创建打印任务失败:`, error);
|
|
|
+ const errorMessage = error instanceof Error ? error.message : '创建打印任务失败';
|
|
|
+ return c.json({ success: false, message: errorMessage }, 500);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
app.get('/tasks', async (c) => {
|
|
|
const user = c.get('user');
|
|
|
const tenantId = user?.tenantId || 1;
|
|
|
- const query = c.req.query();
|
|
|
- const filters = {
|
|
|
- orderId: query.orderId ? parseInt(query.orderId, 10) : undefined,
|
|
|
- printerSn: query.printerSn,
|
|
|
- printType: query.printType as any,
|
|
|
- printStatus: query.printStatus as any,
|
|
|
- startDate: query.startDate ? new Date(query.startDate) : undefined,
|
|
|
- endDate: query.endDate ? new Date(query.endDate) : undefined
|
|
|
- };
|
|
|
- const page = query.page ? parseInt(query.page, 10) : 1;
|
|
|
- const limit = query.limit ? parseInt(query.limit, 10) : 20;
|
|
|
|
|
|
- const result = await printTaskService.getPrintTasks(tenantId, filters, page, limit);
|
|
|
- return c.json({ success: true, data: result.tasks, total: result.total, page, limit });
|
|
|
+ try {
|
|
|
+ const query = c.req.query();
|
|
|
+ const filters = {
|
|
|
+ orderId: query.orderId ? parseInt(query.orderId, 10) : undefined,
|
|
|
+ printerSn: query.printerSn,
|
|
|
+ printType: query.printType as any,
|
|
|
+ printStatus: query.status as any, // 前端传递的是status参数
|
|
|
+ startDate: query.startDate ? new Date(query.startDate) : undefined,
|
|
|
+ endDate: query.endDate ? new Date(query.endDate) : undefined,
|
|
|
+ search: query.search
|
|
|
+ };
|
|
|
+ const page = query.page ? parseInt(query.page, 10) : 1;
|
|
|
+ const limit = query.pageSize ? parseInt(query.pageSize, 10) : 20; // 前端传递的是pageSize参数
|
|
|
+
|
|
|
+ // 获取飞鹅API配置
|
|
|
+ const feieConfig = await getFeieApiConfig(tenantId, dataSource);
|
|
|
+ if (!feieConfig) {
|
|
|
+ return c.json({ success: false, message: '飞鹅API配置未找到或配置不完整' }, 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建带配置的打印任务服务实例
|
|
|
+ const tenantPrintTaskService = new PrintTaskService(dataSource, feieConfig);
|
|
|
+ const result = await tenantPrintTaskService.getPrintTasks(tenantId, filters, page, limit);
|
|
|
+ return c.json({
|
|
|
+ success: true,
|
|
|
+ data: {
|
|
|
+ data: result.tasks,
|
|
|
+ total: result.total,
|
|
|
+ page,
|
|
|
+ pageSize: limit
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ console.error(`[租户${tenantId}] 获取打印任务列表失败:`, error);
|
|
|
+ const errorMessage = error instanceof Error ? error.message : '获取打印任务列表失败';
|
|
|
+ return c.json({ success: false, message: errorMessage }, 500);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
app.get('/tasks/:taskId', async (c) => {
|
|
|
const user = c.get('user');
|
|
|
const tenantId = user?.tenantId || 1;
|
|
|
const taskId = c.req.param('taskId');
|
|
|
- const task = await (printTaskService as any).findOne({
|
|
|
- where: { tenantId, taskId }
|
|
|
+ const task = await printTaskService.repository.findOne({
|
|
|
+ where: { tenantId, taskId } as any
|
|
|
});
|
|
|
|
|
|
if (!task) {
|
|
|
@@ -206,8 +386,23 @@ export function createFeieRoutes(dataSource: DataSource) {
|
|
|
const user = c.get('user');
|
|
|
const tenantId = user?.tenantId || 1;
|
|
|
const taskId = c.req.param('taskId');
|
|
|
- const status = await printTaskService.getPrintTaskStatus(tenantId, taskId);
|
|
|
- return c.json({ success: true, data: status });
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 获取飞鹅API配置
|
|
|
+ const feieConfig = await getFeieApiConfig(tenantId, dataSource);
|
|
|
+ if (!feieConfig) {
|
|
|
+ return c.json({ success: false, message: '飞鹅API配置未找到或配置不完整' }, 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建带配置的打印任务服务实例
|
|
|
+ const tenantPrintTaskService = new PrintTaskService(dataSource, feieConfig);
|
|
|
+ const status = await tenantPrintTaskService.getPrintTaskStatus(tenantId, taskId);
|
|
|
+ return c.json({ success: true, data: status });
|
|
|
+ } catch (error) {
|
|
|
+ console.error(`[租户${tenantId}] 获取打印任务状态失败,任务ID: ${taskId}:`, error);
|
|
|
+ const errorMessage = error instanceof Error ? error.message : '获取打印任务状态失败';
|
|
|
+ return c.json({ success: false, message: errorMessage }, 500);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
app.post('/tasks/:taskId/cancel', async (c) => {
|
|
|
@@ -223,31 +418,116 @@ export function createFeieRoutes(dataSource: DataSource) {
|
|
|
const user = c.get('user');
|
|
|
const tenantId = user?.tenantId || 1;
|
|
|
const taskId = c.req.param('taskId');
|
|
|
- const task = await printTaskService.retryPrintTask(tenantId, taskId);
|
|
|
- return c.json({ success: true, data: task });
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 获取飞鹅API配置
|
|
|
+ const feieConfig = await getFeieApiConfig(tenantId, dataSource);
|
|
|
+ if (!feieConfig) {
|
|
|
+ return c.json({ success: false, message: '飞鹅API配置未找到或配置不完整' }, 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建带配置的打印任务服务实例
|
|
|
+ const tenantPrintTaskService = new PrintTaskService(dataSource, feieConfig);
|
|
|
+ const task = await tenantPrintTaskService.retryPrintTask(tenantId, taskId);
|
|
|
+ return c.json({ success: true, data: task });
|
|
|
+ } catch (error) {
|
|
|
+ console.error(`[租户${tenantId}] 重试打印任务失败,任务ID: ${taskId}:`, error);
|
|
|
+ const errorMessage = error instanceof Error ? error.message : '重试打印任务失败';
|
|
|
+ return c.json({ success: false, message: errorMessage }, 500);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
// 调度器管理路由
|
|
|
app.get('/scheduler/status', async (c) => {
|
|
|
+ const user = c.get('user');
|
|
|
+ console.debug('获取调度器状态 - 用户对象:', JSON.stringify(user, null, 2));
|
|
|
+ const tenantId = user?.tenantId || 1;
|
|
|
+
|
|
|
+ // 创建租户特定的调度器实例
|
|
|
+ const delaySchedulerService = new DelaySchedulerService(dataSource, {
|
|
|
+ baseUrl: 'https://api.feieyun.cn/Api/Open/',
|
|
|
+ user: '',
|
|
|
+ ukey: '',
|
|
|
+ timeout: 10000,
|
|
|
+ maxRetries: 3
|
|
|
+ }, tenantId);
|
|
|
+
|
|
|
const status = delaySchedulerService.getStatus();
|
|
|
return c.json({ success: true, data: status });
|
|
|
});
|
|
|
|
|
|
app.post('/scheduler/start', async (c) => {
|
|
|
+ const user = c.get('user');
|
|
|
+ console.debug('启动调度器 - 用户对象:', JSON.stringify(user, null, 2));
|
|
|
+ const tenantId = user?.tenantId || 1;
|
|
|
+
|
|
|
+ // 创建租户特定的调度器实例
|
|
|
+ const delaySchedulerService = new DelaySchedulerService(dataSource, {
|
|
|
+ baseUrl: 'https://api.feieyun.cn/Api/Open/',
|
|
|
+ user: '',
|
|
|
+ ukey: '',
|
|
|
+ timeout: 10000,
|
|
|
+ maxRetries: 3
|
|
|
+ }, tenantId);
|
|
|
+
|
|
|
await delaySchedulerService.start();
|
|
|
return c.json({ success: true, message: '调度器已启动' });
|
|
|
});
|
|
|
|
|
|
app.post('/scheduler/stop', async (c) => {
|
|
|
+ const user = c.get('user');
|
|
|
+ console.debug('停止调度器 - 用户对象:', JSON.stringify(user, null, 2));
|
|
|
+ const tenantId = user?.tenantId || 1;
|
|
|
+
|
|
|
+ // 创建租户特定的调度器实例
|
|
|
+ const delaySchedulerService = new DelaySchedulerService(dataSource, {
|
|
|
+ baseUrl: 'https://api.feieyun.cn/Api/Open/',
|
|
|
+ user: '',
|
|
|
+ ukey: '',
|
|
|
+ timeout: 10000,
|
|
|
+ maxRetries: 3
|
|
|
+ }, tenantId);
|
|
|
+
|
|
|
await delaySchedulerService.stop();
|
|
|
return c.json({ success: true, message: '调度器已停止' });
|
|
|
});
|
|
|
|
|
|
app.get('/scheduler/health', async (c) => {
|
|
|
+ const user = c.get('user');
|
|
|
+ console.debug('调度器健康检查 - 用户对象:', JSON.stringify(user, null, 2));
|
|
|
+ const tenantId = user?.tenantId || 1;
|
|
|
+
|
|
|
+ // 创建租户特定的调度器实例
|
|
|
+ const delaySchedulerService = new DelaySchedulerService(dataSource, {
|
|
|
+ baseUrl: 'https://api.feieyun.cn/Api/Open/',
|
|
|
+ user: '',
|
|
|
+ ukey: '',
|
|
|
+ timeout: 10000,
|
|
|
+ maxRetries: 3
|
|
|
+ }, tenantId);
|
|
|
+
|
|
|
const health = await delaySchedulerService.healthCheck();
|
|
|
return c.json({ success: true, data: health });
|
|
|
});
|
|
|
|
|
|
+ app.post('/scheduler/trigger', async (c) => {
|
|
|
+ const user = c.get('user');
|
|
|
+ console.debug('手动触发调度器处理 - 用户对象:', JSON.stringify(user, null, 2));
|
|
|
+ const tenantId = user?.tenantId || 1;
|
|
|
+
|
|
|
+ // 创建租户特定的调度器实例
|
|
|
+ const delaySchedulerService = new DelaySchedulerService(dataSource, {
|
|
|
+ baseUrl: 'https://api.feieyun.cn/Api/Open/',
|
|
|
+ user: '',
|
|
|
+ ukey: '',
|
|
|
+ timeout: 10000,
|
|
|
+ maxRetries: 3
|
|
|
+ }, tenantId);
|
|
|
+
|
|
|
+ const result = await delaySchedulerService.triggerManualProcess();
|
|
|
+ return c.json({ success: result.success, data: result });
|
|
|
+ });
|
|
|
+
|
|
|
// 打印配置管理路由
|
|
|
app.get('/config', async (c) => {
|
|
|
const user = c.get('user');
|
|
|
@@ -255,7 +535,20 @@ export function createFeieRoutes(dataSource: DataSource) {
|
|
|
|
|
|
try {
|
|
|
const configs = await configService.getPrintConfigs(tenantId);
|
|
|
- return c.json({ success: true, data: configs });
|
|
|
+
|
|
|
+ // 将 FeieConfigMt 转换为前端需要的 FeieConfig 格式
|
|
|
+ const transformedConfigs = configs.map(config => ({
|
|
|
+ id: config.id,
|
|
|
+ tenantId: config.tenantId,
|
|
|
+ configKey: config.configKey as any, // 字符串转换为 ConfigKey 枚举
|
|
|
+ configValue: config.configValue || '', // 处理null值
|
|
|
+ configType: config.configType as any, // 字符串转换为 ConfigType 枚举
|
|
|
+ description: config.description || undefined,
|
|
|
+ createdAt: config.createdAt.toISOString(),
|
|
|
+ updatedAt: config.updatedAt.toISOString()
|
|
|
+ }));
|
|
|
+
|
|
|
+ return c.json({ success: true, data: { data: transformedConfigs } });
|
|
|
} catch (error) {
|
|
|
console.error(`[租户${tenantId}] 获取打印配置失败:`, error);
|
|
|
return c.json({ success: false, message: '获取打印配置失败' }, 500);
|
|
|
@@ -274,7 +567,20 @@ export function createFeieRoutes(dataSource: DataSource) {
|
|
|
|
|
|
try {
|
|
|
const config = await configService.updatePrintConfig(tenantId, configKey, body.configValue);
|
|
|
- return c.json({ success: true, data: config });
|
|
|
+
|
|
|
+ // 将 FeieConfigMt 转换为前端需要的 FeieConfig 格式
|
|
|
+ const transformedConfig = {
|
|
|
+ id: config.id,
|
|
|
+ tenantId: config.tenantId,
|
|
|
+ configKey: config.configKey as any, // 字符串转换为 ConfigKey 枚举
|
|
|
+ configValue: config.configValue || '', // 处理null值
|
|
|
+ configType: config.configType as any, // 字符串转换为 ConfigType 枚举
|
|
|
+ description: config.description || undefined,
|
|
|
+ createdAt: config.createdAt.toISOString(),
|
|
|
+ updatedAt: config.updatedAt.toISOString()
|
|
|
+ };
|
|
|
+
|
|
|
+ return c.json({ success: true, data: transformedConfig });
|
|
|
} catch (error) {
|
|
|
console.error(`[租户${tenantId}] 更新配置失败,key: ${configKey}:`, error);
|
|
|
return c.json({ success: false, message: '更新配置失败' }, 500);
|