mirror of
https://github.com/rnvm9wjdtj-bot/myaps_api.git
synced 2026-06-02 05:54:40 +00:00
优化removing逻辑
This commit is contained in:
@@ -510,8 +510,8 @@ class DataCleaner:
|
||||
condition_values[cond["foreign"]] = local_value
|
||||
|
||||
if all_fields_present:
|
||||
# 构建查询条件
|
||||
exists = await model_class.filter(**condition_values).exists()
|
||||
# 构建查询条件,排除removing状态的数据
|
||||
exists = await model_class.filter(**condition_values).exclude(_status=StagingStatus.REMOVING).exists()
|
||||
if not exists:
|
||||
# 构建错误信息,显示所有条件值
|
||||
error_value_parts = [f"{data.get(cond['local'])}" for cond in conditions]
|
||||
@@ -526,7 +526,8 @@ class DataCleaner:
|
||||
value_field = fk_config.get("value_field", field_name)
|
||||
value = data.get(field_name)
|
||||
if value:
|
||||
exists = await model_class.filter(**{value_field: value}).exists()
|
||||
# 排除removing状态的数据
|
||||
exists = await model_class.filter(**{value_field: value}).exclude(_status=StagingStatus.REMOVING).exists()
|
||||
if not exists:
|
||||
errors.append(self._create_error(
|
||||
staging_id, ErrorType.FK_NOT_FOUND,
|
||||
|
||||
@@ -493,6 +493,16 @@ async def apply_dedup_strategy(
|
||||
existing_records = existing_item.get("existing_records", [])
|
||||
new_data = last_item["data"]
|
||||
|
||||
# 检查是否有removing状态的记录需要恢复
|
||||
removing_records = [r for r in existing_records if getattr(r, '_status', None) == 'removing']
|
||||
if removing_records:
|
||||
# 将removing记录恢复为pending状态
|
||||
for record in removing_records:
|
||||
await record.update_from_dict({_status: StagingStatus.PENDING}).save()
|
||||
logger.info(f"removing状态恢复为pending: {pk_value}, 共{len(removing_records)}条")
|
||||
# 从existing_records中移除removing记录
|
||||
existing_records = [r for r in existing_records if getattr(r, '_status', None) != 'removing']
|
||||
|
||||
all_same = True
|
||||
diff_info = ""
|
||||
if existing_records:
|
||||
@@ -554,6 +564,16 @@ async def apply_dedup_strategy(
|
||||
existing_records = item.get("existing_records", [])
|
||||
new_data = item["data"]
|
||||
|
||||
# 检查是否有removing状态的记录需要恢复
|
||||
removing_records = [r for r in existing_records if getattr(r, '_status', None) == 'removing']
|
||||
if removing_records:
|
||||
# 将removing记录恢复为pending状态
|
||||
for record in removing_records:
|
||||
await record.update_from_dict({_status: StagingStatus.PENDING}).save()
|
||||
logger.info(f"removing状态恢复为pending: {pk_value}, 共{len(removing_records)}条")
|
||||
# 从existing_records中移除removing记录(已恢复为pending,会被覆盖)
|
||||
existing_records = [r for r in existing_records if getattr(r, '_status', None) != 'removing']
|
||||
|
||||
# 对所有已存在记录进行内容比对
|
||||
all_same = True
|
||||
diff_info = ""
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
3. 拖拽或点击上传文件(支持 `.xlsx`, `.xls`, `.csv`)
|
||||
|
||||
**方式二:API接口调用**
|
||||
- 调用 `POST /api/mds/{table_key}` 接口
|
||||
- 调用 `POST /api/mds/{table}` 或 `POST /api/{table}?db_name=--s`接口
|
||||
- 适用于系统对接场景(ERP、MES、PLM等)
|
||||
|
||||
### 2. 数据校验
|
||||
|
||||
Reference in New Issue
Block a user