feat(diet-records): 新增营养成分分析记录功能

- 添加营养成分分析记录数据模型和数据库集成
- 实现分析记录保存功能,支持成功和失败状态记录
- 新增获取用户营养成分分析记录的API接口
- 支持按日期范围、状态等条件筛选查询
- 提供分页查询功能,优化大数据量场景性能
This commit is contained in:
richarjiang
2025-10-16 11:25:31 +08:00
parent 91cac3134e
commit 4d1bc9259b
9 changed files with 561 additions and 7 deletions

View File

@@ -0,0 +1,114 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiResponseDto } from '../../base.dto';
/**
* 营养成分分析记录项DTO
*/
export class NutritionAnalysisRecordDto {
@ApiProperty({ description: '记录ID', example: 1 })
id: number;
@ApiProperty({ description: '用户ID', example: 'user123' })
userId: string;
@ApiProperty({ description: '分析图片URL', example: 'https://example.com/nutrition-label.jpg' })
imageUrl: string;
@ApiProperty({ description: '营养成分分析结果' })
analysisResult: any;
@ApiProperty({ description: '分析状态', example: 'success' })
status: string;
@ApiProperty({ description: '分析消息', example: '分析成功' })
message: string;
@ApiProperty({ description: 'AI模型提供商', example: 'dashscope' })
aiProvider: string;
@ApiProperty({ description: '使用的AI模型', example: 'qwen-vl-max' })
aiModel: string;
@ApiProperty({ description: '识别到的营养素数量', example: 15 })
nutritionCount: number;
@ApiProperty({ description: '创建时间' })
createdAt: Date;
@ApiProperty({ description: '更新时间' })
updatedAt: Date;
}
/**
* 营养成分分析记录列表响应DTO
*/
export class NutritionAnalysisRecordsResponseDto extends ApiResponseDto<{
records: NutritionAnalysisRecordDto[];
total: number;
page: number;
limit: number;
totalPages: number;
}> {
constructor(code: number, message: string, data: {
records: NutritionAnalysisRecordDto[];
total: number;
page: number;
limit: number;
totalPages: number;
}) {
super(code, message, data);
}
/**
* 创建成功响应
*/
static createSuccess(
records: NutritionAnalysisRecordDto[],
total: number,
page: number,
limit: number,
message: string = '获取营养分析记录成功'
): NutritionAnalysisRecordsResponseDto {
const totalPages = Math.ceil(total / limit);
return new NutritionAnalysisRecordsResponseDto(0, message, {
records,
total,
page,
limit,
totalPages,
});
}
/**
* 创建失败响应
*/
static createError(message: string = '获取营养分析记录失败'): NutritionAnalysisRecordsResponseDto {
return new NutritionAnalysisRecordsResponseDto(1, message, {
records: [],
total: 0,
page: 1,
limit: 20,
totalPages: 0,
});
}
}
/**
* 查询营养分析记录请求DTO
*/
export class GetNutritionAnalysisRecordsQueryDto {
@ApiProperty({ description: '页码', example: 1, required: false })
page?: number;
@ApiProperty({ description: '每页数量', example: 20, required: false })
limit?: number;
@ApiProperty({ description: '开始日期', example: '2023-01-01', required: false })
startDate?: string;
@ApiProperty({ description: '结束日期', example: '2023-12-31', required: false })
endDate?: string;
@ApiProperty({ description: '分析状态', example: 'success', required: false })
status?: string;
}