feat: 增加会员服务与估价模版智能体

会员服务改为固定栏目,首页在线服务不再进入报告审核。估价模版智能体可多会话制作模版并下载,下载过程显示加载状态。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-11-23 13:36:19 +08:00
1 parent 55b5a87482
commit 2074a45681
63 files changed
+6428 -461

No files matched your search

+289
View File
@@ -0,0 +1,289 @@
from fastapi import APIRouter, Depends, HTTPException, Query, status
from pydantic import BaseModel, Field
from sqlalchemy import select
from sqlalchemy.orm import Session
from app.core.deps import require_staff
from app.db import get_db
from app.models.membership import (
admin_org_links,
create_event,
create_profile,
create_registration,
delete_event,
delete_profile,
delete_registration,
list_events,
list_profiles,
list_registrations,
read_event,
read_profile,
read_registration,
save_org_links,
update_event,
update_profile,
update_registration,
)
from app.models.member import SiteMember
from app.services.email_code import normalize_email
from app.services.password import DEFAULT_MEMBER_PASSWORD, hash_password, validate_member_password
router = APIRouter(dependencies=[Depends(require_staff)])
class OrgLinkWrite(BaseModel):
name: str = ""
url: str = ""
imageFileId: int | None = None
sortOrder: int = 0
class OrgLinksWrite(BaseModel):
items: list[OrgLinkWrite] = Field(default_factory=list)
class ProfileWrite(BaseModel):
email: str = ""
password: str | None = None
kind: str = "individual"
memberNo: str = ""
membershipStatus: str = "active"
joinedOn: str = ""
expiresOn: str = ""
feeStatus: str = "unpaid"
mobile: str = ""
region: str = ""
address: str = ""
postalCode: str = ""
remark: str = ""
personName: str = ""
gender: str = ""
birthDate: str = ""
idCard: str = ""
education: str = ""
major: str = ""
jobTitle: str = ""
practiceYears: int | None = None
employer: str = ""
position: str = ""
appraiserRegNo: str = ""
qualificationNo: str = ""
regValidUntil: str = ""
photoFileId: int | None = None
orgName: str = ""
creditCode: str = ""
qualificationLevel: str = ""
filingNo: str = ""
legalPerson: str = ""
contactName: str = ""
contactPosition: str = ""
contactMobile: str = ""
contactEmail: str = ""
officeAddress: str = ""
class EventWrite(BaseModel):
title: str = ""
place: str = ""
startsOn: str = ""
endsOn: str = ""
quota: int | None = None
bodyHtml: str = ""
published: bool = False
mealNote: str = ""
mealDates: list[str] = Field(default_factory=list)
payeeName: str = ""
bankName: str = ""
bankAccount: str = ""
transferNote: str = ""
lodgingNote: str = ""
class RegistrationWrite(BaseModel):
region: str = ""
orgName: str = ""
personName: str = ""
gender: str = ""
position: str = ""
idCard: str = ""
mobile: str = ""
appraiserRegNo: str = ""
email: str = ""
lodging: str = "self"
roomStandard: bool = False
roomSingle: bool = False
standardCount: int = 0
singleCount: int = 0
dine: bool = False
mealDates: list[str] = Field(default_factory=list)
def _bad(exc: Exception) -> None:
if isinstance(exc, LookupError):
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(exc)) from exc
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(exc)) from exc
def _password(value: str | None, *, default_if_blank: bool) -> str | None:
password = (value or "").strip()
if not password:
if not default_if_blank:
return None
password = DEFAULT_MEMBER_PASSWORD
validate_member_password(password)
return hash_password(password)
def _is_new_portal_account(db: Session, email: str) -> bool:
normalized = normalize_email(email or "")
if not normalized:
return True
found = db.scalar(select(SiteMember.id).where(SiteMember.email == normalized))
return found is None
@router.get("/membership/orgs")
def read_orgs(db: Session = Depends(get_db)) -> dict:
return admin_org_links(db)
@router.put("/membership/orgs")
def write_orgs(body: OrgLinksWrite, db: Session = Depends(get_db)) -> dict:
try:
save_org_links(db, [item.model_dump() for item in body.items])
except ValueError as exc:
_bad(exc)
return {"ok": True}
@router.get("/membership/profiles")
def read_profiles(
current: int = Query(default=1),
size: int = Query(default=10),
keyword: str = Query(default=""),
db: Session = Depends(get_db),
) -> dict:
return list_profiles(db, current=current, size=size, keyword=keyword)
@router.post("/membership/profiles")
def add_profile(body: ProfileWrite, db: Session = Depends(get_db)) -> dict:
try:
return create_profile(
db,
body.model_dump(),
_password(body.password, default_if_blank=_is_new_portal_account(db, body.email)),
)
except (ValueError, LookupError) as exc:
_bad(exc)
@router.get("/membership/profiles/{profile_id}")
def get_profile(profile_id: int, db: Session = Depends(get_db)) -> dict:
try:
return read_profile(db, profile_id, reveal=True)
except LookupError as exc:
_bad(exc)
@router.put("/membership/profiles/{profile_id}")
def edit_profile(profile_id: int, body: ProfileWrite, db: Session = Depends(get_db)) -> dict:
try:
return update_profile(db, profile_id, body.model_dump(), _password(body.password, default_if_blank=False))
except (ValueError, LookupError) as exc:
_bad(exc)
@router.delete("/membership/profiles/{profile_id}")
def remove_profile(profile_id: int, db: Session = Depends(get_db)) -> dict:
try:
delete_profile(db, profile_id)
except LookupError as exc:
_bad(exc)
return {"ok": True}
@router.get("/membership/events")
def read_events(db: Session = Depends(get_db)) -> dict:
return list_events(db, published_only=False)
@router.post("/membership/events")
def add_event(body: EventWrite, db: Session = Depends(get_db)) -> dict:
try:
return create_event(db, body.model_dump())
except ValueError as exc:
_bad(exc)
@router.get("/membership/events/{event_id}")
def get_event(event_id: int, db: Session = Depends(get_db)) -> dict:
try:
return read_event(db, event_id, published_only=False)
except LookupError as exc:
_bad(exc)
@router.put("/membership/events/{event_id}")
def edit_event(event_id: int, body: EventWrite, db: Session = Depends(get_db)) -> dict:
try:
return update_event(db, event_id, body.model_dump())
except (ValueError, LookupError) as exc:
_bad(exc)
@router.delete("/membership/events/{event_id}")
def remove_event(event_id: int, db: Session = Depends(get_db)) -> dict:
try:
delete_event(db, event_id)
except LookupError as exc:
_bad(exc)
return {"ok": True}
@router.get("/membership/events/{event_id}/registrations")
def read_registrations(event_id: int, db: Session = Depends(get_db)) -> dict:
try:
return list_registrations(db, event_id, reveal=False)
except LookupError as exc:
_bad(exc)
@router.post("/membership/events/{event_id}/registrations")
def add_registration(event_id: int, body: RegistrationWrite, db: Session = Depends(get_db)) -> dict:
try:
return create_registration(
db,
event_id,
body.model_dump(),
site_member_id=None,
enforce_quota=False,
published_only=False,
)
except (ValueError, LookupError) as exc:
_bad(exc)
@router.get("/membership/registrations/{registration_id}")
def get_registration(registration_id: int, db: Session = Depends(get_db)) -> dict:
try:
return read_registration(db, registration_id)
except LookupError as exc:
_bad(exc)
@router.put("/membership/registrations/{registration_id}")
def edit_registration(registration_id: int, body: RegistrationWrite, db: Session = Depends(get_db)) -> dict:
try:
return update_registration(db, registration_id, body.model_dump())
except (ValueError, LookupError) as exc:
_bad(exc)
@router.delete("/membership/registrations/{registration_id}")
def remove_registration(registration_id: int, db: Session = Depends(get_db)) -> dict:
try:
delete_registration(db, registration_id)
except LookupError as exc:
_bad(exc)
return {"ok": True}