package cn.flightfeather.supervision.domain.ds2.repository
|
|
import cn.flightfeather.supervision.business.autooutput.score.ScoreUtil
|
import cn.flightfeather.supervision.common.utils.Constant
|
import cn.flightfeather.supervision.domain.ds2.entity.OverallEvaluation
|
import cn.flightfeather.supervision.domain.ds2.mapper.OverallEvaluationMapper
|
import org.springframework.stereotype.Repository
|
import java.time.LocalDate
|
import java.time.ZoneId
|
import java.util.*
|
|
@Repository
|
class OverallEvaluationRep(private val overallEvaluationMapper: OverallEvaluationMapper){
|
|
/**
|
* 插入一条环信码记录
|
* @param userId
|
* @param score
|
* @param sceneType
|
* @param sT
|
* @param eT
|
* @return
|
*/
|
fun insertOrUpdateOne(
|
userId: String?,
|
score: Int?,
|
sceneType: Constant.SceneType,
|
sT: LocalDate,
|
eT: LocalDate,
|
): Int {
|
val period = "${sT.year}/${sT.monthValue}-${eT.monthValue}"
|
val codeLevel = ScoreUtil.scoreToCredit(score)
|
val oE = overallEvaluationMapper.selectOne(OverallEvaluation().apply {
|
biGuid = userId
|
oePeriod = period
|
})
|
if (oE != null) {
|
oE.oeScore = score
|
oE.oeCodeLevel = codeLevel.first?.toByte()
|
return overallEvaluationMapper.updateByPrimaryKey(oE)
|
} else {
|
val startTime = sT.withDayOfMonth(1)
|
val endTime = eT.plusMonths(1).withDayOfMonth(1).minusDays(1)
|
val publishTime = Date.from(endTime.plusDays(1).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())
|
val e = OverallEvaluation().apply {
|
biGuid = userId
|
oeScore = score
|
oePublishTime = publishTime
|
oeUpdateTime = publishTime
|
oeSceneTypeId = Constant.SceneType.typeMap(sceneType.value.toByte())
|
oeSceneType = sceneType.text
|
oePeriod = period
|
oeCodeLevel = codeLevel.first?.toByte()
|
oeStartTime = Date.from(startTime.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())
|
oeEndTime = Date.from(endTime.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())
|
}
|
return overallEvaluationMapper.insert(e)
|
}
|
}
|
}
|