|
|
|
@@ -341,6 +341,7 @@ open class ProductionScheduleService( |
|
|
|
|
|
|
|
return DetailedProdScheduleWithLine( |
|
|
|
id = sqlResult.id, |
|
|
|
produceAt = sqlResult.produceAt, |
|
|
|
scheduleAt = sqlResult.scheduleAt, |
|
|
|
totalEstProdCount = sqlResult.totalEstProdCount, |
|
|
|
totalFGType = sqlResult.totalFGType, |
|
|
|
@@ -418,52 +419,53 @@ open class ProductionScheduleService( |
|
|
|
|
|
|
|
try { |
|
|
|
jobOrderService.jobOrderDetailByItemId(itemId) |
|
|
|
logger.info("jobOrderDetailByItemId ok itemId:$itemId") |
|
|
|
} catch (e: NoSuchElementException) { |
|
|
|
//only do with no JO is working |
|
|
|
|
|
|
|
logger.info("NoSuchElementException itemId:$itemId") |
|
|
|
try { |
|
|
|
jobOrderService.jobOrderDetailByItemId(itemId) |
|
|
|
} catch (e: NoSuchElementException) { |
|
|
|
val bom = bomService.findByItemId(itemId) |
|
|
|
?: throw NoSuchElementException("BOM not found for Item ID $itemId.") |
|
|
|
|
|
|
|
// 4. Update Prod Schedule Line fields |
|
|
|
prodScheduleLine.apply { |
|
|
|
// Use bom.outputQty, ensuring it's treated as Double for prodQty |
|
|
|
prodQty = bom.outputQty?.toDouble() |
|
|
|
?: throw IllegalStateException("BOM output quantity is null for Item ID $itemId.") |
|
|
|
approverId = approver?.id |
|
|
|
} |
|
|
|
|
|
|
|
productionScheduleLineRepository.save(prodScheduleLine) |
|
|
|
|
|
|
|
// 5. Logging (optional but kept) |
|
|
|
logger.info("prodScheduleLine.prodQty: ${prodScheduleLine.prodQty}") |
|
|
|
logger.info("bom?.outputQty: ${bom.outputQty} ${bom.outputQtyUom}") |
|
|
|
|
|
|
|
logger.info("[releaseProdSchedule] prodScheduleLine.needNoOfJobOrder:" + prodScheduleLine.needNoOfJobOrder) |
|
|
|
//repeat(prodScheduleLine.needNoOfJobOrder) { |
|
|
|
// 6. Create Job Order |
|
|
|
val joRequest = CreateJobOrderRequest( |
|
|
|
bomId = bom.id, // bom is guaranteed non-null here |
|
|
|
reqQty = bom.outputQty?.multiply(BigDecimal.valueOf(prodScheduleLine.batchNeed.toLong())), |
|
|
|
approverId = approver?.id, |
|
|
|
|
|
|
|
// CRUCIAL FIX: Use the line ID, not the parent schedule ID |
|
|
|
prodScheduleLineId = prodScheduleLine.id!! |
|
|
|
) |
|
|
|
|
|
|
|
// Assuming createJobOrder returns the created Job Order (jo) |
|
|
|
val jo = jobOrderService.createJobOrder(joRequest) |
|
|
|
// 4. Update Prod Schedule Line fields |
|
|
|
prodScheduleLine.apply { |
|
|
|
// Use bom.outputQty, ensuring it's treated as Double for prodQty |
|
|
|
prodQty = bom.outputQty?.toDouble() |
|
|
|
?: throw IllegalStateException("BOM output quantity is null for Item ID $itemId.") |
|
|
|
approverId = approver?.id |
|
|
|
} |
|
|
|
|
|
|
|
val createdJobOrderId = jo.id |
|
|
|
?: throw IllegalStateException("Job Order creation failed: returned object ID is null.") |
|
|
|
|
|
|
|
// 7. Create related job order data |
|
|
|
jobOrderBomMaterialService.createJobOrderBomMaterialsByJoId(createdJobOrderId) |
|
|
|
jobOrderProcessService.createJobOrderProcessesByJoId(createdJobOrderId) |
|
|
|
productProcessService.createProductProcessByJobOrderId(createdJobOrderId, prodScheduleLine.itemPriority.toInt()) |
|
|
|
//} |
|
|
|
productionScheduleLineRepository.save(prodScheduleLine) |
|
|
|
|
|
|
|
// 5. Logging (optional but kept) |
|
|
|
logger.info("prodScheduleLine.prodQty: ${prodScheduleLine.prodQty}") |
|
|
|
logger.info("bom?.outputQty: ${bom.outputQty} ${bom.outputQtyUom}") |
|
|
|
|
|
|
|
logger.info("[releaseProdSchedule] prodScheduleLine.needNoOfJobOrder:" + prodScheduleLine.needNoOfJobOrder) |
|
|
|
//repeat(prodScheduleLine.needNoOfJobOrder) { |
|
|
|
// 6. Create Job Order |
|
|
|
val joRequest = CreateJobOrderRequest( |
|
|
|
bomId = bom.id, // bom is guaranteed non-null here |
|
|
|
reqQty = bom.outputQty?.multiply(BigDecimal.valueOf(prodScheduleLine.batchNeed.toLong())), |
|
|
|
approverId = approver?.id, |
|
|
|
|
|
|
|
// CRUCIAL FIX: Use the line ID, not the parent schedule ID |
|
|
|
prodScheduleLineId = prodScheduleLine.id!! |
|
|
|
) |
|
|
|
|
|
|
|
// Assuming createJobOrder returns the created Job Order (jo) |
|
|
|
val jo = jobOrderService.createJobOrder(joRequest) |
|
|
|
|
|
|
|
val createdJobOrderId = jo.id |
|
|
|
?: throw IllegalStateException("Job Order creation failed: returned object ID is null.") |
|
|
|
|
|
|
|
// 7. Create related job order data |
|
|
|
jobOrderBomMaterialService.createJobOrderBomMaterialsByJoId(createdJobOrderId) |
|
|
|
jobOrderProcessService.createJobOrderProcessesByJoId(createdJobOrderId) |
|
|
|
productProcessService.createProductProcessByJobOrderId(createdJobOrderId, prodScheduleLine.itemPriority.toInt()) |
|
|
|
//} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@@ -736,7 +738,11 @@ open class ProductionScheduleService( |
|
|
|
var machineCap = 10000.0 |
|
|
|
var needQtyList = getNeedQty() |
|
|
|
|
|
|
|
//remove the production schedule >= today |
|
|
|
clearTodayAndFutureProdSchedule() |
|
|
|
|
|
|
|
println("needQtyList - " + needQtyList); |
|
|
|
|
|
|
|
//##### The 22000, 10000 machine cap just means the max warehouse storage qty, not production qty cap |
|
|
|
//##### The total production qty of the date is 10000 due to machine cap |
|
|
|
//##### search all items with bom to consider need or no need production |
|
|
|
@@ -1613,5 +1619,30 @@ open class ProductionScheduleService( |
|
|
|
return jdbcDao.queryForList(sql, args); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Transactional |
|
|
|
open fun clearTodayAndFutureProdSchedule() { |
|
|
|
val deleteLinesSql = """ |
|
|
|
DELETE FROM production_schedule_line |
|
|
|
WHERE prodScheduleId IN ( |
|
|
|
SELECT id FROM production_schedule |
|
|
|
WHERE DATE(produceAt) >= DATE(NOW()) |
|
|
|
) |
|
|
|
""".trimIndent() |
|
|
|
|
|
|
|
val deleteSchedulesSql = """ |
|
|
|
DELETE FROM production_schedule |
|
|
|
WHERE DATE(produceAt) >= DATE(NOW()) |
|
|
|
""".trimIndent() |
|
|
|
|
|
|
|
// Execute child delete first |
|
|
|
jdbcDao.executeUpdate(deleteLinesSql) |
|
|
|
|
|
|
|
// Then delete parent schedules |
|
|
|
jdbcDao.executeUpdate(deleteSchedulesSql) |
|
|
|
|
|
|
|
// Optional: log the action (if you have logging setup) |
|
|
|
// logger.info("Cleared all production schedules with produceAt >= today") |
|
|
|
} |
|
|
|
|
|
|
|
} |