855 协议版本-调整完毕内容
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
from datetime import datetime
|
||||
import json
|
||||
import os
|
||||
import logging
|
||||
from loguru import logger
|
||||
from typing import Dict, Optional, List, Any, Set
|
||||
|
||||
from db.connection import DBConnectionManager
|
||||
@@ -14,14 +14,14 @@ class KidPhotoRedisDB:
|
||||
def __init__(self, db_manager: DBConnectionManager):
|
||||
self.db_manager = db_manager
|
||||
self.prefix = "group:kid_photo:"
|
||||
logger = logging.getLogger("DB.KidPhotoRedis")
|
||||
self.LOG = logger
|
||||
|
||||
def get_redis_connection(self):
|
||||
"""获取Redis连接"""
|
||||
try:
|
||||
return self.db_manager.get_redis_connection()
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取Redis连接失败: {e}")
|
||||
self.LOG.error(f"获取Redis连接失败: {e}")
|
||||
return None
|
||||
|
||||
def save_last_analysis_time(self, group_id: str) -> bool:
|
||||
@@ -34,7 +34,7 @@ class KidPhotoRedisDB:
|
||||
redis_client.set(f'{self.prefix}{group_id}:last_time', str(timestamp))
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"保存最后分析时间失败: {e}")
|
||||
self.LOG.error(f"保存最后分析时间失败: {e}")
|
||||
return False
|
||||
|
||||
def get_last_analysis_time(self, group_id: str) -> Optional[int]:
|
||||
@@ -50,7 +50,7 @@ class KidPhotoRedisDB:
|
||||
return int(timestamp)
|
||||
return None
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取最后分析时间失败: {e}")
|
||||
self.LOG.error(f"获取最后分析时间失败: {e}")
|
||||
return None
|
||||
|
||||
def save_analysis_result(self, group_id: str, result: Dict) -> bool:
|
||||
@@ -62,7 +62,7 @@ class KidPhotoRedisDB:
|
||||
redis_client.set(f'{self.prefix}{group_id}:results', json.dumps(result, ensure_ascii=False))
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"保存分析结果失败: {e}")
|
||||
self.LOG.error(f"保存分析结果失败: {e}")
|
||||
return False
|
||||
|
||||
def get_last_analysis_result(self, group_id: str) -> Optional[Dict]:
|
||||
@@ -78,10 +78,10 @@ class KidPhotoRedisDB:
|
||||
return json.loads(result)
|
||||
return None
|
||||
except json.JSONDecodeError as e:
|
||||
self.logger.error(f"解析分析结果JSON失败: {e}")
|
||||
self.LOG.error(f"解析分析结果JSON失败: {e}")
|
||||
return None
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取最后分析结果失败: {e}")
|
||||
self.LOG.error(f"获取最后分析结果失败: {e}")
|
||||
return None
|
||||
|
||||
def save_processed_photo(self, group_id: str, photo_path: str) -> bool:
|
||||
@@ -96,7 +96,7 @@ class KidPhotoRedisDB:
|
||||
redis_client.sadd(f'{self.prefix}{group_id}:processed_photos', photo_path)
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"保存已处理照片失败: {e}")
|
||||
self.LOG.error(f"保存已处理照片失败: {e}")
|
||||
return False
|
||||
|
||||
def save_processed_photos(self, group_id: str, photo_paths: List[str]) -> bool:
|
||||
@@ -128,7 +128,7 @@ class KidPhotoRedisDB:
|
||||
pipeline.execute()
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"批量保存已处理照片失败: {e}")
|
||||
self.LOG.error(f"批量保存已处理照片失败: {e}")
|
||||
return False
|
||||
|
||||
def get_processed_photos(self, group_id: str) -> Set[str]:
|
||||
@@ -146,7 +146,7 @@ class KidPhotoRedisDB:
|
||||
photos.add(path)
|
||||
return photos
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取已处理照片失败: {e}")
|
||||
self.LOG.error(f"获取已处理照片失败: {e}")
|
||||
return set()
|
||||
|
||||
def is_photo_processed(self, group_id: str, photo_path: str) -> bool:
|
||||
@@ -160,7 +160,7 @@ class KidPhotoRedisDB:
|
||||
return False
|
||||
return redis_client.sismember(f'{self.prefix}{group_id}:processed_photos', photo_path)
|
||||
except Exception as e:
|
||||
self.logger.error(f"检查照片是否已处理失败: {e}")
|
||||
self.LOG.error(f"检查照片是否已处理失败: {e}")
|
||||
return False
|
||||
|
||||
def save_photo_mapping(self, group_id: str, kid_id: str, photo_path: str) -> bool:
|
||||
@@ -183,7 +183,7 @@ class KidPhotoRedisDB:
|
||||
pipeline.execute()
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"保存照片映射关系失败: {e}")
|
||||
self.LOG.error(f"保存照片映射关系失败: {e}")
|
||||
return False
|
||||
|
||||
def get_kid_photos(self, group_id: str, kid_id: str) -> List[str]:
|
||||
@@ -204,7 +204,7 @@ class KidPhotoRedisDB:
|
||||
photos.append(path)
|
||||
return photos
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取小朋友照片失败: {e}")
|
||||
self.LOG.error(f"获取小朋友照片失败: {e}")
|
||||
return []
|
||||
|
||||
def get_photo_kid(self, group_id: str, photo_name: str) -> Optional[str]:
|
||||
@@ -222,7 +222,7 @@ class KidPhotoRedisDB:
|
||||
kid_id = kid_id.decode('utf-8')
|
||||
return kid_id
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取照片对应的小朋友ID失败: {e}")
|
||||
self.LOG.error(f"获取照片对应的小朋友ID失败: {e}")
|
||||
return None
|
||||
|
||||
def save_last_process_time(self, group_id: str) -> bool:
|
||||
@@ -235,7 +235,7 @@ class KidPhotoRedisDB:
|
||||
redis_client.set(f'{self.prefix}{group_id}:last_process_time', str(timestamp))
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"保存最后处理时间失败: {e}")
|
||||
self.LOG.error(f"保存最后处理时间失败: {e}")
|
||||
return False
|
||||
|
||||
def get_last_process_time(self, group_id: str) -> Optional[int]:
|
||||
@@ -252,7 +252,7 @@ class KidPhotoRedisDB:
|
||||
return int(timestamp)
|
||||
return None
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取最后处理时间失败: {e}")
|
||||
self.LOG.error(f"获取最后处理时间失败: {e}")
|
||||
return None
|
||||
|
||||
def clear_processed_photos(self, group_id: str) -> bool:
|
||||
@@ -264,7 +264,7 @@ class KidPhotoRedisDB:
|
||||
redis_client.delete(f'{self.prefix}{group_id}:processed_photos')
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"清理已处理照片记录失败: {e}")
|
||||
self.LOG.error(f"清理已处理照片记录失败: {e}")
|
||||
return False
|
||||
|
||||
def clear_analysis_data(self, group_id: str) -> bool:
|
||||
@@ -301,5 +301,5 @@ class KidPhotoRedisDB:
|
||||
pipeline.execute()
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"清理分析数据失败: {e}")
|
||||
self.LOG.error(f"清理分析数据失败: {e}")
|
||||
return False
|
||||
Reference in New Issue
Block a user