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