Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9aa16ef31 | ||
|
|
7751cc0f4a | ||
|
|
0346bc0b1d | ||
|
|
76ddb81818 |
No files matched your search
@@ -29,6 +29,7 @@ from app.crud import user as user_svc
|
|||||||
from app.crud.collection_protocol import _lookup_attachment_by_url
|
from app.crud.collection_protocol import _lookup_attachment_by_url
|
||||||
from app.models.models import BizAttachment, SysDept, SysRole, SysUser, SysMenu, SysPost
|
from app.models.models import BizAttachment, SysDept, SysRole, SysUser, SysMenu, SysPost
|
||||||
from app.services.permission_administration import validate_tenant_references
|
from app.services.permission_administration import validate_tenant_references
|
||||||
|
from app.services.user_select_options import prioritize_caller_dept_options
|
||||||
from app.services.web_auth_roles import (
|
from app.services.web_auth_roles import (
|
||||||
_map_role_name_to_web,
|
_map_role_name_to_web,
|
||||||
list_user_ids_with_effective_role_name,
|
list_user_ids_with_effective_role_name,
|
||||||
@@ -77,12 +78,15 @@ async def list_roles_for_select(
|
|||||||
@router.get("/users/options")
|
@router.get("/users/options")
|
||||||
async def list_users_for_select(
|
async def list_users_for_select(
|
||||||
roleName: Optional[str] = Query(None, alias="roleName"),
|
roleName: Optional[str] = Query(None, alias="roleName"),
|
||||||
|
prioritizeCallerDept: bool = Query(False, alias="prioritizeCallerDept"),
|
||||||
_user: dict = Depends(require_admin_or_super_admin),
|
_user: dict = Depends(require_admin_or_super_admin),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""返回用户下拉选项(label=昵称,value=用户ID),供流程设计器审批人选择使用。
|
"""返回用户下拉选项(label=昵称,value=用户ID,deptId=部门ID)。
|
||||||
|
|
||||||
|
供流程设计器审批人选择、OA 评论 @ 人员等使用。
|
||||||
可选 roleName:按有效角色(直接绑定 ∪ 职位继承)精确过滤。
|
可选 roleName:按有效角色(直接绑定 ∪ 职位继承)精确过滤。
|
||||||
|
可选 prioritizeCallerDept:当前登录用户同部门人员排在前面(组内仍按创建时间倒序)。
|
||||||
"""
|
"""
|
||||||
tenant_no = _user.get("tenant_no", "")
|
tenant_no = _user.get("tenant_no", "")
|
||||||
q = db.query(SysUser).filter(SysUser.del_flag == 0, SysUser.status == "1")
|
q = db.query(SysUser).filter(SysUser.del_flag == 0, SysUser.status == "1")
|
||||||
@@ -97,7 +101,16 @@ async def list_users_for_select(
|
|||||||
return success_response([])
|
return success_response([])
|
||||||
q = q.filter(SysUser.id.in_(matched_ids))
|
q = q.filter(SysUser.id.in_(matched_ids))
|
||||||
rows = q.order_by(SysUser.create_time.desc()).distinct().all()
|
rows = q.order_by(SysUser.create_time.desc()).distinct().all()
|
||||||
out = [{"label": (r.nick_name or r.user_no or ""), "value": r.id} for r in rows]
|
out = [
|
||||||
|
{
|
||||||
|
"label": (r.nick_name or r.user_no or ""),
|
||||||
|
"value": r.id,
|
||||||
|
"deptId": (r.dept_id or ""),
|
||||||
|
}
|
||||||
|
for r in rows
|
||||||
|
]
|
||||||
|
if prioritizeCallerDept:
|
||||||
|
out = prioritize_caller_dept_options(out, _user.get("region_id") or "")
|
||||||
return success_response(out)
|
return success_response(out)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1045,12 +1045,11 @@ def create_sample_reception(
|
|||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
create_dept_id=create_dept_id or "",
|
create_dept_id=create_dept_id or "",
|
||||||
)
|
)
|
||||||
if conclusion == "bj":
|
from app.services.protocol_reception_discard_sync import after_sample_reception_saved
|
||||||
from app.services.protocol_reception_discard_sync import after_sample_reception_saved
|
|
||||||
|
|
||||||
after_sample_reception_saved(
|
after_sample_reception_saved(
|
||||||
db, reception=obj, tenant_no=tenant_no, user_id=user_id
|
db, reception=obj, tenant_no=tenant_no, user_id=user_id
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(obj)
|
db.refresh(obj)
|
||||||
return obj
|
return obj
|
||||||
@@ -1169,12 +1168,11 @@ def update_sample_reception(
|
|||||||
)
|
)
|
||||||
check_result_svc.sync_legacy_columns_from_results(db, rec, saved_rows)
|
check_result_svc.sync_legacy_columns_from_results(db, rec, saved_rows)
|
||||||
db.add(rec)
|
db.add(rec)
|
||||||
if conclusion == "bj":
|
from app.services.protocol_reception_discard_sync import after_sample_reception_saved
|
||||||
from app.services.protocol_reception_discard_sync import after_sample_reception_saved
|
|
||||||
|
|
||||||
after_sample_reception_saved(
|
after_sample_reception_saved(
|
||||||
db, reception=rec, tenant_no=tenant_no, user_id=user_id
|
db, reception=rec, tenant_no=tenant_no, user_id=user_id
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(rec)
|
db.refresh(rec)
|
||||||
return rec
|
return rec
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
"""市场协议无效态 ↔ 样本接收废弃 / 样本状态作废联动。
|
"""市场协议无效态 ↔ 样本接收废弃 / 样本状态作废联动。
|
||||||
|
|
||||||
规则(细胞存储 / 科研捐赠):
|
规则(细胞存储 / 科研捐赠):
|
||||||
1. 协议变为已作废(yzf)或属地废弃(sdfq)时:
|
1. 单条样本接收结论为废弃(bj)时:仅该样本 `sample_status` 置为已作废(yzf)并写 `void_date`;
|
||||||
|
协议状态保持不变。接收结论改回接收(js)且协议仍有效时:若该样本为 yzf,则清空状态与 void_date。
|
||||||
|
2. 协议变为已作废(yzf)或属地废弃(sdfq)时:
|
||||||
- 协议下全部样本接收结论自动为废弃(bj);
|
- 协议下全部样本接收结论自动为废弃(bj);
|
||||||
- 协议下全部有效样本 `sample_status` 置为已作废(yzf),并写入 `void_date`。
|
- 协议下全部有效样本 `sample_status` 置为已作废(yzf),并写入 `void_date`。
|
||||||
2. 协议下全部有效样本均已废弃/拒收(bj)时,协议自动已作废,作废类型为「实验室废弃」。
|
3. 协议下全部有效样本均已废弃/拒收(bj)时,协议自动已作废,作废类型为「实验室废弃」。
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
@@ -471,6 +473,160 @@ def maybe_void_protocol_when_all_samples_discarded(
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def _find_sample_for_reception(
|
||||||
|
db: Session,
|
||||||
|
*,
|
||||||
|
reception: BizSampleReception,
|
||||||
|
tenant_no: str,
|
||||||
|
) -> tuple[str, Optional[Union[BizProtocolSample, BizResearchDonationSample]]]:
|
||||||
|
source = (reception.reception_source or "cell_storage").strip() or "cell_storage"
|
||||||
|
tenant = (tenant_no or "").strip()
|
||||||
|
code = (reception.sample_code or "").strip()
|
||||||
|
if source == "cell_storage":
|
||||||
|
sid = (reception.protocol_sample_id or "").strip()
|
||||||
|
if sid:
|
||||||
|
obj = (
|
||||||
|
db.query(BizProtocolSample)
|
||||||
|
.filter(
|
||||||
|
BizProtocolSample.id == sid,
|
||||||
|
BizProtocolSample.tenant_no == tenant,
|
||||||
|
BizProtocolSample.del_flag == 0,
|
||||||
|
)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
if obj:
|
||||||
|
return source, obj
|
||||||
|
pid = (reception.collection_protocol_id or "").strip()
|
||||||
|
if code and pid:
|
||||||
|
return source, (
|
||||||
|
db.query(BizProtocolSample)
|
||||||
|
.filter(
|
||||||
|
BizProtocolSample.collection_protocol_id == pid,
|
||||||
|
BizProtocolSample.sample_code == code,
|
||||||
|
BizProtocolSample.tenant_no == tenant,
|
||||||
|
BizProtocolSample.del_flag == 0,
|
||||||
|
)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
return source, None
|
||||||
|
|
||||||
|
sid = (reception.donation_sample_id or "").strip()
|
||||||
|
if sid:
|
||||||
|
obj = (
|
||||||
|
db.query(BizResearchDonationSample)
|
||||||
|
.filter(
|
||||||
|
BizResearchDonationSample.id == sid,
|
||||||
|
BizResearchDonationSample.tenant_no == tenant,
|
||||||
|
BizResearchDonationSample.del_flag == 0,
|
||||||
|
)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
if obj:
|
||||||
|
return source, obj
|
||||||
|
pid = (reception.research_donation_id or "").strip()
|
||||||
|
if code and pid:
|
||||||
|
return source, (
|
||||||
|
db.query(BizResearchDonationSample)
|
||||||
|
.filter(
|
||||||
|
BizResearchDonationSample.research_donation_id == pid,
|
||||||
|
BizResearchDonationSample.sample_code == code,
|
||||||
|
BizResearchDonationSample.tenant_no == tenant,
|
||||||
|
BizResearchDonationSample.del_flag == 0,
|
||||||
|
)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
return source, None
|
||||||
|
|
||||||
|
|
||||||
|
def _protocol_is_inactive(
|
||||||
|
db: Session,
|
||||||
|
*,
|
||||||
|
source: str,
|
||||||
|
protocol_id: str,
|
||||||
|
tenant_no: str,
|
||||||
|
) -> bool:
|
||||||
|
src = (source or "").strip()
|
||||||
|
pid = (protocol_id or "").strip()
|
||||||
|
tenant = (tenant_no or "").strip()
|
||||||
|
if not pid or not tenant:
|
||||||
|
return False
|
||||||
|
if src == "cell_storage":
|
||||||
|
obj = (
|
||||||
|
db.query(BizCollectionProtocol)
|
||||||
|
.filter(
|
||||||
|
BizCollectionProtocol.id == pid,
|
||||||
|
BizCollectionProtocol.tenant_no == tenant,
|
||||||
|
BizCollectionProtocol.del_flag == 0,
|
||||||
|
)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
status = (obj.protocol_status or "").strip() if obj else ""
|
||||||
|
else:
|
||||||
|
obj = (
|
||||||
|
db.query(BizResearchDonation)
|
||||||
|
.filter(
|
||||||
|
BizResearchDonation.id == pid,
|
||||||
|
BizResearchDonation.tenant_no == tenant,
|
||||||
|
BizResearchDonation.del_flag == 0,
|
||||||
|
)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
status = (obj.donation_status or "").strip() if obj else ""
|
||||||
|
return status in INACTIVE_PROTOCOL_STATUSES
|
||||||
|
|
||||||
|
|
||||||
|
def void_sample_for_discarded_reception(
|
||||||
|
db: Session,
|
||||||
|
*,
|
||||||
|
reception: BizSampleReception,
|
||||||
|
tenant_no: str,
|
||||||
|
user_id: Optional[str] = None,
|
||||||
|
) -> bool:
|
||||||
|
"""单条接收废弃:仅将该样本置为已作废。"""
|
||||||
|
_source, sample = _find_sample_for_reception(db, reception=reception, tenant_no=tenant_no)
|
||||||
|
if not sample:
|
||||||
|
return False
|
||||||
|
now = datetime.now()
|
||||||
|
sample.sample_status = SAMPLE_VOID_STATUS
|
||||||
|
sample.void_date = _void_date_yyyymmdd(void_time=reception.reception_time or now)
|
||||||
|
sample.update_by = user_id
|
||||||
|
sample.update_time = now
|
||||||
|
db.add(sample)
|
||||||
|
db.flush()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def clear_sample_void_for_accepted_reception(
|
||||||
|
db: Session,
|
||||||
|
*,
|
||||||
|
reception: BizSampleReception,
|
||||||
|
tenant_no: str,
|
||||||
|
user_id: Optional[str] = None,
|
||||||
|
) -> bool:
|
||||||
|
"""接收改回接收:协议仍有效且样本为 yzf 时,清空样本作废状态。"""
|
||||||
|
source, sample = _find_sample_for_reception(db, reception=reception, tenant_no=tenant_no)
|
||||||
|
if not sample:
|
||||||
|
return False
|
||||||
|
if (sample.sample_status or "").strip() != SAMPLE_VOID_STATUS:
|
||||||
|
return False
|
||||||
|
if source == "cell_storage":
|
||||||
|
protocol_id = (reception.collection_protocol_id or "").strip()
|
||||||
|
else:
|
||||||
|
protocol_id = (reception.research_donation_id or "").strip()
|
||||||
|
if _protocol_is_inactive(
|
||||||
|
db, source=source, protocol_id=protocol_id, tenant_no=tenant_no
|
||||||
|
):
|
||||||
|
return False
|
||||||
|
now = datetime.now()
|
||||||
|
sample.sample_status = None
|
||||||
|
sample.void_date = None
|
||||||
|
sample.update_by = user_id
|
||||||
|
sample.update_time = now
|
||||||
|
db.add(sample)
|
||||||
|
db.flush()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def after_sample_reception_saved(
|
def after_sample_reception_saved(
|
||||||
db: Session,
|
db: Session,
|
||||||
*,
|
*,
|
||||||
@@ -478,23 +634,32 @@ def after_sample_reception_saved(
|
|||||||
tenant_no: str,
|
tenant_no: str,
|
||||||
user_id: Optional[str] = None,
|
user_id: Optional[str] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""样本接收保存后:若结论为废弃,尝试自动作废所属协议。"""
|
"""样本接收保存后:同步该样本状态;若全部废弃则尝试自动作废协议。"""
|
||||||
if (reception.accept_conclusion or "").strip() != "bj":
|
conclusion = (reception.accept_conclusion or "").strip()
|
||||||
return
|
|
||||||
source = (reception.reception_source or "cell_storage").strip() or "cell_storage"
|
source = (reception.reception_source or "cell_storage").strip() or "cell_storage"
|
||||||
if source == "cell_storage":
|
if source == "cell_storage":
|
||||||
protocol_id = (reception.collection_protocol_id or "").strip()
|
protocol_id = (reception.collection_protocol_id or "").strip()
|
||||||
else:
|
else:
|
||||||
protocol_id = (reception.research_donation_id or "").strip()
|
protocol_id = (reception.research_donation_id or "").strip()
|
||||||
if not protocol_id:
|
|
||||||
|
if conclusion == "bj":
|
||||||
|
void_sample_for_discarded_reception(
|
||||||
|
db, reception=reception, tenant_no=tenant_no, user_id=user_id
|
||||||
|
)
|
||||||
|
if protocol_id:
|
||||||
|
maybe_void_protocol_when_all_samples_discarded(
|
||||||
|
db,
|
||||||
|
source=source,
|
||||||
|
protocol_id=protocol_id,
|
||||||
|
tenant_no=tenant_no,
|
||||||
|
user_id=user_id,
|
||||||
|
)
|
||||||
return
|
return
|
||||||
maybe_void_protocol_when_all_samples_discarded(
|
|
||||||
db,
|
if conclusion == "js":
|
||||||
source=source,
|
clear_sample_void_for_accepted_reception(
|
||||||
protocol_id=protocol_id,
|
db, reception=reception, tenant_no=tenant_no, user_id=user_id
|
||||||
tenant_no=tenant_no,
|
)
|
||||||
user_id=user_id,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def after_protocol_voided(
|
def after_protocol_voided(
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
"""用户下拉选项:同部门优先排序等轻量辅助。"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any, Dict, List, Sequence
|
||||||
|
|
||||||
|
|
||||||
|
def prioritize_caller_dept_options(
|
||||||
|
options: Sequence[Dict[str, Any]],
|
||||||
|
caller_dept_id: str,
|
||||||
|
) -> List[Dict[str, Any]]:
|
||||||
|
"""稳定排序:当前登录用户同部门在前,其余保持原相对顺序。"""
|
||||||
|
items = list(options)
|
||||||
|
dept = (caller_dept_id or "").strip()
|
||||||
|
if not dept or not items:
|
||||||
|
return items
|
||||||
|
return sorted(
|
||||||
|
items,
|
||||||
|
key=lambda item: 0 if str(item.get("deptId") or "").strip() == dept else 1,
|
||||||
|
)
|
||||||
@@ -399,6 +399,143 @@ class TestProtocolReceptionDiscardSync(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(rec.accept_conclusion, "bj")
|
self.assertEqual(rec.accept_conclusion, "bj")
|
||||||
|
|
||||||
|
def test_single_reception_discard_voids_only_that_sample(self):
|
||||||
|
db = _session()
|
||||||
|
now = _now()
|
||||||
|
db.add(
|
||||||
|
BizCollectionProtocol(
|
||||||
|
id="p-multi",
|
||||||
|
protocol_no="CP-MULTI",
|
||||||
|
protocol_status="sxz",
|
||||||
|
tenant_no="tenant-a",
|
||||||
|
create_dept_id="",
|
||||||
|
create_time=now,
|
||||||
|
update_time=now,
|
||||||
|
del_flag=0,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
for sid, code, status in (
|
||||||
|
("sa", "ZKA", "ycj"),
|
||||||
|
("sb", "ZKB", "ycj"),
|
||||||
|
("sc", "ZKC", "ycj"),
|
||||||
|
):
|
||||||
|
db.add(
|
||||||
|
BizProtocolSample(
|
||||||
|
id=sid,
|
||||||
|
collection_protocol_id="p-multi",
|
||||||
|
sample_code=code,
|
||||||
|
sample_status=status,
|
||||||
|
tenant_no="tenant-a",
|
||||||
|
create_dept_id="",
|
||||||
|
create_time=now,
|
||||||
|
update_time=now,
|
||||||
|
del_flag=0,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
rec_a = BizSampleReception(
|
||||||
|
id="ra",
|
||||||
|
protocol_sample_id="sa",
|
||||||
|
collection_protocol_id="p-multi",
|
||||||
|
reception_time=now,
|
||||||
|
accept_conclusion="bj",
|
||||||
|
reception_source="cell_storage",
|
||||||
|
sample_code="ZKA",
|
||||||
|
tenant_no="tenant-a",
|
||||||
|
create_dept_id="",
|
||||||
|
create_time=now,
|
||||||
|
update_time=now,
|
||||||
|
del_flag=0,
|
||||||
|
check_packaging=0,
|
||||||
|
check_sealing=0,
|
||||||
|
check_no_damage=0,
|
||||||
|
check_no_leakage=0,
|
||||||
|
check_color=0,
|
||||||
|
check_tying_rope=0,
|
||||||
|
check_no_stratification=0,
|
||||||
|
)
|
||||||
|
db.add(rec_a)
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
after_sample_reception_saved(
|
||||||
|
db, reception=rec_a, tenant_no="tenant-a", user_id="u1"
|
||||||
|
)
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
proto = db.query(BizCollectionProtocol).filter(BizCollectionProtocol.id == "p-multi").one()
|
||||||
|
self.assertEqual(proto.protocol_status, "sxz")
|
||||||
|
by_id = {
|
||||||
|
s.id: s
|
||||||
|
for s in db.query(BizProtocolSample)
|
||||||
|
.filter(BizProtocolSample.collection_protocol_id == "p-multi")
|
||||||
|
.all()
|
||||||
|
}
|
||||||
|
self.assertEqual(by_id["sa"].sample_status, SAMPLE_VOID_STATUS)
|
||||||
|
self.assertEqual(by_id["sa"].void_date, "20261105")
|
||||||
|
self.assertEqual(by_id["sb"].sample_status, "ycj")
|
||||||
|
self.assertEqual(by_id["sc"].sample_status, "ycj")
|
||||||
|
|
||||||
|
def test_reception_accept_clears_sample_void_when_protocol_active(self):
|
||||||
|
db = _session()
|
||||||
|
now = _now()
|
||||||
|
db.add(
|
||||||
|
BizCollectionProtocol(
|
||||||
|
id="p-clear",
|
||||||
|
protocol_no="CP-CLEAR",
|
||||||
|
protocol_status="sxz",
|
||||||
|
tenant_no="tenant-a",
|
||||||
|
create_dept_id="",
|
||||||
|
create_time=now,
|
||||||
|
update_time=now,
|
||||||
|
del_flag=0,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
db.add(
|
||||||
|
BizProtocolSample(
|
||||||
|
id="s-clear",
|
||||||
|
collection_protocol_id="p-clear",
|
||||||
|
sample_code="ZKCLR",
|
||||||
|
sample_status=SAMPLE_VOID_STATUS,
|
||||||
|
void_date="20261101",
|
||||||
|
tenant_no="tenant-a",
|
||||||
|
create_dept_id="",
|
||||||
|
create_time=now,
|
||||||
|
update_time=now,
|
||||||
|
del_flag=0,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
rec = BizSampleReception(
|
||||||
|
id="r-clear",
|
||||||
|
protocol_sample_id="s-clear",
|
||||||
|
collection_protocol_id="p-clear",
|
||||||
|
reception_time=now,
|
||||||
|
accept_conclusion="js",
|
||||||
|
reception_source="cell_storage",
|
||||||
|
sample_code="ZKCLR",
|
||||||
|
tenant_no="tenant-a",
|
||||||
|
create_dept_id="",
|
||||||
|
create_time=now,
|
||||||
|
update_time=now,
|
||||||
|
del_flag=0,
|
||||||
|
check_packaging=0,
|
||||||
|
check_sealing=0,
|
||||||
|
check_no_damage=0,
|
||||||
|
check_no_leakage=0,
|
||||||
|
check_color=0,
|
||||||
|
check_tying_rope=0,
|
||||||
|
check_no_stratification=0,
|
||||||
|
)
|
||||||
|
db.add(rec)
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
after_sample_reception_saved(
|
||||||
|
db, reception=rec, tenant_no="tenant-a", user_id="u1"
|
||||||
|
)
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
sample = db.query(BizProtocolSample).filter(BizProtocolSample.id == "s-clear").one()
|
||||||
|
self.assertFalse((sample.sample_status or "").strip())
|
||||||
|
self.assertFalse((sample.void_date or "").strip())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
"""用户下拉选项:同部门优先排序。"""
|
||||||
|
from app.services.user_select_options import prioritize_caller_dept_options
|
||||||
|
|
||||||
|
|
||||||
|
def test_prioritize_caller_dept_keeps_relative_order():
|
||||||
|
options = [
|
||||||
|
{"label": "外1", "value": "a", "deptId": "d2"},
|
||||||
|
{"label": "同1", "value": "b", "deptId": "d1"},
|
||||||
|
{"label": "外2", "value": "c", "deptId": "d3"},
|
||||||
|
{"label": "同2", "value": "d", "deptId": "d1"},
|
||||||
|
{"label": "无部门", "value": "e", "deptId": ""},
|
||||||
|
]
|
||||||
|
out = prioritize_caller_dept_options(options, "d1")
|
||||||
|
assert [x["value"] for x in out] == ["b", "d", "a", "c", "e"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_prioritize_caller_dept_noop_without_caller_dept():
|
||||||
|
options = [
|
||||||
|
{"label": "a", "value": "a", "deptId": "d1"},
|
||||||
|
{"label": "b", "value": "b", "deptId": "d2"},
|
||||||
|
]
|
||||||
|
assert prioritize_caller_dept_options(options, "") == options
|
||||||
|
assert prioritize_caller_dept_options(options, " ") == options
|
||||||
|
|
||||||
|
|
||||||
|
def test_prioritize_caller_dept_empty_list():
|
||||||
|
assert prioritize_caller_dept_options([], "d1") == []
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
-- Issue #129:样本接收结论已为废弃(bj)、但样本状态尚未作废的历史回刷
|
||||||
|
-- 细胞存储 / 科研捐赠;可重复执行。
|
||||||
|
-- 仅处理协议仍有效(非 yzf/sdfq)的样本行;已作废协议样本由 #127 回刷脚本覆盖。
|
||||||
|
|
||||||
|
-- 细胞存储
|
||||||
|
UPDATE biz_protocol_sample s
|
||||||
|
INNER JOIN biz_sample_reception r
|
||||||
|
ON r.tenant_no = s.tenant_no
|
||||||
|
AND r.del_flag = 0
|
||||||
|
AND r.reception_source = 'cell_storage'
|
||||||
|
AND r.accept_conclusion = 'bj'
|
||||||
|
AND r.sample_code = s.sample_code
|
||||||
|
AND r.collection_protocol_id = s.collection_protocol_id
|
||||||
|
INNER JOIN biz_collection_protocol p
|
||||||
|
ON p.id = s.collection_protocol_id
|
||||||
|
AND p.tenant_no = s.tenant_no
|
||||||
|
AND p.del_flag = 0
|
||||||
|
SET
|
||||||
|
s.sample_status = 'yzf',
|
||||||
|
s.void_date = CASE
|
||||||
|
WHEN s.void_date IS NOT NULL AND TRIM(s.void_date) <> '' THEN s.void_date
|
||||||
|
WHEN r.reception_time IS NOT NULL THEN DATE_FORMAT(r.reception_time, '%Y%m%d')
|
||||||
|
WHEN s.update_time IS NOT NULL THEN DATE_FORMAT(s.update_time, '%Y%m%d')
|
||||||
|
ELSE DATE_FORMAT(NOW(), '%Y%m%d')
|
||||||
|
END,
|
||||||
|
s.update_time = NOW()
|
||||||
|
WHERE s.del_flag = 0
|
||||||
|
AND p.protocol_status NOT IN ('yzf', 'sdfq')
|
||||||
|
AND (
|
||||||
|
s.sample_status IS NULL
|
||||||
|
OR TRIM(s.sample_status) = ''
|
||||||
|
OR s.sample_status <> 'yzf'
|
||||||
|
OR s.void_date IS NULL
|
||||||
|
OR TRIM(s.void_date) = ''
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 科研捐赠
|
||||||
|
UPDATE biz_research_donation_sample s
|
||||||
|
INNER JOIN biz_sample_reception r
|
||||||
|
ON r.tenant_no = s.tenant_no
|
||||||
|
AND r.del_flag = 0
|
||||||
|
AND r.reception_source = 'research_donation'
|
||||||
|
AND r.accept_conclusion = 'bj'
|
||||||
|
AND r.sample_code = s.sample_code
|
||||||
|
AND r.research_donation_id = s.research_donation_id
|
||||||
|
INNER JOIN biz_research_donation d
|
||||||
|
ON d.id = s.research_donation_id
|
||||||
|
AND d.tenant_no = s.tenant_no
|
||||||
|
AND d.del_flag = 0
|
||||||
|
SET
|
||||||
|
s.sample_status = 'yzf',
|
||||||
|
s.void_date = CASE
|
||||||
|
WHEN s.void_date IS NOT NULL AND TRIM(s.void_date) <> '' THEN s.void_date
|
||||||
|
WHEN r.reception_time IS NOT NULL THEN DATE_FORMAT(r.reception_time, '%Y%m%d')
|
||||||
|
WHEN s.update_time IS NOT NULL THEN DATE_FORMAT(s.update_time, '%Y%m%d')
|
||||||
|
ELSE DATE_FORMAT(NOW(), '%Y%m%d')
|
||||||
|
END,
|
||||||
|
s.update_time = NOW()
|
||||||
|
WHERE s.del_flag = 0
|
||||||
|
AND d.donation_status NOT IN ('yzf', 'sdfq')
|
||||||
|
AND (
|
||||||
|
s.sample_status IS NULL
|
||||||
|
OR TRIM(s.sample_status) = ''
|
||||||
|
OR s.sample_status <> 'yzf'
|
||||||
|
OR s.void_date IS NULL
|
||||||
|
OR TRIM(s.void_date) = ''
|
||||||
|
);
|
||||||
@@ -216,7 +216,8 @@ async function ensureUserCache() {
|
|||||||
if (userCachePromise) return userCachePromise
|
if (userCachePromise) return userCachePromise
|
||||||
userCachePromise = (async () => {
|
userCachePromise = (async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetchUserOptions()
|
// 同部门优先:由后端按当前登录用户部门排序
|
||||||
|
const res = await fetchUserOptions({ prioritizeCallerDept: true })
|
||||||
const list = Array.isArray(res) ? res : res?.list || []
|
const list = Array.isArray(res) ? res : res?.list || []
|
||||||
const next = []
|
const next = []
|
||||||
const seen = new Set()
|
const seen = new Set()
|
||||||
|
|||||||
@@ -22,9 +22,12 @@ export function fetchGetRoleList() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 流程设计器:用户下拉选项(label=昵称,value=用户ID) */
|
/** 用户下拉选项(label=昵称,value=用户ID;可选 deptId / prioritizeCallerDept) */
|
||||||
export function fetchUserOptions(params?: { roleName?: string }) {
|
export function fetchUserOptions(params?: {
|
||||||
return request.get<Array<{ label: string; value: string }>>({
|
roleName?: string
|
||||||
|
prioritizeCallerDept?: boolean
|
||||||
|
}) {
|
||||||
|
return request.get<Array<{ label: string; value: string; deptId?: string }>>({
|
||||||
url: '/web/admin/users/options',
|
url: '/web/admin/users/options',
|
||||||
params
|
params
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -255,7 +255,8 @@
|
|||||||
if (userCachePromise) return userCachePromise
|
if (userCachePromise) return userCachePromise
|
||||||
userCachePromise = (async () => {
|
userCachePromise = (async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetchUserOptions()
|
// 同部门优先:由后端按当前登录用户部门排序
|
||||||
|
const res = await fetchUserOptions({ prioritizeCallerDept: true })
|
||||||
const list = Array.isArray(res) ? res : []
|
const list = Array.isArray(res) ? res : []
|
||||||
const next: MentionUser[] = []
|
const next: MentionUser[] = []
|
||||||
const seen = new Set<string>()
|
const seen = new Set<string>()
|
||||||
|
|||||||
Reference in new issue
Block a user