修复bug

main
risingLee 2026-01-04 23:56:11 +08:00
parent 49a9cfc035
commit 4d4908bb2f
4 changed files with 24 additions and 6 deletions

View File

@ -43,7 +43,9 @@ async def get_warehouse_receipt_detail(
获取入库单详情
"""
try:
print(f"DEBUG Controller: 请求入库单详情 receipt_id={receipt_id}, type={type(receipt_id)}")
receipt_detail = await WarehouseReceiptService.get_receipt_detail(query_db, receipt_id)
print(f"DEBUG Controller: 返回的入库单号={receipt_detail.get('receiptNo')}, receipt_id={receipt_detail.get('receiptId')}")
logger.info('获取成功')
return ResponseUtil.success(data=receipt_detail)
except Exception as e:

View File

@ -111,7 +111,7 @@ class WarehouseReceiptDao:
"""
编辑入库单
"""
update_data = receipt.model_dump(exclude_unset=True, exclude={'receipt_id'})
update_data = receipt.model_dump(exclude_unset=True, exclude={'receipt_id', 'samples', 'sample_count'})
stmt = update(WarehouseReceipt).where(WarehouseReceipt.receipt_id == receipt.receipt_id).values(**update_data)
await db.execute(stmt)
await db.flush()

View File

@ -27,10 +27,14 @@ class WarehouseSampleDao:
"""
获取样品列表
"""
# 添加日志
print(f"DEBUG DAO: receipt_id={query_object.receipt_id}, type={type(query_object.receipt_id)}")
query = select(WarehouseSample).where(WarehouseSample.del_flag == '0')
# 条件筛选
if query_object.receipt_id:
print(f"DEBUG DAO: 添加 receipt_id 筛选条件")
query = query.where(WarehouseSample.receipt_id == query_object.receipt_id)
if query_object.receipt_no:
query = query.where(WarehouseSample.receipt_no.like(f'%{query_object.receipt_no}%'))

View File

@ -48,27 +48,37 @@ class WarehouseReceiptService:
"""
获取入库单详情
"""
import sys
print(f"DEBUG Service START: get_receipt_detail called with receipt_id={receipt_id}", flush=True)
sys.stdout.flush()
try:
receipt = await WarehouseReceiptDao.get_receipt_by_id(db, receipt_id)
if not receipt:
raise ServiceException(message='入库单不存在')
print(f"DEBUG Service: receipt found, receipt.receipt_id={receipt.receipt_id}, receipt_no={receipt.receipt_no}", flush=True)
sys.stdout.flush()
receipt_dict = CamelCaseUtil.transform_result(receipt)
# 获取样品列表
from module_admin.entity.vo.warehouse_sample_vo import WarehouseSamplePageQueryModel
sample_query = WarehouseSamplePageQueryModel(receipt_id=receipt.receipt_id, page_num=1, page_size=1000)
# 使用 camelCase 字段名来构造查询对象
sample_query = WarehouseSamplePageQueryModel(receiptId=receipt.receipt_id, pageNum=1, pageSize=1000)
# 添加日志
print(f"DEBUG: 查询入库单 {receipt_id} 的样品receipt.receipt_id={receipt.receipt_id}")
print(f"DEBUG: 查询入库单 {receipt_id} 的样品receipt.receipt_id={receipt.receipt_id}", flush=True)
print(f"DEBUG: sample_query.receipt_id={sample_query.receipt_id}", flush=True)
sys.stdout.flush()
samples = await WarehouseSampleDao.get_sample_list(db, sample_query, is_page=False)
# 添加日志
print(f"DEBUG: 查询到 {len(samples) if samples else 0} 个样品")
print(f"DEBUG: 查询到 {len(samples) if samples else 0} 个样品", flush=True)
if samples:
for sample in samples[:3]: # 只打印前3个
print(f"DEBUG: 样品 ID={sample.sample_id}, receipt_id={sample.receipt_id}, SN={sample.sample_sn}")
print(f"DEBUG: 样品 ID={sample.sample_id}, receipt_id={sample.receipt_id}, SN={sample.sample_sn}", flush=True)
sys.stdout.flush()
# 转换样品列表
samples_list = [CamelCaseUtil.transform_result(sample) for sample in samples] if samples else []
@ -79,6 +89,7 @@ class WarehouseReceiptService:
except ServiceException:
raise
except Exception as e:
print(f"DEBUG Service ERROR: {str(e)}", flush=True)
raise ServiceException(message=f'获取入库单详情失败: {str(e)}')
@classmethod
@ -151,7 +162,8 @@ class WarehouseReceiptService:
if receipt_model.samples is not None:
# 获取现有样品列表
from module_admin.entity.vo.warehouse_sample_vo import WarehouseSamplePageQueryModel
sample_query = WarehouseSamplePageQueryModel(receipt_id=receipt_model.receipt_id, page_num=1, page_size=1000)
# 使用 camelCase 字段名来构造查询对象
sample_query = WarehouseSamplePageQueryModel(receiptId=receipt_model.receipt_id, pageNum=1, pageSize=1000)
existing_samples = await WarehouseSampleDao.get_sample_list(db, sample_query, is_page=False)
existing_sample_ids = {sample.sample_id for sample in existing_samples} if existing_samples else set()