diff --git a/src/main/java/de/avatic/lcc/repositories/bulk/BulkOperationRepository.java b/src/main/java/de/avatic/lcc/repositories/bulk/BulkOperationRepository.java index f9335cf..1fc0201 100644 --- a/src/main/java/de/avatic/lcc/repositories/bulk/BulkOperationRepository.java +++ b/src/main/java/de/avatic/lcc/repositories/bulk/BulkOperationRepository.java @@ -69,38 +69,38 @@ public class BulkOperationRepository { // First, update sys_error records to set bulk_operation_id to NULL // for bulk operations that will be deleted (all but the 10 newest for the current user) String updateErrorsSql = """ - UPDATE sys_error - SET bulk_operation_id = NULL - WHERE bulk_operation_id IN ( - SELECT id FROM ( - SELECT id - FROM bulk_operation - WHERE user_id = ? - AND state NOT IN ('SCHEDULED', 'PROCESSING') - ORDER BY created_at DESC - LIMIT 18446744073709551615 OFFSET 10 - ) AS old_operations - ) - """; + UPDATE sys_error + SET bulk_operation_id = NULL + WHERE bulk_operation_id IN ( + SELECT id FROM ( + SELECT id + FROM bulk_operation + WHERE user_id = ? + AND state NOT IN ('SCHEDULED', 'PROCESSING') + ORDER BY created_at DESC + LIMIT 18446744073709551615 OFFSET 10 + ) AS old_operations + ) + """; jdbcTemplate.update(updateErrorsSql, userId); // Then delete the old bulk_operation entries (keeping only the 10 newest for the current user) String deleteBulkSql = """ - DELETE FROM bulk_operation - WHERE user_id = ? - AND state NOT IN ('SCHEDULED', 'PROCESSING') - AND id NOT IN ( - SELECT id FROM ( - SELECT id - FROM bulk_operation - WHERE user_id = ? - AND state NOT IN ('SCHEDULED', 'PROCESSING') - ORDER BY created_at DESC - LIMIT 10 - ) AS newest_operations - ) - """; + DELETE FROM bulk_operation + WHERE user_id = ? + AND state NOT IN ('SCHEDULED', 'PROCESSING') + AND id NOT IN ( + SELECT id FROM ( + SELECT id + FROM bulk_operation + WHERE user_id = ? + AND state NOT IN ('SCHEDULED', 'PROCESSING') + ORDER BY created_at DESC + LIMIT 10 + ) AS newest_operations + ) + """; jdbcTemplate.update(deleteBulkSql, userId, userId); } @@ -119,10 +119,10 @@ public class BulkOperationRepository { @Transactional public List listByUserId(Integer userId) { String sql = """ - SELECT id, user_id, bulk_file_type, bulk_processing_type, state, created_at + SELECT id, user_id, bulk_file_type, bulk_processing_type, state, created_at, validity_period_id FROM bulk_operation WHERE user_id = ? - + ORDER BY created_at DESC LIMIT 10 """; @@ -132,7 +132,7 @@ public class BulkOperationRepository { @Transactional public Optional getOperationById(Integer id) { String sql = """ - SELECT id, user_id, bulk_file_type, bulk_processing_type, state, file, created_at + SELECT id, user_id, bulk_file_type, bulk_processing_type, state, file, created_at, validity_period_id FROM bulk_operation WHERE id = ? """; @@ -180,6 +180,12 @@ public class BulkOperationRepository { operation.setProcessingType(BulkProcessingType.valueOf(rs.getString("bulk_processing_type"))); operation.setFileType(BulkFileType.valueOf(rs.getString("bulk_file_type"))); operation.setProcessState(BulkOperationState.valueOf(rs.getString("state"))); + + + operation.setValidityPeriodId(rs.getInt("validity_period_id")); + if (rs.wasNull()) + operation.setValidityPeriodId(null); + if (!skipFile) operation.setFile(rs.getBytes("file")); operation.setCreatedAt(rs.getTimestamp("created_at").toLocalDateTime()); diff --git a/src/main/java/de/avatic/lcc/service/bulk/BulkImportService.java b/src/main/java/de/avatic/lcc/service/bulk/BulkImportService.java index 91da7a3..04769c0 100644 --- a/src/main/java/de/avatic/lcc/service/bulk/BulkImportService.java +++ b/src/main/java/de/avatic/lcc/service/bulk/BulkImportService.java @@ -63,6 +63,7 @@ public class BulkImportService { break; case COUNTRY_MATRIX: var matrixRates = matrixRateExcelMapper.extractSheet(sheet); + matrixRates.forEach(System.out::println); break; case MATERIAL: var materials = materialExcelMapper.extractSheet(sheet); diff --git a/src/main/java/de/avatic/lcc/service/bulk/bulkImport/MaterialBulkImportService.java b/src/main/java/de/avatic/lcc/service/bulk/bulkImport/MaterialBulkImportService.java index e4c2fa9..480c5d0 100644 --- a/src/main/java/de/avatic/lcc/service/bulk/bulkImport/MaterialBulkImportService.java +++ b/src/main/java/de/avatic/lcc/service/bulk/bulkImport/MaterialBulkImportService.java @@ -17,10 +17,6 @@ public class MaterialBulkImportService { this.materialRepository = materialRepository; } - private static String normalizePartNumber(String partNumber) { - if (partNumber.length() > 12) throw new IllegalArgumentException("Part number must be less than 12 characters"); - return "000000000000".concat(partNumber).substring(partNumber.length()); - } public void processMaterialInstructions(BulkInstruction instr) { BulkInstructionType instrType = instr.getType();