feat: add location registration service
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
34
app/services/location_service.py
Normal file
34
app/services/location_service.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user