diff --git a/backend/app/routers/collections.py b/backend/app/routers/collections.py index 468fb21..1db510f 100644 --- a/backend/app/routers/collections.py +++ b/backend/app/routers/collections.py @@ -107,8 +107,13 @@ def get_collections( ): """获取藏品列表""" # admin 用户可以看到所有藏品,普通用户只能看到自己的 + from sqlalchemy.orm import joinedload + if current_user.role == "admin": - query = db.query(Collection) + # 联表查询获取用户名 + query = db.query(Collection, User.f01_01_name.label('owner_name')).join( + User, Collection.f99_91_user_id == User.f99_90_id, isouter=True + ) else: query = db.query(Collection).filter(Collection.f99_91_user_id == current_user.f99_90_id) @@ -122,8 +127,11 @@ def get_collections( (Collection.f01_05_remark.contains(search)) ) - # 总数 - total = query.count() + # 总数(分开查询避免join影响count) + if current_user.role == "admin": + total = db.query(Collection).count() + else: + total = query.count() # 分页 data = query.order_by(Collection.f99_92_created_at.desc()) \ @@ -134,43 +142,51 @@ def get_collections( # 转换为字典列表并转为 camelCase data_list = [] for item in data: + # 处理联表查询结果 + if current_user.role == "admin": + collection_item, owner_name = item + else: + collection_item = item + owner_name = None + item_dict = { - 'f99_90_id': item.f99_90_id, - 'f99_91_user_id': item.f99_91_user_id, - 'f01_01_name': item.f01_01_name, - 'f01_02_code': item.f01_02_code, - 'f01_03_category': item.f01_03_category, - 'f01_04_status': item.f01_04_status, - 'f01_05_remark': item.f01_05_remark, - 'f02_10_prefix_serial': item.f02_10_prefix_serial, - 'f02_11_version': item.f02_11_version, - 'f02_12_packaging': item.f02_12_packaging, - 'f02_13_rarity': item.f02_13_rarity, - 'f03_20_is_graded': item.f03_20_is_graded, - 'f03_21_grading_company': item.f03_21_grading_company, - 'f03_22_grading_score': item.f03_22_grading_score, - 'f03_23_three_star': item.f03_23_three_star, - 'f04_30_special_mark': item.f04_30_special_mark, - 'f04_31_serial_feature': item.f04_31_serial_feature, - 'f04_32_issuer': item.f04_32_issuer, - 'f04_33_issue_year': item.f04_33_issue_year, - 'f04_34_material': item.f04_34_material, - 'f04_35_denomination': item.f04_35_denomination, - 'f04_36_issue_quantity': item.f04_36_issue_quantity, - 'f05_40_cost_price': float(item.f05_40_cost_price) if item.f05_40_cost_price else None, - 'f05_41_target_price': float(item.f05_41_target_price) if item.f05_41_target_price else None, - 'f05_42_goal_price': float(item.f05_42_goal_price) if item.f05_42_goal_price else None, - 'f05_43_repair_fee': float(item.f05_43_repair_fee) if item.f05_43_repair_fee else None, - 'f05_44_grading_fee': float(item.f05_44_grading_fee) if item.f05_44_grading_fee else None, - 'f06_50_purpose': item.f06_50_purpose, - 'f99_92_created_at': item.f99_92_created_at.isoformat() if item.f99_92_created_at else None, + 'f99_90_id': collection_item.f99_90_id, + 'f99_91_user_id': collection_item.f99_91_user_id, + 'owner_name': owner_name, # 所属用户名(仅管理员可见) + 'f01_01_name': collection_item.f01_01_name, + 'f01_02_code': collection_item.f01_02_code, + 'f01_03_category': collection_item.f01_03_category, + 'f01_04_status': collection_item.f01_04_status, + 'f01_05_remark': collection_item.f01_05_remark, + 'f02_10_prefix_serial': collection_item.f02_10_prefix_serial, + 'f02_11_version': collection_item.f02_11_version, + 'f02_12_packaging': collection_item.f02_12_packaging, + 'f02_13_rarity': collection_item.f02_13_rarity, + 'f03_20_is_graded': collection_item.f03_20_is_graded, + 'f03_21_grading_company': collection_item.f03_21_grading_company, + 'f03_22_grading_score': collection_item.f03_22_grading_score, + 'f03_23_three_star': collection_item.f03_23_three_star, + 'f04_30_special_mark': collection_item.f04_30_special_mark, + 'f04_31_serial_feature': collection_item.f04_31_serial_feature, + 'f04_32_issuer': collection_item.f04_32_issuer, + 'f04_33_issue_year': collection_item.f04_33_issue_year, + 'f04_34_material': collection_item.f04_34_material, + 'f04_35_denomination': collection_item.f04_35_denomination, + 'f04_36_issue_quantity': collection_item.f04_36_issue_quantity, + 'f05_40_cost_price': float(collection_item.f05_40_cost_price) if collection_item.f05_40_cost_price else None, + 'f05_41_target_price': float(collection_item.f05_41_target_price) if collection_item.f05_41_target_price else None, + 'f05_42_goal_price': float(collection_item.f05_42_goal_price) if collection_item.f05_42_goal_price else None, + 'f05_43_repair_fee': float(collection_item.f05_43_repair_fee) if collection_item.f05_43_repair_fee else None, + 'f05_44_grading_fee': float(collection_item.f05_44_grading_fee) if collection_item.f05_44_grading_fee else None, + 'f06_50_purpose': collection_item.f06_50_purpose, + 'f99_92_created_at': collection_item.f99_92_created_at.isoformat() if collection_item.f99_92_created_at else None, 'images': [] } # 加载图片数据 from app.models.models import CollectionImage images = db.query(CollectionImage).filter( - CollectionImage.collection_id == item.f99_90_id + CollectionImage.collection_id == collection_item.f99_90_id ).all() for img in images: diff --git a/config/VERSION b/config/VERSION index 94dfc72..946544f 100644 --- a/config/VERSION +++ b/config/VERSION @@ -2,7 +2,7 @@ # Version Configuration for Zodiac Collection Management System # 当前版本号 (语义化版本:主版本。次版本.修订版) -VERSION=1.1.9 +VERSION=1.2.0 # 版本代号 (可选) VERSION_CODENAME="新生" diff --git a/frontend/index.html b/frontend/index.html index a9c1bc5..a5c51ce 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -4,7 +4,7 @@ - 甲辰收藏 v1.1.8 + 甲辰收藏 v1.1.9 diff --git a/frontend/src/pages/List.jsx b/frontend/src/pages/List.jsx index 52f54fa..b3aa459 100644 --- a/frontend/src/pages/List.jsx +++ b/frontend/src/pages/List.jsx @@ -343,7 +343,7 @@ export default function List() {
goDetail(item.id)} style={{ background: 'rgba(255,255,255,0.03)', border: '1px solid rgba(255,255,255,0.05)', borderRadius: '12px', padding: '14px', marginBottom: '10px', cursor: 'pointer' }}>
- {isAdmin && item.user &&
👤 {item.username}
} + {isAdmin && item.owner_name &&
👤 {item.owner_name}
}
{item.code || '-'}
{item.prefixSerial || '-'}