- flask_app.py 1166行→33行纯入口
- 新建 db.py(配置+连接+SQL工具)
- 新建 helpers.py(attach_common/monthly_finance/add_file_index)
- 新建 routes.py(全路由 Blueprint + 装饰器 + TABLES)
- 新建 migrations/seed_data.py(seed_db 搬迁)
- migrations/{tables,columns,data_fixes,seed}.py 改 import 为 from db
- 删除死代码 init_db(228行)+ latest_followup(10行)
- 反向依赖消除:migrations 不再 import flask_app
- 前端零改动,URL 不变
128 lines
8.8 KiB
Python
128 lines
8.8 KiB
Python
# seed_data.py — 初始示例数据填充(仅在空库时执行一次)
|
||
# 从 flask_app.py 搬迁,被 migrations/seed.py 调用
|
||
|
||
from datetime import date
|
||
from pathlib import Path
|
||
from db import db, _exec, one, WEIXIN_BASE
|
||
from helpers import add_file_index
|
||
|
||
|
||
def seed_db():
|
||
"""填充初始示例数据(仅在空库时执行一次)"""
|
||
conn = db()
|
||
try:
|
||
if one(conn, "SELECT id FROM sales_leads LIMIT 1"):
|
||
return # 已有数据,跳过
|
||
|
||
sales = [
|
||
("齐鲁制药", "P0", "跟进中", "多产品线科普年度框架,需推进高层沟通。"),
|
||
("百利天恒", "P0", "方案中", "BL-B01D1 上市前医生教育机会,准备方案。"),
|
||
("信达生物", "P0", "已签约", "现有科普项目升级/续约,重点保障执行。"),
|
||
("三生制药", "P1", "待跟进", "多科室医生教育+患者科普机会。"),
|
||
("天广实生物", "P1", "待跟进", "血液肿瘤医生教育机会。"),
|
||
]
|
||
for customer, priority, status, note in sales:
|
||
cur = _exec(conn,
|
||
"INSERT INTO sales_leads (target_customer, priority, status) VALUES (?,?,?)",
|
||
(customer, priority, status),
|
||
)
|
||
_exec(conn,
|
||
"INSERT INTO follow_up_records (target_type,target_id,followed_at,content,next_action) VALUES (?,?,?,?,?)",
|
||
("sales", cur.lastrowid, date.today().isoformat(), note, "明确下一次沟通人和时间"),
|
||
)
|
||
|
||
cur = _exec(conn,
|
||
"INSERT INTO business_proposals (customer_or_project_name,version,description,status,created_date) VALUES (?,?,?,?,?)",
|
||
("信达生物", "v1.5", "信达科普项目续约与报价方案", "已提交客户", "2026-05-28"),
|
||
)
|
||
proposal_id = cur.lastrowid
|
||
proposal_dir = WEIXIN_BASE / "2、业务方案/信达/v1.5"
|
||
for category, names in {
|
||
"方案": ["整体方案.pptx", "整体方案.pdf"],
|
||
"成本": ["业务报价-2亿方案.xlsx", "业务报价-5250万方案.xlsx", "5、最新报价.xlsx"],
|
||
"SOP": ["SOP.docx"],
|
||
"财务流程": ["财务流程.docx"],
|
||
}.items():
|
||
for name in names:
|
||
add_file_index(conn, "proposal", proposal_id, "v1.5", category, proposal_dir / name, external=True)
|
||
|
||
projects = [
|
||
("圆心科技 科普文章项目", "v2026-文章", "execution", "SOP 执行中", "内容生产", 55, "文章内容生产与审核执行中"),
|
||
("圆心科技 科普视频项目", "v2026-视频", "execution", "SOP 执行中", "内容生产", 45, "视频脚本、拍摄与审核推进"),
|
||
("圆心科技 科普专访项目", "v2026-专访", "opportunity", "方案已提交", "商务推进", 0, "专访项目推动签约"),
|
||
]
|
||
op_dir = WEIXIN_BASE / "3、运营方案"
|
||
for name, version, kind, status, stage, progress, note in projects:
|
||
cur = _exec(conn,
|
||
"""INSERT INTO operation_projects
|
||
(project_name,project_version,project_type,project_status,current_stage,target_customer,customer_need,
|
||
expected_contract_amount,expected_sign_date,sign_probability,next_action,sop_stage,execution_progress,current_deliverable)
|
||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)""",
|
||
(name, version, kind, status, stage, "圆心科技", "科普内容项目执行与管理", 0 if kind == "execution" else 200, "2026-06", 100 if kind == "execution" else 70, "补齐版本要求文件并更新下一节点", stage, progress, note),
|
||
)
|
||
_exec(conn,
|
||
"INSERT INTO follow_up_records (target_type,target_id,followed_at,content,next_action) VALUES (?,?,?,?,?)",
|
||
("operation", cur.lastrowid, date.today().isoformat(), note, "补齐版本要求文件并更新下一节点"),
|
||
)
|
||
|
||
file_map = [
|
||
(1, "v2026-文章", "项目方案", "圆心科技--科普文章项目(1).pptx"),
|
||
(2, "v2026-视频", "项目方案", "圆心科技-科普视频项目(1).pptx"),
|
||
(3, "v2026-专访", "项目方案", "圆心科技-科普专访项目-2026年(1).pdf"),
|
||
(1, "v2026-文章", "项目管理手册", "圆心科技《项目管理手册》-2026年.pdf"),
|
||
(2, "v2026-视频", "审核标准", "科普项目-审核标准(文章-视频-音频).pdf"),
|
||
]
|
||
for project_id, version, category, filename in file_map:
|
||
add_file_index(conn, "operation", project_id, version, category, op_dir / filename, external=True)
|
||
|
||
products = [
|
||
("妙手医生服务小程序", "v1.1", "视频任务增强 + 积分商城", "草稿箱、批量上传、积分商城、消息通知", "2026-Q3", "规划中", "科普平台"),
|
||
("数字化营销后台管理系统", "v1.2", "运营数据看板 + 智能审核", "医生活跃、任务完成率、AI 预审、渠道数据上报", "2026-Q3", "设计中", "真研平台"),
|
||
("妙手患者服务", "v0.5", "科普浏览 + 医生主页 MVP", "科普文章/视频浏览、医生主页、搜索", "2026-Q3", "规划中", "科普平台"),
|
||
("数字人内容平台", "v0.1", "基础数字人视频生成 MVP", "预设形象、AI 配音、脚本驱动、简单模板", "2026-Q3", "规划中", "科普平台"),
|
||
("渠道分发引擎", "v1.0", "六渠道统一分发", "分发 API、内容适配、分发排期、效果追踪", "2027-Q1", "规划中", "科普平台"),
|
||
]
|
||
for product in products:
|
||
cur = _exec(conn,
|
||
"INSERT INTO product_versions (product_name,version,version_goal,feature_list,launch_date,status,platform) VALUES (?,?,?,?,?,?,?)",
|
||
product,
|
||
)
|
||
_exec(conn,
|
||
"INSERT INTO follow_up_records (target_type,target_id,followed_at,content,next_action) VALUES (?,?,?,?,?)",
|
||
("product", cur.lastrowid, date.today().isoformat(), f"{product[0]} {product[1]}:{product[2]}", "按路线图推进"),
|
||
)
|
||
|
||
for month, record_type, category, amount, notes in [
|
||
("2026-05", "revenue", "信达生物续约确认收入", 120, "信达项目阶段确收"),
|
||
("2026-06", "revenue", "信达生物续约确认收入", 80, "信达项目尾款预估"),
|
||
("2026-05", "cost_expense", "内容生产", 32, "医生劳务与内容制作"),
|
||
("2026-05", "cost_expense", "运营管理", 16, "项目管理与渠道协同"),
|
||
("2026-06", "cost_expense", "渠道分发", 24, "投放与分发费用"),
|
||
]:
|
||
_exec(conn,
|
||
"INSERT INTO finance_records (month,record_type,category,amount,occurred_date,notes) VALUES (?,?,?,?,?,?)",
|
||
(month, record_type, category, amount, f"{month}-01", notes),
|
||
)
|
||
|
||
tasks_seed = [
|
||
("阶段1:渠道与商务确认", "商务对接", "合同签订", "Anna", "2026-06-30", "法务审核中", "合同签订后开始执行"),
|
||
("阶段1:渠道与商务确认", "官媒渠道确认", "沟通官媒确定", "段丽华", "2026-06-30", "官媒尽力推,以先达成合作为准", "集团支持"),
|
||
("阶段1:渠道与商务确认", "官媒渠道确认", "官媒合作签约", "段丽华", "2026-06-18", "", "官媒确认细节"),
|
||
("阶段2:系统与标准搭建", "系统开发上线", "音频专访系统开发上线", "戴敏/梁军营", "2026-06-18", "客户比较着急执行,需要技术的资源", ""),
|
||
("阶段2:系统与标准搭建", "系统开发上线", "精品视频系统开发上线", "戴敏/梁军营", "2026-06-25", "", ""),
|
||
("阶段2:系统与标准搭建", "标准与培训", "业务执行手册SOP", "胡龙飞", "2026-06-12", "", "系统开发上线"),
|
||
("阶段3:人员与审核入驻", "团队组建", "医学审核人员到位", "胡龙飞", "2026-06-15", "", "审核人员招聘"),
|
||
("阶段3:人员与审核入驻", "团队组建", "视频制作人员到位", "胡龙飞", "2026-06-18", "", "项目经理招聘"),
|
||
("阶段4:供应链与制作", "供应商准入", "准入拍摄/剪辑/主持人", "胡龙飞/侯亚凤", "2026-06-18", "", ""),
|
||
("阶段2:系统与标准搭建", "脚本生产及审核", "生产脚本", "军营", "2026-06-12", "脚本目前生产比较机械,需要提前准备", "细分标签领域完成"),
|
||
]
|
||
for phase, milestone, task, owner, due_date, blockers, notes in tasks_seed:
|
||
_exec(conn,
|
||
"INSERT INTO project_tasks (project_id,phase,milestone,task,owner,due_date,blockers,notes) VALUES (?,?,?,?,?,?,?,?)",
|
||
(1, phase, milestone, task, owner, due_date, blockers, notes),
|
||
)
|
||
|
||
conn.commit()
|
||
finally:
|
||
conn.close()
|