From a69bca80b6c0aa963cc1479aec97241a0be23b02 Mon Sep 17 00:00:00 2001 From: "cyril.tsui" Date: Sat, 2 Aug 2025 16:09:30 +0800 Subject: [PATCH] update production schedule --- .../entity/ProductionScheduleRepository.kt | 14 +++++++++----- .../service/ProductionScheduleService.kt | 19 +++++++++++++++++-- .../web/ProductionScheduleController.kt | 15 +++++++++------ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/ffii/fpsms/modules/master/entity/ProductionScheduleRepository.kt b/src/main/java/com/ffii/fpsms/modules/master/entity/ProductionScheduleRepository.kt index 8664f2d..3012b77 100644 --- a/src/main/java/com/ffii/fpsms/modules/master/entity/ProductionScheduleRepository.kt +++ b/src/main/java/com/ffii/fpsms/modules/master/entity/ProductionScheduleRepository.kt @@ -14,7 +14,6 @@ interface ProductionScheduleRepository : AbstractRepository 7 + else -> (inputDate.dayOfWeek.value + 7 - DayOfWeek.WEDNESDAY.value) % 7 + } + + val lastWednesday = inputDate.minusDays(daysToSubtract.toLong()) + + return lastWednesday; + } + open fun allProdSchedulesByPage(request: SearchProdScheduleRequest): RecordsRes { val pageable = PageRequest.of(request.pageNum ?: 0, request.pageSize ?: 10); val response = productionScheduleRepository.findProdScheduleInfoByPage( scheduleAt = request.scheduleAt, +// produceAt = request.produceAt, schedulePeriod = request.schedulePeriod, schedulePeriodTo = request.schedulePeriodTo, totalEstProdCount = request.totalEstProdCount, @@ -462,7 +476,6 @@ open class ProductionScheduleService( //用缺口決定生產順序 val productionPriorityMap: HashMap = HashMap(); - //TODO: update to use SQL get shop order record for detailed scheduling (real prodQty and openBal) for (record in scheduledList) { println("Object - " + record.toString()); @@ -595,10 +608,11 @@ open class ProductionScheduleService( + " LEFT JOIN bom b ON i.id = b.itemId " + " WHERE ps.deleted = FALSE " + " AND psl.deleted = FALSE " + + " AND ps.`type` = 'rough' " ); if (args.containsKey("selectedDate")) { - sql.append(" AND DATE(ps.scheduleAt) LIKE DATE(:selectedDate) AND ps.id = (select max(ps1.id) from production_schedule ps1 where DATE(ps1.scheduleAt) LIKE DATE(:selectedDate))"); + sql.append(" AND DATE(ps.scheduleAt) LIKE DATE(:selectedDate) AND ps.id = (select max(ps1.id) from production_schedule ps1 where DATE(ps1.scheduleAt) LIKE DATE(:selectedDate) AND ps1.`type` = 'rough') "); } if (args.containsKey("name")) { sql.append(" AND i.name LIKE :name "); @@ -613,6 +627,7 @@ open class ProductionScheduleService( sql.append(" ORDER BY psl.assignDate, psl.itemPriority ASC "); print(sql) + print(args.toString()) val resultList = jdbcDao.queryForList(sql.toString(), args); print(resultList) diff --git a/src/main/java/com/ffii/fpsms/modules/master/web/ProductionScheduleController.kt b/src/main/java/com/ffii/fpsms/modules/master/web/ProductionScheduleController.kt index a8499ec..ed34049 100644 --- a/src/main/java/com/ffii/fpsms/modules/master/web/ProductionScheduleController.kt +++ b/src/main/java/com/ffii/fpsms/modules/master/web/ProductionScheduleController.kt @@ -81,12 +81,15 @@ class ProductionScheduleController( // For test val genDate = request?.getParameter("genDate")?.let { LocalDate.parse(it).atStartOfDay() } - println(request) val today = LocalDateTime.now() - val latestRoughScheduleAt = productionScheduleService.getLatestScheduleAt("rough") - // assume schedule period is thursday to wednesday - val assignDate = ((genDate ?: today).dayOfWeek.value + 3) % 7 + 1 + val latestRoughScheduleAt = productionScheduleService.getLatestScheduleAt("rough"); +// val latestRoughScheduleAt = productionScheduleService.getSecondLatestRoughScheduleAt("rough"); +// val latestRoughScheduleAt = productionScheduleService.getScheduledAtByDate(genDate?.toLocalDate() ?: today.toLocalDate()); + // assume schedule period is monday to sunday + val assignDate = (genDate ?: today).dayOfWeek.value +// val day = 1 +// val assignDate = ((genDate ?: today).dayOfWeek.value + day) % 7 + 1 // val assignDate = abs(Duration.between(latestRoughScheduleAt, today).toDays() % 7) + 1 // val finalAssignDate = if (assignDate.toInt() == 0) { @@ -94,8 +97,8 @@ class ProductionScheduleController( // } else assignDate.toInt() //TODO: update this to receive selectedDate and assignDate from schedule // productionScheduleService.generateDetailedScheduleByDay(1, LocalDateTime.of(2025,6,25,0,0,0)) - println("genDate: $genDate | today: $today | latestRoughScheduleAty: $latestRoughScheduleAt | assignDate: $assignDate ") - productionScheduleService.generateDetailedScheduleByDay(assignDate, genDate ?: LocalDateTime.now()) + println("genDate: $genDate | today: $today | latestRoughScheduleAt: $latestRoughScheduleAt | assignDate: $assignDate ") + productionScheduleService.generateDetailedScheduleByDay(assignDate, latestRoughScheduleAt ?: LocalDateTime.now()) return 200 } catch (e: Exception) { throw RuntimeException("Error generate schedule: ${e.message}", e)