2026-04-04 18:17:10 +08:00
|
|
|
from sqlalchemy import Column, Integer, String, Float, Boolean, DateTime, ForeignKey, Text, JSON
|
|
|
|
|
from sqlalchemy.sql import func
|
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InspectionPlan(Base):
|
|
|
|
|
__tablename__ = "inspection_plans"
|
|
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
|
name = Column(String(200), nullable=False)
|
|
|
|
|
description = Column(Text)
|
|
|
|
|
device_group_id = Column(Integer, ForeignKey("device_groups.id"))
|
|
|
|
|
device_ids = Column(JSON) # specific devices to inspect
|
|
|
|
|
schedule_type = Column(String(20)) # daily, weekly, monthly, custom
|
|
|
|
|
schedule_cron = Column(String(100)) # cron expression for custom
|
|
|
|
|
inspector_id = Column(Integer, ForeignKey("users.id"))
|
|
|
|
|
checklist = Column(JSON) # [{item: "检查外观", required: true, type: "checkbox"}]
|
|
|
|
|
is_active = Column(Boolean, default=True)
|
|
|
|
|
next_run_at = Column(DateTime(timezone=True))
|
|
|
|
|
created_by = Column(Integer, ForeignKey("users.id"))
|
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InspectionRecord(Base):
|
|
|
|
|
__tablename__ = "inspection_records"
|
|
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
|
plan_id = Column(Integer, ForeignKey("inspection_plans.id"), nullable=False)
|
|
|
|
|
inspector_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
|
|
|
status = Column(String(20), default="pending") # pending, in_progress, completed, issues_found
|
|
|
|
|
findings = Column(JSON) # [{item, result, note, photo_url}]
|
|
|
|
|
started_at = Column(DateTime(timezone=True))
|
|
|
|
|
completed_at = Column(DateTime(timezone=True))
|
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RepairOrder(Base):
|
|
|
|
|
__tablename__ = "repair_orders"
|
|
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
|
code = Column(String(50), unique=True, nullable=False) # WO-20260402-001
|
feat: v2.0 — maintenance module, AI analysis, station power fix
- Add full 检修维护中心 (6.4): 3-type work orders (消缺/巡检/抄表),
asset management, warehouse, work plans, billing settlement
- Add AI智能分析 tab with LLM-powered diagnostics (StepFun + ZhipuAI)
- Add AI模型配置 settings page (provider, temperature, prompts)
- Fix station power accuracy: use API station total (station_power)
instead of inverter-level computation — eliminates timing gaps
- Add 7 new DB models, 4 new API routers, 5 new frontend pages
- Migrations: 009 (maintenance expansion) + 010 (AI analysis)
- Version bump: 1.6.1 → 2.0.0
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 21:16:03 +08:00
|
|
|
order_type = Column(String(20), default="repair") # repair(消缺), inspection(巡检), meter_reading(抄表)
|
2026-04-04 18:17:10 +08:00
|
|
|
title = Column(String(200), nullable=False)
|
|
|
|
|
description = Column(Text)
|
|
|
|
|
device_id = Column(Integer, ForeignKey("devices.id"))
|
feat: v2.0 — maintenance module, AI analysis, station power fix
- Add full 检修维护中心 (6.4): 3-type work orders (消缺/巡检/抄表),
asset management, warehouse, work plans, billing settlement
- Add AI智能分析 tab with LLM-powered diagnostics (StepFun + ZhipuAI)
- Add AI模型配置 settings page (provider, temperature, prompts)
- Fix station power accuracy: use API station total (station_power)
instead of inverter-level computation — eliminates timing gaps
- Add 7 new DB models, 4 new API routers, 5 new frontend pages
- Migrations: 009 (maintenance expansion) + 010 (AI analysis)
- Version bump: 1.6.1 → 2.0.0
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 21:16:03 +08:00
|
|
|
station_name = Column(String(200))
|
2026-04-04 18:17:10 +08:00
|
|
|
alarm_event_id = Column(Integer, ForeignKey("alarm_events.id"))
|
|
|
|
|
priority = Column(String(20), default="medium") # critical, high, medium, low
|
|
|
|
|
status = Column(String(20), default="open") # open, assigned, in_progress, completed, verified, closed
|
|
|
|
|
assigned_to = Column(Integer, ForeignKey("users.id"))
|
|
|
|
|
resolution = Column(Text)
|
|
|
|
|
cost_estimate = Column(Float)
|
|
|
|
|
actual_cost = Column(Float)
|
|
|
|
|
created_by = Column(Integer, ForeignKey("users.id"))
|
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
|
assigned_at = Column(DateTime(timezone=True))
|
|
|
|
|
completed_at = Column(DateTime(timezone=True))
|
|
|
|
|
closed_at = Column(DateTime(timezone=True))
|
feat: v2.0 — maintenance module, AI analysis, station power fix
- Add full 检修维护中心 (6.4): 3-type work orders (消缺/巡检/抄表),
asset management, warehouse, work plans, billing settlement
- Add AI智能分析 tab with LLM-powered diagnostics (StepFun + ZhipuAI)
- Add AI模型配置 settings page (provider, temperature, prompts)
- Fix station power accuracy: use API station total (station_power)
instead of inverter-level computation — eliminates timing gaps
- Add 7 new DB models, 4 new API routers, 5 new frontend pages
- Migrations: 009 (maintenance expansion) + 010 (AI analysis)
- Version bump: 1.6.1 → 2.0.0
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 21:16:03 +08:00
|
|
|
due_date = Column(DateTime(timezone=True)) # 要求完成时间
|
2026-04-04 18:17:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class DutySchedule(Base):
|
|
|
|
|
__tablename__ = "duty_schedules"
|
|
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
|
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
|
|
|
duty_date = Column(DateTime(timezone=True), nullable=False)
|
|
|
|
|
shift = Column(String(20)) # day, night, on_call
|
|
|
|
|
area_id = Column(Integer, ForeignKey("device_groups.id"))
|
|
|
|
|
notes = Column(Text)
|
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
feat: v2.0 — maintenance module, AI analysis, station power fix
- Add full 检修维护中心 (6.4): 3-type work orders (消缺/巡检/抄表),
asset management, warehouse, work plans, billing settlement
- Add AI智能分析 tab with LLM-powered diagnostics (StepFun + ZhipuAI)
- Add AI模型配置 settings page (provider, temperature, prompts)
- Fix station power accuracy: use API station total (station_power)
instead of inverter-level computation — eliminates timing gaps
- Add 7 new DB models, 4 new API routers, 5 new frontend pages
- Migrations: 009 (maintenance expansion) + 010 (AI analysis)
- Version bump: 1.6.1 → 2.0.0
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 21:16:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class AssetCategory(Base):
|
|
|
|
|
__tablename__ = "asset_categories"
|
|
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
|
name = Column(String(100), nullable=False)
|
|
|
|
|
parent_id = Column(Integer, ForeignKey("asset_categories.id"), nullable=True)
|
|
|
|
|
description = Column(Text)
|
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Asset(Base):
|
|
|
|
|
__tablename__ = "assets"
|
|
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
|
name = Column(String(200), nullable=False)
|
|
|
|
|
asset_code = Column(String(50), unique=True)
|
|
|
|
|
category_id = Column(Integer, ForeignKey("asset_categories.id"))
|
|
|
|
|
device_id = Column(Integer, ForeignKey("devices.id"), nullable=True)
|
|
|
|
|
station_name = Column(String(200))
|
|
|
|
|
manufacturer = Column(String(200))
|
|
|
|
|
model_number = Column(String(100))
|
|
|
|
|
serial_number = Column(String(100))
|
|
|
|
|
purchase_date = Column(DateTime(timezone=True))
|
|
|
|
|
warranty_expiry = Column(DateTime(timezone=True))
|
|
|
|
|
purchase_price = Column(Float)
|
|
|
|
|
status = Column(String(20), default="active")
|
|
|
|
|
location = Column(String(200))
|
|
|
|
|
responsible_dept = Column(String(100))
|
|
|
|
|
custodian = Column(String(100))
|
|
|
|
|
supplier = Column(String(200))
|
|
|
|
|
notes = Column(Text)
|
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AssetChange(Base):
|
|
|
|
|
__tablename__ = "asset_changes"
|
|
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
|
asset_id = Column(Integer, ForeignKey("assets.id"), nullable=False)
|
|
|
|
|
change_type = Column(String(20))
|
|
|
|
|
change_date = Column(DateTime(timezone=True))
|
|
|
|
|
description = Column(Text)
|
|
|
|
|
old_value = Column(JSON)
|
|
|
|
|
new_value = Column(JSON)
|
|
|
|
|
operator_id = Column(Integer, ForeignKey("users.id"))
|
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SparePart(Base):
|
|
|
|
|
__tablename__ = "spare_parts"
|
|
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
|
name = Column(String(200), nullable=False)
|
|
|
|
|
part_code = Column(String(50), unique=True)
|
|
|
|
|
category = Column(String(100))
|
|
|
|
|
specification = Column(String(200))
|
|
|
|
|
unit = Column(String(20))
|
|
|
|
|
current_stock = Column(Integer, default=0)
|
|
|
|
|
min_stock = Column(Integer, default=0)
|
|
|
|
|
max_stock = Column(Integer)
|
|
|
|
|
warehouse_location = Column(String(100))
|
|
|
|
|
unit_price = Column(Float)
|
|
|
|
|
supplier = Column(String(200))
|
|
|
|
|
notes = Column(Text)
|
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WarehouseTransaction(Base):
|
|
|
|
|
__tablename__ = "warehouse_transactions"
|
|
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
|
spare_part_id = Column(Integer, ForeignKey("spare_parts.id"), nullable=False)
|
|
|
|
|
transaction_type = Column(String(20))
|
|
|
|
|
quantity = Column(Integer, nullable=False)
|
|
|
|
|
unit_price = Column(Float)
|
|
|
|
|
total_price = Column(Float)
|
|
|
|
|
transaction_date = Column(DateTime(timezone=True))
|
|
|
|
|
work_order_id = Column(Integer, ForeignKey("repair_orders.id"), nullable=True)
|
|
|
|
|
reason = Column(String(200))
|
|
|
|
|
operator_id = Column(Integer, ForeignKey("users.id"))
|
|
|
|
|
notes = Column(Text)
|
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MaintenanceWorkPlan(Base):
|
|
|
|
|
__tablename__ = "maintenance_work_plans"
|
|
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
|
name = Column(String(200), nullable=False)
|
|
|
|
|
plan_type = Column(String(20))
|
|
|
|
|
station_name = Column(String(200))
|
|
|
|
|
device_ids = Column(JSON)
|
|
|
|
|
cycle_period = Column(String(20))
|
|
|
|
|
execution_days = Column(Integer)
|
|
|
|
|
effective_start = Column(DateTime(timezone=True))
|
|
|
|
|
effective_end = Column(DateTime(timezone=True))
|
|
|
|
|
description = Column(Text)
|
|
|
|
|
workflow_config = Column(JSON)
|
|
|
|
|
is_active = Column(Boolean, default=True)
|
|
|
|
|
created_by = Column(Integer, ForeignKey("users.id"))
|
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BillingRecord(Base):
|
|
|
|
|
__tablename__ = "billing_records"
|
|
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
|
station_name = Column(String(200))
|
|
|
|
|
billing_type = Column(String(20))
|
|
|
|
|
billing_period_start = Column(DateTime(timezone=True))
|
|
|
|
|
billing_period_end = Column(DateTime(timezone=True))
|
|
|
|
|
generation_kwh = Column(Float)
|
|
|
|
|
self_use_kwh = Column(Float)
|
|
|
|
|
grid_feed_kwh = Column(Float)
|
|
|
|
|
electricity_price = Column(Float)
|
|
|
|
|
self_use_price = Column(Float)
|
|
|
|
|
feed_in_tariff = Column(Float)
|
|
|
|
|
total_amount = Column(Float)
|
|
|
|
|
self_use_amount = Column(Float)
|
|
|
|
|
feed_in_amount = Column(Float)
|
|
|
|
|
subsidy_amount = Column(Float)
|
|
|
|
|
status = Column(String(20), default="pending")
|
|
|
|
|
invoice_number = Column(String(100))
|
|
|
|
|
invoice_date = Column(DateTime(timezone=True))
|
|
|
|
|
attachment_url = Column(String(500))
|
|
|
|
|
notes = Column(Text)
|
|
|
|
|
created_by = Column(Integer, ForeignKey("users.id"))
|
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|