feat(shipping-notice): 添加 RPA 工作者心跳告警开关,更新环境配置以支持样本证据历史记录
This commit is contained in:
1 parent
705971ad03
commit
88408490d7
34 files changed
+1697
-109
No files matched your search
@@ -406,7 +406,12 @@ def _test_analysis_validation(source: ShippingInventorySource) -> tuple[list[str
|
||||
source_config_version=source.config_version,
|
||||
).order_by(ShippingInventoryConfigurationTestRun.id.desc()).first()
|
||||
result = confirmed_test.result_json if confirmed_test and isinstance(confirmed_test.result_json, dict) else {}
|
||||
if not confirmed_test or int(result.get('confirmed_profile_id') or 0) != int(source.parsing_profile_id or 0):
|
||||
if (
|
||||
not confirmed_test
|
||||
or source.rpa_profile is None
|
||||
or confirmed_test.rpa_profile_config_version != source.rpa_profile.config_version
|
||||
or int(result.get('confirmed_profile_id') or 0) != int(source.parsing_profile_id or 0)
|
||||
):
|
||||
return ['configuration_test'], details
|
||||
analysis = db.session.get(ShippingInventoryStructureAnalysis, confirmed_test.analysis_id)
|
||||
profile = source.parsing_profile
|
||||
@@ -503,29 +508,118 @@ def _template_validation_missing(source: ShippingInventorySource) -> list[str]:
|
||||
return ['template_validation'] if not mappings or invalid else []
|
||||
|
||||
|
||||
def _activation_missing_requirements(source: ShippingInventorySource) -> tuple[list[str], dict[str, Any]]:
|
||||
"""计算库存站点进入正式运行前尚未完成的业务步骤和测试验证详情。"""
|
||||
missing: list[str] = []
|
||||
if source.rpa_profile is None or not source.rpa_profile.enabled:
|
||||
missing.append('rpa_profile')
|
||||
if source.parsing_profile is None or source.parsing_profile.status != 'published':
|
||||
missing.append('parsing_profile')
|
||||
if source.excel_template is None or source.excel_template.status != 'published':
|
||||
missing.append('excel_template')
|
||||
else:
|
||||
missing.extend(_template_validation_missing(source))
|
||||
def _latest_test_run_evidence(source: ShippingInventorySource) -> dict[str, Any]:
|
||||
"""提取最近一次配置测试的非敏感证据,供上线检查说明测试是否过期或失败。"""
|
||||
run = ShippingInventoryConfigurationTestRun.query.filter_by(
|
||||
inventory_source_id=source.id,
|
||||
).order_by(ShippingInventoryConfigurationTestRun.id.desc()).first()
|
||||
if run is None:
|
||||
return {'state': 'not_started'}
|
||||
profile_version = source.rpa_profile.config_version if source.rpa_profile is not None else None
|
||||
if (
|
||||
run.source_config_version != source.config_version
|
||||
or run.rpa_profile_config_version != profile_version
|
||||
):
|
||||
return {
|
||||
'state': 'stale', 'run_no': run.run_no, 'status': run.status,
|
||||
'source_config_version': run.source_config_version,
|
||||
'rpa_profile_config_version': run.rpa_profile_config_version,
|
||||
}
|
||||
if run.status == 'failed':
|
||||
return {'state': 'failed', 'run_no': run.run_no, 'status': run.status, 'stage': run.stage}
|
||||
return {'state': 'current', 'run_no': run.run_no, 'status': run.status, 'stage': run.stage}
|
||||
|
||||
|
||||
def _activation_check(
|
||||
code: str, *, passed: bool, action: str, evidence: dict[str, Any], status: str | None = None,
|
||||
blocking: bool | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""构造单项上线门禁结果,确保管理端只展示服务端已判定的业务事实。"""
|
||||
return {
|
||||
'code': code,
|
||||
'status': status or ('passed' if passed else 'pending'),
|
||||
'blocking': not passed if blocking is None else blocking,
|
||||
'action': action,
|
||||
'evidence': evidence,
|
||||
}
|
||||
|
||||
|
||||
def _source_activation_checks(source: ShippingInventorySource) -> list[dict[str, Any]]:
|
||||
"""构建库存站点正式运行的权威检查清单。
|
||||
|
||||
检查项按管理员完成配置的业务顺序返回。测试、解析、模板和仓库映射均以当前
|
||||
``config_version`` 的持久化事实为准,避免管理端依据本地表单状态猜测启用资格。
|
||||
"""
|
||||
validation_missing, validation_details = _test_analysis_validation(source)
|
||||
missing.extend(validation_missing)
|
||||
return missing, validation_details
|
||||
missing = set(validation_missing)
|
||||
test_evidence = _latest_test_run_evidence(source)
|
||||
test_complete = 'configuration_test' not in missing
|
||||
profile_ready = source.rpa_profile is not None and bool(source.rpa_profile.enabled)
|
||||
parsing_ready = source.parsing_profile is not None and source.parsing_profile.status == 'published'
|
||||
template_ready = source.excel_template is not None and source.excel_template.status == 'published'
|
||||
template_valid = template_ready and 'template_validation' not in missing
|
||||
checks = [
|
||||
_activation_check(
|
||||
'rpa_profile', passed=profile_ready, action='configure_connection',
|
||||
evidence={'profile_id': source.rpa_profile_id, 'enabled': profile_ready},
|
||||
),
|
||||
_activation_check(
|
||||
'parsing_profile', passed=parsing_ready, action='configure_parsing_profile',
|
||||
evidence={'profile_id': source.parsing_profile_id, 'published': parsing_ready},
|
||||
),
|
||||
_activation_check(
|
||||
'excel_template', passed=template_ready, action='configure_excel_template',
|
||||
evidence={'template_id': source.excel_template_id, 'published': template_ready},
|
||||
),
|
||||
_activation_check(
|
||||
'template_validation', passed=not template_ready or template_valid,
|
||||
action='configure_excel_template', evidence={}, blocking=template_ready and not template_valid,
|
||||
),
|
||||
_activation_check(
|
||||
'configuration_test', passed=test_complete,
|
||||
action='run_configuration_test', evidence=test_evidence,
|
||||
status=test_evidence['state'] if test_evidence['state'] in {'stale', 'failed'} else None,
|
||||
),
|
||||
_activation_check(
|
||||
'parsing_validation', passed=test_complete and 'parsing_validation' not in missing,
|
||||
action='run_configuration_test', evidence={'sample_warehouses': validation_details['sample_warehouses']},
|
||||
status='pending' if not test_complete else None, blocking='parsing_validation' in missing,
|
||||
),
|
||||
]
|
||||
if source.warehouse_resolution_mode == 'inventory_match':
|
||||
checks.append(_activation_check(
|
||||
'warehouse_identification', passed=test_complete and 'warehouse_identification' not in missing,
|
||||
action='configure_parsing_profile', evidence={'sample_warehouses': validation_details['sample_warehouses']},
|
||||
status='pending' if not test_complete else None, blocking='warehouse_identification' in missing,
|
||||
))
|
||||
checks.append(_activation_check(
|
||||
'warehouse_mapping', passed=test_complete and 'warehouse_mapping' not in missing, action='configure_warehouse_mapping',
|
||||
evidence={
|
||||
'mode': source.warehouse_resolution_mode,
|
||||
'fixed_warehouse_id': source.fixed_warehouse_id,
|
||||
'sample_warehouses': validation_details['sample_warehouses'],
|
||||
},
|
||||
status='pending' if not test_complete else None, blocking='warehouse_mapping' in missing,
|
||||
))
|
||||
return checks
|
||||
|
||||
|
||||
def get_source_activation_status(source: ShippingInventorySource) -> dict[str, Any]:
|
||||
"""返回库存站点启用检查结果,供管理端展示下一步操作。"""
|
||||
missing, validation = _activation_missing_requirements(source)
|
||||
"""返回库存站点正式运行的结构化门禁结果。
|
||||
|
||||
Args:
|
||||
source: 已持久化的库存站点,关联配置由当前数据库事务提供。
|
||||
|
||||
Returns:
|
||||
dict[str, Any]: ``checks`` 为前端唯一的检查真相;``ready`` 为启用结论;
|
||||
``missing_requirements`` 是由 checks 派生的紧凑摘要,供现有调用方读取。
|
||||
"""
|
||||
checks = _source_activation_checks(source)
|
||||
missing = [item['code'] for item in checks if item['blocking']]
|
||||
return {
|
||||
'ready': not missing,
|
||||
'checks': checks,
|
||||
'missing_requirements': missing,
|
||||
'validation': validation,
|
||||
}
|
||||
|
||||
|
||||
@@ -543,7 +637,6 @@ def activate_source(source_id: int, *, actor_id: int | None) -> dict[str, Any]:
|
||||
)
|
||||
source.enabled = True
|
||||
source.updated_by = actor_id
|
||||
source.config_version += 1
|
||||
db.session.commit()
|
||||
return _source_payload(source)
|
||||
|
||||
@@ -555,7 +648,6 @@ def deactivate_source(source_id: int, *, actor_id: int | None) -> dict[str, Any]
|
||||
raise NotFoundError('Inventory Source not found', code='SHIPPING.INVENTORY_SOURCE_NOT_FOUND')
|
||||
source.enabled = False
|
||||
source.updated_by = actor_id
|
||||
source.config_version += 1
|
||||
db.session.commit()
|
||||
return _source_payload(source)
|
||||
|
||||
|
||||
Reference in new issue
Block a user