From 6b1bf8a1d2f4d5bebf802f9e04023c1587702745 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Fri, 20 Nov 2026 15:51:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(pilot):=20=E4=B8=B4=E5=BA=8A=E7=A7=91?= =?UTF-8?q?=E7=A0=94=E7=94=B3=E8=AF=B7=E5=8D=95=E6=96=B0=E5=A2=9E=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E7=B1=BB=E5=9E=8B=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在申请单信息中增加 researchCategory(生物新技术临床科研/临床课题联合申报/生物制药研发),贯通 SQL、后端校验与 Web 表单/列表/详情;用户确认免除 Figma。 Co-authored-by: Cursor --- backend/app/api/pilot_application.py | 8 ++++++ backend/app/constants/__init__.py | 0 backend/app/constants/research_category.py | 27 +++++++++++++++++++ backend/app/crud/pilot_application.py | 16 +++++++++++ backend/app/models/models.py | 5 ++++ .../test_basic_experiment_application.py | 20 ++++++++++++++ ...20-pilot-application-research-category.sql | 20 ++++++++++++++ .../constants/clinical-research-category.ts | 18 +++++++++++++ .../ApplicationFormDialog.vue | 25 ++++++++++++++++- .../ApplicationViewDialog.vue | 7 +++++ .../pilot-application/PilotApplicationTab.vue | 12 +++++++++ 11 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 backend/app/constants/__init__.py create mode 100644 backend/app/constants/research_category.py create mode 100644 docs/sql/migrations/2026-11-20-pilot-application-research-category.sql create mode 100644 web-admin/src/constants/clinical-research-category.ts diff --git a/backend/app/api/pilot_application.py b/backend/app/api/pilot_application.py index 010a8b31..1c837b9d 100644 --- a/backend/app/api/pilot_application.py +++ b/backend/app/api/pilot_application.py @@ -53,6 +53,7 @@ class ApplicationCreateBody(BaseModel): customer_name: Optional[str] = Field(None, alias="customerName") customer_contact: Optional[str] = Field(None, alias="customerContact") customer_phone: Optional[str] = Field(None, alias="customerPhone") + research_category: Optional[str] = Field(None, alias="researchCategory") class ApplicationUpdateBody(BaseModel): @@ -65,6 +66,7 @@ class ApplicationUpdateBody(BaseModel): customer_name: Optional[str] = Field(None, alias="customerName") customer_contact: Optional[str] = Field(None, alias="customerContact") customer_phone: Optional[str] = Field(None, alias="customerPhone") + research_category: Optional[str] = Field(None, alias="researchCategory") class PatientSaveBody(BaseModel): @@ -206,6 +208,7 @@ class ApplicationSaveBody(BaseModel): customer_name: Optional[str] = Field(None, alias="customerName") customer_contact: Optional[str] = Field(None, alias="customerContact") customer_phone: Optional[str] = Field(None, alias="customerPhone") + research_category: Optional[str] = Field(None, alias="researchCategory") remark: Optional[str] = None consent_form_urls: Optional[str] = Field(None, alias="consentFormUrls") consent_attachments: Optional[list] = Field(None, alias="consentAttachments") @@ -287,6 +290,7 @@ async def api_create_application( "customerName": body.customer_name, "customerContact": body.customer_contact, "customerPhone": body.customer_phone, + "researchCategory": body.research_category, } result = pilot_application.create_application( db, @@ -322,6 +326,8 @@ async def api_update_application( data["customerContact"] = body.customer_contact if body.customer_phone is not None: data["customerPhone"] = body.customer_phone + if body.research_category is not None: + data["researchCategory"] = body.research_category result = pilot_application.update_application( db, app_id=body.id, data=data, tenant_no=tenant_no ) @@ -364,6 +370,8 @@ async def api_save_application( app_data["customerContact"] = body.customer_contact if body.customer_phone is not None: app_data["customerPhone"] = body.customer_phone + if body.research_category is not None: + app_data["researchCategory"] = body.research_category if body.consent_attachments is not None: app_data["consentAttachments"] = body.consent_attachments elif body.consent_form_urls is not None: diff --git a/backend/app/constants/__init__.py b/backend/app/constants/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/app/constants/research_category.py b/backend/app/constants/research_category.py new file mode 100644 index 00000000..6e2004b0 --- /dev/null +++ b/backend/app/constants/research_category.py @@ -0,0 +1,27 @@ +"""临床科研申请单 · 业务子类型(research_category)""" +from typing import Optional + +RESEARCH_CATEGORY_LABELS = { + "bio_tech_clinical": "生物新技术临床科研", + "joint_topic_declare": "临床课题联合申报", + "bio_pharma_rd": "生物制药研发", +} + +RESEARCH_CATEGORY_CODES = tuple(RESEARCH_CATEGORY_LABELS.keys()) + + +def research_category_label(code: Optional[str]) -> str: + if not code: + return "" + return RESEARCH_CATEGORY_LABELS.get(code, code) + + +def validate_research_category(code: Optional[str], required: bool = False) -> str: + value = (code or "").strip() + if not value: + if required: + raise ValueError("请选择业务类型") + return "" + if value not in RESEARCH_CATEGORY_LABELS: + raise ValueError("业务类型无效") + return value diff --git a/backend/app/crud/pilot_application.py b/backend/app/crud/pilot_application.py index d59fa164..5a05c2e7 100644 --- a/backend/app/crud/pilot_application.py +++ b/backend/app/crud/pilot_application.py @@ -25,6 +25,7 @@ from app.models.models import ( ) from app.crud import pilot_checkup from app.crud.collection_protocol import attachments_to_urls, urls_to_attachment_list +from app.constants.research_category import validate_research_category # ──────────────────────────────────────────── @@ -125,6 +126,7 @@ def _row_to_dict_application(row, db=None, tenant_no=None) -> Dict[str, Any]: "customerName": row.customer_name or "", "customerContact": row.customer_contact or "", "customerPhone": row.customer_phone or "", + "researchCategory": getattr(row, "research_category", None) or "", "applicationStatus": row.application_status or "", "bizType": row.biz_type or "pilot_service", "channelServiceOrderId": row.channel_service_order_id or "", @@ -455,6 +457,7 @@ def create_application( customer_name = "" customer_contact = "" customer_phone = "" + research_category = "" consent_form_urls = data.get("consentFormUrls") or None if biz_type == "basic_experiment": @@ -466,6 +469,9 @@ def create_application( raise ValueError("请填写客户联系人") if not (data.get("customerPhone") or "").strip(): raise ValueError("请填写客户联系方式") + research_category = validate_research_category( + data.get("researchCategory"), required=True + ) project_title = (data.get("projectTitle") or "").strip() customer_name = (data.get("customerName") or "").strip() customer_contact = (data.get("customerContact") or "").strip() @@ -527,6 +533,7 @@ def create_application( customer_name=customer_name or None, customer_contact=customer_contact or None, customer_phone=customer_phone or None, + research_category=research_category or None, application_status="dks", channel_service_order_id=channel_service_order_id or "", channel_id=( @@ -586,6 +593,15 @@ def update_application(db: Session, app_id: str, data: dict, tenant_no: str) -> row.customer_contact = (data["customerContact"] or "").strip() or None if "customerPhone" in data and data["customerPhone"] is not None: row.customer_phone = (data["customerPhone"] or "").strip() or None + if "researchCategory" in data and data["researchCategory"] is not None: + if (row.biz_type or "") == "basic_experiment": + row.research_category = validate_research_category( + data.get("researchCategory"), required=True + ) or None + else: + row.research_category = validate_research_category( + data.get("researchCategory"), required=False + ) or None if "consentFormUrls" in data: row.consent_form_urls = data.get("consentFormUrls") or None if "attachmentUrls" in data: diff --git a/backend/app/models/models.py b/backend/app/models/models.py index a9350612..f25aea40 100644 --- a/backend/app/models/models.py +++ b/backend/app/models/models.py @@ -4182,6 +4182,11 @@ class BizPilotApplication(Base): customer_name = Column(String(200), nullable=True, comment="客户名称(临床科研)") customer_contact = Column(String(100), nullable=True, comment="客户联系人(临床科研)") customer_phone = Column(String(32), nullable=True, comment="客户联系方式(临床科研)") + research_category = Column( + String(32), + nullable=True, + comment="临床科研业务子类型: bio_tech_clinical/joint_topic_declare/bio_pharma_rd", + ) application_status = Column(String(16), nullable=False, default="dks", comment="dks待开始 jxz进行中 ywc已完成 yzf已作废") channel_service_order_id = Column(String(64), nullable=False, comment="渠道服务购买订单ID") channel_id = Column(String(64), nullable=True, comment="渠道ID(缓存自服务订单)") diff --git a/backend/tests/test_basic_experiment_application.py b/backend/tests/test_basic_experiment_application.py index 1c82df20..48ae9429 100644 --- a/backend/tests/test_basic_experiment_application.py +++ b/backend/tests/test_basic_experiment_application.py @@ -28,6 +28,7 @@ class TestBasicExperimentCreateValidation(unittest.TestCase): db = MagicMock() data = { "bizType": "basic_experiment", + "researchCategory": "bio_tech_clinical", "projectTitle": "课题A", "customerName": "", "customerContact": "张三", @@ -43,6 +44,25 @@ class TestBasicExperimentCreateValidation(unittest.TestCase): ) self.assertIn("客户名称", str(ctx.exception)) + def test_create_basic_experiment_requires_research_category(self): + db = MagicMock() + data = { + "bizType": "basic_experiment", + "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/docs/sql/migrations/2026-11-20-pilot-application-research-category.sql b/docs/sql/migrations/2026-11-20-pilot-application-research-category.sql new file mode 100644 index 00000000..e8e187c9 --- /dev/null +++ b/docs/sql/migrations/2026-11-20-pilot-application-research-category.sql @@ -0,0 +1,20 @@ +-- 临床科研申请单:业务子类型 research_category +-- MySQL 5.7,可重复执行。 + +SET @col_exists := ( + SELECT COUNT(*) + FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() + AND TABLE_NAME = 'biz_pilot_application' + AND COLUMN_NAME = 'research_category' +); + +SET @sql := IF( + @col_exists = 0, + "ALTER TABLE biz_pilot_application ADD COLUMN research_category VARCHAR(32) NULL COMMENT '临床科研业务子类型: bio_tech_clinical/joint_topic_declare/bio_pharma_rd' AFTER customer_phone", + 'SELECT 1' +); + +PREPARE stmt FROM @sql; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; diff --git a/web-admin/src/constants/clinical-research-category.ts b/web-admin/src/constants/clinical-research-category.ts new file mode 100644 index 00000000..3fda1dce --- /dev/null +++ b/web-admin/src/constants/clinical-research-category.ts @@ -0,0 +1,18 @@ +/** 临床科研申请单 · 业务子类型(researchCategory) */ +export const CLINICAL_RESEARCH_CATEGORY_OPTIONS = [ + { value: 'bio_tech_clinical', label: '生物新技术临床科研' }, + { value: 'joint_topic_declare', label: '临床课题联合申报' }, + { value: 'bio_pharma_rd', label: '生物制药研发' } +] as const + +export type ClinicalResearchCategory = + (typeof CLINICAL_RESEARCH_CATEGORY_OPTIONS)[number]['value'] + +const LABEL_MAP = Object.fromEntries( + CLINICAL_RESEARCH_CATEGORY_OPTIONS.map((o) => [o.value, o.label]) +) as Record + +export function clinicalResearchCategoryLabel(code?: string | null): string { + if (!code) return '' + return LABEL_MAP[code] || code +} 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 58700572..d0a5534a 100644 --- a/web-admin/src/views/pilot-service/pilot-application/ApplicationFormDialog.vue +++ b/web-admin/src/views/pilot-service/pilot-application/ApplicationFormDialog.vue @@ -71,6 +71,21 @@ /> + + +