ソースを参照

no message

master
コミット
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 select
prod.id, prod.id,
prod.scheduleAt, prod.scheduleAt,
prod.produceAt,
prod.totalFGType, prod.totalFGType,
prod.totalEstProdCount, prod.totalEstProdCount,
prod.daysLeft, prod.daysLeft,
@@ -241,6 +242,7 @@ interface ProductionScheduleRepository : AbstractRepository<ProductionSchedule,
select select
ps.id, ps.id,
ps.scheduleAt, ps.scheduleAt,
ps.produceAt,
ps.totalFGType, ps.totalFGType,
ps.totalEstProdCount, ps.totalEstProdCount,
psl.approverId is not null as approved, 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 // Detailed Production Schedule With Line
interface DetailedProdScheduleWithLineWithJsonString { interface DetailedProdScheduleWithLineWithJsonString {
val id: Long? val id: Long?
val produceAt: LocalDateTime?
val scheduleAt: LocalDateTime? val scheduleAt: LocalDateTime?
val totalEstProdCount: BigDecimal? val totalEstProdCount: BigDecimal?
val totalFGType: Long? val totalFGType: Long?
@@ -27,6 +28,7 @@ interface DetailedProdScheduleWithLineWithJsonString {


data class DetailedProdScheduleWithLine ( data class DetailedProdScheduleWithLine (
val id: Long?, val id: Long?,
val produceAt: LocalDateTime?,
val scheduleAt: LocalDateTime?, val scheduleAt: LocalDateTime?,
val totalEstProdCount: BigDecimal?, val totalEstProdCount: BigDecimal?,
val totalFGType: Long?, 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( return DetailedProdScheduleWithLine(
id = sqlResult.id, id = sqlResult.id,
produceAt = sqlResult.produceAt,
scheduleAt = sqlResult.scheduleAt, scheduleAt = sqlResult.scheduleAt,
totalEstProdCount = sqlResult.totalEstProdCount, totalEstProdCount = sqlResult.totalEstProdCount,
totalFGType = sqlResult.totalFGType, totalFGType = sqlResult.totalFGType,
@@ -418,52 +419,53 @@ open class ProductionScheduleService(


try { try {
jobOrderService.jobOrderDetailByItemId(itemId) jobOrderService.jobOrderDetailByItemId(itemId)
logger.info("jobOrderDetailByItemId ok itemId:$itemId")
} catch (e: NoSuchElementException) { } catch (e: NoSuchElementException) {
//only do with no JO is working //only do with no JO is working
logger.info("NoSuchElementException itemId:$itemId")
try { try {
jobOrderService.jobOrderDetailByItemId(itemId) jobOrderService.jobOrderDetailByItemId(itemId)
} catch (e: NoSuchElementException) { } catch (e: NoSuchElementException) {
val bom = bomService.findByItemId(itemId) val bom = bomService.findByItemId(itemId)
?: throw NoSuchElementException("BOM not found for Item ID $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 machineCap = 10000.0
var needQtyList = getNeedQty() var needQtyList = getNeedQty()
//remove the production schedule >= today
clearTodayAndFutureProdSchedule()

println("needQtyList - " + needQtyList); println("needQtyList - " + needQtyList);
//##### The 22000, 10000 machine cap just means the max warehouse storage qty, not production qty cap //##### 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 //##### 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 //##### search all items with bom to consider need or no need production
@@ -1613,5 +1619,30 @@ open class ProductionScheduleService(
return jdbcDao.queryForList(sql, args); 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")
}
} }

読み込み中…
キャンセル
保存