package cn.flightfeather.supervision.business.bgtask
|
|
import cn.flightfeather.supervision.common.utils.Constant
|
import cn.flightfeather.supervision.domain.ds1.entity.Task
|
import cn.flightfeather.supervision.domain.ds1.repository.TaskRep
|
import org.springframework.stereotype.Component
|
import java.time.LocalDateTime
|
import java.time.ZoneId
|
|
/**
|
* 结束本月之前所有已创建的日任务都完成的的顶层任务
|
* @date 2024/7/2
|
* @author feiyu02
|
*/
|
@Component
|
class TaskFinishTopTask(private val taskRep: TaskRep) {
|
|
fun handle() {
|
// 筛选所有正在执行中的顶层任务
|
val topTasks = taskRep.findTasks(Task().apply {
|
levelnum = 2
|
runingstatus = Constant.TaskProgress.RUNINGSTATUS2.text
|
})
|
|
// 获取上月底时间
|
val lastMonth = LocalDateTime.now().withDayOfMonth(1).withHour(0)
|
.withMinute(0).withSecond(0).minusSeconds(1)
|
topTasks.forEach { tt ->
|
if (tt == null) return@forEach
|
val time = LocalDateTime.ofInstant(tt.starttime?.toInstant(), ZoneId.systemDefault())
|
// 筛选本月之前的顶层任务
|
if (time.isBefore(lastMonth)) {
|
// 统计对应的所有日任务是否都已结束,若都结束,则结束该顶层任务
|
val dayTasks = taskRep.findDayTasks(tt.tguid)
|
var finished = true
|
for (dt in dayTasks) {
|
if (dt?.runingstatus != Constant.TaskProgress.RUNINGSTATUS3.text) {
|
finished = false
|
break
|
}
|
}
|
if (finished) {
|
tt.runingstatus = Constant.TaskProgress.RUNINGSTATUS3.text
|
taskRep.update(tt)
|
}
|
}
|
}
|
}
|
}
|