From 1ca2cf1dd12cb321b4d2207699bfe67b96ada834 Mon Sep 17 00:00:00 2001 From: "mula.liu" Date: Wed, 4 Nov 2026 01:46:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor(projects):=20=E4=BC=98=E5=85=88?= =?UTF-8?q?=E7=BA=A7/=E9=A1=B9=E7=9B=AE=E8=AF=B4=E6=98=8E=E6=95=B4?= =?UTF-8?q?=E9=93=BE=E4=B8=8B=E7=BA=BF=E2=80=94=E2=80=94=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E9=9B=B6=E8=AF=BB=E5=86=99=E3=80=81=E5=BA=93=E5=86=85=200=20?= =?UTF-8?q?=E8=A1=8C=E6=95=B0=E6=8D=AE=E3=80=81=E5=AF=BC=E5=87=BA=E6=81=92?= =?UTF-8?q?=E4=B8=BA=E3=80=8CP2=20=E4=B8=AD=E3=80=8D=EF=BC=9AProject.prior?= =?UTF-8?q?ity/description=20=E6=A8=A1=E5=9E=8B=E5=88=97=20+=20ProjectIn/P?= =?UTF-8?q?atch=20=E5=AD=97=E6=AE=B5=20+=20to=5Fdict=20=E9=94=AE=20+=20/ex?= =?UTF-8?q?port/projects=E3=80=8C=E4=BC=98=E5=85=88=E7=BA=A7=E3=80=8D?= =?UTF-8?q?=E5=88=97=EF=BC=88=E6=B5=8B=E8=AF=95=E5=88=97=E5=8F=B7=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=EF=BC=89+=20/meta=20priorities=20+=20constants.PRIORI?= =?UTF-8?q?TIES=EF=BC=9B=E4=B8=A4=E5=88=97=E7=99=BB=E8=AE=B0=20STALE=5FCOL?= =?UTF-8?q?UMNS=20=E5=90=AF=E5=8A=A8=E6=B8=85=E8=80=81=E5=BA=93=E3=80=82py?= =?UTF-8?q?test=2093=20passed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- app/constants.py | 8 -------- app/models.py | 5 +---- app/routers/board.py | 3 --- app/routers/export.py | 5 ++--- app/schema_patch.py | 2 ++ app/schemas.py | 4 ---- tests/test_ai_export.py | 4 ++-- tests/test_periods_projects.py | 6 +++--- 9 files changed, 12 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 4df667f..8960210 100644 --- a/README.md +++ b/README.md @@ -488,7 +488,7 @@ python scripts/legacy/add_entry_date.py --force # 全部重算 ``` # 项目管理(长期重点项目) Period(周期: 年/月/周, sort_key) - └── Project(分类, 负责人 owners[0], 其他负责人, 团队成员, 状态, 优先级, 重点标记, 进度, 标签) + └── Project(分类, 负责人 owners[0], 其他负责人, 团队成员, 状态, 重点标记, 进度, 标签) ├── Task(子任务) └── Update(执行情况: 正文, 摘要, 进度, 状态, 风险, 下一步, 来源, 原文) @@ -625,7 +625,7 @@ GET|DELETE /api/rbac/logs 操作审计(服务端分页)?username= / DELETE 按 days 清理 # 通用 -GET /api/meta 状态字典 / 优先级 / 菜单 / AI 配置状态 +GET /api/meta 状态字典 / 菜单 / AI 配置状态 GET /api/periods 周列表 + 按月聚合(today_id = 今天所在的周,顶栏默认落它;没有会自动补建) POST /api/periods 新增周期(传 label 如「9月第1周」,年份自动接续;重复提交返回已有的) DELETE /api/periods/{id} 删除空周期(有记录则拒绝) diff --git a/app/constants.py b/app/constants.py index 5410c2d..9e07198 100644 --- a/app/constants.py +++ b/app/constants.py @@ -15,14 +15,6 @@ STATUSES = [ STATUS_MAP = {code: (name, color) for code, name, color in STATUSES} STATUS_CODES = [c for c, _, _ in STATUSES] -# 项目优先级 -PRIORITIES = [ - ("p0", "P0 最高", "#dc2626"), - ("p1", "P1 高", "#d97706"), - ("p2", "P2 中", "#2563eb"), - ("p3", "P3 低", "#6b7280"), -] - # -------------------------------------------------------------------------- # 权限菜单目录(前后端共用:键是权限标识,顺序即权限管理页里的展示顺序) # rw = 可编辑(含新增/修改/删除/导出写入口) diff --git a/app/models.py b/app/models.py index b06a969..572f9d0 100644 --- a/app/models.py +++ b/app/models.py @@ -150,10 +150,9 @@ class Project(Base, TimestampMixin): other_owners: Mapped[str | None] = mapped_column(String(512), nullable=True) # 其他负责人 members: Mapped[str | None] = mapped_column(String(512), nullable=True) # 团队成员 status: Mapped[str] = mapped_column(String(32), default="in_progress", nullable=False) - priority: Mapped[str] = mapped_column(String(8), default="p2", nullable=False) + # priority / description 两列 2026-11-04 下线:无任何界面读写,导出恒为「P2 中」 is_key: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False) # 重点标记 progress: Mapped[float] = mapped_column(Float, default=0.0, nullable=False) # 最新进度 % - description: Mapped[str | None] = mapped_column(Text, nullable=True) archived: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False) sort_order: Mapped[int] = mapped_column(Integer, default=0, nullable=False) @@ -176,10 +175,8 @@ class Project(Base, TimestampMixin): "owners": all_owners(self.owner, self.other_owners), "members": split_people(self.members), "status": self.status, - "priority": self.priority, "is_key": self.is_key, "progress": round(self.progress or 0, 1), - "description": self.description, "archived": self.archived, "sort_order": self.sort_order, "tags": [t.to_dict() for t in self.tags], diff --git a/app/routers/board.py b/app/routers/board.py index e9117c1..b52720b 100644 --- a/app/routers/board.py +++ b/app/routers/board.py @@ -189,9 +189,6 @@ def meta(db: Session = Depends(get_db)): "statuses": [ {"code": c, "name": n, "color": col} for c, n, col in constants.STATUSES ], - "priorities": [ - {"code": c, "name": n, "color": col} for c, n, col in constants.PRIORITIES - ], "ai": { "enabled": ai_enabled(db), "model": s.get("ai_model"), diff --git a/app/routers/export.py b/app/routers/export.py index d6a8fb2..596cf4c 100644 --- a/app/routers/export.py +++ b/app/routers/export.py @@ -194,7 +194,7 @@ def export_projects( periods = {p.id: p for p in db.query(Period).all()} headers = [ - "项目名称", "分类", "负责人", "状态", "优先级", "重点", + "项目名称", "分类", "负责人", "状态", "重点", "进度(%)", "标签", "子任务数", "执行记录数", "最近更新周期", "归档", ] status_names = { @@ -211,7 +211,6 @@ def export_projects( p.category.name if p.category else "未分类", p.owner or "", status_names.get(p.status, p.status), - (p.priority or "").upper(), "是" if p.is_key else "", round(p.progress or 0, 1), "、".join(t.name for t in p.tags), @@ -226,7 +225,7 @@ def export_projects( "项目管理", headers, rows, - widths=[46, 12, 12, 10, 9, 7, 10, 24, 11, 12, 18, 7], + widths=[46, 12, 12, 10, 7, 10, 24, 11, 12, 18, 7], title="项目管理清单", ) return _resp(content, "项目管理清单") diff --git a/app/schema_patch.py b/app/schema_patch.py index 04c44b8..d38ee76 100644 --- a/app/schema_patch.py +++ b/app/schema_patch.py @@ -21,6 +21,8 @@ STALE_COLUMNS: tuple[tuple[str, str], ...] = ( ("tasks", "sort_order"), # 子任务实际按 id 排序,此列只写不读 ("periods", "start_date"), # 周期起止由 year/month/week 推导,两列从未被读取 ("periods", "end_date"), + ("projects", "priority"), # 优先级无界面读写,导出恒为 P2(NOT NULL 列,必须清) + ("projects", "description"), ) diff --git a/app/schemas.py b/app/schemas.py index bfac7fd..616d8e3 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -12,10 +12,8 @@ class ProjectIn(BaseModel): owners: list[str] | None = None # 多负责人(第一位是主负责人),整体替换 members: list[str] | None = None # 团队成员,整体替换 status: str = "in_progress" - priority: str = "p2" is_key: bool = False progress: float = 0 - description: str | None = None archived: bool = False tags: list[str] = Field(default_factory=list) # 标签名,自动创建 @@ -27,10 +25,8 @@ class ProjectPatch(BaseModel): owners: list[str] | None = None # 不传即不改;传空数组即清空 members: list[str] | None = None status: str | None = None - priority: str | None = None is_key: bool | None = None progress: float | None = None - description: str | None = None archived: bool | None = None tags: list[str] | None = None diff --git a/tests/test_ai_export.py b/tests/test_ai_export.py index 048c71f..04ace1a 100644 --- a/tests/test_ai_export.py +++ b/tests/test_ai_export.py @@ -356,8 +356,8 @@ def test_项目导出含归档开关与统计列(h): _, rows = _sheet(h.admin.get("/api/export/projects", params={"archived": "all"})) assert "导出-已归档项目" in [r[0] for r in rows[3:]] # 整库留档要显式 archived=all row = next(r for r in rows[3:] if r[0] == "导出-常规项目") - assert row[3] == "进行中" and row[5] == "是" and row[9] == 1 - assert row[10] and "第" in row[10] # 最近更新周期写了周次 + assert row[3] == "进行中" and row[4] == "是" and row[8] == 1 + assert row[9] and "第" in row[9] # 最近更新周期写了周次 _, rows = _sheet(h.admin.get("/api/export/projects", params={"archived": "false"})) names = [r[0] for r in rows[3:]] diff --git a/tests/test_periods_projects.py b/tests/test_periods_projects.py index 6e65c89..3ec3c74 100644 --- a/tests/test_periods_projects.py +++ b/tests/test_periods_projects.py @@ -98,10 +98,10 @@ def test_有记录的周期不能删(h): assert h.admin.delete("/api/periods/424242").status_code == 404 -def test_元信息给状态优先级和AI状态(h): +def test_元信息给状态字典和AI状态(h): meta = h.admin.get("/api/meta").json() assert [x["code"] for x in meta["statuses"]] == [c for c, _, _ in constants.STATUSES] - assert [x["code"] for x in meta["priorities"]] == [c for c, _, _ in constants.PRIORITIES] + assert "priorities" not in meta # 优先级已随 Project.priority 下线 assert meta["ai"]["enabled"] is False # 没配 Key:走本地规则 assert meta["ai"]["has_key"] is False @@ -130,7 +130,7 @@ def test_项目字段与人员标签的写入(h): cat = h.category("交付项目") p = h.project("智慧园区", category_id=cat["id"], owners=["张三", "李四"], members=["王五", "赵六"], tags=["新客户", "重点"], is_key=True, - progress=35, priority="p1", description="备注说明") + progress=35) assert p["owner"] == "张三" and p["owners"] == ["张三", "李四"] # 第一位是主负责人 assert p["members"] == ["王五", "赵六"] assert {t["name"] for t in p["tags"]} == {"新客户", "重点"}