package cn.flightfeather.supervision.bgtask
|
|
import cn.flightfeather.supervision.common.autoledger.AutoLedger
|
import cn.flightfeather.supervision.domain.repository.PracticalOperationRep
|
import cn.flightfeather.supervision.domain.repository.UserConfigRep
|
import cn.flightfeather.supervision.domain.repository.UserInfoRep
|
import cn.flightfeather.supervision.lightshare.vo.UserSearchCondition
|
import org.springframework.stereotype.Component
|
import java.time.LocalDateTime
|
|
/**
|
* 台账自动生成任务
|
*/
|
@Component
|
class TaskAutoLedger(
|
private val autoLedger: AutoLedger,
|
private val userInfoRep: UserInfoRep,
|
private val practicalOperationRep: PracticalOperationRep,
|
private val userConfigRep: UserConfigRep
|
) : BaseTimingTask() {
|
|
companion object {
|
// 上海市静安区排污企业
|
private const val CONFIG_ID = 18
|
}
|
|
override val period: Long
|
get() = 1440L
|
|
override fun doTask(localtime: LocalDateTime) {
|
val config = userConfigRep.select(CONFIG_ID)
|
val condition = UserSearchCondition.fromUserConfig(config).apply {
|
sceneTypes = config?.ucSceneRange?.split(";") ?: emptyList()
|
}
|
val userInfos = userInfoRep.searchUser(condition)
|
val operations = practicalOperationRep.getOperation(listOf(CONFIG_ID))
|
val year = localtime.year
|
val month = localtime.monthValue
|
userInfos.forEach {
|
autoLedger.create(it, operations, year, month)
|
}
|
}
|
|
/**
|
* 台账自动生成任务定为每月1号早上0点,生成上个月的台账
|
*/
|
override fun execute(localtime: LocalDateTime) {
|
if (localtime.dayOfMonth == 1 && localtime.hour == 0 && localtime.minute == 0) {
|
doTask(localtime)
|
}
|
}
|
}
|