diff --git a/backend/app/api/pilot_application.py b/backend/app/api/pilot_application.py index 1c837b9d..beec2552 100644 --- a/backend/app/api/pilot_application.py +++ b/backend/app/api/pilot_application.py @@ -388,7 +388,11 @@ async def api_save_application( ): return error_response(400, "请选择渠道服务订单") - if not is_edit and biz_type == "clinical_application" and not app_data["channelId"]: + if ( + not is_edit + and biz_type in ("clinical_application", "basic_experiment") + and not app_data["channelId"] + ): return error_response(400, "请选择渠道") if is_edit: diff --git a/backend/app/crud/pilot_application.py b/backend/app/crud/pilot_application.py index 5a05c2e7..498ad1ef 100644 --- a/backend/app/crud/pilot_application.py +++ b/backend/app/crud/pilot_application.py @@ -477,8 +477,21 @@ def create_application( customer_contact = (data.get("customerContact") or "").strip() customer_phone = (data.get("customerPhone") or "").strip() channel_service_order_id = "" - channel_id = "" - channel_name = "" + channel_id = (data.get("channelId") or "").strip() + if not channel_id: + raise ValueError("请选择渠道") + ch = ( + db.query(BizChannel) + .filter( + BizChannel.id == channel_id, + BizChannel.tenant_no == tenant_no, + BizChannel.del_flag == 0, + ) + .first() + ) + if not ch: + raise ValueError("渠道不存在") + channel_name = ch.channel_name or "" consent_form_urls = None elif not channel_service_order_id and biz_type != "clinical_application": raise ValueError("请选择渠道服务订单") @@ -602,6 +615,26 @@ def update_application(db: Session, app_id: str, data: dict, tenant_no: str) -> row.research_category = validate_research_category( data.get("researchCategory"), required=False ) or None + if "channelId" in data and data["channelId"] is not None: + if (row.biz_type or "") in ("basic_experiment", "clinical_application"): + new_channel_id = (data.get("channelId") or "").strip() + if not new_channel_id: + raise ValueError("请选择渠道") + ch = ( + db.query(BizChannel) + .filter( + BizChannel.id == new_channel_id, + BizChannel.tenant_no == tenant_no, + BizChannel.del_flag == 0, + ) + .first() + ) + if not ch: + raise ValueError("渠道不存在") + row.channel_id = new_channel_id + row.channel_name = ch.channel_name or "" + if (row.biz_type or "") == "basic_experiment": + row.channel_service_order_id = "" if "consentFormUrls" in data: row.consent_form_urls = data.get("consentFormUrls") or None if "attachmentUrls" in data: diff --git a/backend/tests/test_basic_experiment_application.py b/backend/tests/test_basic_experiment_application.py index 48ae9429..69499015 100644 --- a/backend/tests/test_basic_experiment_application.py +++ b/backend/tests/test_basic_experiment_application.py @@ -29,6 +29,7 @@ class TestBasicExperimentCreateValidation(unittest.TestCase): data = { "bizType": "basic_experiment", "researchCategory": "bio_tech_clinical", + "channelId": "ch-1", "projectTitle": "课题A", "customerName": "", "customerContact": "张三", @@ -48,6 +49,7 @@ class TestBasicExperimentCreateValidation(unittest.TestCase): db = MagicMock() data = { "bizType": "basic_experiment", + "channelId": "ch-1", "projectTitle": "课题A", "customerName": "客户A", "customerContact": "张三", @@ -63,6 +65,26 @@ class TestBasicExperimentCreateValidation(unittest.TestCase): ) self.assertIn("业务类型", str(ctx.exception)) + def test_create_basic_experiment_requires_channel(self): + db = MagicMock() + data = { + "bizType": "basic_experiment", + "researchCategory": "bio_tech_clinical", + "projectTitle": "课题A", + "customerName": "客户A", + "customerContact": "张三", + "customerPhone": "13800000000", + } + with self.assertRaises(ValueError) as ctx: + crud.create_application( + db, + data=data, + tenant_no="zkxw", + user_id="user-1", + dept_id="dept-1", + ) + self.assertIn("渠道", str(ctx.exception)) + class TestBasicExperimentSaleSchedules(unittest.TestCase): @patch("app.crud.pilot_application.create_schedule") diff --git a/web-admin/src/config/pilot-biz-type.ts b/web-admin/src/config/pilot-biz-type.ts index a53850c9..c4670e1c 100644 --- a/web-admin/src/config/pilot-biz-type.ts +++ b/web-admin/src/config/pilot-biz-type.ts @@ -62,7 +62,7 @@ export const PILOT_BIZ_TYPE_CONFIG: Record = { basic_experiment: { label: '临床科研', applicationNoPrefix: 'JCSY', - showChannel: false, + showChannel: true, showPatient: false, showConsent: false, showOtherAttachments: false, diff --git a/web-admin/src/views/pilot-service/pilot-application/ApplicationFormDialog.vue b/web-admin/src/views/pilot-service/pilot-application/ApplicationFormDialog.vue index d0a5534a..d0ca2e5a 100644 --- a/web-admin/src/views/pilot-service/pilot-application/ApplicationFormDialog.vue +++ b/web-admin/src/views/pilot-service/pilot-application/ApplicationFormDialog.vue @@ -86,6 +86,24 @@ /> + + + + + @@ -107,7 +125,11 @@ /> - + fetchChannelServiceOrderList({ @@ -2985,7 +3009,7 @@ })) })) } - if (formData.channelId && !isClinical.value) { + if (formData.channelId && !isClinical.value && !isBasicExperiment.value) { await loadAgreements(formData.channelId) } if (isBasicExperiment.value && detail.infusionSchedules?.length) { @@ -3085,6 +3109,7 @@ if (isBasicExperiment.value) { payload.researchCategory = formData.researchCategory || undefined + payload.channelId = formData.channelId || undefined payload.projectTitle = formData.projectTitle || undefined payload.customerName = formData.customerName || undefined payload.customerContact = formData.customerContact || undefined diff --git a/web-admin/src/views/pilot-service/pilot-application/ApplicationViewDialog.vue b/web-admin/src/views/pilot-service/pilot-application/ApplicationViewDialog.vue index e75d706b..c00e6c59 100644 --- a/web-admin/src/views/pilot-service/pilot-application/ApplicationViewDialog.vue +++ b/web-admin/src/views/pilot-service/pilot-application/ApplicationViewDialog.vue @@ -82,7 +82,7 @@
{{ dash(applicationDetail.customerName) }}
-
+
@@ -127,6 +127,10 @@ {{ dash(clinicalResearchCategoryLabel(applicationDetail.researchCategory)) }}
+
+
渠道名称
+
{{ dash(applicationDetail.channelName) }}
+
课题名称
{{ dash(applicationDetail.projectTitle) }}