会员服务改为固定栏目,首页在线服务不再进入报告审核。估价模版智能体可多会话制作模版并下载,下载过程显示加载状态。 Co-authored-by: Cursor <cursoragent@cursor.com>
298 lines
10 KiB
Python
298 lines
10 KiB
Python
"""写入会员服务演示数据,供本地查看。
|
|
|
|
同名外链、同标题资讯、同名会议和同一登录邮箱已存在则跳过。
|
|
演示账号口令写在本命令里,只用于本地库,不是生产口令。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import struct
|
|
import zlib
|
|
from html import escape
|
|
|
|
from sqlalchemy import func, select
|
|
|
|
from app.db import Base, SessionLocal, get_engine
|
|
from app.models.content import AdminFile
|
|
from app.models.home import HomeArticle, create_article
|
|
from app.models.member import SiteMember
|
|
from app.models.membership import (
|
|
AssociationProfile,
|
|
MemberOrgLink,
|
|
TrainingEvent,
|
|
TrainingRegistration,
|
|
create_profile,
|
|
create_registration,
|
|
save_org_links,
|
|
)
|
|
from app.services.password import hash_password
|
|
from app.services.storage import ensure_buckets, make_object_key, upload_object
|
|
|
|
DEMO_PASSWORD = "Member123"
|
|
INDIVIDUAL_EMAIL = "member.zhang@example.com"
|
|
ORGANIZATION_EMAIL = "member.org@example.com"
|
|
|
|
|
|
def _png(width: int, height: int, rgb: tuple[int, int, int]) -> bytes:
|
|
def chunk(tag: bytes, data: bytes) -> bytes:
|
|
return struct.pack(">I", len(data)) + tag + data + struct.pack(">I", zlib.crc32(tag + data) & 0xFFFFFFFF)
|
|
|
|
raw = b"".join(b"\x00" + bytes(rgb) * width for _ in range(height))
|
|
return (
|
|
b"\x89PNG\r\n\x1a\n"
|
|
+ chunk(b"IHDR", struct.pack(">IIBBBBB", width, height, 8, 2, 0, 0, 0))
|
|
+ chunk(b"IDAT", zlib.compress(raw))
|
|
+ chunk(b"IEND", b"")
|
|
)
|
|
|
|
|
|
def _store_png(db, filename: str, rgb: tuple[int, int, int]) -> AdminFile:
|
|
row = db.scalar(select(AdminFile).where(AdminFile.bucket == "public", AdminFile.filename == filename))
|
|
if row is not None:
|
|
return row
|
|
data = _png(640, 360, rgb)
|
|
key = make_object_key(filename)
|
|
upload_object("public", key, data, "image/png")
|
|
row = AdminFile(
|
|
bucket="public",
|
|
object_key=key,
|
|
filename=filename,
|
|
content_type="image/png",
|
|
size=len(data),
|
|
created_by=None,
|
|
)
|
|
db.add(row)
|
|
db.commit()
|
|
db.refresh(row)
|
|
return row
|
|
|
|
|
|
def _paragraphs(lines: list[str]) -> str:
|
|
return "".join(f"<p>{escape(line)}</p>" for line in lines)
|
|
|
|
|
|
def _seed_orgs(db) -> int:
|
|
if db.scalar(select(func.count()).select_from(MemberOrgLink)) :
|
|
return 0
|
|
cards = [
|
|
("中国房地产估价师与房地产经纪人学会", "https://www.cirea.org.cn/", "member-org-cirea.png", (12, 74, 150)),
|
|
("甘肃省住房和城乡建设厅", "http://zjt.gansu.gov.cn/", "member-org-gansu-zjt.png", (14, 116, 144)),
|
|
("住房和城乡建设部", "https://www.mohurd.gov.cn/", "member-org-mohurd.png", (22, 101, 52)),
|
|
]
|
|
items = []
|
|
for index, (name, url, filename, color) in enumerate(cards, start=1):
|
|
image = _store_png(db, filename, color)
|
|
items.append({"name": name, "url": url, "imageFileId": image.id, "sortOrder": index})
|
|
save_org_links(db, items)
|
|
return len(items)
|
|
|
|
|
|
def _seed_notices(db) -> int:
|
|
samples = [
|
|
(
|
|
"协会章程(演示)",
|
|
"2026-01-15T08:00:00",
|
|
["本条为本地演示数据,正式文本以协会发布的章程为准。", "章程说明协会宗旨、会员权利与义务、组织机构和议事规则。"],
|
|
),
|
|
(
|
|
"单位会员管理办法(演示)",
|
|
"2026-02-10T08:00:00",
|
|
["本条为本地演示数据。", "单位会员的入会、变更、年检和退会,按本办法办理。", "咨询电话:0931-8126195。"],
|
|
),
|
|
(
|
|
"会费管理办法(演示)",
|
|
"2026-02-20T08:00:00",
|
|
["本条为本地演示数据。", "会费标准、缴纳时间和减免情形以最新办法为准。"],
|
|
),
|
|
]
|
|
added = 0
|
|
for title, published_at, lines in samples:
|
|
exists = db.scalar(
|
|
select(HomeArticle.id).where(HomeArticle.category == "member_notices", HomeArticle.title == title)
|
|
)
|
|
if exists is not None:
|
|
continue
|
|
create_article(
|
|
db,
|
|
{
|
|
"category": "member_notices",
|
|
"title": title,
|
|
"publishedAt": published_at,
|
|
"published": True,
|
|
"bodyHtml": _paragraphs(lines),
|
|
"attachmentFileIds": [],
|
|
},
|
|
)
|
|
added += 1
|
|
return added
|
|
|
|
|
|
def _ensure_profile(db, payload: dict) -> None:
|
|
email = payload["email"]
|
|
account = db.scalar(select(SiteMember).where(SiteMember.email == email))
|
|
if account is not None and db.scalar(
|
|
select(AssociationProfile.id).where(AssociationProfile.site_member_id == account.id)
|
|
):
|
|
return
|
|
create_profile(db, payload, hash_password(DEMO_PASSWORD))
|
|
|
|
|
|
def _seed_profiles(db) -> None:
|
|
_ensure_profile(
|
|
db,
|
|
{
|
|
"email": INDIVIDUAL_EMAIL,
|
|
"kind": "individual",
|
|
"memberNo": "GS-P-2026-001",
|
|
"membershipStatus": "active",
|
|
"joinedOn": "2024-03-01",
|
|
"expiresOn": "2027-03-01",
|
|
"feeStatus": "paid",
|
|
"mobile": "13800001111",
|
|
"region": "甘肃省兰州市城关区",
|
|
"address": "张掖路63号",
|
|
"postalCode": "730030",
|
|
"personName": "张伟",
|
|
"gender": "male",
|
|
"birthDate": "1988-05-16",
|
|
"idCard": "620102198805161234",
|
|
"education": "本科",
|
|
"major": "工程管理",
|
|
"jobTitle": "房地产估价师",
|
|
"practiceYears": 12,
|
|
"employer": "兰州示例房地产估价有限公司",
|
|
"position": "估价师",
|
|
"appraiserRegNo": "6201028812",
|
|
"qualificationNo": "GS20140088",
|
|
"regValidUntil": "2028-06-30",
|
|
"remark": "本地演示个人会员",
|
|
},
|
|
)
|
|
_ensure_profile(
|
|
db,
|
|
{
|
|
"email": ORGANIZATION_EMAIL,
|
|
"kind": "organization",
|
|
"memberNo": "GS-O-2026-018",
|
|
"membershipStatus": "active",
|
|
"joinedOn": "2019-06-18",
|
|
"expiresOn": "2026-12-31",
|
|
"feeStatus": "unpaid",
|
|
"mobile": "13900002222",
|
|
"region": "甘肃省兰州市七里河区",
|
|
"address": "西津西路100号",
|
|
"postalCode": "730050",
|
|
"orgName": "兰州示例房地产估价有限公司",
|
|
"creditCode": "91620100MA1234567X",
|
|
"qualificationLevel": "二级",
|
|
"filingNo": "甘估备20190018",
|
|
"legalPerson": "赵敏",
|
|
"officeAddress": "兰州市七里河区西津西路100号",
|
|
"contactName": "赵敏",
|
|
"contactPosition": "总经理",
|
|
"contactMobile": "13900002222",
|
|
"contactEmail": ORGANIZATION_EMAIL,
|
|
"remark": "本地演示机构会员",
|
|
},
|
|
)
|
|
|
|
|
|
def _seed_training(db) -> str:
|
|
title = "2026年房地产估价业务培训会(演示)"
|
|
event = db.scalar(select(TrainingEvent).where(TrainingEvent.title == title))
|
|
if event is None:
|
|
from app.models.membership import create_event
|
|
|
|
created = create_event(
|
|
db,
|
|
{
|
|
"title": title,
|
|
"place": "兰州市城关区",
|
|
"startsOn": "2026-07-29",
|
|
"endsOn": "2026-07-31",
|
|
"quota": 40,
|
|
"published": True,
|
|
"mealNote": "午餐自助餐80元/位",
|
|
"mealDates": ["7月29日", "7月30日", "7月31日"],
|
|
"payeeName": "甘肃省房地产价格评估行业协会",
|
|
"bankName": "招商银行兰州中央广场支行",
|
|
"bankAccount": "931904878610818",
|
|
"transferNote": "转账备注请写单位简称、参会人姓名、房间和用餐数量",
|
|
"lodgingNote": "酒店食宿标准详见本场会议通知。",
|
|
"bodyHtml": _paragraphs(
|
|
[
|
|
"本条为本地演示数据。",
|
|
"会议时间:2026年7月29日至7月31日。",
|
|
"用餐日期可多选:7月29日、7月30日、7月31日。",
|
|
"住宿可选协会代订或自理。",
|
|
]
|
|
),
|
|
},
|
|
)
|
|
event_id = created["id"]
|
|
else:
|
|
event_id = event.id
|
|
account = db.scalar(select(SiteMember).where(SiteMember.email == INDIVIDUAL_EMAIL))
|
|
if account is None:
|
|
return "培训公告已在,个人会员账号不存在,未写报名"
|
|
exists = db.scalar(
|
|
select(TrainingRegistration.id).where(
|
|
TrainingRegistration.event_id == event_id,
|
|
TrainingRegistration.email == INDIVIDUAL_EMAIL,
|
|
)
|
|
)
|
|
if exists is None:
|
|
create_registration(
|
|
db,
|
|
event_id,
|
|
{
|
|
"region": "甘肃省兰州市城关区",
|
|
"orgName": "兰州示例房地产估价有限公司",
|
|
"personName": "张伟",
|
|
"gender": "male",
|
|
"position": "估价师",
|
|
"idCard": "620102198805161234",
|
|
"mobile": "13800001111",
|
|
"appraiserRegNo": "6201028812",
|
|
"email": INDIVIDUAL_EMAIL,
|
|
"lodging": "association",
|
|
"roomStandard": True,
|
|
"standardCount": 1,
|
|
"dine": True,
|
|
"mealDates": ["7月29日", "7月30日"],
|
|
},
|
|
site_member_id=account.id,
|
|
enforce_quota=False,
|
|
published_only=False,
|
|
)
|
|
return "已写培训公告,并为张伟报名两天用餐"
|
|
return "培训公告和张伟的报名已在,跳过"
|
|
|
|
|
|
def seed() -> None:
|
|
import app.models.content # noqa: F401
|
|
import app.models.home # noqa: F401
|
|
import app.models.member # noqa: F401
|
|
import app.models.membership # noqa: F401
|
|
|
|
ensure_buckets()
|
|
engine = get_engine()
|
|
Base.metadata.create_all(bind=engine)
|
|
SessionLocal.configure(bind=engine)
|
|
db = SessionLocal()
|
|
try:
|
|
orgs = _seed_orgs(db)
|
|
notices = _seed_notices(db)
|
|
_seed_profiles(db)
|
|
training = _seed_training(db)
|
|
print(f"会员机构:新增 {orgs} 条。")
|
|
print(f"会员资讯:新增 {notices} 条。")
|
|
print(f"会员账号:{INDIVIDUAL_EMAIL} 、{ORGANIZATION_EMAIL}")
|
|
print(training)
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
seed()
|