提交
This commit is contained in:
1 parent
f90726927e
commit
6eea13370c
103 files changed
+38401
-32231
No files matched your search
@@ -180,6 +180,8 @@ class ProtocolCreateBody(BaseModel):
|
||||
protocol_no_id: Optional[str] = Field(None, alias="protocolNoId")
|
||||
protocol_status: str = Field("dsx", alias="protocolStatus")
|
||||
protocol_attachments: Optional[str] = Field(None, alias="protocolAttachments")
|
||||
consent_form_urls: Optional[str] = Field(None, alias="consentFormUrls")
|
||||
health_survey_form_urls: Optional[str] = Field(None, alias="healthSurveyFormUrls")
|
||||
register_date: Optional[str] = Field(None, alias="registerDate")
|
||||
collector_user_id: Optional[str] = Field(None, alias="collectorUserId")
|
||||
remark: Optional[str] = None
|
||||
@@ -189,6 +191,8 @@ class ProtocolCreateBody(BaseModel):
|
||||
payment: Optional[dict] = Field(None, alias="payment")
|
||||
payment_details: Optional[list] = Field(None, alias="paymentDetails")
|
||||
attachments: Optional[list] = Field(None, alias="attachments")
|
||||
consent_attachments: Optional[list] = Field(None, alias="consentAttachments")
|
||||
health_survey_attachments: Optional[list] = Field(None, alias="healthSurveyAttachments")
|
||||
storage_cert: Optional[dict] = Field(None, alias="storageCert")
|
||||
|
||||
|
||||
@@ -198,6 +202,8 @@ class ProtocolUpdateBody(BaseModel):
|
||||
protocol_no: Optional[str] = Field(None, alias="protocolNo")
|
||||
protocol_status: Optional[str] = Field(None, alias="protocolStatus")
|
||||
protocol_attachments: Optional[str] = Field(None, alias="protocolAttachments")
|
||||
consent_form_urls: Optional[str] = Field(None, alias="consentFormUrls")
|
||||
health_survey_form_urls: Optional[str] = Field(None, alias="healthSurveyFormUrls")
|
||||
register_date: Optional[str] = Field(None, alias="registerDate")
|
||||
effective_time: Optional[str] = Field(None, alias="effectiveTime")
|
||||
effective_desc: Optional[str] = Field(None, alias="effectiveDesc")
|
||||
@@ -216,6 +222,8 @@ class ProtocolUpdateBody(BaseModel):
|
||||
payment: Optional[dict] = Field(None, alias="payment")
|
||||
payment_details: Optional[list] = Field(None, alias="paymentDetails")
|
||||
attachments: Optional[list] = Field(None, alias="attachments")
|
||||
consent_attachments: Optional[list] = Field(None, alias="consentAttachments")
|
||||
health_survey_attachments: Optional[list] = Field(None, alias="healthSurveyAttachments")
|
||||
storage_cert: Optional[dict] = Field(None, alias="storageCert")
|
||||
|
||||
|
||||
@@ -229,6 +237,26 @@ def _resolve_protocol_attachments(
|
||||
return protocol_attachments
|
||||
|
||||
|
||||
def _resolve_consent_form_urls(
|
||||
consent_form_urls: Optional[str],
|
||||
consent_attachments: Optional[list],
|
||||
) -> Optional[str]:
|
||||
from_urls = cp_svc.attachments_to_urls(consent_attachments)
|
||||
if from_urls:
|
||||
return from_urls
|
||||
return consent_form_urls
|
||||
|
||||
|
||||
def _resolve_health_survey_form_urls(
|
||||
health_survey_form_urls: Optional[str],
|
||||
health_survey_attachments: Optional[list],
|
||||
) -> Optional[str]:
|
||||
from_urls = cp_svc.attachments_to_urls(health_survey_attachments)
|
||||
if from_urls:
|
||||
return from_urls
|
||||
return health_survey_form_urls
|
||||
|
||||
|
||||
def _persist_protocol_sub_resources(
|
||||
db: Session,
|
||||
protocol_id: str,
|
||||
@@ -277,6 +305,14 @@ async def create_collection_protocol(
|
||||
body.protocol_attachments,
|
||||
body.attachments,
|
||||
)
|
||||
consent_form_urls = _resolve_consent_form_urls(
|
||||
body.consent_form_urls,
|
||||
body.consent_attachments,
|
||||
)
|
||||
health_survey_form_urls = _resolve_health_survey_form_urls(
|
||||
body.health_survey_form_urls,
|
||||
body.health_survey_attachments,
|
||||
)
|
||||
collector = (body.collector_user_id or "").strip()
|
||||
if not collector:
|
||||
collector = user_id
|
||||
@@ -286,6 +322,8 @@ async def create_collection_protocol(
|
||||
protocol_no_id=body.protocol_no_id,
|
||||
protocol_status=body.protocol_status,
|
||||
protocol_attachments=protocol_attachments,
|
||||
consent_form_urls=consent_form_urls,
|
||||
health_survey_form_urls=health_survey_form_urls,
|
||||
register_date=body.register_date,
|
||||
collector_user_id=collector,
|
||||
remark=body.remark,
|
||||
@@ -325,7 +363,8 @@ async def update_collection_protocol(
|
||||
payload = body.model_dump(exclude_unset=True, by_alias=False)
|
||||
sub_keys = {
|
||||
"party_customer", "collection_info", "samples",
|
||||
"payment", "payment_details", "attachments", "storage_cert",
|
||||
"payment", "payment_details", "attachments",
|
||||
"consent_attachments", "health_survey_attachments", "storage_cert",
|
||||
}
|
||||
main_payload = {k: v for k, v in payload.items() if k not in sub_keys}
|
||||
if body.attachments is not None:
|
||||
@@ -335,6 +374,20 @@ async def update_collection_protocol(
|
||||
)
|
||||
if resolved is not None:
|
||||
main_payload["protocol_attachments"] = resolved
|
||||
if body.consent_attachments is not None:
|
||||
resolved = _resolve_consent_form_urls(
|
||||
main_payload.get("consent_form_urls"),
|
||||
body.consent_attachments,
|
||||
)
|
||||
if resolved is not None:
|
||||
main_payload["consent_form_urls"] = resolved
|
||||
if body.health_survey_attachments is not None:
|
||||
resolved = _resolve_health_survey_form_urls(
|
||||
main_payload.get("health_survey_form_urls"),
|
||||
body.health_survey_attachments,
|
||||
)
|
||||
if resolved is not None:
|
||||
main_payload["health_survey_form_urls"] = resolved
|
||||
obj = cp_svc.update_collection_protocol(
|
||||
db,
|
||||
protocol_id,
|
||||
|
||||
@@ -661,6 +661,17 @@ STATIC_MENU_TREE = [
|
||||
"component": "/quality-inspection/qc-material/index",
|
||||
"meta": {"title": "质检物料库", "keepAlive": True, "menuCode": "biz:qcMaterial:list"},
|
||||
},
|
||||
{
|
||||
"id": "95100000000000000000000000000001",
|
||||
"name": "QualityInspectionQcMaterialAmountAuth",
|
||||
"path": "qc-material-amount-auth",
|
||||
"component": "/quality-inspection/qc-material-amount-auth/index",
|
||||
"meta": {
|
||||
"title": "质检物料金额查看授权",
|
||||
"keepAlive": True,
|
||||
"menuCode": "biz:qcMaterialAmountAuth:list",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
+152
-9
@@ -34,6 +34,8 @@ from app.crud import qc_material as mat_svc
|
||||
from app.crud import qc_material_stock_batch as batch_svc
|
||||
from app.crud import qc_material_stock_check as stock_check_svc
|
||||
from app.crud import qc_material_usage as mu_svc
|
||||
from app.crud import qc_material_amount_auth as amount_auth_svc
|
||||
from app.core.qc_material_amount_auth_constants import QC_MATERIAL_AMOUNT_AUTH_LIST_PERM
|
||||
from app.crud import inbound_sample_special as inbound_sample_special_svc
|
||||
from app.crud import qc_work_order as wo_svc
|
||||
from app.crud.collection_protocol import total_pages
|
||||
@@ -1280,6 +1282,25 @@ def _maybe_strip_qc_material_amount_fields(
|
||||
strip_row_fields(rows, *QC_MATERIAL_AMOUNT_FIELD_NAMES)
|
||||
|
||||
|
||||
def _user_can_view_qc_material_amount(db: Session, user: dict) -> bool:
|
||||
return user_has_menu_perm(db, user, QC_MATERIAL_VIEW_AMOUNT_PERM)
|
||||
|
||||
|
||||
def _strip_amount_from_write_data(db: Session, user: dict, data: Dict[str, Any]) -> None:
|
||||
if _user_can_view_qc_material_amount(db, user):
|
||||
return
|
||||
for key in ("unit_price", "unitPrice", "amount"):
|
||||
data.pop(key, None)
|
||||
|
||||
|
||||
def _resolve_stock_in_amounts(
|
||||
db: Session, user: dict, unit_price: Any, amount: Any
|
||||
) -> tuple:
|
||||
if _user_can_view_qc_material_amount(db, user):
|
||||
return unit_price, amount
|
||||
return 0, 0
|
||||
|
||||
|
||||
def _maybe_strip_qc_third_party_fee_fields(
|
||||
db: Session, user: dict, data: Dict[str, Any]
|
||||
) -> None:
|
||||
@@ -1507,6 +1528,7 @@ async def update_qc_material_batch(
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
user_id = _get_current_user_id(user)
|
||||
data = body.model_dump(exclude_none=True)
|
||||
_strip_amount_from_write_data(db, user, data)
|
||||
obj = batch_svc.update_batch(
|
||||
db,
|
||||
batch_id,
|
||||
@@ -1669,8 +1691,13 @@ async def batch_stock_in_qc_material(
|
||||
if not rt:
|
||||
return error_response(400, "入库时间格式无效")
|
||||
operate_time = rt
|
||||
items = [
|
||||
{
|
||||
items = []
|
||||
for x in body.items:
|
||||
unit_price, amount = _resolve_stock_in_amounts(
|
||||
db, user, x.unit_price, x.amount
|
||||
)
|
||||
items.append(
|
||||
{
|
||||
"material_id": x.material_id,
|
||||
"materialId": x.material_id,
|
||||
"stock_in_no": x.stock_in_no,
|
||||
@@ -1684,14 +1711,13 @@ async def batch_stock_in_qc_material(
|
||||
"batch_no": x.batch_no,
|
||||
"batchNo": x.batch_no,
|
||||
"manufacturer": x.manufacturer,
|
||||
"unit_price": x.unit_price,
|
||||
"unitPrice": x.unit_price,
|
||||
"amount": x.amount,
|
||||
"unit_price": unit_price,
|
||||
"unitPrice": unit_price,
|
||||
"amount": amount,
|
||||
"qty": x.qty,
|
||||
"remark": x.remark,
|
||||
}
|
||||
for x in body.items
|
||||
]
|
||||
)
|
||||
count = batch_svc.batch_stock_in(
|
||||
db,
|
||||
items=items,
|
||||
@@ -1803,6 +1829,9 @@ async def stock_in_qc_material(
|
||||
operate_time = rt
|
||||
from decimal import Decimal
|
||||
|
||||
unit_price, amount = _resolve_stock_in_amounts(
|
||||
db, user, body.unit_price, body.amount
|
||||
)
|
||||
obj = batch_svc.stock_in_one(
|
||||
db,
|
||||
material_id,
|
||||
@@ -1812,8 +1841,8 @@ async def stock_in_qc_material(
|
||||
catalog_no=body.catalog_no,
|
||||
batch_no=body.batch_no,
|
||||
manufacturer=body.manufacturer,
|
||||
unit_price=body.unit_price,
|
||||
amount=body.amount,
|
||||
unit_price=unit_price,
|
||||
amount=amount,
|
||||
qty=Decimal(str(body.qty)),
|
||||
remark=body.remark,
|
||||
tenant_no=tenant_no,
|
||||
@@ -2181,3 +2210,117 @@ async def cancel_qc_material_stock_check(
|
||||
return error_response(400, str(e))
|
||||
except Exception as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
# ---------- 质检物料金额查看授权 ----------
|
||||
|
||||
|
||||
class QcMaterialAmountAuthGrantBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
user_id: str = Field(..., alias="userId")
|
||||
|
||||
|
||||
class QcMaterialAmountAuthBatchBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
user_ids: List[str] = Field(..., alias="userIds", min_length=1)
|
||||
|
||||
|
||||
@router.get("/qc-material-amount-auth/users")
|
||||
async def list_qc_material_amount_auth_users(
|
||||
page: int = Query(1, ge=1),
|
||||
pageSize: int = Query(10, ge=1, le=100),
|
||||
keyword: Optional[str] = None,
|
||||
db: Session = Depends(get_db),
|
||||
user: dict = Depends(require_menu_code(QC_MATERIAL_AMOUNT_AUTH_LIST_PERM)),
|
||||
):
|
||||
"""已授权「质检物料金额查看」角色的用户列表。"""
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
items, total = amount_auth_svc.list_authorized_users(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
page=page,
|
||||
page_size=pageSize,
|
||||
keyword=keyword,
|
||||
)
|
||||
return success_response(_page_payload(items, total, page, pageSize))
|
||||
except Exception as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
@router.post("/qc-material-amount-auth/users")
|
||||
async def grant_qc_material_amount_auth(
|
||||
body: QcMaterialAmountAuthGrantBody,
|
||||
db: Session = Depends(get_db),
|
||||
user: dict = Depends(require_menu_code(QC_MATERIAL_AMOUNT_AUTH_LIST_PERM)),
|
||||
):
|
||||
"""为用户绑定「质检物料金额查看」专用角色。"""
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
operator_id = _get_current_user_id(user)
|
||||
created = amount_auth_svc.grant_amount_view_role(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
user_id=body.user_id.strip(),
|
||||
operator_id=operator_id,
|
||||
)
|
||||
msg = "授权成功" if created else "该用户已授权"
|
||||
return success_response({"created": created}, message=msg)
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
except Exception as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
@router.delete("/qc-material-amount-auth/users/{user_id}")
|
||||
async def revoke_qc_material_amount_auth(
|
||||
user_id: str,
|
||||
db: Session = Depends(get_db),
|
||||
user: dict = Depends(require_menu_code(QC_MATERIAL_AMOUNT_AUTH_LIST_PERM)),
|
||||
):
|
||||
"""解除用户的「质检物料金额查看」专用角色。"""
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
operator_id = _get_current_user_id(user)
|
||||
removed = amount_auth_svc.revoke_amount_view_role(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
user_id=user_id.strip(),
|
||||
operator_id=operator_id,
|
||||
)
|
||||
if not removed:
|
||||
return error_response(400, "该用户未授权或已解除")
|
||||
return success_response(None, message="已解除授权")
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
except Exception as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
@router.post("/qc-material-amount-auth/users/batch-revoke")
|
||||
async def batch_revoke_qc_material_amount_auth(
|
||||
body: QcMaterialAmountAuthBatchBody,
|
||||
db: Session = Depends(get_db),
|
||||
user: dict = Depends(require_menu_code(QC_MATERIAL_AMOUNT_AUTH_LIST_PERM)),
|
||||
):
|
||||
"""批量解除「质检物料金额查看」授权。"""
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
operator_id = _get_current_user_id(user)
|
||||
count = 0
|
||||
for uid in body.user_ids:
|
||||
uid = (uid or "").strip()
|
||||
if not uid:
|
||||
continue
|
||||
if amount_auth_svc.revoke_amount_view_role(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
user_id=uid,
|
||||
operator_id=operator_id,
|
||||
):
|
||||
count += 1
|
||||
return success_response({"count": count}, message=f"已解除 {count} 项授权")
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
except Exception as e:
|
||||
return error_response(400, str(e))
|
||||
@@ -49,6 +49,12 @@ class DonationCreateBody(BaseModel):
|
||||
consent_attachments: Optional[list] = Field(None, alias="consentAttachments")
|
||||
attachment_urls: Optional[str] = Field(None, alias="attachmentUrls")
|
||||
other_attachments: Optional[list] = Field(None, alias="otherAttachments")
|
||||
infectious_disease_report_urls: Optional[str] = Field(
|
||||
None, alias="infectiousDiseaseReportUrls"
|
||||
)
|
||||
infectious_disease_report_attachments: Optional[list] = Field(
|
||||
None, alias="infectiousDiseaseReportAttachments"
|
||||
)
|
||||
remark: Optional[str] = None
|
||||
party: Optional[dict] = None
|
||||
party_customer: Optional[dict] = Field(None, alias="partyCustomer")
|
||||
@@ -70,6 +76,12 @@ class DonationUpdateBody(BaseModel):
|
||||
consent_attachments: Optional[list] = Field(None, alias="consentAttachments")
|
||||
attachment_urls: Optional[str] = Field(None, alias="attachmentUrls")
|
||||
other_attachments: Optional[list] = Field(None, alias="otherAttachments")
|
||||
infectious_disease_report_urls: Optional[str] = Field(
|
||||
None, alias="infectiousDiseaseReportUrls"
|
||||
)
|
||||
infectious_disease_report_attachments: Optional[list] = Field(
|
||||
None, alias="infectiousDiseaseReportAttachments"
|
||||
)
|
||||
remark: Optional[str] = None
|
||||
party: Optional[dict] = None
|
||||
party_customer: Optional[dict] = Field(None, alias="partyCustomer")
|
||||
|
||||
Reference in new issue
Block a user