fix+feat: 修复工作台接口不存在 + 3D 区域分配制重建
- 补齐公告后端: Announcement 模型 + /api/announcements + 种子公告 (修复工作台/布局页调用不存在接口报'接口不存在') - 修复 seed init_db 前置模型导入(announcements 表未建) - WindoorThreed 区域分配制: 每个重放区域唯一归属 (扇认领重叠最大区域, 其余静态玻璃), 杜绝扇面板与玻璃重叠混乱 - 全区域薄框线还原真实窗格, 扇面板含玻璃+四边扇框
This commit is contained in:
@@ -210,3 +210,17 @@ async def list_articles(db: DbSession, category: str | None = None):
|
||||
items = list((await db.execute(stmt)).scalars())
|
||||
return ok(data=[{"id": a.id, "title": a.title, "category": a.category, "content": a.content}
|
||||
for a in items])
|
||||
|
||||
|
||||
# ---------------- 平台公告 ----------------
|
||||
|
||||
@router.get("/announcements")
|
||||
async def list_announcements(db: DbSession):
|
||||
"""平台公告(工作台轮播 + 顶栏气泡)。"""
|
||||
from huamenchuang.models.announcement import Announcement
|
||||
stmt = select(Announcement).order_by(Announcement.sort, Announcement.id.desc())
|
||||
items = list((await db.execute(stmt)).scalars())
|
||||
return ok(data=[{
|
||||
"id": a.id, "name": a.name, "desc": a.desc, "content": a.content,
|
||||
"pic_url": a.pic_url, "created_at": str(a.created_at),
|
||||
} for a in items])
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"""ORM 模型统一导出。"""
|
||||
from huamenchuang.models.announcement import Announcement
|
||||
from huamenchuang.models.business import (
|
||||
AfterSale,
|
||||
MeasureOrder,
|
||||
@@ -19,6 +20,7 @@ from huamenchuang.models.windoor_template import WindoorCatelog, WindoorTemplate
|
||||
|
||||
__all__ = [
|
||||
"AfterSale",
|
||||
"Announcement",
|
||||
"Contract",
|
||||
"Customer",
|
||||
"DEFAULT_PROCESSES",
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
"""平台公告模型。"""
|
||||
import datetime
|
||||
|
||||
from sqlalchemy import DateTime, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from huamenchuang.core.database import Base
|
||||
|
||||
|
||||
class Announcement(Base):
|
||||
__tablename__ = "announcements"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
name: Mapped[str] = mapped_column(String(128))
|
||||
desc: Mapped[str] = mapped_column(String(255), default="")
|
||||
content: Mapped[str] = mapped_column(Text, default="")
|
||||
pic_url: Mapped[str] = mapped_column(String(255), default="")
|
||||
sort: Mapped[int] = mapped_column(default=0)
|
||||
created_at: Mapped[datetime.datetime] = mapped_column(DateTime, default=datetime.datetime.utcnow)
|
||||
@@ -11,6 +11,7 @@ DATA = Path(__file__).resolve().parents[3] / "data"
|
||||
|
||||
|
||||
async def seed() -> None:
|
||||
import huamenchuang.models # noqa: F401 确保全部模型注册到 metadata 后再建表
|
||||
from huamenchuang.core.database import SessionLocal, init_db
|
||||
from huamenchuang.models.user import User
|
||||
from huamenchuang.models.windoor_template import WindoorCatelog, WindoorTemplate
|
||||
@@ -82,6 +83,22 @@ async def seed() -> None:
|
||||
await db.commit()
|
||||
print("帮助文章就绪")
|
||||
|
||||
# 5) 平台公告(幂等:按名称去重)
|
||||
async with SessionLocal() as db:
|
||||
from huamenchuang.models.announcement import Announcement
|
||||
ANNOUNCEMENTS = [
|
||||
("AI 炫图功能上线", "选择样板一键生成多风格效果图,支持日景/黄昏/夜景与四种装修风格", 1),
|
||||
("样板组合工场发布", "拖拽组合多个窗型样板,自由摆放、等高对齐、边缘吸附,支持 3D 预览", 2),
|
||||
("3D 门窗开合演示", "3D 展示支持平开扇旋转、推拉扇滑动动画,可调节开合度", 3),
|
||||
("优化下料引擎", "合同级汇总算料需求,一维优化切割提升型材利用率", 4),
|
||||
]
|
||||
existing = {n for (n,) in (await db.execute(select(Announcement.name))).all()}
|
||||
for name, desc, sort in ANNOUNCEMENTS:
|
||||
if name not in existing:
|
||||
db.add(Announcement(name=name, desc=desc, sort=sort))
|
||||
await db.commit()
|
||||
print("平台公告就绪")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(seed())
|
||||
|
||||
Reference in New Issue
Block a user