소스 검색

update production schedule

master
cyril.tsui 3 주 전
부모
커밋
a69bca80b6
3개의 변경된 파일35개의 추가작업 그리고 13개의 파일을 삭제
  1. +9
    -5
      src/main/java/com/ffii/fpsms/modules/master/entity/ProductionScheduleRepository.kt
  2. +17
    -2
      src/main/java/com/ffii/fpsms/modules/master/service/ProductionScheduleService.kt
  3. +9
    -6
      src/main/java/com/ffii/fpsms/modules/master/web/ProductionScheduleController.kt

+ 9
- 5
src/main/java/com/ffii/fpsms/modules/master/entity/ProductionScheduleRepository.kt 파일 보기

@@ -14,7 +14,6 @@ interface ProductionScheduleRepository : AbstractRepository<ProductionSchedule,
"""
select max(ps.scheduleAt) from ProductionSchedule ps
where (:type is null or ps.type = :type)
or ps.type = 'manual'
"""
)
fun getLatestRoughScheduleAt(type: String?): LocalDateTime
@@ -28,8 +27,9 @@ interface ProductionScheduleRepository : AbstractRepository<ProductionSchedule,
ps.id,
ps.deleted,
ps.scheduleAt,
date_add(ps.scheduleAt, interval 7 + 4 - if(weekday(ps.scheduleAt) = 6, 0, weekday(ps.scheduleAt) + 1) day) as schedulePeriod,
date_add(ps.scheduleAt, interval 7 + 4 + 6 - if(weekday(ps.scheduleAt) = 6, 0, weekday(ps.scheduleAt) + 1) day) as schedulePeriodTo,
-- ps.produceAt,
date_add(ps.scheduleAt, interval 7 + 1 - if(weekday(ps.scheduleAt) = 6, 0, weekday(ps.scheduleAt) + 1) day) as schedulePeriod,
date_add(ps.scheduleAt, interval 7 + 1 + 6 - if(weekday(ps.scheduleAt) = 6, 0, weekday(ps.scheduleAt) + 1) day) as schedulePeriodTo,
ps.totalEstProdCount,
ps.totalFGType,
ps.`type`
@@ -38,6 +38,7 @@ interface ProductionScheduleRepository : AbstractRepository<ProductionSchedule,
select * from prod
where deleted = false
and (:scheduleAt = '' or datediff(scheduleAt, coalesce(:scheduleAt, scheduleAt)) = 0)
-- and (:produceAt = '' or datediff(produceAt, coalesce(:produceAt, produceAt)) = 0)
and (:schedulePeriod = '' or datediff(schedulePeriod, coalesce(:schedulePeriod, schedulePeriod)) = 0)
and (:schedulePeriodTo = '' or datediff(schedulePeriodTo, coalesce(:schedulePeriodTo, schedulePeriodTo)) = 0)
and (:totalEstProdCount is null or :totalEstProdCount = '' or totalEstProdCount = :totalEstProdCount)
@@ -51,8 +52,9 @@ interface ProductionScheduleRepository : AbstractRepository<ProductionSchedule,
ps.id,
ps.deleted,
ps.scheduleAt,
date_add(ps.scheduleAt, interval 7 + 4 - if(weekday(ps.scheduleAt) = 6, 0, weekday(ps.scheduleAt) + 1) day) as schedulePeriod,
date_add(ps.scheduleAt, interval 7 + 4 + 6 - if(weekday(ps.scheduleAt) = 6, 0, weekday(ps.scheduleAt) + 1) day) as schedulePeriodTo,
-- ps.produceAt,
date_add(ps.scheduleAt, interval 7 + 1 - if(weekday(ps.scheduleAt) = 6, 0, weekday(ps.scheduleAt) + 1) day) as schedulePeriod,
date_add(ps.scheduleAt, interval 7 + 1 + 6 - if(weekday(ps.scheduleAt) = 6, 0, weekday(ps.scheduleAt) + 1) day) as schedulePeriodTo,
ps.totalEstProdCount,
ps.totalFGType,
ps.`type`
@@ -61,6 +63,7 @@ interface ProductionScheduleRepository : AbstractRepository<ProductionSchedule,
select count(*) from prod
where deleted = false
and (:scheduleAt = '' or datediff(scheduleAt, coalesce(:scheduleAt, scheduleAt)) = 0)
-- and (:produceAt = '' or datediff(produceAt, coalesce(:produceAt, produceAt)) = 0)
and (:schedulePeriod = '' or datediff(schedulePeriod, coalesce(:schedulePeriod, schedulePeriod)) = 0)
and (:schedulePeriodTo = '' or datediff(schedulePeriodTo, coalesce(:schedulePeriodTo, schedulePeriodTo)) = 0)
and (:totalEstProdCount is null or :totalEstProdCount = '' or totalEstProdCount = :totalEstProdCount)
@@ -70,6 +73,7 @@ interface ProductionScheduleRepository : AbstractRepository<ProductionSchedule,
)
fun findProdScheduleInfoByPage(
scheduleAt: String?,
// produceAt: String?,
schedulePeriod: String?,
schedulePeriodTo: String?,
totalEstProdCount: Double?,


+ 17
- 2
src/main/java/com/ffii/fpsms/modules/master/service/ProductionScheduleService.kt 파일 보기

@@ -31,6 +31,8 @@ import org.springframework.transaction.annotation.Transactional
import java.lang.reflect.Type
import java.math.BigDecimal
import java.math.RoundingMode
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import kotlin.collections.component1
@@ -64,11 +66,23 @@ open class ProductionScheduleService(
return productionScheduleRepository.getLatestRoughScheduleAt(type)
}

open fun getScheduledAtByDate(inputDate: LocalDate): LocalDate {
val daysToSubtract = when (inputDate.dayOfWeek) {
DayOfWeek.WEDNESDAY -> 7
else -> (inputDate.dayOfWeek.value + 7 - DayOfWeek.WEDNESDAY.value) % 7
}

val lastWednesday = inputDate.minusDays(daysToSubtract.toLong())

return lastWednesday;
}

open fun allProdSchedulesByPage(request: SearchProdScheduleRequest): RecordsRes<ProdScheduleInfo> {
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<ProductionScheduleRecord, Double> = 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)



+ 9
- 6
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)


불러오는 중...
취소
저장