Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a011926d7 | ||
|
|
0ac8c924aa | ||
|
|
2bc20e695f | ||
|
|
95b07639e8 |
No files matched your search
@@ -1178,6 +1178,9 @@ async def list_my_qc_tasks(
|
||||
qcBizType: Optional[str] = None,
|
||||
receptionSource: Optional[str] = Query(None, alias="receptionSource"),
|
||||
bizType: Optional[str] = Query(None, alias="bizType"),
|
||||
protocolStatus: Optional[str] = Query(
|
||||
None, alias="protocolStatus", description="协议/捐赠状态,多个用英文逗号分隔"
|
||||
),
|
||||
db: Session = Depends(get_db),
|
||||
user: dict = Depends(require_menu_code("biz:myQcTask:list")),
|
||||
):
|
||||
@@ -1194,6 +1197,7 @@ async def list_my_qc_tasks(
|
||||
qc_biz_type=qcBizType,
|
||||
reception_source=receptionSource,
|
||||
biz_type=bizType,
|
||||
protocol_status=protocolStatus,
|
||||
tenant_no=tenant_no,
|
||||
)
|
||||
return success_response(_page_payload(items, total, page, pageSize))
|
||||
|
||||
@@ -23,14 +23,14 @@ def resolve_research_donation_protocol_status_filter(
|
||||
|
||||
Returns:
|
||||
("in", statuses) — 按所选状态 IN 过滤
|
||||
("none", []) — 显式空选择,无匹配结果
|
||||
("all", []) — 显式空选择,不限制协议状态
|
||||
("default", DEFAULT_QC_DONATION_PROTOCOL_STATUSES) — 未传参,与列表默认一致
|
||||
"""
|
||||
if protocol_status is None:
|
||||
return ("default", list(DEFAULT_QC_DONATION_PROTOCOL_STATUSES))
|
||||
statuses = [s.strip() for s in str(protocol_status).split(",") if s.strip()]
|
||||
if not statuses:
|
||||
return ("none", [])
|
||||
return ("all", [])
|
||||
return ("in", statuses)
|
||||
|
||||
_PROTOCOL_STATUS_LABELS = {
|
||||
|
||||
@@ -19,6 +19,8 @@ from app.crud.qc_work_order import (
|
||||
_sample_type_name_for_reception,
|
||||
_work_order_qc_biz_type,
|
||||
_OUTBOUND_BIZ_TYPE_LABELS,
|
||||
apply_research_donation_protocol_status_filter,
|
||||
build_qc_work_order_keyword_conditions,
|
||||
build_work_order_list_summaries,
|
||||
)
|
||||
from app.core.db_collation import eq_unicode, unicode_ci
|
||||
@@ -574,6 +576,7 @@ def list_mine_tasks(
|
||||
qc_biz_type: Optional[str] = None,
|
||||
reception_source: Optional[str] = None,
|
||||
biz_type: Optional[str] = None,
|
||||
protocol_status: Optional[str] = None,
|
||||
tenant_no: Optional[str] = None,
|
||||
) -> Tuple[List[Dict[str, Any]], int]:
|
||||
def _filtered():
|
||||
@@ -601,14 +604,21 @@ def list_mine_tasks(
|
||||
kw = (keyword or "").strip()
|
||||
if kw:
|
||||
like = f"%{kw}%"
|
||||
q0 = q0.filter(
|
||||
or_(
|
||||
BizQcTask.task_no.like(like),
|
||||
BizQcTask.item_name.like(like),
|
||||
BizQcWorkOrder.work_order_no.like(like),
|
||||
BizQcWorkOrder.sample_code.like(like),
|
||||
)
|
||||
)
|
||||
wt = (qc_biz_type or "").strip()
|
||||
# temporary Tab 的 qcBizType=temporary,与工单 work_order_type 对齐
|
||||
wo_type = "temporary" if wt == "temporary" else (wt or None)
|
||||
keyword_conditions = [
|
||||
BizQcTask.task_no.like(like),
|
||||
BizQcTask.item_name.like(like),
|
||||
*build_qc_work_order_keyword_conditions(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
keyword=kw,
|
||||
work_order_type=wo_type,
|
||||
reception_source=(reception_source or "").strip() or None,
|
||||
),
|
||||
]
|
||||
q0 = q0.filter(or_(*keyword_conditions))
|
||||
tt = (task_type or "").strip()
|
||||
if tt:
|
||||
q0 = q0.filter(BizQcTask.task_type == tt)
|
||||
@@ -632,6 +642,11 @@ def list_mine_tasks(
|
||||
bt_out = (biz_type or "").strip()
|
||||
if bt_out:
|
||||
q0 = q0.filter(BizQcWorkOrder.biz_type == bt_out)
|
||||
q0 = apply_research_donation_protocol_status_filter(
|
||||
q0,
|
||||
protocol_status,
|
||||
reception_source=reception_source,
|
||||
)
|
||||
return q0
|
||||
|
||||
total = _filtered().order_by(None).with_entities(func.count(BizQcTask.id)).scalar() or 0
|
||||
|
||||
@@ -560,6 +560,56 @@ def _inbound_qc_work_order_ids_by_mother_name(
|
||||
return list(ids)
|
||||
|
||||
|
||||
def build_qc_work_order_keyword_conditions(
|
||||
db: Optional[Session],
|
||||
*,
|
||||
tenant_no: Optional[str],
|
||||
keyword: str,
|
||||
work_order_type: Optional[str] = None,
|
||||
reception_source: Optional[str] = None,
|
||||
) -> List[Any]:
|
||||
"""质检工单列表关键词 OR 条件(工单号/样本/协议号/外部编号 + 入库编码/母亲/出库申请字段)。
|
||||
|
||||
供质检工单列表与「我的质检任务」共用,避免两端口径漂移。
|
||||
"""
|
||||
kw = (keyword or "").strip()
|
||||
if not kw:
|
||||
return []
|
||||
like = f"%{kw}%"
|
||||
wt = (work_order_type or "").strip()
|
||||
rs = (reception_source or "").strip()
|
||||
conditions: List[Any] = [
|
||||
BizQcWorkOrder.work_order_no.like(like),
|
||||
BizQcWorkOrder.sample_code.like(like),
|
||||
BizQcWorkOrder.protocol_no.like(like),
|
||||
BizQcWorkOrder.external_target_code.like(like),
|
||||
]
|
||||
if db is not None and tenant_no:
|
||||
from app.crud import sample_reception as reception_svc
|
||||
|
||||
rec_ids = reception_svc.reception_ids_matching_lab_storage_keyword(
|
||||
db, tenant_no, kw
|
||||
)
|
||||
if rec_ids:
|
||||
conditions.append(BizQcWorkOrder.reception_id.in_(rec_ids))
|
||||
lab_codes = reception_svc.sample_codes_matching_lab_storage_keyword(
|
||||
db, tenant_no, kw
|
||||
)
|
||||
if lab_codes:
|
||||
conditions.append(BizQcWorkOrder.sample_code.in_(lab_codes))
|
||||
if wt == "outbound" or not wt:
|
||||
outbound_ids = _outbound_qc_work_order_ids_by_keyword(db, tenant_no, kw)
|
||||
if outbound_ids:
|
||||
conditions.append(BizQcWorkOrder.id.in_(outbound_ids))
|
||||
if not wt or wt == "inbound":
|
||||
inbound_mother_ids = _inbound_qc_work_order_ids_by_mother_name(
|
||||
db, tenant_no, kw, reception_source=rs or None
|
||||
)
|
||||
if inbound_mother_ids:
|
||||
conditions.append(BizQcWorkOrder.id.in_(inbound_mother_ids))
|
||||
return conditions
|
||||
|
||||
|
||||
def _accept_conclusion_label(v: Optional[str]) -> str:
|
||||
key = (v or "").strip()
|
||||
return _ACCEPT_CONCLUSION_LABELS.get(key, key)
|
||||
@@ -1718,8 +1768,8 @@ def apply_research_donation_protocol_status_filter(
|
||||
return query
|
||||
|
||||
mode, statuses = resolve_research_donation_protocol_status_filter(protocol_status)
|
||||
if mode == "none":
|
||||
return query.filter(BizQcWorkOrder.id.in_([]))
|
||||
if mode == "all":
|
||||
return query
|
||||
if mode == "in":
|
||||
return query.filter(_research_donation_status_exists(statuses))
|
||||
# default:与前端默认勾选一致
|
||||
@@ -1791,37 +1841,15 @@ def list_work_orders(
|
||||
q0 = q0.filter(BizQcWorkOrder.trigger_source == ts)
|
||||
kw = (keyword or "").strip()
|
||||
if kw:
|
||||
like = f"%{kw}%"
|
||||
keyword_conditions = [
|
||||
BizQcWorkOrder.work_order_no.like(like),
|
||||
BizQcWorkOrder.sample_code.like(like),
|
||||
BizQcWorkOrder.protocol_no.like(like),
|
||||
BizQcWorkOrder.external_target_code.like(like),
|
||||
]
|
||||
if tenant_no:
|
||||
from app.crud import sample_reception as reception_svc
|
||||
|
||||
rec_ids = reception_svc.reception_ids_matching_lab_storage_keyword(
|
||||
db, tenant_no, kw
|
||||
)
|
||||
if rec_ids:
|
||||
keyword_conditions.append(BizQcWorkOrder.reception_id.in_(rec_ids))
|
||||
lab_codes = reception_svc.sample_codes_matching_lab_storage_keyword(
|
||||
db, tenant_no, kw
|
||||
)
|
||||
if lab_codes:
|
||||
keyword_conditions.append(BizQcWorkOrder.sample_code.in_(lab_codes))
|
||||
if tenant_no and (wt == "outbound" or not wt):
|
||||
outbound_ids = _outbound_qc_work_order_ids_by_keyword(db, tenant_no, kw)
|
||||
if outbound_ids:
|
||||
keyword_conditions.append(BizQcWorkOrder.id.in_(outbound_ids))
|
||||
if tenant_no and (not wt or wt == "inbound"):
|
||||
inbound_mother_ids = _inbound_qc_work_order_ids_by_mother_name(
|
||||
db, tenant_no, kw, reception_source=rs or None
|
||||
)
|
||||
if inbound_mother_ids:
|
||||
keyword_conditions.append(BizQcWorkOrder.id.in_(inbound_mother_ids))
|
||||
q0 = q0.filter(or_(*keyword_conditions))
|
||||
keyword_conditions = build_qc_work_order_keyword_conditions(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
keyword=kw,
|
||||
work_order_type=wt or None,
|
||||
reception_source=rs or None,
|
||||
)
|
||||
if keyword_conditions:
|
||||
q0 = q0.filter(or_(*keyword_conditions))
|
||||
st_raw = (work_order_status or "").strip()
|
||||
if st_raw:
|
||||
statuses = [s.strip() for s in st_raw.split(",") if s.strip()]
|
||||
|
||||
@@ -17,8 +17,8 @@ def test_explicit_statuses_returned():
|
||||
assert resolve_research_donation_protocol_status_filter("dsx,sxz") == ("in", ["dsx", "sxz"])
|
||||
|
||||
|
||||
def test_explicit_empty_means_none():
|
||||
assert resolve_research_donation_protocol_status_filter("") == ("none", [])
|
||||
def test_explicit_empty_means_all():
|
||||
assert resolve_research_donation_protocol_status_filter("") == ("all", [])
|
||||
|
||||
|
||||
def test_missing_means_default_dsx_sxz():
|
||||
@@ -27,5 +27,5 @@ def test_missing_means_default_dsx_sxz():
|
||||
assert statuses == ["dsx", "sxz"]
|
||||
|
||||
|
||||
def test_whitespace_only_means_none():
|
||||
assert resolve_research_donation_protocol_status_filter(" , ") == ("none", [])
|
||||
def test_whitespace_only_means_all():
|
||||
assert resolve_research_donation_protocol_status_filter(" , ") == ("all", [])
|
||||
@@ -0,0 +1,34 @@
|
||||
"""质检工单 / 我的质检任务共用关键词条件(无库路径)。"""
|
||||
|
||||
# qc_work_order ↔ qc_task 存在循环依赖:先经 qc_task 再取 helper
|
||||
import app.crud.qc_task # noqa: F401
|
||||
from app.crud.qc_work_order import build_qc_work_order_keyword_conditions
|
||||
from app.models.models import BizQcWorkOrder
|
||||
|
||||
|
||||
def test_empty_keyword_returns_no_conditions():
|
||||
assert build_qc_work_order_keyword_conditions(
|
||||
None, tenant_no=None, keyword=""
|
||||
) == []
|
||||
assert build_qc_work_order_keyword_conditions(
|
||||
None, tenant_no="t1", keyword=" "
|
||||
) == []
|
||||
|
||||
|
||||
def test_base_conditions_without_tenant_cover_list_fields():
|
||||
conds = build_qc_work_order_keyword_conditions(
|
||||
None,
|
||||
tenant_no=None,
|
||||
keyword="ABC",
|
||||
work_order_type="inbound",
|
||||
reception_source="cell_storage",
|
||||
)
|
||||
assert len(conds) == 4
|
||||
# 与质检工单列表一致的四列(无租户时不做入库/母亲/出库扩展)
|
||||
cols = {str(c.left) for c in conds}
|
||||
assert str(BizQcWorkOrder.work_order_no) in cols or any(
|
||||
"work_order_no" in str(c) for c in conds
|
||||
)
|
||||
assert any("sample_code" in str(c) for c in conds)
|
||||
assert any("protocol_no" in str(c) for c in conds)
|
||||
assert any("external_target_code" in str(c) for c in conds)
|
||||
@@ -170,6 +170,8 @@ export function fetchMyQcTaskList(params?: {
|
||||
qcBizType?: string
|
||||
receptionSource?: string
|
||||
bizType?: string
|
||||
/** 科研捐赠:协议/捐赠状态,多个逗号分隔;空串=不限制 */
|
||||
protocolStatus?: string
|
||||
}) {
|
||||
return request.get<PageList<QcTask>>({
|
||||
url: '/web/admin/qc-tasks/mine',
|
||||
|
||||
@@ -25,7 +25,7 @@ describe('donation protocol status filter helpers', () => {
|
||||
|
||||
it('matchesProtocolStatusFilter semantics', () => {
|
||||
assert.equal(matchesProtocolStatusFilter('yzf', undefined), true)
|
||||
assert.equal(matchesProtocolStatusFilter('yzf', []), false)
|
||||
assert.equal(matchesProtocolStatusFilter('yzf', []), true)
|
||||
assert.equal(matchesProtocolStatusFilter('sxz', ['dsx', 'sxz']), true)
|
||||
assert.equal(matchesProtocolStatusFilter('yzf', ['dsx', 'sxz']), false)
|
||||
assert.equal(matchesProtocolStatusFilter('', ['dsx']), false)
|
||||
|
||||
@@ -18,7 +18,7 @@ export const DEFAULT_DONATION_PROTOCOL_STATUS_FILTER = ['dsx', 'sxz']
|
||||
/**
|
||||
* 拼协议状态查询参数。
|
||||
* - 有选中:逗号串
|
||||
* - 空数组:返回 ''(显式空;勿当 undefined)
|
||||
* - 空数组:返回 ''(显式空=不限制;勿当 undefined,undefined 会走后端默认勾选)
|
||||
*/
|
||||
export function joinProtocolStatusFilter(statuses: string[]): string {
|
||||
return statuses.map((s) => s.trim()).filter(Boolean).join(',')
|
||||
@@ -27,13 +27,12 @@ export function joinProtocolStatusFilter(statuses: string[]): string {
|
||||
/**
|
||||
* 协议状态是否命中筛选。
|
||||
* - filter === undefined:不限制
|
||||
* - filter 为空数组:无匹配
|
||||
* - filter 为空数组:不限制(显式清空)
|
||||
*/
|
||||
export function matchesProtocolStatusFilter(
|
||||
status: string,
|
||||
filter: string[] | undefined
|
||||
): boolean {
|
||||
if (filter === undefined) return true
|
||||
if (!filter.length) return false
|
||||
if (filter === undefined || !filter.length) return true
|
||||
return filter.includes((status || '').trim())
|
||||
}
|
||||
@@ -27,13 +27,15 @@ export type QcTaskMineFilters = {
|
||||
keyword?: string
|
||||
taskType?: string
|
||||
taskStatus?: string
|
||||
/** 科研捐赠:协议状态逗号串;''=不限制;缺省不传 */
|
||||
protocolStatus?: string
|
||||
tabKey: QcWorkOrderTabKey
|
||||
}
|
||||
|
||||
export type MineWorkOrderSearchFilters = {
|
||||
keyword?: string
|
||||
workOrderStatus?: string | string[]
|
||||
/** 科研捐赠 Tab:协议/捐赠状态多选;undefined=不限制;[]=无匹配 */
|
||||
/** 科研捐赠 Tab:协议/捐赠状态多选;undefined/[]=不限制 */
|
||||
protocolStatus?: string[]
|
||||
triggerSource?: string
|
||||
qcCategory?: string
|
||||
@@ -145,6 +147,8 @@ export async function fetchAllMineTasks(filters: QcTaskMineFilters): Promise<QcT
|
||||
let page = 1
|
||||
const all: QcTask[] = []
|
||||
let total = 0
|
||||
const protocolStatusParam =
|
||||
filters.tabKey === 'inbound_research_donation' ? (filters.protocolStatus ?? '') : undefined
|
||||
while (true) {
|
||||
const res = await fetchMyQcTaskList({
|
||||
page,
|
||||
@@ -154,7 +158,8 @@ export async function fetchAllMineTasks(filters: QcTaskMineFilters): Promise<QcT
|
||||
taskStatus: filters.taskStatus || undefined,
|
||||
qcBizType: listQuery.workOrderType,
|
||||
receptionSource: listQuery.receptionSource,
|
||||
bizType: listQuery.bizType
|
||||
bizType: listQuery.bizType,
|
||||
...(protocolStatusParam !== undefined ? { protocolStatus: protocolStatusParam } : {})
|
||||
})
|
||||
const list = res.list || []
|
||||
all.push(...list)
|
||||
|
||||
+4
-6
@@ -153,6 +153,10 @@ export function useQcWorkOrderTabPage(
|
||||
keyword: searchForm.keyword || undefined,
|
||||
taskStatus: searchForm.taskStatus || undefined,
|
||||
taskType: searchForm.taskType || undefined,
|
||||
protocolStatus:
|
||||
tabKey.value === 'inbound_research_donation'
|
||||
? joinProtocolStatusFilter(searchForm.protocolStatus)
|
||||
: undefined,
|
||||
tabKey: tabKey.value
|
||||
})
|
||||
let entries = groupMineTasksByWorkOrder(tasks)
|
||||
@@ -172,12 +176,6 @@ export function useQcWorkOrderTabPage(
|
||||
}
|
||||
|
||||
const tab = tabConfig.value
|
||||
if (tabKey.value === 'inbound_research_donation' && !searchForm.protocolStatus.length) {
|
||||
tableData.value = []
|
||||
presetBatchesByWorkOrderId.value = undefined
|
||||
pagination.total = 0
|
||||
return
|
||||
}
|
||||
const timeParams =
|
||||
isAllQcWorkOrderTab(tabKey.value) || !tabUsesInfusionTimeFilter(tab)
|
||||
? {
|
||||
|
||||
Reference in new issue
Block a user