feiyu02
2025-09-30 6904763f0e74d9a9fa4dbc39f635d2aee39416c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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)
        }
    }
}