From e352d6dc187c981dda384149c854cb23bbadf7ab Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Mon, 11 May 2026 11:09:38 +0800 Subject: [PATCH] feat: add location registration service Co-Authored-By: Claude Opus 4.6 --- app/services/__init__.py | 0 app/services/location_service.py | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 app/services/__init__.py create mode 100644 app/services/location_service.py diff --git a/app/services/__init__.py b/app/services/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/services/location_service.py b/app/services/location_service.py new file mode 100644 index 0000000..973748f --- /dev/null +++ b/app/services/location_service.py @@ -0,0 +1,34 @@ +from fastapi import HTTPException +from sqlalchemy.orm import Session + +from app.models.finished_goods import FinishedGoodsLocation +from app.schemas.location import LocationRequest + + +def register_location(db: Session, req: LocationRequest) -> FinishedGoodsLocation: + existing = ( + db.query(FinishedGoodsLocation) + .filter(FinishedGoodsLocation.zongpai_no == req.zongpai_no) + .first() + ) + if existing: + raise HTTPException( + status_code=409, + detail={ + "error_code": "DUPLICATE_LOCATION", + "message": "该总排号已存在货位记录", + "detail": { + "existing_location": existing.location_code, + "created_at": existing.created_at.isoformat(), + }, + }, + ) + + record = FinishedGoodsLocation( + zongpai_no=req.zongpai_no, + location_code=req.location_code, + ) + db.add(record) + db.commit() + db.refresh(record) + return record