fix: 修复中介导入成功条数计算错误

问题:
- 导入成功条数显示为负数
- 原因:成功数量计算使用 validRecords.size() - failures.size()
- 但没有使用实际的数据库操作返回值

修复:
- saveBatchWithUpsert 和 saveBatch 方法现在返回 int
- 累加实际的数据库影响行数
- 使用 actualSuccessCount 变量跟踪真实成功数量

影响范围:
- CcdiIntermediaryPersonImportServiceImpl
- CcdiIntermediaryEntityImportServiceImpl
This commit is contained in:
wkc
2026-02-08 17:18:18 +08:00
parent bb0d68c41d
commit 5ec5913759
2058 changed files with 234134 additions and 269 deletions

View File

@@ -100,6 +100,7 @@
<script>
import {getToken} from "@/utils/auth";
import {getPersonImportStatus, getEntityImportStatus} from "@/api/ccdiIntermediary";
import ImportResultDialog from "@/components/ImportResultDialog.vue";
export default {
@@ -126,7 +127,10 @@ export default {
isFileSelected: false,
// 导入结果弹窗
importResultVisible: false,
importResultContent: ""
importResultContent: "",
// 轮询状态
pollingTimer: null,
currentTaskId: null
};
},
computed: {
@@ -140,11 +144,6 @@ export default {
}
}
},
watch: {
visible(val) {
this.$emit("update:visible", val);
}
},
methods: {
handleDialogOpen() {
this.isFileSelected = false;
@@ -180,28 +179,31 @@ export default {
},
handleFileSuccess(response) {
this.isUploading = false;
this.visible = false;
this.$emit("success");
// 解析后端返回的消息,只展示错误部分
let displayMessage = response.msg;
if (response.code === 200 && response.data && response.data.taskId) {
const taskId = response.data.taskId;
this.currentTaskId = taskId;
// 如果消息包含"恭喜您,数据已全部导入成功",说明全部成功,不展示详细列表
if (displayMessage.includes('恭喜您,数据已全部导入成功')) {
// 全部成功,使用简洁提示
displayMessage = '导入成功!';
// 显示通知
this.$notify({
title: '导入任务已提交',
message: '正在后台处理中,处理完成后将通知您',
type: 'info',
duration: 3000
});
// 关闭对话框 - 使用$emit更新父组件的visible
this.$emit('update:visible', false);
this.$refs.upload.clearFiles();
// 通知父组件刷新列表
this.$emit("success");
// 开始轮询
this.startImportStatusPolling(taskId);
} else {
this.$modal.msgError(response.msg || '导入失败');
}
// 如果消息包含"很抱歉,导入失败",说明有错误,只展示错误部分
else if (displayMessage.includes('很抱歉,导入失败')) {
// 只保留错误部分,移除成功统计信息
const lines = displayMessage.split('<br/><br/>');
displayMessage = lines[0]; // 只取错误部分
}
// 显示导入结果弹窗
this.importResultContent = displayMessage;
this.importResultVisible = true;
this.$refs.upload.clearFiles();
},
// 导入结果弹窗关闭
handleImportResultClose() {
@@ -215,6 +217,73 @@ export default {
},
handleSubmit() {
this.$refs.upload.submit();
},
/** 开始轮询导入状态 */
startImportStatusPolling(taskId) {
let pollCount = 0;
const maxPolls = 150; // 最多5分钟
this.pollingTimer = setInterval(async () => {
try {
pollCount++;
if (pollCount > maxPolls) {
clearInterval(this.pollingTimer);
this.$modal.msgWarning('导入任务处理超时,请联系管理员');
return;
}
// 根据导入类型调用不同的API
const apiMethod = this.formData.importType === 'person'
? getPersonImportStatus
: getEntityImportStatus;
const response = await apiMethod(taskId);
if (response.data && response.data.status !== 'PROCESSING') {
clearInterval(this.pollingTimer);
this.handleImportComplete(response.data);
}
} catch (error) {
clearInterval(this.pollingTimer);
this.$modal.msgError('查询导入状态失败: ' + error.message);
}
}, 2000); // 每2秒轮询一次
},
/** 处理导入完成 */
handleImportComplete(statusResult) {
if (statusResult.status === 'SUCCESS') {
this.$notify({
title: '导入完成',
message: `全部成功!共导入${statusResult.totalCount}条数据`,
type: 'success',
duration: 5000
});
} else if (statusResult.failureCount > 0) {
this.$notify({
title: '导入完成',
message: `成功${statusResult.successCount}条,失败${statusResult.failureCount}`,
type: 'warning',
duration: 5000
});
}
// 通知父组件更新失败记录状态
this.$emit("import-complete", {
taskId: statusResult.taskId,
hasFailures: statusResult.failureCount > 0,
importType: this.formData.importType,
totalCount: statusResult.totalCount,
successCount: statusResult.successCount,
failureCount: statusResult.failureCount
});
}
},
/** 组件销毁时清除定时器 */
beforeDestroy() {
if (this.pollingTimer) {
clearInterval(this.pollingTimer);
this.pollingTimer = null;
}
}
};