diff --git a/backend/app/crud/pilot_application.py b/backend/app/crud/pilot_application.py index 0014c738..c7a5a0d7 100644 --- a/backend/app/crud/pilot_application.py +++ b/backend/app/crud/pilot_application.py @@ -118,17 +118,25 @@ def _row_to_dict_application(row, db=None, tenant_no=None) -> Dict[str, Any]: ) d["patientName"] = patient.patient_name if patient else "" - # infusionPlanCount - plan_count = ( - db.query(func.count(BizPilotInfusionPlan.id)) + # infusionScheduleCount:该申请单下全部输注计划条数(跨输注方案汇总) + schedule_count = ( + db.query(func.count(BizPilotInfusionSchedule.id)) + .join( + BizPilotInfusionPlan, + and_( + BizPilotInfusionSchedule.infusion_plan_id == BizPilotInfusionPlan.id, + BizPilotInfusionPlan.del_flag == 0, + ), + ) .filter( BizPilotInfusionPlan.pilot_application_id == row.id, BizPilotInfusionPlan.tenant_no == tenant_no, - BizPilotInfusionPlan.del_flag == 0, + BizPilotInfusionSchedule.tenant_no == tenant_no, + BizPilotInfusionSchedule.del_flag == 0, ) .scalar() ) or 0 - d["infusionPlanCount"] = plan_count + d["infusionScheduleCount"] = schedule_count # serviceOrderNo + orderType svc_order = ( @@ -251,6 +259,9 @@ def _row_to_dict_infusion_schedule(row, cell_products: Optional[List[Dict[str, A "infusionLocation": row.infusion_location or "", "infusionMethod": row.infusion_method or "", "scheduleStatus": row.schedule_status or "", + "infusionStatus": row.infusion_status or "dtz", + "cancelReason": row.cancel_reason or "", + "qcStatus": row.qc_status or "dzc", "cellProducts": cell_products if cell_products is not None else [], "attachments": row.attachments or "", "tenantNo": row.tenant_no or "", @@ -853,7 +864,9 @@ def auto_generate_schedules( infusion_plan_id=plan_id, cell_type=plan.cell_type or "", spec_text=plan.spec_text or "", - schedule_status="", + schedule_status="dsc", + infusion_status="dtz", + qc_status="dzc", tenant_no=tenant_no, order_num=i, remark="", @@ -894,7 +907,7 @@ def _create_schedule_products( agreement_price=item.get("agreementPrice"), actual_price=item.get("actualPrice"), quantity=item.get("quantity") if item.get("quantity") is not None else 1, - product_status=item.get("status") or item.get("productStatus") or "待输注", + product_status=item.get("status") or item.get("productStatus") or "dtz", tenant_no=tenant_no, order_num=item.get("sortNo") or (idx + 1), remark=item.get("remark") or "", @@ -933,6 +946,8 @@ def create_schedule( infusion_location=data.get("infusionLocation") or "", infusion_method=data.get("infusionMethod") or "", schedule_status=data.get("scheduleStatus") or "dsc", + infusion_status=data.get("infusionStatus") or "dtz", + qc_status=data.get("qcStatus") or "dzc", attachments=data.get("attachments") or "", tenant_no=tenant_no, order_num=data.get("sortNo") or data.get("orderNum") or 0, @@ -948,6 +963,17 @@ def create_schedule( products = _create_schedule_products( db, schedule_id, cell_products, tenant_no, user_id, dept_id, now ) + # 自动创建出库生产工单 + from app.crud import production_work_order as pwo_svc + + pwo_svc.create_outbound_production_work_order( + db, + schedule_id=schedule_id, + tenant_no=tenant_no, + user_id=user_id, + create_dept_id=dept_id, + biz_type="pilot_service", + ) if commit: db.commit() db.refresh(row) @@ -1059,6 +1085,23 @@ def soft_delete_schedule(db: Session, schedule_id: str, tenant_no: str) -> None: if not row: raise ValueError("输注计划不存在") + # 关联的出库生产工单标记为已作废 + from app.models.models import BizProductionWorkOrder + + outbound_wo = ( + db.query(BizProductionWorkOrder) + .filter( + BizProductionWorkOrder.infusion_schedule_id == schedule_id, + BizProductionWorkOrder.tenant_no == tenant_no, + BizProductionWorkOrder.del_flag == 0, + BizProductionWorkOrder.work_order_type == "outbound", + ) + .first() + ) + if outbound_wo: + outbound_wo.work_order_status = "yzf" + outbound_wo.update_time = datetime.now() + row.del_flag = 1 row.update_time = datetime.now() db.commit()