Files
wwjcloud-nest-v1/wwjcloud-nest/src/core/member/jobs/SetMemberNoJob.ts
wanwujie c4e588a2fe feat: 完成PHP到NestJS迁移工具和代码生成
-  成功运行迁移工具,生成28个模块的完整NestJS代码
-  生成所有实体、服务、控制器、验证器等组件
-  修复npm依赖冲突,更新package-lock.json
-  添加Docker测试脚本和配置文件
-  完善迁移工具的调试日志和错误处理
- 🔧 包含增量更新工具和质量检查工具
- 📊 迁移统计:28个模块,数千个文件,耗时26.47秒

主要变更:
- wwjcloud-nest/src/core/* - 生成的业务模块代码
- tools/* - 迁移工具和辅助脚本
- wwjcloud-nest/package.json - 依赖更新
- docker/* - 容器化配置和测试脚本
2025-10-20 18:43:52 +08:00

87 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Injectable, Logger } from '@nestjs/common';
import { InjectQueue } from '@nestjs/bullmq';
import { Queue } from 'bullmq';
import { BusinessException } from '@wwjCommon/exceptions/business.exception';
/**
* SetMemberNoJob - 基于NestJS BullMQ
* 参考: https://docs.nestjs.com/techniques/queues
* 对应 Java: @Async + RabbitMQ
* 对应 PHP: thinkqueue
*/
@Injectable()
export class SetMemberNoJob {
private readonly logger = new Logger(SetMemberNoJob.name);
constructor(@InjectQueue('member') private readonly queue: Queue) {}
/**
* 添加任务到队列 - 使用BullMQ标准API
* 参考: https://docs.nestjs.com/techniques/queues#producers
*/
async addJob(data: any, options?: any) {
try {
const job = await this.queue.add('SetMemberNo', data, options);
this.logger.log(`SetMemberNo job added to queue: ${job.id}`, data);
return job;
} catch (error) {
this.logger.error('Failed to add SetMemberNo job to queue:', error);
throw new BusinessException('SetMemberNo任务添加失败');
}
}
/**
* 处理队列任务
* 使用Core层基础设施统一队列服务、异常处理、日志服务
*/
async processJob(data: any) {
this.logger.log('SetMemberNo job processing:', data);
try {
// 任务逻辑
await this.executeJob(data);
this.logger.log('SetMemberNo job completed successfully');
} catch (error) {
this.logger.error('SetMemberNo job failed:', error);
// 使用Core层异常处理
throw new BusinessException('SetMemberNo任务处理失败', error);
}
}
/**
* 执行任务
* 使用Core层基础设施日志服务、异常处理
*/
private async executeJob(data: any) {
// 实现具体的任务逻辑
// 例如:
// - 数据清理
// - 报表生成
// - 邮件发送
// - 数据同步
// - 备份操作
this.logger.log('Executing SetMemberNo job logic with data:', data);
// 模拟异步操作
await new Promise((resolve) => setTimeout(resolve, 1000));
this.logger.log('SetMemberNo job logic completed');
}
/**
* 手动触发任务
* 使用Core层基础设施日志服务、异常处理
*/
async triggerJob(data?: any) {
this.logger.log('Manually triggering SetMemberNo job...');
try {
await this.executeJob(data || {});
} catch (error) {
this.logger.error('Failed to trigger SetMemberNo job:', error);
// 使用Core层异常处理
throw new BusinessException('SetMemberNo任务触发失败', error);
}
}
}