[email protected] 3 недель назад
Родитель
Сommit
27e34d71ed
3 измененных файлов: 72 добавлений и 37 удалений
  1. +2
    -0
      src/main/java/com/ffii/fpsms/modules/master/entity/ProductionScheduleRepository.kt
  2. +2
    -0
      src/main/java/com/ffii/fpsms/modules/master/entity/projections/ProdScheduleInfo.kt
  3. +68
    -37
      src/main/java/com/ffii/fpsms/modules/master/service/ProductionScheduleService.kt

+ 2
- 0
src/main/java/com/ffii/fpsms/modules/master/entity/ProductionScheduleRepository.kt Просмотреть файл

@@ -204,6 +204,7 @@ interface ProductionScheduleRepository : AbstractRepository<ProductionSchedule,
select
prod.id,
prod.scheduleAt,
prod.produceAt,
prod.totalFGType,
prod.totalEstProdCount,
prod.daysLeft,
@@ -241,6 +242,7 @@ interface ProductionScheduleRepository : AbstractRepository<ProductionSchedule,
select
ps.id,
ps.scheduleAt,
ps.produceAt,
ps.totalFGType,
ps.totalEstProdCount,
psl.approverId is not null as approved,


+ 2
- 0
src/main/java/com/ffii/fpsms/modules/master/entity/projections/ProdScheduleInfo.kt Просмотреть файл

@@ -18,6 +18,7 @@ interface ProdScheduleInfo {
// Detailed Production Schedule With Line
interface DetailedProdScheduleWithLineWithJsonString {
val id: Long?
val produceAt: LocalDateTime?
val scheduleAt: LocalDateTime?
val totalEstProdCount: BigDecimal?
val totalFGType: Long?
@@ -27,6 +28,7 @@ interface DetailedProdScheduleWithLineWithJsonString {

data class DetailedProdScheduleWithLine (
val id: Long?,
val produceAt: LocalDateTime?,
val scheduleAt: LocalDateTime?,
val totalEstProdCount: BigDecimal?,
val totalFGType: Long?,


+ 68
- 37
src/main/java/com/ffii/fpsms/modules/master/service/ProductionScheduleService.kt Просмотреть файл

@@ -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")
}
}

Загрузка…
Отмена
Сохранить