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

@@ -128,3 +128,37 @@ export function importEntityData(data, updateSupport) {
data: data
})
}
// 查询个人中介导入状态
export function getPersonImportStatus(taskId) {
return request({
url: `/ccdi/intermediary/importPersonStatus/${taskId}`,
method: 'get'
})
}
// 查询个人中介导入失败记录
export function getPersonImportFailures(taskId, pageNum, pageSize) {
return request({
url: `/ccdi/intermediary/importPersonFailures/${taskId}`,
method: 'get',
params: { pageNum, pageSize }
})
}
// 查询实体中介导入状态
export function getEntityImportStatus(taskId) {
return request({
url: `/ccdi/intermediary/importEntityStatus/${taskId}`,
method: 'get'
})
}
// 查询实体中介导入失败记录
export function getEntityImportFailures(taskId, pageNum, pageSize) {
return request({
url: `/ccdi/intermediary/importEntityFailures/${taskId}`,
method: 'get',
params: { pageNum, pageSize }
})
}

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;
}
}
};

View File

@@ -29,6 +29,34 @@
v-hasPermi="['ccdi:intermediary:import']"
>导入</el-button>
</el-col>
<el-col :span="1.5" v-if="showPersonFailureButton">
<el-tooltip
:content="getPersonImportTooltip()"
placement="top"
>
<el-button
type="warning"
plain
icon="el-icon-warning"
size="mini"
@click="viewPersonImportFailures"
>查看个人导入失败记录</el-button>
</el-tooltip>
</el-col>
<el-col :span="1.5" v-if="showEntityFailureButton">
<el-tooltip
:content="getEntityImportTooltip()"
placement="top"
>
<el-button
type="warning"
plain
icon="el-icon-warning"
size="mini"
@click="viewEntityImportFailures"
>查看实体导入失败记录</el-button>
</el-tooltip>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
@@ -72,7 +100,103 @@
:title="upload.title"
@close="handleImportDialogClose"
@success="getList"
@import-complete="handleImportComplete"
/>
<!-- 个人中介导入失败记录对话框 -->
<el-dialog
title="个人中介导入失败记录"
:visible.sync="personFailureDialogVisible"
width="1200px"
append-to-body
>
<el-alert
v-if="getPersonLastImportInfo()"
:title="getPersonLastImportInfo()"
type="info"
:closable="false"
style="margin-bottom: 15px"
/>
<el-table :data="personFailureList" v-loading="personFailureLoading">
<el-table-column label="姓名" prop="name" align="center" />
<el-table-column label="证件号码" prop="personId" align="center" />
<el-table-column label="人员类型" prop="personType" align="center" />
<el-table-column label="性别" prop="gender" align="center" />
<el-table-column label="手机号码" prop="mobile" align="center" />
<el-table-column label="所在公司" prop="company" align="center" />
<el-table-column
label="失败原因"
prop="errorMessage"
align="center"
min-width="200"
:show-overflow-tooltip="true"
/>
</el-table>
<pagination
v-show="personFailureTotal > 0"
:total="personFailureTotal"
:page.sync="personFailureQueryParams.pageNum"
:limit.sync="personFailureQueryParams.pageSize"
@pagination="getPersonFailureList"
/>
<div slot="footer" class="dialog-footer">
<el-button @click="personFailureDialogVisible = false">关闭</el-button>
<el-button type="danger" plain @click="clearPersonImportHistory">清除历史记录</el-button>
</div>
</el-dialog>
<!-- 实体中介导入失败记录对话框 -->
<el-dialog
title="实体中介导入失败记录"
:visible.sync="entityFailureDialogVisible"
width="1200px"
append-to-body
>
<el-alert
v-if="getEntityLastImportInfo()"
:title="getEntityLastImportInfo()"
type="info"
:closable="false"
style="margin-bottom: 15px"
/>
<el-table :data="entityFailureList" v-loading="entityFailureLoading">
<el-table-column label="机构名称" prop="enterpriseName" align="center" />
<el-table-column label="统一社会信用代码" prop="socialCreditCode" align="center" />
<el-table-column label="主体类型" prop="enterpriseType" align="center" />
<el-table-column label="企业性质" prop="enterpriseNature" align="center" />
<el-table-column label="法定代表人" prop="legalRepresentative" align="center" />
<el-table-column label="成立日期" prop="establishDate" align="center" width="120">
<template slot-scope="scope">
<span v-if="scope.row.establishDate">{{ parseTime(scope.row.establishDate, '{y}-{m}-{d}') }}</span>
<span v-else>-</span>
</template>
</el-table-column>
<el-table-column
label="失败原因"
prop="errorMessage"
align="center"
min-width="200"
:show-overflow-tooltip="true"
/>
</el-table>
<pagination
v-show="entityFailureTotal > 0"
:total="entityFailureTotal"
:page.sync="entityFailureQueryParams.pageNum"
:limit.sync="entityFailureQueryParams.pageSize"
@pagination="getEntityFailureList"
/>
<div slot="footer" class="dialog-footer">
<el-button @click="entityFailureDialogVisible = false">关闭</el-button>
<el-button type="danger" plain @click="clearEntityImportHistory">清除历史记录</el-button>
</div>
</el-dialog>
</div>
</template>
@@ -85,7 +209,9 @@ import {
getPersonIntermediary,
listIntermediary,
updateEntityIntermediary,
updatePersonIntermediary
updatePersonIntermediary,
getPersonImportFailures,
getEntityImportFailures
} from "@/api/ccdiIntermediary";
import {
getCertTypeOptions,
@@ -140,12 +266,34 @@ export default {
certTypeOptions: [],
relationTypeOptions: [],
corpTypeOptions: [],
corpNatureOptions: []
corpNatureOptions: [],
// 导入失败记录相关状态
showPersonFailureButton: false,
showEntityFailureButton: false,
currentPersonTaskId: null,
currentEntityTaskId: null,
personFailureDialogVisible: false,
personFailureList: [],
personFailureLoading: false,
personFailureTotal: 0,
personFailureQueryParams: {
pageNum: 1,
pageSize: 10
},
entityFailureDialogVisible: false,
entityFailureList: [],
entityFailureLoading: false,
entityFailureTotal: 0,
entityFailureQueryParams: {
pageNum: 1,
pageSize: 10
}
};
},
created() {
this.getList();
this.loadEnumOptions();
this.restoreImportState();
},
methods: {
/** 加载枚举选项 */
@@ -335,6 +483,319 @@ export default {
/** 导入对话框关闭处理 */
handleImportDialogClose() {
// 子组件已处理文件清理
},
/** 处理导入完成 */
handleImportComplete(importData) {
const { taskId, hasFailures, importType, totalCount, successCount, failureCount } = importData;
if (importType === 'person') {
// 保存个人导入任务
this.savePersonImportTaskToStorage({
taskId,
hasFailures,
totalCount,
successCount,
failureCount
});
// 更新按钮显示
this.showPersonFailureButton = hasFailures;
this.currentPersonTaskId = taskId;
} else if (importType === 'entity') {
// 保存实体导入任务
this.saveEntityImportTaskToStorage({
taskId,
hasFailures,
totalCount,
successCount,
failureCount
});
// 更新按钮显示
this.showEntityFailureButton = hasFailures;
this.currentEntityTaskId = taskId;
}
// 刷新列表
this.getList();
},
/** ==================== 个人中介导入任务管理 ==================== */
/** 保存个人导入任务到localStorage */
savePersonImportTaskToStorage(taskData) {
try {
const data = {
...taskData,
saveTime: Date.now()
};
localStorage.setItem('intermediary_person_import_last_task', JSON.stringify(data));
} catch (error) {
console.error('保存个人导入任务状态失败:', error);
}
},
/** 从localStorage读取个人导入任务 */
getPersonImportTaskFromStorage() {
try {
const data = localStorage.getItem('intermediary_person_import_last_task');
if (!data) return null;
const task = JSON.parse(data);
// 数据格式校验
if (!task || !task.taskId) {
this.clearPersonImportTaskFromStorage();
return null;
}
// 时间戳校验
if (task.saveTime && typeof task.saveTime !== 'number') {
this.clearPersonImportTaskFromStorage();
return null;
}
// 过期检查(7天)
const sevenDays = 7 * 24 * 60 * 60 * 1000;
if (Date.now() - task.saveTime > sevenDays) {
this.clearPersonImportTaskFromStorage();
return null;
}
return task;
} catch (error) {
console.error('读取个人导入任务状态失败:', error);
this.clearPersonImportTaskFromStorage();
return null;
}
},
/** 清除个人导入任务 */
clearPersonImportTaskFromStorage() {
try {
localStorage.removeItem('intermediary_person_import_last_task');
} catch (error) {
console.error('清除个人导入任务状态失败:', error);
}
},
/** 获取上次个人导入的提示信息 */
getPersonImportTooltip() {
const savedTask = this.getPersonImportTaskFromStorage();
if (savedTask && savedTask.saveTime) {
const date = new Date(savedTask.saveTime);
const timeStr = this.parseTime(date, '{y}-{m}-{d} {h}:{i}');
return `上次导入: ${timeStr}`;
}
return '';
},
/** 获取上次个人导入的统计信息 */
getPersonLastImportInfo() {
const savedTask = this.getPersonImportTaskFromStorage();
if (savedTask && savedTask.totalCount) {
return `导入时间: ${this.parseTime(savedTask.saveTime)} | 总数: ${savedTask.totalCount}条 | 成功: ${savedTask.successCount}条 | 失败: ${savedTask.failureCount}`;
}
return '';
},
/** 查看个人导入失败记录 */
viewPersonImportFailures() {
this.personFailureDialogVisible = true;
this.getPersonFailureList();
},
/** 查询个人失败记录列表 */
getPersonFailureList() {
this.personFailureLoading = true;
getPersonImportFailures(
this.currentPersonTaskId,
this.personFailureQueryParams.pageNum,
this.personFailureQueryParams.pageSize
).then(response => {
this.personFailureList = response.rows;
this.personFailureTotal = response.total;
this.personFailureLoading = false;
}).catch(error => {
this.personFailureLoading = false;
// 处理不同类型的错误
if (error.response) {
const status = error.response.status;
if (status === 404) {
// 记录不存在或已过期
this.$modal.msgWarning('导入记录已过期,无法查看失败记录');
this.clearPersonImportTaskFromStorage();
this.showPersonFailureButton = false;
this.currentPersonTaskId = null;
this.personFailureDialogVisible = false;
} else if (status === 500) {
this.$modal.msgError('服务器错误,请稍后重试');
} else {
this.$modal.msgError(`查询失败: ${error.response.data.msg || '未知错误'}`);
}
} else if (error.request) {
// 请求发送了但没有收到响应
this.$modal.msgError('网络连接失败,请检查网络');
} else {
this.$modal.msgError('查询失败记录失败: ' + error.message);
}
});
},
/** 清除个人导入历史记录 */
clearPersonImportHistory() {
this.$confirm('确认清除上次导入记录?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.clearPersonImportTaskFromStorage();
this.showPersonFailureButton = false;
this.currentPersonTaskId = null;
this.personFailureDialogVisible = false;
this.$message.success('已清除');
}).catch(() => {});
},
/** ==================== 实体中介导入任务管理 ==================== */
/** 保存实体导入任务到localStorage */
saveEntityImportTaskToStorage(taskData) {
try {
const data = {
...taskData,
saveTime: Date.now()
};
localStorage.setItem('intermediary_entity_import_last_task', JSON.stringify(data));
} catch (error) {
console.error('保存实体导入任务状态失败:', error);
}
},
/** 从localStorage读取实体导入任务 */
getEntityImportTaskFromStorage() {
try {
const data = localStorage.getItem('intermediary_entity_import_last_task');
if (!data) return null;
const task = JSON.parse(data);
// 数据格式校验
if (!task || !task.taskId) {
this.clearEntityImportTaskFromStorage();
return null;
}
// 时间戳校验
if (task.saveTime && typeof task.saveTime !== 'number') {
this.clearEntityImportTaskFromStorage();
return null;
}
// 过期检查(7天)
const sevenDays = 7 * 24 * 60 * 60 * 1000;
if (Date.now() - task.saveTime > sevenDays) {
this.clearEntityImportTaskFromStorage();
return null;
}
return task;
} catch (error) {
console.error('读取实体导入任务状态失败:', error);
this.clearEntityImportTaskFromStorage();
return null;
}
},
/** 清除实体导入任务 */
clearEntityImportTaskFromStorage() {
try {
localStorage.removeItem('intermediary_entity_import_last_task');
} catch (error) {
console.error('清除实体导入任务状态失败:', error);
}
},
/** 获取上次实体导入的提示信息 */
getEntityImportTooltip() {
const savedTask = this.getEntityImportTaskFromStorage();
if (savedTask && savedTask.saveTime) {
const date = new Date(savedTask.saveTime);
const timeStr = this.parseTime(date, '{y}-{m}-{d} {h}:{i}');
return `上次导入: ${timeStr}`;
}
return '';
},
/** 获取上次实体导入的统计信息 */
getEntityLastImportInfo() {
const savedTask = this.getEntityImportTaskFromStorage();
if (savedTask && savedTask.totalCount) {
return `导入时间: ${this.parseTime(savedTask.saveTime)} | 总数: ${savedTask.totalCount}条 | 成功: ${savedTask.successCount}条 | 失败: ${savedTask.failureCount}`;
}
return '';
},
/** 查看实体导入失败记录 */
viewEntityImportFailures() {
this.entityFailureDialogVisible = true;
this.getEntityFailureList();
},
/** 查询实体失败记录列表 */
getEntityFailureList() {
this.entityFailureLoading = true;
getEntityImportFailures(
this.currentEntityTaskId,
this.entityFailureQueryParams.pageNum,
this.entityFailureQueryParams.pageSize
).then(response => {
this.entityFailureList = response.rows;
this.entityFailureTotal = response.total;
this.entityFailureLoading = false;
}).catch(error => {
this.entityFailureLoading = false;
// 处理不同类型的错误
if (error.response) {
const status = error.response.status;
if (status === 404) {
// 记录不存在或已过期
this.$modal.msgWarning('导入记录已过期,无法查看失败记录');
this.clearEntityImportTaskFromStorage();
this.showEntityFailureButton = false;
this.currentEntityTaskId = null;
this.entityFailureDialogVisible = false;
} else if (status === 500) {
this.$modal.msgError('服务器错误,请稍后重试');
} else {
this.$modal.msgError(`查询失败: ${error.response.data.msg || '未知错误'}`);
}
} else if (error.request) {
// 请求发送了但没有收到响应
this.$modal.msgError('网络连接失败,请检查网络');
} else {
this.$modal.msgError('查询失败记录失败: ' + error.message);
}
});
},
/** 清除实体导入历史记录 */
clearEntityImportHistory() {
this.$confirm('确认清除上次导入记录?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.clearEntityImportTaskFromStorage();
this.showEntityFailureButton = false;
this.currentEntityTaskId = null;
this.entityFailureDialogVisible = false;
this.$message.success('已清除');
}).catch(() => {});
},
/** ==================== 导入状态恢复 ==================== */
/** 恢复导入状态 */
restoreImportState() {
// 恢复个人中介导入状态
const personTask = this.getPersonImportTaskFromStorage();
if (personTask && personTask.hasFailures && personTask.taskId) {
this.currentPersonTaskId = personTask.taskId;
this.showPersonFailureButton = true;
}
// 恢复实体中介导入状态
const entityTask = this.getEntityImportTaskFromStorage();
if (entityTask && entityTask.hasFailures && entityTask.taskId) {
this.currentEntityTaskId = entityTask.taskId;
this.showEntityFailureButton = true;
}
}
}
};