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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package cn.flightfeather.supervision.lightshare.service.Impl
 
import cn.flightfeather.supervision.domain.entity.Evaluation
import cn.flightfeather.supervision.domain.entity.Evaluationrule
import cn.flightfeather.supervision.domain.entity.Evaluationsubrule
import cn.flightfeather.supervision.domain.entity.Itemevaluation
import cn.flightfeather.supervision.domain.enumeration.SceneType
import cn.flightfeather.supervision.domain.mapper.*
import cn.flightfeather.supervision.lightshare.service.EvaluationsubruleService
import cn.flightfeather.supervision.lightshare.vo.EvaluationVo
import cn.flightfeather.supervision.lightshare.vo.SubEvaluationVo
import cn.flightfeather.supervision.lightshare.vo.ThirdEvaluationVo
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
 
@Service
class EvaluationsubruleServiceImpl(
        val evaluationsubruleMapper: EvaluationsubruleMapper,
        private val userinfoMapper: UserinfoMapper,
        private val evaluationruleMapper: EvaluationruleMapper,
        private val evaluationMapper: EvaluationMapper,
        private val itemevaluationMapper: ItemevaluationMapper
):EvaluationsubruleService {
 
    override fun findOne(id: String): Evaluationsubrule = evaluationsubruleMapper.selectByPrimaryKey(id)
 
    override fun findAll(): MutableList<Evaluationsubrule> = evaluationsubruleMapper.selectAll()
 
    override fun save(evaluationsubrule: Evaluationsubrule): Int = evaluationsubruleMapper.insert(evaluationsubrule)
 
    override fun update(evaluationsubrule: Evaluationsubrule): Int = evaluationsubruleMapper.updateByPrimaryKey(evaluationsubrule)
 
    override fun delete(id: String): Int = evaluationsubruleMapper.deleteByPrimaryKey(id)
 
    override fun findByRuleId(erguid: String): List<Evaluationsubrule> {
        val example = Example(Evaluationsubrule::class.java)
        val criteria = example.createCriteria()
        criteria.andEqualTo("erguid", erguid)
        return evaluationsubruleMapper.selectByExample(example)
    }
 
    override fun getScore(userId: String, time: String, platform:String?): List<EvaluationVo> {
        val userinfo = userinfoMapper.selectByPrimaryKey(userId) ?: return emptyList()
        var sceneType = userinfo.extension2
        // FIXME: 2022/11/8 临时添加过度功能,提供微信小程序前端汽修类型的场景单独的评估清单 ,场景类型为 -7
        if (platform == "weixin" && sceneType == SceneType.VehicleRepair.value.toString()) {
            sceneType = "-7"
        }
        //评分总规则
        val rules = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
            createCriteria().andEqualTo("scensetypeid", sceneType)
//                    .andEqualTo("ruletype", "1")
                .andIsNull("tasktypeid")
        })
        if (rules.isEmpty()) return emptyList()
 
        val rIdList = mutableListOf<String?>()
        rules.forEach {
            rIdList.add(it.guid)
        }
 
        //总规则对应的评分子规则
        val subRules = mutableListOf<Evaluationsubrule>()
        val sr = evaluationsubruleMapper.selectByExample(Example(Evaluationsubrule::class.java).apply {
            createCriteria().andIn("erguid", rIdList)
            orderBy("ertype")
            orderBy("displayid")
        })
        subRules.addAll(sr)
 
        //总规则的得分
        val ruleScore = evaluationMapper.selectByExample(Example(Evaluation::class.java).apply {
            createCriteria().andIn("stguid", rIdList)//规则id
                    .andEqualTo("evaluatorguid", userId)//用户id
                    .andEqualTo("scensename", time)//评估周期,例:2020/6-6
        })
        //子规则逐条得分
        val subRuleScores = if (ruleScore.isEmpty()) {
            mutableListOf<Itemevaluation>()
        } else {
            val scoreIds = mutableListOf<String?>()
            ruleScore.forEach { scoreIds.add(it.guid) }
            itemevaluationMapper.selectByExample(Example(Itemevaluation::class.java).apply {
                createCriteria().andIn("sguid", scoreIds)
            })
        }
 
        val resultList = mutableListOf<EvaluationVo>()
 
        var _group = 0
        subRules.forEach {
            when (it.ertype) {
                2 -> resultList.add(EvaluationVo().apply {
                    id = it.guid
                    title1 = it.itemname
                    scoreMode = it.extension1
                    gradeMode = it.extension2
                    score = when (gradeMode) {
                        "minus_mode" -> it.minscore?.minus(it.maxscore ?: 0) ?: 0
                        "add_mode" -> it.maxscore ?: 0
                        else -> it.minscore?.minus(it.maxscore ?: 0) ?: 0
                    }
                    selectMode = it.extension3
 
                    //如果有得分记录,则改变状态为选中
                    for (s in subRuleScores) {
                        if (it.guid == s.esrguid) {
                            select = s.extension1 == "true"
                            break
                        }
                    }
                })
                3 -> {
                    for (r in resultList) {
                        if (it.fatherid == r.id) {
                            r.sub1.add(SubEvaluationVo().apply {
                                id = it.guid
                                title2 = it.itemname
                                gradeMode = it.extension2
                                selectMode = it.extension3
                                score = when (gradeMode) {
                                    "minus_mode" -> it.minscore?.minus(it.maxscore ?: 0) ?: 0
                                    "add_mode" -> it.maxscore ?: 0
                                    else -> it.minscore?.minus(it.maxscore ?: 0) ?: 0
                                }
                                group = _group++
 
                                //如果有得分记录,则改变状态为选中
                                for (s in subRuleScores) {
                                    if (it.guid == s.esrguid) {
                                        select = s.extension1 == "true"
                                        break
                                    }
                                }
                            })
                            break
                        }
                    }
                }
                4 -> {
                    resultList.forEach{ r ->
                        //4级的评估项直接附属于2级评估项
                        if (r.id == it.fatherid) {
                            if (r.sub1.isEmpty()) {
                                r.sub1.add(SubEvaluationVo().apply {
                                    placeholder = true
                                    id = it.guid
                                    title2 = r.title1
                                    score = r.score
                                    gradeMode = r.gradeMode
                                    selectMode = r.selectMode
                                    group = _group++
                                })
                            }
                            r.sub1[0].sub2.add(ThirdEvaluationVo().apply {
                                id = it.guid
                                content = it.itemname
                                score = when (r.sub1[0].gradeMode) {
                                    "minus_mode" -> r.score.plus(it.maxscore ?: 0)
                                    "add_mode" -> it.maxscore ?: 0
                                    else -> r.score.plus(it.maxscore ?: 0)
                                }
                                //如果有得分记录,则改变状态为选中
                                for (s in subRuleScores) {
                                    if (it.guid == s.esrguid) {
                                        select = s.extension1 == "true"
                                        break
                                    }
                                }
                            })
                        } else {
                            r.sub1.forEach { sr ->
                                if (sr.id == it.fatherid){
                                    sr.sub2.add(ThirdEvaluationVo().apply {
                                        id = it.guid
                                        content = it.itemname
                                        score = when (sr.gradeMode) {
                                            "minus_mode" -> sr.score.plus(it.maxscore ?: 0)
                                            "add_mode" -> it.maxscore ?: 0
                                            else -> sr.score.plus(it.maxscore ?: 0)
                                        }
                                        //如果有得分记录,则改变状态为选中
                                        for (s in subRuleScores) {
                                            if (it.guid == s.esrguid) {
                                                select = s.extension1 == "true"
                                                break
                                            }
                                        }
                                    })
                                }
                            }
                        }
                    }
                }
            }
        }
 
        return resultList
    }
}