feiyu02
2022-11-15 23bd719cebe5feeff4e48fde925b0b39755eea93
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package cn.flightfeather.supervision.common.score.item
 
import cn.flightfeather.supervision.common.score.ScoreItem
import cn.flightfeather.supervision.domain.entity.LedgerRecord
import cn.flightfeather.supervision.domain.entity.LedgerSubType
import cn.flightfeather.supervision.domain.mapper.LedgerRecordMapper
import cn.flightfeather.supervision.domain.mapper.LedgerSubTypeMapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import tk.mybatis.mapper.entity.Example
import javax.annotation.PostConstruct
 
@Component
class ScoreItem_4: ScoreItem() {
    companion object {
        private lateinit var instance: ScoreItem_4
    }
 
    @PostConstruct
    fun init() {
        instance = this
    }
 
    @Autowired
    lateinit var ledgerRecordMapper: LedgerRecordMapper
 
    @Autowired
    lateinit var ledgerSubTypeMapper: LedgerSubTypeMapper
 
    override var id: String = ""
 
    override var name: String="台账完整性"
 
    override var maxScore: Int = 10
 
    override fun calScore(): Pair<Int, Int> {
        val result = mutableListOf<Int>()
        val originSMonth = sMonth
 
        // FIXME: 2021/4/26 手动调整起始月份,同时将起始月份之前的月份默认为“台账全部完整提交” 
//        sMonth = 3
//        repeat(sMonth - originSMonth) { result.add(0)}
        
        //必填台账
        val required = mutableListOf<LedgerSubType>()
        // TODO: 2021/3/9 找出用户类型对应的必填台账
        val ledgerTypes = ledgerSubTypeMapper.selectByExample(Example(LedgerSubType::class.java).apply {
            createCriteria().andEqualTo("lScenetype", info.sceneType.value)
        }).onEach { l ->
            if (l.getlNeedupdate())
                required.add(l)
        }
        
        for (i in sMonth..eMonth) {
 
            // TODO: 2021/3/9 找出当月用户提交的台账
            val ledgers = ledgerRecordMapper.selectByExample(Example(LedgerRecord::class.java).apply {
                createCriteria().andEqualTo("lrYear", info.year).andEqualTo("lrMonth", i)
                    .andEqualTo("lrSubmitid", info.userId)
            }).map { it.lsSubtypeid }
 
            // TODO: 2021/3/9 比对
            when {
                // 台账必填项全无
                condition1(required, ledgers) -> {
                    result.add(2)
                }
                // 必填项台账部分缺失
                condition2(ledgerTypes, ledgers) -> {
                    result.add(1)
                }
                // 台账提交完整
                else -> {
                    result.add(0)
                }
            }
        }
 
        return when (result.sum()) {
            0 -> Pair(0, maxScore)
            2 * result.size -> Pair(2, minScore)
            else -> Pair(1, maxScore / 2)
        }
 
//        return Pair(2, minScore)
//        return Pair(1, maxScore / 2)
//        //台账提交完整
//        return Pair(0, maxScore)
    }
 
    /**
     * 季度内存在任何一月台账必填项全无 -10分
     * @return true 必填项台账全部缺失; false 必填项台账部分缺失或完整
     */
    private fun condition1(ledgerTypes: List<LedgerSubType>, ledgers: List<Int>): Boolean {
        for (l in ledgerTypes) {
            if (ledgers.contains(l.lsSubtypeid)) {
                return false
            }
        }
        return true
    }
 
    /**
     * 季度内存在任何一月未完整提交台账(必填项不完整) -5分
     * @return true 必填项台账部分缺失; false 必填项台账完整
     */
    private fun condition2(ledgerTypes: List<LedgerSubType>, ledgers: List<Int>): Boolean {
        for (l in ledgerTypes) {
            if (!ledgers.contains(l.lsSubtypeid)) {
                return true
            }
        }
        return false
    }
}