feat(market): 完善临床科研与委托加工上线能力
补齐项目组负责人审批、费用信息、合作客户、生产出库菜单、申请单号 LCKY 前缀及配套 SQL 迁移,并同步相关前后端与单测。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7a3c58ed99
commit
c22a0d1eb0
77 files changed
+8375
-1869
No files matched your search
@@ -25,6 +25,35 @@ def _get_tenant_no(db: Session, user: dict) -> str:
|
||||
return sys_user.tenant_no
|
||||
|
||||
|
||||
def _access_pilot_application(
|
||||
db: Session,
|
||||
tenant_no: str,
|
||||
user: dict,
|
||||
app_id: str,
|
||||
*,
|
||||
lock: bool = False,
|
||||
for_approval: bool = False,
|
||||
):
|
||||
"""科研类走项目组可见性;其它业务走通用数据权限。"""
|
||||
q = db.query(BizPilotApplication).filter(
|
||||
BizPilotApplication.id == app_id,
|
||||
BizPilotApplication.tenant_no == tenant_no,
|
||||
BizPilotApplication.del_flag == 0,
|
||||
)
|
||||
if lock:
|
||||
q = q.populate_existing().with_for_update()
|
||||
row = q.first()
|
||||
if row is None:
|
||||
raise HTTPException(404, "单据不存在或无权访问")
|
||||
if pilot_application.requires_leader_approval(row.biz_type):
|
||||
if not pilot_application.user_can_access_research_application(
|
||||
db, tenant_no, user, row, for_approval=for_approval
|
||||
):
|
||||
raise HTTPException(404, "单据不存在或无权访问")
|
||||
return row
|
||||
return accessible_order(db, BizPilotApplication, tenant_no, user, app_id, lock=lock)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Pydantic Schemas
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -236,8 +265,11 @@ async def api_list_applications(
|
||||
keyword: Optional[str] = Query(None, alias="keyword"),
|
||||
channelId: Optional[str] = Query(None, alias="channelId"),
|
||||
applicationStatus: Optional[str] = Query(None, alias="applicationStatus"),
|
||||
approvalStatus: Optional[str] = Query(None, alias="approvalStatus"),
|
||||
pendingMine: Optional[bool] = Query(False, alias="pendingMine"),
|
||||
channelServiceOrderId: Optional[str] = Query(None, alias="channelServiceOrderId"),
|
||||
bizType: Optional[str] = Query(None, alias="bizType"),
|
||||
forApproval: Optional[bool] = Query(False, alias="forApproval"),
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
@@ -251,10 +283,13 @@ async def api_list_applications(
|
||||
page_size=pageSize,
|
||||
channel_id=channelId,
|
||||
application_status=applicationStatus,
|
||||
approval_status=approvalStatus,
|
||||
pending_mine=bool(pendingMine),
|
||||
channel_service_order_id=channelServiceOrderId,
|
||||
keyword=keyword,
|
||||
biz_type=bizType,
|
||||
user_info=user,
|
||||
for_approval=bool(forApproval),
|
||||
)
|
||||
return success_response(result)
|
||||
|
||||
@@ -266,7 +301,10 @@ async def api_get_application(
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
accessible_order(db, BizPilotApplication, tenant_no, user, id)
|
||||
try:
|
||||
_access_pilot_application(db, tenant_no, user, id)
|
||||
except HTTPException as e:
|
||||
return error_response(e.status_code, e.detail)
|
||||
result = pilot_application.get_application(db, app_id=id, tenant_no=tenant_no)
|
||||
if result is None:
|
||||
return error_response(404, "申请单不存在")
|
||||
@@ -312,7 +350,7 @@ async def api_update_application(
|
||||
):
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
accessible_order(db, BizPilotApplication, tenant_no, user, body.id, lock=True)
|
||||
_access_pilot_application(db, tenant_no, user, body.id, lock=True)
|
||||
data = {}
|
||||
if "project_id" in body.model_fields_set:
|
||||
data["projectId"] = body.project_id
|
||||
@@ -334,6 +372,8 @@ async def api_update_application(
|
||||
return success_response(result, message="更新成功")
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
except HTTPException as e:
|
||||
return error_response(e.status_code, e.detail)
|
||||
|
||||
|
||||
@router.post("/pilot-application/save")
|
||||
@@ -390,13 +430,13 @@ async def api_save_application(
|
||||
|
||||
if (
|
||||
not is_edit
|
||||
and biz_type in ("clinical_application", "basic_experiment", "contract_processing")
|
||||
and biz_type == "clinical_application"
|
||||
and not app_data["channelId"]
|
||||
):
|
||||
return error_response(400, "请选择渠道")
|
||||
|
||||
if is_edit:
|
||||
accessible_order(db, BizPilotApplication, tenant_no, user, body.id, lock=True)
|
||||
_access_pilot_application(db, tenant_no, user, body.id, lock=True)
|
||||
if is_edit:
|
||||
app_result = pilot_application.update_application(
|
||||
db,
|
||||
@@ -517,6 +557,41 @@ async def api_start_application(
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
class ApplicationApproveBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
id: str
|
||||
approval_status: str = Field(..., alias="approvalStatus")
|
||||
approval_remark: Optional[str] = Field(None, alias="approvalRemark")
|
||||
|
||||
|
||||
@router.post("/pilot-application/approve")
|
||||
async def api_approve_application(
|
||||
body: ApplicationApproveBody,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
_access_pilot_application(
|
||||
db, tenant_no, user, body.id, lock=True, for_approval=True
|
||||
)
|
||||
result = pilot_application.approve_application(
|
||||
db,
|
||||
app_id=body.id,
|
||||
tenant_no=tenant_no,
|
||||
user_id=user.get("user_id"),
|
||||
approval_status=body.approval_status,
|
||||
approval_remark=body.approval_remark,
|
||||
is_super_admin=pilot_application._is_super_admin_user(user),
|
||||
)
|
||||
return success_response(result, message="审批成功")
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
except HTTPException as e:
|
||||
return error_response(e.status_code, e.detail)
|
||||
|
||||
|
||||
@router.post("/pilot-application/complete")
|
||||
async def api_complete_application(
|
||||
body: IdBody,
|
||||
@@ -869,6 +944,32 @@ class ScheduleIdBody(BaseModel):
|
||||
scheduleId: str
|
||||
|
||||
|
||||
def _assert_schedule_app_approved(db: Session, schedule_id: str, tenant_no: str) -> None:
|
||||
from app.models.models import BizPilotInfusionPlan, BizPilotInfusionSchedule
|
||||
|
||||
row = (
|
||||
db.query(BizPilotApplication)
|
||||
.join(
|
||||
BizPilotInfusionPlan,
|
||||
BizPilotInfusionPlan.pilot_application_id == BizPilotApplication.id,
|
||||
)
|
||||
.join(
|
||||
BizPilotInfusionSchedule,
|
||||
BizPilotInfusionSchedule.infusion_plan_id == BizPilotInfusionPlan.id,
|
||||
)
|
||||
.filter(
|
||||
BizPilotInfusionSchedule.id == schedule_id,
|
||||
BizPilotInfusionSchedule.tenant_no == tenant_no,
|
||||
BizPilotInfusionSchedule.del_flag == 0,
|
||||
BizPilotInfusionPlan.del_flag == 0,
|
||||
BizPilotApplication.del_flag == 0,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
if row:
|
||||
pilot_application.assert_research_leader_approved(row)
|
||||
|
||||
|
||||
@router.post("/pilot-infusion-schedule/create-production-work-order")
|
||||
async def api_create_outbound_production(
|
||||
body: ScheduleIdBody,
|
||||
@@ -877,6 +978,7 @@ async def api_create_outbound_production(
|
||||
):
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
_assert_schedule_app_approved(db, body.scheduleId, tenant_no)
|
||||
from app.crud import production_work_order as pwo_svc
|
||||
|
||||
from app.crud.qc_work_order import resolve_outbound_biz_type_for_schedule
|
||||
@@ -915,6 +1017,7 @@ async def api_create_outbound_qc(
|
||||
):
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
_assert_schedule_app_approved(db, body.scheduleId, tenant_no)
|
||||
from app.crud import qc_work_order as qc_svc
|
||||
|
||||
from app.crud.qc_work_order import resolve_outbound_biz_type_for_schedule
|
||||
@@ -937,3 +1040,126 @@ async def api_create_outbound_qc(
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 临床科研 / 委托加工 · 自定义业务类型
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class ContractProcessingCategoryCreateBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
category_name: str = Field(..., alias="categoryName")
|
||||
biz_type: str = Field(..., alias="bizType", description="basic_experiment | contract_processing")
|
||||
order_num: Optional[int] = Field(None, alias="orderNum")
|
||||
remark: Optional[str] = None
|
||||
|
||||
|
||||
class ContractProcessingCategoryUpdateBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
category_name: Optional[str] = Field(None, alias="categoryName")
|
||||
order_num: Optional[int] = Field(None, alias="orderNum")
|
||||
remark: Optional[str] = None
|
||||
|
||||
|
||||
@router.get("/contract-processing-categories")
|
||||
async def list_contract_processing_categories(
|
||||
page: int = Query(1, ge=1),
|
||||
pageSize: int = Query(100, ge=1, le=200, alias="pageSize"),
|
||||
keyword: Optional[str] = None,
|
||||
bizType: str = Query(..., alias="bizType", description="basic_experiment | contract_processing"),
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
from app.crud import contract_processing_category as cat_svc
|
||||
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
rows, total = cat_svc.list_categories(
|
||||
db,
|
||||
page=page,
|
||||
page_size=pageSize,
|
||||
keyword=keyword,
|
||||
tenant_no=tenant_no,
|
||||
biz_type=bizType,
|
||||
)
|
||||
return success_response(
|
||||
{
|
||||
"list": rows,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"pageSize": pageSize,
|
||||
"totalPages": cat_svc.total_pages(total, pageSize),
|
||||
}
|
||||
)
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
@router.post("/contract-processing-categories")
|
||||
async def create_contract_processing_category(
|
||||
body: ContractProcessingCategoryCreateBody,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
from app.crud import contract_processing_category as cat_svc
|
||||
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
obj = cat_svc.create_category(
|
||||
db,
|
||||
category_name=body.category_name,
|
||||
biz_type=body.biz_type,
|
||||
tenant_no=tenant_no,
|
||||
order_num=body.order_num,
|
||||
remark=body.remark,
|
||||
user_id=user.get("user_id"),
|
||||
create_dept_id=user.get("dept_id") or "",
|
||||
)
|
||||
return success_response(cat_svc._row_to_dict(obj), message="创建成功")
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
@router.put("/contract-processing-categories/{category_id}")
|
||||
async def update_contract_processing_category(
|
||||
category_id: str,
|
||||
body: ContractProcessingCategoryUpdateBody,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
from app.crud import contract_processing_category as cat_svc
|
||||
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
payload = body.model_dump(exclude_unset=True, by_alias=False)
|
||||
obj = cat_svc.update_category(
|
||||
db,
|
||||
category_id,
|
||||
category_name=payload.get("category_name"),
|
||||
order_num=payload.get("order_num"),
|
||||
remark=payload.get("remark"),
|
||||
user_id=user.get("user_id"),
|
||||
tenant_no=tenant_no,
|
||||
)
|
||||
return success_response(cat_svc._row_to_dict(obj), message="更新成功")
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
@router.delete("/contract-processing-categories/{category_id}")
|
||||
async def delete_contract_processing_category(
|
||||
category_id: str,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
from app.crud import contract_processing_category as cat_svc
|
||||
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
cat_svc.soft_delete_category(db, category_id, tenant_no=tenant_no)
|
||||
return success_response(None, message="删除成功")
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
Reference in new issue
Block a user