feiyu02
2024-11-19 752e00503f672ddfe2066afb6c235721a3a912b5
src/main/kotlin/cn/flightfeather/supervision/lightshare/vo/ScheduleVo.kt
@@ -77,16 +77,17 @@
        }
        fun toScheduleVoList(schedule: EnvironmentalSchedule, option: ScheduleOption): List<ScheduleVo> {
            val sT = LocalDateTime.ofInstant(option.startTime.toInstant(), ZoneId.systemDefault()).toLocalDate()
            var sT = LocalDateTime.ofInstant(option.startTime.toInstant(), ZoneId.systemDefault()).toLocalDate()
            val eT = LocalDateTime.ofInstant(option.endTime.toInstant(), ZoneId.systemDefault()).toLocalDate()
                .plusDays(1)
            val dateList = mutableListOf<Date>()
            when (schedule.scPeriodType.toInt()) {
                // 每日
                0 -> {
                    do {
                        dateList.add(Date.from(sT.atTime(0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))
                        sT.plusDays(1)
                    } while (sT.isAfter(eT))
                        sT = sT.plusDays(1)
                    } while (sT.isBefore(eT))
                }
                // 每周
                1 -> {
@@ -95,30 +96,30 @@
                        if (weekList.contains(sT.dayOfWeek.value.toString())) {
                            dateList.add(Date.from(sT.atTime(0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))
                        }
                        sT.plusDays(1)
                    } while (sT.isAfter(eT))
                        sT = sT.plusDays(1)
                    } while (sT.isBefore(eT))
                }
                // 每月
                2 -> {
                    val dayList = schedule.scEveryMonth.split(";")
//                    do {
//                        if (dayList.contains(sT.dayOfMonth.toString())) {
//                            dateList.add(Date.from(sT.atTime(0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))
                    do {
                        if (dayList.contains(sT.dayOfMonth.toString())) {
                            dateList.add(Date.from(sT.atTime(0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))
                        }
                        sT = sT.plusDays(1)
                    } while (sT.isBefore(eT))
//                    var diffDays: Int? = null
//                    var mostRecentSchedule: Date? = null
//                    dayList.forEach {
//                        val diff = abs(it.toInt() - sT.dayOfMonth)
//                        if (diffDays == null || diff < diffDays!!) {
//                            mostRecentSchedule = Date.from(sT.withDayOfMonth(it.toInt()).atTime(0, 0, 0).atZone(ZoneId
//                                .systemDefault())
//                                .toInstant())
//                            diffDays = diff
//                        }
//                        sT.plusDays(1)
//                    } while (sT.isAfter(eT))
                    var diffDays: Int? = null
                    var mostRecentSchedule: Date? = null
                    dayList.forEach {
                        val diff = abs(it.toInt() - sT.dayOfMonth)
                        if (diffDays == null || diff < diffDays!!) {
                            mostRecentSchedule = Date.from(sT.withDayOfMonth(it.toInt()).atTime(0, 0, 0).atZone(ZoneId
                                .systemDefault())
                                .toInstant())
                            diffDays = diff
                        }
                    }
                    mostRecentSchedule?.let { dateList.add(it) }
//                    }
//                    mostRecentSchedule?.let { dateList.add(it) }
                }
                // 每年
                3 -> {
@@ -128,8 +129,8 @@
                        if (dayList.contains(timeFormat)) {
                            dateList.add(Date.from(sT.atTime(0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))
                        }
                        sT.plusDays(1)
                    } while (sT.isAfter(eT))
                        sT = sT.plusDays(1)
                    } while (sT.isBefore(eT))
                }
                // 固定日期
                4 -> {