refactor: 彻底删除实际模块status字段

- 数据库: DROP project_finances.status 列(幂等迁移)
- 后端: routes.py移除status过滤(12处), helpers.py修复SQL
- 后端: 删除migrate_move_pending_to_plan, seed_data移除status
- 前端: finance.js/performance.js/utils.js全部清除status引用
- finFilter默认值改为projects
- 版本号 v1.0.0.23
This commit is contained in:
mac
2026-07-08 13:46:10 +08:00
parent a57cba8043
commit e21d41b218
10 changed files with 60 additions and 94 deletions

View File

@@ -17,7 +17,7 @@ def run_migrations():
"""
from migrations.tables import migrate_create_tables
from migrations.columns import migrate_add_columns
from migrations.data_fixes import migrate_fix_task_status, migrate_rename_tenant, migrate_drop_product_fields, migrate_fix_service_fee_standard, migrate_fix_expense_status, migrate_move_pending_to_plan
from migrations.data_fixes import migrate_fix_task_status, migrate_rename_tenant, migrate_drop_product_fields, migrate_fix_service_fee_standard, migrate_fix_expense_status
from migrations.data_split import migrate_data_split
from migrations.seed import migrate_seed_users, migrate_seed_demo_data
@@ -28,7 +28,6 @@ def run_migrations():
migrate_drop_product_fields()
migrate_fix_service_fee_standard()
migrate_fix_expense_status()
migrate_move_pending_to_plan()
migrate_data_split()
migrate_seed_users()
migrate_seed_demo_data()

View File

@@ -122,6 +122,12 @@ def migrate_add_columns():
cur.execute("ALTER TABLE plan_finances DROP COLUMN status")
conn.commit()
print("[migrate] plan_finances.status 列已删除")
# 删除 project_finances.status 列(实际模块不再需要状态字段)
cur.execute("SHOW COLUMNS FROM project_finances LIKE 'status'")
if cur.fetchone():
cur.execute("ALTER TABLE project_finances DROP COLUMN status")
conn.commit()
print("[migrate] project_finances.status 列已删除")
cur.close()
finally:
conn.close()

View File

@@ -114,34 +114,3 @@ def migrate_fix_expense_status():
conn.close()
def migrate_move_pending_to_plan():
"""迁移业务待签约项目到计划模块(幂等)"""
from db import db
conn = db()
try:
cur = conn.cursor()
# 获取 plan_finances 的列名(排除 status因计划模块已删除该列
cur.execute("SHOW COLUMNS FROM plan_finances")
plan_cols = [row[0] for row in cur.fetchall()]
col_list = ", ".join(plan_cols)
# 仅迁移 id 不存在于计划表的待签约项目
cur.execute(
f"INSERT INTO plan_finances ({col_list}) "
f"SELECT {col_list} FROM project_finances WHERE status='待签约' "
f"AND id NOT IN (SELECT id FROM plan_finances)"
)
moved = cur.rowcount
if moved:
# 删除已迁移的原记录
cur.execute(
"DELETE FROM project_finances WHERE status='待签约' "
"AND id IN (SELECT id FROM plan_finances)"
)
deleted = cur.rowcount
conn.commit()
print(f"[migrate] 待签约项目迁移到计划: {moved} 条 (已删除 {deleted} 条)")
cur.close()
finally:
conn.close()

View File

@@ -72,7 +72,7 @@ def make_budget_data(sign_amount, signed_month, status):
"""生成12个月的预算数据"""
months = []
start_m = int(signed_month.split("-")[1]) if signed_month else 1
rev_total = sign_amount if status == "已签约" else int(sign_amount * random.uniform(0.3, 0.7))
rev_total = sign_amount
gross_rate = random.uniform(0.25, 0.55)
payment_rate = random.uniform(0.7, 0.95)
@@ -135,17 +135,17 @@ def seed_db():
cust_idx += i % 3
# 70% 已签约, 30% 待签约
status = "已签约" if random.random() < 0.7 else "待签约"
sign_month = f"2026-{random.randint(1, 6):02d}" if status == "已签约" else ""
status = "已签约"
sign_month = f"2026-{random.randint(1, 6):02d}"
project_code = f"{tenant[:2]}-2026-{i+1:03d}"
business_type = random.choice(["学术推广", "医生教育", "患者管理", "科研合作", "科普内容"])
# 如果签约,总额 = 签约额否则为0
total_rev = int(sign_amount * random.uniform(0.8, 1.0)) if status == "已签约" else 0
total_gross = int(total_rev * random.uniform(0.25, 0.5)) if status == "已签约" else 0
total_payment = int(total_rev * random.uniform(0.7, 0.9)) if status == "已签约" else 0
total_cost = int(total_rev * random.uniform(0.3, 0.5)) if status == "已签约" else 0
total_paid = int(total_cost * random.uniform(0.7, 0.95)) if status == "已签约" else 0
total_rev = int(sign_amount * random.uniform(0.8, 1.0))
total_gross = int(total_rev * random.uniform(0.25, 0.5))
total_payment = int(total_rev * random.uniform(0.7, 0.9))
total_cost = int(total_rev * random.uniform(0.3, 0.5))
total_paid = int(total_cost * random.uniform(0.7, 0.95))
budget_data = make_budget_data(sign_amount, sign_month, status)
expense_data = make_expense_data() if status == "已签约" else "[]"
@@ -157,16 +157,16 @@ def seed_db():
cur = _exec(conn, """
INSERT INTO project_finances
(tenant, project_id, business_type, customer_name, sign_amount, sign_month, status,
(tenant, project_id, business_type, customer_name, sign_amount, sign_month,
sales_person, total_rev, total_gross, total_payment, total_cost, total_paid,
budget_data, expense_data, task_data,
project_code, start_date, end_date, task_type, task_count,
service_fee_standard, project_manager, contact_name, contact_phone, other_info,
created_at, updated_at)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
""", (
tenant, f"PF-{tenant[:2]}-{i+1:04d}", business_type, cust_name,
sign_amount, sign_month, status,
sign_amount, sign_month,
f"销售{random.choice(['A','B','C','D'])}", total_rev, total_gross,
total_payment, total_cost, total_paid,
budget_data, expense_data, task_data,
@@ -178,7 +178,7 @@ def seed_db():
today, today,
))
# Store for later use
pf_ids.setdefault(tenant, []).append((cur.lastrowid, proj_name, cust_name, status))
pf_ids.setdefault(tenant, []).append((cur.lastrowid, proj_name, cust_name))
# operation_projects: 每个工作台 3-5 个
op_count = random.randint(3, 5)