diff --git a/src/main/java/com/ffii/fpsms/modules/master/entity/Warehouse.kt b/src/main/java/com/ffii/fpsms/modules/master/entity/Warehouse.kt index 993a3bf..6f033ef 100644 --- a/src/main/java/com/ffii/fpsms/modules/master/entity/Warehouse.kt +++ b/src/main/java/com/ffii/fpsms/modules/master/entity/Warehouse.kt @@ -15,8 +15,8 @@ open class Warehouse : BaseEntity() { @Column(name = "code", nullable = false, length = 30) open var code: String? = null @NotNull - @Column(name = "order", nullable = false, length = 30) - open var order: String? = null + @Column(name = "`order`", nullable = false,) + open var order: Int? = null @NotNull @Column(name = "name", nullable = false, length = 30) open var name: String? = null @@ -28,4 +28,20 @@ open class Warehouse : BaseEntity() { @NotNull @Column(name = "capacity", nullable = false, precision = 14, scale = 2) open var capacity: BigDecimal? = null + + + @Column(name = "store_id", nullable = false, length = 30) + open var store_id: String? = null + @Column(name = "storeLocation", nullable = true, length = 30) + open var storeLocation: String? = null + @Column(name = "stockTakeTable", nullable = true, length = 30) + open var stockTakeTable: String? = null + @Column(name = "company", nullable = true, length = 30) + open var company: String? = null + @Column(name = "warehouse", nullable = true, length = 30) + open var warehouse: String? = null + @Column(name = "area", nullable = true, length = 30) + open var area: String? = null + @Column(name = "slot", nullable = true, length = 30) + open var slot: String? = null } \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/master/service/WarehouseService.kt b/src/main/java/com/ffii/fpsms/modules/master/service/WarehouseService.kt index f936c62..89363a5 100644 --- a/src/main/java/com/ffii/fpsms/modules/master/service/WarehouseService.kt +++ b/src/main/java/com/ffii/fpsms/modules/master/service/WarehouseService.kt @@ -9,6 +9,7 @@ import com.ffii.fpsms.modules.master.entity.Warehouse import com.ffii.fpsms.modules.master.entity.WarehouseRepository import com.ffii.fpsms.modules.master.entity.projections.WarehouseCombo import com.ffii.fpsms.modules.master.web.models.SaveWarehouseRequest +import com.ffii.fpsms.modules.master.web.models.NewWarehouseRequest import com.ffii.fpsms.modules.purchaseOrder.entity.PurchaseOrderLineRepository import com.ffii.fpsms.modules.stock.entity.InventoryLotRepository import com.ffii.fpsms.modules.stock.entity.StockInLine @@ -23,7 +24,7 @@ import org.slf4j.LoggerFactory import org.springframework.stereotype.Service import java.math.BigDecimal import kotlin.jvm.optionals.getOrNull - +import com.ffii.fpsms.modules.master.web.models.ExcelWarehouseData @Service open class WarehouseService( private val jdbcDao: JdbcDao, @@ -109,4 +110,233 @@ open class WarehouseService( logger.info("--------- End - Import Warehouse Excel -------") return "Import Excel success"; } + open fun importNewExcel(workbook: Workbook?): String { + logger.info("--------- Start - Import Warehouse Excel -------"); + + if (workbook == null) { + logger.error("No Excel Import"); + return "Import Excel failure"; + } + val sheet: Sheet = workbook.getSheetAt(0); + + // Columns + val COLUMN_WAREHOSE_INDEX = 1; + val COLUMN_ZONE_INDEX = 2; + val COLUMN_SLOT_INDEX = 3; + val COLUMN_FLOOR_INDEX = 4; + val COLUMN_PICK_ROUTING_INDEX = 5; + val COLUMN_STORE_LOCATION_INDEX = 6; + val COLUMN_STOCK_TAKE_TABLE_INDEX = 7; + val COLUMN_COMPANY_INDEX = 8; + + val START_ROW_INDEX = 5; + + // 第一步:收集所有 Excel 数据(包含行索引,用于调试) + data class ExcelWarehouseDataWithRow( + val rowIndex: Int, + val warehouse: String, + val area: String, + val slot: String + ) + + val excelDataList = mutableListOf() + var skippedRows = 0 + + for (i in START_ROW_INDEX..() + + for (i in START_ROW_INDEX.. + private fun calculateOrderMap(excelDataList: List): Map { + data class WarehouseWithSort( + val data: ExcelWarehouseData, + val sortValue: Long, + val uniqueKey: String + ) + + val sortedWarehouses = excelDataList.map { data -> + val slot = data.slot.toIntOrNull() ?: 0 + val sortValue = calculateSortValue(data.warehouse, data.area, slot) + val uniqueKey = "${data.warehouse}-${data.area}-${data.slot}" + WarehouseWithSort(data, sortValue, uniqueKey) + }.sortedBy { it.sortValue } + + // 分配连续的 order(1, 2, 3...),类似 ROW_NUMBER() + return sortedWarehouses.mapIndexed { index, warehouseWithSort -> + warehouseWithSort.uniqueKey to (index + 1) // 唯一标识 -> order + }.toMap() + } + + // 计算单个仓库的排序值(与 MySQL 逻辑一致) + private fun calculateSortValue(warehouseStr: String, areaStr: String, slot: Int): Long { + // 提取楼层号 + val floorNumber = if (warehouseStr.length >= 2) { + warehouseStr.substring(1, 2).toIntOrNull() ?: 99 + } else 99 + + // 提取字母部分 + val letterPart = if (areaStr.startsWith("#") && areaStr.length >= 2) { + areaStr.substring(1, 2) + } else null + + // 计算楼层排序值 + val floorOrder = when (floorNumber) { + 2 -> 1 + 3 -> 2 + 4 -> 3 + else -> 99 + } + + // 计算字母排序值(与 MySQL 逻辑一致) + val letterOrder = when { + letterPart == null -> 9999 + letterPart in listOf("C", "B", "A", "E", "F", "G", "H", "I", "N", "M", "L", "P", "Q", "R", "S", "Y", "O", "K", "D") -> { + val orderMap = mapOf( + "C" to 1, "B" to 2, "A" to 3, "E" to 4, "F" to 5, "G" to 6, "H" to 7, "I" to 8, + "N" to 9, "M" to 10, "L" to 11, "P" to 12, "Q" to 13, "R" to 14, "S" to 15, + "Y" to 16, "O" to 17, "K" to 18, "D" to 19 + ) + orderMap[letterPart] ?: 9999 + } + else -> 1000 + letterPart[0].code + } + + // 计算总排序值:楼层 * 10000 + 字母 * 100 + slot + return floorOrder * 10000L + letterOrder * 100L + slot + } } \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/master/web/WarehouseController.kt b/src/main/java/com/ffii/fpsms/modules/master/web/WarehouseController.kt index 1f493df..a04e304 100644 --- a/src/main/java/com/ffii/fpsms/modules/master/web/WarehouseController.kt +++ b/src/main/java/com/ffii/fpsms/modules/master/web/WarehouseController.kt @@ -43,4 +43,18 @@ class WarehouseController( return ResponseEntity.ok(warehouseService.importExcel(workbook)) } + @PostMapping("/importNew") + @Throws(ServletRequestBindingException::class) + fun importNewExcel(request: HttpServletRequest): ResponseEntity<*> { + var workbook: Workbook? = null; + + try { + val multipartFile = (request as MultipartHttpServletRequest).getFile("multipartFileList") + workbook = XSSFWorkbook(multipartFile?.inputStream) + } catch (e: Exception) { + println(e) + } + + return ResponseEntity.ok(warehouseService.importNewExcel(workbook)) + } } \ No newline at end of file diff --git a/src/main/java/com/ffii/fpsms/modules/master/web/models/SaveWarehouseRequest.kt b/src/main/java/com/ffii/fpsms/modules/master/web/models/SaveWarehouseRequest.kt index 317ad93..39872ea 100644 --- a/src/main/java/com/ffii/fpsms/modules/master/web/models/SaveWarehouseRequest.kt +++ b/src/main/java/com/ffii/fpsms/modules/master/web/models/SaveWarehouseRequest.kt @@ -9,3 +9,24 @@ data class SaveWarehouseRequest( val description: String, val capacity: BigDecimal, ) +data class NewWarehouseRequest( + + val id: Long? = null, + val code: String, + val name: String, + val description: String, + val capacity: BigDecimal, + val warehouse: String, + val area: String, + val slot: String, + val store_id: String, + val order: Int, + val storeLocation: String, + val stockTakeTable: String, + val company: String, +) + data class ExcelWarehouseData( + val warehouse: String, + val area: String, + val slot: String +) diff --git a/src/main/java/com/ffii/fpsms/modules/pickOrder/service/PickOrderService.kt b/src/main/java/com/ffii/fpsms/modules/pickOrder/service/PickOrderService.kt index 925d548..863b399 100644 --- a/src/main/java/com/ffii/fpsms/modules/pickOrder/service/PickOrderService.kt +++ b/src/main/java/com/ffii/fpsms/modules/pickOrder/service/PickOrderService.kt @@ -5206,7 +5206,7 @@ open fun getLotDetailsByDoPickOrderRecordId(doPickOrderRecordId: Long): Map