package cn.flightfeather.supervision.lightshare.vo
|
|
import cn.flightfeather.supervision.domain.entity.EnvironmentalSchedule
|
import java.time.Duration
|
import java.time.LocalDate
|
import java.time.LocalDateTime
|
import java.time.ZoneId
|
import java.time.format.DateTimeFormatter
|
import java.util.*
|
import kotlin.math.abs
|
|
class ScheduleVo {
|
|
inner class Step{
|
var title: String? = null
|
var content: String? = null
|
}
|
|
// 日程编号
|
var id: Int? = null
|
|
// 日程名称
|
var title: String? = null
|
|
// 日程描述
|
var content: String? = null
|
|
// 日程步骤解说
|
var steps: MutableList<Step> = mutableListOf()
|
|
// 日程类型,0:环保日程;1:环保事务
|
var type: Byte? = null
|
|
// 日程生效时间
|
var time: Date? = null
|
set(value) {
|
if (value != null) {
|
val now = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0)
|
val date = LocalDateTime.ofInstant(value.toInstant(), ZoneId.systemDefault()).withHour(0).withMinute(0).withSecond(0)
|
this.diffDays = Duration.between(now, date).toDays().toInt()
|
}
|
field = value
|
}
|
|
// 日程是否需要签收
|
var needSign: Boolean = false
|
|
// 日程和服务器时间相差天数
|
var diffDays: Int = 0
|
|
// 日程是否有已经签收完成
|
var finished: Boolean = false
|
|
// 签收记录id
|
var recordId: Int? = null
|
|
companion object {
|
|
fun toScheduleVo(schedule: EnvironmentalSchedule) = ScheduleVo().apply {
|
id = schedule.scId
|
title = schedule.scTitle
|
content = schedule.scContent
|
type = schedule.scType
|
needSign = schedule.scNeedSign ?: false
|
|
if (schedule.scStepName != null && schedule.scStepDetail != null) {
|
val stepNames = schedule.scStepName.split(";")
|
val stepDetail = schedule.scStepDetail.split(";")
|
val count = if (stepNames.size > stepDetail.size) stepDetail.size else stepNames.size
|
for (i in 0 until count) {
|
steps.add(Step().apply {
|
title = stepNames[i]
|
content = stepDetail[i]
|
})
|
}
|
}
|
}
|
|
fun toScheduleVoList(schedule: EnvironmentalSchedule, option: ScheduleOption): List<ScheduleVo> {
|
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 = sT.plusDays(1)
|
} while (sT.isBefore(eT))
|
}
|
// 每周
|
1 -> {
|
val weekList = schedule.scEveryWeek.split(";")
|
do {
|
if (weekList.contains(sT.dayOfWeek.value.toString())) {
|
dateList.add(Date.from(sT.atTime(0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))
|
}
|
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()))
|
}
|
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
|
// }
|
// }
|
// mostRecentSchedule?.let { dateList.add(it) }
|
}
|
// 每年
|
3 -> {
|
val dayList = schedule.scEveryYear.split(";")
|
do {
|
val timeFormat = sT.format(DateTimeFormatter.ofPattern("MM-dd"))
|
if (dayList.contains(timeFormat)) {
|
dateList.add(Date.from(sT.atTime(0, 0, 0).atZone(ZoneId.systemDefault()).toInstant()))
|
}
|
sT = sT.plusDays(1)
|
} while (sT.isBefore(eT))
|
}
|
// 固定日期
|
4 -> {
|
val time = LocalDateTime.ofInstant(schedule.scEffectiveTime.toInstant(), ZoneId.systemDefault()).toLocalDate()
|
if (
|
(sT.isBefore(time) || sT.isEqual(time)) && (eT.isAfter(time) || eT.isEqual(time))
|
) {
|
dateList.add(schedule.scEffectiveTime)
|
}
|
}
|
}
|
return dateList.map { toScheduleVo(schedule).apply { time = it } }
|
}
|
}
|
}
|