package cn.flightfeather.supervision.common.risk
|
|
import cn.flightfeather.supervision.domain.entity.*
|
import cn.flightfeather.supervision.domain.enumeration.AuthenticationType
|
import com.github.pagehelper.PageHelper
|
import tk.mybatis.mapper.entity.Example
|
import java.time.LocalDateTime
|
import java.time.ZoneId
|
|
/**
|
* 获取认证完成情况
|
*/
|
class RiskAuthenticated {
|
|
private val summary = listOf(
|
"企业未认证,\n",
|
"管理人员未认证,\n",
|
)
|
|
inner class Result(){
|
// 小程序登录情况
|
var login = false
|
// 店铺信息
|
var baseInfo: BaseInfo? = null
|
// 企业认证情况
|
var finished1 = false
|
// 个人认证情况
|
var finished2 = false
|
// 个人认证人数
|
var count = 0
|
// 个人认证级别最高角色
|
var type = ""
|
}
|
|
private val result = Result()
|
|
private fun reset(){
|
result.apply {
|
login = false
|
baseInfo = null
|
finished1 = false
|
finished2 = false
|
count = 0
|
type = ""
|
}
|
}
|
|
fun getResult(user: Userinfo, config: DataSource.Config, dbMapper: DbMapper): Result {
|
reset()
|
|
val startTime = LocalDateTime.of(config.year, config.month, 1, 0, 0, 0)
|
val endTime = startTime.plusMonths(1).minusSeconds(1)
|
// dbMapper.userinfoMapper.selectByExample(Example(Userinfo::class.java).apply {
|
// createCriteria().andEqualTo("guid", user.guid)
|
// .andGreaterThanOrEqualTo("uiLoginTime", time)
|
// })?.run { if (isNotEmpty()) result.login = true }
|
PageHelper.startPage<UserLoginLog>(1, 1)
|
dbMapper.userLoginLogMapper.selectByExample(Example(UserLoginLog::class.java).apply {
|
createCriteria().andEqualTo("ulUserGuid", user.guid)
|
.andBetween("ulLoginTime", startTime, endTime)
|
})?.run { if (isNotEmpty()) result.login = true }
|
val baseInfo = dbMapper.baseInfoMapper.selectByPrimaryKey(user.guid)
|
result.baseInfo = baseInfo
|
val company = dbMapper.companyMapper.selectByPrimaryKey(baseInfo?.ciGuid)
|
val createTime = if (baseInfo?.biCreateTime != null) {
|
LocalDateTime.ofInstant(baseInfo.biCreateTime.toInstant(), ZoneId.systemDefault())
|
.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).plusSeconds(1)
|
} else {
|
// 如果场景没有填写创建时间,则默认已创建
|
startTime.minusSeconds(1)
|
}
|
result.finished1 = company?.ciExtension3 == "authenticated" && startTime.isAfter(createTime)
|
|
val pList = dbMapper.personalInfoMapper.selectByExample(Example(PersonalInfo::class.java).apply {
|
createCriteria().andEqualTo("piSceneId", user.guid)
|
})
|
result.finished2 = pList.isNotEmpty() && startTime.isAfter(createTime)
|
if (result.finished2) {
|
result.count = pList.size
|
pList.forEach {
|
if (result.type.isBlank() || it?.piPosition == AuthenticationType.Admin.des) {
|
result.type = it?.piPosition ?: ""
|
}
|
}
|
}
|
|
return result
|
}
|
|
/**
|
* 根据是否完成,返回总结
|
*/
|
fun getSummary(): String {
|
val s = StringBuilder()
|
if (!result.finished1) {
|
s.append(summary[0])
|
}
|
if (result.type != AuthenticationType.Admin.des) s.append(summary[1])
|
return s.toString()
|
}
|
}
|