抓变化

This commit is contained in:
jiang 2025-06-20 16:55:23 +08:00
parent 3ce40dd036
commit a59c925d56
5 changed files with 194 additions and 113 deletions

View File

@ -1,29 +1,29 @@
const { contextBridge, ipcRenderer } = require('electron'); const {contextBridge, ipcRenderer} = require('electron');
// 暴露安全的API给渲染进程 // 暴露安全的API给渲染进程
contextBridge.exposeInMainWorld('electronAPI', { contextBridge.exposeInMainWorld('electronAPI', {
// 文件操作 // 文件操作
selectExcelFile: () => ipcRenderer.invoke('select-excel-file'), selectExcelFile: () => ipcRenderer.invoke('select-excel-file'),
// 数据库操作 // 数据库操作
getProjects: () => ipcRenderer.invoke('get-projects'), getProjects: () => ipcRenderer.invoke('get-projects'),
getProjectsRange: () => ipcRenderer.invoke('get-projects-range'), getProjectsRange: () => ipcRenderer.invoke('get-projects-range'),
getTreeStructure: () => ipcRenderer.invoke('get-tree-structure'), getTreeStructure: () => ipcRenderer.invoke('get-tree-structure'),
filterProjects: (filters) => ipcRenderer.invoke('filter-projects', filters), filterProjects: (filters) => ipcRenderer.invoke('filter-projects', filters),
updateProject: (project) => ipcRenderer.invoke('update-project', project), updateProject: (project) => ipcRenderer.invoke('update-project', project),
deleteProject: (projectId) => ipcRenderer.invoke('delete-project', projectId), deleteProject: (projectId) => ipcRenderer.invoke('delete-project', projectId),
// Excel处理 // Excel处理
importExcel: (filePath) => ipcRenderer.invoke('import-excel', filePath), importExcel: (filePath) => ipcRenderer.invoke('import-excel', filePath),
// 数据清除 // 数据清除
clearAllData: () => ipcRenderer.invoke('clear-all-data'), clearAllData: () => ipcRenderer.invoke('clear-all-data'),
// 事件监听 // 事件监听
onImportProgress: (callback) => { onImportProgress: (callback) => {
// 移除之前的监听器,避免重复 // 移除之前的监听器,避免重复
ipcRenderer.removeAllListeners('import-progress'); ipcRenderer.removeAllListeners('import-progress');
// 添加新的监听器 // 添加新的监听器
ipcRenderer.on('import-progress', (event, data) => callback(data)); ipcRenderer.on('import-progress', (event, data) => callback(data));
} }
}); });

View File

@ -29,6 +29,8 @@ function App() {
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [isDarkMode] = useState(true); // 固定使用深色主题 const [isDarkMode] = useState(true); // 固定使用深色主题
const [lastImportedFilePath, setLastImportedFilePath] = useState(null); // 记录最后导入的文件路径 const [lastImportedFilePath, setLastImportedFilePath] = useState(null); // 记录最后导入的文件路径
// 根据选中的节点筛选项目数据
let select = {};
// 初始化数据 // 初始化数据
useEffect(() => { useEffect(() => {
@ -111,8 +113,6 @@ function App() {
const key = selectedKeys[0]; const key = selectedKeys[0];
setSelectedNode(key); setSelectedNode(key);
// 根据选中的节点筛选项目数据
let filters = {};
if (key === 'headquarters') { if (key === 'headquarters') {
// 总部节点,显示所有数据 // 总部节点,显示所有数据
@ -120,17 +120,17 @@ function App() {
} else if (key.startsWith('unit-')) { } else if (key.startsWith('unit-')) {
// 单位节点,筛选该单位的数据 // 单位节点,筛选该单位的数据
const unit = key.replace('unit-', ''); const unit = key.replace('unit-', '');
filters = {unit}; select = {unit};
} else if (key.startsWith('construction-')) { } else if (key.startsWith('construction-')) {
// 建设单位节点,筛选该建设单位的数据 // 建设单位节点,筛选该建设单位的数据
const parts = key.split('-'); const parts = key.split('-');
const unit = parts[1]; const unit = parts[1];
const constructionUnit = parts.slice(2).join('-'); const constructionUnit = parts.slice(2).join('-');
filters = {unit, constructionUnit}; select = {unit, constructionUnit};
} }
// 应用筛选 // 应用筛选
filterProjects(filters); filterProjects(select);
} }
}; };
@ -159,16 +159,17 @@ function App() {
} }
// 应用筛选 // 应用筛选
filterProjects(filters); filterProjects({ ...filters, ...select });
}; };
// 处理项目搜索 // 处理项目搜索
const handleSearch = (text) => { const handleSearch = (text) => {
setSearchText(text);
setSearchText(text);
console.log(select)
// 根据搜索文本筛选项目数据 // 根据搜索文本筛选项目数据
const filters = {subProjectName: text}; const filters = {subProjectName: text};
filterProjects(filters); filterProjects({ ...filters, ...select });
}; };
// 处理项目选择 // 处理项目选择
@ -261,6 +262,7 @@ function App() {
const progressMessage = document.getElementById('import-progress-message'); const progressMessage = document.getElementById('import-progress-message');
if (progressBar && progressMessage) { if (progressBar && progressMessage) {
const antProgressText = progressBar.querySelector('.ant-progress-text');
// 更新进度条 // 更新进度条
const antProgress = progressBar.querySelector('.ant-progress-bg'); const antProgress = progressBar.querySelector('.ant-progress-bg');
if (antProgress) { if (antProgress) {
@ -270,7 +272,7 @@ function App() {
// 更新文本 // 更新文本
progressMessage.textContent = data.message; progressMessage.textContent = data.message;
antProgressText.textContent = `${data.progress}%`;
// 如果导入完成,关闭对话框并重新加载数据 // 如果导入完成,关闭对话框并重新加载数据
if (data.status === 'complete') { if (data.status === 'complete') {
setTimeout(() => { setTimeout(() => {

View File

@ -1,5 +1,5 @@
import React, {useEffect} from 'react'; import React, {useEffect} from 'react';
import {Modal, Form, Input, Select, Switch, Button} from 'antd'; import {Modal, Form, Input, Select, Switch, Button, InputNumber} from 'antd';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
const {Option} = Select; const {Option} = Select;
@ -104,14 +104,26 @@ const ProjectDetailForm = ({visible, project, onCancel, onSave}) => {
<Form.Item label="下次梳理时间" name="next_review_time"> <Form.Item label="下次梳理时间" name="next_review_time">
<Input placeholder="YYYY-MM-DD"/> <Input placeholder="YYYY-MM-DD"/>
</Form.Item> </Form.Item>
<Form.Item label="参建人数" name="participants_count"> <Form.Item label="参建人数" name="participants_count"
<Input type="number"/> rules={[
{type: 'number', min: 1, message: '必须为正整数'},
]}
>
<InputNumber min={1} precision={0} style={{width: '100%'}}/>
</Form.Item> </Form.Item>
<Form.Item label="新班组进场数量" name="new_team_count"> <Form.Item label="新班组进场数量" name="new_team_count" rules={[
<Input type="number"/> {type: 'number', min: 1, message: '必须为正整数'},
]}
>
<InputNumber min={1} precision={0} style={{width: '100%'}}/>
</Form.Item> </Form.Item>
<Form.Item label="新人进场数量" name="new_person_count"> <Form.Item label="新人进场数量" name="new_person_count" rules={[
<Input type="number"/> {type: 'number', min: 1, message: '必须为正整数'},
]}
>
<InputNumber min={1} precision={0} style={{width: '100%'}}/>
</Form.Item> </Form.Item>
<Form.Item label="带班人姓名、电话" name="leader_info"> <Form.Item label="带班人姓名、电话" name="leader_info">
<Input/> <Input/>
@ -144,19 +156,50 @@ const ProjectDetailForm = ({visible, project, onCancel, onSave}) => {
<Form.Item> <Form.Item>
<div> <div>
<p style={{fontSize: '20px', fontWeight: 'bold'}}>人的变化</p> <p style={{fontSize: '20px', fontWeight: 'bold'}}>人的变化</p><Form.Item
<Form.Item label="新进班组数量" name="new_team"> label="新进班组数量"
<Input type="number"/> name="new_team"
rules={[
{ message: '请输入新进班组数量'},
{type: 'number', min: 1, message: '必须为正整数'},
]}
>
<InputNumber min={1} precision={0} style={{width: '100%'}}/>
</Form.Item>
<Form.Item
label="新进班组骨干数量"
name="new_members"
rules={[
{message: '请输入新进班组骨干数量'},
{type: 'number', min: 1, message: '必须为正整数'},
]}
>
<InputNumber min={1} precision={0} style={{width: '100%'}}/>
</Form.Item> </Form.Item>
<Form.Item label="新进班组骨干数量" name="new_members">
<Input type="number"/> <Form.Item
label="新进高空人员数量"
name="new_high_altitude"
rules={[
{message: '请输入新进高空人员数量'},
{type: 'number', min: 1, message: '必须为正整数'},
]}
>
<InputNumber min={1} precision={0} style={{width: '100%'}}/>
</Form.Item> </Form.Item>
<Form.Item label="新进高空人员数量" name="new_high_altitude">
<Input type="number"/> <Form.Item
</Form.Item> label="新进一般人员数量"
<Form.Item label="新进一般人员数量" name="new_hired_general"> name="new_hired_general"
<Input type="number"/> rules={[
{message: '请输入新进一般人员数量'},
{type: 'number', min: 1, message: '必须为正整数'},
]}
>
<InputNumber min={1} precision={0} style={{width: '100%'}}/>
</Form.Item> </Form.Item>
</div> </div>
</Form.Item> </Form.Item>

View File

@ -6,7 +6,7 @@ const path = require('path');
class ExcelService { class ExcelService {
constructor(db) { constructor(db) {
this.db = db; this.db = db;
// 不在构造函数中注册事件,避免重复注册 // 不在构造函数中注册事件,避免重复注册
// 事件处理器现在由main.js处理 // 事件处理器现在由main.js处理
} }
@ -15,11 +15,11 @@ class ExcelService {
async importExcel(filePath) { async importExcel(filePath) {
try { try {
console.log('正在导入Excel文件:', filePath); console.log('正在导入Excel文件:', filePath);
if (!filePath) { if (!filePath) {
throw new Error('文件路径不能为空'); throw new Error('文件路径不能为空');
} }
// 发送开始导入进度事件 // 发送开始导入进度事件
if (global.mainWindow) { if (global.mainWindow) {
global.mainWindow.webContents.send('import-progress', { global.mainWindow.webContents.send('import-progress', {
@ -28,21 +28,21 @@ class ExcelService {
message: '正在读取Excel文件...' message: '正在读取Excel文件...'
}); });
} }
const workbook = new ExcelJS.Workbook(); const workbook = new ExcelJS.Workbook();
await workbook.xlsx.readFile(filePath); await workbook.xlsx.readFile(filePath);
// 读取第一个工作表 // 读取第一个工作表
const worksheet = workbook.getWorksheet(1); const worksheet = workbook.getWorksheet(1);
const data = []; const data = [];
const totalRows = worksheet.rowCount - 1; // 减去表头行 const totalRows = worksheet.rowCount - 1; // 减去表头行
// 读取表头 // 读取表头
const headers = []; const headers = [];
worksheet.getRow(1).eachCell((cell, colNumber) => { worksheet.getRow(1).eachCell((cell, colNumber) => {
headers[colNumber - 1] = cell.value; headers[colNumber - 1] = cell.value;
}); });
// 发送读取表头完成进度事件 // 发送读取表头完成进度事件
if (global.mainWindow) { if (global.mainWindow) {
global.mainWindow.webContents.send('import-progress', { global.mainWindow.webContents.send('import-progress', {
@ -51,7 +51,7 @@ class ExcelService {
message: '表头读取完成,正在读取数据...' message: '表头读取完成,正在读取数据...'
}); });
} }
// 读取数据 // 读取数据
let processedRows = 0; let processedRows = 0;
worksheet.eachRow((row, rowNumber) => { worksheet.eachRow((row, rowNumber) => {
@ -61,7 +61,7 @@ class ExcelService {
rowData[headers[colNumber - 1]] = cell.value; rowData[headers[colNumber - 1]] = cell.value;
}); });
data.push(rowData); data.push(rowData);
// 计算并发送进度 // 计算并发送进度
processedRows++; processedRows++;
if (processedRows % 10 === 0 || processedRows === totalRows) { // 每10行或最后一行发送一次进度 if (processedRows % 10 === 0 || processedRows === totalRows) { // 每10行或最后一行发送一次进度
@ -76,7 +76,7 @@ class ExcelService {
} }
} }
}); });
// 发送数据读取完成进度事件 // 发送数据读取完成进度事件
if (global.mainWindow) { if (global.mainWindow) {
global.mainWindow.webContents.send('import-progress', { global.mainWindow.webContents.send('import-progress', {
@ -85,11 +85,11 @@ class ExcelService {
message: `数据读取完成,正在保存到数据库...` message: `数据读取完成,正在保存到数据库...`
}); });
} }
// 将数据保存到数据库(这里可以根据实际需求修改) // 将数据保存到数据库(这里可以根据实际需求修改)
if (data.length > 0 && this.db) { if (data.length > 0 && this.db) {
await this.saveDataToDatabase(data); await this.saveDataToDatabase(data);
// 发送数据保存完成进度事件 // 发送数据保存完成进度事件
if (global.mainWindow) { if (global.mainWindow) {
global.mainWindow.webContents.send('import-progress', { global.mainWindow.webContents.send('import-progress', {
@ -98,10 +98,10 @@ class ExcelService {
message: `数据保存完成,正在构建树状结构...` message: `数据保存完成,正在构建树状结构...`
}); });
} }
// 构建树状结构 // 构建树状结构
await this.buildTreeStructure(data); await this.buildTreeStructure(data);
// 发送导入完成进度事件 // 发送导入完成进度事件
if (global.mainWindow) { if (global.mainWindow) {
global.mainWindow.webContents.send('import-progress', { global.mainWindow.webContents.send('import-progress', {
@ -120,7 +120,7 @@ class ExcelService {
}); });
} }
} }
return { return {
success: true, success: true,
message: `成功读取 ${data.length} 条数据`, message: `成功读取 ${data.length} 条数据`,
@ -128,7 +128,7 @@ class ExcelService {
}; };
} catch (error) { } catch (error) {
console.error('Excel导入错误:', error); console.error('Excel导入错误:', error);
// 发送导入错误进度事件 // 发送导入错误进度事件
if (global.mainWindow) { if (global.mainWindow) {
global.mainWindow.webContents.send('import-progress', { global.mainWindow.webContents.send('import-progress', {
@ -137,14 +137,14 @@ class ExcelService {
message: `导入失败: ${error.message}` message: `导入失败: ${error.message}`
}); });
} }
return { return {
success: false, success: false,
error: error.message error: error.message
}; };
} }
} }
// 将数据保存到数据库 // 将数据保存到数据库
saveDataToDatabase(data) { saveDataToDatabase(data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -183,35 +183,68 @@ class ExcelService {
remarks remarks
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`); `);
// 开始事务 // 开始事务
this.db.serialize(() => { this.db.serialize(() => {
this.db.run('BEGIN TRANSACTION'); this.db.run('BEGIN TRANSACTION');
// 发送进度更新 // 发送进度更新
let processedRows = 0; let processedRows = 0;
const totalRows = data.length; const totalRows = data.length;
for (const row of data) { for (const row of data) {
// 处理字段值,确保所有字段都能正确导入 // 处理字段值,确保所有字段都能正确导入
const getValue = (fieldName, defaultValue = null) => { const getValue = (fieldName, defaultValue = null) => {
// 检查字段是否存在,并处理空值 // 检查字段是否存在,并处理空值
const value = row[fieldName]; const value = row[fieldName];
if (value === undefined || value === null || value === '') { if (value === undefined || value === null || value === '') {
return defaultValue; return defaultValue;
} }
// 如果是日期类型转换为ISO格式 // 如果是日期类型转换为ISO格式
if (fieldName === '实际开工时间' || fieldName === '计划竣工时间' || fieldName === '完成时间' || fieldName === '下次梳理时间(注意与 隐患提示/工作要求 对应)') { if (
const date = new Date(value); fieldName === '实际开工时间' ||
if (!isNaN(date.getTime())) { fieldName === '计划竣工时间' ||
fieldName === '完成时间' ||
return date.toISOString().split('T')[0]; // 只保留日期部分 fieldName === '下次梳理时间(注意与 隐患提示/工作要求 对应)'
) {
if (value == null) return ''; // 空值处理
// ✅ Excel 日期序列号(一般从 25569 开始)
if (typeof value === 'number') {
if (value > 1e12 && value < 1e14) {
// ✅ 毫秒级时间戳
const date = new Date(value);
if (!isNaN(date.getTime())) return date.toISOString().split('T')[0];
} else {
// ✅ Excel 序列号转日期(从 1900-01-01 起第1天是 1
const utcDays = Math.floor(value - 25569);
const utcValue = utcDays * 86400; // 转秒
const date = new Date(utcValue * 1000);
if (!isNaN(date.getTime())) return date.toISOString().split('T')[0];
}
} }
if (typeof value === 'string') {
let parsed = new Date(value);
if (!isNaN(parsed.getTime())) return parsed.toISOString().split('T')[0];
// ✅ 支持“5-12”、“5月12日” 等格式
const matched = value.match(/^(\d{1,2})[月/-](\d{1,2})/);
if (matched) {
const year = new Date().getFullYear(); // 默认今年
const mm = matched[1].padStart(2, '0');
const dd = matched[2].padStart(2, '0');
return `${year}-${mm}-${dd}`;
}
}
return ''; // 未能解析,返回空字符串
} }
return value; return value;
}; };
// 处理布尔值字段 // 处理布尔值字段
const getBooleanValue = (fieldName) => { const getBooleanValue = (fieldName) => {
const value = row[fieldName]; const value = row[fieldName];
@ -220,7 +253,7 @@ class ExcelService {
} }
return 0; return 0;
}; };
// 处理数字字段 // 处理数字字段
const getNumberValue = (fieldName, defaultValue = 0) => { const getNumberValue = (fieldName, defaultValue = 0) => {
const value = row[fieldName]; const value = row[fieldName];
@ -231,7 +264,7 @@ class ExcelService {
const num = Number(value); const num = Number(value);
return isNaN(num) ? defaultValue : num; return isNaN(num) ? defaultValue : num;
}; };
// 使用处理函数获取字段值 // 使用处理函数获取字段值
stmt.run( stmt.run(
getValue('单位'), getValue('单位'),
@ -265,12 +298,15 @@ class ExcelService {
getValue('下次梳理时间(注意与 隐患提示/工作要求 对应)'), getValue('下次梳理时间(注意与 隐患提示/工作要求 对应)'),
getValue('备注') getValue('备注')
); );
// 更新进度 // 更新进度
processedRows++; processedRows++;
if (processedRows % 10 === 0 || processedRows === totalRows) { if (processedRows % 10 === 0 || processedRows === totalRows) {
const progress = Math.floor(50 + (processedRows / totalRows) * 20); // 50%-70%的进度 const progress = Math.floor(50 + (processedRows / totalRows) * 20); // 50%-70%的进度
if (global.mainWindow) { if (global.mainWindow) {
console.log("进度+++",progress)
global.mainWindow.webContents.send('import-progress', { global.mainWindow.webContents.send('import-progress', {
status: 'saving', status: 'saving',
progress: progress, progress: progress,
@ -279,7 +315,7 @@ class ExcelService {
} }
} }
} }
this.db.run('COMMIT', (err) => { this.db.run('COMMIT', (err) => {
if (err) { if (err) {
console.error('提交事务失败:', err); console.error('提交事务失败:', err);
@ -291,12 +327,12 @@ class ExcelService {
} }
}); });
}); });
// 完成后关闭准备好的语句 // 完成后关闭准备好的语句
stmt.finalize(); stmt.finalize();
}); });
} }
// 构建树状结构 // 构建树状结构
buildTreeStructure(data) { buildTreeStructure(data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -307,10 +343,10 @@ class ExcelService {
reject(err); reject(err);
return; return;
} }
// 使用Promise和事务来确保操作的原子性和顺序性 // 使用Promise和事务来确保操作的原子性和顺序性
const headquarters = '总部'; const headquarters = '总部';
// 开始事务 // 开始事务
this.db.run('BEGIN TRANSACTION', (err) => { this.db.run('BEGIN TRANSACTION', (err) => {
if (err) { if (err) {
@ -318,7 +354,7 @@ class ExcelService {
reject(err); reject(err);
return; return;
} }
// 发送进度更新 - 开始创建树状结构 // 发送进度更新 - 开始创建树状结构
if (global.mainWindow) { if (global.mainWindow) {
global.mainWindow.webContents.send('import-progress', { global.mainWindow.webContents.send('import-progress', {
@ -327,7 +363,7 @@ class ExcelService {
message: `正在创建总部节点...` message: `正在创建总部节点...`
}); });
} }
// 插入总部节点 // 插入总部节点
this.db.run( this.db.run(
`INSERT INTO tree_structure (headquarters, unit, construction_unit, parent_id, node_level) `INSERT INTO tree_structure (headquarters, unit, construction_unit, parent_id, node_level)
@ -340,7 +376,7 @@ class ExcelService {
reject(err); reject(err);
return; return;
} }
// 获取总部节点ID // 获取总部节点ID
this.db.get('SELECT last_insert_rowid() as id', (err, row) => { this.db.get('SELECT last_insert_rowid() as id', (err, row) => {
if (err) { if (err) {
@ -349,16 +385,16 @@ class ExcelService {
reject(err); reject(err);
return; return;
} }
const headquartersId = row.id; const headquartersId = row.id;
console.log(`创建总部节点成功, ID: ${headquartersId}`); console.log(`创建总部节点成功, ID: ${headquartersId}`);
// 单位映射 // 单位映射
const unitMap = {}; const unitMap = {};
// 首先处理所有单位节点 // 首先处理所有单位节点
const uniqueUnits = [...new Set(data.filter(row => row['单位']).map(row => row['单位']))]; const uniqueUnits = [...new Set(data.filter(row => row['单位']).map(row => row['单位']))];
// 发送进度更新 - 开始创建单位节点 // 发送进度更新 - 开始创建单位节点
if (global.mainWindow) { if (global.mainWindow) {
global.mainWindow.webContents.send('import-progress', { global.mainWindow.webContents.send('import-progress', {
@ -367,16 +403,16 @@ class ExcelService {
message: `正在创建单位节点...` message: `正在创建单位节点...`
}); });
} }
const processUnits = () => { const processUnits = () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let unitProcessed = 0; let unitProcessed = 0;
if (uniqueUnits.length === 0) { if (uniqueUnits.length === 0) {
resolve(); resolve();
return; return;
} }
uniqueUnits.forEach(unit => { uniqueUnits.forEach(unit => {
this.db.run( this.db.run(
`INSERT INTO tree_structure (headquarters, unit, construction_unit, parent_id, node_level) `INSERT INTO tree_structure (headquarters, unit, construction_unit, parent_id, node_level)
@ -388,13 +424,13 @@ class ExcelService {
reject(err); reject(err);
return; return;
} }
const unitId = this.lastID; const unitId = this.lastID;
unitMap[unit] = { id: unitId, constructionUnits: {} }; unitMap[unit] = { id: unitId, constructionUnits: {} };
console.log(`创建单位节点: ${unit}, ID: ${unitId}`); console.log(`创建单位节点: ${unit}, ID: ${unitId}`);
unitProcessed++; unitProcessed++;
// 更新进度 // 更新进度
if (unitProcessed % 5 === 0 || unitProcessed === uniqueUnits.length) { if (unitProcessed % 5 === 0 || unitProcessed === uniqueUnits.length) {
const progress = Math.floor(80 + (unitProcessed / uniqueUnits.length) * 10); // 80%-90%的进度 const progress = Math.floor(80 + (unitProcessed / uniqueUnits.length) * 10); // 80%-90%的进度
@ -406,7 +442,7 @@ class ExcelService {
}); });
} }
} }
if (unitProcessed === uniqueUnits.length) { if (unitProcessed === uniqueUnits.length) {
resolve(); resolve();
} }
@ -415,18 +451,18 @@ class ExcelService {
}); });
}); });
}; };
// 然后处理所有建设单位节点 // 然后处理所有建设单位节点
const processConstructionUnits = () => { const processConstructionUnits = () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// 收集所有有效的建设单位数据 // 收集所有有效的建设单位数据
const constructionUnitData = []; const constructionUnitData = [];
data.forEach(row => { data.forEach(row => {
const unit = row['单位']; const unit = row['单位'];
const constructionUnit = row['建设单位']; const constructionUnit = row['建设单位'];
if (unit && constructionUnit && unitMap[unit] && if (unit && constructionUnit && unitMap[unit] &&
!unitMap[unit].constructionUnits[constructionUnit]) { !unitMap[unit].constructionUnits[constructionUnit]) {
constructionUnitData.push({ constructionUnitData.push({
unit, unit,
@ -436,7 +472,7 @@ class ExcelService {
unitMap[unit].constructionUnits[constructionUnit] = true; unitMap[unit].constructionUnits[constructionUnit] = true;
} }
}); });
// 发送进度更新 - 开始创建建设单位节点 // 发送进度更新 - 开始创建建设单位节点
if (global.mainWindow) { if (global.mainWindow) {
global.mainWindow.webContents.send('import-progress', { global.mainWindow.webContents.send('import-progress', {
@ -445,14 +481,14 @@ class ExcelService {
message: `正在创建建设单位节点...` message: `正在创建建设单位节点...`
}); });
} }
if (constructionUnitData.length === 0) { if (constructionUnitData.length === 0) {
resolve(); resolve();
return; return;
} }
let processed = 0; let processed = 0;
constructionUnitData.forEach(item => { constructionUnitData.forEach(item => {
this.db.run( this.db.run(
`INSERT INTO tree_structure (headquarters, unit, construction_unit, parent_id, node_level) `INSERT INTO tree_structure (headquarters, unit, construction_unit, parent_id, node_level)
@ -465,9 +501,9 @@ class ExcelService {
} else { } else {
console.log(`创建建设单位节点: ${item.constructionUnit}, 父节点: ${item.unit}`); console.log(`创建建设单位节点: ${item.constructionUnit}, 父节点: ${item.unit}`);
} }
processed++; processed++;
// 更新进度 // 更新进度
if (processed % 10 === 0 || processed === constructionUnitData.length) { if (processed % 10 === 0 || processed === constructionUnitData.length) {
const progress = Math.floor(90 + (processed / constructionUnitData.length) * 10); // 90%-100%的进度 const progress = Math.floor(90 + (processed / constructionUnitData.length) * 10); // 90%-100%的进度
@ -479,7 +515,7 @@ class ExcelService {
}); });
} }
} }
if (processed === constructionUnitData.length) { if (processed === constructionUnitData.length) {
resolve(); resolve();
} }
@ -488,7 +524,7 @@ class ExcelService {
}); });
}); });
}; };
// 按顺序执行:先处理单位,再处理建设单位 // 按顺序执行:先处理单位,再处理建设单位
processUnits() processUnits()
.then(() => processConstructionUnits()) .then(() => processConstructionUnits())

View File

@ -86,7 +86,7 @@ code {
.ant-tree { .ant-tree {
background-color: transparent !important; background-color: transparent !important;
color: var(--vscode-text) !important; color: var(--vscode-text) !important;
} }mm
.ant-tree-node-content-wrapper:hover { .ant-tree-node-content-wrapper:hover {
background-color: var(--vscode-hover-item) !important; background-color: var(--vscode-hover-item) !important;