stash
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
NotFoundException,
|
||||
UseInterceptors,
|
||||
UploadedFile,
|
||||
forwardRef,
|
||||
} from '@nestjs/common';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { Request } from 'express';
|
||||
@@ -45,6 +46,7 @@ import { AccessTokenPayload } from './services/apple-auth.service';
|
||||
import { JwtAuthGuard } from 'src/common/guards/jwt-auth.guard';
|
||||
import { ResponseCode } from 'src/base.dto';
|
||||
import { CosService } from './cos.service';
|
||||
import { AiReportService } from '../ai-coach/services/ai-report.service';
|
||||
|
||||
|
||||
@ApiTags('users')
|
||||
@@ -55,6 +57,8 @@ export class UsersController {
|
||||
private readonly usersService: UsersService,
|
||||
@Inject(WINSTON_MODULE_PROVIDER) private readonly winstonLogger: WinstonLogger,
|
||||
private readonly cosService: CosService,
|
||||
@Inject(forwardRef(() => AiReportService))
|
||||
private readonly aiReportService: AiReportService,
|
||||
) { }
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@@ -472,4 +476,65 @@ export class UsersController {
|
||||
return this.usersService.checkVersion(query);
|
||||
}
|
||||
|
||||
// ==================== AI 健康报告 ====================
|
||||
|
||||
/**
|
||||
* 生成用户的 AI 健康报告图片
|
||||
*/
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('ai-report')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: '生成用户的 AI 健康报告图片' })
|
||||
@ApiBody({ type: Object, required: false, description: '请求体,可以传入 date 指定日期,格式 YYYY-MM-DD' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: '成功生成 AI 报告图片',
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
code: { type: 'number', example: 0 },
|
||||
message: { type: 'string', example: 'success' },
|
||||
data: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
imageUrl: { type: 'string', example: 'https://example.com/generated-image.png' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
async generateAiHealthReport(
|
||||
@CurrentUser() user: AccessTokenPayload,
|
||||
@Body() body: { date?: string },
|
||||
): Promise<{ code: ResponseCode; message: string; data: { imageUrl: string } }> {
|
||||
try {
|
||||
this.logger.log(`生成AI健康报告请求 - 用户ID: ${user.sub}, 日期: ${body.date || '今天'}`);
|
||||
|
||||
const result = await this.aiReportService.generateHealthReportImage(user.sub, body.date);
|
||||
|
||||
return {
|
||||
code: ResponseCode.SUCCESS,
|
||||
message: 'AI健康报告生成成功',
|
||||
data: {
|
||||
imageUrl: result.imageUrl,
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
this.winstonLogger.error('生成AI健康报告失败', {
|
||||
context: 'UsersController',
|
||||
userId: user?.sub,
|
||||
error: (error as Error).message,
|
||||
stack: (error as Error).stack,
|
||||
});
|
||||
|
||||
return {
|
||||
code: ResponseCode.ERROR,
|
||||
message: `生成失败: ${(error as Error).message}`,
|
||||
data: {
|
||||
imageUrl: '',
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user