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)
|
}
|
|
}
|
}
|