feiyu02
2024-11-19 752e00503f672ddfe2066afb6c235721a3a912b5
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
62
package cn.flightfeather.supervision.common.risk
 
import cn.flightfeather.supervision.domain.entity.RiskEvaluation
import cn.flightfeather.supervision.domain.entity.Userinfo
import cn.flightfeather.supervision.domain.enumeration.SceneType
import java.time.LocalDate
import java.time.ZoneId
import java.util.*
 
class UtilDatabase(private val dbMapper: DbMapper) {
    private var period: String? = null
    private var startTime: Date? = null
    private var endTime: Date? = null
    private var publishTime: Date? = null
 
    fun setConfig(year: Int, month: Int) {
        setPeriod(year, month)
        setDuration(year, month)
    }
 
    private fun setPeriod(year: Int, month: Int) {
        period = "$year/$month-$month"
    }
 
    private fun setDuration(year: Int, month: Int) {
        val s = LocalDate.of(year, month, 1)
        val e = s.plusMonths(1).minusDays(1)
        val p = s.plusMonths(1)
        startTime = Date.from(s.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())
        endTime = Date.from(e.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())
        publishTime = Date.from(p.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())
    }
 
    fun insertToDataBase(userinfo: Userinfo, riskLevel: Int, summary: String) {
        val risk = RiskEvaluation().apply {
            biGuid = userinfo.guid
            rePeriod = period
        }
        val result = dbMapper.riskEvaluationMapper.selectOne(risk)
        if (result == null) {
            val vo = RiskEvaluation().apply {
                biGuid = userinfo.guid
                reRiskLevel = riskLevel
                rePublishTime = publishTime
                reSceneTypeId = userinfo.extension2?.toInt()
                reSceneType = SceneType.getByValue(reSceneTypeId).des
                rePeriod = period
                reStartTime = startTime
                reEndTime = endTime
                reSummary = summary
            }
            dbMapper.riskEvaluationMapper.insert(vo)
        } else {
            result.apply {
                reRiskLevel = riskLevel
                reSummary = summary
            }
            dbMapper.riskEvaluationMapper.updateByPrimaryKeySelective(result)
        }
 
    }
}