Files
zkxw/backend/app/services/project_assignment.py
T
cykjandCursor c22a0d1eb0 feat(market): 完善临床科研与委托加工上线能力
补齐项目组负责人审批、费用信息、合作客户、生产出库菜单、申请单号 LCKY 前缀及配套 SQL 迁移,并同步相关前后端与单测。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-30 18:51:37 +08:00

55 lines
2.4 KiB
Python

"""Shared attribution boundary for existing business write and read paths."""
from fastapi import HTTPException
from app.core.config import settings
def create_assignment(db, tenant_no, user, project_id, biz_type):
from app.services.project_management import validate_assignment
from app.constants.pilot_biz import requires_leader_approval
if biz_type == 'clinical_application':
if project_id:
raise HTTPException(400, '临床应用不支持项目归属')
return None
# 临床科研/委托加工须绑定项目,供项目组负责人审批
required = True if requires_leader_approval(biz_type) else settings.PROJECT_ASSIGNMENT_REQUIRED
return validate_assignment(db, tenant_no, user, project_id, biz_type,
required=required)
def guard_project_edit(row, payload):
"""Omission preserves attribution; explicit changes require audited maintenance."""
key = 'projectId' if 'projectId' in payload else 'project_id'
if key in payload and (payload[key] or None) != (row.project_id or None):
raise HTTPException(400, '请通过项目归属维护调整')
def assignment_brief(db, tenant_no, project_id):
if not db or not project_id:
return dict(projectId=project_id, projectName=None, teamId=None, teamName=None)
from app.services.project_management import project_brief
return project_brief(db, tenant_no, project_id)
def filter_assignment(query, model, db, tenant_no, project_id=None, team_id=None):
if project_id:
query = query.filter(model.project_id == project_id)
if team_id:
from app.models.project_management import Project
projects = db.query(Project.id).filter(Project.tenant_no == tenant_no,
Project.team_id == team_id, Project.del_flag == 0)
query = query.filter(model.project_id.in_(projects))
return query
def accessible_order(db, model, tenant_no, user, record_id, *, lock=False):
from app.core.data_scope import apply_data_scope
query = db.query(model).filter(model.id == record_id, model.tenant_no == tenant_no,
model.del_flag == 0)
query = apply_data_scope(query, model, user, db, tenant_no)
if lock:
query = query.populate_existing().with_for_update()
row = query.first()
if row is None:
raise HTTPException(404, '单据不存在或无权访问')
return row