feiyu02
2024-08-15 196bb14112448857a885e32dc4149e308e00b01a
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
53
54
55
56
57
58
59
60
61
package cn.flightfeather.supervision.common.risk
 
import cn.flightfeather.supervision.domain.entity.*
import com.github.pagehelper.PageHelper
import tk.mybatis.mapper.entity.Example
import java.time.Duration
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.temporal.ChronoUnit
 
/**
 * 获取守法承诺完成情况
 */
class RiskCommitment {
 
    private val summary = listOf(
        "信用/守法承诺失效未及时更新,\n",
    )
 
    private var finished = false
 
    private fun reset(){
        finished = false
    }
 
    fun getResult(user: Userinfo, config: DataSource.Config, dbMapper: DbMapper): Int {
        reset()
 
        // 统计月份的最后一天最后一秒
        val time = LocalDateTime.of(config.year, config.month, 1, 0, 0, 0)
            .plusMonths(1).minusSeconds(1)
        // 查询统计月份之前签订的最新一期守法承诺
        PageHelper.startPage<Commitment>(1, 1)
        val commitment = dbMapper.commitmentMapper.selectByExample(Example(Commitment::class.java).apply {
            createCriteria().andEqualTo("uiGuid", user.guid)
                .andLessThanOrEqualTo("cmCreateTime", time)
            orderBy("cmCreateTime").desc()
        })
        return if (commitment.isEmpty()) {
            0
        } else {
            // 判断承诺签订日期和统计月份的时间差是否超过有效时间(1年)
            val date = commitment[0].cmCreateTime
            val createTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault())
            val days = ChronoUnit.DAYS.between(createTime, time)
            finished = days <= 365
            if (finished) 2 else 1
        }
    }
 
    /**
     * 根据是否完成,返回总结
     */
    fun getSummary(): String {
        return when {
            !finished -> summary[0]
            else -> ""
        }
    }
}