Files
s2f/backend/app/models/cost_analysis.py
selfrelease 5278190750 feat: 凭证生成、成本分析、AI问答、前端页面、集成测试与E2E测试
- 后端: 凭证生成引擎、金蝶导出器、凭证模板服务
- 后端: 成本分析服务、AI问答服务
- 后端: 科目映射CRUD API、分析API、QA API
- 后端: 集成测试(认证/任务/凭证) 49个测试全部通过
- 前端: 凭证管理、成本分析、导出中心、知识库、系统设置页面
- 前端: AuthGuard认证守卫、Dashboard AI聊天功能
- 前端: Playwright E2E测试 16 passed, 1 skipped
- 基础设施: Docker Compose、Nginx反向代理、.env.example
- 文档: 用户手册、管理员手册、发布检查清单
2026-07-07 21:21:29 +08:00

56 lines
2.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
成本分析模型
存储人工成本分析结果,包括总额、部门拆分、费用科目拆分、环比变化等
"""
from typing import Optional
from sqlalchemy import ForeignKey, Integer, String, Float, JSON, DateTime
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.models.base import BaseModel
class CostAnalysis(BaseModel):
"""
成本分析模型
记录一次成本分析的计算结果
Attributes:
task_id: 关联的对账任务ID
company_id: 企业ID
total_cost: 人工成本总额
salary_cost: 工资成本
social_security_cost: 社保成本(公司部分)
fund_cost: 公积金成本(公司部分)
department_breakdown: 部门成本拆分(JSON
expense_breakdown: 费用科目拆分(JSON
month_over_month: 环比变化数据(JSON
ai_summary: AI 生成的分析摘要
"""
__tablename__ = "cost_analyses"
task_id: Mapped[int] = mapped_column(Integer, ForeignKey("reconciliation_tasks.id"), nullable=False, index=True)
company_id: Mapped[int] = mapped_column(Integer, ForeignKey("companies.id"), nullable=False, index=True)
total_cost: Mapped[float] = mapped_column(Float, nullable=False, default=0.0, comment="人工成本总额")
salary_cost: Mapped[float] = mapped_column(Float, nullable=False, default=0.0, comment="工资成本")
social_security_cost: Mapped[float] = mapped_column(Float, nullable=False, default=0.0, comment="社保成本(公司部分)")
fund_cost: Mapped[float] = mapped_column(Float, nullable=False, default=0.0, comment="公积金成本(公司部分)")
department_breakdown: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True, comment="部门成本拆分")
expense_breakdown: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True, comment="费用科目拆分")
month_over_month: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True, comment="环比变化数据")
ai_summary: Mapped[Optional[str]] = mapped_column(String(2000), nullable=True, comment="AI 生成的分析摘要")
# 关系
task = relationship("ReconciliationTask", backref="cost_analyses")
company = relationship("Company", backref="cost_analyses")
def __repr__(self) -> str:
return f"<CostAnalysis(task_id={self.task_id}, total_cost={self.total_cost})>"