|
|
@@ -16,7 +16,9 @@ import jakarta.servlet.http.HttpServletRequest |
|
|
|
import jakarta.validation.Valid |
|
|
|
import org.springframework.web.bind.annotation.* |
|
|
|
import java.time.Duration |
|
|
|
import java.time.LocalDate |
|
|
|
import java.time.LocalDateTime |
|
|
|
import java.time.format.DateTimeFormatter |
|
|
|
import java.util.HashMap |
|
|
|
import kotlin.collections.component1 |
|
|
|
import kotlin.collections.component2 |
|
|
@@ -34,6 +36,7 @@ class ProductionScheduleController( |
|
|
|
// return uomConversionService.allItems() |
|
|
|
// } |
|
|
|
|
|
|
|
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|
|
|
@GetMapping("/test") |
|
|
|
fun test(request: HttpServletRequest): Any { |
|
|
|
val criteriaArgs = CriteriaArgsBuilder.withRequest(request) |
|
|
@@ -76,18 +79,23 @@ class ProductionScheduleController( |
|
|
|
fun generateDetailSchedule(request: HttpServletRequest?): Int { |
|
|
|
try { |
|
|
|
// For test |
|
|
|
val genDate = request?.getParameter("genDate")?.let { LocalDateTime.parse(it) } |
|
|
|
val genDate = request?.getParameter("genDate")?.let { LocalDate.parse(it).atStartOfDay() } |
|
|
|
|
|
|
|
println(request) |
|
|
|
val today = LocalDateTime.now() |
|
|
|
val latestRoughScheduleAt = productionScheduleService.getLatestScheduleAt("rough") |
|
|
|
val assignDate = abs(Duration.between(latestRoughScheduleAt, today).toDays() % 7) + 1 |
|
|
|
|
|
|
|
// assume schedule period is sunday to saturday |
|
|
|
val assignDate = (genDate ?: today).dayOfWeek.value |
|
|
|
|
|
|
|
// val assignDate = abs(Duration.between(latestRoughScheduleAt, today).toDays() % 7) + 1 |
|
|
|
// val finalAssignDate = if (assignDate.toInt() == 0) { |
|
|
|
// 1 |
|
|
|
// } 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("today: $today | latestRoughScheduleAty: $latestRoughScheduleAt | assignDate: $assignDate ") |
|
|
|
productionScheduleService.generateDetailedScheduleByDay(assignDate.toInt(), genDate ?: LocalDateTime.now()) |
|
|
|
println("genDate: $genDate | today: $today | latestRoughScheduleAty: $latestRoughScheduleAt | assignDate: $assignDate ") |
|
|
|
productionScheduleService.generateDetailedScheduleByDay(assignDate, genDate ?: LocalDateTime.now()) |
|
|
|
return 200 |
|
|
|
} catch (e: Exception) { |
|
|
|
throw RuntimeException("Error generate schedule: ${e.message}", e) |
|
|
|