|
|
@@ -100,7 +100,7 @@ open class BomService( |
|
|
|
return savedBom |
|
|
|
} |
|
|
|
|
|
|
|
fun saveBomMaterial(req: ImportBomMatRequest): BomMaterial { |
|
|
|
private fun saveBomMaterial(req: ImportBomMatRequest): BomMaterial { |
|
|
|
// val uom = uomConversionRepository.findByCodeAndDeletedFalse() |
|
|
|
val bomMaterial = BomMaterial().apply { |
|
|
|
this.item = req.item |
|
|
@@ -116,7 +116,7 @@ open class BomService( |
|
|
|
} |
|
|
|
return bomMaterialRepository.saveAndFlush(bomMaterial) |
|
|
|
} |
|
|
|
fun saveBomProcess(req: ImportBomProcessRequest): BomProcess { |
|
|
|
private fun saveBomProcess(req: ImportBomProcessRequest): BomProcess { |
|
|
|
val bomProcess = BomProcess().apply { |
|
|
|
this.process = req.process |
|
|
|
this.equipment = req.equipment |
|
|
@@ -155,10 +155,11 @@ open class BomService( |
|
|
|
var bomMatRequest = ImportBomMatRequest( |
|
|
|
bom = bom |
|
|
|
) |
|
|
|
println("starting new loop") |
|
|
|
while (startRowIndex != endRowIndex || startColumnIndex != endColumnIndex) { |
|
|
|
val tempRow = sheet.getRow(startRowIndex) |
|
|
|
val tempCell = tempRow.getCell(startColumnIndex) |
|
|
|
if (tempCell == null || tempCell.cellType == CellType.BLANK) { |
|
|
|
if (startColumnIndex == 0 && (tempCell == null || tempCell.cellType == CellType.BLANK)) { |
|
|
|
break |
|
|
|
} else { |
|
|
|
try { |
|
|
@@ -185,6 +186,8 @@ open class BomService( |
|
|
|
bomMatRequest.salesUnit = salesUnit |
|
|
|
} |
|
|
|
10 -> { |
|
|
|
println("seqNo: ${tempCell.numericCellValue.toInt()}") |
|
|
|
println("bomId: ${bom.id!!}") |
|
|
|
val bomProcess = bomProcessRepository.findBySeqNoAndBomIdAndDeletedIsFalse( |
|
|
|
seqNo = tempCell.numericCellValue.toInt(), |
|
|
|
bomId = bom.id!! |
|
|
@@ -192,11 +195,19 @@ open class BomService( |
|
|
|
bomProcessMatRequest.bomProcess = bomProcess |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
println("startRowIndex: $startRowIndex") |
|
|
|
println("endRowIndex: $endRowIndex") |
|
|
|
|
|
|
|
println("first condition: ${startColumnIndex < endColumnIndex}") |
|
|
|
println("second condition: ${startRowIndex < endRowIndex}") |
|
|
|
if (startColumnIndex < endColumnIndex) { |
|
|
|
startColumnIndex++ |
|
|
|
} else if (startRowIndex < endRowIndex) { |
|
|
|
startRowIndex++ |
|
|
|
// do save |
|
|
|
println("req:") |
|
|
|
println(bomMatRequest) |
|
|
|
val bomMaterial = saveBomMaterial(bomMatRequest) |
|
|
|
bomProcessMatRequest.bomMaterial = bomMaterial |
|
|
|
val bomProcessMaterial = saveBomProcessMaterial(bomProcessMatRequest) |
|
|
@@ -205,6 +216,7 @@ open class BomService( |
|
|
|
bomMatRequest = ImportBomMatRequest( |
|
|
|
bom = bom |
|
|
|
) |
|
|
|
println("saved: $bomMatRequest") |
|
|
|
} |
|
|
|
} catch(e: Error) { |
|
|
|
println("DEBUG ERROR:") |
|
|
@@ -307,13 +319,17 @@ open class BomService( |
|
|
|
} |
|
|
|
|
|
|
|
private fun extractDurationStringToMinutes(str: String): Int { |
|
|
|
val regex = """(\d+)(\D+)""".toRegex() |
|
|
|
val regex = """(\d+)(\D+)(\d+)(\D+)""".toRegex() |
|
|
|
val matchResult = regex.find(str) |
|
|
|
|
|
|
|
// fun returnMultiplier(unit: String): { |
|
|
|
// |
|
|
|
// } |
|
|
|
val (number, unit) = matchResult?.let { |
|
|
|
val number = it.groupValues[1].toInt() |
|
|
|
val unit = it.groupValues[2] |
|
|
|
Pair(number, unit) |
|
|
|
val num1 = it.groupValues[1].toInt() |
|
|
|
val unit1 = it.groupValues[2] |
|
|
|
// val num2 = it.groupValues[3].toInt() |
|
|
|
// val unit2 = it.groupValues[4] |
|
|
|
Pair(num1, unit1) |
|
|
|
}!! |
|
|
|
var multiplier = 1 |
|
|
|
when { |
|
|
@@ -336,7 +352,7 @@ open class BomService( |
|
|
|
val tempCell = tempRow.getCell(startColumnIndex) |
|
|
|
if (tempCell != null && tempCell.cellType == CellType.STRING && tempCell.stringCellValue.trim() == "工序") { |
|
|
|
startRowIndex += 2 // skip column header |
|
|
|
println("last: $startRowIndex") |
|
|
|
// println("last: $startRowIndex") |
|
|
|
break |
|
|
|
} |
|
|
|
startRowIndex++ |
|
|
@@ -349,7 +365,7 @@ open class BomService( |
|
|
|
val tempCell = tempRow.getCell(startColumnIndex) |
|
|
|
val checkCell = tempRow.getCell(0) |
|
|
|
if (startColumnIndex == 0 && (tempCell == null || tempCell.cellType == CellType.BLANK)) { |
|
|
|
println("hi") |
|
|
|
// println("hi") |
|
|
|
break |
|
|
|
} else { |
|
|
|
println(tempCell.cellType) |
|
|
@@ -357,16 +373,16 @@ open class BomService( |
|
|
|
try { |
|
|
|
when (startColumnIndex) { |
|
|
|
0 -> { |
|
|
|
println("startRowIndex: $startRowIndex") |
|
|
|
// println("startRowIndex: $startRowIndex") |
|
|
|
bomProcessRequest.seqNo = tempCell.numericCellValue.toLong() |
|
|
|
println("seqNo: ${tempCell.numericCellValue.toLong()}") |
|
|
|
println("bomProcessRequest: $bomProcessRequest") |
|
|
|
// println("seqNo: ${tempCell.numericCellValue.toLong()}") |
|
|
|
// println("bomProcessRequest: $bomProcessRequest") |
|
|
|
} |
|
|
|
1 -> { |
|
|
|
val equipmentName = tempCell.stringCellValue.trim() |
|
|
|
if (equipmentName != "不適用") { |
|
|
|
val equipment = bomGetOrCreateEquipment(equipmentName) |
|
|
|
println("equipment created") |
|
|
|
// println("equipment created") |
|
|
|
bomProcessRequest.equipment = equipment |
|
|
|
} |
|
|
|
} |
|
|
@@ -374,7 +390,7 @@ open class BomService( |
|
|
|
val processName = tempCell.stringCellValue.trim() |
|
|
|
val process = bomGetOrCreateProcess(processName) |
|
|
|
bomProcessRequest.process = process |
|
|
|
println("process created") |
|
|
|
// println("process created") |
|
|
|
} |
|
|
|
3 -> { |
|
|
|
val description = tempCell.stringCellValue.trim() |
|
|
@@ -420,18 +436,18 @@ open class BomService( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
println("req:") |
|
|
|
println(bomProcessRequest) |
|
|
|
// println("req:") |
|
|
|
// println(bomProcessRequest) |
|
|
|
// moving the loop |
|
|
|
if (startColumnIndex < endColumnIndex) { |
|
|
|
println("case1") |
|
|
|
// println("case1") |
|
|
|
startColumnIndex++ |
|
|
|
println("next col startColumnIndex: $startColumnIndex") |
|
|
|
// println("next col startColumnIndex: $startColumnIndex") |
|
|
|
} else if (startRowIndex < endRowIndex) { |
|
|
|
println("case2") |
|
|
|
// println("case2") |
|
|
|
// when doesn't meet first condition, falls to this and go new row |
|
|
|
startRowIndex++ |
|
|
|
println("next row startRowIndex: $startRowIndex") |
|
|
|
// println("next row startRowIndex: $startRowIndex") |
|
|
|
// do save |
|
|
|
saveBomProcess(bomProcessRequest) |
|
|
|
// clean up |
|
|
|