feiyu02
2022-07-28 237d7c42498806a3ca205f63d151671a45304854
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
package cn.flightfeather.supervision.lightshare.service.Impl
 
import cn.flightfeather.supervision.domain.entity.Evaluationrule
import cn.flightfeather.supervision.domain.enumeration.SceneType
import cn.flightfeather.supervision.domain.mapper.EvaluationruleMapper
import cn.flightfeather.supervision.lightshare.service.EvaluationruleService
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
 
@Service
class EvaluationruleServiceImpl(val evaluationruleMapper: EvaluationruleMapper) : EvaluationruleService {
 
    override fun findOne(id: String): Evaluationrule{
        return evaluationruleMapper.selectByPrimaryKey(id)
    }
 
    override fun findAll(): MutableList<Evaluationrule> = evaluationruleMapper.selectAll()
 
    override fun save(evaluationrule: Evaluationrule): Int = evaluationruleMapper.insert(evaluationrule)
 
    override fun update(evaluationrule: Evaluationrule): Int = evaluationruleMapper.updateByPrimaryKey(evaluationrule)
 
    override fun delete(id: String): Int = evaluationruleMapper.deleteByPrimaryKey(id)
 
    override fun findBySpecificRule(tasktypeid: Byte?, scensetypeid: Byte?, districtcode: String?): Evaluationrule? {
        val example =Example(Evaluationrule::class.java)
        val criteria = example.createCriteria()
        criteria.andEqualTo("tasktypeid", tasktypeid)
                .andEqualTo("scensetypeid", scensetypeid)
                .andEqualTo("districtcode", districtcode)
        val evaluationrules = evaluationruleMapper.selectByExample(example)
        return if (evaluationrules.size>0) evaluationrules[0] else null
    }
 
    override fun getRule(erGuid: String?, sceneTypeId: Int, erType: Int?): List<Evaluationrule> {
        val example = Example(Evaluationrule::class.java)
        val criteria = example.createCriteria()
        erGuid?.let { criteria.andEqualTo("guid", it) }
        if (erType == 0 || erType == null) {
            example.and(example.createCriteria().orIsNull("tasktypeid").orEqualTo("tasktypeid", 0))
        } else {
            criteria.andEqualTo("tasktypeid", erType.toByte())
        }
        criteria.andEqualTo("scensetypeid", sceneTypeId.toByte())
            .andEqualTo("isuse", true)
 
        val resultList = evaluationruleMapper.selectByExample(example)
 
        return if (resultList.isEmpty()) {
            //默认返回工业企业类型的评分表格
            evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
                val criteria1 = createCriteria()
                erGuid?.let { criteria1.andEqualTo("guid", it)  }
                criteria1.andEqualTo("scensetypeid", SceneType.Industrial.value.toByte())
            })
        } else {
            resultList
        }
    }
}