|
|
@@ -17,6 +17,9 @@ import java.nio.file.Paths |
|
|
import java.nio.file.Files; |
|
|
import java.nio.file.Files; |
|
|
import java.nio.file.StandardCopyOption |
|
|
import java.nio.file.StandardCopyOption |
|
|
import com.ffii.fpsms.modules.master.entity.EquipmentDetailRepository |
|
|
import com.ffii.fpsms.modules.master.entity.EquipmentDetailRepository |
|
|
|
|
|
import com.ffii.fpsms.modules.settings.entity.BomWeightingScoreRepository |
|
|
|
|
|
import java.math.BigDecimal |
|
|
|
|
|
import java.math.RoundingMode |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
@@ -32,6 +35,7 @@ open class BomService( |
|
|
private val equipmentRepository: EquipmentRepository, |
|
|
private val equipmentRepository: EquipmentRepository, |
|
|
private val processRepository: ProcessRepository, |
|
|
private val processRepository: ProcessRepository, |
|
|
private val equipmentDetailRepository: EquipmentDetailRepository, |
|
|
private val equipmentDetailRepository: EquipmentDetailRepository, |
|
|
|
|
|
private val bomWeightingScoreRepository: BomWeightingScoreRepository, |
|
|
) { |
|
|
) { |
|
|
open fun findAll(): List<Bom> { |
|
|
open fun findAll(): List<Bom> { |
|
|
return bomRepository.findAll() |
|
|
return bomRepository.findAll() |
|
|
@@ -112,6 +116,7 @@ open class BomService( |
|
|
this.uom = uom |
|
|
this.uom = uom |
|
|
// this.excelUom = req.excelUom |
|
|
// this.excelUom = req.excelUom |
|
|
} |
|
|
} |
|
|
|
|
|
bom.baseScore = calculateBaseScore(bom) |
|
|
val savedBom = bomRepository.saveAndFlush(bom) |
|
|
val savedBom = bomRepository.saveAndFlush(bom) |
|
|
// println("saved: ${savedBom.id}") |
|
|
// println("saved: ${savedBom.id}") |
|
|
return savedBom |
|
|
return savedBom |
|
|
@@ -337,8 +342,12 @@ open class BomService( |
|
|
|
|
|
|
|
|
when { |
|
|
when { |
|
|
//use fix row column by index not by search value contain later |
|
|
//use fix row column by index not by search value contain later |
|
|
tempCellVal.contains("深淺") -> request.isDark = calculateColourScore(getCellValueAsString(leftTargetValueCell)) |
|
|
|
|
|
tempCellVal.contains("浮沉") -> request.isFloat = calculateFloatScore(getCellValueAsString(leftTargetValueCell)) |
|
|
|
|
|
|
|
|
tempCellVal.contains("深淺") -> request.isDark = if (leftTargetValueCell?.cellType == CellType.NUMERIC) |
|
|
|
|
|
leftTargetValueCell.numericCellValue.toInt() |
|
|
|
|
|
else 0 |
|
|
|
|
|
tempCellVal.contains("浮沉") -> request.isFloat = if (leftTargetValueCell?.cellType == CellType.NUMERIC) |
|
|
|
|
|
leftTargetValueCell.numericCellValue.toInt() |
|
|
|
|
|
else 0 |
|
|
tempCellVal.contains("過敏原 (如有)") -> request.allergicSubstances = calculateAllergicSubstancesScore(getCellValueAsString(leftTargetValueCell)) |
|
|
tempCellVal.contains("過敏原 (如有)") -> request.allergicSubstances = calculateAllergicSubstancesScore(getCellValueAsString(leftTargetValueCell)) |
|
|
tempCellVal.contains("濃淡") -> request.isDense = if (leftTargetValueCell?.cellType == CellType.NUMERIC) |
|
|
tempCellVal.contains("濃淡") -> request.isDense = if (leftTargetValueCell?.cellType == CellType.NUMERIC) |
|
|
leftTargetValueCell.numericCellValue.toInt() |
|
|
leftTargetValueCell.numericCellValue.toInt() |
|
|
@@ -622,6 +631,50 @@ open class BomService( |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Calculates baseScore from BOM basic info using bom_weighting_score (code = BOM column name). |
|
|
|
|
|
* For isDark, isFloat, isDense, allergicSubstances, timeSequence, complexity: (extractedScore / range) * weighting * 100. |
|
|
|
|
|
* For equipmentConflict: weighting * 100 only. |
|
|
|
|
|
*/ |
|
|
|
|
|
private fun calculateBaseScore(bom: Bom): BigDecimal { |
|
|
|
|
|
val scale = 2 |
|
|
|
|
|
val roundingMode = RoundingMode.HALF_UP |
|
|
|
|
|
var sum = BigDecimal.ZERO.setScale(scale, roundingMode) |
|
|
|
|
|
|
|
|
|
|
|
// Score columns: contribution = (extractedScore / range) * weighting * 100 |
|
|
|
|
|
val scoreColumns = listOf( |
|
|
|
|
|
"isDark" to (bom.isDark?.toBigDecimal() ?: BigDecimal.ZERO), |
|
|
|
|
|
"isFloat" to (bom.isFloat?.toBigDecimal() ?: BigDecimal.ZERO), |
|
|
|
|
|
"isDense" to (bom.isDense?.toBigDecimal() ?: BigDecimal.ZERO), |
|
|
|
|
|
"allergicSubstances" to (bom.allergicSubstances?.toBigDecimal() ?: BigDecimal.ZERO), |
|
|
|
|
|
"timeSequence" to (bom.timeSequence?.toBigDecimal() ?: BigDecimal.ZERO), |
|
|
|
|
|
"complexity" to (bom.complexity?.toBigDecimal() ?: BigDecimal.ZERO), |
|
|
|
|
|
) |
|
|
|
|
|
for ((code, extractedScore) in scoreColumns) { |
|
|
|
|
|
val row = bomWeightingScoreRepository.findByCodeAndDeletedFalse(code) ?: continue |
|
|
|
|
|
val range = (row.range ?: 1).toBigDecimal() |
|
|
|
|
|
val weighting = row.weighting ?: continue |
|
|
|
|
|
if (range.compareTo(BigDecimal.ZERO) == 0) continue |
|
|
|
|
|
val contribution = extractedScore |
|
|
|
|
|
.divide(range, scale, roundingMode) |
|
|
|
|
|
.multiply(weighting) |
|
|
|
|
|
.multiply(BigDecimal(100)) |
|
|
|
|
|
.setScale(scale, roundingMode) |
|
|
|
|
|
sum = sum.add(contribution) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// equipmentConflict: contribution = weighting * 100 only |
|
|
|
|
|
val equipmentConflictRow = bomWeightingScoreRepository.findByCodeAndDeletedFalse("equipmentConflict") |
|
|
|
|
|
if (equipmentConflictRow?.weighting != null) { |
|
|
|
|
|
val contribution = equipmentConflictRow.weighting!! |
|
|
|
|
|
.multiply(BigDecimal(100)) |
|
|
|
|
|
.setScale(scale, roundingMode) |
|
|
|
|
|
sum = sum.add(contribution) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return sum.setScale(scale, roundingMode) |
|
|
|
|
|
} |
|
|
open fun exportProblematicBOM() { |
|
|
open fun exportProblematicBOM() { |
|
|
val resolver = PathMatchingResourcePatternResolver() |
|
|
val resolver = PathMatchingResourcePatternResolver() |
|
|
val successExcel = resolver.getResources("file:C:/Users/2Fi/Desktop/fail/*.xlsx") |
|
|
val successExcel = resolver.getResources("file:C:/Users/2Fi/Desktop/fail/*.xlsx") |
|
|
|