|
@@ -137,9 +137,6 @@ open class BomService( |
|
|
return bomProcessMaterialRepository.saveAndFlush(bomProcessMaterial) |
|
|
return bomProcessMaterialRepository.saveAndFlush(bomProcessMaterial) |
|
|
} |
|
|
} |
|
|
private fun importExcelBomMaterial(bom: Bom, sheet: Sheet) { |
|
|
private fun importExcelBomMaterial(bom: Bom, sheet: Sheet) { |
|
|
var bomMatRequest = ImportBomMatRequest( |
|
|
|
|
|
bom = bom |
|
|
|
|
|
) |
|
|
|
|
|
var bomProcessMatRequest = ImportBomProcessMaterialRequest() |
|
|
var bomProcessMatRequest = ImportBomProcessMaterialRequest() |
|
|
var startRowIndex = 10 |
|
|
var startRowIndex = 10 |
|
|
val endRowIndex = 30 |
|
|
val endRowIndex = 30 |
|
@@ -155,6 +152,9 @@ open class BomService( |
|
|
} |
|
|
} |
|
|
startRowIndex++ |
|
|
startRowIndex++ |
|
|
} |
|
|
} |
|
|
|
|
|
var bomMatRequest = ImportBomMatRequest( |
|
|
|
|
|
bom = bom |
|
|
|
|
|
) |
|
|
while (startRowIndex != endRowIndex || startColumnIndex != endColumnIndex) { |
|
|
while (startRowIndex != endRowIndex || startColumnIndex != endColumnIndex) { |
|
|
val tempRow = sheet.getRow(startRowIndex) |
|
|
val tempRow = sheet.getRow(startRowIndex) |
|
|
val tempCell = tempRow.getCell(startColumnIndex) |
|
|
val tempCell = tempRow.getCell(startColumnIndex) |
|
@@ -172,57 +172,49 @@ open class BomService( |
|
|
?: itemsRepository.findByNameAndDeletedFalse(nameCell.stringCellValue.trim()) |
|
|
?: itemsRepository.findByNameAndDeletedFalse(nameCell.stringCellValue.trim()) |
|
|
// println("getting item.....:") |
|
|
// println("getting item.....:") |
|
|
// println(item) |
|
|
// println(item) |
|
|
bomMatRequest.apply { |
|
|
|
|
|
this.item = item |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bomMatRequest.item = item |
|
|
} |
|
|
} |
|
|
2 -> { |
|
|
2 -> { |
|
|
bomMatRequest.apply { |
|
|
|
|
|
this.qty = tempCell.numericCellValue.toBigDecimal() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bomMatRequest.qty = tempCell.numericCellValue.toBigDecimal() |
|
|
} |
|
|
} |
|
|
3 -> { |
|
|
3 -> { |
|
|
bomMatRequest.apply { |
|
|
|
|
|
this.uomName = tempCell.stringCellValue.trim() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bomMatRequest.uomName = tempCell.stringCellValue.trim() |
|
|
} |
|
|
} |
|
|
7 -> { |
|
|
7 -> { |
|
|
val salesUnit = uomConversionRepository.findByCodeAndDeletedFalse(tempCell.stringCellValue.trim()) |
|
|
val salesUnit = uomConversionRepository.findByCodeAndDeletedFalse(tempCell.stringCellValue.trim()) |
|
|
bomMatRequest.apply { |
|
|
|
|
|
this.salesUnit = salesUnit |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bomMatRequest.salesUnit = salesUnit |
|
|
} |
|
|
} |
|
|
10 -> { |
|
|
10 -> { |
|
|
val bomProcess = bomProcessRepository.findBySeqNoAndBomIdAndDeletedIsFalse( |
|
|
val bomProcess = bomProcessRepository.findBySeqNoAndBomIdAndDeletedIsFalse( |
|
|
seqNo = tempCell.numericCellValue.toInt(), |
|
|
seqNo = tempCell.numericCellValue.toInt(), |
|
|
bomId = bom.id!! |
|
|
bomId = bom.id!! |
|
|
)!! // if null = bugged |
|
|
)!! // if null = bugged |
|
|
bomProcessMatRequest.apply { |
|
|
|
|
|
this.bomProcess = bomProcess |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bomProcessMatRequest.bomProcess = bomProcess |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if (startColumnIndex < endColumnIndex) { |
|
|
|
|
|
startColumnIndex++ |
|
|
|
|
|
} else if (startRowIndex < endRowIndex) { |
|
|
|
|
|
startRowIndex++ |
|
|
|
|
|
// do save |
|
|
|
|
|
val bomMaterial = saveBomMaterial(bomMatRequest) |
|
|
|
|
|
bomProcessMatRequest.bomMaterial = bomMaterial |
|
|
|
|
|
val bomProcessMaterial = saveBomProcessMaterial(bomProcessMatRequest) |
|
|
|
|
|
// clean up |
|
|
|
|
|
startColumnIndex = 0 |
|
|
|
|
|
bomMatRequest = ImportBomMatRequest( |
|
|
|
|
|
bom = bom |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
} catch(e: Error) { |
|
|
} catch(e: Error) { |
|
|
println("DEBUG ERROR:") |
|
|
println("DEBUG ERROR:") |
|
|
println(e) |
|
|
println(e) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (startColumnIndex < endColumnIndex) { |
|
|
|
|
|
startColumnIndex++ |
|
|
|
|
|
} else if (startRowIndex < endRowIndex) { |
|
|
|
|
|
startRowIndex++ |
|
|
|
|
|
// do save |
|
|
|
|
|
val bomMaterial = saveBomMaterial(bomMatRequest) |
|
|
|
|
|
bomProcessMatRequest.apply { |
|
|
|
|
|
this.bomMaterial = bomMaterial |
|
|
|
|
|
} |
|
|
|
|
|
val bomProcessMaterial = saveBomProcessMaterial(bomProcessMatRequest) |
|
|
|
|
|
startColumnIndex = 0 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fun importExcelBomBasicInfo(sheet: Sheet): Bom { |
|
|
|
|
|
|
|
|
private fun importExcelBomBasicInfo(sheet: Sheet): Bom { |
|
|
var request = ImportBomRequest( |
|
|
var request = ImportBomRequest( |
|
|
code = "", |
|
|
code = "", |
|
|
name = "", |
|
|
name = "", |
|
@@ -242,23 +234,12 @@ open class BomService( |
|
|
val topTargetValueCell = topTargetValueRow.getCell(startColumnIndex) |
|
|
val topTargetValueCell = topTargetValueRow.getCell(startColumnIndex) |
|
|
when (tempCellVal) { |
|
|
when (tempCellVal) { |
|
|
"編號" -> { |
|
|
"編號" -> { |
|
|
println(topTargetValueCell.stringCellValue.trim()) |
|
|
|
|
|
request.apply { |
|
|
|
|
|
code = topTargetValueCell.stringCellValue.trim() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
"產品名稱" -> request.apply { |
|
|
|
|
|
name = topTargetValueCell.stringCellValue.trim() |
|
|
|
|
|
} |
|
|
|
|
|
"種類" -> request.apply { |
|
|
|
|
|
description = topTargetValueCell.stringCellValue.trim() |
|
|
|
|
|
} |
|
|
|
|
|
"份量 (Qty)" -> request.apply { |
|
|
|
|
|
outputQty = topTargetValueCell.numericCellValue.toBigDecimal() |
|
|
|
|
|
} |
|
|
|
|
|
"單位" -> request.apply { |
|
|
|
|
|
outputQtyUom = topTargetValueCell.stringCellValue.trim() |
|
|
|
|
|
|
|
|
request.code = topTargetValueCell.stringCellValue.trim() |
|
|
} |
|
|
} |
|
|
|
|
|
"產品名稱" -> request.name = topTargetValueCell.stringCellValue.trim() |
|
|
|
|
|
"種類" -> request.description = topTargetValueCell.stringCellValue.trim() |
|
|
|
|
|
"份量 (Qty)" -> request.outputQty = topTargetValueCell.numericCellValue.toBigDecimal() |
|
|
|
|
|
"單位" -> request.outputQtyUom = topTargetValueCell.stringCellValue.trim() |
|
|
} |
|
|
} |
|
|
// ----------------------------------------------------------------------------------------------- // |
|
|
// ----------------------------------------------------------------------------------------------- // |
|
|
// --------------------- assigning value that is next to a header to request ------------------------ // |
|
|
// --------------------- assigning value that is next to a header to request ------------------------ // |
|
@@ -281,15 +262,11 @@ open class BomService( |
|
|
val leftTargetValueRow = sheet.getRow(startRowIndex) |
|
|
val leftTargetValueRow = sheet.getRow(startRowIndex) |
|
|
val leftTargetValueCell = leftTargetValueRow.getCell(startColumnIndex + 1) |
|
|
val leftTargetValueCell = leftTargetValueRow.getCell(startColumnIndex + 1) |
|
|
when { |
|
|
when { |
|
|
tempCellVal.contains("深淺") -> request.apply { |
|
|
|
|
|
isDark = calculateColourScore(leftTargetValueCell.stringCellValue.trim()) |
|
|
|
|
|
} |
|
|
|
|
|
tempCellVal.contains("浮沉") -> request.apply { |
|
|
|
|
|
isFloat = calculateFloatScore(leftTargetValueCell.stringCellValue.trim()) |
|
|
|
|
|
} |
|
|
|
|
|
tempCellVal.contains("濃淡") -> request.apply { |
|
|
|
|
|
isDense = if (leftTargetValueCell.cellType == CellType.NUMERIC) leftTargetValueCell.numericCellValue.toInt() else 0 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
tempCellVal.contains("深淺") -> request.isDark = calculateColourScore(leftTargetValueCell.stringCellValue.trim()) |
|
|
|
|
|
tempCellVal.contains("浮沉") -> request.isFloat = calculateFloatScore(leftTargetValueCell.stringCellValue.trim()) |
|
|
|
|
|
tempCellVal.contains("濃淡") -> request.isDense = if (leftTargetValueCell.cellType == CellType.NUMERIC) |
|
|
|
|
|
leftTargetValueCell.numericCellValue.toInt() |
|
|
|
|
|
else 0 |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (startRowIndex < endRowIndex) { |
|
|
if (startRowIndex < endRowIndex) { |
|
@@ -350,15 +327,11 @@ open class BomService( |
|
|
return number * multiplier |
|
|
return number * multiplier |
|
|
} |
|
|
} |
|
|
private fun importExcelBomProcess(bom: Bom, sheet: Sheet) { |
|
|
private fun importExcelBomProcess(bom: Bom, sheet: Sheet) { |
|
|
var bomProcessRequest = ImportBomProcessRequest( |
|
|
|
|
|
bom = bom |
|
|
|
|
|
) |
|
|
|
|
|
var startRowIndex = 30 |
|
|
var startRowIndex = 30 |
|
|
val endRowIndex = 70 |
|
|
val endRowIndex = 70 |
|
|
var startColumnIndex = 0 |
|
|
var startColumnIndex = 0 |
|
|
val endColumnIndex = 11 |
|
|
val endColumnIndex = 11 |
|
|
while (startRowIndex < endRowIndex) { |
|
|
while (startRowIndex < endRowIndex) { |
|
|
println("") |
|
|
|
|
|
val tempRow = sheet.getRow(startRowIndex) |
|
|
val tempRow = sheet.getRow(startRowIndex) |
|
|
val tempCell = tempRow.getCell(startColumnIndex) |
|
|
val tempCell = tempRow.getCell(startColumnIndex) |
|
|
if (tempCell != null && tempCell.cellType == CellType.STRING && tempCell.stringCellValue.trim() == "工序") { |
|
|
if (tempCell != null && tempCell.cellType == CellType.STRING && tempCell.stringCellValue.trim() == "工序") { |
|
@@ -368,6 +341,9 @@ open class BomService( |
|
|
} |
|
|
} |
|
|
startRowIndex++ |
|
|
startRowIndex++ |
|
|
} |
|
|
} |
|
|
|
|
|
var bomProcessRequest = ImportBomProcessRequest( |
|
|
|
|
|
bom = bom |
|
|
|
|
|
) |
|
|
while (startRowIndex != endRowIndex || startColumnIndex != endColumnIndex) { |
|
|
while (startRowIndex != endRowIndex || startColumnIndex != endColumnIndex) { |
|
|
val tempRow = sheet.getRow(startRowIndex) |
|
|
val tempRow = sheet.getRow(startRowIndex) |
|
|
val tempCell = tempRow.getCell(startColumnIndex) |
|
|
val tempCell = tempRow.getCell(startColumnIndex) |
|
@@ -381,45 +357,37 @@ open class BomService( |
|
|
try { |
|
|
try { |
|
|
when (startColumnIndex) { |
|
|
when (startColumnIndex) { |
|
|
0 -> { |
|
|
0 -> { |
|
|
println(tempCell.cellType) |
|
|
|
|
|
bomProcessRequest.apply { |
|
|
|
|
|
this.seqNo = tempCell.numericCellValue.toLong() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
println("startRowIndex: $startRowIndex") |
|
|
|
|
|
bomProcessRequest.seqNo = tempCell.numericCellValue.toLong() |
|
|
|
|
|
println("seqNo: ${tempCell.numericCellValue.toLong()}") |
|
|
|
|
|
println("bomProcessRequest: $bomProcessRequest") |
|
|
} |
|
|
} |
|
|
1 -> { |
|
|
1 -> { |
|
|
val equipmentName = tempCell.stringCellValue.trim() |
|
|
val equipmentName = tempCell.stringCellValue.trim() |
|
|
if (equipmentName != "不適用") {0 |
|
|
|
|
|
|
|
|
if (equipmentName != "不適用") { |
|
|
val equipment = bomGetOrCreateEquipment(equipmentName) |
|
|
val equipment = bomGetOrCreateEquipment(equipmentName) |
|
|
bomProcessRequest.apply { |
|
|
|
|
|
this.equipment = equipment |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
println("equipment created") |
|
|
|
|
|
bomProcessRequest.equipment = equipment |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
2 -> { |
|
|
2 -> { |
|
|
val processName = tempCell.stringCellValue.trim() |
|
|
val processName = tempCell.stringCellValue.trim() |
|
|
val process = bomGetOrCreateProcess(processName) |
|
|
val process = bomGetOrCreateProcess(processName) |
|
|
bomProcessRequest.apply { |
|
|
|
|
|
this.process = process |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bomProcessRequest.process = process |
|
|
|
|
|
println("process created") |
|
|
} |
|
|
} |
|
|
3 -> { |
|
|
3 -> { |
|
|
val description = tempCell.stringCellValue.trim() |
|
|
val description = tempCell.stringCellValue.trim() |
|
|
bomProcessRequest.apply { |
|
|
|
|
|
this.description = description |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bomProcessRequest.description = description |
|
|
} |
|
|
} |
|
|
6 -> { //duration |
|
|
6 -> { //duration |
|
|
when (tempCell.cellType) { |
|
|
when (tempCell.cellType) { |
|
|
CellType.NUMERIC -> { |
|
|
CellType.NUMERIC -> { |
|
|
bomProcessRequest.apply { |
|
|
|
|
|
this.durationInMinute = tempCell.numericCellValue.toInt() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bomProcessRequest.durationInMinute = tempCell.numericCellValue.toInt() |
|
|
} |
|
|
} |
|
|
CellType.STRING -> { |
|
|
CellType.STRING -> { |
|
|
val durationString = tempCell.stringCellValue.trim() |
|
|
val durationString = tempCell.stringCellValue.trim() |
|
|
bomProcessRequest.apply { |
|
|
|
|
|
this.durationInMinute = extractDurationStringToMinutes(durationString) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bomProcessRequest.durationInMinute = extractDurationStringToMinutes(durationString) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
else -> {} |
|
|
else -> {} |
|
@@ -429,15 +397,11 @@ open class BomService( |
|
|
10 -> { //prepTimeInMinute |
|
|
10 -> { //prepTimeInMinute |
|
|
when (tempCell.cellType) { |
|
|
when (tempCell.cellType) { |
|
|
CellType.NUMERIC -> { |
|
|
CellType.NUMERIC -> { |
|
|
bomProcessRequest.apply { |
|
|
|
|
|
this.prepTimeInMinute = tempCell.numericCellValue.toInt() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bomProcessRequest.prepTimeInMinute = tempCell.numericCellValue.toInt() |
|
|
} |
|
|
} |
|
|
CellType.STRING -> { |
|
|
CellType.STRING -> { |
|
|
val prepTimeInMinuteString = tempCell.stringCellValue.trim() |
|
|
val prepTimeInMinuteString = tempCell.stringCellValue.trim() |
|
|
bomProcessRequest.apply { |
|
|
|
|
|
this.prepTimeInMinute = extractDurationStringToMinutes(prepTimeInMinuteString) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bomProcessRequest.prepTimeInMinute = extractDurationStringToMinutes(prepTimeInMinuteString) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
else -> {} |
|
|
else -> {} |
|
@@ -446,44 +410,40 @@ open class BomService( |
|
|
11 -> { //postProdTimeInMinute |
|
|
11 -> { //postProdTimeInMinute |
|
|
when (tempCell.cellType) { |
|
|
when (tempCell.cellType) { |
|
|
CellType.NUMERIC -> { |
|
|
CellType.NUMERIC -> { |
|
|
bomProcessRequest.apply { |
|
|
|
|
|
this.postProdTimeInMinute = tempCell.numericCellValue.toInt() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bomProcessRequest.postProdTimeInMinute = tempCell.numericCellValue.toInt() |
|
|
} |
|
|
} |
|
|
CellType.STRING -> { |
|
|
CellType.STRING -> { |
|
|
val postProdTimeInMinuteString = tempCell.stringCellValue.trim() |
|
|
val postProdTimeInMinuteString = tempCell.stringCellValue.trim() |
|
|
bomProcessRequest.apply { |
|
|
|
|
|
this.postProdTimeInMinute = extractDurationStringToMinutes(postProdTimeInMinuteString) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bomProcessRequest.postProdTimeInMinute = extractDurationStringToMinutes(postProdTimeInMinuteString) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
else -> {} |
|
|
else -> {} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
println("req:") |
|
|
|
|
|
println(bomProcessRequest) |
|
|
|
|
|
// moving the loop |
|
|
|
|
|
if (startColumnIndex < endColumnIndex) { |
|
|
|
|
|
println("case1") |
|
|
|
|
|
startColumnIndex++ |
|
|
|
|
|
println("next col startColumnIndex: $startColumnIndex") |
|
|
|
|
|
} else if (startRowIndex < endRowIndex) { |
|
|
|
|
|
println("case2") |
|
|
|
|
|
// when doesn't meet first condition, falls to this and go new row |
|
|
|
|
|
startRowIndex++ |
|
|
|
|
|
println("next row startRowIndex: $startRowIndex") |
|
|
|
|
|
// do save |
|
|
|
|
|
saveBomProcess(bomProcessRequest) |
|
|
|
|
|
// clean up |
|
|
|
|
|
startColumnIndex = 0 |
|
|
|
|
|
bomProcessRequest = ImportBomProcessRequest( |
|
|
|
|
|
bom = bom |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
} catch (e: Error) { |
|
|
} catch (e: Error) { |
|
|
throw e |
|
|
throw e |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
println("startRowIndex: $startRowIndex") |
|
|
|
|
|
println("endRowIndex: $endRowIndex") |
|
|
|
|
|
println(startRowIndex < endRowIndex) |
|
|
|
|
|
|
|
|
|
|
|
println("startColumnIndex: $startColumnIndex") |
|
|
|
|
|
println("endColumnIndex: $endColumnIndex") |
|
|
|
|
|
println(startColumnIndex < endColumnIndex) |
|
|
|
|
|
// moving the loop |
|
|
|
|
|
if (startColumnIndex < endColumnIndex) { |
|
|
|
|
|
println("1st") |
|
|
|
|
|
startColumnIndex++ |
|
|
|
|
|
} else if (startRowIndex < endRowIndex) { |
|
|
|
|
|
println("2nd") |
|
|
|
|
|
// when doesn't meet first condition, falls to this and go new row |
|
|
|
|
|
startRowIndex++ |
|
|
|
|
|
// do save |
|
|
|
|
|
saveBomProcess(bomProcessRequest) |
|
|
|
|
|
startColumnIndex = 0 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|