|
@@ -18,6 +18,8 @@ export class ImportProcessor {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async processImport(importId: number): Promise<ImportResult> {
|
|
async processImport(importId: number): Promise<ImportResult> {
|
|
|
|
|
+ console.log('[IMPORT_PROCESSOR] 🔷 Starting processImport for importId:', importId);
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
// Get import record with layout configuration
|
|
// Get import record with layout configuration
|
|
|
const importRecord = await this.prisma.import.findUnique({
|
|
const importRecord = await this.prisma.import.findUnique({
|
|
@@ -33,11 +35,21 @@ export class ImportProcessor {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ console.log('[IMPORT_PROCESSOR] 📄 Import record:', {
|
|
|
|
|
+ id: importRecord?.id,
|
|
|
|
|
+ name: importRecord?.name,
|
|
|
|
|
+ hasFileId: !!importRecord?.fileId,
|
|
|
|
|
+ layoutName: importRecord?.layout?.name,
|
|
|
|
|
+ sectionsCount: importRecord?.layout?.sections?.length
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
if (!importRecord) {
|
|
if (!importRecord) {
|
|
|
|
|
+ console.error('[IMPORT_PROCESSOR] ❌ Import not found');
|
|
|
throw new Error('Import not found');
|
|
throw new Error('Import not found');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!importRecord.fileId) {
|
|
if (!importRecord.fileId) {
|
|
|
|
|
+ console.error('[IMPORT_PROCESSOR] ❌ No file attached to import');
|
|
|
throw new Error('No file attached to import');
|
|
throw new Error('No file attached to import');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -46,7 +58,15 @@ export class ImportProcessor {
|
|
|
where: { id: importRecord.fileId }
|
|
where: { id: importRecord.fileId }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ console.log('[IMPORT_PROCESSOR] 📁 File record:', {
|
|
|
|
|
+ id: fileRecord?.id,
|
|
|
|
|
+ filename: fileRecord?.filename,
|
|
|
|
|
+ size: fileRecord?.size,
|
|
|
|
|
+ mimetype: fileRecord?.mimetype
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
if (!fileRecord) {
|
|
if (!fileRecord) {
|
|
|
|
|
+ console.error('[IMPORT_PROCESSOR] ❌ File not found');
|
|
|
throw new Error('File not found');
|
|
throw new Error('File not found');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -62,7 +82,10 @@ export class ImportProcessor {
|
|
|
totalSections: importRecord.layout?.sections?.length ?? 0
|
|
totalSections: importRecord.layout?.sections?.length ?? 0
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ console.log('[IMPORT_PROCESSOR] 📊 Initial progress:', { totalSections: progress.totalSections });
|
|
|
|
|
+
|
|
|
// Read Excel file
|
|
// Read Excel file
|
|
|
|
|
+ console.log('[IMPORT_PROCESSOR] 📖 Starting to read Excel file...');
|
|
|
const sections = await this.reader.readExcelFile(
|
|
const sections = await this.reader.readExcelFile(
|
|
|
fileRecord.data,
|
|
fileRecord.data,
|
|
|
importRecord.layout,
|
|
importRecord.layout,
|
|
@@ -71,10 +94,21 @@ export class ImportProcessor {
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+ console.log('[IMPORT_PROCESSOR] 📖 Excel read complete. Sections parsed:', sections.length);
|
|
|
|
|
+ sections.forEach((section, idx) => {
|
|
|
|
|
+ console.log(`[IMPORT_PROCESSOR] Section ${idx + 1}:`, {
|
|
|
|
|
+ name: section.name,
|
|
|
|
|
+ tableName: section.tableName,
|
|
|
|
|
+ dataRows: section.data?.length
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
// Process each section
|
|
// Process each section
|
|
|
const processedSections: ProcessedSection[] = [];
|
|
const processedSections: ProcessedSection[] = [];
|
|
|
let totalInserted = 0;
|
|
let totalInserted = 0;
|
|
|
|
|
|
|
|
|
|
+ console.log('[IMPORT_PROCESSOR] 🔄 Starting to process', sections.length, 'sections...');
|
|
|
|
|
+
|
|
|
for (let i = 0; i < sections.length; i++) {
|
|
for (let i = 0; i < sections.length; i++) {
|
|
|
const section = sections[i];
|
|
const section = sections[i];
|
|
|
|
|
|
|
@@ -83,6 +117,12 @@ export class ImportProcessor {
|
|
|
progress.processedSections = i + 1;
|
|
progress.processedSections = i + 1;
|
|
|
this.progressServer.broadcastProgress(importId, progress);
|
|
this.progressServer.broadcastProgress(importId, progress);
|
|
|
|
|
|
|
|
|
|
+ console.log(`[IMPORT_PROCESSOR] 📥 Processing section ${i + 1}/${sections.length}:`, {
|
|
|
|
|
+ name: section.name,
|
|
|
|
|
+ tableName: section.tableName,
|
|
|
|
|
+ dataRows: section.data?.length
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
const insertedRows = await this.inserter.insertSectionData(
|
|
const insertedRows = await this.inserter.insertSectionData(
|
|
|
section,
|
|
section,
|
|
@@ -93,6 +133,8 @@ export class ImportProcessor {
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+ console.log(`[IMPORT_PROCESSOR] ✅ Section ${section.name} inserted ${insertedRows} rows`);
|
|
|
|
|
+
|
|
|
processedSections.push({
|
|
processedSections.push({
|
|
|
sectionData: section,
|
|
sectionData: section,
|
|
|
insertedRows
|
|
insertedRows
|
|
@@ -102,6 +144,7 @@ export class ImportProcessor {
|
|
|
|
|
|
|
|
} catch (error: unknown) {
|
|
} catch (error: unknown) {
|
|
|
const errorMessage = `Error processing section ${section.name ?? 'unknown'}: ${error instanceof Error ? error.message : 'Unknown error'}`;
|
|
const errorMessage = `Error processing section ${section.name ?? 'unknown'}: ${error instanceof Error ? error.message : 'Unknown error'}`;
|
|
|
|
|
+ console.error('[IMPORT_PROCESSOR] ❌', errorMessage);
|
|
|
progress.errors.push(errorMessage);
|
|
progress.errors.push(errorMessage);
|
|
|
this.progressServer.broadcastProgress(importId, progress);
|
|
this.progressServer.broadcastProgress(importId, progress);
|
|
|
}
|
|
}
|
|
@@ -112,6 +155,12 @@ export class ImportProcessor {
|
|
|
progress.status = 'completed';
|
|
progress.status = 'completed';
|
|
|
this.progressServer.broadcastProgress(importId, progress);
|
|
this.progressServer.broadcastProgress(importId, progress);
|
|
|
|
|
|
|
|
|
|
+ console.log('[IMPORT_PROCESSOR] ✅ Import processing completed:', {
|
|
|
|
|
+ totalInserted,
|
|
|
|
|
+ sectionsProcessed: processedSections.length,
|
|
|
|
|
+ errors: progress.errors.length
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
success: true,
|
|
success: true,
|
|
|
totalInserted,
|
|
totalInserted,
|
|
@@ -130,6 +179,7 @@ export class ImportProcessor {
|
|
|
totalSections: 0
|
|
totalSections: 0
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ console.error('[IMPORT_PROCESSOR] ❌ Import processing failed:', error);
|
|
|
this.progressServer.broadcastProgress(importId, progress);
|
|
this.progressServer.broadcastProgress(importId, progress);
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
@@ -171,4 +221,4 @@ export class ImportProcessor {
|
|
|
return { valid: false, errors };
|
|
return { valid: false, errors };
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|