事务回滚判断优化
This commit is contained in:
@@ -191,12 +191,14 @@ class LevelDataService(BaseService[LevelData]):
|
||||
logger.error(f"Failed to insert batch: {str(e)}")
|
||||
raise e
|
||||
|
||||
# 如果有失败记录,不提交事务
|
||||
if failed_items:
|
||||
# 如果有插入失败记录(不是跳过记录),不提交事务
|
||||
# 跳过记录不应该影响事务,只插入失败的记录才需要回滚
|
||||
insert_failed_items = [item for item in failed_items if '插入失败' in item.get('error', '')]
|
||||
if insert_failed_items:
|
||||
db.rollback()
|
||||
return {
|
||||
'success': False,
|
||||
'message': f'批量导入失败: {len(failed_items)}条记录处理失败',
|
||||
'message': f'批量导入失败: {len(insert_failed_items)}条记录插入失败',
|
||||
'total_count': total_count,
|
||||
'success_count': success_count,
|
||||
'failed_count': failed_count,
|
||||
|
||||
Reference in New Issue
Block a user