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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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()
    }
}