fixing
This commit is contained in:
parent
7262a33a93
commit
7d6ac687da
|
|
@ -79,6 +79,23 @@ def _normalize_job_no(v: Any) -> str:
|
||||||
return s.upper()
|
return s.upper()
|
||||||
|
|
||||||
|
|
||||||
|
def _to_int_candidate(v: Any) -> int | None:
|
||||||
|
if v is None:
|
||||||
|
return None
|
||||||
|
if isinstance(v, dict):
|
||||||
|
v = _cell_value(v)
|
||||||
|
s = str(v).strip()
|
||||||
|
if not s:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
# 兼容 "123.0"
|
||||||
|
if "." in s and s.endswith(".0"):
|
||||||
|
return int(float(s))
|
||||||
|
return int(s)
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _extract_oa_row_id_and_fields(row: dict[str, Any]) -> tuple[int | None, dict[str, Any]]:
|
def _extract_oa_row_id_and_fields(row: dict[str, Any]) -> tuple[int | None, dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
兼容不同 OA export 返回结构,提取:
|
兼容不同 OA export 返回结构,提取:
|
||||||
|
|
@ -94,14 +111,20 @@ def _extract_oa_row_id_and_fields(row: dict[str, Any]) -> tuple[int | None, dict
|
||||||
for k, v in master.items():
|
for k, v in master.items():
|
||||||
if isinstance(k, str) and k.startswith("field"):
|
if isinstance(k, str) and k.startswith("field"):
|
||||||
field_map[k] = v
|
field_map[k] = v
|
||||||
for candidate in (row.get("id"), row.get("masterDataId"), master.get("id")):
|
# 常见主键位置优先尝试
|
||||||
if candidate is None:
|
for candidate in (
|
||||||
continue
|
row.get("id"),
|
||||||
try:
|
row.get("masterDataId"),
|
||||||
row_id = int(str(candidate))
|
master.get("id"),
|
||||||
|
master.get("ID"),
|
||||||
|
master.get("recordId"),
|
||||||
|
master.get("dataId"),
|
||||||
|
master.get("_id"),
|
||||||
|
):
|
||||||
|
rid = _to_int_candidate(candidate)
|
||||||
|
if rid is not None:
|
||||||
|
row_id = rid
|
||||||
break
|
break
|
||||||
except Exception:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# 结构 B:masterTable.record.fields = [{name,value,showValue}, ...]
|
# 结构 B:masterTable.record.fields = [{name,value,showValue}, ...]
|
||||||
master_table = row.get("masterTable")
|
master_table = row.get("masterTable")
|
||||||
|
|
@ -117,12 +140,7 @@ def _extract_oa_row_id_and_fields(row: dict[str, Any]) -> tuple[int | None, dict
|
||||||
if name:
|
if name:
|
||||||
field_map[name] = fld
|
field_map[name] = fld
|
||||||
if row_id is None:
|
if row_id is None:
|
||||||
rid = record.get("id")
|
row_id = _to_int_candidate(record.get("id"))
|
||||||
if rid is not None:
|
|
||||||
try:
|
|
||||||
row_id = int(str(rid))
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# 结构 C:行级 fields 列表
|
# 结构 C:行级 fields 列表
|
||||||
row_fields = row.get("fields")
|
row_fields = row.get("fields")
|
||||||
|
|
@ -351,6 +369,8 @@ class SyncEhrToOaFormJob(BaseJob):
|
||||||
oa_id_by_job_no: dict[str, int] = {}
|
oa_id_by_job_no: dict[str, int] = {}
|
||||||
oa_id_by_job_no_norm: dict[str, int] = {}
|
oa_id_by_job_no_norm: dict[str, int] = {}
|
||||||
row_parse_miss = 0
|
row_parse_miss = 0
|
||||||
|
row_id_fallback_count = 0
|
||||||
|
row_id_fallback_samples: list[str] = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
if not isinstance(row, dict):
|
if not isinstance(row, dict):
|
||||||
continue
|
continue
|
||||||
|
|
@ -368,24 +388,30 @@ class SyncEhrToOaFormJob(BaseJob):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if row_id is None:
|
if row_id is None:
|
||||||
row_parse_miss += 1
|
# 某些 OA export 不返回主键 id;此时依赖 uniqueFiled(工号) 进行更新匹配。
|
||||||
if verbose_trace and row_parse_miss <= 20:
|
row_id = 0
|
||||||
|
row_id_fallback_count += 1
|
||||||
|
if len(row_id_fallback_samples) < 20:
|
||||||
|
row_id_fallback_samples.append(job_no)
|
||||||
|
if verbose_trace and row_id_fallback_count <= 20:
|
||||||
logger.info(
|
logger.info(
|
||||||
"OA 行解析未取到记录ID:job_no=%s row_keys=%s",
|
"OA 行解析未取到记录ID,使用回退ID=0:job_no=%s row_keys=%s",
|
||||||
job_no,
|
job_no,
|
||||||
list(row.keys())[:20],
|
list(row.keys())[:20],
|
||||||
)
|
)
|
||||||
continue
|
|
||||||
oa_id_by_job_no[job_no] = row_id
|
oa_id_by_job_no[job_no] = row_id
|
||||||
job_no_norm = _normalize_job_no(job_no)
|
job_no_norm = _normalize_job_no(job_no)
|
||||||
if job_no_norm:
|
if job_no_norm:
|
||||||
oa_id_by_job_no_norm[job_no_norm] = row_id
|
oa_id_by_job_no_norm[job_no_norm] = row_id
|
||||||
logger.info(
|
logger.info(
|
||||||
"OA 工号索引完成:indexed_job_numbers=%s indexed_job_numbers_norm=%s parse_miss=%s",
|
"OA 工号索引完成:indexed_job_numbers=%s indexed_job_numbers_norm=%s parse_miss=%s id_fallback=%s",
|
||||||
len(oa_id_by_job_no),
|
len(oa_id_by_job_no),
|
||||||
len(oa_id_by_job_no_norm),
|
len(oa_id_by_job_no_norm),
|
||||||
row_parse_miss,
|
row_parse_miss,
|
||||||
|
row_id_fallback_count,
|
||||||
)
|
)
|
||||||
|
if row_id_fallback_samples:
|
||||||
|
logger.info("OA 记录ID回退样本(前20):%s", row_id_fallback_samples)
|
||||||
if verbose_trace:
|
if verbose_trace:
|
||||||
for job_no, row_id in list(oa_id_by_job_no.items()):
|
for job_no, row_id in list(oa_id_by_job_no.items()):
|
||||||
logger.info("OA 工号索引明细:raw=%s norm=%s row_id=%s", job_no, _normalize_job_no(job_no), row_id)
|
logger.info("OA 工号索引明细:raw=%s norm=%s row_id=%s", job_no, _normalize_job_no(job_no), row_id)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue