|
@@ -21,7 +21,7 @@ export class DatabaseCintasImportProcessor {
|
|
|
async processCintasImport(importId: number): Promise<ImportResult> {
|
|
async processCintasImport(importId: number): Promise<ImportResult> {
|
|
|
try {
|
|
try {
|
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Starting import processing for ID: ${importId}`);
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Starting import processing for ID: ${importId}`);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Initialize the progress server if not already done
|
|
// Initialize the progress server if not already done
|
|
|
if (!this.progressServer.isServerInitialized()) {
|
|
if (!this.progressServer.isServerInitialized()) {
|
|
|
this.progressServer.initialize();
|
|
this.progressServer.initialize();
|
|
@@ -61,7 +61,7 @@ export class DatabaseCintasImportProcessor {
|
|
|
|
|
|
|
|
// Read Excel file directly from database
|
|
// Read Excel file directly from database
|
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Starting Excel file reading from database...`);
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Starting Excel file reading from database...`);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
const sections = await this.reader.readExcelFromDatabase(
|
|
const sections = await this.reader.readExcelFromDatabase(
|
|
|
importRecord.fileId!,
|
|
importRecord.fileId!,
|
|
|
importRecord.layout,
|
|
importRecord.layout,
|
|
@@ -78,8 +78,8 @@ export class DatabaseCintasImportProcessor {
|
|
|
|
|
|
|
|
for (let i = 0; i < sections.length; i++) {
|
|
for (let i = 0; i < sections.length; i++) {
|
|
|
const section = sections[i];
|
|
const section = sections[i];
|
|
|
-
|
|
|
|
|
- console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Processing section ${i+1}/${sections.length}: ${section.name}`);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Processing section ${i + 1}/${sections.length}: ${section.name}`);
|
|
|
progress.currentSection = section.name;
|
|
progress.currentSection = section.name;
|
|
|
progress.processedSections = i + 1;
|
|
progress.processedSections = i + 1;
|
|
|
this.progressServer.broadcastProgress(importId, progress);
|
|
this.progressServer.broadcastProgress(importId, progress);
|
|
@@ -88,7 +88,7 @@ export class DatabaseCintasImportProcessor {
|
|
|
// Ensure table exists for this section
|
|
// Ensure table exists for this section
|
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Creating table ${section.tableName} for section ${section.name}`);
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Creating table ${section.tableName} for section ${section.name}`);
|
|
|
await this.inserter.createImportTable(section.tableName, section.fields);
|
|
await this.inserter.createImportTable(section.tableName, section.fields);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
const insertedRows = await this.inserter.insertSectionData(
|
|
const insertedRows = await this.inserter.insertSectionData(
|
|
|
section,
|
|
section,
|
|
|
importId,
|
|
importId,
|
|
@@ -114,18 +114,6 @@ export class DatabaseCintasImportProcessor {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Run the stored procedure to calculate summary
|
|
|
|
|
- console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Running summary calculation procedure...`);
|
|
|
|
|
- try {
|
|
|
|
|
- await this.prisma.$executeRawUnsafe(
|
|
|
|
|
- `CALL cintas_calculate_summary(${importId})`
|
|
|
|
|
- );
|
|
|
|
|
- console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Summary calculation completed successfully`);
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- console.error(`[${new Date().toISOString()}] [DatabaseCintasImport] ERROR: Summary calculation failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
|
|
|
- progress.errors.push(`Stored procedure error: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
progress.status = 'completed';
|
|
progress.status = 'completed';
|
|
|
this.progressServer.broadcastProgress(importId, progress);
|
|
this.progressServer.broadcastProgress(importId, progress);
|
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Import processing completed successfully. Total inserted: ${totalInserted}`);
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Import processing completed successfully. Total inserted: ${totalInserted}`);
|
|
@@ -167,7 +155,7 @@ export class DatabaseCintasImportProcessor {
|
|
|
): Promise<ImportResult> {
|
|
): Promise<ImportResult> {
|
|
|
try {
|
|
try {
|
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Starting import processing from buffer`);
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Starting import processing from buffer`);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Initialize progress tracking
|
|
// Initialize progress tracking
|
|
|
const progress: ImportProgress = {
|
|
const progress: ImportProgress = {
|
|
|
importId: 0,
|
|
importId: 0,
|
|
@@ -182,7 +170,7 @@ export class DatabaseCintasImportProcessor {
|
|
|
|
|
|
|
|
// Read Excel file directly from buffer
|
|
// Read Excel file directly from buffer
|
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Starting Excel file reading from buffer...`);
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Starting Excel file reading from buffer...`);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
const sections = await this.reader.readExcelFromBuffer(
|
|
const sections = await this.reader.readExcelFromBuffer(
|
|
|
buffer,
|
|
buffer,
|
|
|
layoutConfig,
|
|
layoutConfig,
|
|
@@ -199,8 +187,8 @@ export class DatabaseCintasImportProcessor {
|
|
|
|
|
|
|
|
for (let i = 0; i < sections.length; i++) {
|
|
for (let i = 0; i < sections.length; i++) {
|
|
|
const section = sections[i];
|
|
const section = sections[i];
|
|
|
-
|
|
|
|
|
- console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Processing section ${i+1}/${sections.length}: ${section.name}`);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Processing section ${i + 1}/${sections.length}: ${section.name}`);
|
|
|
progress.currentSection = section.name;
|
|
progress.currentSection = section.name;
|
|
|
progress.processedSections = i + 1;
|
|
progress.processedSections = i + 1;
|
|
|
onProgress(progress);
|
|
onProgress(progress);
|
|
@@ -209,7 +197,7 @@ export class DatabaseCintasImportProcessor {
|
|
|
// Ensure table exists for this section
|
|
// Ensure table exists for this section
|
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Creating table ${section.tableName} for section ${section.name}`);
|
|
console.log(`[${new Date().toISOString()}] [DatabaseCintasImport] Creating table ${section.tableName} for section ${section.name}`);
|
|
|
await this.inserter.createImportTable(section.tableName, section.fields);
|
|
await this.inserter.createImportTable(section.tableName, section.fields);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
const insertedRows = await this.inserter.insertSectionData(
|
|
const insertedRows = await this.inserter.insertSectionData(
|
|
|
section,
|
|
section,
|
|
|
0, // Use 0 for buffer-based imports
|
|
0, // Use 0 for buffer-based imports
|