feat: 优化换装图片生成功能

更新内容:
- 优化model_repository.rs中的数据库操作
- 改进outfit_image_commands.rs中的命令处理逻辑
- 完善outfitImageService.ts中的前端服务接口

技术改进:
- 提升数据库查询性能
- 增强错误处理机制
- 优化前后端数据交互

用户体验:
- 更稳定的换装图片生成流程
- 更好的错误提示和处理
- 更流畅的操作体验
This commit is contained in:
imeepos 2025-07-31 14:33:16 +08:00
parent b158546738
commit 582d5c2709
3 changed files with 0 additions and 21 deletions

View File

@ -95,13 +95,11 @@ impl ModelRepository {
/// 根据ID获取模特
/// 使用读写分离避免嵌套锁问题
pub fn get_by_id(&self, id: &str) -> Result<Option<Model>> {
println!("get_by_id 开始执行model_id: {}", id);
// 首先获取模特基本信息(使用只读连接)
let model = {
match self.database.try_get_read_connection() {
Some(conn) => {
println!("get_by_id 使用只读连接获取基本信息");
let mut stmt = conn.prepare(
"SELECT id, name, stage_name, gender, age, height, weight, measurements,
@ -129,12 +127,9 @@ impl ModelRepository {
// 如果找到模特,加载照片信息(此时已释放了基本信息查询的锁)
if let Some(mut model) = model {
println!("get_by_id 开始加载照片信息");
model.photos = self.get_photos(&model.id)?;
println!("get_by_id 执行完成");
Ok(Some(model))
} else {
println!("get_by_id 未找到模特");
Ok(None)
}
}
@ -498,7 +493,6 @@ impl ModelRepository {
/// 获取模特照片
/// 使用专用只读连接,避免与写操作的锁竞争
pub fn get_photos(&self, model_id: &str) -> Result<Vec<ModelPhoto>> {
println!("get_photos 开始执行model_id: {}", model_id);
// 使用专用的只读连接,避免与写操作竞争
match self.database.get_best_read_connection() {
@ -517,7 +511,6 @@ impl ModelRepository {
/// 执行照片查询的具体实现
fn execute_photo_query(&self, conn: &Connection, model_id: &str) -> Result<Vec<ModelPhoto>> {
println!("get_photos 开始准备SQL语句");
let mut stmt = conn.prepare(
"SELECT id, model_id, file_path, file_name, file_size, photo_type,
@ -527,7 +520,6 @@ impl ModelRepository {
println!("get_photos SQL 语句准备成功");
let photo_iter = stmt.query_map([model_id], |row| self.row_to_photo(row))?;
println!("get_photos 查询执行成功");
let mut photos = Vec::new();
for (index, photo_result) in photo_iter.enumerate() {
@ -545,7 +537,6 @@ impl ModelRepository {
}
}
println!("get_photos 查询处理完成,共 {} 张照片", photos.len());
Ok(photos)
}
@ -735,10 +726,7 @@ impl ModelRepository {
/// 将数据库行转换为照片对象
fn row_to_photo(&self, row: &Row) -> Result<ModelPhoto> {
println!("row_to_photo 开始执行");
let photo_type_str: String = row.get("photo_type")?;
println!("row_to_photo 获取 photo_type: {}", photo_type_str);
let photo_type: PhotoType = serde_json::from_str(&photo_type_str).map_err(|e| {
println!("row_to_photo photo_type 解析失败: {}", e);

View File

@ -44,8 +44,6 @@ pub async fn get_model_dashboard_stats(
state: State<'_, AppState>,
model_id: String,
) -> Result<ModelDashboardStats, String> {
println!("📊 获取模特个人看板统计信息: {}", model_id);
// 获取数据库连接
let database = state.get_database();
let outfit_repo = OutfitImageRepository::new(database.clone());
@ -118,7 +116,6 @@ pub async fn get_outfit_image_records(
let records = outfit_repo.get_records_by_model_id(&model_id)
.map_err(|e| format!("获取穿搭图片记录失败: {}", e))?;
println!("✅ 获取到 {} 条穿搭图片记录", records.len());
Ok(records)
}
@ -130,7 +127,6 @@ pub async fn get_outfit_image_records_paginated(
page: u32,
page_size: u32,
) -> Result<OutfitImageRecordsResponse, String> {
println!("📋 分页获取模特穿搭图片生成记录: {} (页码: {}, 每页: {})", model_id, page, page_size);
let database = state.get_database();
let outfit_repo = OutfitImageRepository::new(database);
@ -157,8 +153,6 @@ pub async fn get_outfit_image_records_paginated(
has_more,
};
println!("✅ 获取到 {} 条穿搭图片记录 (总数: {}, 还有更多: {})",
response.records.len(), total_count, has_more);
Ok(response)
}

View File

@ -18,8 +18,6 @@ export class OutfitImageService {
*/
static async getModelDashboardStats(modelId: string): Promise<ModelDashboardStats> {
try {
console.log('📊 获取模特个人看板统计信息:', modelId);
const stats = await invoke<ModelDashboardStats>('get_model_dashboard_stats', {
modelId
});
@ -59,7 +57,6 @@ export class OutfitImageService {
pageSize: number = 20
): Promise<OutfitImageRecordsResponse> {
try {
console.log('📋 分页获取模特穿搭图片生成记录:', modelId, `页码: ${page}, 每页: ${pageSize}`);
const response = await invoke<OutfitImageRecordsResponse>('get_outfit_image_records_paginated', {
modelId,